UNPKG

4.84 kBTypeScriptView Raw
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/// <amd-module name="@angular/compiler-cli/src/ngtools_api2" />
9/**
10 * This is a private API for @ngtools/webpack. This API should be stable for NG 5.
11 *
12 * It contains copies of the interfaces needed and wrapper functions to ensure that
13 * they are not broken accidentally.
14 *
15 * Once the ngc api is public and stable, this can be removed.
16 */
17/**
18 *********************************************************************
19 * Changes to this file need to be approved by the Angular CLI team. *
20 *********************************************************************
21 */
22import { ParseSourceSpan } from '@angular/compiler';
23import * as ts from 'typescript';
24export interface Diagnostic {
25 messageText: string;
26 span?: ParseSourceSpan;
27 category: ts.DiagnosticCategory;
28 code: number;
29 source: 'angular';
30}
31export interface CompilerOptions extends ts.CompilerOptions {
32 basePath?: string;
33 skipMetadataEmit?: boolean;
34 strictMetadataEmit?: boolean;
35 skipTemplateCodegen?: boolean;
36 flatModuleOutFile?: string;
37 flatModuleId?: string;
38 generateCodeForLibraries?: boolean;
39 annotateForClosureCompiler?: boolean;
40 annotationsAs?: 'decorators' | 'static fields';
41 trace?: boolean;
42 disableExpressionLowering?: boolean;
43 i18nOutLocale?: string;
44 i18nOutFormat?: string;
45 i18nOutFile?: string;
46 i18nInFormat?: string;
47 i18nInLocale?: string;
48 i18nInFile?: string;
49 i18nInMissingTranslations?: 'error' | 'warning' | 'ignore';
50 preserveWhitespaces?: boolean;
51 disableTypeScriptVersionCheck?: boolean;
52}
53export interface CompilerHost extends ts.CompilerHost {
54 moduleNameToFileName?(moduleName: string, containingFile?: string): string | null;
55 fileNameToModuleName?(importedFilePath: string, containingFilePath: string): string;
56 resourceNameToFileName?(resourceName: string, containingFilePath: string): string | null;
57 toSummaryFileName?(fileName: string, referringSrcFileName: string): string;
58 fromSummaryFileName?(fileName: string, referringLibFileName: string): string;
59 readResource?(fileName: string): Promise<string> | string;
60}
61export declare enum EmitFlags {
62 DTS = 1,
63 JS = 2,
64 Metadata = 4,
65 I18nBundle = 8,
66 Codegen = 16,
67 Default = 19,
68 All = 31
69}
70export interface CustomTransformers {
71 beforeTs?: ts.TransformerFactory<ts.SourceFile>[];
72 afterTs?: ts.TransformerFactory<ts.SourceFile>[];
73}
74export interface TsEmitArguments {
75 program: ts.Program;
76 host: CompilerHost;
77 options: CompilerOptions;
78 targetSourceFile?: ts.SourceFile;
79 writeFile?: ts.WriteFileCallback;
80 cancellationToken?: ts.CancellationToken;
81 emitOnlyDtsFiles?: boolean;
82 customTransformers?: ts.CustomTransformers;
83}
84export interface TsEmitCallback {
85 (args: TsEmitArguments): ts.EmitResult;
86}
87export interface LazyRoute {
88 module: {
89 name: string;
90 filePath: string;
91 };
92 route: string;
93 referencedModule: {
94 name: string;
95 filePath: string;
96 };
97}
98export interface Program {
99 getTsProgram(): ts.Program;
100 getTsOptionDiagnostics(cancellationToken?: ts.CancellationToken): ReadonlyArray<ts.Diagnostic>;
101 getNgOptionDiagnostics(cancellationToken?: ts.CancellationToken): ReadonlyArray<ts.Diagnostic | Diagnostic>;
102 getTsSyntacticDiagnostics(sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken): ReadonlyArray<ts.Diagnostic>;
103 getNgStructuralDiagnostics(cancellationToken?: ts.CancellationToken): ReadonlyArray<Diagnostic>;
104 getTsSemanticDiagnostics(sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken): ReadonlyArray<ts.Diagnostic>;
105 getNgSemanticDiagnostics(fileName?: string, cancellationToken?: ts.CancellationToken): ReadonlyArray<ts.Diagnostic | Diagnostic>;
106 loadNgStructureAsync(): Promise<void>;
107 listLazyRoutes(entryRoute?: string): LazyRoute[];
108 emit({ emitFlags, cancellationToken, customTransformers, emitCallback }: {
109 emitFlags?: EmitFlags;
110 cancellationToken?: ts.CancellationToken;
111 customTransformers?: CustomTransformers;
112 emitCallback?: TsEmitCallback;
113 }): ts.EmitResult;
114}
115export declare function createProgram({ rootNames, options, host, oldProgram }: {
116 rootNames: string[];
117 options: CompilerOptions;
118 host: CompilerHost;
119 oldProgram?: Program;
120}): Program;
121export declare function createCompilerHost({ options, tsHost }: {
122 options: CompilerOptions;
123 tsHost?: ts.CompilerHost;
124}): CompilerHost;
125export declare type Diagnostics = ReadonlyArray<ts.Diagnostic | Diagnostic>;
126export declare function formatDiagnostics(diags: Diagnostics): string;