Skip to content

Commit e6461ba

Browse files
clydinalan-agius4
authored andcommitted
fix(@angular-devkit/build-angular): prevent optimization adding unsupported ECMASCript features
When optimization is enabled with the `@angular-devkit/build-angular:browser` builder, terser is used as a second phase optimizer. The terser configuration previously set its `ecma` option to `es2020` due to all officially supported browsers supporting the version. However, it is possible to add browsers to the browserslist configuration that are not officially supported that still may work but do not support es2020 syntax features. By setting the terser `ecma` option to `es2015`, terser will not turn existing syntax into newer syntax features that might be unsupported. Terser will also not downlevel any code based on this option. Fixes #24347 (cherry picked from commit ef99a68)
1 parent d77416f commit e6461ba

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

packages/angular_devkit/build_angular/src/webpack/plugins/javascript-optimizer-worker.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,9 @@ async function optimizeWithTerser(
190190
passes: advanced ? 2 : 1,
191191
pure_getters: advanced,
192192
},
193-
// terser only supports up to ES2020
194-
ecma: 2020,
193+
// Set to ES2015 to prevent higher level features from being introduced when browserslist
194+
// contains older browsers. The build system requires browsers to support ES2015 at a minimum.
195+
ecma: 2015,
195196
// esbuild in the first pass is used to minify identifiers instead of mangle here
196197
mangle: false,
197198
// esbuild in the first pass is used to minify function names

0 commit comments

Comments
 (0)