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
18 changes: 14 additions & 4 deletions packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -860,25 +860,35 @@ test('class props', async () => {
expect(
await ssrTransformSimpleCode(
`
import { remove, add } from 'vue'
import { remove, add, update, del, call } from 'vue'

class A {
remove = 1
add = null
update = update
del = () => del()
call = call(4)
}

remove(2);
add(4);
`,
),
).toMatchInlineSnapshot(`
"const __vite_ssr_import_0__ = await __vite_ssr_import__("vue", {"importedNames":["remove","add"]});
"const __vite_ssr_import_0__ = await __vite_ssr_import__("vue", {"importedNames":["remove","add","update","del","call"]});



const add = __vite_ssr_import_0__.add;
const remove = __vite_ssr_import_0__.remove;
class A {
remove = 1
add = null
update = __vite_ssr_import_0__.update
del = () => (0,__vite_ssr_import_0__.del)()
call = (0,__vite_ssr_import_0__.call)(4)
}

(0,__vite_ssr_import_0__.remove)(2);
(0,__vite_ssr_import_0__.add)(4);
"
`)
})
Expand Down
13 changes: 9 additions & 4 deletions packages/vite/src/node/ssr/ssrTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ async function ssrTransformScript(
}
},
onIdentifier(id, parent, parentStack) {
const grandparent = parentStack[1]
const binding = idToImportMap.get(id.name)
if (!binding) {
return
Expand All @@ -360,9 +359,8 @@ async function ssrTransformScript(
s.appendLeft(id.end, `: ${binding}`)
}
} else if (
(parent.type === 'PropertyDefinition' &&
grandparent?.type === 'ClassBody') ||
(parent.type === 'ClassDeclaration' && id === parent.superClass)
parent.type === 'ClassDeclaration' &&
id === parent.superClass
) {
if (!declaredConst.has(id.name)) {
declaredConst.add(id.name)
Expand Down Expand Up @@ -680,6 +678,13 @@ function isRefIdentifier(
return false
}

// class property key
if (parent.type === 'PropertyDefinition' && !parent.computed) {
// values can still contain identifier references,
// but keys cannot unless computed.
return parent.value === id
}

// property key
if (isStaticPropertyKey(id, parent)) {
return false
Expand Down