Skip to content

Commit

Permalink
fix: respect interopDefault in babel transform
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jul 2, 2024
1 parent 54d6b4a commit 485b4e9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export interface TransformOptions {
filename?: string;
ts?: boolean;
retainLines?: boolean;
interopDefault?: boolean;
async: boolean;
[key: string]: any;
}
Expand Down
9 changes: 8 additions & 1 deletion src/babel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
3 changes: 2 additions & 1 deletion src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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) {
Expand Down

0 comments on commit 485b4e9

Please sign in to comment.