Skip to content

Don't rename member and label names in renameTo - #767

Open
0z5a wants to merge 1 commit into
meta:mainfrom
0z5a:renameto-member-names
Open

0z5a wants to merge 1 commit into
meta:mainfrom
0z5a:renameto-member-names

Conversation

@0z5a

@0z5a 0z5a commented Nov 18, 2026

Copy link
Copy Markdown

Fixes #766.

Summary

renameTo collects every Identifier with the old name in the declaring scope and drops the ones in known non-variable positions. This adds the positions that were missing from that list:

  • TSPropertySignature, TSMethodSignature, TSDeclareMethod, ClassAccessorProperty and Flow ObjectTypeProperty keys, when not computed
  • TSEnumMember.id
  • TSQualifiedName.right
  • any Identifier under PrivateName or MetaProperty
  • the label of LabeledStatement, BreakStatement and ContinueStatement

The new checks sit as one block after the existing ones and follow the same style. Computed keys ({ [name]: number }) and typeof name in a type are still renamed, and the tests check both.

This doesn't touch shorthand properties or export specifiers, which #752 and #756 are about; that should keep it from conflicting with the open PRs for those, apart from both adding tests at the end of the same describe.

How I found it

I was reading the filter in src/collections/VariableDeclarator.js and compared the parent types it skips against the places Babel and the TS parser put an Identifier that names a member, not a binding. I then ran findVariableDeclarators(x).renameTo(...) on small inputs with the ts, tsx, babylon and flow parsers for each candidate position. The positions above were all renamed on main. obj?.name was already handled by the MemberExpression check.

Where this can show up in practice

This is my estimate; I have not seen a field report.

  • TypeScript codemods that rename a local which shares its name with a field of an interface or type alias in the same file (const config = ...; interface Props { config: Config }). The type silently changes shape, and it only shows up later as type errors at use sites, or not at all if the type isn't used in that file.
  • Renaming a variable called meta in Storybook CSF files (const meta = {...}; export default meta;) that also use import.meta. The output doesn't parse anymore. Same for a variable called target next to new.target.
  • Enum members and E.A type references: the enum member is renamed but E.A value accesses are not, so the code refers to a member that no longer exists.

Test

Added six tests under identifiers that are member or label names in src/collections/__tests__/VariableDeclarator-test.js, using the ts, flow and babylon parsers. Each compares the printed output and includes a real reference that must still be renamed.

On macOS, node 24:

  • npx jest src/collections/__tests__/VariableDeclarator-test.js with only the test file changed: 6 failed, 15 passed
  • with the fix: 21 passed
  • npx jest: 19 suites, 227 passed, 1 skipped
  • npx eslint on the two changed files: clean (I passed --parser-options=requireConfigFile:false, since eslint couldn't find a Babel config otherwise)

Not run: Linux, other Node versions, and the CI workflows.

A changeset is included as .changeset/rename-to-member-names.md.

renameTo renamed identifiers that are member or label names rather than
references to the variable: TypeScript interface and type literal
members, abstract/overload methods and accessor fields, enum members,
the right side of qualified type names, Flow object type members,
private names, import.meta / new.target, and statement labels.

Refs meta#766
@vercel

vercel Bot commented Nov 18, 2026

Copy link
Copy Markdown

@0z5a is attempting to deploy a commit to the Meta Open Source Team on Vercel.

A member of the Team first needs to authorize it.

@meta-cla meta-cla Bot added the CLA Signed label Nov 18, 2026
@changeset-bot

changeset-bot Bot commented Nov 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 872e2e1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
jscodeshift Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

renameTo renames TypeScript interface members, import.meta, new.target and other member names

1 participant