Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ssr): transform superclass identifier #13635

Merged
merged 1 commit into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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