-
Notifications
You must be signed in to change notification settings - Fork 47.9k
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
v0.14.3: Inside render's return, any comments placed above the first line cause various errors #5573
Comments
Looks like both your first and second snippets are resulting in parse errors. At least they are for me when I drop them into a React component in the Babel repl (http://babeljs.io/repl/). I haven't tested with anything else (perhaps Babel 6 behaves slightly differently, though I don't think it's supposed to). Maybe you're using something else to parse? This is unfortunately one of those areas where JSX gets weird. Since it's all a bit made up, there are edge cases with the behavior, and maybe we can define things a bit better. I'll walk through each of these though and try to explain why they're parse errors and why the last one works. 1, 2These are both parse errors for the same reason. It boils down to not knowing that you're in a piece of JSX when you put the comments inside the braces. At that point the parser hasn't switched over the treating the block as JSX (it hasn't encountered something it believes is an opening tag) so it thinks you just have an object. 3For this one, the opening I'm sorry that you hit one of the cases where JSX breaks down but hopefully that clears it up for you. There isn't much we can really do. We don't really own the tooling anymore and unfortunately since we're building this on top of JS, until the parse sees something to indicate JSX, it has to assume you're still in JS. |
Thanks so much for the explanation and quick response! It makes sense though, now that you explain it. I know you guys are probably busy, but if you have a sec to check it out, I was talking about this with one of my professors and he was wondering if using an explicit JSX declaration could potentially fix the issue? Something along the lines of: var Foo = React.createClass({ |
@emkolardev Probably not; specifying a It would be trivial to disambiguate if you had some obvious start and end token:
But since JSX is just javascript with a couple extra token types, the Ultimately, one could write a parser that used some clever backtracking and heuristics to "figure it out", but there is something to be said for managing complexity and keeping something reminiscent of a LL Grammar. If you are interested in this stuff, you should take a class on compilers! |
Using v0.14.3, one comment placed on first line of render()'s return causes nothing to be rendered in browser. My code causing this:
Two comments cause an unexpected token error. My code causing this:
This causes no errors at all:
The text was updated successfully, but these errors were encountered: