Skip to content

Commit

Permalink
fix(ssr): rewrite dynamic class method name (fix #7751) (#7757)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Apr 15, 2022
1 parent 1f2ca53 commit b89974a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
39 changes: 39 additions & 0 deletions packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,45 @@ class A {
`)
})

test('class methods', async () => {
expect(
(
await ssrTransform(
`
import foo from 'foo'
const bar = 'bar'
class A {
foo() {}
[foo]() {}
[bar]() {}
#foo() {}
bar(foo) {}
}
`,
null,
null
)
).code
).toMatchInlineSnapshot(`
"
const __vite_ssr_import_0__ = await __vite_ssr_import__(\\"foo\\");
const bar = 'bar'
class A {
foo() {}
[__vite_ssr_import_0__.default]() {}
[bar]() {}
#foo() {}
bar(foo) {}
}
"
`)
})

test('declare scope', async () => {
expect(
(
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/ssr/ssrTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ function isRefIdentifier(id: Identifier, parent: _Node, parentStack: _Node[]) {
}

// class method name
if (parent.type === 'MethodDefinition') {
if (parent.type === 'MethodDefinition' && !parent.computed) {
return false
}

Expand Down

0 comments on commit b89974a

Please sign in to comment.