Skip to content

Commit

Permalink
fix: properly handle tsx (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Sep 30, 2024
1 parent 6a4e13a commit 2ae340f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/babel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ export default function transform(opts: TransformOptions): TransformResult {
if (opts.ts) {
_opts.plugins.push([
transformTypeScriptPlugin,
{ allowDeclareFields: true },
{
allowDeclareFields: true,
isTSX: opts.jsx && /\.[cm]?tsx$/.test(opts.filename || ""),
},
]);
// `unshift` because these plugin must come before `@babel/plugin-syntax-class-properties`
_opts.plugins.unshift(
Expand Down
4 changes: 2 additions & 2 deletions src/eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function evalModule(
const cache = (evalOptions.cache || ctx.parentCache || {}) as ModuleCache;

// Transpile
const isTypescript = ext === ".ts" || ext === ".mts" || ext === ".cts";
const isTypescript = /\.[cm]?tsx?$/.test(ext);
const isESM =
ext === ".mjs" ||
(ext === ".js" && readNearestPackageJSON(filename)?.type === "module");
Expand All @@ -45,7 +45,7 @@ export function evalModule(
ctx.isTransformRe.test(filename) ||
hasESMSyntax(source));
const start = performance.now();
if (needsTranspile || (ctx.opts.jsx && (ext === ".jsx" || ext === ".tsx"))) {
if (needsTranspile) {
source = transform(ctx, {
filename,
source,
Expand Down
2 changes: 2 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export function resolveJitiOptions(userOptions: JitiOptions): JitiOptions {
".tsx",
".mts",
".cts",
".mtsx",
".ctsx",
]),
alias: _jsonEnv<Record<string, string>>("JITI_ALIAS", {}),
nativeModules: _jsonEnv<string[]>("JITI_NATIVE_MODULES", []),
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/jsx/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "./nano-jsx.jsx";
import "./nano-jsx.tsx";
import "./preact.jsx";
import "./react.jsx";
import "./vue.jsx";
File renamed without changes.

0 comments on commit 2ae340f

Please sign in to comment.