Skip to content
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
31 changes: 31 additions & 0 deletions packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,3 +498,34 @@ objRest()
"
`)
})

test('class props', async () => {
expect(
(
await ssrTransform(
`
import { remove, add } from 'vue'

class A {
remove = 1
add = null
}
`,
null,
null
)
).code
).toMatchInlineSnapshot(`
"
const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"vue\\");


const add = __vite_ssr_import_0__.add;
const remove = __vite_ssr_import_0__.remove;
class A {
remove = 1
add = null
}
"
`)
})
6 changes: 4 additions & 2 deletions packages/vite/src/node/ssr/ssrTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export async function ssrTransform(
// 3. convert references to import bindings & import.meta references
walk(ast, {
onIdentifier(id, parent, parentStack) {
const grandparent = parentStack[parentStack.length - 2]
const binding = idToImportMap.get(id.name)
if (!binding) {
return
Expand All @@ -195,8 +196,9 @@ export async function ssrTransform(
s.appendLeft(id.end, `: ${binding}`)
}
} else if (
parent.type === 'ClassDeclaration' &&
id === parent.superClass
(parent.type === 'PropertyDefinition' &&
grandparent?.type === 'ClassBody') ||
(parent.type === 'ClassDeclaration' && id === parent.superClass)
) {
if (!declaredConst.has(id.name)) {
declaredConst.add(id.name)
Expand Down