Skip to content

Commit feb0675

Browse files
committed
perf(@angular-devkit/build-angular): use esbuild-based builder to directly downlevel for await...of
esbuild 0.15.6 now supports transforming `for await..of` syntax and will now be used instead of babel when the syntax is found within code that will be bundled. Zone.js requires that all async/await related code be downleveled to properly hook promise callbacks. esbuild does not yet support transforming async generators and so babel is still used when async generator syntax is detected in an input file. esbuild 0.15.6 also adjusted the `supported` option to imply that all dependent features of a disabled feature are disabled as well. For the CLI, this allows only needing to specify that `async-await` is disabled in the esbuild options.
1 parent e402c23 commit feb0675

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

packages/angular_devkit/build_angular/src/builders/browser-esbuild/compiler-plugin.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ export function createCompilerPlugin(
342342
}
343343

344344
const data = typescriptResult.content ?? '';
345-
const forceAsyncTransformation = /for\s+await\s*\(|async\s+function\s*\*/.test(data);
345+
const forceAsyncTransformation = /async\s+function\s*\*/.test(data);
346346
const useInputSourcemap =
347347
pluginOptions.sourcemap &&
348348
(!!pluginOptions.thirdPartySourcemaps || !/[\\/]node_modules[\\/]/.test(args.path));
@@ -388,8 +388,7 @@ export function createCompilerPlugin(
388388
build.onLoad({ filter: /\.[cm]?js$/ }, async (args) => {
389389
const data = await fs.readFile(args.path, 'utf-8');
390390
const forceAsyncTransformation =
391-
!/[\\/][_f]?esm2015[\\/]/.test(args.path) &&
392-
/for\s+await\s*\(|async\s+function\s*\*/.test(data);
391+
!/[\\/][_f]?esm2015[\\/]/.test(args.path) && /async\s+function\s*\*/.test(data);
393392
const shouldLink = await requiresLinking(args.path, data);
394393
const useInputSourcemap =
395394
pluginOptions.sourcemap &&

packages/angular_devkit/build_angular/src/builders/browser-esbuild/index.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -259,15 +259,11 @@ async function bundleCode(
259259
target: 'es2020',
260260
supported: {
261261
// Native async/await is not supported with Zone.js. Disabling support here will cause
262-
// esbuild to downlevel async/await to a Zone.js supported form.
262+
// esbuild to downlevel async/await and for await...of to a Zone.js supported form. However, esbuild
263+
// does not currently support downleveling async generators. Instead babel is used within the JS/TS
264+
// loader to perform the downlevel transformation.
265+
// NOTE: If esbuild adds support in the future, the babel support for async generators can be disabled.
263266
'async-await': false,
264-
// Zone.js also does not support async generators or async iterators. However, esbuild does
265-
// not currently support downleveling either of them. Instead babel is used within the JS/TS
266-
// loader to perform the downlevel transformation. They are both disabled here to allow
267-
// esbuild to handle them in the future if support is ever added.
268-
// NOTE: If esbuild adds support in the future, the babel support for these can be disabled.
269-
'async-generator': false,
270-
'for-await': false,
271267
},
272268
mainFields: ['es2020', 'browser', 'module', 'main'],
273269
conditions: ['es2020', 'es2015', 'module'],

0 commit comments

Comments
 (0)