babel-plugin-transform-react-remove-prop-types
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -45,4 +45,14 @@ 'use strict'; | ||
var superClass = binding.path.get('superClass'); | ||
if (superClass.matchesPattern('React.Component') || superClass.matchesPattern('Component')) { | ||
if (superClass.matchesPattern('React.Component') || superClass.node.name === 'Component') { | ||
path.remove(); | ||
} else if (superClass.node.name) { | ||
// Check for inheritance | ||
className = superClass.node.name; | ||
binding = scope.getBinding(className); | ||
superClass = binding.path.get('superClass'); | ||
if (superClass.matchesPattern('React.Component') || superClass.node.name === 'Component') { | ||
path.remove(); | ||
} | ||
} | ||
@@ -61,8 +71,13 @@ } | ||
var binding = scope.getBinding(className); | ||
if (!binding || !binding.path.isClassDeclaration()) { | ||
if (!binding) { | ||
return; | ||
} | ||
var superClass = binding.path.get('superClass'); | ||
if (superClass.matchesPattern('React.Component') || superClass.matchesPattern('Component')) { | ||
if (binding.path.isClassDeclaration()) { | ||
var superClass = binding.path.get('superClass'); | ||
if (superClass.matchesPattern('React.Component') || superClass.matchesPattern('Component')) { | ||
path.remove(); | ||
} | ||
} else if ((0, _isStatelessComponent2.default)(binding.path)) { | ||
path.remove(); | ||
@@ -77,2 +92,6 @@ } | ||
; | ||
var _isStatelessComponent = require('./isStatelessComponent'); | ||
var _isStatelessComponent2 = _interopRequireDefault(_isStatelessComponent); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
{ | ||
"name": "babel-plugin-transform-react-remove-prop-types", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Remove unnecessary React propTypes from the production build", | ||
@@ -37,5 +37,5 @@ "main": "lib/index.js", | ||
"babel-preset-stage-0": "^6.3.13", | ||
"istanbul": "^0.3.20", | ||
"istanbul": "^0.4.2", | ||
"mocha": "^2.2.5" | ||
} | ||
} |
@@ -0,1 +1,3 @@ | ||
import isStatelessComponent from './isStatelessComponent'; | ||
export default function ({ Plugin, types: t }) { | ||
@@ -35,7 +37,16 @@ return { | ||
if (node.key.name === 'propTypes') { | ||
const className = scope.block.id.name; | ||
const binding = scope.getBinding(className); | ||
const superClass = binding.path.get('superClass'); | ||
if (superClass.matchesPattern('React.Component') || superClass.matchesPattern('Component')) { | ||
let className = scope.block.id.name; | ||
let binding = scope.getBinding(className); | ||
let superClass = binding.path.get('superClass'); | ||
if (superClass.matchesPattern('React.Component') || superClass.node.name === 'Component') { | ||
path.remove(); | ||
} else if (superClass.node.name) { // Check for inheritance | ||
className = superClass.node.name; | ||
binding = scope.getBinding(className); | ||
superClass = binding.path.get('superClass'); | ||
if (superClass.matchesPattern('React.Component') || superClass.node.name === 'Component') { | ||
path.remove(); | ||
} | ||
} | ||
@@ -56,8 +67,13 @@ } | ||
const binding = scope.getBinding(className); | ||
if (!binding || !binding.path.isClassDeclaration()) { | ||
if (!binding) { | ||
return; | ||
} | ||
const superClass = binding.path.get('superClass'); | ||
if (superClass.matchesPattern('React.Component') || superClass.matchesPattern('Component')) { | ||
if (binding.path.isClassDeclaration()) { | ||
const superClass = binding.path.get('superClass'); | ||
if (superClass.matchesPattern('React.Component') || superClass.matchesPattern('Component')) { | ||
path.remove(); | ||
} | ||
} else if (isStatelessComponent(binding.path)) { | ||
path.remove(); | ||
@@ -70,2 +86,2 @@ } | ||
}; | ||
}; | ||
} |
"use strict"; | ||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
@@ -11,3 +11,3 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var Foo = (function (_React$Component) { | ||
var Foo = function (_React$Component) { | ||
_inherits(Foo, _React$Component); | ||
@@ -27,2 +27,2 @@ | ||
return Foo; | ||
})(React.Component); | ||
}(React.Component); |
"use strict"; | ||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
@@ -11,3 +11,3 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var Foo = (function (_React$Component) { | ||
var Foo = function (_React$Component) { | ||
_inherits(Foo, _React$Component); | ||
@@ -27,2 +27,2 @@ | ||
return Foo; | ||
})(React.Component); | ||
}(React.Component); |
Sorry, the diff of this file is not supported yet
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
38022
30
525