diff --git a/packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts b/packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts index ac47c732fdaa60..47b94f8179b7e5 100644 --- a/packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts +++ b/packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts @@ -49,6 +49,19 @@ test('named import: arbitrary module namespace specifier', async () => { ) }) +test('named import colliding with label', async () => { + expect( + await ssrTransformSimpleCode( + `import { query } from 'vue';function foo() { query: while (true) { continue query; break query } }`, + ), + ).toMatchInlineSnapshot( + ` + "const __vite_ssr_import_0__ = await __vite_ssr_import__("vue", {"importedNames":["query"]}); + function foo() { query: while (true) { continue query; break query } }" + `, + ) +}) + test('namespace import', async () => { expect( await ssrTransformSimpleCode( diff --git a/packages/vite/src/node/ssr/ssrTransform.ts b/packages/vite/src/node/ssr/ssrTransform.ts index 927661424a0c28..bdb0f42802ca45 100644 --- a/packages/vite/src/node/ssr/ssrTransform.ts +++ b/packages/vite/src/node/ssr/ssrTransform.ts @@ -712,6 +712,16 @@ function isRefIdentifier( return false } + // label declaration or break/continue target + if ( + (parent.type === 'LabeledStatement' || + parent.type === 'BreakStatement' || + parent.type === 'ContinueStatement') && + parent.label === id + ) { + return false + } + // meta property (e.g. import.meta) if (parent.type === 'MetaProperty') { return false