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

Do not allow TypeCastExpressions w/o parens #8956

Merged
merged 1 commit into from Nov 5, 2018
Merged

Conversation

danez
Copy link
Member

@danez danez commented Oct 31, 2018

Q                       A
Fixed Issues? Fixes #6718 Fixes #6698
Patch: Bug Fix? 👍
Major: Breaking Change? sort of
Minor: New Feature? no
Tests Added + Pass? 👍
Documentation PR Link
Any Dependency Changes? no
License MIT

This adds an additional check to disallow flow type casts without parens inside of sequence expressions.

It also enables another check which was already present but never executed.

It is technically a breaking change, but as flow does not allow this, it is probably safe to assume nobody is using this. Or are we now being more strict?

I also tried using babel/babylon#446 (which also solves this problems), but the detection of arrow functions had lots of edge cases and ambiguities and overall seemed harder to maintain than the current parsing of arrows.

@danez danez added PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: parser labels Oct 31, 2018
@babel-bot
Copy link
Collaborator

babel-bot commented Oct 31, 2018

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/9334/

Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

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

Instead of duplicating parseExpressionParenItem/parseParenItem and the check in toReferencedList/parseParenAndDistinguishExpression, I think that it would be easier to pass an optional boolean isParenthesizedExpression parameter to toReferencedList. We should then disallow type casts if !isParenthesizedExpression || length > 1.

@@ -1932,36 +1961,16 @@ export default (superClass: Class<Parser>): Class<Parser> =>
for (let i = 0; i < exprList.length; i++) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: we can use for/of here, since we compile it using the assuneArray option (for (a of b) -> for (let i = 0; i < b.length ..)

Copy link
Member Author

@danez danez Nov 5, 2018

Choose a reason for hiding this comment

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

I leave that for now, i don't want to make the commit diff bigger. Can do that in a separate PR.

@danez
Copy link
Member Author

danez commented Nov 5, 2018

@nicolo-ribaudo Thanks for the very helpful input. I changed it and it is a lot cleaner and easier now, and still works the same. 👍

@danez danez changed the title Do not allow TypeCastExpressions w/o parens inside of SequenceExpressions Do not allow TypeCastExpressions w/o parens Nov 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Flow typecasts parsed too leniently Tighten up parsing of Flow TypeCasts
4 participants