fix(transform): skip explicit-resource-management lowering on Node 24+ (#41517)

This commit is contained in:
Simon Knott
2026-06-29 13:15:17 +02:00
committed by GitHub
parent 2a78ee542b
commit 6c0717dff6
4 changed files with 24 additions and 7 deletions
@@ -32,6 +32,8 @@ export type { BabelAPI } from '@babel/helper-plugin-utils';
export type BabelPlugin = [string, any?];
export type BabelTransformFunction = (code: string, filename: string, isModule: boolean, pluginsPrefix: BabelPlugin[], pluginsSuffix: BabelPlugin[], jsxImportSource?: string) => BabelFileResult | null;
const nodeMajorVersion = +process.versions.node.split('.')[0];
function babelTransformOptions(isTypeScript: boolean, isModule: boolean, pluginsPrologue: [string, any?][], pluginsEpilogue: [string, any?][], jsxImportSource?: string): TransformOptions {
const plugins = [
[require('@babel/plugin-syntax-import-attributes'), { deprecatedAssertSyntax: true }],
@@ -40,7 +42,6 @@ function babelTransformOptions(isTypeScript: boolean, isModule: boolean, plugins
if (isTypeScript) {
plugins.push(
[require('@babel/plugin-proposal-decorators'), { version: '2023-05' }],
[require('@babel/plugin-transform-explicit-resource-management')],
[require('@babel/plugin-transform-class-properties')],
[require('@babel/plugin-transform-class-static-block')],
[require('@babel/plugin-transform-numeric-separator')],
@@ -69,6 +70,9 @@ function babelTransformOptions(isTypeScript: boolean, isModule: boolean, plugins
})
]
);
if (nodeMajorVersion < 24)
plugins.push([require('@babel/plugin-transform-explicit-resource-management')]);
}
// Support JSX/TSX at all times, regardless of the file extension.
-6
View File
@@ -40,7 +40,6 @@ export type BrowserTestWorkerFixtures = PageWorkerFixtures & {
isElectron: boolean;
isHeadlessShell: boolean;
isFrozenWebkit: boolean;
nodeVersion: { major: number, minor: number, patch: number };
isBidi: boolean;
bidiTestSkipPredicate: (info: TestInfo) => boolean;
};
@@ -94,11 +93,6 @@ const test = baseTest.extend<BrowserTestTestFixtures & { _contextFactory: Contex
await run(Number(browserVersion.split('.')[0]));
}, { scope: 'worker' }],
nodeVersion: [async ({}, use) => {
const [major, minor, patch] = process.versions.node.split('.');
await use({ major: +major, minor: +minor, patch: +patch });
}, { scope: 'worker' }],
isBidi: [async ({ channel }, use) => {
await use(isBidiChannel(channel));
}, { scope: 'worker' }],
+5
View File
@@ -23,6 +23,7 @@ export type PlatformWorkerFixtures = {
isMac: boolean;
isLinux: boolean;
macVersion: number; // major only, 11 or later, zero if not mac
nodeVersion: { major: number, minor: number, patch: number };
};
function platform(): 'win32' | 'darwin' | 'linux' {
@@ -51,4 +52,8 @@ export const platformTest = test.extend<{}, PlatformWorkerFixtures>({
isMac: [platform() === 'darwin', { scope: 'worker' }],
isLinux: [platform() === 'linux', { scope: 'worker' }],
macVersion: [macVersion(), { scope: 'worker' }],
nodeVersion: [async ({}, use) => {
const [major, minor, patch] = process.versions.node.split('.');
await use({ major: +major, minor: +minor, patch: +patch });
}, { scope: 'worker' }],
});
+14
View File
@@ -867,6 +867,20 @@ it('should work with Array.from/map', async ({ page }) => {
})).toBe('([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})');
});
it('should work with a using declaration', async ({ page, nodeVersion }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/41511' });
it.skip(nodeVersion.major < 24, 'using is lowered to a module-scope helper that does not survive evaluate serialization on Node < 24');
const disposed = await page.evaluate(() => {
let disposed = false;
{
using r = { [Symbol.dispose]: () => { disposed = true; } };
void r;
}
return disposed;
});
expect(disposed).toBe(true);
});
it('should ignore dangerous object keys', async ({ page }) => {
const input = {
__proto__: { polluted: true },