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
|
||||
;(node as any).inPattern = true
|
||||
} else if (isFunctionType(node)) {
|
||||
if (node.scopeIds) {
|
||||
node.scopeIds.forEach(id => markKnownIds(id, knownIds))
|
||||
} else {
|
||||
// walk function expressions and add its arguments to known identifiers
|
||||
// so that we don't prefix them
|
||||
walkFunctionParams(node, id =>
|
||||
markScopeIdentifier(node, id, knownIds),
|
||||
)
|
||||
}
|
||||
} else if (node.type === 'BlockStatement') {
|
||||
if (node.scopeIds) {
|
||||
node.scopeIds.forEach(id => markKnownIds(id, knownIds))
|
||||
} else {
|
||||
// #3445 record block-level local variables
|
||||
walkBlockDeclarations(node, id =>
|
||||
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 (isFunctionType(node) && !reuseScopeIds(node, knownIds)) {
|
||||
// walk function expressions and add its arguments to known identifiers
|
||||
// so that we don't prefix them
|
||||
walkFunctionParams(node, id => markScopeIdentifier(node, id, knownIds))
|
||||
} else if (
|
||||
node.type === 'BlockStatement' &&
|
||||
!reuseScopeIds(node, knownIds)
|
||||
) {
|
||||
// #3445 record block-level local variables
|
||||
walkBlockDeclarations(node, id =>
|
||||
markScopeIdentifier(node, id, knownIds),
|
||||
)
|
||||
} else if (
|
||||
node.type === 'CatchClause' &&
|
||||
node.param &&
|
||||
!reuseScopeIds(node, knownIds)
|
||||
) {
|
||||
for (const id of extractIdentifiers(node.param)) {
|
||||
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) {
|
||||
|
@ -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(
|
||||
id: Identifier,
|
||||
parent: Node | null,
|
||||
|
|
Loading…
Reference in New Issue