Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): prevent optimization adding unsup…
Browse files Browse the repository at this point in the history
…ported 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)
  • Loading branch information
clydin authored and alan-agius4 committed Dec 1, 2022
1 parent d77416f commit e6461ba
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,9 @@ async function optimizeWithTerser(
passes: advanced ? 2 : 1,
pure_getters: advanced,
},
// terser only supports up to ES2020
ecma: 2020,
// Set to ES2015 to prevent higher level features from being introduced when browserslist
// contains older browsers. The build system requires browsers to support ES2015 at a minimum.
ecma: 2015,
// esbuild in the first pass is used to minify identifiers instead of mangle here
mangle: false,
// esbuild in the first pass is used to minify function names
Expand Down

0 comments on commit e6461ba

Please sign in to comment.