babel-plugin-transform-react-remove-prop-types
Advanced tools
Comparing version 0.4.15 to 0.4.16
@@ -32,3 +32,3 @@ "use strict"; | ||
if (node && matchers && node.name.match(matchers)) { | ||
if (node && matchers && matchers.test(node.name)) { | ||
return true; | ||
@@ -82,2 +82,33 @@ } | ||
function memberExpressionRootIdentifier(path) { | ||
// Traverse up to the parent before the topmost member expression, and then | ||
// traverse back down to find the topmost identifier. It seems like there | ||
// might be a better way to do this. | ||
var parent = path.findParent(function (p) { | ||
return !p.isMemberExpression(); | ||
}); | ||
var type = parent.node.type; | ||
var memberExpression; | ||
if (type === 'ObjectProperty') { | ||
// The topmost MemberExpression's parent is an object property, so the | ||
// topmost MemberExpression should be the value. | ||
memberExpression = parent.get('value'); | ||
} | ||
if (!memberExpression) { | ||
// This case is currently unhandled by this plugin. | ||
return null; | ||
} // We have a topmost MemberExpression now, so we want to traverse down the | ||
// left half untli we no longer see MemberExpressions. This node will give us | ||
// our leftmost identifier. | ||
while (memberExpression.node.object.type === 'MemberExpression') { | ||
memberExpression = memberExpression.get('object'); | ||
} | ||
return memberExpression.get('object'); | ||
} | ||
function _default(api) { | ||
@@ -88,3 +119,3 @@ var template = api.template, | ||
var nestedIdentifiers = new Set(); | ||
var removedPaths = new Set(); | ||
var removedPaths = new WeakSet(); | ||
var collectNestedIdentifiers = { | ||
@@ -94,2 +125,8 @@ Identifier: function Identifier(path) { | ||
// foo.bar | ||
var root = memberExpressionRootIdentifier(path); | ||
if (root) { | ||
nestedIdentifiers.add(root.node.name); | ||
} | ||
return; | ||
@@ -114,3 +151,3 @@ } | ||
if (state.opts.ignoreFilenames) { | ||
ignoreFilenames = new RegExp(state.opts.ignoreFilenames.join('|'), 'gi'); | ||
ignoreFilenames = new RegExp(state.opts.ignoreFilenames.join('|'), 'i'); | ||
} else { | ||
@@ -121,3 +158,3 @@ ignoreFilenames = undefined; | ||
if (state.opts.classNameMatchers) { | ||
classNameMatchers = new RegExp(state.opts.classNameMatchers.join('|'), 'g'); | ||
classNameMatchers = new RegExp(state.opts.classNameMatchers.join('|')); | ||
} else { | ||
@@ -124,0 +161,0 @@ classNameMatchers = undefined; |
@@ -22,3 +22,7 @@ "use strict"; | ||
return filename.match(regex) !== null; | ||
if (!regex) { | ||
return false; | ||
} | ||
return regex.test(filename); | ||
} // Remove a specific path. | ||
@@ -25,0 +29,0 @@ |
{ | ||
"name": "babel-plugin-transform-react-remove-prop-types", | ||
"version": "0.4.15", | ||
"version": "0.4.16", | ||
"description": "Remove unnecessary React propTypes from the production build", | ||
@@ -34,15 +34,13 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@babel/cli": "7.0.0-beta.42", | ||
"@babel/core": "7.0.0-beta.42", | ||
"@babel/generator": "7.0.0-beta.42", | ||
"@babel/plugin-external-helpers": "7.0.0-beta.42", | ||
"@babel/plugin-proposal-class-properties": "7.0.0-beta.42", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.0.0-rc.1", | ||
"@babel/plugin-transform-flow-strip-types": "7.0.0-beta.42", | ||
"@babel/preset-env": "7.0.0-beta.42", | ||
"@babel/preset-flow": "7.0.0-beta.42", | ||
"@babel/preset-react": "7.0.0-beta.42", | ||
"@babel/preset-stage-1": "7.0.0-beta.42", | ||
"@babel/register": "7.0.0-beta.42", | ||
"babel-eslint": "^8.0.2", | ||
"@babel/cli": "^7.1.0", | ||
"@babel/core": "^7.1.0", | ||
"@babel/generator": "^7.0.0", | ||
"@babel/plugin-external-helpers": "^7.0.0", | ||
"@babel/plugin-proposal-class-properties": "^7.1.0", | ||
"@babel/plugin-transform-flow-strip-types": "^7.0.0", | ||
"@babel/preset-env": "^7.1.0", | ||
"@babel/preset-flow": "^7.0.0", | ||
"@babel/preset-react": "^7.0.0", | ||
"@babel/register": "^7.0.0", | ||
"babel-eslint": "^9.0.0", | ||
"babel-plugin-flow-react-proptypes": "^6.1.0", | ||
@@ -63,4 +61,4 @@ "chai": "^4.1.2", | ||
"pkgfiles": "^2.3.2", | ||
"prettier": "^1.8.2" | ||
"prettier": "^1.14.3" | ||
} | ||
} |
@@ -22,3 +22,3 @@ // @flow weak | ||
if (node && matchers && node.name.match(matchers)) { | ||
if (node && matchers && matchers.test(node.name)) { | ||
return true | ||
@@ -69,2 +69,31 @@ } | ||
function memberExpressionRootIdentifier(path) { | ||
// Traverse up to the parent before the topmost member expression, and then | ||
// traverse back down to find the topmost identifier. It seems like there | ||
// might be a better way to do this. | ||
const parent = path.findParent(p => !p.isMemberExpression()) | ||
const { type } = parent.node | ||
let memberExpression | ||
if (type === 'ObjectProperty') { | ||
// The topmost MemberExpression's parent is an object property, so the | ||
// topmost MemberExpression should be the value. | ||
memberExpression = parent.get('value') | ||
} | ||
if (!memberExpression) { | ||
// This case is currently unhandled by this plugin. | ||
return null | ||
} | ||
// We have a topmost MemberExpression now, so we want to traverse down the | ||
// left half untli we no longer see MemberExpressions. This node will give us | ||
// our leftmost identifier. | ||
while (memberExpression.node.object.type === 'MemberExpression') { | ||
memberExpression = memberExpression.get('object') | ||
} | ||
return memberExpression.get('object') | ||
} | ||
export default function(api) { | ||
@@ -74,3 +103,3 @@ const { template, types, traverse } = api | ||
const nestedIdentifiers = new Set() | ||
const removedPaths = new Set() | ||
const removedPaths = new WeakSet() | ||
const collectNestedIdentifiers = { | ||
@@ -80,2 +109,8 @@ Identifier(path) { | ||
// foo.bar | ||
const root = memberExpressionRootIdentifier(path) | ||
if (root) { | ||
nestedIdentifiers.add(root.node.name) | ||
} | ||
return | ||
@@ -104,3 +139,3 @@ } | ||
if (state.opts.ignoreFilenames) { | ||
ignoreFilenames = new RegExp(state.opts.ignoreFilenames.join('|'), 'gi') | ||
ignoreFilenames = new RegExp(state.opts.ignoreFilenames.join('|'), 'i') | ||
} else { | ||
@@ -111,3 +146,3 @@ ignoreFilenames = undefined | ||
if (state.opts.classNameMatchers) { | ||
classNameMatchers = new RegExp(state.opts.classNameMatchers.join('|'), 'g') | ||
classNameMatchers = new RegExp(state.opts.classNameMatchers.join('|')) | ||
} else { | ||
@@ -197,2 +232,3 @@ classNameMatchers = undefined | ||
}, | ||
// Here to support stage-1 transform-class-properties. | ||
@@ -215,2 +251,3 @@ ClassProperty(path) { | ||
}, | ||
AssignmentExpression(path) { | ||
@@ -217,0 +254,0 @@ const { node, scope } = path |
@@ -15,3 +15,7 @@ // @flow weak | ||
return filename.match(regex) !== null | ||
if (!regex) { | ||
return false | ||
} | ||
return regex.test(filename) | ||
} | ||
@@ -18,0 +22,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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
44342
27
974
0