-
-
Notifications
You must be signed in to change notification settings - Fork 5.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
Disallow escape sequences in contextual keywords #9618
Conversation
@@ -704,11 +712,11 @@ export default class ExpressionParser extends LValParser { | |||
|
|||
atPossibleAsync(base: N.Expression): boolean { | |||
return ( | |||
!this.state.containsEsc && |
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.
containsEsc
only says if the current token has escape sequences. Here it already references the token after async
which is not what we want, hence the slice check.
node.arguments = this.parseCallExpressionArguments( | ||
tt.parenR, | ||
possibleAsync, | ||
); |
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.
I removed this, as I don't see a what an OptionalCallExpression
has anything todo with the async
keyword. No tests failed or changed. I guess this was copied wrong.
@@ -525,12 +525,21 @@ export default class ExpressionParser extends LValParser { | |||
startLoc: Position, | |||
noCalls?: ?boolean, | |||
): N.Expression { | |||
const maybeAsyncArrow = this.atPossibleAsync(base); |
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.
moving it from line 624 to here, basically prevents (async)(a) => {}
.
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/10376/ |
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/10356/ |
if (possibleAsync && this.shouldParseAsyncArrow()) { | ||
if ( | ||
maybeAsyncArrow && | ||
!this.canInsertSemicolon() && |
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.canInsertSemicolon()
prevents
async (x)
=> {}
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.
Maybe we could move the check inside shouldParseAsyncArrow
?
Also note that both flow and TS allow this code:
async (f)
: t => { }
but disallow
async (f) : t
=> { }
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.
Thanks, I added testcases and moved it into shouldParseAsyncArrow
Resolves two problems:
async, as, of, get, set, static, ...
The cases which were parsing successfully with escape sequences (although shouldn't) were: async in almost all cases. get & set in classes.
Also added tests for a lot of cases that were already correctly working.