feat(ivy): output diagnostics for many errors in ngtsc (#25647)

This commit takes the first steps towards ngtsc producing real
TypeScript diagnostics instead of simply throwing errors when
encountering incorrect code.

A new class is introduced, FatalDiagnosticError, which can be thrown by
handlers whenever a condition in the code is encountered which by
necessity prevents the class from being compiled. This error type is
convertable to a ts.Diagnostic which represents the type and source of
the error.

Error codes are introduced for Angular errors, and are prefixed with -99
(so error code 1001 becomes -991001) to distinguish them from other TS
errors.

A function is provided which will read TS diagnostic output and convert
the TS errors to NG errors if they match this negative error code
format.

PR Close #25647
This commit is contained in:
Alex Rickabaugh
2018-08-23 14:34:55 -07:00
committed by Misko Hevery
parent b424b3187e
commit 38f624d7e3
19 changed files with 331 additions and 85 deletions

View File

@ -11,6 +11,7 @@ ts_library(
module_name = "@angular/compiler-cli/src/ngtsc/transform",
deps = [
"//packages/compiler",
"//packages/compiler-cli/src/ngtsc/diagnostics",
"//packages/compiler-cli/src/ngtsc/host",
"//packages/compiler-cli/src/ngtsc/metadata",
"//packages/compiler-cli/src/ngtsc/util",

View File

@ -9,6 +9,7 @@
import {ConstantPool} from '@angular/compiler';
import * as ts from 'typescript';
import {FatalDiagnosticError} from '../../diagnostics';
import {Decorator, ReflectionHost} from '../../host';
import {reflectNameOfDeclaration} from '../../metadata/src/reflector';
@ -98,23 +99,30 @@ export class IvyCompilation {
// Run analysis on the metadata. This will produce either diagnostics, an
// analysis result, or both.
const analysis = adapter.analyze(node, metadata);
try {
const analysis = adapter.analyze(node, metadata);
if (analysis.analysis !== undefined) {
this.analysis.set(node, {
adapter,
analysis: analysis.analysis,
metadata: metadata,
});
}
if (analysis.analysis !== undefined) {
this.analysis.set(node, {
adapter,
analysis: analysis.analysis,
metadata: metadata,
});
}
if (analysis.diagnostics !== undefined) {
this._diagnostics.push(...analysis.diagnostics);
}
if (analysis.diagnostics !== undefined) {
this._diagnostics.push(...analysis.diagnostics);
}
if (analysis.factorySymbolName !== undefined && this.sourceToFactorySymbols !== null &&
this.sourceToFactorySymbols.has(sf.fileName)) {
this.sourceToFactorySymbols.get(sf.fileName) !.add(analysis.factorySymbolName);
if (analysis.factorySymbolName !== undefined && this.sourceToFactorySymbols !== null &&
this.sourceToFactorySymbols.has(sf.fileName)) {
this.sourceToFactorySymbols.get(sf.fileName) !.add(analysis.factorySymbolName);
}
} catch (err) {
if (err instanceof FatalDiagnosticError) {
this._diagnostics.push(err.toDiagnostic());
} else {
throw err;
}
}
};