Skip to content

Commit

Permalink
fix(smart-rename): name of useRef should not need pascalCase
Browse files Browse the repository at this point in the history
  • Loading branch information
pionxzh committed Jul 6, 2024
1 parent 548f121 commit 0e586d5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions packages/ast-utils/src/case.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/**
* PascalCase
*
* @example
* pascalCase('foo') // Foo
* pascalCase('foo-bar') // FooBar
* pascalCase('foo_bar') // FooBar
*/
export function pascalCase(str: string): string {
return str.replace(/(?:^|[-_])(\w)/g, (_, c) => c.toUpperCase())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,14 @@ const d = useRef();
const ef = o.useRef(null);
const g = o.useRef(a, b); // invalid parameters
const ButtonRef = o.useRef(null); // name is not minified
const buttonRef = o.useRef(null); // name is not minified
`,
`
const DRef = useRef();
const EfRef = o.useRef(null);
const dRef = useRef();
const efRef = o.useRef(null);
const g = o.useRef(a, b); // invalid parameters
const ButtonRef = o.useRef(null); // name is not minified
const buttonRef = o.useRef(null); // name is not minified
`,
)

Expand Down
2 changes: 1 addition & 1 deletion packages/unminify/src/transformations/smart-rename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ function handleReactRename(j: JSCodeshift, root: Collection) {

// rename the identifier
const oldName = id.name
const newName = generateName(`${pascalCase(oldName)}Ref`, scope)
const newName = generateName(`${oldName}Ref`, scope)
renameIdentifier(j, scope, oldName, newName)
})

Expand Down

0 comments on commit 0e586d5

Please sign in to comment.