Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove workarounds for Safari 14 and 15 #28682

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.