Skip to content

Commit

Permalink
Add failing test case for #153
Browse files Browse the repository at this point in the history
I have been investigating a bug that occurs when a ClassExpression is
using the experimental class properties for propTypes. I am not sure
what the best fix for it is yet, but I wanted to get up a failing test
case to help showcase the bug.
  • Loading branch information
lencioni committed Sep 19, 2018
1 parent 5fa6824 commit 5be830f
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,20 @@ export default function remove(path, globalOptions, options) {

// Inspired from babel-plugin-transform-class-properties.
case 'class static': {
let ref
let pathClassDeclaration = options.pathClassDeclaration

if (!pathClassDeclaration.isClassExpression() && pathClassDeclaration.node.id) {
ref = pathClassDeclaration.node.id
} else {
if (!pathClassDeclaration.node.id) {
// Class without name not supported
return
}

if (pathClassDeclaration.isClassExpression()) {
// () => class Foo {}
return
}

const ref = pathClassDeclaration.node.id

const node = types.expressionStatement(
types.assignmentExpression(
'=',
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/es-class-static-property/actual.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@ export default class Foo2 extends React.Component {

render() {}
}

const componentFactory = () => {
return class Foo3 extends React.Component {
static propTypes = {
bar3: PropTypes.string,
}

render() {}
};
};
20 changes: 20 additions & 0 deletions test/fixtures/es-class-static-property/expected-remove-es5.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,23 @@ function (_React$Component2) {
}(React.Component);

exports.default = Foo2;

var componentFactory = function componentFactory() {
return (
/*#__PURE__*/
function (_React$Component3) {
babelHelpers.inherits(Foo3, _React$Component3);

function Foo3() {
babelHelpers.classCallCheck(this, Foo3);
return babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(Foo3).apply(this, arguments));
}

babelHelpers.createClass(Foo3, [{
key: "render",
value: function render() {}
}]);
return Foo3;
}(React.Component)
);
};
7 changes: 7 additions & 0 deletions test/fixtures/es-class-static-property/expected-remove-es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ export default class Foo2 extends React.Component {
render() {}

}

const componentFactory = () => {
return class Foo3 extends React.Component {
render() {}

};
};
23 changes: 23 additions & 0 deletions test/fixtures/es-class-static-property/expected-wrap-es5.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,26 @@ exports.default = Foo2;
Foo2.propTypes = process.env.NODE_ENV !== "production" ? {
bar2: PropTypes.string
} : {};

var componentFactory = function componentFactory() {
var _temp;

return _temp =
/*#__PURE__*/
function (_React$Component3) {
babelHelpers.inherits(Foo3, _React$Component3);

function Foo3() {
babelHelpers.classCallCheck(this, Foo3);
return babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(Foo3).apply(this, arguments));
}

babelHelpers.createClass(Foo3, [{
key: "render",
value: function render() {}
}]);
return Foo3;
}(React.Component), Foo3.propTypes = process.env.NODE_ENV !== "production" ? {
bar3: PropTypes.string
} : {}, _temp;
};
11 changes: 11 additions & 0 deletions test/fixtures/es-class-static-property/expected-wrap-es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,14 @@ export default class Foo2 extends React.Component {
Foo2.propTypes = process.env.NODE_ENV !== "production" ? {
bar2: PropTypes.string
} : {};

const componentFactory = () => {
var _temp;

return _temp = class Foo3 extends React.Component {
render() {}

}, Foo3.propTypes = process.env.NODE_ENV !== "production" ? {
bar3: PropTypes.string
} : {}, _temp;
};

0 comments on commit 5be830f

Please sign in to comment.