ngtsc accepts a class expression as a query predicate and emits it as written. OXC rejects it on the stack and silently drops the query on main.
Repro
import {Component, ViewChild} from '@angular/core';
@Component({selector: 'c', template: ''})
export class C { @ViewChild(class Foo {}) q: any; }
The queries: form fails the same way:
@Component({selector: 'c', template: '', queries: {q: new ViewChild(class Foo {})}})
export class C { q: any; }
Error: @ViewChild predicate cannot be interpreted
No viewQuery is emitted.
OXC main
No diagnostic, and no viewQuery in ɵɵdefineComponent. The query is silently lost.
ngtsc 22.1.7
Compiles; the predicate is emitted in place:
viewQuery: function C_Query(rf, ctx) { if (rf & 1) {
i0.ɵɵviewQuery(class Foo {
}, 5);
} ... }
Where
At the #504 tip, crates/oxc_angular_compiler/src/directive/property_decorators.rs (~L1917, added by #495) evaluates the predicate to Value::Dynamic and then calls convert_oxc_expression. That returns None for a class expression (output/oxc_converter.rs has no ClassExpression case), so it reports "predicate cannot be interpreted". On main the same None makes the query disappear silently. In ngtsc (annotations/directive/src/shared.ts, extractQueryMetadata), a predicate that evaluates to a Reference or a DynamicValue is emitted as written (new WrappedNodeExpr(node)). A class expression is a DynamicValue. "predicate cannot be interpreted" is only for values that are neither strings nor string arrays.
Direction
Let convert_oxc_expression emit a class expression as raw source with types stripped. The predicate path then works without changes.
On main?
Yes, but differently: main drops the query silently, the stack reports an error. Low priority; class-expression predicates are rare.
ngtsc accepts a class expression as a query predicate and emits it as written. OXC rejects it on the stack and silently drops the query on main.
Repro
The
queries:form fails the same way:OXC #504 tip
No
viewQueryis emitted.OXC main
No diagnostic, and no
viewQueryinɵɵdefineComponent. The query is silently lost.ngtsc 22.1.7
Compiles; the predicate is emitted in place:
Where
At the #504 tip,
crates/oxc_angular_compiler/src/directive/property_decorators.rs(~L1917, added by #495) evaluates the predicate toValue::Dynamicand then callsconvert_oxc_expression. That returnsNonefor a class expression (output/oxc_converter.rshas noClassExpressioncase), so it reports "predicate cannot be interpreted". On main the sameNonemakes the query disappear silently. In ngtsc (annotations/directive/src/shared.ts,extractQueryMetadata), a predicate that evaluates to aReferenceor aDynamicValueis emitted as written (new WrappedNodeExpr(node)). A class expression is aDynamicValue. "predicate cannot be interpreted" is only for values that are neither strings nor string arrays.Direction
Let
convert_oxc_expressionemit a class expression as raw source with types stripped. The predicate path then works without changes.On main?
Yes, but differently: main drops the query silently, the stack reports an error. Low priority; class-expression predicates are rare.