Skip to content

Commit

Permalink
fix: fix function name reference
Browse files Browse the repository at this point in the history
  • Loading branch information
pionxzh committed Sep 8, 2024
1 parent 25a6c7a commit abbb9fc
Show file tree
Hide file tree
Showing 8 changed files with 238 additions and 213 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
}
},
"resolutions": {
"ast-types": "npm:ast-types-x@1.17.1",
"recast": "npm:[email protected].3"
"ast-types": "npm:ast-types-x@1.18.0",
"recast": "npm:[email protected].5"
}
}
2 changes: 1 addition & 1 deletion packages/ast-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
},
"dependencies": {
"@babel/helper-validator-identifier": "^7.24.7",
"ast-types": "npm:ast-types-x@1.17.1",
"ast-types": "npm:ast-types-x@1.18.0",
"jscodeshift": "npm:[email protected]"
},
"devDependencies": {
Expand Down
6 changes: 6 additions & 0 deletions packages/ast-utils/src/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export function findReferences(
): Collection<Identifier> {
const targetScope = 'bindings' in nodeOrScope ? nodeOrScope : j(nodeOrScope).get().scope as Scope
const range = 'bindings' in nodeOrScope ? nodeOrScope.path : nodeOrScope
const rangeNode = 'node' in range ? range.node : range

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

// ignore function name that is at the top level
if (path.parent.node === rangeNode && j.FunctionDeclaration.check(path.parent.node) && path.parent.node.id === path.node) {
return false
}

if (!path.scope) return false

let scope: Scope | null = path.scope
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"lint:fix": "eslint src --fix --max-warnings=0"
},
"dependencies": {
"@babel/parser": "^7.25.0",
"ast-types": "npm:ast-types-x@1.17.1",
"@babel/parser": "^7.25.6",
"ast-types": "npm:ast-types-x@1.18.0",
"jscodeshift": "npm:[email protected]",
"pathe": "^1.1.2",
"zod": "^3.23.8"
Expand Down
10 changes: 5 additions & 5 deletions packages/unminify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@
},
"dependencies": {
"@babel/helper-validator-identifier": "^7.24.7",
"@babel/parser": "^7.25.0",
"ast-types": "npm:ast-types-x@1.17.1",
"@babel/parser": "^7.25.6",
"ast-types": "npm:ast-types-x@1.18.0",
"jscodeshift": "npm:[email protected]",
"lebab": "^3.2.4",
"pathe": "^1.1.2",
"prettier": "^2.8.8",
"zod": "^3.23.8"
},
"devDependencies": {
"@babel/core": "^7.24.9",
"@babel/core": "^7.25.2",
"@rollup/plugin-commonjs": "^26.0.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"@swc/core": "^1.7.2",
"@swc/core": "^1.7.22",
"@types/jscodeshift": "^0.11.11",
"@types/prettier": "^2.7.3",
"@types/yargs": "^17.0.32",
Expand All @@ -46,7 +46,7 @@
"@wakaru/shared": "workspace:*",
"@wakaru/test-utils": "workspace:*",
"picocolors": "^1.0.1",
"rollup": "^4.19.1",
"rollup": "^4.21.2",
"rollup-plugin-dts": "^6.1.1",
"rollup-plugin-swc3": "^0.11.2",
"typescript": "^5.5.4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,25 @@ function foo() {
`,
)

inlineTest('property destructuring - resolve naming conflicts #4',
`
function J(U) {
const B = U.children;
const G = U.className;
const J = U.description;
}
`,
`
function J(U) {
const {
children,
className,
description
} = U;
}
`,
)

inlineTest('array destructuring',
`
const t = e[0];
Expand Down
8 changes: 4 additions & 4 deletions packages/unpacker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@
},
"dependencies": {
"@babel/helper-validator-identifier": "^7.24.7",
"@babel/parser": "^7.25.0",
"ast-types": "npm:ast-types-x@1.17.1",
"@babel/parser": "^7.25.6",
"ast-types": "npm:ast-types-x@1.18.0",
"jscodeshift": "npm:[email protected]",
"pathe": "^1.1.2",
"zod": "^3.23.8"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^26.0.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"@swc/core": "^1.7.2",
"@swc/core": "^1.7.22",
"@types/jscodeshift": "^0.11.11",
"@wakaru/ast-utils": "workspace:*",
"@wakaru/shared": "workspace:*",
"@wakaru/test-utils": "workspace:*",
"rollup": "^4.18.1",
"rollup": "^4.21.2",
"rollup-plugin-dts": "^6.1.1",
"rollup-plugin-swc3": "^0.11.2",
"typescript": "^5.5.4"
Expand Down
Loading

0 comments on commit abbb9fc

Please sign in to comment.