`$safeNavigationMigration(...)` in an event listener reads template locals from the wrong context
维护者通常 1 天内回复
已经有一个关联 PR 被合并了。
- #587 来自 @edbzn —— 已合并
评估
调研方向
Start by reading remove_safe_navigation_migration and the name resolution phase that handles listener handlerOps; the issue identifies both as possible points where the local scope is lost. Compare listener compilation with the working property binding in a focused reproduction using the supplied template. Done when the listener reads the restored option_r2 value and a regression test covers template locals inside migrated listener expressions.
由索引模型根据 Issue 内容生成。
描述
Summary
When $safeNavigationMigration(expr) is used inside an event binding, OXC resolves template-local
variables in expr (@for items, @if … as x aliases, let- variables) against the listener's
ctx (ctx.option) instead of the local restored from the view (option_r2). The argument is
always undefined, so the expression evaluates to null.
Property bindings that use the same builtin compile correctly. The bug is specific to listener
handler ops.
Reproduction (@oxc-angular/[email protected], @oxc-angular/vite/api)
import { transformAngularFile } from '@oxc-angular/vite/api';
const src = `import { Component } from '@angular/core';
@Component({ selector: 'x-probe', template: \`
@for (option of options; track $index) {
<button (click)="pick(option?.value); pick2($safeNavigationMigration(option?.value))"
[title]="$safeNavigationMigration(option?.label)"></button>
}\` })
export class Probe { options: any[] = []; pick(v: any) {} pick2(v: any) {} }`;
const r = await transformAngularFile(src, '/tmp/probe.component.ts', {}, { templates: {}, styles: {} });
console.log(r.code);
Actual
i0.ɵɵlistener("click", function Probe_For_1_Template_button_click_0_listener() {
const option_r2 = i0.ɵɵrestoreView(_r1).$implicit;
const ctx_r2 = i0.ɵɵnextContext();
ctx_r2.pick(((option_r2 == null) ? null : option_r2.value)); // correct
return i0.ɵɵresetView(ctx_r2.pick2(((ctx.option == null) ? null : ctx.option.value))); // wrong: ctx.option
});
// update block, correct:
i0.ɵɵproperty("title", ((option_r3 == null) ? null : option_r3.label));
Expected (what ngc emits)
The listener should read option_r2 for both calls:
ctx_r2.pick2(((option_r2 == null) ? null : option_r2.value)).
Impact
Angular's ng update migration for the v22 safe-navigation change inserts $safeNavigationMigration
automatically. Any migrated listener such as (click)="select($safeNavigationMigration(item?.id))"
inside @for/@if as/*ngFor now passes null at runtime. There's no compile error. In our
monorepo this broke a shared select component (every dropdown emitted null) and profile
activation toggles, and failed 21 component tests across 4 projects that pass under
@analogjs/vite-plugin-angular / ngc. Rewriting the three affected bindings as x?.y ?? null
made all 21 pass under OXC.
Possible cause
remove_safe_navigation_migration iterates view.create and view.update. Angular's
unit.ops() also yields each listener's handlerOps. If the marker in handler ops isn't converted
before resolve_names, or is converted with a different scope, the argument's LexicalReads skip
the restored-view locals. Unverified, this is a guess from reading the phase source.
Environment
@oxc-angular/vite0.0.41 (linux-x64-gnu binding)- Angular 22.2.0, Vite 7.3.6
- 主要语言
- Rust
- 星标
- 240
- 派生
- 24
- 平均合并
- 1 天 15 小时
- 30 天内合并 PR
- 75
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
voidzero-dev/oxc-angular-compiler 的其他 Issue
-
bug
难度 4/5 3-5 天 新手友好度 68/100
voidzero-dev/oxc-angular-compiler#505 ·
维护者通常 1 天内回复
-
Support useDefineForClassFields: false (Class Field Lowering)可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 5/5 一周以上 新手友好度 35/100
voidzero-dev/oxc-angular-compiler#73 · 11 条评论 ·
维护者通常 1 天内回复
-
Angular 21.2.0 + @oxc-angular/vite 0.0.7 SSR runtime parity regressions (RouterLinkActive, Forms DI, Apollo DI) require app-level shims可能重新可做 @Brooooooklyn 于 231 天前认领,目前没有进行中的 PR。 未关闭
voidzero-dev/oxc-angular-compiler#61 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Angular 21.2.0 + @oxc-angular/vite 0.0.7 SSR: AngularNodeAppEngine is unusable (missing app-engine manifest)可能重新可做 @Brooooooklyn 于 231 天前认领,目前没有进行中的 PR。 未关闭
voidzero-dev/oxc-angular-compiler#60 · 4 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 voidzero-dev/oxc-angular-compiler 的全部 Issue
相似的 Issue
-
area: config effort: S good first issue P3 type: bug
难度 2/5 1-3 小时 新手友好度 70/100
ferenyl/azuredevopstui#63 ·
-
needs-triage O-Arm T-libs
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
bug CLI config mcp
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
documentation good first issue
难度 1/5 1-3 小时 新手友好度 88/100
yunaremaia/sandbox-ffi-layers#56 ·
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
git-ai-project/git-ai#2434 ·
维护者通常 1 天内回复