Skip to content

Commit b89974a

Browse files
authored
fix(ssr): rewrite dynamic class method name (fix #7751) (#7757)
1 parent 1f2ca53 commit b89974a

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts

+39
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,45 @@ class A {
545545
`)
546546
})
547547

548+
test('class methods', async () => {
549+
expect(
550+
(
551+
await ssrTransform(
552+
`
553+
import foo from 'foo'
554+
555+
const bar = 'bar'
556+
557+
class A {
558+
foo() {}
559+
[foo]() {}
560+
[bar]() {}
561+
#foo() {}
562+
bar(foo) {}
563+
}
564+
`,
565+
null,
566+
null
567+
)
568+
).code
569+
).toMatchInlineSnapshot(`
570+
"
571+
const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"foo\\");
572+
573+
574+
const bar = 'bar'
575+
576+
class A {
577+
foo() {}
578+
[__vite_ssr_import_0__.default]() {}
579+
[bar]() {}
580+
#foo() {}
581+
bar(foo) {}
582+
}
583+
"
584+
`)
585+
})
586+
548587
test('declare scope', async () => {
549588
expect(
550589
(

packages/vite/src/node/ssr/ssrTransform.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ function isRefIdentifier(id: Identifier, parent: _Node, parentStack: _Node[]) {
429429
}
430430

431431
// class method name
432-
if (parent.type === 'MethodDefinition') {
432+
if (parent.type === 'MethodDefinition' && !parent.computed) {
433433
return false
434434
}
435435

0 commit comments

Comments
 (0)