Skip to content

Commit d9b18e0

Browse files
authored
fix(ssr): avoid rewriting labels that collide with imports (#22451)
1 parent 4f0949f commit d9b18e0

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

‎packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ test('named import: arbitrary module namespace specifier', async () => {
4949
)
5050
})
5151

52+
test('named import colliding with label', async () => {
53+
expect(
54+
await ssrTransformSimpleCode(
55+
`import { query } from 'vue';function foo() { query: while (true) { continue query; break query } }`,
56+
),
57+
).toMatchInlineSnapshot(
58+
`
59+
"const __vite_ssr_import_0__ = await __vite_ssr_import__("vue", {"importedNames":["query"]});
60+
function foo() { query: while (true) { continue query; break query } }"
61+
`,
62+
)
63+
})
64+
5265
test('namespace import', async () => {
5366
expect(
5467
await ssrTransformSimpleCode(

‎packages/vite/src/node/ssr/ssrTransform.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,16 @@ function isRefIdentifier(
712712
return false
713713
}
714714

715+
// label declaration or break/continue target
716+
if (
717+
(parent.type === 'LabeledStatement' ||
718+
parent.type === 'BreakStatement' ||
719+
parent.type === 'ContinueStatement') &&
720+
parent.label === id
721+
) {
722+
return false
723+
}
724+
715725
// meta property (e.g. import.meta)
716726
if (parent.type === 'MetaProperty') {
717727
return false

0 commit comments

Comments
 (0)