fix(compiler-sfc): fix function scope variable declaration marking
This commit is contained in:
parent
bb937e9033
commit
69b4727204
@ -1389,14 +1389,12 @@ export function walkIdentifiers(
|
|||||||
if (node.body.type === 'BlockStatement') {
|
if (node.body.type === 'BlockStatement') {
|
||||||
node.body.body.forEach(p => {
|
node.body.body.forEach(p => {
|
||||||
if (p.type === 'VariableDeclaration') {
|
if (p.type === 'VariableDeclaration') {
|
||||||
;(walk as any)(p, {
|
for (const decl of p.declarations) {
|
||||||
enter(child: Node) {
|
extractIdentifiers(decl.id).forEach(id => {
|
||||||
if (child.type === 'Identifier') {
|
markScopeIdentifier(node, id, knownIds)
|
||||||
markScopeIdentifier(node, child, knownIds)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// walk function expressions and add its arguments to known identifiers
|
// walk function expressions and add its arguments to known identifiers
|
||||||
@ -1692,3 +1690,48 @@ function getObjectOrArrayExpressionKeys(value: Node): string[] {
|
|||||||
}
|
}
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function extractIdentifiers(
|
||||||
|
param: Node,
|
||||||
|
nodes: Identifier[] = []
|
||||||
|
): Identifier[] {
|
||||||
|
switch (param.type) {
|
||||||
|
case 'Identifier':
|
||||||
|
nodes.push(param)
|
||||||
|
break
|
||||||
|
|
||||||
|
case 'MemberExpression':
|
||||||
|
let object: any = param
|
||||||
|
while (object.type === 'MemberExpression') {
|
||||||
|
object = object.object
|
||||||
|
}
|
||||||
|
nodes.push(object)
|
||||||
|
break
|
||||||
|
|
||||||
|
case 'ObjectPattern':
|
||||||
|
param.properties.forEach(prop => {
|
||||||
|
if (prop.type === 'RestElement') {
|
||||||
|
extractIdentifiers(prop.argument, nodes)
|
||||||
|
} else {
|
||||||
|
extractIdentifiers(prop.value, nodes)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
break
|
||||||
|
|
||||||
|
case 'ArrayPattern':
|
||||||
|
param.elements.forEach(element => {
|
||||||
|
if (element) extractIdentifiers(element, nodes)
|
||||||
|
})
|
||||||
|
break
|
||||||
|
|
||||||
|
case 'RestElement':
|
||||||
|
extractIdentifiers(param.argument, nodes)
|
||||||
|
break
|
||||||
|
|
||||||
|
case 'AssignmentPattern':
|
||||||
|
extractIdentifiers(param.left, nodes)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
return nodes
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user