Conversation
✅ Deploy Preview for rspack canceled.
|
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug in the SWC lexer usage that was causing incorrect automatic semicolon insertion (ASI) behavior. The unstable swc_ecma_parser::Lexer produces different tokens when used in parse versus .collect_vec(), leading to lexing errors for template literals and incorrect semicolon placement.
Key changes:
- Switch from unstable
swc_ecma_parser::Lexerto stableswc_ecma_lexer::Lexer - Update token imports to use the stable lexer's token types
- Add test case to verify correct handling of template literals and ASI
Reviewed Changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/rspack_plugin_javascript/Cargo.toml | Add dependency on stable swc_ecma_lexer crate |
| crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs | Switch lexer instantiation to use stable swc_ecma_lexer |
| crates/rspack_plugin_javascript/src/visitors/semicolon.rs | Update token imports to use stable lexer types |
| packages/rspack-test-tools/tests/normalCases/parsing/asi/index.js | Add test case for template literal ASI behavior |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
📦 Binary Size-limit
❌ Size increased by 182.25KB from 47.14MB to 47.32MB (⬆️0.38%) |
CodSpeed Performance ReportMerging #11555 will not alter performanceComparing 🎉 Hooray!
|
Summary
The
swc_ecma_parser::Lexerwill output different tokens when using it inparseand.collect_vec()For example:
In
parsethis will have correct tokens, but using with.collect_vec()it will have a lexing error:Error { error: (60..97, UnterminatedTpl) }And the lexing error causes rspack collected the wrong semicolons (which is used for adding semicolons before replaced dependency to generate the correct code)
So this PR switch to the stable
swc_ecma_lexer::Lexer.Related links
fix #11551
A better solution is using SWC's API swc-project/swc#11053
Checklist