-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Make TS InstantiationExpr parsing more permissive #2188
Make TS InstantiationExpr parsing more permissive #2188
Conversation
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 for giving me a heads up about this change in TypeScript!
js_lexer.TSlash, | ||
js_lexer.TSlashEquals, | ||
js_lexer.TIdentifier: | ||
return false |
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.
Where did these come from? This doesn't appear to follow what Microsoft changed in their parser. For example, consider the following code:
f<T>
import "x"
f<T>
import("x")
After their PR, TypeScript parses it like this:
f;
import "x";
f < T > import("x");
But with your PR, esbuild parses it like this:
f;
import "x";
f;
import("x");
I tested this case with import
because some of the code Microsoft is now using looks like this:
function isStartOfLeftHandSideExpression(): boolean {
switch (token()) {
case SyntaxKind.ThisKeyword:
case SyntaxKind.SuperKeyword:
case SyntaxKind.NullKeyword:
case SyntaxKind.TrueKeyword:
case SyntaxKind.FalseKeyword:
case SyntaxKind.NumericLiteral:
case SyntaxKind.BigIntLiteral:
case SyntaxKind.StringLiteral:
case SyntaxKind.NoSubstitutionTemplateLiteral:
case SyntaxKind.TemplateHead:
case SyntaxKind.OpenParenToken:
case SyntaxKind.OpenBracketToken:
case SyntaxKind.OpenBraceToken:
case SyntaxKind.FunctionKeyword:
case SyntaxKind.ClassKeyword:
case SyntaxKind.NewKeyword:
case SyntaxKind.SlashToken:
case SyntaxKind.SlashEqualsToken:
case SyntaxKind.Identifier:
return true;
case SyntaxKind.ImportKeyword:
return lookAhead(nextTokenIsOpenParenOrLessThanOrDot);
default:
return isIdentifier();
}
}
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 forgot to handle import
token, and I will add it.
They changed to use an existing function isStartOfExpression
.
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.
How can I do something similar to lookAhead
in esbuild?
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.
It's kind of hacky. I stash a copy of p.lexer
on the stack and then overwrite it again after backtracking has finished. I can take this PR from here and add the backtracking.
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.
To be honest, I hope we can have a more common method to do backtracking.
This PR allows:
Previously it's an error.
References: