tcmts.core.ir

Types

DefParts type
A definition's IR in its parts. It's `["Def", tag, ...]`: the head, then the syntax (`body`). After the tag, the head holds what isn't syntax, each only when the definition has it: its lineage salt (`["Salt", path]`: not a type's, nor a definition analyzed with no `saltFor`, as tests analyze code) and the JSX runtime it compiles to (`["Jsx", runtime]`). So the syntax starts at a different place in different definitions, analyzed or stored: read it through defParts (or declarationOf, initializerOf), never by position.

Shared

childOf (node: IR | undefined, key: string) => IR | undefined
A node's child at `key` (its slot: `name`, `initializer`, `members`…), if it has one.
declarationOf (ir: string | IR[]) => IR[] | undefined
A definition's declaration: its `VariableDeclaration` (a `const`, a `let`, a binding of a destructuring), `ClassDeclaration`, `InterfaceDeclaration`…; an overloaded function's implementation.
defParts (ir: string | IR[]) => DefParts
A definition's IR (as stored, or parsed) in its parts: its tag, salt and JSX runtime, and its syntax, wherever each is (see DefParts). Something that isn't a definition's IR (a file's) has no tag and no syntax.
definesFunction (ir: string | IR[]) => boolean
Whether a definition is a function: `function f() {}`, or a const holding an arrow function or function expression. Its source text is its code (`String(f)`), as a constant's isn't: `${n}` reads a value something ran.
initializerOf (ir: string | IR[]) => IR[] | undefined
What a `const` or `let` is initialized to (its initializer's expression), if it's one with an initializer.
isErased (node: IR) => boolean
Whether a part of a definition's IR is only types, erased when the code is compiled, so nothing in it runs: a `type`, `typeArguments` or `typeParameters` slot (a parameter's, variable's or return type, `as T`, `satisfies T`, `f<T>()`; `typeof x` in a type is in one), a type or interface declared inside code, and `implements`. The rest is code that runs: a global read, called, constructed, or tested with `instanceof` or a `typeof` expression.
writtenOutRefs (ir: IR) => Set<string>
The definitions code only writes out as source text, never running them: `${f}` in a template, `f.toString()`, `String(f)`. A function whose source goes into a file something else runs (a generated runtime, a script run with `node -e`) runs there, not in the code writing it out, so what it needs (the DOM, Node, the clock) isn't that code's. A definition the code also uses any other way (calls it, passes it along) isn't one.

Tests

testDefPartsFindTheSyntaxWhereverItStarts () => void
A definition's syntax is found after its head, salted or not, with a JSX runtime or not, parsed or serialized.