Logo Xantham

Ast Module

The version-5 binary AST returned by `getSourceFile`: one blob per file, from which every node is readable with no further round-trips. All integers here are **little-endian**, unlike the msgpack envelope that carried them.

Types

Type Description

DiagnosticDirective

A suppression directive mapped from an original file onto a virtual one, in UTF-16 code units.

FileReference

A `/// ` directive, with its positions already in UTF-16 code units.

NodeData

What a node's data word means.

SourceFile

A decoded `getSourceFile` response. Cheap to hold: it is the response bytes plus six section offsets read out of the header.

SpanMapSegment

One mapping between a virtual file and the original it was extracted from.

Functions and values

Function or value Description

Ast.KindNodeList

Full Usage: Ast.KindNodeList

Returns: SyntaxKind

A synthetic node representing a list of siblings rather than a syntax node. Outside the schema's numbering, hence not a `SyntaxKind` case.

Returns: SyntaxKind

Ast.ProtocolVersion

Full Usage: Ast.ProtocolVersion

Returns: uint32
Returns: uint32

Ast.Root

Full Usage: Ast.Root

Returns: int

The root SourceFile node.

Returns: int

Ast.ambientModuleNames file

Full Usage: Ast.ambientModuleNames file

Parameters:
Returns: string array

The names of the ambient modules this file declares.

file : SourceFile
Returns: string array

Ast.canonicalSourceFileName file

Full Usage: Ast.canonicalSourceFileName file

Parameters:
Returns: string voption

The name of the file this one is a projection of.

file : SourceFile
Returns: string voption

Ast.childAtOrder file index order

Full Usage: Ast.childAtOrder file index order

Parameters:
Returns: int voption

The child occupying declared slot `order`, if present.

file : SourceFile
index : int
order : int<MeasureProduct<astSlot, MeasureOne>>
Returns: int voption

Ast.children file index

Full Usage: Ast.children file index

Parameters:
Returns: int seq

Every child of a node, in order. For a node list these are its elements.

file : SourceFile
index : int
Returns: int seq

Ast.commonData file index

Full Usage: Ast.commonData file index

Parameters:
Returns: uint32

The six commonData bits of a node's data word, shifted down to bit 0.

What they mean is per kind and is generated: see the accessors in AstNode. A few nodes - the literals, and SyntheticExpression - fill these bits from a compiler function that is not part of the schema, and have no generated accessors as a result.

file : SourceFile
index : int
Returns: uint32

Ast.contentHash file

Full Usage: Ast.contentHash file

Parameters:
Returns: string

The 128-bit content hash, used to tell whether a cached blob is still current.

file : SourceFile
Returns: string

Ast.contentMapper file

Full Usage: Ast.contentMapper file

Parameters:
Returns: string voption

The content mapper that produced this file.

file : SourceFile
Returns: string voption

Ast.data file index

Full Usage: Ast.data file index

Parameters:
Returns: NodeData
file : SourceFile
index : int
Returns: NodeData

Ast.descendants file index

Full Usage: Ast.descendants file index

Parameters:
Returns: int seq

Depth-first walk from `index` inclusive.

file : SourceFile
index : int
Returns: int seq

Ast.diagnosticDirectives file

Full Usage: Ast.diagnosticDirectives file

Parameters:
Returns: DiagnosticDirective array

The suppression directives carried over from the file this one was mapped from.

Not the `@ts-ignore` and `@ts-expect-error` comments of an ordinary file, which the compiler keeps elsewhere: these are the mapped directives of a virtual file, so an ordinary one has none however many such comments it contains.

file : SourceFile
Returns: DiagnosticDirective array

Ast.endPos file index

Full Usage: Ast.endPos file index

Parameters:
Returns: int

End offset in UTF-16 code units.

file : SourceFile
index : int
Returns: int

Ast.externalModuleIndicator file

Full Usage: Ast.externalModuleIndicator file

Parameters:
Returns: int voption

The node whose presence made this file a module, if any.

file : SourceFile
Returns: int voption

Ast.fileName file

Full Usage: Ast.fileName file

Parameters:
Returns: string

The file name the compiler knows this file by.

file : SourceFile
Returns: string

Ast.flags file index

Full Usage: Ast.flags file index

Parameters:
Returns: NodeFlags

The node's `NodeFlags` - `Const`, `Ambient`, `JavaScriptFile` and the rest of the word the parser set while reading it.

file : SourceFile
index : int
Returns: NodeFlags

Ast.getString file index

Full Usage: Ast.getString file index

Parameters:
Returns: string

Reads string `index` from the string table.

file : SourceFile
index : uint32<MeasureProduct<stringIndex, MeasureOne>>
Returns: string

Ast.hasChildren file index

Full Usage: Ast.hasChildren file index

Parameters:
Returns: bool

A node has children when the record that follows it names it as parent.

file : SourceFile
index : int
Returns: bool

Ast.imports file

Full Usage: Ast.imports file

Parameters:
Returns: int array

The module specifiers this file imports, as nodes.

file : SourceFile
Returns: int array

Ast.kind file index

Full Usage: Ast.kind file index

Parameters:
Returns: SyntaxKind

The node's kind. `KindNodeList` for a node list, which is not a schema kind.

file : SourceFile
index : int
Returns: SyntaxKind

Ast.languageVariant file

Full Usage: Ast.languageVariant file

Parameters:
Returns: LanguageVariant

The file's `LanguageVariant`, i.e. whether JSX syntax is on.

file : SourceFile
Returns: LanguageVariant

Ast.libReferenceDirectives file

Full Usage: Ast.libReferenceDirectives file

Parameters:
Returns: FileReference array

The `/// ` directives.

file : SourceFile
Returns: FileReference array

Ast.moduleAugmentations file

Full Usage: Ast.moduleAugmentations file

Parameters:
Returns: int array

The `declare module "..."` augmentations, as nodes.

file : SourceFile
Returns: int array

Ast.next file index

Full Usage: Ast.next file index

Parameters:
Returns: int

The next sibling within a node list; 0 terminates.

file : SourceFile
index : int
Returns: int

Ast.originalText file

Full Usage: Ast.originalText file

Parameters:
Returns: string

The text as it was before any transformation, equal to sourceText for an ordinary file.

file : SourceFile
Returns: string

Ast.parent file index

Full Usage: Ast.parent file index

Parameters:
Returns: int
file : SourceFile
index : int
Returns: int

Ast.path file

Full Usage: Ast.path file

Parameters:
Returns: string

The file's canonicalised path.

file : SourceFile
Returns: string

Ast.pos file index

Full Usage: Ast.pos file index

Parameters:
Returns: int

Start offset w/ leading trivia in UTF-16 code units.

file : SourceFile
index : int
Returns: int

Ast.rawText file index

Full Usage: Ast.rawText file index

Parameters:
Returns: string voption

The unescaped source text of a template literal fragment.

file : SourceFile
index : int
Returns: string voption

Ast.read data

Full Usage: Ast.read data

Parameters:
    data : byte[]

Returns: SourceFile

Reads the 44-byte header. Rejects incompatible protocol versions

data : byte[]
Returns: SourceFile

Ast.referencedFiles file

Full Usage: Ast.referencedFiles file

Parameters:
Returns: FileReference array

The `/// ` directives.

file : SourceFile
Returns: FileReference array

Ast.scriptKind file

Full Usage: Ast.scriptKind file

Parameters:
Returns: ScriptKind

The file's `ScriptKind`: what the compiler decided it was reading.

file : SourceFile
Returns: ScriptKind

Ast.sourceText file

Full Usage: Ast.sourceText file

Parameters:
Returns: string

The file's whole source text, which the string table is mostly made of.

file : SourceFile
Returns: string

Ast.spanMap file

Full Usage: Ast.spanMap file

Parameters:
Returns: SpanMapSegment array

The mapping back to the file this one was extracted from, empty when there is none.

file : SourceFile
Returns: SpanMapSegment array

Ast.supplementalSourceFileNames file

Full Usage: Ast.supplementalSourceFileNames file

Parameters:
Returns: string array

The names of the files this one was assembled from.

file : SourceFile
Returns: string array

Ast.templateFlags file index

Full Usage: Ast.templateFlags file index

Parameters:
Returns: TokenFlags voption

The template fragment's `TokenFlags`, which sit past its raw text.

file : SourceFile
index : int
Returns: TokenFlags voption

Ast.text file index

Full Usage: Ast.text file index

Parameters:
Returns: string voption

The node's text, for the kinds that carry one. Identifiers and the like read straight from the string table; literals go through their extended-data record.

file : SourceFile
index : int
Returns: string voption

Ast.tokenFlags file index

Full Usage: Ast.tokenFlags file index

Parameters:
Returns: TokenFlags voption

The literal's `TokenFlags`, for the kinds that record them.

file : SourceFile
index : int
Returns: TokenFlags voption

Ast.typeReferenceDirectives file

Full Usage: Ast.typeReferenceDirectives file

Parameters:
Returns: FileReference array

The `/// ` directives.

file : SourceFile
Returns: FileReference array

Ast.virtualFileName file

Full Usage: Ast.virtualFileName file

Parameters:
Returns: string voption

The name this file is addressed by when it is virtual.

file : SourceFile
Returns: string voption

Type something to start searching.