Skip to content

Commit 59e3671

Browse files
author
Keyan Zhang
committed
bail out if arguments is found
1 parent e00677f commit 59e3671

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

transforms/__testfixtures__/class-initial-state.input.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,13 @@ var UseGetInitialState = React.createClass({
158158
return null;
159159
},
160160
});
161+
162+
var UseArguments = React.createClass({
163+
helper() {
164+
console.log(arguments);
165+
},
166+
167+
render() {
168+
return null;
169+
},
170+
});

transforms/__testfixtures__/class-initial-state.output.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,13 @@ var UseGetInitialState = React.createClass({
170170
return null;
171171
},
172172
});
173+
174+
var UseArguments = React.createClass({
175+
helper() {
176+
console.log(arguments);
177+
},
178+
179+
render() {
180+
return null;
181+
},
182+
});

transforms/class.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ module.exports = (file, api, options) => {
8686

8787
const hasNoCallsToDeprecatedAPIs = classPath => {
8888
if (checkDeprecatedAPICalls(classPath)) {
89-
console.log(
89+
console.warn(
9090
file.path + ': `' + ReactUtils.getComponentName(classPath) + '` ' +
9191
'was skipped because of deprecated API calls. Remove calls to ' +
9292
DEPRECATED_APIS.join(', ') + ' in your React component and re-run ' +
@@ -103,7 +103,7 @@ module.exports = (file, api, options) => {
103103
j(classPath).find(j.Identifier, {name: GET_INITIAL_STATE_FIELD}).size() > 1
104104
);
105105
if (hasInvalidCalls) {
106-
console.log(
106+
console.warn(
107107
file.path + ': `' + ReactUtils.getComponentName(classPath) + '` ' +
108108
'was skipped because of API calls that will be removed. Remove calls to `' +
109109
DEFAULT_PROPS_FIELD + '` and/or `' + GET_INITIAL_STATE_FIELD +
@@ -114,6 +114,22 @@ module.exports = (file, api, options) => {
114114
return true;
115115
};
116116

117+
const doesNotUseArguments = classPath => {
118+
const hasArguments = (
119+
j(classPath).find(j.Identifier, {name: 'arguments'}).size() > 0
120+
);
121+
if (hasArguments) {
122+
console.warn(
123+
file.path + ': `' + ReactUtils.getComponentName(classPath) + '` ' +
124+
'was skipped because `arguments` was found in your functions. ' +
125+
'Arrow functions do not expose an `arguments` object; ' +
126+
'consider changing to use ES6 spread operator and re-run this script.'
127+
);
128+
return false;
129+
}
130+
return true;
131+
};
132+
117133
const canConvertToClass = classPath => {
118134
const specPath = ReactUtils.getReactCreateClassSpec(classPath);
119135
const invalidProperties = specPath.properties.filter(prop => (
@@ -133,7 +149,7 @@ module.exports = (file, api, options) => {
133149
const invalidText = invalidProperties
134150
.map(prop => prop.key.name ? prop.key.name : prop.key)
135151
.join(', ');
136-
console.log(
152+
console.warn(
137153
file.path + ': `' + ReactUtils.getComponentName(classPath) + '` ' +
138154
'was skipped because of invalid field(s) `' + invalidText + '` on ' +
139155
'the React component. Remove any right-hand-side expressions that ' +
@@ -835,7 +851,7 @@ module.exports = (file, api, options) => {
835851
return true;
836852
}
837853
}
838-
console.log(
854+
console.warn(
839855
file.path + ': `' + ReactUtils.getComponentName(classPath) + '` ' +
840856
'was skipped because of inconvertible mixins.'
841857
);
@@ -847,6 +863,7 @@ module.exports = (file, api, options) => {
847863
.filter(mixinsFilter)
848864
.filter(hasNoCallsToDeprecatedAPIs)
849865
.filter(hasNoCallsToAPIsThatWillBeRemoved)
866+
.filter(doesNotUseArguments)
850867
.filter(canConvertToClass)
851868
.forEach(classPath => updateToClass(classPath, type));
852869

0 commit comments

Comments
 (0)