Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore: fallback to the original code after babel transform (#34635)
Pavel Feldman11e1b8f30a2c
diff --git a/packages/playwright/bundles/babel/src/babelBundleImpl.ts b/packages/playwright/bundles/babel/src/babelBundleImpl.tsindex 54822134ea..d58554b44b 100644--- a/packages/playwright/bundles/babel/src/babelBundleImpl.ts+++ b/packages/playwright/bundles/babel/src/babelBundleImpl.ts@@ -118,15 +118,15 @@ function isTypeScript(filename: string) {return filename.endsWith('.ts') || filename.endsWith('.tsx') || filename.endsWith('.mts') || filename.endsWith('.cts');}-export function babelTransform(code: string, filename: string, isModule: boolean, pluginsPrologue: [string, any?][], pluginsEpilogue: [string, any?][]): BabelFileResult {+export function babelTransform(code: string, filename: string, isModule: boolean, pluginsPrologue: [string, any?][], pluginsEpilogue: [string, any?][]): BabelFileResult | null {if (isTransforming)- return {};+ return null;// Prevent reentry while requiring plugins lazily.isTransforming = true;try {const options = babelTransformOptions(isTypeScript(filename), isModule, pluginsPrologue, pluginsEpilogue);- return babel.transform(code, { filename, ...options })!;+ return babel.transform(code, { filename, ...options });} finally {isTransforming = false;}diff --git a/packages/playwright/src/transform/babelBundle.ts b/packages/playwright/src/transform/babelBundle.tsindex d2f8b5919a..349b7b9c30 100644--- a/packages/playwright/src/transform/babelBundle.ts+++ b/packages/playwright/src/transform/babelBundle.ts@@ -20,7 +20,7 @@ export const declare: typeof import('../../bundles/babel/node_modules/@types/babexport const types: typeof import('../../bundles/babel/node_modules/@types/babel__core').types = require('./babelBundleImpl').types;export const traverse: typeof import('../../bundles/babel/node_modules/@types/babel__traverse').default = require('./babelBundleImpl').traverse;export type BabelPlugin = [string, any?];-export type BabelTransformFunction = (code: string, filename: string, isModule: boolean, pluginsPrefix: BabelPlugin[], pluginsSuffix: BabelPlugin[]) => BabelFileResult;+export type BabelTransformFunction = (code: string, filename: string, isModule: boolean, pluginsPrefix: BabelPlugin[], pluginsSuffix: BabelPlugin[]) => BabelFileResult | null;export const babelTransform: BabelTransformFunction = require('./babelBundleImpl').babelTransform;export type BabelParseFunction = (code: string, filename: string, isModule: boolean) => ParseResult;export const babelParse: BabelParseFunction = require('./babelBundleImpl').babelParse;diff --git a/packages/playwright/src/transform/transform.ts b/packages/playwright/src/transform/transform.tsindex 549d83a168..88950670be 100644--- a/packages/playwright/src/transform/transform.ts+++ b/packages/playwright/src/transform/transform.ts@@ -232,9 +232,10 @@ export function transformHook(originalCode: string, filename: string, moduleUrl?const { babelTransform }: { babelTransform: BabelTransformFunction } = require('./babelBundle');transformData = new Map<string, any>();- const { code, map } = babelTransform(originalCode, filename, !!moduleUrl, pluginsPrologue, pluginsEpilogue);- if (!code)- return { code: '', serializedCache };+ const babelResult = babelTransform(originalCode, filename, !!moduleUrl, pluginsPrologue, pluginsEpilogue);+ if (!babelResult?.code)+ return { code: originalCode, serializedCache };+ const { code, map } = babelResult;const added = addToCache!(code, map, transformData);return { code, serializedCache: added.serializedCache };}