@@ -46,38 +46,46 @@ export class AotCompiler {
46
46
}
47
47
48
48
compile ( ) {
49
- clearDiagnostics ( this . context , DiagnosticsType . TypeScript ) ;
50
- const i18nOptions : NgcCliOptions = {
51
- i18nFile : undefined ,
52
- i18nFormat : undefined ,
53
- locale : undefined ,
54
- basePath : this . options . rootDir
55
- } ;
56
-
57
- // Create the Code Generator.
58
- const codeGenerator = CodeGenerator . create (
59
- this . angularCompilerOptions ,
60
- i18nOptions ,
61
- this . program ,
62
- this . compilerHost ,
63
- new NodeReflectorHostContext ( this . compilerHost )
64
- ) ;
65
-
66
- // We need to temporarily patch the CodeGenerator until either it's patched or allows us
67
- // to pass in our own ReflectorHost.
68
- patchReflectorHost ( codeGenerator ) ;
69
- return codeGenerator . codegen ( { transitiveModules : true } )
70
- . then ( ( ) => {
49
+ return Promise . resolve ( ) . then ( ( ) => {
50
+ clearDiagnostics ( this . context , DiagnosticsType . TypeScript ) ;
51
+ const i18nOptions : NgcCliOptions = {
52
+ i18nFile : undefined ,
53
+ i18nFormat : undefined ,
54
+ locale : undefined ,
55
+ basePath : this . options . rootDir
56
+ } ;
57
+
58
+ // Create the Code Generator.
59
+ const codeGenerator = CodeGenerator . create (
60
+ this . angularCompilerOptions ,
61
+ i18nOptions ,
62
+ this . program ,
63
+ this . compilerHost ,
64
+ new NodeReflectorHostContext ( this . compilerHost )
65
+ ) ;
66
+
67
+ // We need to temporarily patch the CodeGenerator until either it's patched or allows us
68
+ // to pass in our own ReflectorHost.
69
+ patchReflectorHost ( codeGenerator ) ;
70
+ return codeGenerator . codegen ( { transitiveModules : true } )
71
+ } ) . then ( ( ) => {
71
72
// Create a new Program, based on the old one. This will trigger a resolution of all
72
73
// transitive modules, which include files that might just have been generated.
73
74
this . program = createProgram ( this . tsConfig . parsed . fileNames , this . tsConfig . parsed . options , this . compilerHost , this . program ) ;
74
-
75
+ const globalDiagnostics = this . program . getGlobalDiagnostics ( ) ;
75
76
const tsDiagnostics = this . program . getSyntacticDiagnostics ( )
76
77
. concat ( this . program . getSemanticDiagnostics ( ) )
77
78
. concat ( this . program . getOptionsDiagnostics ( ) ) ;
78
79
80
+ if ( globalDiagnostics . length ) {
81
+ const diagnostics = runTypeScriptDiagnostics ( this . context , globalDiagnostics ) ;
82
+ printDiagnostics ( this . context , DiagnosticsType . TypeScript , diagnostics , true , false ) ;
83
+ throw new BuildError ( new Error ( 'Failed to transpile TypeScript' ) ) ;
84
+ }
79
85
if ( tsDiagnostics . length ) {
80
- throw tsDiagnostics ;
86
+ const diagnostics = runTypeScriptDiagnostics ( this . context , tsDiagnostics ) ;
87
+ printDiagnostics ( this . context , DiagnosticsType . TypeScript , diagnostics , true , false ) ;
88
+ throw new BuildError ( new Error ( 'Failed to transpile TypeScript' ) ) ;
81
89
}
82
90
} )
83
91
. then ( ( ) => {
@@ -111,14 +119,6 @@ export class AotCompiler {
111
119
}
112
120
113
121
transpileFileContent ( fileName : string , sourceText : string , options : CompilerOptions ) : TranspileOutput {
114
- const sourceFile = this . program . getSourceFile ( fileName ) ;
115
- const diagnostics = this . program . getSyntacticDiagnostics ( sourceFile )
116
- . concat ( this . program . getSemanticDiagnostics ( sourceFile ) )
117
- . concat ( this . program . getDeclarationDiagnostics ( sourceFile ) ) ;
118
- if ( diagnostics . length ) {
119
- throw diagnostics ;
120
- }
121
-
122
122
const transpileOptions : TranspileOptions = {
123
123
compilerOptions : options ,
124
124
fileName : fileName ,
0 commit comments