Skip to content

Commit 8683123

Browse files
committed
destructuring react Component functionality
1 parent b580375 commit 8683123

3 files changed

Lines changed: 32 additions & 1 deletion

File tree

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ export default function ({ Plugin, types: t }) {
4343
let className = scope.block.id.name;
4444
let binding = scope.getBinding(className);
4545
let superClass = binding.path.get('superClass');
46-
4746
if (superClass.matchesPattern('React.Component') || superClass.node.name === 'Component') {
4847
path.remove();
4948
} else if (superClass.node.name) { // Check for inheritance
@@ -78,6 +77,8 @@ export default function ({ Plugin, types: t }) {
7877
const superClass = binding.path.get('superClass');
7978
if (superClass.matchesPattern('React.Component') || superClass.matchesPattern('Component')) {
8079
path.remove();
80+
} else if (superClass.node.name === 'Component') {
81+
path.remove();
8182
}
8283
} else if (isStatelessComponent(binding.path)) {
8384
path.remove();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1+
import { Component } from "react";
2+
13
class Foo extends React.Component {
24
render() {}
35
}
46

57
Foo.propTypes = {
68
foo: React.PropTypes.string
79
};
10+
11+
class Foo2 extends Component {
12+
render() {}
13+
}
14+
15+
Foo2.propTypes = {
16+
foo: React.PropTypes.string
17+
};
18+

test/fixtures/es-class-assign-property/expected.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
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; }; }();
44

5+
var _react = require("react");
6+
57
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
68

79
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
@@ -24,3 +26,20 @@ var Foo = function (_React$Component) {
2426

2527
return Foo;
2628
}(React.Component);
29+
30+
var Foo2 = function (_Component) {
31+
_inherits(Foo2, _Component);
32+
33+
function Foo2() {
34+
_classCallCheck(this, Foo2);
35+
36+
return _possibleConstructorReturn(this, Object.getPrototypeOf(Foo2).apply(this, arguments));
37+
}
38+
39+
_createClass(Foo2, [{
40+
key: "render",
41+
value: function render() {}
42+
}]);
43+
44+
return Foo2;
45+
}(_react.Component);

0 commit comments

Comments
 (0)