Skip to content

Commit 11e1b8f

Browse files
authored
chore: fallback to the original code after babel transform (#34635)
1 parent 7f09ba7 commit 11e1b8f

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

packages/playwright/bundles/babel/src/babelBundleImpl.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,15 @@ function isTypeScript(filename: string) {
118118
return filename.endsWith('.ts') || filename.endsWith('.tsx') || filename.endsWith('.mts') || filename.endsWith('.cts');
119119
}
120120

121-
export function babelTransform(code: string, filename: string, isModule: boolean, pluginsPrologue: [string, any?][], pluginsEpilogue: [string, any?][]): BabelFileResult {
121+
export function babelTransform(code: string, filename: string, isModule: boolean, pluginsPrologue: [string, any?][], pluginsEpilogue: [string, any?][]): BabelFileResult | null {
122122
if (isTransforming)
123-
return {};
123+
return null;
124124

125125
// Prevent reentry while requiring plugins lazily.
126126
isTransforming = true;
127127
try {
128128
const options = babelTransformOptions(isTypeScript(filename), isModule, pluginsPrologue, pluginsEpilogue);
129-
return babel.transform(code, { filename, ...options })!;
129+
return babel.transform(code, { filename, ...options });
130130
} finally {
131131
isTransforming = false;
132132
}

packages/playwright/src/transform/babelBundle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const declare: typeof import('../../bundles/babel/node_modules/@types/bab
2020
export const types: typeof import('../../bundles/babel/node_modules/@types/babel__core').types = require('./babelBundleImpl').types;
2121
export const traverse: typeof import('../../bundles/babel/node_modules/@types/babel__traverse').default = require('./babelBundleImpl').traverse;
2222
export type BabelPlugin = [string, any?];
23-
export type BabelTransformFunction = (code: string, filename: string, isModule: boolean, pluginsPrefix: BabelPlugin[], pluginsSuffix: BabelPlugin[]) => BabelFileResult;
23+
export type BabelTransformFunction = (code: string, filename: string, isModule: boolean, pluginsPrefix: BabelPlugin[], pluginsSuffix: BabelPlugin[]) => BabelFileResult | null;
2424
export const babelTransform: BabelTransformFunction = require('./babelBundleImpl').babelTransform;
2525
export type BabelParseFunction = (code: string, filename: string, isModule: boolean) => ParseResult;
2626
export const babelParse: BabelParseFunction = require('./babelBundleImpl').babelParse;

packages/playwright/src/transform/transform.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,10 @@ export function transformHook(originalCode: string, filename: string, moduleUrl?
232232

233233
const { babelTransform }: { babelTransform: BabelTransformFunction } = require('./babelBundle');
234234
transformData = new Map<string, any>();
235-
const { code, map } = babelTransform(originalCode, filename, !!moduleUrl, pluginsPrologue, pluginsEpilogue);
236-
if (!code)
237-
return { code: '', serializedCache };
235+
const babelResult = babelTransform(originalCode, filename, !!moduleUrl, pluginsPrologue, pluginsEpilogue);
236+
if (!babelResult?.code)
237+
return { code: originalCode, serializedCache };
238+
const { code, map } = babelResult;
238239
const added = addToCache!(code, map, transformData);
239240
return { code, serializedCache: added.serializedCache };
240241
}

0 commit comments

Comments
 (0)