Skip to content

Commit 62fbc94

Browse files
committed
Use NodePath in LinkableDictionary
1 parent 46bf57a commit 62fbc94

22 files changed

+228
-172
lines changed

packages/errors/src/context.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export type CodamaErrorContext = DefaultUnspecifiedErrorContextToUndefined<{
7575
kind: LinkNode['kind'];
7676
linkNode: LinkNode;
7777
name: CamelCaseString;
78-
stack: Node[];
78+
path: readonly Node[];
7979
};
8080
[CODAMA_ERROR__NODE_FILESYSTEM_FUNCTION_UNAVAILABLE]: {
8181
fsFunction: string;
@@ -169,7 +169,7 @@ type ValidationItem = {
169169
level: 'debug' | 'error' | 'info' | 'trace' | 'warn';
170170
message: string;
171171
node: Node;
172-
stack: Node[];
172+
path: Node[];
173173
};
174174

175175
export function decodeEncodedContext(encodedContext: string): object {

packages/renderers-js-umi/src/getRenderMapVisitor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ export function getRenderMapVisitor(options: GetRenderMapOptions = {}): Visitor<
204204
}
205205

206206
// Seeds.
207-
const pda = node.pda ? linkables.get(node.pda, stack) : undefined;
207+
const pda = node.pda ? linkables.get([...stack.getPath(), node.pda]) : undefined;
208208
const pdaSeeds = pda?.seeds ?? [];
209209
const seeds = pdaSeeds.map(seed => {
210210
if (isNode(seed, 'variablePdaSeedNode')) {

packages/renderers-js-umi/src/getTypeManifestVisitor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ export function getTypeManifestVisitor(input: {
429429
const importFrom = getImportFrom(node.enum);
430430

431431
// FIXME(loris): No program node can ever be in this stack.
432-
const enumNode = linkables.get(node.enum, stack)?.type;
432+
const enumNode = linkables.get([...stack.getPath(), node.enum])?.type;
433433
const isScalar =
434434
enumNode && isNode(enumNode, 'enumTypeNode')
435435
? isScalarEnum(enumNode)

packages/renderers-js/src/fragments/accountPdaHelpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function getAccountPdaHelpersFragment(
1313
},
1414
): Fragment {
1515
const { accountNode, accountStack, nameApi, linkables, customAccountData, typeManifest } = scope;
16-
const pdaNode = accountNode.pda ? linkables.get(accountNode.pda, accountStack) : undefined;
16+
const pdaNode = accountNode.pda ? linkables.get([...accountStack.getPath(), accountNode.pda]) : undefined;
1717
if (!pdaNode) {
1818
return fragment('');
1919
}

packages/renderers-js/src/fragments/instructionAccountTypeParam.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ function getDefaultAddress(
4343
case 'publicKeyValueNode':
4444
return `"${defaultValue.publicKey}"`;
4545
case 'programLinkNode':
46-
// FIXME(loris): No need for a stack here.
4746
// eslint-disable-next-line no-case-declarations
48-
const programNode = linkables.get(defaultValue, new NodeStack());
47+
const programNode = linkables.get([defaultValue]);
4948
return programNode ? `"${programNode.publicKey}"` : 'string';
5049
case 'programIdValueNode':
5150
return `"${programId}"`;

packages/renderers-js/src/getTypeManifestVisitor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ export function getTypeManifestVisitor(input: {
355355
const importFrom = getImportFrom(node.enum);
356356

357357
// FIXME(loris): No program node can ever be in this stack.
358-
const enumNode = linkables.get(node.enum, stack)?.type;
358+
const enumNode = linkables.get([...stack.getPath(), node.enum])?.type;
359359
const isScalar =
360360
enumNode && isNode(enumNode, 'enumTypeNode')
361361
? isScalarEnum(enumNode)

packages/renderers-rust/src/getRenderMapVisitor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export function getRenderMapVisitor(options: GetRenderMapOptions = {}) {
6464

6565
// Seeds.
6666
const seedsImports = new ImportMap();
67-
const pda = node.pda ? linkables.get(node.pda, stack) : undefined;
67+
const pda = node.pda ? linkables.get([...stack.getPath(), node.pda]) : undefined;
6868
const pdaSeeds = pda?.seeds ?? [];
6969
const seeds = pdaSeeds.map(seed => {
7070
if (isNode(seed, 'variablePdaSeedNode')) {

packages/validators/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ type ValidationItem = {
3636
message: string;
3737
// The node that the validation item is related to.
3838
node: Node;
39-
// The stack of nodes that led to the node above.
40-
stack: readonly Node[];
39+
// The path of nodes that led to the node above (including the node itself).
40+
path: readonly Node[];
4141
};
4242
```
4343

packages/validators/src/ValidationItem.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export type ValidationItem = {
88
level: LogLevel;
99
message: string;
1010
node: Node;
11-
stack: readonly Node[];
11+
path: readonly Node[];
1212
};
1313

1414
export function validationItem(
@@ -21,7 +21,7 @@ export function validationItem(
2121
level,
2222
message,
2323
node,
24-
stack: Array.isArray(stack) ? [...stack] : stack.all(),
24+
path: Array.isArray(stack) ? [...stack] : stack.all(),
2525
};
2626
}
2727

packages/validators/src/getValidationItemsVisitor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export function getValidationItemsVisitor(): Visitor<readonly ValidationItem[]>
4747
const items = [] as ValidationItem[];
4848
if (!node.name) {
4949
items.push(validationItem('error', 'Pointing to a defined type with no name.', node, stack));
50-
} else if (!linkables.has(node, stack)) {
50+
} else if (!linkables.has(stack.getPath())) {
5151
items.push(
5252
validationItem(
5353
'error',

0 commit comments

Comments
 (0)