UNPKG

5.97 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8/// <amd-module name="@angular/compiler-cli/src/transformers/node_emitter" />
9import { AssertNotNull, BinaryOperatorExpr, CastExpr, ClassStmt, CommaExpr, ConditionalExpr, DeclareFunctionStmt, DeclareVarStmt, ExpressionStatement, ExpressionVisitor, ExternalExpr, FunctionExpr, IfStmt, InstantiateExpr, InvokeFunctionExpr, LiteralArrayExpr, LiteralExpr, LiteralMapExpr, LocalizedString, NotExpr, ParseSourceSpan, PartialModule, ReadKeyExpr, ReadPropExpr, ReadVarExpr, ReturnStatement, Statement, StatementVisitor, TaggedTemplateExpr, ThrowStmt, TryCatchStmt, TypeofExpr, UnaryOperatorExpr, WrappedNodeExpr, WriteKeyExpr, WritePropExpr, WriteVarExpr } from '@angular/compiler';
10import ts from 'typescript';
11export interface Node {
12 sourceSpan: ParseSourceSpan | null;
13}
14export declare class TypeScriptNodeEmitter {
15 private annotateForClosureCompiler;
16 constructor(annotateForClosureCompiler: boolean);
17 updateSourceFile(sourceFile: ts.SourceFile, stmts: Statement[], preamble?: string): [
18 ts.SourceFile,
19 Map<ts.Node, Node>
20 ];
21}
22/**
23 * Update the given source file to include the changes specified in module.
24 *
25 * The module parameter is treated as a partial module meaning that the statements are added to
26 * the module instead of replacing the module. Also, any classes are treated as partial classes
27 * and the included members are added to the class with the same name instead of a new class
28 * being created.
29 */
30export declare function updateSourceFile(sourceFile: ts.SourceFile, module: PartialModule, annotateForClosureCompiler: boolean): [ts.SourceFile, Map<ts.Node, Node>];
31export declare type RecordedNode<T extends ts.Node = ts.Node> = (T & {
32 __recorded: any;
33}) | null;
34/**
35 * Visits an output ast and produces the corresponding TypeScript synthetic nodes.
36 */
37export declare class NodeEmitterVisitor implements StatementVisitor, ExpressionVisitor {
38 private annotateForClosureCompiler;
39 private _nodeMap;
40 private _importsWithPrefixes;
41 private _reexports;
42 private _templateSources;
43 private _exportedVariableIdentifiers;
44 constructor(annotateForClosureCompiler: boolean);
45 /**
46 * Process the source file and collect exported identifiers that refer to variables.
47 *
48 * Only variables are collected because exported classes still exist in the module scope in
49 * CommonJS, whereas variables have their declarations moved onto the `exports` object, and all
50 * references are updated accordingly.
51 */
52 loadExportedVariableIdentifiers(sourceFile: ts.SourceFile): void;
53 getReexports(): ts.Statement[];
54 getImports(): ts.Statement[];
55 getNodeMap(): Map<ts.Node, Node>;
56 updateSourceMap(statements: ts.Statement[]): void;
57 private postProcess;
58 private sourceRangeOf;
59 private getModifiers;
60 visitDeclareVarStmt(stmt: DeclareVarStmt): (ts.VariableStatement & {
61 __recorded: any;
62 }) | ((ts.VariableStatement & {
63 __recorded: any;
64 }) | (ts.ExportDeclaration & {
65 __recorded: any;
66 }) | null)[] | null;
67 visitDeclareFunctionStmt(stmt: DeclareFunctionStmt): RecordedNode<ts.FunctionDeclaration>;
68 visitExpressionStmt(stmt: ExpressionStatement): RecordedNode<ts.ExpressionStatement>;
69 visitReturnStmt(stmt: ReturnStatement): RecordedNode<ts.ReturnStatement>;
70 visitDeclareClassStmt(stmt: ClassStmt): RecordedNode<ts.ClassDeclaration>;
71 visitIfStmt(stmt: IfStmt): RecordedNode<ts.IfStatement>;
72 visitTryCatchStmt(stmt: TryCatchStmt): RecordedNode<ts.TryStatement>;
73 visitThrowStmt(stmt: ThrowStmt): RecordedNode<ts.ThrowStatement>;
74 visitWrappedNodeExpr(expr: WrappedNodeExpr<any>): any;
75 visitTypeofExpr(expr: TypeofExpr): RecordedNode<ts.TypeOfExpression>;
76 visitReadVarExpr(expr: ReadVarExpr): (ts.Identifier & {
77 __recorded: any;
78 }) | (ts.SuperExpression & {
79 __recorded: any;
80 }) | null;
81 visitWriteVarExpr(expr: WriteVarExpr): RecordedNode<ts.BinaryExpression>;
82 visitWriteKeyExpr(expr: WriteKeyExpr): RecordedNode<ts.BinaryExpression>;
83 visitWritePropExpr(expr: WritePropExpr): RecordedNode<ts.BinaryExpression>;
84 visitInvokeFunctionExpr(expr: InvokeFunctionExpr): RecordedNode<ts.CallExpression>;
85 visitTaggedTemplateExpr(expr: TaggedTemplateExpr): RecordedNode<ts.TaggedTemplateExpression>;
86 visitInstantiateExpr(expr: InstantiateExpr): RecordedNode<ts.NewExpression>;
87 visitLiteralExpr(expr: LiteralExpr): RecordedNode<ts.Identifier | ts.NullLiteral | ts.StringLiteral>;
88 visitLocalizedString(expr: LocalizedString, context: any): void;
89 visitExternalExpr(expr: ExternalExpr): RecordedNode<ts.Expression>;
90 visitConditionalExpr(expr: ConditionalExpr): RecordedNode<ts.ParenthesizedExpression>;
91 visitNotExpr(expr: NotExpr): RecordedNode<ts.PrefixUnaryExpression>;
92 visitAssertNotNullExpr(expr: AssertNotNull): RecordedNode<ts.Expression>;
93 visitCastExpr(expr: CastExpr): RecordedNode<ts.Expression>;
94 visitFunctionExpr(expr: FunctionExpr): RecordedNode<ts.FunctionExpression>;
95 visitUnaryOperatorExpr(expr: UnaryOperatorExpr): RecordedNode<ts.UnaryExpression | ts.ParenthesizedExpression>;
96 visitBinaryOperatorExpr(expr: BinaryOperatorExpr): RecordedNode<ts.BinaryExpression | ts.ParenthesizedExpression>;
97 visitReadPropExpr(expr: ReadPropExpr): RecordedNode<ts.PropertyAccessExpression>;
98 visitReadKeyExpr(expr: ReadKeyExpr): RecordedNode<ts.ElementAccessExpression>;
99 visitLiteralArrayExpr(expr: LiteralArrayExpr): RecordedNode<ts.ArrayLiteralExpression>;
100 visitLiteralMapExpr(expr: LiteralMapExpr): RecordedNode<ts.ObjectLiteralExpression>;
101 visitCommaExpr(expr: CommaExpr): RecordedNode<ts.Expression>;
102 private _visitStatements;
103 private _visitStatementsPrefix;
104 private _visitIdentifier;
105}