Skip to content
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

Parse error is confusing when trying to return two elements #1584

Closed
sophiebits opened this issue May 21, 2014 · 1 comment · Fixed by facebookarchive/esprima#20
Closed

Comments

@sophiebits
Copy link
Collaborator

(Opening here because esprima-fb apparently doesn't accept issues.)

If you write

return <div className="one" /><div className="two" />;

then you get "Unexpected identifier" because it tries to parse it as

return React.DOM.div({className: "one"})  < div className ...

That is, the < of the second div is interpreted as a less than. I think we can give nicer errors here if we disallow the less than operator directly after an XJSElement. I don't think this prevents any real uses but if it did, you could always wrap it in parens:

return (<div className="one" />) < threshold;

cc @jeffmo @syranide

sophiebits added a commit to sophiebits/esprima that referenced this issue May 22, 2014
sophiebits added a commit to sophiebits/esprima that referenced this issue May 22, 2014
@sophiebits
Copy link
Collaborator Author

facebookarchive/esprima#20 was merged; we can close this after a version bump.

josephsavona added a commit that referenced this issue May 15, 2024
Implements an efficient algorithm for computing the dominator (or post 
dominator) tree of a CFG, following 
https://www.cs.rice.edu/~keith/Embed/dom.pdf. This is used/tested in the next PR 
to validate that hooks are called unconditionally. 

note: I clean up the implementation quite a bit late in the stack in #1584
josephsavona added a commit that referenced this issue May 15, 2024
React will retry or abort components that throw (depending on a few conditions), 
so from React's perspective a `throw` statement is not a normal exit node. Thus 
the Rules of Hooks really have a caveat: the set of hooks that are called _in an 
execution that returns successfully_ must be consistent. Examples such as the 
following are therefore allowed: 

```javascript 

function Component(props) { 

if (props.cond) { 

throw new Error(...); 

} 

useHook(); 

} 

``` 

By modeling `throw` as an exit node, we rejected cases such as this. This diff 
changes to not model throws as exit nodes. #1584  changes this to make it an 
option, since some cases will want to consider throw as an exit node.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant