babel-plugin-transform-remove-imports
Advanced tools
Comparing version 1.7.0 to 1.7.1
@@ -7,3 +7,2 @@ "use strict"; | ||
exports["default"] = _default; | ||
function _default() { | ||
@@ -16,22 +15,18 @@ return { | ||
var node = path.node; | ||
if (node.callee.name !== 'require') { | ||
return; | ||
} | ||
var argument = node.arguments[0]; | ||
var moduleId = argument.value; | ||
var options = state.opts; | ||
if (options.test && !testMatches(moduleId, options.test)) { | ||
return; | ||
} | ||
var parentType = path.parentPath.node.type; | ||
var parentType = path.parentPath.node.type; // In remove effects mode we should delete only requires that are | ||
// In remove effects mode we should delete only requires that are | ||
// simple expression statements | ||
if (options.remove === 'effects' && parentType !== 'ExpressionStatement') { | ||
return; | ||
} | ||
path.remove(); | ||
@@ -44,3 +39,2 @@ }, | ||
var opts = state.opts; | ||
if (opts.removeAll) { | ||
@@ -50,3 +44,2 @@ path.remove(); | ||
} | ||
if (!opts.test) { | ||
@@ -56,8 +49,8 @@ console.warn('transform-remove-imports: "test" option should be specified'); | ||
} | ||
/** @var {string} importName */ | ||
var importName = source && source.value ? source.value : undefined; | ||
var isMatch = testMatches(importName, opts.test); // https://github.com/uiwjs/babel-plugin-transform-remove-imports/issues/3 | ||
var isMatch = testMatches(importName, opts.test); | ||
// https://github.com/uiwjs/babel-plugin-transform-remove-imports/issues/3 | ||
if (opts.remove === 'effects') { | ||
@@ -67,6 +60,4 @@ if (node.specifiers && node.specifiers.length === 0 && importName && isMatch) { | ||
} | ||
return; | ||
} | ||
if (importName && isMatch) { | ||
@@ -79,2 +70,3 @@ path.remove(); | ||
} | ||
/** | ||
@@ -87,8 +79,7 @@ * Determines if the import matches the specified tests. | ||
*/ | ||
function testMatches(importName, test) { | ||
// Normalizing tests | ||
var tests = Array.isArray(test) ? test : [test]; // Finding out if at least one test matches | ||
var tests = Array.isArray(test) ? test : [test]; | ||
// Finding out if at least one test matches | ||
return tests.some(function (regex) { | ||
@@ -98,5 +89,4 @@ if (typeof regex === 'string') { | ||
} | ||
return regex.test(importName || ''); | ||
}); | ||
} |
{ | ||
"name": "babel-plugin-transform-remove-imports", | ||
"version": "1.7.0", | ||
"version": "1.7.1", | ||
"description": "Remove the specified import declaration when you use the babel transform to build the package.", | ||
"repository": "https://github.com/uiwjs/babel-plugin-transform-remove-imports", | ||
"homepage": "https://uiwjs.github.io/babel-plugin-transform-remove-imports/", | ||
"typings": "./index.d.ts", | ||
@@ -40,11 +41,11 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@babel/cli": "7.15.7", | ||
"@babel/core": "7.15.5", | ||
"@babel/plugin-proposal-class-properties": "7.14.5", | ||
"@babel/plugin-proposal-do-expressions": "7.14.5", | ||
"@babel/plugin-proposal-export-default-from": "7.14.5", | ||
"@babel/preset-env": "7.15.6", | ||
"@babel/preset-react": "7.14.5", | ||
"@babel/cli": "7.23.0", | ||
"@babel/core": "7.23.3", | ||
"@babel/plugin-proposal-class-properties": "7.18.6", | ||
"@babel/plugin-proposal-do-expressions": "7.23.3", | ||
"@babel/plugin-proposal-export-default-from": "7.23.3", | ||
"@babel/preset-env": "7.23.3", | ||
"@babel/preset-react": "7.23.3", | ||
"babel-core": "7.0.0-bridge.0", | ||
"jest": "27.2.0" | ||
"jest": "29.7.0" | ||
}, | ||
@@ -51,0 +52,0 @@ "files": [ |
babel-plugin-transform-remove-imports | ||
=== | ||
<!--rehype:style=display: flex; height: 230px; align-items: center; justify-content: center; font-size: 38px;--> | ||
[![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/badge.svg)](https://github.com/uiwjs/babel-plugin-transform-remove-imports/actions) | ||
[![CI](https://github.com/uiwjs/babel-plugin-transform-remove-imports/actions/workflows/ci.yml/badge.svg)](https://github.com/uiwjs/babel-plugin-transform-remove-imports/actions/workflows/ci.yml) | ||
[![Coverage Status](https://uiwjs.github.io/babel-plugin-transform-remove-imports/badges.svg)](https://uiwjs.github.io/babel-plugin-transform-remove-imports/lcov-report) | ||
[![Downloadss](https://img.shields.io/npm/dm/babel-plugin-transform-remove-imports.svg?style=flat)](https://npmjs.org/package/babel-plugin-transform-remove-imports) | ||
[![Repo Dependents](https://badgen.net/github/dependents-repo/jaywcjlove/babel-plugin-transform-remove-imports)](https://github.com/jaywcjlove/babel-plugin-transform-remove-imports/network/dependents) | ||
@@ -129,4 +131,14 @@ Modular import plugin for babel for server-side rendering. Also works for cjs to delete imported CSS to avoid compilation errors.. | ||
## Contributors | ||
As always, thanks to our amazing contributors! | ||
<a href="https://github.com/uiwjs/babel-plugin-transform-remove-imports/graphs/contributors"> | ||
<img src="https://uiwjs.github.io/babel-plugin-transform-remove-imports/CONTRIBUTORS.svg" /> | ||
</a> | ||
Made with [github-action-contributors](https://github.com/jaywcjlove/github-action-contributors). | ||
## License | ||
[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
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
8976
81
0
144