Skip to content

Commit 2037664

Browse files
clydinangular-robot[bot]
authored andcommitted
fix(@angular-devkit/build-angular): transform async generator class methods for Zone.js support
When using the experimental esbuild-based browser application builder, async generator class methods will now be transformed to a downlevel form based on promise objects. This transformation is performed by babel and was previously (and still is) performed on async generator functions. This transformation is necessary to ensure Zone.js can hook async code via the Promise objects. Only async generator transformation is currently performed via babel as esbuild can handle all other native async syntax that requires transformation for Zone.js support.
1 parent 6fd3d36 commit 2037664

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

packages/angular_devkit/build_angular/src/builders/browser-esbuild/javascript-transformer-worker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async function transformWithBabel({
4242
}: JavaScriptTransformRequest): Promise<string> {
4343
const forceAsyncTransformation =
4444
options.forceAsyncTransformation ??
45-
(!/[\\/][_f]?esm2015[\\/]/.test(filename) && /async\s+function\s*\*/.test(data));
45+
(!/[\\/][_f]?esm2015[\\/]/.test(filename) && /async(?:\s+function)?\s*\*/.test(data));
4646
const shouldLink = !options.skipLinker && (await requiresLinking(filename, data));
4747
const useInputSourcemap =
4848
options.sourcemap &&

packages/angular_devkit/build_angular/src/builders/browser-esbuild/javascript-transformer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ export class JavaScriptTransformer {
7272
let forceAsyncTransformation;
7373
if (skipLinker && !this.#commonOptions.advancedOptimizations) {
7474
// If the linker is being skipped and no optimizations are needed, only async transformation is left.
75-
// This checks for async generator functions. All other async transformation is handled by esbuild.
76-
forceAsyncTransformation = data.includes('async') && /async\s+function\s*\*/.test(data);
75+
// This checks for async generator functions and class methods. All other async transformation is handled by esbuild.
76+
forceAsyncTransformation = data.includes('async') && /async(?:\s+function)?\s*\*/.test(data);
7777

7878
if (!forceAsyncTransformation) {
7979
return Buffer.from(data, 'utf-8');

0 commit comments

Comments
 (0)