mirror of https://github.com/vuejs/core.git
chore: refactor
This commit is contained in:
parent
39d34416cf
commit
54f1269ae3
|
@ -61,41 +61,30 @@ export function walkIdentifiers(
|
||||||
) {
|
) {
|
||||||
// mark property in destructure pattern
|
// mark property in destructure pattern
|
||||||
;(node as any).inPattern = true
|
;(node as any).inPattern = true
|
||||||
} else if (isFunctionType(node)) {
|
} else if (isFunctionType(node) && !reuseScopeIds(node, knownIds)) {
|
||||||
if (node.scopeIds) {
|
// walk function expressions and add its arguments to known identifiers
|
||||||
node.scopeIds.forEach(id => markKnownIds(id, knownIds))
|
// so that we don't prefix them
|
||||||
} else {
|
walkFunctionParams(node, id => markScopeIdentifier(node, id, knownIds))
|
||||||
// walk function expressions and add its arguments to known identifiers
|
} else if (
|
||||||
// so that we don't prefix them
|
node.type === 'BlockStatement' &&
|
||||||
walkFunctionParams(node, id =>
|
!reuseScopeIds(node, knownIds)
|
||||||
markScopeIdentifier(node, id, knownIds),
|
) {
|
||||||
)
|
// #3445 record block-level local variables
|
||||||
}
|
walkBlockDeclarations(node, id =>
|
||||||
} else if (node.type === 'BlockStatement') {
|
markScopeIdentifier(node, id, knownIds),
|
||||||
if (node.scopeIds) {
|
)
|
||||||
node.scopeIds.forEach(id => markKnownIds(id, knownIds))
|
} else if (
|
||||||
} else {
|
node.type === 'CatchClause' &&
|
||||||
// #3445 record block-level local variables
|
node.param &&
|
||||||
walkBlockDeclarations(node, id =>
|
!reuseScopeIds(node, knownIds)
|
||||||
markScopeIdentifier(node, id, knownIds),
|
) {
|
||||||
)
|
for (const id of extractIdentifiers(node.param)) {
|
||||||
}
|
markScopeIdentifier(node, id, knownIds)
|
||||||
} else if (node.type === 'CatchClause' && node.param) {
|
|
||||||
if (node.scopeIds) {
|
|
||||||
node.scopeIds.forEach(id => markKnownIds(id, knownIds))
|
|
||||||
} else {
|
|
||||||
for (const id of extractIdentifiers(node.param)) {
|
|
||||||
markScopeIdentifier(node, id, knownIds)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (isForStatement(node)) {
|
|
||||||
if (node.scopeIds) {
|
|
||||||
node.scopeIds.forEach(id => markKnownIds(id, knownIds))
|
|
||||||
} else {
|
|
||||||
walkForStatement(node, false, id =>
|
|
||||||
markScopeIdentifier(node, id, knownIds),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
} else if (isForStatement(node) && !reuseScopeIds(node, knownIds)) {
|
||||||
|
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) {
|
||||||
|
@ -112,6 +101,17 @@ export function walkIdentifiers(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function reuseScopeIds(
|
||||||
|
node: Node & { scopeIds?: Set<string> },
|
||||||
|
knownIds: Record<string, number>,
|
||||||
|
): boolean {
|
||||||
|
if (node.scopeIds) {
|
||||||
|
node.scopeIds.forEach(id => markKnownIds(id, knownIds))
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
export function isReferencedIdentifier(
|
export function isReferencedIdentifier(
|
||||||
id: Identifier,
|
id: Identifier,
|
||||||
parent: Node | null,
|
parent: Node | null,
|
||||||
|
|
Loading…
Reference in New Issue