Skip to content

Commit bf4c498

Browse files
Merge pull request #94 from oliviertassinari/fix-90
fix(react): support one more React API
2 parents 2db26a9 + b4350d8 commit bf4c498

File tree

6 files changed

+37
-5
lines changed

6 files changed

+37
-5
lines changed

src/isStatelessComponent.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ function isJSXElementOrReactCreateElement(path) {
55

66
path.traverse({
77
CallExpression(path2) {
8-
const {
9-
callee,
10-
} = path2.node;
8+
const callee = path2.get('callee');
119

12-
if (callee && callee.object && callee.object.name === 'React' &&
13-
callee.property.name === 'createElement') {
10+
if (
11+
callee.matchesPattern('React.createElement') ||
12+
callee.matchesPattern('React.cloneElement')
13+
) {
1414
visited = true;
1515
}
1616
},

test/fixtures/stateless-functional-components/actual.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,11 @@ const Foo11 = () => (
115115
Foo11.propTypes = {
116116
foo: PropTypes.string
117117
};
118+
119+
function Foo12(props) {
120+
return React.cloneElement(props.children);
121+
}
122+
123+
Foo12.propTypes = {
124+
foo: PropTypes.string,
125+
};

test/fixtures/stateless-functional-components/expected-remove-es5.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,7 @@ var Foo10 = function Foo10() {
7373
var Foo11 = function Foo11() {
7474
return true && React.createElement("div", null);
7575
};
76+
77+
function Foo12(props) {
78+
return React.cloneElement(props.children);
79+
}

test/fixtures/stateless-functional-components/expected-remove-es6.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,7 @@ const Foo10 = () => {
6565
};
6666

6767
const Foo11 = () => true && <div />;
68+
69+
function Foo12(props) {
70+
return React.cloneElement(props.children);
71+
}

test/fixtures/stateless-functional-components/expected-wrap-es5.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,11 @@ var Foo11 = function Foo11() {
117117
process.env.NODE_ENV !== "production" ? Foo11.propTypes = {
118118
foo: PropTypes.string
119119
} : void 0;
120+
121+
function Foo12(props) {
122+
return React.cloneElement(props.children);
123+
}
124+
125+
process.env.NODE_ENV !== "production" ? Foo12.propTypes = {
126+
foo: PropTypes.string
127+
} : void 0;

test/fixtures/stateless-functional-components/expected-wrap-es6.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,11 @@ const Foo11 = () => true && <div />;
109109
process.env.NODE_ENV !== "production" ? Foo11.propTypes = {
110110
foo: PropTypes.string
111111
} : void 0;
112+
113+
function Foo12(props) {
114+
return React.cloneElement(props.children);
115+
}
116+
117+
process.env.NODE_ENV !== "production" ? Foo12.propTypes = {
118+
foo: PropTypes.string
119+
} : void 0;

0 commit comments

Comments
 (0)