1
|
/**
|
2
|
* @license
|
3
|
* Copyright Google Inc. 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
|
import { ParseSourceSpan } from '@angular/compiler';
|
9
|
import * as ts from 'typescript';
|
10
|
export declare enum DiagnosticCategory {
|
11
|
Warning = 0,
|
12
|
Error = 1,
|
13
|
Message = 2,
|
14
|
}
|
15
|
export interface Diagnostic {
|
16
|
message: string;
|
17
|
span?: ParseSourceSpan;
|
18
|
category: DiagnosticCategory;
|
19
|
}
|
20
|
export interface CompilerOptions extends ts.CompilerOptions {
|
21
|
genDir?: string;
|
22
|
basePath?: string;
|
23
|
skipMetadataEmit?: boolean;
|
24
|
strictMetadataEmit?: boolean;
|
25
|
skipTemplateCodegen?: boolean;
|
26
|
flatModuleOutFile?: string;
|
27
|
flatModuleId?: string;
|
28
|
generateCodeForLibraries?: boolean;
|
29
|
annotateForClosureCompiler?: boolean;
|
30
|
annotationsAs?: 'decorators' | 'static fields';
|
31
|
trace?: boolean;
|
32
|
enableLegacyTemplate?: boolean;
|
33
|
preserveWhitespaces?: boolean;
|
34
|
}
|
35
|
export interface ModuleFilenameResolver {
|
36
|
/**
|
37
|
* Converts a module name that is used in an `import` to a file path.
|
38
|
* I.e. `path/to/containingFile.ts` containing `import {...} from 'module-name'`.
|
39
|
*/
|
40
|
moduleNameToFileName(moduleName: string, containingFile?: string): string | null;
|
41
|
/**
|
42
|
* Converts a file path to a module name that can be used as an `import.
|
43
|
* I.e. `path/to/importedFile.ts` should be imported by `path/to/containingFile.ts`.
|
44
|
*
|
45
|
* See ImportResolver.
|
46
|
*/
|
47
|
fileNameToModuleName(importedFilePath: string, containingFilePath: string): string | null;
|
48
|
getNgCanonicalFileName(fileName: string): string;
|
49
|
assumeFileExists(fileName: string): void;
|
50
|
}
|
51
|
export interface CompilerHost extends ts.CompilerHost, ModuleFilenameResolver {
|
52
|
/**
|
53
|
* Load a referenced resource either statically or asynchronously. If the host returns a
|
54
|
* `Promise<string>` it is assumed the user of the corresponding `Program` will call
|
55
|
* `loadNgStructureAsync()`. Returing `Promise<string>` outside `loadNgStructureAsync()` will
|
56
|
* cause a diagnostics diagnostic error or an exception to be thrown.
|
57
|
*
|
58
|
* If `loadResource()` is not provided, `readFile()` will be called to load the resource.
|
59
|
*/
|
60
|
readResource?(fileName: string): Promise<string> | string;
|
61
|
}
|
62
|
export declare enum EmitFlags {
|
63
|
DTS = 1,
|
64
|
JS = 2,
|
65
|
Metadata = 4,
|
66
|
I18nBundle = 8,
|
67
|
Summary = 16,
|
68
|
Default = 3,
|
69
|
All = 31,
|
70
|
}
|
71
|
export interface Program {
|
72
|
/**
|
73
|
* Retrieve the TypeScript program used to produce semantic diagnostics and emit the sources.
|
74
|
*
|
75
|
* Angular structural information is required to produce the program.
|
76
|
*/
|
77
|
getTsProgram(): ts.Program;
|
78
|
/**
|
79
|
* Retreive options diagnostics for the TypeScript options used to create the program. This is
|
80
|
* faster than calling `getTsProgram().getOptionsDiagnostics()` since it does not need to
|
81
|
* collect Angular structural information to produce the errors.
|
82
|
*/
|
83
|
getTsOptionDiagnostics(cancellationToken?: ts.CancellationToken): ts.Diagnostic[];
|
84
|
/**
|
85
|
* Retrieve options diagnostics for the Angular options used to create the program.
|
86
|
*/
|
87
|
getNgOptionDiagnostics(cancellationToken?: ts.CancellationToken): Diagnostic[];
|
88
|
/**
|
89
|
* Retrive the syntax diagnostics from TypeScript. This is faster than calling
|
90
|
* `getTsProgram().getSyntacticDiagnostics()` since it does not need to collect Angular structural
|
91
|
* information to produce the errors.
|
92
|
*/
|
93
|
getTsSyntacticDiagnostics(sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken): ts.Diagnostic[];
|
94
|
/**
|
95
|
* Retrieve the diagnostics for the structure of an Angular application is correctly formed.
|
96
|
* This includes validating Angular annotations and the syntax of referenced and imbedded HTML
|
97
|
* and CSS.
|
98
|
*
|
99
|
* Note it is important to displaying TypeScript semantic diagnostics along with Angular
|
100
|
* structural diagnostics as an error in the program strucutre might cause errors detected in
|
101
|
* semantic analysis and a semantic error might cause errors in specifying the program structure.
|
102
|
*
|
103
|
* Angular structural information is required to produce these diagnostics.
|
104
|
*/
|
105
|
getNgStructuralDiagnostics(cancellationToken?: ts.CancellationToken): Diagnostic[];
|
106
|
/**
|
107
|
* Retreive the semantic diagnostics from TypeScript. This is equivilent to calling
|
108
|
* `getTsProgram().getSemanticDiagnostics()` directly and is included for completeness.
|
109
|
*/
|
110
|
getTsSemanticDiagnostics(sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken): ts.Diagnostic[];
|
111
|
/**
|
112
|
* Retrieve the Angular semantic diagnostics.
|
113
|
*
|
114
|
* Angular structural information is required to produce these diagnostics.
|
115
|
*/
|
116
|
getNgSemanticDiagnostics(fileName?: string, cancellationToken?: ts.CancellationToken): Diagnostic[];
|
117
|
/**
|
118
|
* Load Angular structural information asynchronously. If this method is not called then the
|
119
|
* Angular structural information, including referenced HTML and CSS files, are loaded
|
120
|
* synchronously. If the supplied Angular compiler host returns a promise from `loadResource()`
|
121
|
* will produce a diagnostic error message or, `getTsProgram()` or `emit` to throw.
|
122
|
*/
|
123
|
loadNgStructureAsync(): Promise<void>;
|
124
|
/**
|
125
|
* Retrieve the lazy route references in the program.
|
126
|
*
|
127
|
* Angular structural information is required to produce these routes.
|
128
|
*/
|
129
|
getLazyRoutes(cancellationToken?: ts.CancellationToken): {
|
130
|
[route: string]: string;
|
131
|
};
|
132
|
/**
|
133
|
* Emit the files requested by emitFlags implied by the program.
|
134
|
*
|
135
|
* Angular structural information is required to emit files.
|
136
|
*/
|
137
|
emit({emitFlags, cancellationToken}: {
|
138
|
emitFlags: EmitFlags;
|
139
|
cancellationToken?: ts.CancellationToken;
|
140
|
}): void;
|
141
|
}
|