refactor(compiler): recursive ast expression visitor not passing context (#31085)

Currently the `RecursiveAstVisitor` that is part of the template expression
parser does not _always_ properly pass through the context that can be
specified when visting a given expression. Only a handful of AST types
pass through the context while others are accidentally left out. This causes
unexpected and inconsistent behavior and basically makes the `context`
parameter not usable if the type of template expression is not known.

e.g. the template variable assignment migration currently depends on
the `RecursiveAstVisitor` but sometimes breaks if developers use
things like conditionals in their template variable assignments.

Fixes #31043

PR Close #31085
This commit is contained in:
Paul Gschwendtner
2019-06-17 11:41:16 +02:00
committed by Kara Erickson
parent 75ac724842
commit 70ad91ed8b
2 changed files with 44 additions and 20 deletions

View File

@ -211,6 +211,30 @@ describe('template variable assignment migration', () => {
expect(warnOutput.length).toBe(0);
});
it('should warn for template variable assignments in expression conditional', async() => {
writeFile('/index.ts', `
import {Component} from '@angular/core';
@Component({
templateUrl: './sub_dir/tmpl.html',
})
export class MyComp {
otherVar = false;
}
`);
writeFile('/sub_dir/tmpl.html', `
<ng-template let-tmplVar>
<p (click)="enabled ? tmplVar = true : otherVar = true"></p>
</ng-template>
`);
await runMigration();
expect(warnOutput.length).toBe(1);
expect(warnOutput[0]).toMatch(/^⮑ {3}sub_dir\/tmpl.html@3:31: Found assignment/);
});
it('should not warn for property writes with template variable name but different scope',
async() => {
writeFile('/index.ts', `