Skip to content

fix(ssr): avoid rewriting labels that collide with imports#22451

Merged
sapphi-red merged 1 commit into
vitejs:mainfrom
camc314:c/fix-ssr-transform
May 14, 2026
Merged

fix(ssr): avoid rewriting labels that collide with imports#22451
sapphi-red merged 1 commit into
vitejs:mainfrom
camc314:c/fix-ssr-transform

Conversation

@camc314
Copy link
Copy Markdown
Contributor

@camc314 camc314 commented May 14, 2026

fixes oxc-project/oxc#22412

previously,

function foo() {
    query: while (true) {
        continue query;
        break query
    }
}

would generate

function foo() {
    __vite_ssr_import_0__.query: while (true) {
        continue __vite_ssr_import_0__.query;
        break __vite_ssr_import_0__.query
    }
}

This is invalid, as the spec says:

continue [no LineTerminator here] LabelIdentifier[?Yield, ?Await] ;

LabelIdentifier is an Identifier, member expressions are not allowed.

It now generates

function foo() {
    query: while (true) {
        continue query;
        break query
    }
}

Copilot AI review requested due to automatic review settings May 14, 2026 09:35
Copy link
Copy Markdown
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 SSR import rewriting so JavaScript labels that share a name with imported bindings are not treated as import references.

Changes:

  • Excludes LabeledStatement, BreakStatement, and ContinueStatement label identifiers from SSR reference rewriting.
  • Adds regression coverage for a named import colliding with a loop label and break/continue targets.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/vite/src/node/ssr/ssrTransform.ts Updates identifier classification to ignore labels and label targets during SSR transform rewriting.
packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts Adds a regression test for imported names colliding with labels.

@sapphi-red sapphi-red added p3-minor-bug An edge case that only affects very specific usage (priority) feat: ssr labels May 14, 2026
@sapphi-red sapphi-red merged commit d9b18e0 into vitejs:main May 14, 2026
25 of 26 checks passed
@camc314 camc314 deleted the c/fix-ssr-transform branch May 14, 2026 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat: ssr p3-minor-bug An edge case that only affects very specific usage (priority)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Label having the same name with variables caused SyntaxError: Unexpected token ':'

3 participants