Skip to content

Commit 48feaba

Browse files
committed
fix: fix function name reference
1 parent 091c68c commit 48feaba

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

packages/ast-utils/src/reference.ts

+6
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ export function findReferences(
171171
): Collection<Identifier> {
172172
const targetScope = 'bindings' in nodeOrScope ? nodeOrScope : j(nodeOrScope).get().scope as Scope
173173
const range = 'bindings' in nodeOrScope ? nodeOrScope.path : nodeOrScope
174+
const rangeNode = 'node' in range ? range.node : range
174175

175176
return j(range)
176177
.find(j.Identifier, { name: identifierName })
@@ -179,6 +180,11 @@ export function findReferences(
179180
// ignore properties (e.g. in MemberExpression
180181
if (path.name === 'property' && j.MemberExpression.check(path.parent.node) && !path.parent.node.computed) return false
181182

183+
// ignore function name that is at the top level
184+
if (path.parent.node === rangeNode && j.FunctionDeclaration.check(path.parent.node) && path.parent.node.id === path.node) {
185+
return false
186+
}
187+
182188
if (!path.scope) return false
183189

184190
let scope: Scope | null = path.scope

packages/unminify/src/transformations/__tests__/smart-inline.spec.ts

+19
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,25 @@ function foo() {
323323
`,
324324
)
325325

326+
inlineTest('property destructuring - resolve naming conflicts #4',
327+
`
328+
function J(U) {
329+
const B = U.children;
330+
const G = U.className;
331+
const J = U.description;
332+
}
333+
`,
334+
`
335+
function J(U) {
336+
const {
337+
children,
338+
className,
339+
description
340+
} = U;
341+
}
342+
`,
343+
)
344+
326345
inlineTest('array destructuring',
327346
`
328347
const t = e[0];

0 commit comments

Comments
 (0)