Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(reactivity-transform): should not rewrite catch param #5711

Merged
merged 2 commits into from Apr 14, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -216,6 +216,11 @@ exports[`should not rewrite scope variable 1`] = `
console.log(d.value)
console.log(e)
}
let err = _ref(null)
try {
} catch (err) {
console.log(err)
}
"
`;

Expand Down
Expand Up @@ -222,12 +222,18 @@ test('should not rewrite scope variable', () => {
console.log(d)
console.log(e)
}
let err = $ref(null)
try {
} catch (err) {
console.log(err)
}
`)
expect(code).toMatch('console.log(a)')
expect(code).toMatch('console.log(b.value)')
expect(code).toMatch('console.log(c)')
expect(code).toMatch('console.log(d.value)')
expect(code).toMatch('console.log(e)')
expect(code).toMatch('console.log(err)')
assertCode(code)
})

Expand Down
10 changes: 10 additions & 0 deletions packages/reactivity-transform/src/reactivityTransform.ts
Expand Up @@ -566,6 +566,16 @@ export function transformAST(
return
}

// catch param
if (node.type === 'CatchClause') {
scopeStack.push((currentScope = {}))
if (node.param && node.param.type === 'Identifier') {
registerBinding(node.param)
}
walkScope(node.body)
return
}

// non-function block scopes
if (node.type === 'BlockStatement' && !isFunctionType(parent!)) {
scopeStack.push((currentScope = {}))
Expand Down