Skip to content

Commit

Permalink
fix(ssr): transform superclass identifier (#13635)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Jun 26, 2023
1 parent c72fb9b commit c5b2c8f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
23 changes: 20 additions & 3 deletions packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts
Expand Up @@ -907,11 +907,28 @@ for (const test in tests) {

test('avoid binding ClassExpression', async () => {
const result = await ssrTransformSimple(
`import Foo, {Bar} from './foo';console.log(Foo, Bar);const obj = {foo: class Foo{}, bar: class Bar{}}`,
`
import Foo, { Bar } from './foo';
console.log(Foo, Bar);
const obj = {
foo: class Foo {},
bar: class Bar {}
}
const Baz = class extends Foo {}
`,
)
expect(result?.code).toMatchInlineSnapshot(`
"const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"./foo\\");
console.log(__vite_ssr_import_0__.default, __vite_ssr_import_0__.Bar);const obj = {foo: class Foo{}, bar: class Bar{}}"
console.log(__vite_ssr_import_0__.default, __vite_ssr_import_0__.Bar);
const obj = {
foo: class Foo {},
bar: class Bar {}
}
const Baz = class extends __vite_ssr_import_0__.default {}
"
`)
})
5 changes: 4 additions & 1 deletion packages/vite/src/node/ssr/ssrTransform.ts
Expand Up @@ -256,7 +256,10 @@ async function ssrTransformScript(
const topNode = parentStack[parentStack.length - 2]
s.prependRight(topNode.start, `const ${id.name} = ${binding};\n`)
}
} else if (parent.type !== 'ClassExpression') {
} else if (
// don't transform class name identifier
!(parent.type === 'ClassExpression' && id === parent.id)
) {
s.update(id.start, id.end, binding)
}
},
Expand Down

0 comments on commit c5b2c8f

Please sign in to comment.