mirror of https://github.com/vuejs/core.git
fix(compiler-core): fix for loop temp variable prefixing edge case caused by reused AST
This commit is contained in:
parent
ed01d92571
commit
39d34416cf
|
@ -81,13 +81,21 @@ export function walkIdentifiers(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else if (node.type === 'CatchClause' && node.param) {
|
} else if (node.type === 'CatchClause' && node.param) {
|
||||||
for (const id of extractIdentifiers(node.param)) {
|
if (node.scopeIds) {
|
||||||
markScopeIdentifier(node, id, knownIds)
|
node.scopeIds.forEach(id => markKnownIds(id, knownIds))
|
||||||
|
} else {
|
||||||
|
for (const id of extractIdentifiers(node.param)) {
|
||||||
|
markScopeIdentifier(node, id, knownIds)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (isForStatement(node)) {
|
} else if (isForStatement(node)) {
|
||||||
walkForStatement(node, false, id =>
|
if (node.scopeIds) {
|
||||||
markScopeIdentifier(node, id, knownIds),
|
node.scopeIds.forEach(id => markKnownIds(id, knownIds))
|
||||||
)
|
} else {
|
||||||
|
walkForStatement(node, false, id =>
|
||||||
|
markScopeIdentifier(node, id, knownIds),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
leave(node: Node & { scopeIds?: Set<string> }, parent: Node | null) {
|
leave(node: Node & { scopeIds?: Set<string> }, parent: Node | null) {
|
||||||
|
|
|
@ -428,6 +428,31 @@ test('prefixing edge case for reused AST', () => {
|
||||||
expect(code).not.toMatch(`_ctx.t`)
|
expect(code).not.toMatch(`_ctx.t`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('for loop prefixing edge case for reused AST', () => {
|
||||||
|
const src = `
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { Foo } from './foo'
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div @click="(event) => {
|
||||||
|
for (const item of event) {
|
||||||
|
console.log(item)
|
||||||
|
}
|
||||||
|
}"></div>
|
||||||
|
</template>
|
||||||
|
`
|
||||||
|
const { descriptor } = parse(src)
|
||||||
|
// compileScript triggers importUsageCheck
|
||||||
|
compileScript(descriptor, { id: 'xxx' })
|
||||||
|
const { code } = compileTemplate({
|
||||||
|
id: 'xxx',
|
||||||
|
filename: 'test.vue',
|
||||||
|
ast: descriptor.template!.ast,
|
||||||
|
source: descriptor.template!.content,
|
||||||
|
})
|
||||||
|
expect(code).not.toMatch(`_ctx.item`)
|
||||||
|
})
|
||||||
|
|
||||||
test('prefixing edge case for reused AST ssr mode', () => {
|
test('prefixing edge case for reused AST ssr mode', () => {
|
||||||
const src = `
|
const src = `
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
|
Loading…
Reference in New Issue