diff --git a/lib/types.d.ts b/lib/types.d.ts index a83db020..ea8243d0 100644 --- a/lib/types.d.ts +++ b/lib/types.d.ts @@ -152,6 +152,7 @@ export interface TransformOptions { filename?: string; ts?: boolean; retainLines?: boolean; + interopDefault?: boolean; async: boolean; [key: string]: any; } diff --git a/src/babel.ts b/src/babel.ts index ff825f75..fb754abf 100644 --- a/src/babel.ts +++ b/src/babel.ts @@ -32,7 +32,14 @@ export default function transform(opts: TransformOptions): TransformResult { cwd: "/", ...opts.babel, plugins: [ - [transformModulesPlugin, { allowTopLevelThis: true, async: opts.async }], + [ + transformModulesPlugin, + { + allowTopLevelThis: true, + noInterop: !opts.interopDefault, + async: opts.async, + }, + ], [TransformImportMetaPlugin, { filename: opts.filename }], [syntaxClassPropertiesPlugin], [transformExportNamespaceFromPlugin], diff --git a/src/transform.ts b/src/transform.ts index e0c7d9fe..78509319 100644 --- a/src/transform.ts +++ b/src/transform.ts @@ -3,7 +3,7 @@ import { getCache } from "./cache"; import { debug } from "./utils"; export function transform(ctx: Context, topts: TransformOptions): string { - let code = getCache(ctx, topts.filename, topts.source, topts.async, () => { + let code = getCache(ctx, topts, () => { const res = ctx.opts.transform!({ ...ctx.opts.transformOptions, babel: { @@ -15,6 +15,7 @@ export function transform(ctx: Context, topts: TransformOptions): string { : {}), ...ctx.opts.transformOptions?.babel, }, + interopDefault: ctx.opts.interopDefault, ...topts, }); if (res.error && ctx.opts.debug) {