babel-plugin-transform-react-remove-prop-types
Advanced tools
Comparing version 0.4.12 to 0.4.13
@@ -18,3 +18,6 @@ "use strict"; | ||
function isPathReactClass(path) { | ||
function isPathReactClass(path, globalOptions) { | ||
var node = path.node; | ||
var matchers = globalOptions.classNameMatchers; | ||
if (path.matchesPattern('React.Component') || path.matchesPattern('React.PureComponent')) { | ||
@@ -24,4 +27,2 @@ return true; | ||
var node = path.node; | ||
if (node && (node.name === 'Component' || node.name === 'PureComponent')) { | ||
@@ -31,6 +32,10 @@ return true; | ||
if (node && matchers && node.name.match(matchers)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
function isReactClass(superClass, scope) { | ||
function isReactClass(superClass, scope, globalOptions) { | ||
if (!superClass.node) { | ||
@@ -42,3 +47,3 @@ return false; | ||
if (isPathReactClass(superClass)) { | ||
if (isPathReactClass(superClass, globalOptions)) { | ||
answer = true; | ||
@@ -55,3 +60,3 @@ } else if (superClass.node.name) { | ||
if (isPathReactClass(bindingSuperClass)) { | ||
if (isPathReactClass(bindingSuperClass, globalOptions)) { | ||
answer = true; | ||
@@ -73,2 +78,3 @@ } | ||
var ignoreFilenames; | ||
var classNameMatchers; | ||
@@ -81,2 +87,8 @@ if (state.opts.ignoreFilenames) { | ||
if (state.opts.classNameMatchers) { | ||
classNameMatchers = new RegExp(state.opts.classNameMatchers.join('|'), 'g'); | ||
} else { | ||
classNameMatchers = undefined; | ||
} | ||
var globalOptions = { | ||
@@ -94,3 +106,4 @@ visitedKey: "transform-react-remove-prop-types".concat(Date.now()), | ||
removeImport: state.opts.removeImport || false, | ||
libraries: (state.opts.additionalLibraries || []).concat('prop-types') | ||
libraries: (state.opts.additionalLibraries || []).concat('prop-types'), | ||
classNameMatchers: classNameMatchers | ||
}; | ||
@@ -154,3 +167,3 @@ | ||
if (isReactClass(pathClassDeclaration.get('superClass'), scope)) { | ||
if (isReactClass(pathClassDeclaration.get('superClass'), scope, globalOptions)) { | ||
(0, _remove.default)(path, globalOptions, { | ||
@@ -190,3 +203,3 @@ type: 'class static', | ||
if (isReactClass(superClass, scope)) { | ||
if (isReactClass(superClass, scope, globalOptions)) { | ||
(0, _remove.default)(path, globalOptions, { | ||
@@ -193,0 +206,0 @@ type: 'assign' |
{ | ||
"name": "babel-plugin-transform-react-remove-prop-types", | ||
"version": "0.4.12", | ||
"version": "0.4.13", | ||
"description": "Remove unnecessary React propTypes from the production build", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -5,8 +5,8 @@ # babel-plugin-transform-react-remove-prop-types | ||
[![npm version](https://img.shields.io/npm/v/babel-plugin-transform-react-remove-prop-types.svg?style=flat-square)](https://www.npmjs.com/package/babel-plugin-transform-react-remove-prop-types) | ||
[![npm downloads](https://img.shields.io/npm/dm/babel-plugin-transform-react-remove-prop-types.svg?style=flat-square)](https://www.npmjs.com/package/babel-plugin-transform-react-remove-prop-types) | ||
[![npm version](https://img.shields.io/npm/v/babel-plugin-transform-react-remove-prop-types.svg)](https://www.npmjs.com/package/babel-plugin-transform-react-remove-prop-types) | ||
[![npm downloads](https://img.shields.io/npm/dm/babel-plugin-transform-react-remove-prop-types.svg)](https://www.npmjs.com/package/babel-plugin-transform-react-remove-prop-types) | ||
[![Build Status](https://travis-ci.org/oliviertassinari/babel-plugin-transform-react-remove-prop-types.svg?branch=master)](https://travis-ci.org/oliviertassinari/babel-plugin-transform-react-remove-prop-types) | ||
[![Dependencies](https://img.shields.io/david/oliviertassinari/babel-plugin-transform-react-remove-prop-types.svg?style=flat-square)](https://david-dm.org/oliviertassinari/babel-plugin-transform-react-remove-prop-types) | ||
[![DevDependencies](https://img.shields.io/david/dev/oliviertassinari/babel-plugin-transform-react-remove-prop-types.svg?style=flat-square)](https://david-dm.org/oliviertassinari/babel-plugin-transform-react-remove-prop-types#info=devDependencies&view=list) | ||
[![Dependencies](https://img.shields.io/david/oliviertassinari/babel-plugin-transform-react-remove-prop-types.svg)](https://david-dm.org/oliviertassinari/babel-plugin-transform-react-remove-prop-types) | ||
[![DevDependencies](https://img.shields.io/david/dev/oliviertassinari/babel-plugin-transform-react-remove-prop-types.svg)](https://david-dm.org/oliviertassinari/babel-plugin-transform-react-remove-prop-types#info=devDependencies&view=list) | ||
@@ -184,3 +184,18 @@ ## Installation | ||
### `classNameMatchers` | ||
Use this option to enable this plugin to run on components that extend a class different than `React.Component` or `React.PureComponent`. | ||
Given this example: | ||
```js | ||
class MyComponent extends BaseComponent { | ||
... | ||
} | ||
``` | ||
You would use: | ||
```js | ||
classNameMatchers: ["BaseComponent"] | ||
``` | ||
## Is it safe? | ||
@@ -187,0 +202,0 @@ |
@@ -10,3 +10,6 @@ // @flow weak | ||
function isPathReactClass(path) { | ||
function isPathReactClass(path, globalOptions) { | ||
const node = path.node | ||
const matchers = globalOptions.classNameMatchers | ||
if (path.matchesPattern('React.Component') || path.matchesPattern('React.PureComponent')) { | ||
@@ -16,4 +19,2 @@ return true | ||
const node = path.node | ||
if (node && (node.name === 'Component' || node.name === 'PureComponent')) { | ||
@@ -23,6 +24,10 @@ return true | ||
if (node && matchers && node.name.match(matchers)) { | ||
return true | ||
} | ||
return false | ||
} | ||
function isReactClass(superClass, scope) { | ||
function isReactClass(superClass, scope, globalOptions) { | ||
if (!superClass.node) { | ||
@@ -34,3 +39,3 @@ return false | ||
if (isPathReactClass(superClass)) { | ||
if (isPathReactClass(superClass, globalOptions)) { | ||
answer = true | ||
@@ -46,3 +51,3 @@ } else if (superClass.node.name) { | ||
if (isPathReactClass(bindingSuperClass)) { | ||
if (isPathReactClass(bindingSuperClass, globalOptions)) { | ||
answer = true | ||
@@ -61,2 +66,3 @@ } | ||
let ignoreFilenames | ||
let classNameMatchers | ||
@@ -69,2 +75,8 @@ if (state.opts.ignoreFilenames) { | ||
if (state.opts.classNameMatchers) { | ||
classNameMatchers = new RegExp(state.opts.classNameMatchers.join('|'), 'g') | ||
} else { | ||
classNameMatchers = undefined | ||
} | ||
const globalOptions = { | ||
@@ -91,2 +103,3 @@ visitedKey: `transform-react-remove-prop-types${Date.now()}`, | ||
libraries: (state.opts.additionalLibraries || []).concat('prop-types'), | ||
classNameMatchers, | ||
} | ||
@@ -155,3 +168,3 @@ | ||
if (isReactClass(pathClassDeclaration.get('superClass'), scope)) { | ||
if (isReactClass(pathClassDeclaration.get('superClass'), scope, globalOptions)) { | ||
remove(path, globalOptions, { | ||
@@ -192,3 +205,3 @@ type: 'class static', | ||
if (isReactClass(superClass, scope)) { | ||
if (isReactClass(superClass, scope, globalOptions)) { | ||
remove(path, globalOptions, { type: 'assign' }) | ||
@@ -195,0 +208,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
38874
17
826
222