diff --git a/packages/angular/build/src/tools/esbuild/utils.ts b/packages/angular/build/src/tools/esbuild/utils.ts index 21ea46ff55d1..3e62c6e7bb1a 100644 --- a/packages/angular/build/src/tools/esbuild/utils.ts +++ b/packages/angular/build/src/tools/esbuild/utils.ts @@ -195,7 +195,7 @@ export function getFeatureSupport( target: string[], nativeAsyncAwait: boolean, ): BuildOptions['supported'] { - const supported: Record = { + return { // Native async/await is not supported with Zone.js. Disabling support here will cause // esbuild to downlevel async/await, async generators, and for await...of to a Zone.js supported form. 'async-await': nativeAsyncAwait, @@ -205,35 +205,6 @@ export function getFeatureSupport( // For more details: https://bugs.chromium.org/p/v8/issues/detail?id=11536 'object-rest-spread': false, }; - - // Detect Safari browser versions that have a class field behavior bug - // See: https://github.com/angular/angular-cli/issues/24355#issuecomment-1333477033 - // See: https://github.com/WebKit/WebKit/commit/e8788a34b3d5f5b4edd7ff6450b80936bff396f2 - let safariClassFieldScopeBug = false; - for (const browser of target) { - let majorVersion; - if (browser.startsWith('ios')) { - majorVersion = Number(browser.slice(3, 5)); - } else if (browser.startsWith('safari')) { - majorVersion = Number(browser.slice(6, 8)); - } else { - continue; - } - // Technically, 14.0 is not broken but rather does not have support. However, the behavior - // is identical since it would be set to false by esbuild if present as a target. - if (majorVersion === 14 || majorVersion === 15) { - safariClassFieldScopeBug = true; - break; - } - } - // If class field support cannot be used set to false; otherwise leave undefined to allow - // esbuild to use `target` to determine support. - if (safariClassFieldScopeBug) { - supported['class-field'] = false; - supported['class-static-field'] = false; - } - - return supported; } const MAX_CONCURRENT_WRITES = 64; diff --git a/packages/angular_devkit/build_angular/src/tools/babel/presets/application.ts b/packages/angular_devkit/build_angular/src/tools/babel/presets/application.ts index f7c586083004..83ec20a0a8ea 100644 --- a/packages/angular_devkit/build_angular/src/tools/babel/presets/application.ts +++ b/packages/angular_devkit/build_angular/src/tools/babel/presets/application.ts @@ -23,15 +23,6 @@ import { loadEsmModule } from '../../../utils/load-esm'; */ let needsLinking: typeof import('@angular/compiler-cli/linker').needsLinking | undefined; -/** - * List of browsers which are affected by a WebKit bug where class field - * initializers might have incorrect variable scopes. - * - * See: https://github.com/angular/angular-cli/issues/24355#issuecomment-1333477033 - * See: https://github.com/WebKit/WebKit/commit/e8788a34b3d5f5b4edd7ff6450b80936bff396f2 - */ -let safariClassFieldScopeBugBrowsers: ReadonlySet; - export type DiagnosticReporter = (type: 'error' | 'warning' | 'info', message: string) => void; /** @@ -188,37 +179,12 @@ export default function (api: unknown, options: ApplicationPresetOptions) { // However, this doesn't effect libraries and hence we use preset-env to downlevel ES features // based on the supported browsers in browserslist. if (options.supportedBrowsers) { - const includePlugins: string[] = []; - - if (safariClassFieldScopeBugBrowsers === undefined) { - const browserslist = require('browserslist') as typeof import('browserslist'); - safariClassFieldScopeBugBrowsers = new Set( - browserslist([ - // Safari <15 is technically not supported via https://angular.dev/reference/versions#browser-support - // but we apply the workaround if forcibly selected. - 'Safari <=15', - 'iOS <=15', - ]), - ); - } - - // If a Safari browser affected by the class field scope bug is selected, we - // downlevel class properties by ensuring the class properties Babel plugin - // is always included- regardless of the preset-env targets. - if (options.supportedBrowsers.some((b) => safariClassFieldScopeBugBrowsers.has(b))) { - includePlugins.push( - '@babel/plugin-proposal-class-properties', - '@babel/plugin-proposal-private-methods', - ); - } - presets.push([ require('@babel/preset-env').default, { bugfixes: true, modules: false, targets: options.supportedBrowsers, - include: includePlugins, exclude: ['transform-typeof-symbol'], }, ]); diff --git a/tests/legacy-cli/e2e/tests/misc/safari-15-class-properties.ts b/tests/legacy-cli/e2e/tests/misc/safari-15-class-properties.ts deleted file mode 100644 index 7f7466b8336e..000000000000 --- a/tests/legacy-cli/e2e/tests/misc/safari-15-class-properties.ts +++ /dev/null @@ -1,77 +0,0 @@ -import assert from 'node:assert'; -import { expectFileToExist, readFile, writeFile, replaceInFile } from '../../utils/fs'; -import { ng } from '../../utils/process'; -import { getGlobalVariable } from '../../utils/env'; -import { updateJsonFile } from '../../utils/project'; - -const unexpectedStaticFieldErrorMessage = - 'Found unexpected static field. This indicates that the Safari <=v15 ' + - 'workaround for a scope variable tracking is not working. ' + - 'See: https://github.com/angular/angular-cli/pull/24357'; - -export default async function () { - // Add a private method - await replaceInFile( - 'src/app/app.component.ts', - `title = 'test-project';`, - ` - #myPrivateMethod() { return 1 } - - constructor() { - console.log(this.#myPrivateMethod) - } - - title = 'test-project';`, - ); - - await updateJsonFile('tsconfig.json', (tsconfig) => { - tsconfig.compilerOptions.useDefineForClassFields = false; - }); - - // Matches two types of static fields that indicate that the Safari bug - // may still occur. With the workaround this should not appear in bundles. - // - static { this.ecmp = bla } - // - static #_ = this.ecmp = bla - const staticIndicatorRegex = /static\s+(\{|#[_\d]+\s+=)/; - - await writeFile('.browserslistrc', 'last 1 chrome version'); - await ng('build', '--configuration=development'); - await expectFileToExist('dist/test-project/browser/main.js'); - const mainContentChromeLatest = await readFile('dist/test-project/browser/main.js'); - - assert.match( - mainContentChromeLatest, - staticIndicatorRegex, - 'Expected static fields to be used when Safari <=v15 is not targeted.', - ); - assert.match( - mainContentChromeLatest, - /#myPrivateMethod/, - 'Expected private method to be used when Safari <=v15 is not targeted.', - ); - - await writeFile('.browserslistrc', 'Safari <=15'); - - await ng('build', '--configuration=development'); - await expectFileToExist('dist/test-project/browser/main.js'); - const mainContentSafari15Explicit = await readFile('dist/test-project/browser/main.js'); - assert.doesNotMatch( - mainContentSafari15Explicit, - staticIndicatorRegex, - unexpectedStaticFieldErrorMessage, - ); - - if (getGlobalVariable('argv')['esbuild']) { - assert.match( - mainContentSafari15Explicit, - /var _myPrivateMethod/, - 'Expected private method to be downlevelled when Safari <=v15 is targeted', - ); - } else { - assert.match( - mainContentSafari15Explicit, - /_assertClassBrand/, - 'Expected private method to be downlevelled when Safari <=v15 is targeted', - ); - } -}