Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): support ESNext as target for Java…
Browse files Browse the repository at this point in the history
…Script optimizations

Previously, when ESNext was used, we fallbacked to ES2020 which caused ESBuild to output broken code.

Closes #22486

(cherry picked from commit b5c4a23)
  • Loading branch information
alan-agius4 authored and filipesilva committed Jan 16, 2022
1 parent 0700bfb commit bddd0fb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ export class JavaScriptOptimizerPlugin {
if (this.options.target) {
if (this.options.target <= ScriptTarget.ES5) {
target = 5;
} else if (this.options.target < ScriptTarget.ESNext) {
} else if (this.options.target === ScriptTarget.ESNext) {
target = 'next';
} else {
target = Number(
ScriptTarget[this.options.target].slice(2),
) as OptimizeRequestOptions['target'];
} else {
target = 2020;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export interface OptimizeRequestOptions {
/**
* Specifies the target ECMAScript version for the output code.
*/
target: 5 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020;
target: 5 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 'next';
/**
* Controls whether esbuild should only use the WASM-variant instead of trying to
* use the native variant. Some platforms may not support the native-variant and
Expand Down Expand Up @@ -105,7 +105,8 @@ export default async function ({ asset, options }: OptimizeRequest) {
asset.name,
esbuildResult.code,
options.sourcemap,
options.target,
// Terser only supports up to ES2020.
options.target === 'next' ? 2020 : options.target,
options.advanced,
);

Expand Down Expand Up @@ -208,7 +209,7 @@ async function optimizeWithTerser(
name: string,
code: string,
sourcemaps: boolean | undefined,
target: OptimizeRequest['options']['target'],
target: Exclude<OptimizeRequest['options']['target'], 'next'>,
advanced: boolean | undefined,
): Promise<{ code: string; map?: object }> {
const result = await minify(
Expand Down

0 comments on commit bddd0fb

Please sign in to comment.