mirror of https://github.com/vuejs/core.git
Merge 891d80631a
into ba391f5fdf
This commit is contained in:
commit
57b653dffd
|
@ -1,4 +1,9 @@
|
||||||
import type { ExpressionNode, TransformContext } from '../src'
|
import { babelParse, walkIdentifiers } from '@vue/compiler-sfc'
|
||||||
|
import {
|
||||||
|
type ExpressionNode,
|
||||||
|
type TransformContext,
|
||||||
|
isReferencedIdentifier,
|
||||||
|
} from '../src'
|
||||||
import { type Position, createSimpleExpression } from '../src/ast'
|
import { type Position, createSimpleExpression } from '../src/ast'
|
||||||
import {
|
import {
|
||||||
advancePositionWithClone,
|
advancePositionWithClone,
|
||||||
|
@ -115,3 +120,18 @@ test('toValidAssetId', () => {
|
||||||
'_component_test_2797935797_1',
|
'_component_test_2797935797_1',
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('isReferencedIdentifier', () => {
|
||||||
|
test('identifiers in function parameters should not be inferred as references', () => {
|
||||||
|
expect.assertions(4)
|
||||||
|
const ast = babelParse(`(({ title }) => [])`)
|
||||||
|
walkIdentifiers(
|
||||||
|
ast.program.body[0],
|
||||||
|
(node, parent, parentStack, isReference) => {
|
||||||
|
expect(isReference).toBe(false)
|
||||||
|
expect(isReferencedIdentifier(node, parent, parentStack)).toBe(false)
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
|
@ -122,7 +122,7 @@ export function isReferencedIdentifier(
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isReferenced(id, parent)) {
|
if (isReferenced(id, parent, parentStack[parentStack.length - 2])) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +132,8 @@ export function isReferencedIdentifier(
|
||||||
case 'AssignmentExpression':
|
case 'AssignmentExpression':
|
||||||
case 'AssignmentPattern':
|
case 'AssignmentPattern':
|
||||||
return true
|
return true
|
||||||
case 'ObjectPattern':
|
case 'ObjectProperty':
|
||||||
|
return parent.key !== id && isInDestructureAssignment(parent, parentStack)
|
||||||
case 'ArrayPattern':
|
case 'ArrayPattern':
|
||||||
return isInDestructureAssignment(parent, parentStack)
|
return isInDestructureAssignment(parent, parentStack)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue