-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
refactor(es/lexer): token eof #10880
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
Conversation
|
CodSpeed Performance ReportMerging #10880 will improve performances by 3.67%Comparing Summary
Benchmarks breakdown
Footnotes |
This appears to be an unexpected closure triggered by the deletion of the target branch. |
Nice catch, I was wondering where did the PR go 🤣 |
I think this is a good improvement. What matters is the performance of the parser. It seems like this PR moves some work of the parser to the lexer, but the total work done by the parser is reduced. |
Warning Review the following alerts detected in dependencies. According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.
|
@@ -1,11 +1,9 @@ | |||
enum Foo__2 { | |||
name__0, | |||
string__0 | |||
name__0 |
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 think this change is acceptable because the input(ts_resolver_nested_enum
) contains invalid syntax.
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.
Pull Request Overview
This pull request refactors the ECMAScript lexer to introduce an explicit EOF (End of File) token rather than using None
/Option
to represent the end of input. This is a significant architectural change that makes EOF handling more explicit and consistent throughout the parser.
- Introduces a new
Token::Eof
variant in both swc_ecma_parser and swc_ecma_lexer crates - Refactors token handling to use
&Token
instead ofOption<&Token>
for current token access - Updates parser initialization to consume the initial EOF token and ensures proper EOF handling at the end of parsing
Reviewed Changes
Copilot reviewed 73 out of 83 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
crates/swc_ecma_parser/src/lexer/token.rs | Adds Eof token variant and implements necessary token factory methods |
crates/swc_ecma_parser/src/parser/input.rs | Major refactor to use TokenAndSpan directly instead of Option<TokenAndSpan> |
crates/swc_ecma_parser/src/parser/mod.rs | Updates parser initialization and ensures EOF consumption after parsing |
crates/swc_ecma_lexer/src/token.rs | Adds Eof token variant to lexer token enum |
crates/swc_ecma_lexer/src/lexer/table.rs | Updates byte handlers to return Token instead of Option<Token> |
Multiple parser files | Updates throughout to handle explicit EOF token instead of None checks |
@@ -956,6 +967,7 @@ impl Token { | |||
Self::JSXTagEnd => TokenKind::JSXTagEnd, | |||
Self::Shebang(..) => TokenKind::Shebang, | |||
Self::Error(..) => TokenKind::Error, | |||
Self::Eof => TokenKind::Error, |
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.
EOF token should not map to TokenKind::Error. This creates semantic confusion as EOF is a valid end-of-input state, not an error condition. Consider creating a dedicated TokenKind::Eof or mapping to a more appropriate kind.
Self::Eof => TokenKind::Error, | |
Self::Eof => TokenKind::Eof, |
Copilot uses AI. Check for mistakes.
No description provided.