rollup-plugin-inject
Advanced tools
Comparing version 1.4.0 to 1.4.1
# rollup-plugin-inject | ||
## 1.4.1 | ||
* Return a `name` | ||
## 1.4.0 | ||
@@ -4,0 +8,0 @@ |
@@ -17,3 +17,2 @@ 'use strict'; | ||
}); | ||
function makeLegalIdentifier(str) { | ||
@@ -33,21 +32,38 @@ str = str.replace(/-(\w)/g, function (_, letter) { | ||
function isReference(node, parent) { | ||
if (node.type === 'MemberExpression') { | ||
return !node.computed && isReference(node.object, node); | ||
} | ||
function isReference(_x, _x2) { | ||
var _left; | ||
if (node.type === 'Identifier') { | ||
// TODO is this right? | ||
if (parent.type === 'MemberExpression') return parent.computed || node === parent.object; | ||
var _again = true; | ||
// disregard the `bar` in { bar: foo } | ||
if (parent.type === 'Property' && node !== parent.value) return false; | ||
_function: while (_again) { | ||
var node = _x, | ||
parent = _x2; | ||
_again = false; | ||
// disregard the `bar` in `class Foo { bar () {...} }` | ||
if (parent.type === 'MethodDefinition') return false; | ||
if (node.type === 'MemberExpression') { | ||
if (!(_left = !node.computed)) { | ||
return _left; | ||
} | ||
// disregard the `bar` in `export { foo as bar }` | ||
if (parent.type === 'ExportSpecifier' && node !== parent.local) return; | ||
_x = node.object; | ||
_x2 = node; | ||
_again = true; | ||
continue _function; | ||
} | ||
return true; | ||
if (node.type === 'Identifier') { | ||
// TODO is this right? | ||
if (parent.type === 'MemberExpression') return parent.computed || node === parent.object; | ||
// disregard the `bar` in { bar: foo } | ||
if (parent.type === 'Property' && node !== parent.value) return false; | ||
// disregard the `bar` in `class Foo { bar () {...} }` | ||
if (parent.type === 'MethodDefinition') return false; | ||
// disregard the `bar` in `export { foo as bar }` | ||
if (parent.type === 'ExportSpecifier' && node !== parent.local) return; | ||
return true; | ||
} | ||
} | ||
@@ -81,3 +97,2 @@ } | ||
} | ||
function inject(options) { | ||
@@ -111,2 +126,4 @@ if (!options) throw new Error('Missing options'); | ||
return { | ||
name: 'inject', | ||
transform: function transform(code, id) { | ||
@@ -147,9 +164,9 @@ if (!filter(id)) return null; | ||
if (keypath in modules && !scope.contains(name) && !imports[name]) { | ||
var module = modules[keypath]; | ||
if (typeof module === 'string') module = [module, 'default']; | ||
var _module = modules[keypath]; | ||
if (typeof _module === 'string') _module = [_module, 'default']; | ||
// prevent module from importing itself | ||
if (module[0] === id) return; | ||
if (_module[0] === id) return; | ||
var hash = keypath + ':' + module[0] + ':' + module[1]; | ||
var hash = keypath + ':' + _module[0] + ':' + _module[1]; | ||
@@ -159,3 +176,3 @@ var importLocalName = name === keypath ? name : makeLegalIdentifier('$inject_' + keypath); | ||
if (!newImports[hash]) { | ||
newImports[hash] = 'import { ' + module[1] + ' as ' + importLocalName + ' } from \'' + module[0] + '\';'; | ||
newImports[hash] = 'import { ' + _module[1] + ' as ' + importLocalName + ' } from \'' + _module[0] + '\';'; | ||
} | ||
@@ -181,4 +198,4 @@ | ||
if (node.type === 'Property' && node.shorthand) { | ||
var name = node.key.name; | ||
handleReference(node, name, name); | ||
var _name = node.key.name; | ||
handleReference(node, _name, _name); | ||
return this.skip(); | ||
@@ -190,6 +207,6 @@ } | ||
var name = _flatten.name; | ||
var _name2 = _flatten.name; | ||
var keypath = _flatten.keypath; | ||
handleReference(node, name, keypath); | ||
handleReference(node, _name2, keypath); | ||
} | ||
@@ -196,0 +213,0 @@ }, |
@@ -14,3 +14,2 @@ import { attachScopes, createFilter } from 'rollup-pluginutils'; | ||
}); | ||
function makeLegalIdentifier(str) { | ||
@@ -30,21 +29,38 @@ str = str.replace(/-(\w)/g, function (_, letter) { | ||
function isReference(node, parent) { | ||
if (node.type === 'MemberExpression') { | ||
return !node.computed && isReference(node.object, node); | ||
} | ||
function isReference(_x, _x2) { | ||
var _left; | ||
if (node.type === 'Identifier') { | ||
// TODO is this right? | ||
if (parent.type === 'MemberExpression') return parent.computed || node === parent.object; | ||
var _again = true; | ||
// disregard the `bar` in { bar: foo } | ||
if (parent.type === 'Property' && node !== parent.value) return false; | ||
_function: while (_again) { | ||
var node = _x, | ||
parent = _x2; | ||
_again = false; | ||
// disregard the `bar` in `class Foo { bar () {...} }` | ||
if (parent.type === 'MethodDefinition') return false; | ||
if (node.type === 'MemberExpression') { | ||
if (!(_left = !node.computed)) { | ||
return _left; | ||
} | ||
// disregard the `bar` in `export { foo as bar }` | ||
if (parent.type === 'ExportSpecifier' && node !== parent.local) return; | ||
_x = node.object; | ||
_x2 = node; | ||
_again = true; | ||
continue _function; | ||
} | ||
return true; | ||
if (node.type === 'Identifier') { | ||
// TODO is this right? | ||
if (parent.type === 'MemberExpression') return parent.computed || node === parent.object; | ||
// disregard the `bar` in { bar: foo } | ||
if (parent.type === 'Property' && node !== parent.value) return false; | ||
// disregard the `bar` in `class Foo { bar () {...} }` | ||
if (parent.type === 'MethodDefinition') return false; | ||
// disregard the `bar` in `export { foo as bar }` | ||
if (parent.type === 'ExportSpecifier' && node !== parent.local) return; | ||
return true; | ||
} | ||
} | ||
@@ -78,3 +94,2 @@ } | ||
} | ||
function inject(options) { | ||
@@ -108,2 +123,4 @@ if (!options) throw new Error('Missing options'); | ||
return { | ||
name: 'inject', | ||
transform: function transform(code, id) { | ||
@@ -144,9 +161,9 @@ if (!filter(id)) return null; | ||
if (keypath in modules && !scope.contains(name) && !imports[name]) { | ||
var module = modules[keypath]; | ||
if (typeof module === 'string') module = [module, 'default']; | ||
var _module = modules[keypath]; | ||
if (typeof _module === 'string') _module = [_module, 'default']; | ||
// prevent module from importing itself | ||
if (module[0] === id) return; | ||
if (_module[0] === id) return; | ||
var hash = keypath + ':' + module[0] + ':' + module[1]; | ||
var hash = keypath + ':' + _module[0] + ':' + _module[1]; | ||
@@ -156,3 +173,3 @@ var importLocalName = name === keypath ? name : makeLegalIdentifier('$inject_' + keypath); | ||
if (!newImports[hash]) { | ||
newImports[hash] = 'import { ' + module[1] + ' as ' + importLocalName + ' } from \'' + module[0] + '\';'; | ||
newImports[hash] = 'import { ' + _module[1] + ' as ' + importLocalName + ' } from \'' + _module[0] + '\';'; | ||
} | ||
@@ -178,4 +195,4 @@ | ||
if (node.type === 'Property' && node.shorthand) { | ||
var name = node.key.name; | ||
handleReference(node, name, name); | ||
var _name = node.key.name; | ||
handleReference(node, _name, _name); | ||
return this.skip(); | ||
@@ -187,6 +204,6 @@ } | ||
var name = _flatten.name; | ||
var _name2 = _flatten.name; | ||
var keypath = _flatten.keypath; | ||
handleReference(node, name, keypath); | ||
handleReference(node, _name2, keypath); | ||
} | ||
@@ -193,0 +210,0 @@ }, |
{ | ||
"name": "rollup-plugin-inject", | ||
"description": "Scan modules for global variables and inject `import` statements where necessary", | ||
"version": "1.4.0", | ||
"version": "1.4.1", | ||
"devDependencies": { | ||
"babel-preset-es2015-rollup": "^1.0.0", | ||
"eslint": "^1.7.3", | ||
"mocha": "^2.3.3", | ||
"rollup": "^0.22.0", | ||
"rollup-plugin-babel": "^2.2.0" | ||
"rollup-plugin-buble": "^0.12.1" | ||
}, | ||
@@ -12,0 +11,0 @@ "main": "dist/rollup-plugin-inject.cjs.js", |
@@ -90,2 +90,4 @@ import { attachScopes, createFilter } from 'rollup-pluginutils'; | ||
return { | ||
name: 'inject', | ||
transform ( code, id ) { | ||
@@ -92,0 +94,0 @@ if ( !filter( id ) ) return null; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4
508
20737
6
1
0