Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-glsl

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-glsl - npm Package Compare versions

Comparing version 0.0.1-alpha.1 to 0.0.1-alpha.2

19

index.js
const { dirname } = require('path');
const { evalConstant } = require('./lib/utils');
const { evalConstant, resolveModule } = require('./lib/utils');
const compile = require('./lib/compile');

@@ -13,3 +13,6 @@

const { quasi, tag } = path.node;
if (tag.type !== 'Identifier' || tag.name !== 'glsl') {
if (
tag.type !== 'Identifier' ||
resolveModule(path, tag.name) !== 'glslify'
) {
return;

@@ -33,4 +36,16 @@ }

},
Program: {
exit(programPath) {
programPath.traverse({
ImportDeclaration(path) {
if (path.node.source.value === 'glslify') {
path.remove();
}
},
// TODO: remove requires
});
},
},
},
};
};

9

lib/bundle.js

@@ -14,3 +14,2 @@ /* eslint-disable no-redeclare */

const descope = require('glsl-token-descope');
const clean = require('glslify-bundle/lib/clean-suffixes');
const string = require('glsl-token-string');

@@ -52,3 +51,3 @@ const scope = require('glsl-token-scope');

this.src = string(clean(trim(this.src)));
this.src = string(trim(this.src));
}

@@ -130,4 +129,6 @@

// Compute suffix for module
// More rigorous hash than glslify does,
// because compiled entry chunks could end up in the same shader
bindings.sort();
const ident = bindings.join(':') + ':' + dep.id;
const ident = bindings.join(':') + ':' + dep.id + entry.source;
let suffix = '_' + hash(ident);

@@ -186,3 +187,3 @@

// Let imports be renamed to a hashed version
// Rename them together with exports to the imported name at the end
// Rename toplevel imports again at the end
if (dep.entry) {

@@ -189,0 +190,0 @@ postRename[importTokens[0]] = importName;

@@ -0,1 +1,57 @@

function resolveImport(identifier, declaration) {
if (
declaration.type === 'ImportDeclaration' &&
declaration.source &&
declaration.source.type === 'StringLiteral'
) {
return declaration.source.value;
}
return '';
}
function resolveRequire(path, identifier, declaration) {
if (declaration.type === 'VariableDeclaration') {
var children = declaration.declarations;
for (var i = 0; i < children.length; ++i) {
if (children[i].id === identifier) {
var rhs = children[i].init;
if (
rhs &&
rhs.type === 'CallExpression' &&
rhs.callee.type === 'Identifier' &&
rhs.callee.name === 'require' &&
!path.scope.getBinding('require') &&
rhs.arguments.length === 1 &&
rhs.arguments[0].type === 'StringLiteral'
) {
return rhs.arguments[0].value;
}
}
}
}
return '';
}
function resolveModule(path, name) {
var binding = path.scope.getBinding(name);
if (!binding) {
return '';
}
if (!binding.constant) {
return '';
}
switch (binding.kind) {
case 'module':
return resolveImport(binding.identifier, binding.path.parent);
case 'var':
case 'let':
case 'const':
return resolveRequire(path, binding.identifier, binding.path.parent);
default:
return '';
}
}
function evalConstant(env, path, expression) {

@@ -106,3 +162,6 @@ if (!expression) {

module.exports = {
resolveImport,
resolveRequire,
resolveModule,
evalConstant,
};
{
"name": "babel-plugin-glsl",
"description": "Process GLSL code with glslify",
"version": "0.0.1-alpha.1",
"version": "0.0.1-alpha.2",
"author": "Onno Visser <visser.onno@gmail.com>",

@@ -26,3 +26,2 @@ "bugs": {

"files": [
"README.md",
"index.js",

@@ -29,0 +28,0 @@ "lib/*"

@@ -9,2 +9,4 @@ # babel-plugin-glsl

```js
import glsl from 'glslify';
const fragmentShader = glsl`

@@ -45,6 +47,6 @@ #pragma glslify: random = require(glsl-random)

# yarn
yarn add -D babel-plugin-glsl
yarn add -D glslify babel-plugin-glsl
# npm
npm i --save-dev babel-plugin-glsl
npm i --save-dev glslify babel-plugin-glsl
```

@@ -51,0 +53,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc