Skip to content

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

Merged
merged 1 commit into from
Jul 19, 2025
Merged

Conversation

bvanjoi
Copy link
Contributor

@bvanjoi bvanjoi commented Jul 17, 2025

No description provided.

@bvanjoi bvanjoi requested review from a team as code owners July 17, 2025 12:43
@bvanjoi bvanjoi marked this pull request as draft July 17, 2025 12:43
Copy link

changeset-bot bot commented Jul 17, 2025

⚠️ No Changeset found

Latest commit: f32db4a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

codspeed-hq bot commented Jul 17, 2025

CodSpeed Performance Report

Merging #10880 will improve performances by 3.67%

Comparing bvanjoi:parse-error (f32db4a) with dev/rust (fc680c2)1

Summary

⚡ 13 improvements
✅ 127 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
es/codegen/with-parser/colors 159.6 µs 155.4 µs +2.64%
es/parser/angular 20.4 ms 19.9 ms +2.16%
es/parser/backbone 3.2 ms 3.1 ms +2.3%
es/parser/cal-com 64.9 ms 63.1 ms +2.91%
es/parser/colors 90.8 µs 88.7 µs +2.37%
es/parser/jquery 16.5 ms 16.1 ms +2.31%
es/parser/jquery mobile 25.6 ms 25.1 ms +2.16%
es/parser/mootools 12.9 ms 12.6 ms +2.56%
es/parser/three 78.5 ms 76.7 ms +2.37%
es/parser/typescript 435 ms 425.7 ms +2.17%
es/parser/underscore 2.8 ms 2.7 ms +2.37%
es/parser/yui 12.6 ms 12.3 ms +2.3%
typescript/fast-strip 532.3 µs 513.4 µs +3.67%

Footnotes

  1. No successful run was found on dev/rust (1c6544e) during the generation of this report, so fc8dc84 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@kdy1 kdy1 added this to the Planned milestone Jul 17, 2025
@kdy1 kdy1 deleted the branch swc-project:dev/rust July 17, 2025 14:57
@kdy1 kdy1 closed this Jul 17, 2025
@magic-akari
Copy link
Member

This appears to be an unexpected closure triggered by the deletion of the target branch.

@kdy1
Copy link
Member

kdy1 commented Jul 17, 2025

Nice catch, I was wondering where did the PR go 🤣

@kdy1
Copy link
Member

kdy1 commented Jul 18, 2025

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.

Copy link

socket-security bot commented Jul 18, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​babel/​traverse@​7.22.1100257897100
Added@​types/​terser@​3.12.0681003575100
Added@​swc/​counter@​0.1.31001003978100
Addednode-releases@​2.0.131001004178100
Added@​types/​parse-json@​4.0.01001005577100
Addedis-arrayish@​0.2.11001005576100
Added@​swc/​plugin-jest@​1.5.117881005590100
Addedtmpl@​1.0.51001005776100
Added@​babel/​plugin-transform-react-jsx-development@​7.18.61001005892100
Addedhas@​1.0.31001005976100
Updatedjest-regex-util@​25.2.6 ⏵ 29.6.31001005991 -1100
Updatedjest-get-type@​25.2.6 ⏵ 29.6.310010060 +184100
Updated@​jest/​globals@​25.5.2 ⏵ 29.7.010010060 +196100
Added@​babel/​plugin-transform-unicode-regex@​7.18.61001006192100
Updatedescape-string-regexp@​2.0.0 ⏵ 1.0.510010061 -576100
Updated@​jest/​source-map@​25.5.0 ⏵ 29.6.31001006192 -1100
Added@​babel/​plugin-transform-unicode-sets-regex@​7.22.31001006292100
Added@​babel/​plugin-transform-exponentiation-operator@​7.18.61001006292100
Added@​babel/​plugin-transform-reserved-words@​7.18.61001006292100
Added@​babel/​plugin-transform-private-methods@​7.22.31001006392100
Updatedcore-util-is@​1.0.2 ⏵ 1.0.310010063 -176100
Added@​babel/​plugin-transform-sticky-regex@​7.18.61001006392100
Addedcollect-v8-coverage@​1.0.11001006376100
Added@​babel/​plugin-transform-named-capturing-groups-regex@​7.22.31001006392100
Updatedjest-resolve-dependencies@​25.5.4 ⏵ 29.7.0100 +110063 +196100
Updatedjest-environment-node@​25.5.0 ⏵ 29.7.0100 +110064 +195100
Added@​babel/​plugin-transform-property-literals@​7.18.61001006492100
Added@​babel/​plugin-transform-optional-catch-binding@​7.22.31001006492100
Added@​babel/​plugin-transform-unicode-property-regex@​7.22.31001006492100
Added@​jest/​schemas@​29.6.31001006491100
Added@​jest/​expect@​29.7.01001006496100
Added@​babel/​plugin-transform-member-expression-literals@​7.18.61001006492100
Addedstrip-final-newline@​2.0.01001006476100
See 413 more rows in the dashboard

View full report

Copy link

socket-security bot commented Jul 18, 2025

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.

Action Severity Alert (click for details)
Warn Critical
@babel/[email protected] has a Critical CVE.

CVE: GHSA-67hx-6x53-jw92 Babel vulnerable to arbitrary code execution when compiling specifically crafted malicious code (CRITICAL)

Affected versions: < 7.23.2; >= 8.0.0-alpha.0 < 8.0.0-alpha.4

Patched version: 7.23.2

From: crates/swc_ecma_minifier/yarn.locknpm/@babel/[email protected]

ℹ Read more on: This package | This alert | What is a critical CVE?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at [email protected].

Suggestion: Remove or replace dependencies that include known critical CVEs. Consumers can use dependency overrides or npm audit fix --force to remove vulnerable dependencies.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/@babel/[email protected]. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

View full report

@bvanjoi bvanjoi marked this pull request as ready for review July 18, 2025 16:45
@@ -1,11 +1,9 @@
enum Foo__2 {
name__0,
string__0
name__0
Copy link
Contributor Author

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.

@kdy1 kdy1 requested a review from Copilot July 19, 2025 13:09
Copy link

@Copilot Copilot AI left a 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 of Option<&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,
Copy link
Preview

Copilot AI Jul 19, 2025

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.

Suggested change
Self::Eof => TokenKind::Error,
Self::Eof => TokenKind::Eof,

Copilot uses AI. Check for mistakes.

@kdy1 kdy1 merged commit eb5819a into swc-project:dev/rust Jul 19, 2025
172 of 173 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants