fix(compiler): don’t call check
if we don’t need to (#15322)
If a directive has not bindings nor has a `ngDoCheck` / `ngOnInit` lifecycle hook, don’t generate a `check` call. This does not have an impact on the behavior, but produces less code. PR Close #15322
This commit is contained in:

committed by
Miško Hevery

parent
9bf2fb4a74
commit
764e90f9bb
@ -339,6 +339,35 @@ describe('compiler (unbundled Angular)', () => {
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('generated templates', () => {
|
||||
it('should not call `check` for directives without bindings nor ngDoCheck/ngOnInit',
|
||||
async(() => {
|
||||
const FILES: MockData = {
|
||||
app: {
|
||||
'app.ts': `
|
||||
import { NgModule, Component } from '@angular/core';
|
||||
|
||||
@Component({ template: '' })
|
||||
export class AppComponent {}
|
||||
|
||||
@NgModule({ declarations: [ AppComponent ] })
|
||||
export class AppModule { }
|
||||
`
|
||||
}
|
||||
};
|
||||
const host = new MockCompilerHost(['/app/app.ts'], FILES, angularFiles);
|
||||
const aotHost = new MockAotCompilerHost(host);
|
||||
const genFilePreamble = '/* Hello world! */';
|
||||
compile(host, aotHost, expectNoDiagnostics, expectNoDiagnostics, {genFilePreamble})
|
||||
.then((generatedFiles) => {
|
||||
const genFile = generatedFiles.find(
|
||||
gf => gf.srcFileUrl === '/app/app.ts' && gf.genFileUrl.endsWith('.ts'));
|
||||
expect(genFile.source).not.toContain('check(');
|
||||
});
|
||||
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
describe('compiler (bundled Angular)', () => {
|
||||
|
Reference in New Issue
Block a user