Revert "Revert "Revert "perf(compiler): skip type check and emit in bazel in some cases. (#19646)"""
This reverts commit 6b7cead0c5
.
This commit is contained in:
@ -14,7 +14,7 @@ export class GeneratedFile {
|
||||
public stmts: Statement[]|null;
|
||||
|
||||
constructor(
|
||||
public srcFileName: string, public genFileName: string, sourceOrStmts: string|Statement[]) {
|
||||
public srcFileUrl: string, public genFileUrl: string, sourceOrStmts: string|Statement[]) {
|
||||
if (typeof sourceOrStmts === 'string') {
|
||||
this.source = sourceOrStmts;
|
||||
this.stmts = null;
|
||||
@ -25,7 +25,7 @@ export class GeneratedFile {
|
||||
}
|
||||
|
||||
isEquivalent(other: GeneratedFile): boolean {
|
||||
if (this.genFileName !== other.genFileName) {
|
||||
if (this.genFileUrl !== other.genFileUrl) {
|
||||
return false;
|
||||
}
|
||||
if (this.source) {
|
||||
@ -42,7 +42,7 @@ export class GeneratedFile {
|
||||
|
||||
export function toTypeScript(file: GeneratedFile, preamble: string = ''): string {
|
||||
if (!file.stmts) {
|
||||
throw new Error(`Illegal state: No stmts present on GeneratedFile ${file.genFileName}`);
|
||||
throw new Error(`Illegal state: No stmts present on GeneratedFile ${file.genFileUrl}`);
|
||||
}
|
||||
return new TypeScriptEmitter().emitStatements(file.genFileName, file.stmts, preamble);
|
||||
return new TypeScriptEmitter().emitStatements(file.genFileUrl, file.stmts, preamble);
|
||||
}
|
||||
|
@ -22,8 +22,8 @@ describe('compiler (unbundled Angular)', () => {
|
||||
describe('Quickstart', () => {
|
||||
it('should compile', () => {
|
||||
const {genFiles} = compile([QUICKSTART, angularFiles]);
|
||||
expect(genFiles.find(f => /app\.component\.ngfactory\.ts/.test(f.genFileName))).toBeDefined();
|
||||
expect(genFiles.find(f => /app\.module\.ngfactory\.ts/.test(f.genFileName))).toBeDefined();
|
||||
expect(genFiles.find(f => /app\.component\.ngfactory\.ts/.test(f.genFileUrl))).toBeDefined();
|
||||
expect(genFiles.find(f => /app\.module\.ngfactory\.ts/.test(f.genFileUrl))).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
@ -54,7 +54,7 @@ describe('compiler (unbundled Angular)', () => {
|
||||
function compileApp(): GeneratedFile {
|
||||
const {genFiles} = compile([rootDir, angularFiles]);
|
||||
return genFiles.find(
|
||||
genFile => genFile.srcFileName === componentPath && genFile.genFileName.endsWith('.ts'));
|
||||
genFile => genFile.srcFileUrl === componentPath && genFile.genFileUrl.endsWith('.ts'));
|
||||
}
|
||||
|
||||
function findLineAndColumn(
|
||||
@ -127,7 +127,7 @@ describe('compiler (unbundled Angular)', () => {
|
||||
const genFile = compileApp();
|
||||
const genSource = toTypeScript(genFile);
|
||||
const sourceMap = extractSourceMap(genSource) !;
|
||||
expect(sourceMap.file).toEqual(genFile.genFileName);
|
||||
expect(sourceMap.file).toEqual(genFile.genFileUrl);
|
||||
|
||||
// Note: the generated file also contains code that is not mapped to
|
||||
// the template (e.g. import statements, ...)
|
||||
@ -322,7 +322,7 @@ describe('compiler (unbundled Angular)', () => {
|
||||
const genFilePreamble = '/* Hello world! */';
|
||||
const {genFiles} = compile([FILES, angularFiles]);
|
||||
const genFile =
|
||||
genFiles.find(gf => gf.srcFileName === '/app/app.ts' && gf.genFileName.endsWith('.ts'));
|
||||
genFiles.find(gf => gf.srcFileUrl === '/app/app.ts' && gf.genFileUrl.endsWith('.ts'));
|
||||
const genSource = toTypeScript(genFile, genFilePreamble);
|
||||
expect(genSource.startsWith(genFilePreamble)).toBe(true);
|
||||
});
|
||||
@ -407,7 +407,7 @@ describe('compiler (unbundled Angular)', () => {
|
||||
};
|
||||
const result = compile([FILES, angularFiles]);
|
||||
const appModuleFactory =
|
||||
result.genFiles.find(f => /my-component\.ngfactory/.test(f.genFileName));
|
||||
result.genFiles.find(f => /my-component\.ngfactory/.test(f.genFileUrl));
|
||||
expect(appModuleFactory).toBeDefined();
|
||||
if (appModuleFactory) {
|
||||
expect(toTypeScript(appModuleFactory)).toContain('MyComponentNgFactory');
|
||||
@ -441,7 +441,7 @@ describe('compiler (unbundled Angular)', () => {
|
||||
}
|
||||
};
|
||||
const {genFiles} = compile([FILES, angularFiles]);
|
||||
const genFile = genFiles.find(genFile => genFile.srcFileName === '/app/app.ts');
|
||||
const genFile = genFiles.find(genFile => genFile.srcFileUrl === '/app/app.ts');
|
||||
const genSource = toTypeScript(genFile);
|
||||
const createComponentFactoryCall = /ɵccf\([^)]*\)/m.exec(genSource) ![0].replace(/\s*/g, '');
|
||||
// selector
|
||||
@ -472,7 +472,7 @@ describe('compiler (unbundled Angular)', () => {
|
||||
};
|
||||
const {genFiles} = compile([FILES, angularFiles]);
|
||||
const genFile =
|
||||
genFiles.find(gf => gf.srcFileName === '/app/app.ts' && gf.genFileName.endsWith('.ts'));
|
||||
genFiles.find(gf => gf.srcFileUrl === '/app/app.ts' && gf.genFileUrl.endsWith('.ts'));
|
||||
const genSource = toTypeScript(genFile);
|
||||
expect(genSource).not.toContain('check(');
|
||||
|
||||
@ -510,7 +510,7 @@ describe('compiler (unbundled Angular)', () => {
|
||||
const {outDir: libOutDir} = compile([libInput, angularSummaryFiles], {useSummaries: true});
|
||||
const {genFiles: appGenFiles} =
|
||||
compile([appInput, libOutDir, angularSummaryFiles], {useSummaries: true});
|
||||
const appNgFactory = appGenFiles.find((f) => f.genFileName === '/app/main.ngfactory.ts');
|
||||
const appNgFactory = appGenFiles.find((f) => f.genFileUrl === '/app/main.ngfactory.ts');
|
||||
expect(toTypeScript(appNgFactory)).not.toContain('AType');
|
||||
});
|
||||
});
|
||||
@ -555,7 +555,7 @@ describe('compiler (unbundled Angular)', () => {
|
||||
compile([libInput, getAngularSummaryFiles()], {useSummaries: true});
|
||||
const {genFiles} =
|
||||
compile([libOutDir, appInput, getAngularSummaryFiles()], {useSummaries: true});
|
||||
return genFiles.find(gf => gf.srcFileName === '/app/main.ts');
|
||||
return genFiles.find(gf => gf.srcFileUrl === '/app/main.ts');
|
||||
}
|
||||
|
||||
it('should inherit ctor and lifecycle hooks from classes in other compilation units', () => {
|
||||
@ -592,7 +592,7 @@ describe('compiler (unbundled Angular)', () => {
|
||||
compile([libInput, getAngularSummaryFiles()], {useSummaries: true});
|
||||
const {genFiles} =
|
||||
compile([libOutDir, appInput, getAngularSummaryFiles()], {useSummaries: true});
|
||||
const mainNgFactory = genFiles.find(gf => gf.srcFileName === '/app/main.ts');
|
||||
const mainNgFactory = genFiles.find(gf => gf.srcFileUrl === '/app/main.ts');
|
||||
const flags = NodeFlags.TypeDirective | NodeFlags.Component | NodeFlags.OnDestroy;
|
||||
expect(toTypeScript(mainNgFactory))
|
||||
.toContain(`${flags},(null as any),0,i1.Extends,[i2.AParam]`);
|
||||
@ -645,7 +645,7 @@ describe('compiler (unbundled Angular)', () => {
|
||||
compile([lib1OutDir, lib2Input, getAngularSummaryFiles()], {useSummaries: true});
|
||||
const {genFiles} =
|
||||
compile([lib2OutDir, appInput, getAngularSummaryFiles()], {useSummaries: true});
|
||||
const mainNgFactory = genFiles.find(gf => gf.srcFileName === '/app/main.ts');
|
||||
const mainNgFactory = genFiles.find(gf => gf.srcFileUrl === '/app/main.ts');
|
||||
const flags = NodeFlags.TypeDirective | NodeFlags.Component | NodeFlags.OnDestroy;
|
||||
expect(toTypeScript(mainNgFactory))
|
||||
.toContain(`${flags},(null as any),0,i1.Extends,[i2.AParam_2]`);
|
||||
@ -803,8 +803,8 @@ describe('compiler (bundled Angular)', () => {
|
||||
describe('Quickstart', () => {
|
||||
it('should compile', () => {
|
||||
const {genFiles} = compile([QUICKSTART, angularFiles]);
|
||||
expect(genFiles.find(f => /app\.component\.ngfactory\.ts/.test(f.genFileName))).toBeDefined();
|
||||
expect(genFiles.find(f => /app\.module\.ngfactory\.ts/.test(f.genFileName))).toBeDefined();
|
||||
expect(genFiles.find(f => /app\.component\.ngfactory\.ts/.test(f.genFileUrl))).toBeDefined();
|
||||
expect(genFiles.find(f => /app\.module\.ngfactory\.ts/.test(f.genFileUrl))).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -41,7 +41,7 @@ describe('aot summaries for jit', () => {
|
||||
const rootDir = {'app': appDir};
|
||||
|
||||
const genFile =
|
||||
compileApp(rootDir).genFiles.find(f => f.genFileName === '/app/app.module.ngsummary.ts');
|
||||
compileApp(rootDir).genFiles.find(f => f.genFileUrl === '/app/app.module.ngsummary.ts');
|
||||
const genSource = toTypeScript(genFile);
|
||||
|
||||
expect(genSource).toContain(`import * as i0 from '/app/app.module'`);
|
||||
@ -70,7 +70,7 @@ describe('aot summaries for jit', () => {
|
||||
const rootDir = {'app': appDir};
|
||||
|
||||
const genFile =
|
||||
compileApp(rootDir).genFiles.find(f => f.genFileName === '/app/app.module.ngsummary.ts');
|
||||
compileApp(rootDir).genFiles.find(f => f.genFileUrl === '/app/app.module.ngsummary.ts');
|
||||
const genSource = toTypeScript(genFile);
|
||||
|
||||
expect(genSource).toContain(`import * as i0 from '/app/app.module'`);
|
||||
@ -99,7 +99,7 @@ describe('aot summaries for jit', () => {
|
||||
const rootDir = {'app': appDir};
|
||||
|
||||
const genFile =
|
||||
compileApp(rootDir).genFiles.find(f => f.genFileName === '/app/app.module.ngsummary.ts');
|
||||
compileApp(rootDir).genFiles.find(f => f.genFileUrl === '/app/app.module.ngsummary.ts');
|
||||
const genSource = toTypeScript(genFile);
|
||||
|
||||
expect(genSource).toContain(`import * as i0 from '/app/app.module'`);
|
||||
@ -125,7 +125,7 @@ describe('aot summaries for jit', () => {
|
||||
const rootDir = {'app': appDir};
|
||||
|
||||
const genFile =
|
||||
compileApp(rootDir).genFiles.find(f => f.genFileName === '/app/app.module.ngsummary.ts');
|
||||
compileApp(rootDir).genFiles.find(f => f.genFileUrl === '/app/app.module.ngsummary.ts');
|
||||
const genSource = toTypeScript(genFile);
|
||||
|
||||
expect(genSource).toContain(`import * as i0 from '/app/app.module'`);
|
||||
@ -164,7 +164,7 @@ describe('aot summaries for jit', () => {
|
||||
const rootDir = {'app': appDir};
|
||||
|
||||
const genFile =
|
||||
compileApp(rootDir).genFiles.find(f => f.genFileName === '/app/app.module.ngsummary.ts');
|
||||
compileApp(rootDir).genFiles.find(f => f.genFileUrl === '/app/app.module.ngsummary.ts');
|
||||
const genSource = toTypeScript(genFile);
|
||||
|
||||
expect(genSource).toMatch(/useClass:\{\s*reference:i1.MyService/);
|
||||
@ -198,7 +198,7 @@ describe('aot summaries for jit', () => {
|
||||
const rootDir = {'app': appDir};
|
||||
|
||||
const genFile =
|
||||
compileApp(rootDir).genFiles.find(f => f.genFileName === '/app/app.module.ngsummary.ts');
|
||||
compileApp(rootDir).genFiles.find(f => f.genFileUrl === '/app/app.module.ngsummary.ts');
|
||||
const genSource = toTypeScript(genFile);
|
||||
|
||||
expect(genSource).toMatch(/useClass:\{\s*reference:i1.MyService/);
|
||||
@ -225,7 +225,7 @@ describe('aot summaries for jit', () => {
|
||||
const rootDir = {'app': appDir};
|
||||
|
||||
const genFile =
|
||||
compileApp(rootDir).genFiles.find(f => f.genFileName === '/app/app.module.ngsummary.ts');
|
||||
compileApp(rootDir).genFiles.find(f => f.genFileUrl === '/app/app.module.ngsummary.ts');
|
||||
const genSource = toTypeScript(genFile);
|
||||
|
||||
expect(genSource).toMatch(
|
||||
@ -247,7 +247,7 @@ describe('aot summaries for jit', () => {
|
||||
const rootDir = {'app': appDir};
|
||||
|
||||
const genFile =
|
||||
compileApp(rootDir).genFiles.find(f => f.genFileName === '/app/app.module.ngsummary.ts');
|
||||
compileApp(rootDir).genFiles.find(f => f.genFileUrl === '/app/app.module.ngsummary.ts');
|
||||
const genSource = toTypeScript(genFile);
|
||||
|
||||
expect(genSource).toMatch(
|
||||
@ -294,9 +294,9 @@ describe('aot summaries for jit', () => {
|
||||
};
|
||||
const {outDir: lib3In, genFiles: lib2Gen} = compileApp(lib2In, {useSummaries: true});
|
||||
|
||||
const lib2ModuleNgSummary = lib2Gen.find(f => f.genFileName === '/lib2/module.ngsummary.ts');
|
||||
const lib2ModuleNgSummary = lib2Gen.find(f => f.genFileUrl === '/lib2/module.ngsummary.ts');
|
||||
const lib2ReexportNgSummary =
|
||||
lib2Gen.find(f => f.genFileName === '/lib2/reexport.ngsummary.ts');
|
||||
lib2Gen.find(f => f.genFileUrl === '/lib2/reexport.ngsummary.ts');
|
||||
|
||||
// ngsummaries should add reexports for imported NgModules from a direct dependency
|
||||
expect(toTypeScript(lib2ModuleNgSummary))
|
||||
@ -325,9 +325,9 @@ describe('aot summaries for jit', () => {
|
||||
};
|
||||
|
||||
const lib3Gen = compileApp(lib3In, {useSummaries: true}).genFiles;
|
||||
const lib3ModuleNgSummary = lib3Gen.find(f => f.genFileName === '/lib3/module.ngsummary.ts');
|
||||
const lib3ModuleNgSummary = lib3Gen.find(f => f.genFileUrl === '/lib3/module.ngsummary.ts');
|
||||
const lib3ReexportNgSummary =
|
||||
lib3Gen.find(f => f.genFileName === '/lib3/reexport.ngsummary.ts');
|
||||
lib3Gen.find(f => f.genFileUrl === '/lib3/reexport.ngsummary.ts');
|
||||
|
||||
// ngsummary.ts files should use the reexported values from direct and deep deps
|
||||
const lib3ModuleNgSummarySource = toTypeScript(lib3ModuleNgSummary);
|
||||
|
@ -27,6 +27,6 @@ describe('regressions', () => {
|
||||
const {genFiles} = compile(
|
||||
[rootDir, angularFiles], {postCompile: expectNoDiagnostics},
|
||||
{noUnusedLocals: true, noUnusedParameters: true});
|
||||
expect(genFiles.find((f) => f.genFileName === '/app/app.module.ngfactory.ts')).toBeTruthy();
|
||||
expect(genFiles.find((f) => f.genFileUrl === '/app/app.module.ngfactory.ts')).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
@ -658,10 +658,10 @@ export function compile(
|
||||
const genFiles = compiler.emitAllImpls(analyzedModules);
|
||||
genFiles.forEach((file) => {
|
||||
const source = file.source || toTypeScript(file);
|
||||
if (isSource(file.genFileName)) {
|
||||
host.addScript(file.genFileName, source);
|
||||
if (isSource(file.genFileUrl)) {
|
||||
host.addScript(file.genFileUrl, source);
|
||||
} else {
|
||||
host.override(file.genFileName, source);
|
||||
host.override(file.genFileUrl, source);
|
||||
}
|
||||
});
|
||||
const newProgram = ts.createProgram(host.scriptNames.slice(0), tsSettings, host);
|
||||
@ -671,7 +671,7 @@ export function compile(
|
||||
}
|
||||
let outDir: MockDirectory = {};
|
||||
if (emit) {
|
||||
const dtsFilesWithGenFiles = new Set<string>(genFiles.map(gf => gf.srcFileName).filter(isDts));
|
||||
const dtsFilesWithGenFiles = new Set<string>(genFiles.map(gf => gf.srcFileUrl).filter(isDts));
|
||||
outDir =
|
||||
arrayToMockDir(toMockFileArray([host.writtenFiles, host.overrides])
|
||||
.filter((entry) => !isSource(entry.fileName))
|
||||
|
Reference in New Issue
Block a user