fix(ivy): support dynamic query tokens in AOT mode (#35307)

For view and content queries, the Ivy compiler attempts to statically
evaluate the predicate token so that string predicates containing
comma-separated reference names can be split into an array of strings
during compilation. When the predicate is a dynamic value that cannot be
statically interpreted at compile time, the compiler would previously
produce an error. This behavior breaks a use-case where an `InjectionToken`
is being used as query predicate, as the usage of the `new` keyword
prevents such predicates from being statically evaluated.

This commit changes the behavior to no longer produce an error for
dynamic values. Instead, the expression is emitted as is into the
generated code, postponing the evaluation to happen at runtime.

Fixes #34267
Resolves FW-1828

PR Close #35307
This commit is contained in:
JoostK
2020-02-10 20:53:13 +01:00
committed by atscott
parent 03d88c7965
commit 3e3a1ef30d
3 changed files with 34 additions and 5 deletions

View File

@ -341,7 +341,8 @@ export function extractQueryMetadata(
// Extract the predicate
let predicate: Expression|string[]|null = null;
if (arg instanceof Reference) {
if (arg instanceof Reference || arg instanceof DynamicValue) {
// References and predicates that could not be evaluated statically are emitted as is.
predicate = new WrappedNodeExpr(node);
} else if (typeof arg === 'string') {
predicate = [arg];