Skip to content

Commit

Permalink
fix(dynamic import): adding interop util at EOF (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Nov 11, 2023
1 parent bf033b0 commit 0039b60
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/utils/transform/transform-dynamic-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import type { RawSourceMap } from '../../source-map';
import { parseEsm } from '../es-module-lexer';

const handlerName = '___tsxInteropDynamicImport';
const handleEsModuleFunction = `function ${handlerName}${(function (imported: Record<string, unknown>) {

// Prefixed with a newline since there could be a comment on the last line (e.g. sourcemap comment)
const handleEsModuleFunction = `\nfunction ${handlerName}${(function (imported: Record<string, unknown>) {
const d = 'default';
const exports = Object.keys(imported);
if (
Expand Down
8 changes: 6 additions & 2 deletions tests/specs/smoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,9 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
}));
// Could .js import TS files?
`,
// Comment at EOF: could be a sourcemap declaration. Edge case for inserting functions here
`.trim(),
});
onTestFinish(async () => await fixture.rm());

Expand Down Expand Up @@ -591,7 +593,9 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => {
pkgCommonjs,
pkgModule,
}));
`,
// Comment at EOF: could be a sourcemap declaration. Edge case for inserting functions here
`.trim(),
});
onFinish(async () => await fixture.rm());

Expand Down

0 comments on commit 0039b60

Please sign in to comment.