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/api" />
|
9 | import { ParseSourceSpan, Position } from '@angular/compiler';
|
10 | import * as ts from 'typescript';
|
11 | import { ExtendedTsCompilerHost, NgCompilerOptions } from '../ngtsc/core/api';
|
12 | export declare const DEFAULT_ERROR_CODE = 100;
|
13 | export declare const UNKNOWN_ERROR_CODE = 500;
|
14 | export declare const SOURCE: "angular";
|
15 | export interface DiagnosticMessageChain {
|
16 | messageText: string;
|
17 | position?: Position;
|
18 | next?: DiagnosticMessageChain[];
|
19 | }
|
20 | export interface Diagnostic {
|
21 | messageText: string;
|
22 | span?: ParseSourceSpan;
|
23 | position?: Position;
|
24 | chain?: DiagnosticMessageChain;
|
25 | category: ts.DiagnosticCategory;
|
26 | code: number;
|
27 | source: 'angular';
|
28 | }
|
29 | export declare function isTsDiagnostic(diagnostic: any): diagnostic is ts.Diagnostic;
|
30 | export declare function isNgDiagnostic(diagnostic: any): diagnostic is Diagnostic;
|
31 | export interface CompilerOptions extends NgCompilerOptions, ts.CompilerOptions {
|
32 | genDir?: string;
|
33 | basePath?: string;
|
34 | skipMetadataEmit?: boolean;
|
35 | strictMetadataEmit?: boolean;
|
36 | skipTemplateCodegen?: boolean;
|
37 | flatModulePrivateSymbolPrefix?: string;
|
38 | generateCodeForLibraries?: boolean;
|
39 | annotationsAs?: 'decorators' | 'static fields';
|
40 | trace?: boolean;
|
41 | disableExpressionLowering?: boolean;
|
42 | i18nOutLocale?: string;
|
43 | i18nOutFormat?: string;
|
44 | i18nOutFile?: string;
|
45 | i18nInFormat?: string;
|
46 | i18nInFile?: string;
|
47 | i18nInMissingTranslations?: 'error' | 'warning' | 'ignore';
|
48 | /**
|
49 | * Whether to generate .ngsummary.ts files that allow to use AOTed artifacts
|
50 | * in JIT mode. This is off by default.
|
51 | */
|
52 | enableSummariesForJit?: boolean;
|
53 | /**
|
54 | * Whether to replace the `templateUrl` and `styleUrls` property in all
|
55 | * @Component decorators with inlined contents in `template` and `styles`
|
56 | * properties.
|
57 | * When enabled, the .js output of ngc will have no lazy-loaded `templateUrl`
|
58 | * or `styleUrl`s. Note that this requires that resources be available to
|
59 | * load statically at compile-time.
|
60 | */
|
61 | enableResourceInlining?: boolean;
|
62 | /**
|
63 | * Whether NGC should generate re-exports for external symbols which are referenced
|
64 | * in Angular metadata (e.g. @Component, @Inject, @ViewChild). This can be enabled in
|
65 | * order to avoid dynamically generated module dependencies which can break strict
|
66 | * dependency enforcements. This is not enabled by default.
|
67 | * Read more about this here: https://github.com/angular/angular/issues/25644.
|
68 | */
|
69 | createExternalSymbolFactoryReexports?: boolean;
|
70 | }
|
71 | export interface CompilerHost extends ts.CompilerHost, ExtendedTsCompilerHost {
|
72 | /**
|
73 | * Converts a module name that is used in an `import` to a file path.
|
74 | * I.e. `path/to/containingFile.ts` containing `import {...} from 'module-name'`.
|
75 | */
|
76 | moduleNameToFileName?(moduleName: string, containingFile: string): string | null;
|
77 | /**
|
78 | * Converts a file name into a representation that should be stored in a summary file.
|
79 | * This has to include changing the suffix as well.
|
80 | * E.g.
|
81 | * `some_file.ts` -> `some_file.d.ts`
|
82 | *
|
83 | * @param referringSrcFileName the soure file that refers to fileName
|
84 | */
|
85 | toSummaryFileName?(fileName: string, referringSrcFileName: string): string;
|
86 | /**
|
87 | * Converts a fileName that was processed by `toSummaryFileName` back into a real fileName
|
88 | * given the fileName of the library that is referrig to it.
|
89 | */
|
90 | fromSummaryFileName?(fileName: string, referringLibFileName: string): string;
|
91 | /**
|
92 | * Produce an AMD module name for the source file. Used in Bazel.
|
93 | *
|
94 | * An AMD module can have an arbitrary name, so that it is require'd by name
|
95 | * rather than by path. See https://requirejs.org/docs/whyamd.html#namedmodules
|
96 | */
|
97 | amdModuleName?(sf: ts.SourceFile): string | undefined;
|
98 | }
|
99 | export declare enum EmitFlags {
|
100 | DTS = 1,
|
101 | JS = 2,
|
102 | Metadata = 4,
|
103 | I18nBundle = 8,
|
104 | Codegen = 16,
|
105 | Default = 19,
|
106 | All = 31
|
107 | }
|
108 | export interface CustomTransformers {
|
109 | beforeTs?: ts.TransformerFactory<ts.SourceFile>[];
|
110 | afterTs?: ts.TransformerFactory<ts.SourceFile>[];
|
111 | }
|
112 | export interface TsEmitArguments {
|
113 | program: ts.Program;
|
114 | host: CompilerHost;
|
115 | options: CompilerOptions;
|
116 | targetSourceFile?: ts.SourceFile;
|
117 | writeFile?: ts.WriteFileCallback;
|
118 | cancellationToken?: ts.CancellationToken;
|
119 | emitOnlyDtsFiles?: boolean;
|
120 | customTransformers?: ts.CustomTransformers;
|
121 | }
|
122 | export interface TsEmitCallback {
|
123 | (args: TsEmitArguments): ts.EmitResult;
|
124 | }
|
125 | export interface TsMergeEmitResultsCallback {
|
126 | (results: ts.EmitResult[]): ts.EmitResult;
|
127 | }
|
128 | export interface LibrarySummary {
|
129 | fileName: string;
|
130 | text: string;
|
131 | sourceFile?: ts.SourceFile;
|
132 | }
|
133 | export interface LazyRoute {
|
134 | route: string;
|
135 | module: {
|
136 | name: string;
|
137 | filePath: string;
|
138 | };
|
139 | referencedModule: {
|
140 | name: string;
|
141 | filePath: string;
|
142 | };
|
143 | }
|
144 | export interface Program {
|
145 | /**
|
146 | * Retrieve the TypeScript program used to produce semantic diagnostics and emit the sources.
|
147 | *
|
148 | * Angular structural information is required to produce the program.
|
149 | */
|
150 | getTsProgram(): ts.Program;
|
151 | /**
|
152 | * Retrieve options diagnostics for the TypeScript options used to create the program. This is
|
153 | * faster than calling `getTsProgram().getOptionsDiagnostics()` since it does not need to
|
154 | * collect Angular structural information to produce the errors.
|
155 | */
|
156 | getTsOptionDiagnostics(cancellationToken?: ts.CancellationToken): ReadonlyArray<ts.Diagnostic>;
|
157 | /**
|
158 | * Retrieve options diagnostics for the Angular options used to create the program.
|
159 | */
|
160 | getNgOptionDiagnostics(cancellationToken?: ts.CancellationToken): ReadonlyArray<ts.Diagnostic | Diagnostic>;
|
161 | /**
|
162 | * Retrieve the syntax diagnostics from TypeScript. This is faster than calling
|
163 | * `getTsProgram().getSyntacticDiagnostics()` since it does not need to collect Angular structural
|
164 | * information to produce the errors.
|
165 | */
|
166 | getTsSyntacticDiagnostics(sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken): ReadonlyArray<ts.Diagnostic>;
|
167 | /**
|
168 | * Retrieve the diagnostics for the structure of an Angular application is correctly formed.
|
169 | * This includes validating Angular annotations and the syntax of referenced and imbedded HTML
|
170 | * and CSS.
|
171 | *
|
172 | * Note it is important to displaying TypeScript semantic diagnostics along with Angular
|
173 | * structural diagnostics as an error in the program structure might cause errors detected in
|
174 | * semantic analysis and a semantic error might cause errors in specifying the program structure.
|
175 | *
|
176 | * Angular structural information is required to produce these diagnostics.
|
177 | */
|
178 | getNgStructuralDiagnostics(cancellationToken?: ts.CancellationToken): ReadonlyArray<Diagnostic>;
|
179 | /**
|
180 | * Retrieve the semantic diagnostics from TypeScript. This is equivalent to calling
|
181 | * `getTsProgram().getSemanticDiagnostics()` directly and is included for completeness.
|
182 | */
|
183 | getTsSemanticDiagnostics(sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken): ReadonlyArray<ts.Diagnostic>;
|
184 | /**
|
185 | * Retrieve the Angular semantic diagnostics.
|
186 | *
|
187 | * Angular structural information is required to produce these diagnostics.
|
188 | */
|
189 | getNgSemanticDiagnostics(fileName?: string, cancellationToken?: ts.CancellationToken): ReadonlyArray<ts.Diagnostic | Diagnostic>;
|
190 | /**
|
191 | * Load Angular structural information asynchronously. If this method is not called then the
|
192 | * Angular structural information, including referenced HTML and CSS files, are loaded
|
193 | * synchronously. If the supplied Angular compiler host returns a promise from `loadResource()`
|
194 | * will produce a diagnostic error message or, `getTsProgram()` or `emit` to throw.
|
195 | */
|
196 | loadNgStructureAsync(): Promise<void>;
|
197 | /**
|
198 | * Returns the lazy routes in the program.
|
199 | * @param entryRoute A reference to an NgModule like `someModule#name`. If given,
|
200 | * will recursively analyze routes starting from this symbol only.
|
201 | * Otherwise will list all routes for all NgModules in the program/
|
202 | */
|
203 | listLazyRoutes(entryRoute?: string): LazyRoute[];
|
204 | /**
|
205 | * Emit the files requested by emitFlags implied by the program.
|
206 | *
|
207 | * Angular structural information is required to emit files.
|
208 | */
|
209 | emit({ emitFlags, cancellationToken, customTransformers, emitCallback, mergeEmitResultsCallback }?: {
|
210 | emitFlags?: EmitFlags;
|
211 | cancellationToken?: ts.CancellationToken;
|
212 | customTransformers?: CustomTransformers;
|
213 | emitCallback?: TsEmitCallback;
|
214 | mergeEmitResultsCallback?: TsMergeEmitResultsCallback;
|
215 | }): ts.EmitResult;
|
216 | /**
|
217 | * Returns the .d.ts / .ngsummary.json / .ngfactory.d.ts files of libraries that have been emitted
|
218 | * in this program or previous programs with paths that emulate the fact that these libraries
|
219 | * have been compiled before with no outDir.
|
220 | */
|
221 | getLibrarySummaries(): Map<string, LibrarySummary>;
|
222 | }
|