Skip to content
This repository was archived by the owner on Jan 19, 2023. It is now read-only.

Commit 43db243

Browse files
committed
refactor(compiler): delete View Engine components of @angular/compiler (angular#44368)
This commit finishes the removal of View Engine from the codebase, deleting those pieces of @angular/compiler which were only used for VE. Co-Authored-By: JoostK <joost.koehoorn@gmail.com> PR Close angular#44368
1 parent 433a956 commit 43db243

File tree

79 files changed

+188
-16177
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+188
-16177
lines changed

packages/bazel/src/ngc-wrapped/index.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import type {AngularCompilerOptions, CompilerHost as NgCompilerHost, TsEmitCallback, Program, Diagnostics, Diagnostic as NgDiagnostic, CompilerOptions} from '@angular/compiler-cli';
9+
import type {AngularCompilerOptions, CompilerHost as NgCompilerHost, TsEmitCallback, Program, CompilerOptions} from '@angular/compiler-cli';
1010
import {BazelOptions, CachedFileLoader, CompilerHost, constructManifest, debug, FileCache, FileLoader, parseTsconfig, resolveNormalizedPath, runAsWorker, runWorkerLoop, UncachedFileLoader} from '@bazel/typescript';
1111
import * as fs from 'fs';
1212
import * as path from 'path';
@@ -195,9 +195,9 @@ export function compile({
195195
bazelOpts: BazelOptions,
196196
files: string[],
197197
expectedOuts: string[],
198-
gatherDiagnostics?: (program: Program) => Diagnostics,
198+
gatherDiagnostics?: (program: Program) => readonly ts.Diagnostic[],
199199
bazelHost?: CompilerHost, ng: CompilerCliModule,
200-
}): {diagnostics: Diagnostics, program: Program} {
200+
}): {diagnostics: readonly ts.Diagnostic[], program: Program} {
201201
let fileLoader: FileLoader;
202202

203203
if (bazelOpts.maxCacheSizeMb !== undefined) {
@@ -449,15 +449,15 @@ function convertToForwardSlashPath(filePath: string): string {
449449

450450
function gatherDiagnosticsForInputsOnly(
451451
options: CompilerOptions, bazelOpts: BazelOptions, ngProgram: Program,
452-
ng: CompilerCliModule): (NgDiagnostic|ts.Diagnostic)[] {
452+
ng: CompilerCliModule): ts.Diagnostic[] {
453453
const tsProgram = ngProgram.getTsProgram();
454454

455455
// For the Ivy compiler, track the amount of time spent fetching TypeScript diagnostics.
456456
let previousPhase = ng.PerfPhase.Unaccounted;
457457
if (ngProgram instanceof ng.NgtscProgram) {
458458
previousPhase = ngProgram.compiler.perfRecorder.phase(ng.PerfPhase.TypeScriptDiagnostics);
459459
}
460-
const diagnostics: (NgDiagnostic|ts.Diagnostic)[] = [];
460+
const diagnostics: ts.Diagnostic[] = [];
461461
// These checks mirror ts.getPreEmitDiagnostics, with the important
462462
// exception of avoiding b/30708240, which is that if you call
463463
// program.getDeclarationDiagnostics() it somehow corrupts the emit.

packages/common/test/pipes/date_pipe_spec.ts

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import {DatePipe} from '@angular/common';
1010
import localeEn from '@angular/common/locales/en';
1111
import localeEnExtra from '@angular/common/locales/extra/en';
12-
import {PipeResolver} from '@angular/compiler/src/pipe_resolver';
1312
import {ɵregisterLocaleData, ɵunregisterLocaleData} from '@angular/core';
1413

1514
{

packages/common/test/pipes/i18n_plural_pipe_spec.ts

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
import {I18nPluralPipe, NgLocalization} from '@angular/common';
10-
import {PipeResolver} from '@angular/compiler/src/pipe_resolver';
1110

1211
{
1312
describe('I18nPluralPipe', () => {

packages/common/test/pipes/i18n_select_pipe_spec.ts

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
import {I18nSelectPipe} from '@angular/common';
10-
import {PipeResolver} from '@angular/compiler/src/pipe_resolver';
1110

1211
{
1312
describe('I18nSelectPipe', () => {

packages/compiler-cli/index.ts

-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88
import {NodeJSFileSystem, setFileSystem} from './src/ngtsc/file_system';
99

10-
export {AotCompilerHost, AotCompilerHost as StaticReflectorHost, StaticReflector, StaticSymbol} from '@angular/compiler';
1110
export {VERSION} from './src/version';
1211

1312
export * from './src/transformers/api';
@@ -18,8 +17,6 @@ export * from './src/perform_compile';
1817
// TODO(tbosch): remove this once usages in G3 are changed to `CompilerOptions`
1918
export {CompilerOptions as AngularCompilerOptions} from './src/transformers/api';
2019

21-
export {ngToTsDiagnostic} from './src/transformers/util';
22-
2320
// Internal exports needed for packages relying on the compiler-cli.
2421
// TODO: Remove this when the CLI has switched to the private entry-point.
2522
export * from './private/tooling';

packages/compiler-cli/src/main.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import ts from 'typescript';
1010
import type {TsickleHost} from 'tsickle';
1111
import yargs from 'yargs';
12-
import {Diagnostics, exitCodeFromResult, formatDiagnostics, ParsedConfiguration, performCompilation, readConfiguration} from './perform_compile';
12+
import {exitCodeFromResult, formatDiagnostics, ParsedConfiguration, performCompilation, readConfiguration} from './perform_compile';
1313
import {createPerformWatchHost, performWatchCompilation} from './perform_watch';
1414
import * as api from './transformers/api';
1515
import {GENERATED_FILES} from './transformers/util';
@@ -57,7 +57,7 @@ export function mainDiagnosticsForTest(
5757
programReuse?: {program: api.Program|undefined}, modifiedResourceFiles?: Set<string>|null,
5858
tsickle?: TsickleModule): {
5959
exitCode: number,
60-
diagnostics: ReadonlyArray<ts.Diagnostic|api.Diagnostic>,
60+
diagnostics: ReadonlyArray<ts.Diagnostic>,
6161
} {
6262
let {rootNames, options, errors: configErrors, emitFlags} =
6363
config || readNgcCommandLineAndConfiguration(args);
@@ -223,7 +223,7 @@ function getFormatDiagnosticsHost(options?: api.CompilerOptions): ts.FormatDiagn
223223
}
224224

225225
function reportErrorsAndExit(
226-
allDiagnostics: Diagnostics, options?: api.CompilerOptions,
226+
allDiagnostics: ReadonlyArray<ts.Diagnostic>, options?: api.CompilerOptions,
227227
consoleError: (s: string) => void = console.error): number {
228228
const errorsAndWarnings =
229229
allDiagnostics.filter(d => d.category !== ts.DiagnosticCategory.Message);
@@ -239,8 +239,8 @@ export function watchMode(
239239
}
240240

241241
function printDiagnostics(
242-
diagnostics: ReadonlyArray<ts.Diagnostic|api.Diagnostic>,
243-
options: api.CompilerOptions|undefined, consoleError: (s: string) => void): void {
242+
diagnostics: ReadonlyArray<ts.Diagnostic>, options: api.CompilerOptions|undefined,
243+
consoleError: (s: string) => void): void {
244244
if (diagnostics.length === 0) {
245245
return;
246246
}

packages/compiler-cli/src/ngtsc/program.ts

+5-13
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {GeneratedFile, HtmlParser, MessageBundle} from '@angular/compiler';
9+
import {HtmlParser, MessageBundle} from '@angular/compiler';
1010
import ts from 'typescript';
1111

1212
import * as api from '../transformers/api';
@@ -179,18 +179,18 @@ export class NgtscProgram implements api.Program {
179179
}
180180

181181
getNgOptionDiagnostics(cancellationToken?: ts.CancellationToken|
182-
undefined): readonly(ts.Diagnostic|api.Diagnostic)[] {
182+
undefined): readonly ts.Diagnostic[] {
183183
return this.compiler.getOptionDiagnostics();
184184
}
185185

186186
getNgStructuralDiagnostics(cancellationToken?: ts.CancellationToken|
187-
undefined): readonly api.Diagnostic[] {
187+
undefined): readonly ts.Diagnostic[] {
188188
return [];
189189
}
190190

191191
getNgSemanticDiagnostics(
192-
fileName?: string|undefined, cancellationToken?: ts.CancellationToken|undefined):
193-
readonly(ts.Diagnostic|api.Diagnostic)[] {
192+
fileName?: string|undefined,
193+
cancellationToken?: ts.CancellationToken|undefined): readonly ts.Diagnostic[] {
194194
let sf: ts.SourceFile|undefined = undefined;
195195
if (fileName !== undefined) {
196196
sf = this.tsProgram.getSourceFile(fileName);
@@ -337,14 +337,6 @@ export class NgtscProgram implements api.Program {
337337
return this.compiler.getIndexedComponents();
338338
}
339339

340-
getLibrarySummaries(): Map<string, api.LibrarySummary> {
341-
throw new Error('Method not implemented.');
342-
}
343-
344-
getEmittedGeneratedFiles(): Map<string, GeneratedFile> {
345-
throw new Error('Method not implemented.');
346-
}
347-
348340
getEmittedSourceFiles(): Map<string, ts.SourceFile> {
349341
throw new Error('Method not implemented.');
350342
}

packages/compiler-cli/src/perform_compile.ts

+25-87
Original file line numberDiff line numberDiff line change
@@ -6,99 +6,31 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {isSyntaxError, Position} from '@angular/compiler';
9+
import {isSyntaxError} from '@angular/compiler';
1010
import ts from 'typescript';
1111

1212
import {absoluteFrom, AbsoluteFsPath, FileSystem, getFileSystem, ReadonlyFileSystem, relative, resolve} from '../src/ngtsc/file_system';
13-
import {NgCompilerOptions} from './ngtsc/core/api';
1413

14+
import {NgCompilerOptions} from './ngtsc/core/api';
1515
import {replaceTsWithNgInErrors} from './ngtsc/diagnostics';
1616
import * as api from './transformers/api';
1717
import * as ng from './transformers/entry_points';
1818
import {createMessageDiagnostic} from './transformers/util';
1919

20-
export type Diagnostics = ReadonlyArray<ts.Diagnostic|api.Diagnostic>;
21-
2220
const defaultFormatHost: ts.FormatDiagnosticsHost = {
2321
getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
2422
getCanonicalFileName: fileName => fileName,
2523
getNewLine: () => ts.sys.newLine
2624
};
2725

28-
function displayFileName(fileName: string, host: ts.FormatDiagnosticsHost): string {
29-
return relative(
30-
resolve(host.getCurrentDirectory()), resolve(host.getCanonicalFileName(fileName)));
31-
}
32-
33-
export function formatDiagnosticPosition(
34-
position: Position, host: ts.FormatDiagnosticsHost = defaultFormatHost): string {
35-
return `${displayFileName(position.fileName, host)}(${position.line + 1},${position.column + 1})`;
36-
}
37-
38-
export function flattenDiagnosticMessageChain(
39-
chain: api.DiagnosticMessageChain, host: ts.FormatDiagnosticsHost = defaultFormatHost,
40-
indent = 0): string {
41-
const newLine = host.getNewLine();
42-
let result = '';
43-
if (indent) {
44-
result += newLine;
45-
46-
for (let i = 0; i < indent; i++) {
47-
result += ' ';
48-
}
49-
}
50-
result += chain.messageText;
51-
52-
const position = chain.position;
53-
// add position if available, and we are not at the depest frame
54-
if (position && indent !== 0) {
55-
result += ` at ${formatDiagnosticPosition(position, host)}`;
56-
}
57-
58-
indent++;
59-
if (chain.next) {
60-
for (const kid of chain.next) {
61-
result += flattenDiagnosticMessageChain(kid, host, indent);
62-
}
63-
}
64-
return result;
65-
}
66-
67-
export function formatDiagnostic(
68-
diagnostic: api.Diagnostic, host: ts.FormatDiagnosticsHost = defaultFormatHost) {
69-
let result = '';
70-
const newLine = host.getNewLine();
71-
const span = diagnostic.span;
72-
if (span) {
73-
result += `${
74-
formatDiagnosticPosition(
75-
{fileName: span.start.file.url, line: span.start.line, column: span.start.col},
76-
host)}: `;
77-
} else if (diagnostic.position) {
78-
result += `${formatDiagnosticPosition(diagnostic.position, host)}: `;
79-
}
80-
if (diagnostic.span && diagnostic.span.details) {
81-
result += `${diagnostic.span.details}, ${diagnostic.messageText}${newLine}`;
82-
} else if (diagnostic.chain) {
83-
result += `${flattenDiagnosticMessageChain(diagnostic.chain, host)}.${newLine}`;
84-
} else {
85-
result += `${diagnostic.messageText}${newLine}`;
86-
}
87-
return result;
88-
}
89-
9026
export function formatDiagnostics(
91-
diags: Diagnostics, host: ts.FormatDiagnosticsHost = defaultFormatHost): string {
27+
diags: ReadonlyArray<ts.Diagnostic>,
28+
host: ts.FormatDiagnosticsHost = defaultFormatHost): string {
9229
if (diags && diags.length) {
9330
return diags
94-
.map(diagnostic => {
95-
if (api.isTsDiagnostic(diagnostic)) {
96-
return replaceTsWithNgInErrors(
97-
ts.formatDiagnosticsWithColorAndContext([diagnostic], host));
98-
} else {
99-
return formatDiagnostic(diagnostic, host);
100-
}
101-
})
31+
.map(
32+
diagnostic => replaceTsWithNgInErrors(
33+
ts.formatDiagnosticsWithColorAndContext([diagnostic], host)))
10234
.join('');
10335
} else {
10436
return '';
@@ -264,12 +196,12 @@ function getExtendedConfigPathWorker(
264196
}
265197

266198
export interface PerformCompilationResult {
267-
diagnostics: Diagnostics;
199+
diagnostics: ReadonlyArray<ts.Diagnostic>;
268200
program?: api.Program;
269201
emitResult?: ts.EmitResult;
270202
}
271203

272-
export function exitCodeFromResult(diags: Diagnostics|undefined): number {
204+
export function exitCodeFromResult(diags: ReadonlyArray<ts.Diagnostic>|undefined): number {
273205
if (!diags) return 0;
274206
if (diags.every((diag) => diag.category !== ts.DiagnosticCategory.Error)) {
275207
// If we have a result and didn't get any errors, we succeeded.
@@ -298,14 +230,14 @@ export function performCompilation({
298230
oldProgram?: api.Program,
299231
emitCallback?: api.TsEmitCallback,
300232
mergeEmitResultsCallback?: api.TsMergeEmitResultsCallback,
301-
gatherDiagnostics?: (program: api.Program) => Diagnostics,
233+
gatherDiagnostics?: (program: api.Program) => ReadonlyArray<ts.Diagnostic>,
302234
customTransformers?: api.CustomTransformers,
303235
emitFlags?: api.EmitFlags,
304236
modifiedResourceFiles?: Set<string>| null,
305237
}): PerformCompilationResult {
306238
let program: api.Program|undefined;
307239
let emitResult: ts.EmitResult|undefined;
308-
let allDiagnostics: Array<ts.Diagnostic|api.Diagnostic> = [];
240+
let allDiagnostics: Array<ts.Diagnostic> = [];
309241
try {
310242
if (!host) {
311243
host = ng.createCompilerHost({options});
@@ -344,15 +276,21 @@ export function performCompilation({
344276
program = undefined;
345277
code = api.UNKNOWN_ERROR_CODE;
346278
}
347-
allDiagnostics.push(
348-
{category: ts.DiagnosticCategory.Error, messageText: errMsg, code, source: api.SOURCE});
279+
allDiagnostics.push({
280+
category: ts.DiagnosticCategory.Error,
281+
messageText: errMsg,
282+
code,
283+
file: undefined,
284+
start: undefined,
285+
length: undefined,
286+
});
349287
return {diagnostics: allDiagnostics, program};
350288
}
351289
}
352-
export function defaultGatherDiagnostics(program: api.Program): Diagnostics {
353-
const allDiagnostics: Array<ts.Diagnostic|api.Diagnostic> = [];
290+
export function defaultGatherDiagnostics(program: api.Program): ReadonlyArray<ts.Diagnostic> {
291+
const allDiagnostics: Array<ts.Diagnostic> = [];
354292

355-
function checkDiagnostics(diags: Diagnostics|undefined) {
293+
function checkDiagnostics(diags: ReadonlyArray<ts.Diagnostic>|undefined) {
356294
if (diags) {
357295
allDiagnostics.push(...diags);
358296
return !hasErrors(diags);
@@ -367,7 +305,7 @@ export function defaultGatherDiagnostics(program: api.Program): Diagnostics {
367305

368306
// Check syntactic diagnostics
369307
checkOtherDiagnostics =
370-
checkOtherDiagnostics && checkDiagnostics(program.getTsSyntacticDiagnostics() as Diagnostics);
308+
checkOtherDiagnostics && checkDiagnostics(program.getTsSyntacticDiagnostics());
371309

372310
// Check TypeScript semantic and Angular structure diagnostics
373311
checkOtherDiagnostics =
@@ -377,11 +315,11 @@ export function defaultGatherDiagnostics(program: api.Program): Diagnostics {
377315

378316
// Check Angular semantic diagnostics
379317
checkOtherDiagnostics =
380-
checkOtherDiagnostics && checkDiagnostics(program.getNgSemanticDiagnostics() as Diagnostics);
318+
checkOtherDiagnostics && checkDiagnostics(program.getNgSemanticDiagnostics());
381319

382320
return allDiagnostics;
383321
}
384322

385-
function hasErrors(diags: Diagnostics) {
323+
function hasErrors(diags: ReadonlyArray<ts.Diagnostic>) {
386324
return diags.some(d => d.category === ts.DiagnosticCategory.Error);
387325
}

0 commit comments

Comments
 (0)