Skip to content

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

Open
GabeSilvaDev wants to merge 1 commit into
voidzero-dev:mainfrom
GabeSilvaDev:fix/event-binding-errors
Open

GabeSilvaDev wants to merge 1 commit into
voidzero-dev:mainfrom
GabeSilvaDev:fix/event-binding-errors

Conversation

@GabeSilvaDev

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 (_parseEvent, _isAllowedAssignmentEvent). Here it compiled to ɵɵtwoWayBindingSet((ctx.a + ctx.b),$event) with no write-back, so the binding silently never updated anything.

Changes

  • parse_event_expression reports Empty expressions are not allowed for an empty handler, or one that parses to an empty expression with no other error. Event bindings, on- bindings, legacy animation events and animate. two-way events go through it.
  • create_two_way_event reports the same for an empty two-way binding, and Unsupported expression in a two-way binding for a target $event cannot be written to, unless parsing already reported an error (isValid upstream). The check is _isAllowedAssignmentEvent: a property or keyed read, also behind ! or $any(...) (not this.$any(...)), and with no ?. anywhere on it (hasRecursiveSafeReceiver).
  • The ?. part is from Angular v20.2.0-next.3 (fix(compiler): exclude more safe reads expression from 2way-binding angular/angular#62852). Before that only a target that is itself a safe read (a?.b) was rejected, so a?.b.c was accepted. AngularVersion::rejects_safe_reads_in_two_way_bindings keeps that for older versions.

Checks

  • r3_template_transform_test.rs, all cases checked against ngc 22.2.2 parseTemplate: the empty handlers above; a + b, a?.b, a?.b.c, a?.[0], (a?.b).c, a(), a.b(), $any(a, b), $any(a + b), this.$any(a), !a and (a) rejected with both [(x)] and bindon-x, and [(animate.x)]="a + b"; a, a.b, a[0], a!, a.b!, $any(a), $any(a.b) and (a).b accepted; no second error on a two-way binding that failed to parse.
  • integration_test.rs: a?.b.c accepted with v20.1 and rejected with v20.2, 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 that returns the transform errors instead of panicking on them.
  • Removing the empty check, the two-way check, the version gate or the ?. check each fails a test.
  • cargo test --all-features, cargo fmt --all -- --check and conformance (1430/1456, snapshot unchanged) pass.

Not in this PR

Event bindings on a selectorless directive (transform_directives) still drop their parse errors, so neither of these errors is reported there.

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-15T22:37:26.820739Z c5562c2 PR opened
ℹ️ 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".

/// so `[(x)]="a?.b.c"` is an error. Before, only a target that is itself a safe read
/// (`a?.b`) was.
pub fn rejects_safe_reads_in_two_way_bindings(&self) -> bool {
self.major > 20 || (self.major == 20 && self.minor >= 2)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Honor the v20.2.0-next.3 cutoff for recursive safe reads

For AngularVersion values 20.2.0-next.0 through 20.2.0-next.2, this predicate is already true even though the recursive safe-receiver check is documented as landing in 20.2.0-next.3. Compiling [(x)]="a?.b.c" against those prereleases therefore reports an unsupported binding that Angular still accepts; gate these prereleases at next.3 and cover the boundary.

Useful? React with 👍 / 👎.

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.

2 participants