refactor(core): static-query migrations fails if options cannot be transformed (#30178)

Currently the `static-query` migrations fails at the final step of
updating a query when the query already specifies options which
cannot be transformed easily. e.g. the options are computed through
a function call: `@ViewChild(..., getQueryOpts());` or `@ViewChild(..., myOptionsVar)`.

In these cases we technically could add additionally logic to update
the query options, but given that this is an edge-case and it's
potentially over-engineering the migration schematic, we just
always add a TODO for the timing and print out the determined
query timing in the console. The developer in that case just needs
to manually update the logic for the query options to contain the
printed query timing.

Potentially related to: https://github.com/angular/angular-cli/issues/14298

PR Close #30178
This commit is contained in:
Paul Gschwendtner
2019-04-28 16:40:59 +02:00
committed by Andrew Kushnir
parent 1353bf0277
commit 164d160b22
4 changed files with 91 additions and 31 deletions

View File

@ -64,13 +64,13 @@ export class Rule extends Rules.TypedRule {
queries.forEach(q => {
const queryExpr = q.decorator.node.expression;
const {timing, message} = usageStrategy.detectTiming(q);
const transformedNode = getTransformedQueryCallExpr(q, timing, !!message);
const result = getTransformedQueryCallExpr(q, timing, !!message);
if (!transformedNode) {
if (!result) {
return;
}
const newText = printer.printNode(ts.EmitHint.Unspecified, transformedNode, sourceFile);
const newText = printer.printNode(ts.EmitHint.Unspecified, result.node, sourceFile);
// Replace the existing query decorator call expression with the
// updated call expression node.