Skip to content

Commit 84f8b71

Browse files
author
Keyan Zhang
committed
merged master and upgraded deps
2 parents 0cfad0a + 74da469 commit 84f8b71

13 files changed

+62
-18
lines changed

.eslintrc

Lines changed: 0 additions & 5 deletions
This file was deleted.

.eslintrc.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
parser: 'babel-eslint',
3+
4+
extends: './node_modules/fbjs-scripts/eslint/.eslintrc.js',
5+
6+
plugins: [
7+
'react',
8+
],
9+
10+
ecmaFeatures: {
11+
modules: false
12+
},
13+
};

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ APIs.
99
* `npm install -g jscodeshift`
1010
* `git clone https://github.com/reactjs/react-codemod.git` or download a zip file
1111
from `https://github.com/reactjs/react-codemod/archive/master.zip`
12+
* Run `npm install` in the react-codemod directory
1213
* `jscodeshift -t <codemod-script> <path>`
1314
* Use the `-d` option for a dry-run and use `-p` to print the output
1415
for comparison

package.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,26 @@
99
"lint": "eslint ."
1010
},
1111
"dependencies": {
12-
"jscodeshift": "^0.3.20",
13-
"babel-eslint": "^5.0.0",
12+
"jscodeshift": "^0.3.24",
13+
"babel-eslint": "^6.0.5",
1414
"babel-plugin-transform-object-rest-spread": "^6.6.5",
1515
"babel-preset-es2015": "^6.6.0",
16-
"babel-jest": "^9.0.2",
17-
"eslint": "^1.7.3",
18-
"fbjs-scripts": "^0.5.0",
19-
"jest-cli": "^0.9.1"
16+
"babel-jest": "^13.0.0",
17+
"eslint": "^2.13.1",
18+
"fbjs-scripts": "^0.7.1",
19+
"jest-cli": "^13.0.0"
2020
},
2121
"jest": {
2222
"automock": false,
2323
"globals": {
2424
"baseDir": "../"
2525
},
26+
"testEnvironment": "node",
2627
"testPathDirs": [
27-
"transforms/__tests__"
28+
"transforms"
2829
]
2930
},
3031
"devDependencies": {
31-
"eslint-plugin-react": "^5.1.1"
32+
"eslint-plugin-react": "^5.2.2"
3233
}
3334
}

transforms/__testfixtures__/.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
rules:
33
no-undef: 0
44
no-unused-vars: 0
5+
no-redeclare: 0

transforms/__testfixtures__/class.input.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ var MyComponent3 = React.createClass({
6161
/>
6262
);
6363
}
64+
return null;
6465
},
6566

6667
autobindMe: function() {},

transforms/__testfixtures__/class.output.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class MyComponent3 extends React.Component {
6161
/>
6262
);
6363
}
64+
return null;
6465
};
6566

6667
autobindMe = () => {};

transforms/__testfixtures__/pure-component.input.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,14 @@ class Impure extends React.Component {
2121
}
2222
}
2323

24+
class ImpureWithRef extends React.Component {
25+
render() {
26+
return (
27+
<div>
28+
<span ref="spanasaurus" />
29+
</div>
30+
);
31+
}
32+
}
33+
2434
var A = props => <div className={props.foo} />;

transforms/__testfixtures__/pure-component.output.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,14 @@ class Impure extends React.Component {
1919
}
2020
}
2121

22+
class ImpureWithRef extends React.Component {
23+
render() {
24+
return (
25+
<div>
26+
<span ref="spanasaurus" />
27+
</div>
28+
);
29+
}
30+
}
31+
2232
var A = props => <div className={props.foo} />;

transforms/create-element-to-jsx.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ module.exports = function(file, api, options) {
7272
value
7373
);
7474
}
75+
return null;
7576
});
7677

7778
return attributes;

transforms/pure-component.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ module.exports = function(file, api, options) {
3636
.filter(p => !isRenderMethod(p.value))
3737
.size() === 0;
3838

39+
const hasRefs = path =>
40+
j(path)
41+
.find(j.JSXAttribute, {
42+
name: {
43+
type: 'JSXIdentifier',
44+
name: 'ref',
45+
},
46+
})
47+
.size() > 0;
48+
3949
const THIS_PROPS = {
4050
object: {
4151
type: 'ThisExpression',
@@ -82,7 +92,7 @@ module.exports = function(file, api, options) {
8292

8393
const pureClasses = ReactUtils.findReactES6ClassDeclaration(f)
8494
.filter(path => {
85-
const isPure = onlyHasRenderMethod(path);
95+
const isPure = onlyHasRenderMethod(path) && !hasRefs(path);
8696
if (!isPure && !silenceWarnings) {
8797
reportSkipped(path);
8898
}
@@ -109,4 +119,3 @@ module.exports = function(file, api, options) {
109119

110120
return f.toSource(printOptions);
111121
};
112-

transforms/sort-comp.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ const defaultMethodsOrder = [
122122
'componentWillUpdate',
123123
'componentDidUpdate',
124124
'componentWillUnmount',
125-
'/^on.+$/',
126-
'/^(get|set)(?!(InitialState$|DefaultProps$|ChildContext$)).+$/',
125+
/^on.+$/,
126+
/^(get|set)(?!(InitialState$|DefaultProps$|ChildContext$)).+$/,
127127
'everything-else',
128-
'/^render.+$/',
128+
/^render.+$/,
129129
'render',
130130
];
131131

transforms/utils/ReactUtils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ module.exports = function(j) {
189189
return spec;
190190
}
191191
}
192+
return null;
192193
};
193194

194195
const getClassExtendReactSpec = classPath => classPath.value.body;

0 commit comments

Comments
 (0)