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

babel-plugin-filter-imports

Package Overview
Dependencies
Maintainers
4
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 1.0.4 to 1.1.0

lib/removeExportSpecifier.js

13

CHANGELOG.md
# Change Log
## [v1.0.4](https://github.com/ember-cli/babel-plugin-filter-imports/tree/v1.0.4) (2017-09-27)
[Full Changelog](https://github.com/ember-cli/babel-plugin-filter-imports/compare/v1.0.3...v1.0.4)
**Closed issues:**
- Cannot find module package.json [\#19](https://github.com/ember-cli/babel-plugin-filter-imports/issues/19)
**Merged pull requests:**
- chore\(package\): update deps, switch to babel-preset-env [\#21](https://github.com/ember-cli/babel-plugin-filter-imports/pull/21) ([layershifter](https://github.com/layershifter))
- fix\(plugin\): restore CommonJS export [\#20](https://github.com/ember-cli/babel-plugin-filter-imports/pull/20) ([layershifter](https://github.com/layershifter))
- chore\(package\): update babel-eslint to the latest version [\#18](https://github.com/ember-cli/babel-plugin-filter-imports/pull/18) ([greenkeeper[bot]](https://github.com/apps/greenkeeper))
## [v1.0.3](https://github.com/ember-cli/babel-plugin-filter-imports/tree/v1.0.3) (2017-09-08)

@@ -4,0 +17,0 @@ [Full Changelog](https://github.com/ember-cli/babel-plugin-filter-imports/compare/v1.0.2...v1.0.3)

@@ -25,2 +25,7 @@ 'use strict';

return {
manipulateOptions: function manipulateOptions(opts, parserOptions) {
parserOptions.plugins.push('decorators');
parserOptions.plugins.push('exportExtensions');
},
visitor: {

@@ -57,2 +62,18 @@ ImportDeclaration: function ImportDeclaration(path, _ref) {

_lodash2.default.set(path, 'node.specifiers', _lodash2.default.without.apply(_lodash2.default, [specifiers].concat(_toConsumableArray(specifiersForRemoval))));
},
ExportNamedDeclaration: function ExportNamedDeclaration(path, _ref2) {
var opts = _ref2.opts;
var declaration = _lodash2.default.get(path, 'node.declaration');
// Heads up! Exports that have decrations will be handled
// by the ImportDeclaration visitor
if (declaration) return;
var imports = opts.imports;
var source = _lodash2.default.get(path, 'node.source.value');
if (_lodash2.default.has(imports, source)) path.remove();
}

@@ -59,0 +80,0 @@ }

2

lib/isRemovablePath.js

@@ -14,5 +14,5 @@ 'use strict';

var isRemovablePath = function isRemovablePath(path) {
return t.isArrowFunctionExpression(path) || t.isExpressionStatement(path) || t.isReturnStatement(path) || t.isVariableDeclarator(path);
return t.isArrowFunctionExpression(path) || t.isDecorator(path) || t.isExpressionStatement(path) || t.isExportSpecifier(path) || t.isReturnStatement(path) || t.isVariableDeclarator(path);
};
exports.default = isRemovablePath;

@@ -19,2 +19,6 @@ 'use strict';

var _removeExportSpecifier = require('./removeExportSpecifier');
var _removeExportSpecifier2 = _interopRequireDefault(_removeExportSpecifier);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -25,2 +29,4 @@

var removeReferences = function removeReferences(path, specifier) {
if (!path.scope.getBinding(specifier)) return;
var _path$scope$getBindin = path.scope.getBinding(specifier),

@@ -32,2 +38,3 @@ referencePaths = _path$scope$getBindin.referencePaths;

if (parent.removed) return;
if (t.isArrowFunctionExpression(parent)) {

@@ -37,2 +44,6 @@ parent.get('body').remove();

}
if (t.isExportSpecifier(parent)) {
(0, _removeExportSpecifier2.default)(parent);
return;
}
if (t.isVariableDeclarator(parent)) removeReferences(parent, _lodash2.default.get(parent, 'node.id.name'));

@@ -39,0 +50,0 @@ parent.remove();

{
"name": "babel-plugin-filter-imports",
"version": "1.0.4",
"version": "1.1.0",
"description": "A babel transform for filtering out imports",

@@ -15,4 +15,4 @@ "main": "lib/index.js",

"lint:fix": "prettier --write \"src/**/*.js\" \"test/test.js\" && eslint --fix \"src/**/*.js\" \"test/test.js\"",
"test": "mocha --compilers js:babel-register",
"test:watch": "npm run test -- --watch"
"test": "mocha --require babel-register \"test/*.js\"",
"test:watch": "npm run test -- --watch --watch-extensions js"
},

@@ -43,9 +43,9 @@ "repository": {

"babel-register": "^6.26.0",
"eslint": "^4.6.1",
"eslint": "^4.8.0",
"eslint-config-prettier": "^2.6.0",
"eslint-plugin-prettier": "^2.3.1",
"mocha": "^3.5.3",
"prettier": "^1.7.0",
"mocha": "^4.0.1",
"prettier": "^1.7.4",
"rimraf": "^2.6.2"
}
}

@@ -8,2 +8,7 @@ import _ from 'lodash'

module.exports = () => ({
manipulateOptions: (opts, parserOptions) => {
parserOptions.plugins.push('decorators')
parserOptions.plugins.push('exportExtensions')
},
visitor: {

@@ -33,2 +38,15 @@ ImportDeclaration: (path, { opts }) => {

},
ExportNamedDeclaration: (path, { opts }) => {
const declaration = _.get(path, 'node.declaration')
// Heads up! Exports that have decrations will be handled
// by the ImportDeclaration visitor
if (declaration) return
const { imports } = opts
const source = _.get(path, 'node.source.value')
if (_.has(imports, source)) path.remove()
},
},

@@ -35,0 +53,0 @@ })

@@ -5,3 +5,5 @@ import * as t from 'babel-types'

t.isArrowFunctionExpression(path) ||
t.isDecorator(path) ||
t.isExpressionStatement(path) ||
t.isExportSpecifier(path) ||
t.isReturnStatement(path) ||

@@ -8,0 +10,0 @@ t.isVariableDeclarator(path)

@@ -5,4 +5,6 @@ import * as t from 'babel-types'

import isRemovablePath from './isRemovablePath'
import removeExportSpecifier from './removeExportSpecifier'
const removeReferences = (path, specifier) => {
if (!path.scope.getBinding(specifier)) return
const { referencePaths } = path.scope.getBinding(specifier)

@@ -13,2 +15,3 @@

if (parent.removed) return
if (t.isArrowFunctionExpression(parent)) {

@@ -18,2 +21,6 @@ parent.get('body').remove()

}
if (t.isExportSpecifier(parent)) {
removeExportSpecifier(parent)
return
}
if (t.isVariableDeclarator(parent)) removeReferences(parent, _.get(parent, 'node.id.name'))

@@ -20,0 +27,0 @@ parent.remove()

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