Skip to content

Commit c412913

Browse files
tboschalxhub
authored andcommitted
fix(compiler): set emitSkipped to false for incremental compilation
1 parent e3a4ece commit c412913

File tree

2 files changed

+37
-25
lines changed

2 files changed

+37
-25
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ export function i18nGetExtension(formatName: string): string {
734734

735735
function mergeEmitResults(emitResults: ts.EmitResult[]): ts.EmitResult {
736736
const diagnostics: ts.Diagnostic[] = [];
737-
let emitSkipped = true;
737+
let emitSkipped = false;
738738
const emittedFiles: string[] = [];
739739
for (const er of emitResults) {
740740
diagnostics.push(...er.diagnostics);

packages/compiler-cli/test/transformers/program_spec.ts

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe('ng program', () => {
5858

5959
function compile(
6060
oldProgram?: ng.Program, overrideOptions?: ng.CompilerOptions, rootNames?: string[],
61-
host?: CompilerHost): ng.Program {
61+
host?: CompilerHost): {program: ng.Program, emitResult: ts.EmitResult} {
6262
const options = testSupport.createCompilerOptions(overrideOptions);
6363
if (!rootNames) {
6464
rootNames = [path.resolve(testSupport.basePath, 'src/index.ts')];
@@ -73,8 +73,8 @@ describe('ng program', () => {
7373
oldProgram,
7474
});
7575
expectNoDiagnosticsInProgram(options, program);
76-
program.emit();
77-
return program;
76+
const emitResult = program.emit();
77+
return {emitResult, program};
7878
}
7979

8080
describe('reuse of old program', () => {
@@ -87,14 +87,14 @@ describe('ng program', () => {
8787
export * from 'lib/index';
8888
`
8989
});
90-
const p1 = compile();
90+
const p1 = compile().program;
9191
expect(p1.getTsProgram().getSourceFiles().some(
9292
sf => /node_modules\/lib\/.*\.ngfactory\.ts$/.test(sf.fileName)))
9393
.toBe(true);
9494
expect(p1.getTsProgram().getSourceFiles().some(
9595
sf => /node_modules\/lib2\/.*\.ngfactory.*$/.test(sf.fileName)))
9696
.toBe(false);
97-
const p2 = compile(p1);
97+
const p2 = compile(p1).program;
9898
expect(p2.getTsProgram().getSourceFiles().some(
9999
sf => /node_modules\/lib\/.*\.ngfactory.*$/.test(sf.fileName)))
100100
.toBe(false);
@@ -111,15 +111,15 @@ describe('ng program', () => {
111111
export * from 'lib2/index';
112112
`,
113113
});
114-
const p3 = compile(p2);
114+
const p3 = compile(p2).program;
115115
expect(p3.getTsProgram().getSourceFiles().some(
116116
sf => /node_modules\/lib\/.*\.ngfactory.*$/.test(sf.fileName)))
117117
.toBe(false);
118118
expect(p3.getTsProgram().getSourceFiles().some(
119119
sf => /node_modules\/lib2\/.*\.ngfactory\.ts$/.test(sf.fileName)))
120120
.toBe(true);
121121

122-
const p4 = compile(p3);
122+
const p4 = compile(p3).program;
123123
expect(p4.getTsProgram().getSourceFiles().some(
124124
sf => /node_modules\/lib\/.*\.ngfactory.*$/.test(sf.fileName)))
125125
.toBe(false);
@@ -140,14 +140,14 @@ describe('ng program', () => {
140140
export * from 'lib/index';
141141
`
142142
});
143-
const p1 = compile(undefined, {declaration: false});
143+
const p1 = compile(undefined, {declaration: false}).program;
144144
expect(p1.getTsProgram().getSourceFiles().some(
145145
sf => /node_modules\/lib\/.*\.ngfactory\.ts$/.test(sf.fileName)))
146146
.toBe(true);
147147
expect(p1.getTsProgram().getSourceFiles().some(
148148
sf => /node_modules\/lib2\/.*\.ngfactory.*$/.test(sf.fileName)))
149149
.toBe(false);
150-
const p2 = compile(p1, {declaration: false});
150+
const p2 = compile(p1, {declaration: false}).program;
151151
expect(p2.getTsProgram().getSourceFiles().some(
152152
sf => /node_modules\/lib\/.*\.ngfactory.*$/.test(sf.fileName)))
153153
.toBe(false);
@@ -178,37 +178,49 @@ describe('ng program', () => {
178178
host.writeFile = (fileName: string, data: string) => written.set(fileName, data);
179179

180180
// compile libraries
181-
const p1 = compile(undefined, options, undefined, host);
181+
const p1 = compile(undefined, options, undefined, host).program;
182182

183183
// first compile without libraries
184-
const p2 = compile(p1, options, undefined, host);
184+
const p2 = compile(p1, options, undefined, host).program;
185185
expect(written.has(path.resolve(testSupport.basePath, 'built/src/index.js'))).toBe(true);
186186
let ngFactoryContent =
187187
written.get(path.resolve(testSupport.basePath, 'built/src/index.ngfactory.js'));
188188
expect(ngFactoryContent).toMatch(/Start/);
189189

190190
// no change -> no emit
191191
written.clear();
192-
const p3 = compile(p2, options, undefined, host);
192+
const p3 = compile(p2, options, undefined, host).program;
193193
expect(written.size).toBe(0);
194194

195195
// change a user file
196196
written.clear();
197197
fileCache.delete(path.resolve(testSupport.basePath, 'src/index.ts'));
198-
const p4 = compile(p3, options, undefined, host);
198+
const p4 = compile(p3, options, undefined, host).program;
199199
expect(written.size).toBe(1);
200200
expect(written.has(path.resolve(testSupport.basePath, 'built/src/index.js'))).toBe(true);
201201

202202
// change a file that is input to generated files
203203
written.clear();
204204
testSupport.writeFiles({'src/index.html': 'Hello'});
205-
const p5 = compile(p4, options, undefined, host);
205+
compile(p4, options, undefined, host);
206206
expect(written.size).toBe(1);
207207
ngFactoryContent =
208208
written.get(path.resolve(testSupport.basePath, 'built/src/index.ngfactory.js'));
209209
expect(ngFactoryContent).toMatch(/Hello/);
210210
});
211211

212+
it('should set emitSkipped to false for full and incremental emit', () => {
213+
testSupport.writeFiles({
214+
'src/index.ts': createModuleAndCompSource('main'),
215+
});
216+
const {emitResult: emitResult1, program: p1} = compile();
217+
expect(emitResult1.emitSkipped).toBe(false);
218+
const {emitResult: emitResult2, program: p2} = compile(p1);
219+
expect(emitResult2.emitSkipped).toBe(false);
220+
const {emitResult: emitResult3, program: p3} = compile(p2);
221+
expect(emitResult3.emitSkipped).toBe(false);
222+
});
223+
212224
it('should store library summaries on emit', () => {
213225
compileLib('lib');
214226
testSupport.writeFiles({
@@ -218,7 +230,7 @@ describe('ng program', () => {
218230
export * from 'lib/index';
219231
`
220232
});
221-
const p1 = compile();
233+
const p1 = compile().program;
222234
expect(Array.from(p1.getLibrarySummaries().values())
223235
.some(sf => /node_modules\/lib\/index\.ngfactory\.d\.ts$/.test(sf.fileName)))
224236
.toBe(true);
@@ -238,9 +250,9 @@ describe('ng program', () => {
238250
testSupport.writeFiles({'src/index.ts': createModuleAndCompSource('main')});
239251
// Note: the second compile drops factories for library files,
240252
// and therefore changes the structure again
241-
const p1 = compile();
242-
const p2 = compile(p1);
243-
const p3 = compile(p2);
253+
const p1 = compile().program;
254+
const p2 = compile(p1).program;
255+
compile(p2);
244256
expect(tsStructureIsReused(p2.getTsProgram())).toBe(StructureIsReused.Completely);
245257
});
246258

@@ -256,13 +268,13 @@ describe('ng program', () => {
256268
});
257269
// Note: the second compile drops factories for library files,
258270
// and therefore changes the structure again
259-
const p1 = compile();
260-
const p2 = compile(p1);
271+
const p1 = compile().program;
272+
const p2 = compile(p1).program;
261273
testSupport.writeFiles({
262274
'src/main.html': `Another template`,
263275
'src/util.ts': `export const x = 2`,
264276
});
265-
const p3 = compile(p2);
277+
compile(p2);
266278
expect(tsStructureIsReused(p2.getTsProgram())).toBe(StructureIsReused.Completely);
267279
});
268280

@@ -277,11 +289,11 @@ describe('ng program', () => {
277289
});
278290
// Note: the second compile drops factories for library files,
279291
// and therefore changes the structure again
280-
const p1 = compile();
281-
const p2 = compile(p1);
292+
const p1 = compile().program;
293+
const p2 = compile(p1).program;
282294
testSupport.writeFiles(
283295
{'src/util.ts': `import {Injectable} from '@angular/core'; export const x = 1;`});
284-
const p3 = compile(p2);
296+
compile(p2);
285297
expect(tsStructureIsReused(p2.getTsProgram())).toBe(StructureIsReused.SafeModules);
286298
});
287299
});

0 commit comments

Comments
 (0)