Skip to content

Commit b457df0

Browse files
committed
chore: reuse analyzed scopeIds when possible
1 parent 47c7af9 commit b457df0

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,6 @@ describe('compiler: expression transform', () => {
717717
})
718718
})
719719

720-
// Test for switch case variable declarations bug fix
721720
describe('switch case variable declarations', () => {
722721
test('should handle const declarations in switch case without braces', () => {
723722
const { code } = compile(

packages/compiler-core/src/babelUtils.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,21 @@ export function walkIdentifiers(
9292
)
9393
}
9494
} else if (node.type === 'CatchClause' && node.param) {
95-
for (const id of extractIdentifiers(node.param)) {
96-
markScopeIdentifier(node, id, knownIds)
95+
if (node.scopeIds) {
96+
node.scopeIds.forEach(id => markKnownIds(id, knownIds))
97+
} else {
98+
for (const id of extractIdentifiers(node.param)) {
99+
markScopeIdentifier(node, id, knownIds)
100+
}
97101
}
98102
} else if (isForStatement(node)) {
99-
walkForStatement(node, false, id =>
100-
markScopeIdentifier(node, id, knownIds),
101-
)
103+
if (node.scopeIds) {
104+
node.scopeIds.forEach(id => markKnownIds(id, knownIds))
105+
} else {
106+
walkForStatement(node, false, id =>
107+
markScopeIdentifier(node, id, knownIds),
108+
)
109+
}
102110
}
103111
},
104112
leave(node: Node & { scopeIds?: Set<string> }, parent: Node | null) {

0 commit comments

Comments
 (0)