babel-plugin-transform-react-remove-prop-types
Advanced tools
Comparing version 0.4.0 to 0.4.1
@@ -27,3 +27,4 @@ 'use strict'; | ||
ignoreFilenames: ignoreFilenames, | ||
types: types | ||
types: types, | ||
removeImport: state.opts.removeImport || false | ||
}; | ||
@@ -104,2 +105,31 @@ | ||
}); | ||
if (globalOptions.removeImport && globalOptions.mode === 'remove') { | ||
programPath.scope.crawl(); | ||
programPath.traverse({ | ||
ImportDeclaration: function ImportDeclaration(path) { | ||
var _path$node = path.node, | ||
source = _path$node.source, | ||
specifiers = _path$node.specifiers; | ||
if (source.value !== 'prop-types') { | ||
return; | ||
} | ||
var haveUsedSpecifiers = specifiers.some(function (specifier) { | ||
var importedIdentifierName = specifier.local.name; | ||
var _path$scope$getBindin = path.scope.getBinding(importedIdentifierName), | ||
referencePaths = _path$scope$getBindin.referencePaths; | ||
return referencePaths.length > 0; | ||
}); | ||
if (!haveUsedSpecifiers) { | ||
path.remove(); | ||
} | ||
path.stop(); | ||
} | ||
}); | ||
} | ||
} | ||
@@ -106,0 +136,0 @@ } |
{ | ||
"name": "babel-plugin-transform-react-remove-prop-types", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "Remove unnecessary React propTypes from the production build", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -20,3 +20,2 @@ # babel-plugin-transform-react-remove-prop-types | ||
Remove React `propTypes` from the production build, as they are only used in development. | ||
@@ -113,2 +112,3 @@ You can **save bandwidth** by removing them. | ||
### `mode` | ||
- `remove` (default): | ||
@@ -127,3 +127,10 @@ the `propTypes` definitions are removed from the source code. | ||
### `removeImport` | ||
- `true`: the import statements are removed as well. This option only works if `mode` is set to `remove`: | ||
```js | ||
import PropTypes from 'prop-types' | ||
``` | ||
- `false` (default): does not remove the import statements. | ||
### `ignoreFilenames` | ||
@@ -133,3 +140,3 @@ | ||
Any filenames containing one of the array's strings will be ignored. | ||
By default, we match everything. | ||
By **default**, we match everything. | ||
@@ -144,3 +151,2 @@ Following the [Is it safe?](#user-content-is-it-safe) section, you might encounter a component | ||
## Is it safe? | ||
@@ -147,0 +153,0 @@ |
@@ -69,2 +69,3 @@ // @flow weak | ||
types, | ||
removeImport: state.opts.removeImport || false, | ||
}; | ||
@@ -147,2 +148,25 @@ | ||
}); | ||
if (globalOptions.removeImport && globalOptions.mode === 'remove') { | ||
programPath.scope.crawl(); | ||
programPath.traverse({ | ||
ImportDeclaration(path) { | ||
const { source, specifiers } = path.node; | ||
if (source.value !== 'prop-types') { | ||
return; | ||
} | ||
const haveUsedSpecifiers = specifiers.some((specifier) => { | ||
const importedIdentifierName = specifier.local.name; | ||
const { referencePaths } = path.scope.getBinding(importedIdentifierName); | ||
return referencePaths.length > 0; | ||
}); | ||
if (!haveUsedSpecifiers) { | ||
path.remove(); | ||
} | ||
path.stop(); | ||
}, | ||
}); | ||
} | ||
}, | ||
@@ -149,0 +173,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
26313
578
170