Skip to content

Commit

Permalink
Update type guards
Browse files Browse the repository at this point in the history
  • Loading branch information
lorisleiva committed Apr 9, 2024
1 parent dbc6281 commit d00f5a1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
17 changes: 9 additions & 8 deletions src/visitors/identityVisitor.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import {
CONDITIONAL_VALUE_BRANCH_NODES,
COUNT_NODES,
DISCRIMINATOR_NODES,
ENUM_VARIANT_TYPE_NODES,
INSTRUCTION_INPUT_VALUE_NODE,
Node,
NodeKind,
PDA_SEED_NODES,
REGISTERED_NODE_KINDS,
COUNT_NODES,
TYPE_NODES,
VALUE_NODES,
accountNode,
amountTypeNode,
arrayTypeNode,
arrayValueNode,
assertIsNestedTypeNode,
assertIsNode,
booleanTypeNode,
conditionalValueNode,
Expand Down Expand Up @@ -308,7 +309,7 @@ export function identityVisitor<TNodeKind extends NodeKind = NodeKind>(
visitor.visitOptionType = function visitOptionType(node) {
const prefix = visit(this)(node.prefix);
if (prefix === null) return null;
assertIsNode(prefix, 'numberTypeNode');
assertIsNestedTypeNode(prefix, 'numberTypeNode');
const item = visit(this)(node.item);
if (item === null) return null;
assertIsNode(item, TYPE_NODES);
Expand All @@ -320,7 +321,7 @@ export function identityVisitor<TNodeKind extends NodeKind = NodeKind>(
visitor.visitBooleanType = function visitBooleanType(node) {
const size = visit(this)(node.size);
if (size === null) return null;
assertIsNode(size, 'numberTypeNode');
assertIsNestedTypeNode(size, 'numberTypeNode');
return booleanTypeNode(size);
};
}
Expand Down Expand Up @@ -372,7 +373,7 @@ export function identityVisitor<TNodeKind extends NodeKind = NodeKind>(
visitor.visitAmountType = function visitAmountType(node) {
const number = visit(this)(node.number);
if (number === null) return null;
assertIsNode(number, 'numberTypeNode');
assertIsNestedTypeNode(number, 'numberTypeNode');
return amountTypeNode(number, node.decimals, node.unit);
};
}
Expand All @@ -381,7 +382,7 @@ export function identityVisitor<TNodeKind extends NodeKind = NodeKind>(
visitor.visitDateTimeType = function visitDateTimeType(node) {
const number = visit(this)(node.number);
if (number === null) return null;
assertIsNode(number, 'numberTypeNode');
assertIsNestedTypeNode(number, 'numberTypeNode');
return dateTimeTypeNode(number);
};
}
Expand All @@ -390,7 +391,7 @@ export function identityVisitor<TNodeKind extends NodeKind = NodeKind>(
visitor.visitSolAmountType = function visitSolAmountType(node) {
const number = visit(this)(node.number);
if (number === null) return null;
assertIsNode(number, 'numberTypeNode');
assertIsNestedTypeNode(number, 'numberTypeNode');
return solAmountTypeNode(number);
};
}
Expand All @@ -399,7 +400,7 @@ export function identityVisitor<TNodeKind extends NodeKind = NodeKind>(
visitor.visitPrefixedCount = function visitPrefixedCount(node) {
const prefix = visit(this)(node.prefix);
if (prefix === null) return null;
assertIsNode(prefix, 'numberTypeNode');
assertIsNestedTypeNode(prefix, 'numberTypeNode');
return prefixedCountNode(prefix);
};
}
Expand Down Expand Up @@ -600,7 +601,7 @@ export function identityVisitor<TNodeKind extends NodeKind = NodeKind>(
visitor.visitSizePrefixType = function visitSizePrefixType(node) {
const prefix = visit(this)(node.prefix);
if (prefix === null) return null;
assertIsNode(prefix, 'numberTypeNode');
assertIsNestedTypeNode(prefix, 'numberTypeNode');
const type = visit(this)(node.type);
if (type === null) return null;
assertIsNode(type, TYPE_NODES);
Expand Down
4 changes: 2 additions & 2 deletions src/visitors/setNumberWrappersVisitor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
amountTypeNode,
assertIsNode,
assertIsNestedTypeNode,
dateTimeTypeNode,
solAmountTypeNode,
} from '../nodes';
Expand All @@ -22,7 +22,7 @@ export function setNumberWrappersVisitor(map: NumberWrapperMap) {
([selectorStack, wrapper]): BottomUpNodeTransformerWithSelector => ({
select: `${selectorStack}.[numberTypeNode]`,
transform: (node) => {
assertIsNode(node, 'numberTypeNode');
assertIsNestedTypeNode(node, 'numberTypeNode');
switch (wrapper.kind) {
case 'DateTime':
return dateTimeTypeNode(node);
Expand Down

0 comments on commit d00f5a1

Please sign in to comment.