Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.

Add friendlier error for two adjacent elements #20

Merged
merged 1 commit into from
May 22, 2014

Conversation

sophiebits
Copy link

Fixes facebook/react#1584. We've had a handful of people confused about this recently so I think this would be nice to do if it doesn't conflict with any real uses that you can think of.

Test Plan: npm test

cc @jeffmo @syranide

@syranide
Copy link

As JSX is just sugar for function-calls, it does technically prevent valid uses. However, JSX is not intended as a substitute for function-calls so comparing the return-value of a JSX-tag never makes sense. If someone for some superweird reason would want that, they'll just have to assign it a variable first and compare that (or possibly flip the expression).

👍

@sophiebits
Copy link
Author

Or parenthesize it, as I verified works in a test case.

@syranide
Copy link

Ah yes ofc.

// element, we disallow it here in the parser in order to provide a
// better error message. (In the rare case that the less-than operator
// was intended, the left tag can be wrapped in parentheses.)
if (!origInXJSChild && lookahead.value === '<') {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/lookahead.value === '<'/match('<')/

(this also checks that the type of the token is Punctuator)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@jeffmo
Copy link

jeffmo commented May 22, 2014

love it!

jeffmo pushed a commit that referenced this pull request May 22, 2014
Add friendlier error for two adjacent elements
@jeffmo jeffmo merged commit eb86ad3 into facebookarchive:fb-harmony May 22, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parse error is confusing when trying to return two elements
3 participants