perf(compiler-cli): only generate template context declaration when used (#39321)
The variable declaration for a template context is only needed when it is referenced from somewhere, so the TCB operation to generate the declaration is marked as optional. PR Close #39321
This commit is contained in:
parent
3b0b7d2210
commit
5d731354d0
|
@ -194,9 +194,8 @@ class TcbTemplateContextOp extends TcbOp {
|
|||
super();
|
||||
}
|
||||
|
||||
get optional() {
|
||||
return false;
|
||||
}
|
||||
// The declaration of the context variable is only needed when the context is actually referenced.
|
||||
readonly optional = true;
|
||||
|
||||
execute(): ts.Identifier {
|
||||
// Allocate a template ctx variable and declare it with an 'any' type. The type of this variable
|
||||
|
|
|
@ -763,13 +763,13 @@ describe('type check blocks', () => {
|
|||
|
||||
it('generates a references var when enabled', () => {
|
||||
const block = tcb(TEMPLATE, DIRECTIVES);
|
||||
expect(block).toContain('var _t2 = (_t1 as any as core.TemplateRef<any>);');
|
||||
expect(block).toContain('var _t1 = (_t2 as any as core.TemplateRef<any>);');
|
||||
});
|
||||
|
||||
it('generates a reference var when disabled', () => {
|
||||
const DISABLED_CONFIG: TypeCheckingConfig = {...BASE_CONFIG, checkTemplateBodies: false};
|
||||
const block = tcb(TEMPLATE, DIRECTIVES, DISABLED_CONFIG);
|
||||
expect(block).toContain('var _t2 = (_t1 as any as core.TemplateRef<any>);');
|
||||
expect(block).toContain('var _t1 = (_t2 as any as core.TemplateRef<any>);');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -913,8 +913,8 @@ describe('type check blocks', () => {
|
|||
it('should trace references to an <ng-template> when enabled', () => {
|
||||
const block = tcb(TEMPLATE, DIRECTIVES);
|
||||
expect(block).toContain(
|
||||
'var _t4 = (_t3 as any as core.TemplateRef<any>); ' +
|
||||
'"" + (((_t4).value2));');
|
||||
'var _t3 = (_t4 as any as core.TemplateRef<any>); ' +
|
||||
'"" + (((_t3).value2));');
|
||||
});
|
||||
|
||||
it('should use any for reference types when disabled', () => {
|
||||
|
|
Loading…
Reference in New Issue