refactor(core): static-query schematic should check templates (#29713)
Queries can technically be also accessed within component templates e.g. ```html <my-comp [binding]="myQuery"></my-comp> ``` In that case the query with the property "myQuery" is accessed statically and needs to be marked with `static: true`. There are other edge cases that need to be handled as the template property read doesn't necessarily resolve to the actual query property. For example: ```html <foo #myQuery></foo> <my-comp [binding]="myQuery"></my-comp> ``` In this scenario the binding doesn't refer to the actual query because the template reference variable takes precedence. The query doesn't need to be marked with "static: true" this time. This commit ensures that the `static-query` migration schematic now handles this cases properly. Also template property reads that access queries from within a `<ng-template>` are ignored as these can't access the query before the view has been initialized. Resolves FW-1216 PR Close #29713
This commit is contained in:

committed by
Igor Minar

parent
b507d076be
commit
5b32f55a3a
@ -9,9 +9,10 @@
|
||||
import {RuleFailure, Rules} from 'tslint';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {createHtmlSourceFile} from '../../../utils/tslint/tslint_html_source_file';
|
||||
import {analyzeResolvedTemplate} from '../analyze_template';
|
||||
import {NgComponentTemplateVisitor} from '../../../utils/ng_component_template';
|
||||
import {createHtmlSourceFile} from '../../../utils/tslint/tslint_html_source_file';
|
||||
import {visitAllNodes} from '../../../utils/typescript/visit_nodes';
|
||||
import {analyzeResolvedTemplate} from '../analyze_template';
|
||||
|
||||
const FAILURE_MESSAGE = 'Found assignment to template variable. This does not work with Ivy and ' +
|
||||
'needs to be updated.';
|
||||
@ -26,7 +27,7 @@ export class Rule extends Rules.TypedRule {
|
||||
const failures: RuleFailure[] = [];
|
||||
|
||||
// Analyze the current source files by detecting all referenced HTML templates.
|
||||
templateVisitor.visitNode(sourceFile);
|
||||
visitAllNodes(sourceFile, [templateVisitor]);
|
||||
|
||||
const {resolvedTemplates} = templateVisitor;
|
||||
|
||||
|
Reference in New Issue
Block a user