Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit 1b0f163

Browse files
committed
fix(ngc): simpler AoT error reporting
simpler AoT error reporting
1 parent cc99a73 commit 1b0f163

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

src/aot/aot-compiler.ts

+32-32
Original file line numberDiff line numberDiff line change
@@ -46,38 +46,46 @@ export class AotCompiler {
4646
}
4747

4848
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(() => {
7172
// Create a new Program, based on the old one. This will trigger a resolution of all
7273
// transitive modules, which include files that might just have been generated.
7374
this.program = createProgram(this.tsConfig.parsed.fileNames, this.tsConfig.parsed.options, this.compilerHost, this.program);
74-
75+
const globalDiagnostics = this.program.getGlobalDiagnostics();
7576
const tsDiagnostics = this.program.getSyntacticDiagnostics()
7677
.concat(this.program.getSemanticDiagnostics())
7778
.concat(this.program.getOptionsDiagnostics());
7879

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+
}
7985
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'));
8189
}
8290
})
8391
.then(() => {
@@ -111,14 +119,6 @@ export class AotCompiler {
111119
}
112120

113121
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-
122122
const transpileOptions: TranspileOptions = {
123123
compilerOptions: options,
124124
fileName: fileName,

0 commit comments

Comments
 (0)