Skip to content

Commit 9e54569

Browse files
crisbetoalxhub
authored andcommitted
fix(compiler-cli): generate less type checking code in for loops (#53515)
The ops for the implicit variables in `@for` loops (e.g. `$index`) are marked as being mandatory which means that they're generated even if they aren't used. These changes make them optional so they're only added when necessary. PR Close #53515
1 parent 00a1b3b commit 9e54569

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

packages/compiler-cli/src/ngtsc/typecheck/src/type_check_block.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,9 +1291,7 @@ class TcbBlockImplicitVariableOp extends TcbOp {
12911291
super();
12921292
}
12931293

1294-
override get optional() {
1295-
return false;
1296-
}
1294+
override readonly optional = true;
12971295

12981296
override execute(): ts.Identifier {
12991297
const id = this.tcb.allocateId();

packages/compiler-cli/src/ngtsc/typecheck/test/type_check_block_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,8 +1612,8 @@ describe('type check blocks', () => {
16121612
const result = tcb(TEMPLATE);
16131613
expect(result).toContain('for (const _t1 of ((this).items)!) { var _t2: number = null!;');
16141614
expect(result).toContain('"" + (_t1) + (_t2)');
1615-
expect(result).toContain('for (const _t8 of ((_t1).items)!) { var _t9: number = null!;');
1616-
expect(result).toContain('"" + (_t1) + (_t2) + (_t8) + (_t9)');
1615+
expect(result).toContain('for (const _t3 of ((_t1).items)!) { var _t4: number = null!;');
1616+
expect(result).toContain('"" + (_t1) + (_t2) + (_t3) + (_t4)');
16171617
});
16181618

16191619
it('should generate the tracking expression of a for loop', () => {

0 commit comments

Comments
 (0)