Repository navigation
Angular: Support @boundary / @error error boundaries - #20015
Conversation
Recognize Angular 22.2 `@boundary` blocks and print them with a following `@error` chain, matching existing `@defer` / `@if` / `@for` control-flow formatting. Co-authored-by: Bennett Payoyo <[email protected]>
Co-authored-by: Bennett Payoyo <[email protected]>
✅ Deploy Preview for prettier ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
commit: |
angular-html-parser 10.12.0 tokenizes @boundary, so the temporary SUPPORTED_ANGULAR_BLOCKS mutation is no longer needed. Co-authored-by: Bennett Payoyo <[email protected]>
|
Thanks @fisker — updated to |
| } | ||
| } @error { | ||
| <span>Load error</span> | ||
| } |
There was a problem hiding this comment.
How were these tests generated?
Maybe we can adopt examples from https://github.com/angular/angular/pull/70560/changes?
|
Looks like the params not correctly formatted? Prettier PR #20015 --parser angularInput: @boundary {
<app-risky-component />
} @error (let err; retry
= $reset; when
isNetworkError(err)) {
<app-network-error [error]="err" />
<button (click)="retry()">Retry</button>
} @error {
<app-generic-error />
}Output: @boundary {
<app-risky-component />
} @error (let err; retry
= $reset; when
isNetworkError(err)) {
<app-network-error [error]="err" />
<button (click)="retry()">Retry</button>
} @error {
<app-generic-error />
} |
Print let / named / when parameters from the existing structured AST instead of leaving raw whitespace, and replace fixtures with Angular docs examples plus the messy playground case. Co-authored-by: Bennett Payoyo <[email protected]>
Parse named aliases before `when`, split comma-separated bindings, and refresh snapshots for the official docs fixtures plus messy playground input. Co-authored-by: Bennett Payoyo <[email protected]>
|
Thanks — both notes should be addressed on this branch. Fixtures. Params. 10.12.0 already gives structured Your playground input now prints as: @boundary {
<app-risky-component />
} @error (let err; retry = $reset; when isNetworkError(err)) {
<app-network-error [error]="err" />
<button (click)="retry()">Retry</button>
} @error {
<app-generic-error />
} |
| @@ -0,0 +1,61 @@ | |||
| import { join } from "../../document/index.js"; | |||
There was a problem hiding this comment.
I don't want to parse the parameters here in this repo.
I saw a parseLetParameters from angular/angular#70463, but our angular-estree-parser currently only uses Parser from @angular/compiler.
@JeanMeche Do you know if there is existing functionality to parse the error parameters?
There was a problem hiding this comment.
Would something like angular/angular#70706 satisfy your needs ?
There was a problem hiding this comment.
Thanks for the PR, but no.
Currently, we print the parameters via our __ng_directive, and __ng_binding printer.
They are based on angular-estree-parser.
The __ng_directive printer calls import('@angular/compiler').Parser#parseTemplateBindings(), and __ng_binding calls import('@angular/compiler').Parser#parseBinding() then transform the AST to an ESTree-compatible AST.
Actually, we are not really sure if we are doing it right.
The maintainers are not familiar with Angular.
When we first added support for letDeclaration, I used parseTemplateBindings only because they have similar syntax and it already exists.
We can make changes to angular-estree-parser to support these expressions with "r3render", but we still need to produce an ESTree-compatible AST.
|
Thanks @fisker — clear on the direction. We'll stop parsing Happy to help on the |
Stop classifying and formatting `@error` parameters in Prettier. Pretty-printing those params should go through angular-estree-parser and the existing `__ng_directive` / `__ng_binding` printers once that parser understands boundary syntax. Keep `@boundary` / `@error` block recognition and pairing. Snapshots now record the honest un-reflowed parameter text. Co-authored-by: Bennett Payoyo <[email protected]>
|
I'm going to leave the error parameters and merge. |
@boundary / @error error boundaries
Co-authored-by: Cursor Agent <[email protected]> Co-authored-by: fisker Cheung <[email protected]> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> # Conflicts: # scripts/build/transform/index.js
Description
Fixes #20014
Adds parsing and printing for Angular 22.2 error boundary blocks (
@boundary/@error), following the same printer pairing rules as existing control-flow blocks (@if/@else,@for/@empty,@defer/@error).Also formats nested boundaries, multiple
@errorblocks,let/$resetaliases, empty blocks, and@defer+@boundarytogether.Uses
[email protected], which includes@boundarynatively (per @fisker).Checklist
docs/directory).changelog_unreleased/*/XXXX.mdfile followingchangelog_unreleased/TEMPLATE.md.Drafted with Cursor (Grok); reviewed before opening.