Skip to content

Commit

Permalink
refactor: remove workarounds for Safari 14 and 15
Browse files Browse the repository at this point in the history
Both of these versions are no longer supported by Angular and thus these workers are no longer required.
  • Loading branch information
alan-agius4 committed Oct 22, 2024
1 parent ebc6aa6 commit b893a6a
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 141 deletions.
31 changes: 1 addition & 30 deletions packages/angular/build/src/tools/esbuild/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export function getFeatureSupport(
target: string[],
nativeAsyncAwait: boolean,
): BuildOptions['supported'] {
const supported: Record<string, boolean> = {
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,
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>;

export type DiagnosticReporter = (type: 'error' | 'warning' | 'info', message: string) => void;

/**
Expand Down Expand Up @@ -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'],
},
]);
Expand Down
77 changes: 0 additions & 77 deletions tests/legacy-cli/e2e/tests/misc/safari-15-class-properties.ts

This file was deleted.

0 comments on commit b893a6a

Please sign in to comment.