-
Notifications
You must be signed in to change notification settings - Fork 47.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JSX Transformer / DisplayName Visitor: Multiple declarations with one var
statement
#27
Conversation
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'.
:like: I hadn't considered this case. I'm curious how you are using the displayName. We have a bookmarklet that will annotate the page with visual labels on top of the DOM that tell you the names of the components that generated that part of the page. I'll see if we can get that checked in. |
Oh actually I'm not using displayName myself, the page just won't render because javascript dies with an var CommentBox = React.createClass({
...
}),
CommentList = React.createClass({
render: function() {
var comments = this.props.data.map(function (comment) {
return <Comment author={comment.author}>{comment.text}</Comment>;
});
return (
<div class="commentList">
{comments}
</div>
);
}
}); (the body of CommentBox is omitted since it is transformed correctly.) |
And: I would really be interested in this bookmarklet! :) |
Hmm, I'm having a hard time reproing this issue... I made repro.js:
and when I run
Did you include the "@jsx" tag in the docblock at the top? Or maybe I'm missing something? |
@jeffmo Could you please try to make Yes, I do have a |
I tried to reproduce the problem with the |
Aha you're right! It's because we move past the contents of the object literal in the displayName transform step before the react.js transform has a chance to run on the declaration node. Ok, do you mind filling out our CLA and then I can merge this in for you: |
dec.init.callee.property.name === 'createClass' && | ||
dec.init['arguments'].length === 1 && | ||
dec.init['arguments'][0].type === Syntax.ObjectExpression) { | ||
if (object.type === Syntax.VariableDeclarator && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This first conditional is no longer necessary since it's checked in visitReactDisplayName.test() -- mind killing it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, if we can rely on test() being called before visitReactDisplayName(), we can remove that first condition!
This looks good to after we clear up line 39 -- thanks a ton for the fix! |
I already signed the CLA! |
JSX Transformer / DisplayName Visitor: Multiple declarations with one `var` statement
…-edition Community Roundup #27 – Relay Edition
(cherry picked from commit f30b0d1)
Update OVERVIEW.md
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' (avar
statement with all its declarations), this visitor now only parses single 'variable declarators'.An example (from the tutorial) that did not work before this patch:
What did work is the following:
Of course, there are different coding styles and guidelines. Most developers probably don't like multiple variables being declared with one
var
statement, but nevertheless, it should be possible.