Skip to content

Commit bddd0fb

Browse files
alan-agius4filipesilva
authored andcommittedJan 16, 2022
fix(@angular-devkit/build-angular): support ESNext as target for JavaScript optimizations
Previously, when ESNext was used, we fallbacked to ES2020 which caused ESBuild to output broken code. Closes #22486 (cherry picked from commit b5c4a23)
1 parent 0700bfb commit bddd0fb

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed
 

Diff for: ‎packages/angular_devkit/build_angular/src/webpack/plugins/javascript-optimizer-plugin.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,12 @@ export class JavaScriptOptimizerPlugin {
156156
if (this.options.target) {
157157
if (this.options.target <= ScriptTarget.ES5) {
158158
target = 5;
159-
} else if (this.options.target < ScriptTarget.ESNext) {
159+
} else if (this.options.target === ScriptTarget.ESNext) {
160+
target = 'next';
161+
} else {
160162
target = Number(
161163
ScriptTarget[this.options.target].slice(2),
162164
) as OptimizeRequestOptions['target'];
163-
} else {
164-
target = 2020;
165165
}
166166
}
167167

Diff for: ‎packages/angular_devkit/build_angular/src/webpack/plugins/javascript-optimizer-worker.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export interface OptimizeRequestOptions {
4848
/**
4949
* Specifies the target ECMAScript version for the output code.
5050
*/
51-
target: 5 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020;
51+
target: 5 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 'next';
5252
/**
5353
* Controls whether esbuild should only use the WASM-variant instead of trying to
5454
* use the native variant. Some platforms may not support the native-variant and
@@ -105,7 +105,8 @@ export default async function ({ asset, options }: OptimizeRequest) {
105105
asset.name,
106106
esbuildResult.code,
107107
options.sourcemap,
108-
options.target,
108+
// Terser only supports up to ES2020.
109+
options.target === 'next' ? 2020 : options.target,
109110
options.advanced,
110111
);
111112

@@ -208,7 +209,7 @@ async function optimizeWithTerser(
208209
name: string,
209210
code: string,
210211
sourcemaps: boolean | undefined,
211-
target: OptimizeRequest['options']['target'],
212+
target: Exclude<OptimizeRequest['options']['target'], 'next'>,
212213
advanced: boolean | undefined,
213214
): Promise<{ code: string; map?: object }> {
214215
const result = await minify(

0 commit comments

Comments
 (0)
Please sign in to comment.