The library for web and native user interfaces.
Fixing Bug in JSX transformer
The bug fixed by this commit prevented the correct parsing of `var` statements with multiple variables being declared. Instead of trying to parse a whole 'variable declarations' (a `var` statement with all its declarations), this visitor now only parses single 'variable declarators'.
Paul Seiffert committed
May 30, 2013 at 20:51 UTC
b03f04ff24373a9898b062705a13f7124eba8c16
1 file changed
+16
-19
vendor/fbtransform/transforms/reactDisplayName.js
+16
-19
@@ -36,32 +36,29 @@ var getDocblock = require('../lib/utils').getDocblock;
36
* });
37
*/
38
function visitReactDisplayName(traverse, object, path, state) {
39
- object.declarations.forEach(function(dec) {
40
- if (dec.type === Syntax.VariableDeclarator &&
41
- dec.id.type === Syntax.Identifier &&
42
- dec.init &&
43
- dec.init.type === Syntax.CallExpression &&
44
- dec.init.callee.type === Syntax.MemberExpression &&
45
- dec.init.callee.object.type === Syntax.Identifier &&
46
- dec.init.callee.object.name === 'React' &&
47
- dec.init.callee.property.type === Syntax.Identifier &&
48
- dec.init.callee.property.name === 'createClass' &&
49
- dec.init['arguments'].length === 1 &&
50
- dec.init['arguments'][0].type === Syntax.ObjectExpression) {
39
+ if (object.type === Syntax.VariableDeclarator &&
40
+ object.id.type === Syntax.Identifier &&
41
+ object.init &&
42
+ object.init.type === Syntax.CallExpression &&
43
+ object.init.callee.type === Syntax.MemberExpression &&
44
+ object.init.callee.object.type === Syntax.Identifier &&
45
+ object.init.callee.object.name === 'React' &&
46
+ object.init.callee.property.type === Syntax.Identifier &&
47
+ object.init.callee.property.name === 'createClass' &&
48
+ object.init['arguments'].length === 1 &&
49
+ object.init['arguments'][0].type === Syntax.ObjectExpression) {
50
52
- var displayName = dec.id.name;
53
- catchup(dec.init['arguments'][0].range[0] + 1, state);
54
- append("displayName: '" + displayName + "',", state);
55
- }
56
- });
51
+ var displayName = object.id.name;
52
+ catchup(object.init['arguments'][0].range[0] + 1, state);
53
+ append("displayName: '" + displayName + "',", state);
54
+ }
55
}
56
59
-
57
/**
58
* Will only run on @jsx files for now.
59
*/
60
visitReactDisplayName.test = function(object, path, state) {
64
- return object.type === Syntax.VariableDeclaration && !!getDocblock(state).jsx;
61
+ return object.type === Syntax.VariableDeclarator && !!getDocblock(state).jsx;
62
};
63
64
exports.visitReactDisplayName = visitReactDisplayName;