UNPKG

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