Skip to content

Commit

Permalink
pass jsxImportSource to swc
Browse files Browse the repository at this point in the history
  • Loading branch information
cspotcode committed Sep 14, 2023
1 parent c2aeb0b commit 30561ba
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/test/transpilers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,38 @@ test.suite('swc', (test) => {
);
});

test.suite('jsx and jsxImportSource', (test) => {
test(
'jsx=react-jsx',
compileMacro,
{
jsx: 'react-jsx',
},
outdent`
<div></div>
`,
outdent`
/*#__PURE__*/ import { jsx as _jsx } from "react/jsx-runtime";
_jsx("div", {});
`
);
test(
'jsx=react-jsx w/custom jsxImportSource',
compileMacro,
{
jsx: 'react-jsx',
jsxImportSource: 'foo',
},
outdent`
<div></div>
`,
outdent`
/*#__PURE__*/ import { jsx as _jsx } from "foo/jsx-runtime";
_jsx("div", {});
`
);
});

test.suite(
'#1996 regression: ts-node gracefully allows swc to not return a sourcemap for type-only files',
(test) => {
Expand Down
2 changes: 2 additions & 0 deletions src/transpilers/swc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export function createSwcOptions(
strict,
alwaysStrict,
noImplicitUseStrict,
jsxImportSource,
} = compilerOptions;

let swcTarget = targetMapping.get(target!) ?? 'es3';
Expand Down Expand Up @@ -235,6 +236,7 @@ export function createSwcOptions(
pragma: jsxFactory!,
pragmaFrag: jsxFragmentFactory!,
runtime: jsxRuntime,
importSource: jsxImportSource,
},
useDefineForClassFields,
},
Expand Down

0 comments on commit 30561ba

Please sign in to comment.