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
+
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
+ import { ParseSourceSpan } from '@angular/compiler' ;
19
+ import * as ts from 'typescript' ;
20
+
21
+ import { formatDiagnostics as formatDiagnosticsOrig } from './perform_compile' ;
22
+ import { createCompilerHost as createCompilerOrig } from './transformers/compiler_host' ;
23
+ import { createProgram as createProgramOrig } from './transformers/program' ;
24
+
25
+ // Interfaces from ./transformers/api;
26
+ export interface Diagnostic {
27
+ messageText : string ;
28
+ span ?: ParseSourceSpan ;
29
+ category : ts . DiagnosticCategory ;
30
+ code : number ;
31
+ source : 'angular' ;
32
+ }
33
+
34
+ export interface CompilerOptions extends ts . CompilerOptions {
35
+ basePath ?: string ;
36
+ skipMetadataEmit ?: boolean ;
37
+ strictMetadataEmit ?: boolean ;
38
+ skipTemplateCodegen ?: boolean ;
39
+ flatModuleOutFile ?: string ;
40
+ flatModuleId ?: string ;
41
+ generateCodeForLibraries ?: boolean ;
42
+ annotateForClosureCompiler ?: boolean ;
43
+ annotationsAs ?: 'decorators' | 'static fields' ;
44
+ trace ?: boolean ;
45
+ enableLegacyTemplate ?: boolean ;
46
+ disableExpressionLowering ?: boolean ;
47
+ i18nOutLocale ?: string ;
48
+ i18nOutFormat ?: string ;
49
+ i18nOutFile ?: string ;
50
+ i18nInFormat ?: string ;
51
+ i18nInLocale ?: string ;
52
+ i18nInFile ?: string ;
53
+ i18nInMissingTranslations ?: 'error' | 'warning' | 'ignore' ;
54
+ preserveWhitespaces ?: boolean ;
55
+ }
56
+
57
+ export interface CompilerHost extends ts . CompilerHost {
58
+ moduleNameToFileName ( moduleName : string , containingFile ?: string ) : string | null ;
59
+ fileNameToModuleName ( importedFilePath : string , containingFilePath : string ) : string | null ;
60
+ resourceNameToFileName ( resourceName : string , containingFilePath : string ) : string | null ;
61
+ toSummaryFileName ( fileName : string , referringSrcFileName : string ) : string ;
62
+ fromSummaryFileName ( fileName : string , referringLibFileName : string ) : string ;
63
+ readResource ?( fileName : string ) : Promise < string > | string ;
64
+ }
65
+
66
+ export enum EmitFlags {
67
+ DTS = 1 << 0 ,
68
+ JS = 1 << 1 ,
69
+
70
+ Default = DTS | JS
71
+ }
72
+
73
+ export interface CustomTransformers {
74
+ beforeTs ?: ts . TransformerFactory < ts . SourceFile > [ ] ;
75
+ afterTs ?: ts . TransformerFactory < ts . SourceFile > [ ] ;
76
+ }
77
+
78
+ export interface TsEmitArguments {
79
+ program : ts . Program ;
80
+ host : CompilerHost ;
81
+ options : CompilerOptions ;
82
+ targetSourceFile ?: ts . SourceFile ;
83
+ writeFile ?: ts . WriteFileCallback ;
84
+ cancellationToken ?: ts . CancellationToken ;
85
+ emitOnlyDtsFiles ?: boolean ;
86
+ customTransformers ?: ts . CustomTransformers ;
87
+ }
88
+
89
+ export interface TsEmitCallback { ( args : TsEmitArguments ) : ts . EmitResult ; }
90
+
91
+ export interface Program {
92
+ getTsProgram ( ) : ts . Program ;
93
+ getTsOptionDiagnostics ( cancellationToken ?: ts . CancellationToken ) : ts . Diagnostic [ ] ;
94
+ getNgOptionDiagnostics ( cancellationToken ?: ts . CancellationToken ) : Diagnostic [ ] ;
95
+ getTsSyntacticDiagnostics ( sourceFile ?: ts . SourceFile , cancellationToken ?: ts . CancellationToken ) :
96
+ ts . Diagnostic [ ] ;
97
+ getNgStructuralDiagnostics ( cancellationToken ?: ts . CancellationToken ) : Diagnostic [ ] ;
98
+ getTsSemanticDiagnostics ( sourceFile ?: ts . SourceFile , cancellationToken ?: ts . CancellationToken ) :
99
+ ts . Diagnostic [ ] ;
100
+ getNgSemanticDiagnostics ( fileName ?: string , cancellationToken ?: ts . CancellationToken ) :
101
+ Diagnostic [ ] ;
102
+ loadNgStructureAsync ( ) : Promise < void > ;
103
+ emit ( { emitFlags, cancellationToken, customTransformers, emitCallback} : {
104
+ emitFlags ?: EmitFlags ,
105
+ cancellationToken ?: ts . CancellationToken ,
106
+ customTransformers ?: CustomTransformers ,
107
+ emitCallback ?: TsEmitCallback
108
+ } ) : ts . EmitResult ;
109
+ }
110
+
111
+ // Wrapper for createProgram.
112
+ export function createProgram (
113
+ { rootNames, options, host, oldProgram} :
114
+ { rootNames : string [ ] , options : CompilerOptions , host : CompilerHost , oldProgram ?: Program } ) :
115
+ Program {
116
+ return createProgramOrig ( { rootNames, options, host, oldProgram} ) ;
117
+ }
118
+
119
+ // Wrapper for createCompilerHost.
120
+ export function createCompilerHost (
121
+ { options, tsHost = ts . createCompilerHost ( options , true ) } :
122
+ { options : CompilerOptions , tsHost ?: ts . CompilerHost } ) : CompilerHost {
123
+ return createCompilerOrig ( { options, tsHost} ) ;
124
+ }
125
+
126
+ // Wrapper for formatDiagnostics.
127
+ export type Diagnostics = Array < ts . Diagnostic | Diagnostic > ;
128
+ export function formatDiagnostics ( options : CompilerOptions , diags : Diagnostics ) : string {
129
+ return formatDiagnosticsOrig ( options , diags ) ;
130
+ }
0 commit comments