babel-plugin-filter-imports
Advanced tools
Comparing version 0.2.1 to 0.3.0
55
index.js
@@ -1,27 +0,18 @@ | ||
var stringify = require('json-stable-stringify'); | ||
module.exports = function(filteredImports) { | ||
function babelPluginFilterImports(babel) { | ||
// A stack of booleans that determine whether an expression statement | ||
// should be removed as it is exited. Expression statements are removed | ||
// when they contain a reference to a filtered imported. | ||
var shouldRemove; | ||
return new babel.Transformer('babel-plugin-filter-imports', { | ||
Program: { | ||
enter: function() { | ||
shouldRemove = []; | ||
}, | ||
exit: function() { | ||
shouldRemove = undefined; | ||
} | ||
module.exports = function(babel) { | ||
return { | ||
visitor: { | ||
Program: function(path, state) { | ||
// A stack of booleans that determine whether an expression statement | ||
// should be removed as it is exited. Expression statements are removed | ||
// when they contain a reference to a filtered imported. | ||
state.shouldRemove = []; | ||
}, | ||
ExpressionStatement: { | ||
enter: function() { | ||
shouldRemove.push(false); | ||
enter: function(path, state) { | ||
state.shouldRemove.push(false); | ||
}, | ||
exit: function() { | ||
if (shouldRemove.pop()) { | ||
this.dangerouslyRemove(); | ||
exit: function(path, state) { | ||
if (state.shouldRemove.pop()) { | ||
path.remove(); | ||
} | ||
@@ -31,22 +22,12 @@ } | ||
Identifier: function() { | ||
Identifier: function(path, state) { | ||
// Ensure that we're inside of an expression statement. | ||
if (shouldRemove.length > 0) { | ||
if (referencesFilteredImport(this, filteredImports)) { | ||
shouldRemove[shouldRemove.length - 1] = true; | ||
if (state.shouldRemove.length > 0) { | ||
if (referencesFilteredImport(path, state.opts)) { | ||
state.shouldRemove[state.shouldRemove.length - 1] = true; | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
}; | ||
babelPluginFilterImports.baseDir = function() { | ||
return __dirname; | ||
}; | ||
babelPluginFilterImports.cacheKey = function() { | ||
return stringify(filteredImports); | ||
}; | ||
return babelPluginFilterImports; | ||
}; | ||
@@ -53,0 +34,0 @@ |
{ | ||
"name": "babel-plugin-filter-imports", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "A babel transform for filtering out imports", | ||
"main": "index.js", | ||
"files": [ | ||
"index.js" | ||
], | ||
"scripts": { | ||
@@ -24,8 +27,5 @@ "test": "mocha" | ||
"devDependencies": { | ||
"babel-core": "^5.5.3", | ||
"mocha": "^2.2.5" | ||
}, | ||
"dependencies": { | ||
"json-stable-stringify": "^1.0.1" | ||
"babel-core": "^6.9.1", | ||
"mocha": "^3.0.0" | ||
} | ||
} |
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
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
0
0
0
1983
2
41
- Removedjson-stable-stringify@^1.0.1
- Removedcall-bind@1.0.7(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removedes-define-property@1.0.0(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.4(transitive)
- Removedgopd@1.0.1(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-proto@1.0.3(transitive)
- Removedhas-symbols@1.0.3(transitive)
- Removedhasown@2.0.2(transitive)
- Removedisarray@2.0.5(transitive)
- Removedjson-stable-stringify@1.1.1(transitive)
- Removedjsonify@0.0.1(transitive)
- Removedobject-keys@1.1.1(transitive)
- Removedset-function-length@1.2.2(transitive)