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

Method execute

packages/compiler/src/typecheck/ops/references.ts:61–90  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

59 override readonly optional = true;
60
61 override execute(): TcbExpr {
62 const id = new TcbExpr(this.tcb.allocateId());
63 let initializer: TcbExpr =
64 this.target instanceof Template || this.target instanceof Element
65 ? this.scope.resolve(this.target)
66 : this.scope.resolve(this.host, this.target);
67
68 // The reference is either to an element, an <ng-template> node, or to a directive on an
69 // element or template.
70 if (
71 (this.target instanceof Element && !this.tcb.env.config.checkTypeOfDomReferences) ||
72 !this.tcb.env.config.checkTypeOfNonDomReferences
73 ) {
74 // References to DOM nodes are pinned to 'any' when `checkTypeOfDomReferences` is `false`.
75 // References to `TemplateRef`s and directives are pinned to 'any' when
76 // `checkTypeOfNonDomReferences` is `false`.
77 initializer = new TcbExpr(`${initializer.print()} as any`);
78 } else if (this.target instanceof Template) {
79 // Direct references to an <ng-template> node simply require a value of type
80 // `TemplateRef<any>`. To get this, an expression of the form
81 // `(_t1 as any as TemplateRef<any>)` is constructed.
82 const templateRef = this.tcb.env.referenceExternalSymbol('@angular/core', 'TemplateRef');
83 initializer = new TcbExpr(`(${initializer.print()} as any as ${templateRef.print()}<any>)`);
84 }
85 initializer.addParseSpanInfo(this.node.sourceSpan);
86 id.addParseSpanInfo(this.node.keySpan);
87
88 this.scope.addStatement(new TcbExpr(`var ${id.print()} = ${initializer.print()}`));
89 return id;
90 }
91}
92
93/**

Callers

nothing calls this directly

Calls 6

printMethod · 0.95
addParseSpanInfoMethod · 0.95
allocateIdMethod · 0.80
addStatementMethod · 0.80
resolveMethod · 0.65

Tested by

no test coverage detected