RTI API Reference

ToJS

A Stringifier subclass which strips TypeScript-only syntax while emitting the JSDoc comments that were attached during the annotate pre-pass.

Summary

Methods

ExportNamedDeclaration

Strips type-only exports and converts type declarations into typedef comments.

ImportDeclaration

Converts type-only imports into @import JSDoc comments and keeps the value imports of mixed imports (import {Value, type AlsoType}).

jsdocComment

Builds a JSDoc comment block string with proper indentation.

namespaceExport

Renders an export statement inside a namespace: the declaration without the export keyword and the list of exported value names.

namespaceMembers

Renders the statements of a namespace body at base indentation, emitting the local members and the trailing Name.

TSDeclareFunction

Drop ambient declarations, they have no runtime representation.

TSEnumDeclaration

Converts enum into a plain const object.

TSInterfaceDeclaration
TSModuleDeclaration

Converts a namespace (namespace X { ... }) into the classic IIFE pattern, exporting members via X.

TSTypeAliasDeclaration
typedefComment

Renders a typedef comment for interfaces/type aliases.

typedefLines

Builds @typedef JSDoc lines for a declaration node.

VariableDeclaration

Strips the declare modifier from variable declarations.

Details

Constructor

ToJS() #

Methods

ExportNamedDeclaration(node) #

Strips type-only exports and converts type declarations into typedef comments.

Parameters

nodeimport('@babel/types').ExportNamedDeclaration

The Babel AST node.

Returns

string

Stringification of the node.

ImportDeclaration(node) #

Converts type-only imports into @import JSDoc comments and keeps the value imports of mixed imports (import {Value, type AlsoType}).

Parameters

nodeimport('@babel/types').ImportDeclaration

The Babel AST node.

Returns

string

Stringification of the node.

jsdocComment(lines) #

Builds a JSDoc comment block string with proper indentation.

Parameters

linesstring[]

The comment body lines (e.g. @param {number} a).

Returns

string

The comment string.

namespaceExport(statement) #

Renders an export statement inside a namespace: the declaration without the export keyword and the list of exported value names.

Parameters

statementimport('@babel/types').ExportNamedDeclaration

The export statement.

Returns

Object

The declaration source and exported names.

namespaceMembers(block, name) #

Renders the statements of a namespace body at base indentation, emitting the local members and the trailing Name.member = member; assignments for exported value members.

Parameters

blockimport('@babel/types').TSModuleBlock

The namespace body.

namestring

The namespace identifier.

Returns

string

The body source (joinable lines).

TSDeclareFunction() #

Drop ambient declarations, they have no runtime representation.

Parameters

Returns

string

An empty string.

TSEnumDeclaration(node) #

Converts enum into a plain const object.

Parameters

nodeimport('@babel/types').TSEnumDeclaration

The Babel AST node.

Returns

string

The object literal.

TSInterfaceDeclaration(node) #

Parameters

nodeimport('@babel/types').TSInterfaceDeclaration

The Babel AST node.

Returns

string

A JSDoc typedef comment.

TSModuleDeclaration(node) #

Converts a namespace (namespace X { ... }) into the classic IIFE pattern, exporting members via X.member = member assignments.

Parameters

nodeimport('@babel/types').TSModuleDeclaration

The namespace declaration.

Returns

string

The IIFE source.

TSTypeAliasDeclaration(node) #

Parameters

nodeimport('@babel/types').TSTypeAliasDeclaration

The Babel AST node.

Returns

string

A JSDoc typedef comment.

typedefComment(node) #

Renders a typedef comment for interfaces/type aliases.

Parameters

nodeNode

The declaration node.

Returns

string

The comment.

typedefLines(node) #

Builds @typedef JSDoc lines for a declaration node.

Parameters

nodeNode

The declaration node.

Returns

string[]

The JSDoc lines.

VariableDeclaration(node) #

Strips the declare modifier from variable declarations.

Parameters

nodeimport('@babel/types').VariableDeclaration

The Babel AST node.

Returns

string

Stringification of the node.