From 2102189a2cc340bd8cdba09b4efc9f1db2b0ede1 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Thu, 4 May 2023 13:10:23 -0400 Subject: [PATCH] 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 --- .../src/builders/browser-esbuild/index.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/index.ts b/packages/angular_devkit/build_angular/src/builders/browser-esbuild/index.ts index a88b45c66d4e..dd7a80ba4497 100644 --- a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/index.ts +++ b/packages/angular_devkit/build_angular/src/builders/browser-esbuild/index.ts @@ -469,6 +469,16 @@ function getFeatureSupport(target: string[]): BuildOptions['supported'] { // will be used instead which provides a workaround for the performance issue. // For more details: https://bugs.chromium.org/p/v8/issues/detail?id=11536 'object-rest-spread': false, + // 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. + // For more details: https://github.com/evanw/esbuild/issues/2950 + 'class-static-blocks': false, }; // Detect Safari browser versions that have a class field behavior bug