babel-plugin-transform-remove-imports
Advanced tools
Comparing version 1.4.1 to 1.5.0
@@ -10,4 +10,29 @@ "use strict"; | ||
return { | ||
name: "transform-remove-imports", | ||
name: 'transform-remove-imports', | ||
visitor: { | ||
// https://babeljs.io/docs/en/babel-types#callexpression | ||
CallExpression: function CallExpression(path, state) { | ||
var node = path.node; | ||
if (node.arguments.length !== 1) { | ||
return; | ||
} | ||
var argument = node.arguments[0]; | ||
var moduleId = argument.value; | ||
var options = state.opts || {}; | ||
if (!testMatches(moduleId, options.test)) { | ||
return; | ||
} | ||
var parentType = path.parentPath.node.type; // In remove effects mode we should delete only requires that are | ||
// simple expression statements | ||
if (options.remove === 'effects' && parentType !== 'ExpressionStatement') { | ||
return; | ||
} | ||
path.remove(); | ||
}, | ||
// https://babeljs.io/docs/en/babel-types#importdeclaration | ||
@@ -26,3 +51,3 @@ ImportDeclaration: function ImportDeclaration(path, state) { | ||
if (!opts.test) { | ||
console.warn("transform-remove-imports: \"test\" option should be specified"); | ||
console.warn('transform-remove-imports: "test" option should be specified'); | ||
return; | ||
@@ -65,3 +90,3 @@ } | ||
return tests.some(function (regex) { | ||
if (typeof regex === "string") { | ||
if (typeof regex === 'string') { | ||
regex = new RegExp(regex); | ||
@@ -68,0 +93,0 @@ } |
{ | ||
"name": "babel-plugin-transform-remove-imports", | ||
"version": "1.4.1", | ||
"version": "1.5.0", | ||
"description": "Remove the specified import declaration when you use the babel transform to build the package.", | ||
@@ -20,8 +20,10 @@ "repository": "https://github.com/uiwjs/babel-plugin-transform-remove-imports", | ||
], | ||
"jset": { | ||
"jest": { | ||
"bail": true, | ||
"verbose": true, | ||
"coveragePathIgnorePatterns": [ | ||
"/test/new-fixtures" | ||
], | ||
"testMatch": [ | ||
"**/__tests__/**/*.js?(x)", | ||
"**/?(*.)+(spec|test).js?(x)" | ||
"**/*.(spec|test).js?(x)" | ||
] | ||
@@ -34,9 +36,9 @@ }, | ||
"devDependencies": { | ||
"@babel/cli": "7.10.3", | ||
"@babel/core": "7.10.3", | ||
"@babel/plugin-proposal-class-properties": "7.10.1", | ||
"@babel/plugin-proposal-do-expressions": "7.10.1", | ||
"@babel/plugin-proposal-export-default-from": "7.10.1", | ||
"@babel/preset-env": "7.10.3", | ||
"@babel/preset-react": "7.10.1", | ||
"@babel/cli": "7.10.4", | ||
"@babel/core": "7.10.4", | ||
"@babel/plugin-proposal-class-properties": "7.10.4", | ||
"@babel/plugin-proposal-do-expressions": "7.10.4", | ||
"@babel/plugin-proposal-export-default-from": "7.10.4", | ||
"@babel/preset-env": "7.10.4", | ||
"@babel/preset-react": "7.10.4", | ||
"babel-core": "7.0.0-bridge.0", | ||
@@ -50,3 +52,6 @@ "jest": "26.0.1" | ||
"author": "Kenny Wong", | ||
"contributors": [ | ||
"Slava Fomin II <slava@fomin.io>" | ||
], | ||
"license": "MIT" | ||
} |
@@ -5,2 +5,3 @@ babel-plugin-transform-remove-imports | ||
[![NPM version](https://img.shields.io/npm/v/babel-plugin-transform-remove-imports.svg?style=flat)](https://npmjs.org/package/babel-plugin-transform-remove-imports) | ||
[![Build and Test](https://github.com/uiwjs/babel-plugin-transform-remove-imports/workflows/Build%20and%20Test%20babel-plugin-transform-remove-imports/badge.svg)](https://github.com/uiwjs/babel-plugin-transform-remove-imports/actions) | ||
[![Build Status](https://img.shields.io/travis/uiwjs/babel-plugin-transform-remove-imports.svg?style=flat)](https://travis-ci.org/uiwjs/babel-plugin-transform-remove-imports) | ||
@@ -52,2 +53,38 @@ [![Coverage Status](https://coveralls.io/repos/github/uiwjs/babel-plugin-transform-remove-imports/badge.svg?branch=master)](https://coveralls.io/github/uiwjs/babel-plugin-transform-remove-imports?branch=master) | ||
#### support `require` | ||
Via `.babelrc` or `babel-loader`. | ||
```json | ||
{ | ||
"plugins": [ | ||
[ | ||
"babel-plugin-transform-remove-imports", { | ||
"test": "@babel/core", | ||
} | ||
] | ||
] | ||
} | ||
``` | ||
```js | ||
// Input Code | ||
const core = require('@babel/core'); | ||
useCore(require('@babel/core')); | ||
require('@babel/core'); | ||
require('jest'); | ||
// Output ↓ ↓ ↓ ↓ ↓ ↓ | ||
require('jest'); | ||
``` | ||
Output Result | ||
```diff | ||
- const core = require('@babel/core'); | ||
- useCore(require('@babel/core')); | ||
- require('@babel/core'); | ||
require('jest'); | ||
``` | ||
## Options | ||
@@ -99,2 +136,2 @@ | ||
MIT © [`Kenny Wong`](https://github.com/jaywcjlove) | ||
[MIT](./LICENSE) © [`Kenny Wong`](https://github.com/jaywcjlove) & [`Slava Fomin II`](https://github.com/slavafomin) |
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
8348
5
79
135