MCPcopy Index your code
hub / github.com/angular/angular / execute

Method execute

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected