Socket
Socket
Sign inDemoInstall

babel-plugin-filter-imports

Package Overview
Dependencies
Maintainers
3
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-filter-imports - npm Package Compare versions

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"
}
}
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