fix(ivy): type checking - handle $implicit ng-template variables (#30675)
When an `ng-template` element has a variable declaration without a value, it is assigned the value of the `$implicit` property in the embedded view's context. The template compiler inserts a property access to `$implicit` for template variables without a value, however the type-check code generation logic did not. This resulted in incorrect type-checking code being generated. Fixes FW-1326 PR Close #30675
This commit is contained in:
parent
4da5e9a156
commit
456f2e70af
|
@ -122,7 +122,7 @@ class TcbVariableOp extends TcbOp {
|
|||
const id = this.tcb.allocateId();
|
||||
const initializer = ts.createPropertyAccess(
|
||||
/* expression */ ctx,
|
||||
/* name */ this.variable.value);
|
||||
/* name */ this.variable.value || '$implicit');
|
||||
|
||||
// Declare the variable, and return its identifier.
|
||||
this.scope.addStatement(tsCreateVariable(id, initializer));
|
||||
|
|
|
@ -45,6 +45,16 @@ describe('type check blocks', () => {
|
|||
expect(tcb(TEMPLATE)).toContain('_t1.htmlFor = "test";');
|
||||
});
|
||||
|
||||
it('should handle implicit vars on ng-template', () => {
|
||||
const TEMPLATE = `<ng-template let-a></ng-template>`;
|
||||
expect(tcb(TEMPLATE)).toContain('var _t2 = _t1.$implicit;');
|
||||
});
|
||||
|
||||
it('should handle implicit vars when using microsyntax', () => {
|
||||
const TEMPLATE = `<div *ngFor="let user of users"></div>`;
|
||||
expect(tcb(TEMPLATE)).toContain('var _t2 = _t1.$implicit;');
|
||||
});
|
||||
|
||||
it('should generate a forward element reference correctly', () => {
|
||||
const TEMPLATE = `
|
||||
{{ i.value }}
|
||||
|
|
Loading…
Reference in New Issue