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 |
| jsdocComment | Builds a JSDoc comment block string with proper indentation. |
| namespaceExport | Renders an |
| namespaceMembers | Renders the statements of a namespace body at base indentation, emitting
the local members and the trailing |
| TSDeclareFunction | Drop ambient declarations, they have no runtime representation. |
| TSEnumDeclaration | Converts |
| TSInterfaceDeclaration | |
| TSModuleDeclaration | Converts a namespace ( |
| TSTypeAliasDeclaration | |
| typedefComment | Renders a typedef comment for interfaces/type aliases. |
| typedefLines | Builds |
| VariableDeclaration | Strips the |
Details
Constructor
ToJS() #
Methods
ExportNamedDeclaration(node) #
Strips type-only exports and converts type declarations into typedef comments.
Parameters
| node | import('@babel/types').ExportNamedDeclaration | The Babel AST node. |
Returns
stringStringification 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
| node | import('@babel/types').ImportDeclaration | The Babel AST node. |
Returns
stringStringification of the node.
jsdocComment(lines) #
Builds a JSDoc comment block string with proper indentation.
Parameters
| lines | string[] | The comment body lines (e.g. |
Returns
stringThe 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
| statement | import('@babel/types').ExportNamedDeclaration | The export statement. |
Returns
ObjectThe 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
| block | import('@babel/types').TSModuleBlock | The namespace body. |
| name | string | The namespace identifier. |
Returns
stringThe body source (joinable lines).
TSDeclareFunction() #
Drop ambient declarations, they have no runtime representation.
Parameters
Returns
stringAn empty string.
TSEnumDeclaration(node) #
Converts enum into a plain const object.
Parameters
| node | import('@babel/types').TSEnumDeclaration | The Babel AST node. |
Returns
stringThe object literal.
TSInterfaceDeclaration(node) #
Parameters
| node | import('@babel/types').TSInterfaceDeclaration | The Babel AST node. |
Returns
stringA JSDoc typedef comment.
TSModuleDeclaration(node) #
Converts a namespace (namespace X { ... }) into the classic IIFE
pattern, exporting members via X.member = member assignments.
Parameters
| node | import('@babel/types').TSModuleDeclaration | The namespace declaration. |
Returns
stringThe IIFE source.
TSTypeAliasDeclaration(node) #
Parameters
| node | import('@babel/types').TSTypeAliasDeclaration | The Babel AST node. |
Returns
stringA JSDoc typedef comment.
typedefComment(node) #
Renders a typedef comment for interfaces/type aliases.
Parameters
| node | Node | The declaration node. |
Returns
stringThe comment.