Skip to content

fix: use stable swc lexer for correct asi#11555

Merged
hardfist merged 2 commits intomainfrom
fix-asi
Sep 2, 2025
Merged

fix: use stable swc lexer for correct asi#11555
hardfist merged 2 commits intomainfrom
fix-asi

Conversation

@ahabhgk
Copy link
Contributor

@ahabhgk ahabhgk commented Sep 2, 2025

Summary

The swc_ecma_parser::Lexer will output different tokens when using it in parse and .collect_vec()

For example:

import {assert} from './a'

const labelType = `${node}Label`

const node = []
assert(labelType)

In parse this 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

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings September 2, 2025 07:31
@netlify
Copy link

netlify bot commented Sep 2, 2025

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit 3665e81
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/68b6a15b7173790008ce7032

@github-actions github-actions bot added release: bug fix release: bug related release(mr only) team The issue/pr is created by the member of Rspack. labels Sep 2, 2025
Copy link
Contributor

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 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::Lexer to stable swc_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.

CPunisher
CPunisher previously approved these changes Sep 2, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Sep 2, 2025

📦 Binary Size-limit

Comparing 3665e81 to chore: release v1.5.2 (#11534) by Fy

❌ Size increased by 182.25KB from 47.14MB to 47.32MB (⬆️0.38%)

@ahabhgk ahabhgk enabled auto-merge (squash) September 2, 2025 08:04
@codspeed-hq
Copy link

codspeed-hq bot commented Sep 2, 2025

CodSpeed Performance Report

Merging #11555 will not alter performance

Comparing fix-asi (3665e81) with main (c85f843)

🎉 Hooray! codspeed-node just leveled up to 4.0.1!

A heads-up, this is a breaking change and it might affect your current performance baseline a bit. But here's the exciting part - it's packed with new, cool features and promises improved result stability 🥳!
Curious about what's new? Visit our releases page to delve into all the awesome details about this new version.

Summary

✅ 17 untouched benchmarks

@hardfist hardfist disabled auto-merge September 2, 2025 09:08
@hardfist hardfist merged commit 6e77584 into main Sep 2, 2025
44 of 46 checks passed
@hardfist hardfist deleted the fix-asi branch September 2, 2025 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: bug fix release: bug related release(mr only) team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: v1.5 compiled code reports an error when running, the same code compiled with v1.4 does not have this problem

4 participants