chore: fallback to the original code after babel transform (#34635)
This commit is contained in:
parent
7f09ba7fa4
commit
11e1b8f30a
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ export const declare: typeof import('../../bundles/babel/node_modules/@types/bab
|
|||
export 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;
|
||||
|
|
|
|||
|
|
@ -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 };
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue