fix(compiler-cli): only use error collector when needed. (#19912)
The error collector changes behavior of the metadata resolver in ways that haven't been fully hardened. This changes limits its use to the lazy route detection and the language service. Issue: #19906 PR Close #19912
This commit is contained in:
parent
c92efc15fb
commit
7bfeac746e
|
@ -89,7 +89,7 @@ export class NgTools_InternalApi_NG_2 {
|
||||||
// as we only needed this to support Angular CLI 1.5.0 rc.*
|
// as we only needed this to support Angular CLI 1.5.0 rc.*
|
||||||
const ngProgram = createProgram({
|
const ngProgram = createProgram({
|
||||||
rootNames: options.program.getRootFileNames(),
|
rootNames: options.program.getRootFileNames(),
|
||||||
options: options.angularCompilerOptions,
|
options: {...options.angularCompilerOptions, collectAllErrors: true},
|
||||||
host: options.host
|
host: options.host
|
||||||
});
|
});
|
||||||
const lazyRoutes = ngProgram.listLazyRoutes(options.entryModule);
|
const lazyRoutes = ngProgram.listLazyRoutes(options.entryModule);
|
||||||
|
|
|
@ -150,6 +150,9 @@ export interface CompilerOptions extends ts.CompilerOptions {
|
||||||
* in JIT mode. This is off by default.
|
* in JIT mode. This is off by default.
|
||||||
*/
|
*/
|
||||||
enableSummariesForJit?: boolean;
|
enableSummariesForJit?: boolean;
|
||||||
|
|
||||||
|
/** @internal */
|
||||||
|
collectAllErrors?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CompilerHost extends ts.CompilerHost {
|
export interface CompilerHost extends ts.CompilerHost {
|
||||||
|
|
|
@ -422,14 +422,15 @@ class AngularCompilerProgram implements Program {
|
||||||
this.oldProgramLibrarySummaries);
|
this.oldProgramLibrarySummaries);
|
||||||
const aotOptions = getAotCompilerOptions(this.options);
|
const aotOptions = getAotCompilerOptions(this.options);
|
||||||
this._structuralDiagnostics = [];
|
this._structuralDiagnostics = [];
|
||||||
const errorCollector = (err: any) => {
|
const errorCollector =
|
||||||
this._structuralDiagnostics !.push({
|
(this.options.collectAllErrors || this.options.fullTemplateTypeCheck) ? (err: any) => {
|
||||||
messageText: err.toString(),
|
this._structuralDiagnostics !.push({
|
||||||
category: ts.DiagnosticCategory.Error,
|
messageText: err.toString(),
|
||||||
source: SOURCE,
|
category: ts.DiagnosticCategory.Error,
|
||||||
code: DEFAULT_ERROR_CODE
|
source: SOURCE,
|
||||||
});
|
code: DEFAULT_ERROR_CODE
|
||||||
};
|
});
|
||||||
|
} : undefined;
|
||||||
this._compiler = createAotCompiler(this._hostAdapter, aotOptions, errorCollector).compiler;
|
this._compiler = createAotCompiler(this._hostAdapter, aotOptions, errorCollector).compiler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1424,11 +1424,8 @@ describe('ngc transformer command-line', () => {
|
||||||
const messages: string[] = [];
|
const messages: string[] = [];
|
||||||
const exitCode =
|
const exitCode =
|
||||||
main(['-p', path.join(basePath, 'src/tsconfig.json')], message => messages.push(message));
|
main(['-p', path.join(basePath, 'src/tsconfig.json')], message => messages.push(message));
|
||||||
expect(exitCode).toBe(1, 'Compile was expected to fail');
|
expect(exitCode).toBe(2, 'Compile was expected to fail');
|
||||||
expect(messages).toEqual([
|
expect(messages[0]).toContain(['Tagged template expressions are not supported in metadata']);
|
||||||
'Error: Error: Error encountered resolving symbol values statically. Tagged template expressions are not supported in metadata (position 3:27 in the original .ts file)\n' +
|
|
||||||
'Error: No template specified for component TestComponent\n'
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -578,8 +578,8 @@ describe('ng program', () => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function createProgram(rootNames: string[]) {
|
function createProgram(rootNames: string[], overrideOptions: ng.CompilerOptions = {}) {
|
||||||
const options = testSupport.createCompilerOptions();
|
const options = testSupport.createCompilerOptions(overrideOptions);
|
||||||
const host = ng.createCompilerHost({options});
|
const host = ng.createCompilerHost({options});
|
||||||
const program = ng.createProgram(
|
const program = ng.createProgram(
|
||||||
{rootNames: rootNames.map(p => path.resolve(testSupport.basePath, p)), options, host});
|
{rootNames: rootNames.map(p => path.resolve(testSupport.basePath, p)), options, host});
|
||||||
|
@ -821,7 +821,7 @@ describe('ng program', () => {
|
||||||
export class ChildModule {}
|
export class ChildModule {}
|
||||||
`,
|
`,
|
||||||
});
|
});
|
||||||
const program = createProgram(['src/main.ts']).program;
|
const program = createProgram(['src/main.ts'], {collectAllErrors: true}).program;
|
||||||
expect(normalizeRoutes(program.listLazyRoutes('src/main#MainModule'))).toEqual([{
|
expect(normalizeRoutes(program.listLazyRoutes('src/main#MainModule'))).toEqual([{
|
||||||
module: {name: 'MainModule', filePath: path.resolve(testSupport.basePath, 'src/main.ts')},
|
module: {name: 'MainModule', filePath: path.resolve(testSupport.basePath, 'src/main.ts')},
|
||||||
referencedModule:
|
referencedModule:
|
||||||
|
|
|
@ -54,7 +54,7 @@ export function createAotUrlResolver(host: {
|
||||||
*/
|
*/
|
||||||
export function createAotCompiler(
|
export function createAotCompiler(
|
||||||
compilerHost: AotCompilerHost, options: AotCompilerOptions,
|
compilerHost: AotCompilerHost, options: AotCompilerOptions,
|
||||||
errorCollector: (error: any, type?: any) =>
|
errorCollector?: (error: any, type?: any) =>
|
||||||
void): {compiler: AotCompiler, reflector: StaticReflector} {
|
void): {compiler: AotCompiler, reflector: StaticReflector} {
|
||||||
let translations: string = options.translations || '';
|
let translations: string = options.translations || '';
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue