@nomicfoundation/slang
Version:
A modular set of compiler APIs empowering the next generation of Solidity code analysis and developer tooling. Written in Rust and distributed in multiple languages.
38 lines • 1.58 kB
JavaScript
import { NonterminalNode, TerminalNode } from "./index.mjs";
/**
* Asserts that `node` is a `NonterminalNode`.
*
* If a `kind` value is provided, it will also assert that it matches its `NonterminalKind`.
*
* If a `text` value is provided, it will also be asserted against the node contents.
*/
export function assertNonterminalNode(node, kind, text) {
if (!(node instanceof NonterminalNode)) {
throw new Error("Node provided is not a NonterminalNode.");
}
if (kind !== undefined && kind !== node.kind) {
throw new Error(`Node's NonterminalKind is expected to be '${kind}', but got '${node.kind}'.`);
}
if (text !== undefined && text !== node.unparse()) {
throw new Error(`Node's text content is expected to be '${text}', but got '${node.unparse()}'.`);
}
}
/**
* Asserts that `node` is a `TerminalNode`.
*
* If a `kind` value is provided, it will also assert that it matches its `TerminalKind`.
*
* If a `text` value is provided, it will also be asserted against the node contents.
*/
export function assertTerminalNode(node, kind, text) {
if (!(node instanceof TerminalNode)) {
throw new Error("Node provided is not a TerminalNode.");
}
if (kind !== undefined && kind !== node.kind) {
throw new Error(`Node's TerminalKind is expected to be '${kind}', but got '${node.kind}'.`);
}
if (text !== undefined && text !== node.unparse()) {
throw new Error(`Node's text content is expected to be '${text}', but got '${node.unparse()}'.`);
}
}
//# sourceMappingURL=assertions.mjs.map