Skip to content

fix(r3): report an empty event handler and a two-way binding that cannot be written to - #720

Merged
Brooooooklyn merged 3 commits into
voidzero-dev:mainfrom
GabeSilvaDev:fix/event-binding-errors
Nov 18, 2026
Merged

Brooooooklyn merged 3 commits into
voidzero-dev:mainfrom
GabeSilvaDev:fix/event-binding-errors

Conversation

@GabeSilvaDev

@GabeSilvaDev GabeSilvaDev commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Two errors ngc's binding parser reports for event bindings were missing here, so these templates compiled without a diagnostic:

  • (click)="", (click)=" ", (click)="// note", on-click="", (@trigger.done)="" and [(x)]="": ngc reports Empty expressions are not allowed (_parseAction). Here the handler was an empty expression, emitted as return undefined.
  • [(ngModel)]="a + b": ngc reports Unsupported expression in a two-way binding (_parseRegularEvent, _isAllowedAssignmentEvent). Here it compiled to ɵɵtwoWayBindingSet((ctx.a + ctx.b),$event) with no write-back, so the binding silently never updated anything.

Behaviour change

A template with one of these bindings that compiled with oxc before now reports the error, and that component is not compiled. This matches ngc for the target Angular version. A library component with a template error now fails the build at link time, as with Angular's linker.

Changes

  • parse_event_expression reports Empty expressions are not allowed when the handler is empty or parses to an empty expression, also after a parse error ((click)=")"), as _parseAction does. Event bindings, on- bindings, legacy animation events and every two-way binding go through it.

  • The event side of a two-way binding is parsed as an action, as in _parseRegularEvent. So [(x)]="a | p" reports Cannot have a pipe in an action expression, and a; b / a = b report the property-side error plus Unsupported expression in a two-way binding, like ngc.

  • create_two_way_event reports Unsupported expression in a two-way binding for a target $event cannot be written to, unless parsing the event side already reported an error (isValid upstream). The check is _isAllowedAssignmentEvent: a property or keyed read, also behind ! or $any(...) (not this.$any(...)), with no ?. anywhere on it (hasRecursiveSafeReceiver).

  • The parts of that check that changed over time follow angularVersion:

    Rule From
    a ?. anywhere on the target is an error (fix(compiler): exclude more safe reads expression from 2way-binding angular/angular#62852); before, only a target that is itself a?.b 20.1.4 and 20.2.0-next.3
    $any(a) is allowed 19.1.0-rc.0
    (a) is its own node and an error; before, the parser dropped the parentheses 20.0.0-next.2
  • The linker reports a partial component whose template has errors, where it used to leave it unlinked without a word (so the build passed and an AOT app failed at runtime). LinkResult.errors (Rust and napi) has one error per such component: Errors found in the template: and each error with its place in the template, labelled at the template string, as Angular's PartialComponentLinkerVersion1 throws a FatalLinkerError. The component is left as it is and the rest of the file still links. The Vite linker plugin fails the build on these errors, in the transform hook and in the dependency optimizer. This matters here because a 20.1.3 library with [(x)]="a?.b.c" linked for 20.1.4+ now has a template error.

Checks

  • r3_template_transform_test.rs: should_report_an_error_on_empty_expression, should_report_pipes_in_two_way_bindings and should_report_unsupported_expressions_in_two_way_bindings follow the upstream spec of the same names, including its full list of rejected targets and the accepted (foo?.bar ?? bar).baz, plus more cases checked against ngc 22.2.2. should_check_a_two_way_target_as_its_angular_version_does covers each cutoff in the table, checked against the published @angular/compiler builds (19.0.7, 19.1.0-next.4, 19.1.0-rc.0, 20.0.0-next.1/2, 20.1.3/4, 20.2.0-next.2/3).
  • A differential run of ~850 templates against ngc 22.2.2 and the builds above: valid two-way bindings compile to the same JS as before, and the error lists match ngc in more cases at every version.
  • integration_test.rs: a?.b.c accepted with 20.1.3 and rejected with 20.1.4, a?.b rejected with both. test_two_way_binding_writeback_target_is_never_optional_v22 (from fix(chaining): preserve optional chaining in chained bindings #382) compiles [(ngModel)]="a?.b", which is now an error; it keeps its output assertions and also asserts the error, through a new compile_template_to_js_and_errors helper.
  • increment_decrement_test.rs: ++; and ++,x now also report Empty expressions are not allowed, as its comment says ngc 22.3 does.
  • linker_test.rs and test/linker.test.ts: the error, its text and place, the declaration left as it is, the other declarations still linked, no made-up place for an expression error, and both plugin hooks failing. Linking every partial package file available locally (67 files, 124 components: Angular 22.x cdk, material, router and analogjs) at four Angular versions gives no errors; ngc's Babel linker links them all too.
  • cargo test --workspace --all-features, cargo fmt --all -- --check, pnpm check, napi vitest, the ngc compare fixtures (100%) and conformance (1430/1456, snapshot unchanged) pass.

Not in this PR

  • Event bindings on a selectorless directive (transform_directives) and host listeners (host: {'(click)': ''}) still drop their parse errors, so neither error is reported there.
  • The linker still skips other declarations it cannot read (no template string, metadata it cannot parse) without a message, where upstream throws.
  • (click)=";" lacks ngc's Unexpected token ;, and the Empty error's span starts before leading whitespace: both come from the expression parser and the handler span, not from this change.

Copilot AI balanced review requested due to automatic review settings November 15, 2026 22:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T10:13:40.165460Z 0cd3afa Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c5562c2a8c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

- `rejects_safe_reads_in_two_way_bindings`: the `?.` check is in 20.1.4
  and 20.2.0-next.3 (angular/angular#62852), not from 20.2.0.
- Before 19.1.0-rc.0 `$any(a)` is not a two-way target; before
  20.0.0-next.2 the parser dropped `(a)`, so `(a)` is `a`.
- Parse the event side of a two-way binding as an action, as
  `_parseRegularEvent` does: `[(x)]="a | p"` reports the pipe error, and
  `a; b` / `a = b` report the same errors as ngc.
- Report `Empty expressions are not allowed` also after a parse error, as
  `_parseAction` does (`(click)=")"`, `++;`).
- Give `event_key_span` its doc comment back; use the upstream spec names
  and cases for the tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2486bd0db9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

The linker dropped template errors (`.ok()?`): the declaration stayed
unlinked and the build passed, so an AOT app failed at runtime. With the
new two-way check, a 20.1.3 library with `[(x)]="a?.b.c"` linked for
20.1.4+ hits this.

- `LinkResult.errors` (Rust and napi): one error per such component,
  "Errors found in the template:" and each error with its place in the
  template, labelled at the `template` string, as Angular's
  `PartialComponentLinkerVersion1` throws a `FatalLinkerError`. The
  component is left as it is; the rest of the file still links.
- The Vite linker plugin fails the build on them, in the transform hook
  and in the dependency optimizer (as the Angular CLI's prebundle does).
- `describeDiagnostic` moves to `vite-plugin/utils/diagnostic.ts` for both
  plugins.

Checked on every partial package file available locally (67 files, 124
components, Angular 22.x cdk/material/router and analogjs): no errors,
and ngc's Babel linker links them all too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 0cd3afa7d5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Brooooooklyn
Brooooooklyn merged commit 7ab2dad into voidzero-dev:main Nov 18, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants