Skip to content

Commit

Permalink
fix(ssr): fix ssrTransform catch clause error (fix #2667) (#2966)
Browse files Browse the repository at this point in the history
  • Loading branch information
leemove committed Apr 13, 2021
1 parent 705a2b3 commit c9e0bcf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
15 changes: 15 additions & 0 deletions packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,21 @@ test('do not rewrite method definition', async () => {
`)
})

test('do not rewrite catch clause', async () => {
expect(
(
await ssrTransform(
`import {error} from './dependency';try {} catch(error) {}`,
null,
null
)
).code
).toMatchInlineSnapshot(`
"const __vite_ssr_import_0__ = __vite_ssr_import__(\\"./dependency\\")
try {} catch(error) {}"
`)
})

// #2221
test('should declare variable for imported super class', async () => {
expect(
Expand Down
5 changes: 3 additions & 2 deletions packages/vite/src/node/ssr/ssrTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,10 @@ function walk(
function isRefIdentifier(id: Identifier, parent: _Node, parentStack: _Node[]) {
// declaration id
if (
(parent.type === 'VariableDeclarator' ||
parent.type === 'CatchClause' ||
((parent.type === 'VariableDeclarator' ||
parent.type === 'ClassDeclaration') &&
parent.id === id
parent.id === id)
) {
return false
}
Expand Down

0 comments on commit c9e0bcf

Please sign in to comment.