Skip to content

Commit abbb9fc

Browse files
committed
fix: fix function name reference
1 parent 25a6c7a commit abbb9fc

File tree

8 files changed

+238
-213
lines changed

8 files changed

+238
-213
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
}
4545
},
4646
"resolutions": {
47-
"ast-types": "npm:ast-types-x@1.17.1",
48-
"recast": "npm:[email protected].3"
47+
"ast-types": "npm:ast-types-x@1.18.0",
48+
"recast": "npm:[email protected].5"
4949
}
5050
}

packages/ast-utils/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
},
4545
"dependencies": {
4646
"@babel/helper-validator-identifier": "^7.24.7",
47-
"ast-types": "npm:ast-types-x@1.17.1",
47+
"ast-types": "npm:ast-types-x@1.18.0",
4848
"jscodeshift": "npm:[email protected]"
4949
},
5050
"devDependencies": {

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/shared/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
"lint:fix": "eslint src --fix --max-warnings=0"
3131
},
3232
"dependencies": {
33-
"@babel/parser": "^7.25.0",
34-
"ast-types": "npm:ast-types-x@1.17.1",
33+
"@babel/parser": "^7.25.6",
34+
"ast-types": "npm:ast-types-x@1.18.0",
3535
"jscodeshift": "npm:[email protected]",
3636
"pathe": "^1.1.2",
3737
"zod": "^3.23.8"

packages/unminify/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@
2525
},
2626
"dependencies": {
2727
"@babel/helper-validator-identifier": "^7.24.7",
28-
"@babel/parser": "^7.25.0",
29-
"ast-types": "npm:ast-types-x@1.17.1",
28+
"@babel/parser": "^7.25.6",
29+
"ast-types": "npm:ast-types-x@1.18.0",
3030
"jscodeshift": "npm:[email protected]",
3131
"lebab": "^3.2.4",
3232
"pathe": "^1.1.2",
3333
"prettier": "^2.8.8",
3434
"zod": "^3.23.8"
3535
},
3636
"devDependencies": {
37-
"@babel/core": "^7.24.9",
37+
"@babel/core": "^7.25.2",
3838
"@rollup/plugin-commonjs": "^26.0.1",
3939
"@rollup/plugin-node-resolve": "^15.2.3",
40-
"@swc/core": "^1.7.2",
40+
"@swc/core": "^1.7.22",
4141
"@types/jscodeshift": "^0.11.11",
4242
"@types/prettier": "^2.7.3",
4343
"@types/yargs": "^17.0.32",
@@ -46,7 +46,7 @@
4646
"@wakaru/shared": "workspace:*",
4747
"@wakaru/test-utils": "workspace:*",
4848
"picocolors": "^1.0.1",
49-
"rollup": "^4.19.1",
49+
"rollup": "^4.21.2",
5050
"rollup-plugin-dts": "^6.1.1",
5151
"rollup-plugin-swc3": "^0.11.2",
5252
"typescript": "^5.5.4"

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];

packages/unpacker/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@
2525
},
2626
"dependencies": {
2727
"@babel/helper-validator-identifier": "^7.24.7",
28-
"@babel/parser": "^7.25.0",
29-
"ast-types": "npm:ast-types-x@1.17.1",
28+
"@babel/parser": "^7.25.6",
29+
"ast-types": "npm:ast-types-x@1.18.0",
3030
"jscodeshift": "npm:[email protected]",
3131
"pathe": "^1.1.2",
3232
"zod": "^3.23.8"
3333
},
3434
"devDependencies": {
3535
"@rollup/plugin-commonjs": "^26.0.1",
3636
"@rollup/plugin-node-resolve": "^15.2.3",
37-
"@swc/core": "^1.7.2",
37+
"@swc/core": "^1.7.22",
3838
"@types/jscodeshift": "^0.11.11",
3939
"@wakaru/ast-utils": "workspace:*",
4040
"@wakaru/shared": "workspace:*",
4141
"@wakaru/test-utils": "workspace:*",
42-
"rollup": "^4.18.1",
42+
"rollup": "^4.21.2",
4343
"rollup-plugin-dts": "^6.1.1",
4444
"rollup-plugin-swc3": "^0.11.2",
4545
"typescript": "^5.5.4"

0 commit comments

Comments
 (0)