Skip to content

fix(queries): class expression as a query predicate (@ViewChild(class Foo {})) is rejected or dropped #516

Description

@Brooooooklyn

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; }

OXC #504 tip

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions