Repository navigation
fix(r3): report an empty event handler and a two-way binding that cannot be written to - #720
Conversation
…not be written to
There was a problem hiding this comment.
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.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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>
|
@codex review |
There was a problem hiding this comment.
💡 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>
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
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 reportsEmpty expressions are not allowed(_parseAction). Here the handler was an empty expression, emitted asreturn undefined.[(ngModel)]="a + b": ngc reportsUnsupported 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_expressionreportsEmpty expressions are not allowedwhen the handler is empty or parses to an empty expression, also after a parse error ((click)=")"), as_parseActiondoes. 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"reportsCannot have a pipe in an action expression, anda; b/a = breport the property-side error plusUnsupported expression in a two-way binding, like ngc.create_two_way_eventreportsUnsupported expression in a two-way bindingfor a target$eventcannot be written to, unless parsing the event side already reported an error (isValidupstream). The check is_isAllowedAssignmentEvent: a property or keyed read, also behind!or$any(...)(notthis.$any(...)), with no?.anywhere on it (hasRecursiveSafeReceiver).The parts of that check that changed over time follow
angularVersion:?.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 itselfa?.b$any(a)is allowed(a)is its own node and an error; before, the parser dropped the parenthesesThe 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 thetemplatestring, as Angular'sPartialComponentLinkerVersion1throws aFatalLinkerError. 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_bindingsandshould_report_unsupported_expressions_in_two_way_bindingsfollow 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_doescovers each cutoff in the table, checked against the published@angular/compilerbuilds (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).integration_test.rs:a?.b.caccepted with 20.1.3 and rejected with 20.1.4,a?.brejected 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 newcompile_template_to_js_and_errorshelper.increment_decrement_test.rs:++;and++,xnow also reportEmpty expressions are not allowed, as its comment says ngc 22.3 does.linker_test.rsandtest/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, napivitest, the ngc compare fixtures (100%) and conformance (1430/1456, snapshot unchanged) pass.Not in this PR
transform_directives) and host listeners (host: {'(click)': ''}) still drop their parse errors, so neither error is reported there.templatestring, metadata it cannot parse) without a message, where upstream throws.(click)=";"lacks ngc'sUnexpected 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.