Skip to content

feat(napi): transformForBrowser - TypeScript with Angular's settings, async lowered for zone.js - #607

Open
Rush wants to merge 3 commits into
voidzero-dev:mainfrom
encharm:feat/transform-for-browser
Open

Rush wants to merge 3 commits into
voidzero-dev:mainfrom
encharm:feat/transform-for-browser

Conversation

@Rush

@Rush Rush commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

A bundler without per-feature lowering (Rolldown's transform.target lowers by ES version) can't build an Angular app that runs zone.js the way the Angular CLI does: zone.js can't see native await, so the CLI's esbuild build turns async functions into generators (supported: { 'async-await': false }) and leaves everything else native. Lowering by target to ES2016 also lowers object spread, optional chaining and class fields.

transformForBrowser(code, filename, options) (and transformForBrowserSync) does just that, with oxc_transformer:

  • async functions, async generators and for await become generators; helpers are imported from @oxc-project/runtime;
  • TypeScript is stripped with Angular's settings: legacy decorators (experimentalDecorators), and useDefineForClassFields: false semantics, so fields are assigned in the constructor after parameter properties and statics after the class (as tsc and esbuild emit them);
  • JavaScript keeps its class fields; only async is lowered;
  • lowerAsync: false keeps async native (server rendering is zoneless).

We use it in a Rolldown plugin's transform hook, after transformAngularFile, for every TypeScript file and every JavaScript file that contains async; with it a production build of our app matches the Angular CLI's output.

Tests: three in crates/oxc_angular_compiler/src/browser.rs and five in napi/angular-compiler/test/transform-for-browser.test.ts (async lowering, lowerAsync: false, field order after parameter properties, legacy decorators, syntax errors). index.js and index.d.ts are regenerated.

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.

1 participant