(
node: AnyParseNode | null | undefined,
type: NODETYPE,
)
| 6 | * typing. Throws if the node's type does not match. |
| 7 | */ |
| 8 | export function assertNodeType<NODETYPE extends NodeType>( |
| 9 | node: AnyParseNode | null | undefined, |
| 10 | type: NODETYPE, |
| 11 | ): ParseNode<NODETYPE> { |
| 12 | if (!node || node.type !== type) { |
| 13 | throw new Error( |
| 14 | `Expected node of type ${type}, but got ` + |
| 15 | (node ? `node of type ${node.type}` : String(node))); |
| 16 | } |
| 17 | |
| 18 | return node as ParseNode<NODETYPE>; |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Returns the node more strictly typed iff it is of the given type. Otherwise, |
no outgoing calls
no test coverage detected
searching dependent graphs…