Rename node name attribute to identifier - #1162
lorisleiva wants to merge 1 commit into
Conversation
|
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
trevor-cortex
left a comment
There was a problem hiding this comment.
Summary
Mechanical name → identifier rename across hand-written src/ in the dynamic-*, nodes-from-anchor, validators, visitors-core and visitors packages. I went through all 87 files: every changed line is a faithful 1:1 swap, the update*Visitor config reads (updates.identifier, argUpdate.identifier) line up with the Partial<…NodeInput> types, and the value-node/link-node accesses I spot-checked (accountValueNode, accountBumpValueNode, pdaSeedValueNode, link nodes) all have identifier: IdentifierString in the regenerated @codama/node-types. Removed-node branches (argumentValueNode, resolverValueNode, instructionArgumentLinkNode) are consistently left on .name as described. Formatter re-wraps look right.
Two in-scope misses the TS check can't catch
The completeness claim in the description rests on 'name' does not exist compiler errors. There are two places that use the 'name' in node narrowing pattern, which compiles cleanly against the v2 Node union but silently returns false at runtime for every node:
-
packages/visitors-core/src/NodeSelector.ts~L36 —if (name && (!('name' in node) || camelCase(name) !== node.name)). This means every name-bearing selector ([programNode]foo,[errorNode]${name},[definedTypeNode]bar, theselectorargument ofupdateAccountsVisitor/updateDefinedTypesVisitor/updateProgramsVisitor,deleteNodesVisitor, …) will match nothing. Several files in this very PR now build selectors from.identifier(deduplicateIdenticalDefinedTypesVisitor,addPdasVisitor,updateAccountsVisitor) and would be no-ops. Needs'identifier' in node/node.identifier. (Separately, and for a follow-up rather than this PR:camelCase(name) !== node.identifierwill also need a decision now that v2 identifiers aren't camelCase-normalised — case-fold/underscore-strip compare per the brand docstring, or normalise both sides.) -
packages/visitors-core/src/getDebugStringVisitor.ts~L115 — thedefault:branchreturn 'name' in node ? [node.name] : [];. This is the generic fallback that prints the name foraccountNode,instructionNode,definedTypeNode,pdaNode,structFieldTypeNode, enum variants,variablePdaSeedNode,accountValueNode,pdaSeedValueNode, etc. — i.e. most of the debug output. Same fix. (Anchored a nit on the link-node branch a few lines above.)
Worth a quick rg "'name' in" across packages/*/src to confirm those are the only two.
Notes for the description / follow-ups
instructionArgumentNodeis also a removed node in v2 —InstructionNodenow carriesdata?: TypeNodeand there's noInstructionArgumentNodein@codama/node-types(the remainingpackages/nodes/src/InstructionArgumentNode.tshelper imports a type that no longer exists). This PR still renamesname:→identifier:oninstructionArgumentNode({...})constructions andix.arguments[].namereads (nodes-from-anchorInstructionNode.ts/InstructionArgumentNode.ts,createSubInstructionsFromEnumArgsVisitor,setInstructionDiscriminatorsVisitor,updateInstructionsVisitor,resolve-standalone-pda,encode-instruction-arguments, …). That's harmless — those sites will become struct fields, which do useidentifier— but it's not in the description's renamed-kinds list and doesn't fit the "removed-node branches are left untouched" rule either. Might be worth a line in the description so the per-package PRs don't treat them as done.- Other non-rename shape changes I noticed while cross-checking, all correctly out of scope here but easy to lose track of:
fieldDiscriminatorNode.name→path(dynamic-parsers/discriminators.ts,getDebugStringVisitor,nodes-from-anchorfieldDiscriminatorNode('discriminator'));accountFieldValueNode→accountDataValueNode(resolve-consumed-members.ts,resolve-injected-value.ts).
For subsequent reviewers
Nothing else needs deep attention — this is the rename it says it is. Once the two 'name' in node sites are fixed I'm happy to approve.
3ac2a18 to
2804f7e
Compare

Phase D, mechanical opener. Renames the v2
namenode attribute toidentifieracross all hand-written package source — a 1:1 rename with no behavioural changes.Stacked on #1158 (the v2 regeneration base).
What changed
.namemember accesses on renamed node kinds →.identifier(programNode, accountNode, instructionNode, errorNode, eventNode, pdaNode, constantNode, definedTypeNode, instructionAccountNode, instructionRemainingAccountsNode, providedNode, structFieldTypeNode, enumVariantTypeNode, variablePdaSeedNode, the value nodes, and all link nodes).name:object-literal keys constructing those nodes →identifier:.update*Visitorconfig reads (updates.name,argUpdate.name) →identifier, since those config types arePartial<…NodeInput>which useidentifierin v2.'name' in nodenarrowing sites — which type-check against the v2Nodeunion but are runtime no-ops (NodeSelector.ts,NodePath.ts,getDebugStringVisitor.tsdefault branch) — switched to'identifier' in node/node.identifier, plus the selector example in the README.Deliberately left untouched (not the
nameattribute)idl.*.name,'name' in field), commander.name(), error-contextname:keys, projected plain-object keys, and anything inside removed-node guards (argumentValueNode,resolverValueNode,instructionArgumentLinkNode) — handled in the per-package adaptation PRs.NodeSelector'scamelCase(name) !== node.identifiercomparison: v2 identifiers are no longer camelCase-normalised, so the comparison semantics need a case-fold rethink. Cast tostringhere to keep the rename compiling; the semantic fix is a selector follow-up.Note for per-package PRs
instructionArgumentNodeis a removed node in v2, but its construction sites still hadname:→identifier:renamed here (harmless — they become struct fields, which useidentifier). Don't treat those as fully migrated; the argument→data rework happens per-package. SimilarlyfieldDiscriminatorNode.name→pathandaccountFieldValueNode→accountDataValueNodeare out-of-scope shape changes left for the per-package PRs.Status
Mechanical rename only; packages are not yet green (numeric/transform/removed-node work follows per-package). Every remaining
'name'error insrc/sits inside a removed-node branch.test/and generated files are untouched.