Skip to content

Commit 8a6ecc4

Browse files
fix(component): pool content-query predicates before view-query predicates
Upstream ngtsc's `compileComponent` emits the `contentQueries:` field before `viewQuery:` in the component definition object literal, and pools predicates in that order. The resulting `_c<N>` constant-table indices end up content-first (`_c0`, `_c1` for content; `_c2`, `_c3` for view) — the form pinned by every compliance golden under `compiler-cli/test/compliance/test_cases/signal_queries/`. This compiler had the order reversed (view queries pooled first), so the same source produced `_c0`/`_c1` for view queries and `_c2`/`_c3` for content — runtime-equivalent but breaks emit-anchored tooling and diff-based comparisons against Angular's own goldens. Fix: swap the call order in `compile_component` so content queries are pooled and emitted before view queries. No behavioral change at runtime — the metadata field order is unchanged in the output object literal (Angular's runtime reads both fields by name); only the const-table indices shift back into upstream alignment. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 61e4371 commit 8a6ecc4

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

crates/oxc_angular_compiler/src/component/transform.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3420,28 +3420,34 @@ fn compile_component_full<'a>(
34203420
// See: packages/compiler/src/render3/view/compiler.ts lines 192-212
34213421
let attrs_ref = pool_selector_attrs(allocator, &mut job, metadata);
34223422

3423-
// BEFORE template compilation: Pool view query predicates.
3424-
// TypeScript Angular pools query predicates BEFORE template compilation and pure functions.
3425-
// This ensures correct constant ordering: attrs -> query predicates -> pure functions.
3426-
let view_query_fn = if !view_queries.is_empty() {
3423+
// BEFORE template compilation: Pool query predicates so they
3424+
// appear in the constant table as `attrs -> query predicates ->
3425+
// pure functions`.
3426+
//
3427+
// Order matters: upstream ngtsc pools **content queries first, then
3428+
// view queries** (compiler/src/render3/view/compiler.ts emits
3429+
// `contentQueries:` before `viewQuery:` in the metadata object, and
3430+
// pools predicates in the same order). Reversing this swaps the
3431+
// `_c<N>` indices visible in the emitted query calls — the runtime
3432+
// still works either way but the emit diverges from upstream and
3433+
// breaks goldens / source-anchored tooling.
3434+
let content_queries_fn = if !content_queries.is_empty() {
34273435
let fn_name = Some(metadata.class_name.as_str());
3428-
Some(create_view_queries_function(
3436+
Some(create_content_queries_function(
34293437
allocator,
3430-
view_queries.as_slice(),
3438+
content_queries.as_slice(),
34313439
fn_name,
34323440
Some(&mut job.pool),
34333441
))
34343442
} else {
34353443
None
34363444
};
34373445

3438-
// BEFORE template compilation: Pool content query predicates.
3439-
// Similar to view queries, content query predicates are pooled before template compilation.
3440-
let content_queries_fn = if !content_queries.is_empty() {
3446+
let view_query_fn = if !view_queries.is_empty() {
34413447
let fn_name = Some(metadata.class_name.as_str());
3442-
Some(create_content_queries_function(
3448+
Some(create_view_queries_function(
34433449
allocator,
3444-
content_queries.as_slice(),
3450+
view_queries.as_slice(),
34453451
fn_name,
34463452
Some(&mut job.pool),
34473453
))

0 commit comments

Comments
 (0)