Repository navigation
Conversation
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
|
@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. |
🦋 Changeset detectedLatest commit: 872e2e1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #766.
Summary
renameTocollects everyIdentifierwith 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,ClassAccessorPropertyand FlowObjectTypePropertykeys, when not computedTSEnumMember.idTSQualifiedName.rightIdentifierunderPrivateNameorMetaPropertylabelofLabeledStatement,BreakStatementandContinueStatementThe new checks sit as one block after the existing ones and follow the same style. Computed keys (
{ [name]: number }) andtypeof namein 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.jsand compared the parent types it skips against the places Babel and the TS parser put anIdentifierthat names a member, not a binding. I then ranfindVariableDeclarators(x).renameTo(...)on small inputs with thets,tsx,babylonandflowparsers for each candidate position. The positions above were all renamed onmain.obj?.namewas already handled by theMemberExpressioncheck.Where this can show up in practice
This is my estimate; I have not seen a field report.
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.metain Storybook CSF files (const meta = {...}; export default meta;) that also useimport.meta. The output doesn't parse anymore. Same for a variable calledtargetnext tonew.target.E.Atype references: the enum member is renamed butE.Avalue 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 namesinsrc/collections/__tests__/VariableDeclarator-test.js, using thets,flowandbabylonparsers. 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.jswith only the test file changed: 6 failed, 15 passednpx jest: 19 suites, 227 passed, 1 skippednpx eslinton 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.