Skip to content

Commit 9b02923

Browse files
authored
fix(compiler-core): identifiers in function parameters should not be inferred as references (#13548)
1 parent d8e40ef commit 9b02923

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

packages/compiler-core/__tests__/utils.spec.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import type { ExpressionNode, TransformContext } from '../src'
1+
import { babelParse, walkIdentifiers } from '@vue/compiler-sfc'
2+
import {
3+
type ExpressionNode,
4+
type TransformContext,
5+
isReferencedIdentifier,
6+
} from '../src'
27
import { type Position, createSimpleExpression } from '../src/ast'
38
import {
49
advancePositionWithClone,
@@ -115,3 +120,18 @@ test('toValidAssetId', () => {
115120
'_component_test_2797935797_1',
116121
)
117122
})
123+
124+
describe('isReferencedIdentifier', () => {
125+
test('identifiers in function parameters should not be inferred as references', () => {
126+
expect.assertions(4)
127+
const ast = babelParse(`(({ title }) => [])`)
128+
walkIdentifiers(
129+
ast.program.body[0],
130+
(node, parent, parentStack, isReference) => {
131+
expect(isReference).toBe(false)
132+
expect(isReferencedIdentifier(node, parent, parentStack)).toBe(false)
133+
},
134+
true,
135+
)
136+
})
137+
})

packages/compiler-core/src/babelUtils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export function isReferencedIdentifier(
122122
return false
123123
}
124124

125-
if (isReferenced(id, parent)) {
125+
if (isReferenced(id, parent, parentStack[parentStack.length - 2])) {
126126
return true
127127
}
128128

@@ -132,7 +132,8 @@ export function isReferencedIdentifier(
132132
case 'AssignmentExpression':
133133
case 'AssignmentPattern':
134134
return true
135-
case 'ObjectPattern':
135+
case 'ObjectProperty':
136+
return parent.key !== id && isInDestructureAssignment(parent, parentStack)
136137
case 'ArrayPattern':
137138
return isInDestructureAssignment(parent, parentStack)
138139
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy