Skip to content

Commit

Permalink
fix(ssr): ssr transform method definition (#2223)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjk authored Feb 26, 2021
1 parent 1342108 commit 8e0c0fa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@ test('import.meta', async () => {
).toMatchInlineSnapshot(`"console.log(__vite_ssr_import_meta__.url)"`)
})

test('do not rewrite method definition', async () => {
expect(
(
await ssrTransform(
`import { fn } from 'vue';class A { fn() { fn() } }`,
null
)
).code
).toMatchInlineSnapshot(`
"const __vite_ssr_import_0__ = __vite_ssr_import__(\\"vue\\")
class A { fn() { __vite_ssr_import_0__.fn() } }"
`)
})

test('dynamic import', async () => {
expect(
(await ssrTransform(`export const i = () => import('./foo')`, null)).code
Expand Down
5 changes: 5 additions & 0 deletions packages/vite/src/node/ssr/ssrTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,11 @@ function isRefIdentifier(id: Identifier, parent: _Node, parentStack: _Node[]) {
return false
}
}

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

// property key
// this also covers object destructure pattern
Expand Down

0 comments on commit 8e0c0fa

Please sign in to comment.