import * as ts from 'typescript'; import { TargetLanguage } from './languages'; import { OTree, UnknownSyntax, Span } from './o-tree'; import { SubmoduleReference, SubmoduleReferenceMap } from './submodule-reference'; import { ImportStatement } from './typescript/imports'; /** * Render a TypeScript AST to some other representation (encoded in OTrees) * * Dispatch the actual conversion to a specific handler which will get the * appropriate method called for particular AST nodes. The handler may use * context to modify its own operations when traversing the tree hierarchy, * the type of which should be expressed via the C parameter. */ export declare class AstRenderer { private readonly sourceFile; readonly typeChecker: ts.TypeChecker; private readonly handler; private readonly options; readonly submoduleReferences: SubmoduleReferenceMap; readonly diagnostics: ts.Diagnostic[]; readonly currentContext: C; constructor(sourceFile: ts.SourceFile, typeChecker: ts.TypeChecker, handler: AstHandler, options?: AstRendererOptions, submoduleReferences?: SubmoduleReferenceMap); /** * Merge the new context with the current context and create a new Converter from it */ updateContext(contextUpdate: Partial): AstRenderer; /** * Convert a single node to an OTree */ convert(node: ts.Node | undefined): OTree; /** * Convert a set of nodes, filtering out hidden nodes */ convertAll(nodes: readonly ts.Node[]): OTree[]; convertWithModifier(nodes: readonly ts.Node[], makeContext: (context: this, node: ts.Node, index: number) => AstRenderer): OTree[]; /** * Convert a set of nodes, but update the context for the last one. * * Takes visibility into account. */ convertLastDifferently(nodes: readonly ts.Node[], lastContext: C): OTree[]; getPosition(node: ts.Node): Span; textOf(node: ts.Node): string; textAt(pos: number, end: number): string; /** * Infer type of expression by the argument it is assigned to * * If the type of the expression can include undefined (if the value is * optional), `undefined` will be removed from the union. * * (Will return undefined for object literals not unified with a declared type) * * @deprecated Use `inferredTypeOfExpression` instead */ inferredTypeOfExpression(node: ts.Expression): ts.Type | undefined; /** * Type of expression from the text of the expression * * (Will return a map type for object literals) * * @deprecated Use `typeOfExpression` directly */ typeOfExpression(node: ts.Expression): ts.Type; typeOfType(node: ts.TypeNode): ts.Type; typeToString(type: ts.Type): string; report(node: ts.Node, messageText: string, category?: ts.DiagnosticCategory): void; reportUnsupported(node: ts.Node, language: TargetLanguage | undefined): void; /** * Whether there is non-whitespace on the same line before the given position */ codeOnLineBefore(pos: number): boolean; /** * Return a newline if the given node is preceded by at least one newline * * Used to mirror newline use between matching brackets (such as { ... } and [ ... ]). */ mirrorNewlineBefore(viz?: ts.Node, suffix?: string, otherwise?: string): string; /** * Dispatch node to handler */ private dispatch; /** * Attach any leading whitespace and comments to the given output tree * * Regardless of whether it's declared to be able to accept such or not. */ private attachLeadingTrivia; } /** * Interface for AST handlers * * C is the type of hierarchical context the handler uses. Context * needs 2 operations: a constructor for a default context, and a * merge operation to combine 2 contexts to yield a new one. * * Otherwise, the handler should return an OTree for every type * of AST node. */ export interface AstHandler { readonly language: TargetLanguage; readonly defaultContext: C; readonly indentChar?: ' ' | '\t'; mergeContext(old: C, update: Partial): C; sourceFile(node: ts.SourceFile, context: AstRenderer): OTree; commentRange(node: CommentSyntax, context: AstRenderer): OTree; importStatement(node: ImportStatement, context: AstRenderer): OTree; stringLiteral(node: ts.StringLiteral | ts.NoSubstitutionTemplateLiteral, children: AstRenderer): OTree; numericLiteral(node: ts.NumericLiteral, children: AstRenderer): OTree; functionDeclaration(node: ts.FunctionDeclaration, children: AstRenderer): OTree; identifier(node: ts.Identifier, children: AstRenderer): OTree; block(node: ts.Block, children: AstRenderer): OTree; parameterDeclaration(node: ts.ParameterDeclaration, children: AstRenderer): OTree; returnStatement(node: ts.ReturnStatement, context: AstRenderer): OTree; binaryExpression(node: ts.BinaryExpression, context: AstRenderer): OTree; ifStatement(node: ts.IfStatement, context: AstRenderer): OTree; propertyAccessExpression(node: ts.PropertyAccessExpression, context: AstRenderer, submoduleReference: SubmoduleReference | undefined): OTree; awaitExpression(node: ts.AwaitExpression, context: AstRenderer): OTree; callExpression(node: ts.CallExpression, context: AstRenderer): OTree; expressionStatement(node: ts.ExpressionStatement, context: AstRenderer): OTree; token(node: ts.Token, context: AstRenderer): OTree; objectLiteralExpression(node: ts.ObjectLiteralExpression, context: AstRenderer): OTree; newExpression(node: ts.NewExpression, context: AstRenderer): OTree; propertyAssignment(node: ts.PropertyAssignment, context: AstRenderer): OTree; variableStatement(node: ts.VariableStatement, context: AstRenderer): OTree; variableDeclarationList(node: ts.VariableDeclarationList, context: AstRenderer): OTree; variableDeclaration(node: ts.VariableDeclaration, context: AstRenderer): OTree; jsDoc(node: ts.JSDoc, context: AstRenderer): OTree; arrayLiteralExpression(node: ts.ArrayLiteralExpression, context: AstRenderer): OTree; shorthandPropertyAssignment(node: ts.ShorthandPropertyAssignment, context: AstRenderer): OTree; forOfStatement(node: ts.ForOfStatement, context: AstRenderer): OTree; classDeclaration(node: ts.ClassDeclaration, context: AstRenderer): OTree; constructorDeclaration(node: ts.ConstructorDeclaration, context: AstRenderer): OTree; propertyDeclaration(node: ts.PropertyDeclaration, context: AstRenderer): OTree; computedPropertyName(node: ts.Expression, context: AstRenderer): OTree; methodDeclaration(node: ts.MethodDeclaration, context: AstRenderer): OTree; interfaceDeclaration(node: ts.InterfaceDeclaration, context: AstRenderer): OTree; propertySignature(node: ts.PropertySignature, context: AstRenderer): OTree; methodSignature(node: ts.MethodSignature, context: AstRenderer): OTree; asExpression(node: ts.AsExpression, context: AstRenderer): OTree; prefixUnaryExpression(node: ts.PrefixUnaryExpression, context: AstRenderer): OTree; spreadElement(node: ts.SpreadElement, context: AstRenderer): OTree; spreadAssignment(node: ts.SpreadAssignment, context: AstRenderer): OTree; templateExpression(node: ts.TemplateExpression, context: AstRenderer): OTree; nonNullExpression(node: ts.NonNullExpression, context: AstRenderer): OTree; parenthesizedExpression(node: ts.ParenthesizedExpression, context: AstRenderer): OTree; maskingVoidExpression(node: ts.VoidExpression, context: AstRenderer): OTree; elementAccessExpression(node: ts.ElementAccessExpression, context: AstRenderer): OTree; ellipsis(node: ts.SpreadElement | ts.SpreadAssignment, context: AstRenderer): OTree; } export declare function nimpl(node: ts.Node, context: AstRenderer, options?: { additionalInfo?: string; }): UnknownSyntax; export interface AstRendererOptions { /** * If enabled, don't translate the text of unknown nodes * * @default true */ bestEffort?: boolean; } /** * Our own representation of comments * * (So we can synthesize 'em */ export interface CommentSyntax { pos: number; text: string; hasTrailingNewLine?: boolean; kind: ts.CommentKind; /** * Whether it's at the end of a code line (so we can render a separating space) */ isTrailing?: boolean; } //# sourceMappingURL=renderer.d.ts.map