Skip to content

Commit 3aa1c4e

Browse files
clydinangular-robot[bot]
authored andcommitted
fix(@angular-devkit/build-angular): workaround for esbuild static block AOT generated code
esbuild currently has a defect involving self-referencing a class within a static code block or static field initializer. This is not an issue for projects that use the default browserslist as these elements are an ES2022 feature which is not support by all browsers in the default list. However, if a custom browserslist is used that only has newer browsers than the static code elements may be present. This issue is compounded by the default usage of the tsconfig `"useDefineForClassFields": false` option present in generated CLI projects which causes static code blocks to be used instead of static fields. esbuild currently unconditionally downlevels all static fields in top-level classes so to workaround the Angular issue only static code blocks are disabled here. Fixes #25127
1 parent 57f0be7 commit 3aa1c4e

File tree

1 file changed

+10
-0
lines changed
  • packages/angular_devkit/build_angular/src/builders/browser-esbuild

1 file changed

+10
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,16 @@ function getFeatureSupport(target: string[]): BuildOptions['supported'] {
462462
// will be used instead which provides a workaround for the performance issue.
463463
// For more details: https://bugs.chromium.org/p/v8/issues/detail?id=11536
464464
'object-rest-spread': false,
465+
// esbuild currently has a defect involving self-referencing a class within a static code block or
466+
// static field initializer. This is not an issue for projects that use the default browserslist as these
467+
// elements are an ES2022 feature which is not support by all browsers in the default list. However, if a
468+
// custom browserslist is used that only has newer browsers than the static code elements may be present.
469+
// This issue is compounded by the default usage of the tsconfig `"useDefineForClassFields": false` option
470+
// present in generated CLI projects which causes static code blocks to be used instead of static fields.
471+
// esbuild currently unconditionally downlevels all static fields in top-level classes so to workaround the
472+
// Angular issue only static code blocks are disabled here.
473+
// For more details: https://github.com/evanw/esbuild/issues/2950
474+
'class-static-blocks': false,
465475
};
466476

467477
// Detect Safari browser versions that have a class field behavior bug

0 commit comments

Comments
 (0)