MCPcopy Create free account
hub / github.com/angular/angular / execute

Method execute

packages/compiler/src/typecheck/ops/for_block.ts:41–75  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

39 }
40
41 override execute(): null {
42 const loopScope = this.scope.createChildScope(
43 this.scope,
44 this.block,
45 this.tcb.env.config.checkControlFlowBodies ? this.block.children : [],
46 null,
47 );
48 const initializerId = loopScope.resolve(this.block.item);
49 const initializer = new TcbExpr(`const ${initializerId.print()}`);
50 initializer.addParseSpanInfo(this.block.item.keySpan);
51
52 // It's common to have a for loop over a nullable value (e.g. produced by the `async` pipe).
53 // Add a non-null expression to allow such values to be assigned.
54 const expr = tcbExpression(this.block.expression, this.tcb, this.scope).wrapForTypeChecker();
55 const expression = new TcbExpr(`${expr.print()}!`).addParseSpanInfo(
56 this.block.expression.sourceSpan,
57 );
58
59 let statements: TcbExpr[];
60
61 if (this.block.trackBy === null) {
62 statements = loopScope.render();
63 } else {
64 const trackTranslator = new TcbForLoopTrackTranslator(this.tcb, loopScope, this.block);
65 const trackExpression = trackTranslator.translate(this.block.trackBy);
66 statements = [...loopScope.render(), trackExpression];
67 }
68
69 this.scope.addStatement(
70 new TcbExpr(
71 `for (${initializer.print()} of ${expression.print()}) {\n${getStatementsBlock(statements)} }`,
72 ),
73 );
74 return null;
75 }
76}
77
78export class TcbForLoopTrackTranslator extends TcbExpressionTranslator {

Callers

nothing calls this directly

Calls 10

printMethod · 0.95
addParseSpanInfoMethod · 0.95
tcbExpressionFunction · 0.90
getStatementsBlockFunction · 0.90
createChildScopeMethod · 0.80
wrapForTypeCheckerMethod · 0.80
addStatementMethod · 0.80
resolveMethod · 0.65
renderMethod · 0.65
translateMethod · 0.65

Tested by

no test coverage detected