Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/bunfig/bunfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -952,14 +952,15 @@ impl<'a> Parser<'a> {

if let Some(expr) = json.get(b"jsx") {
if let Some(value) = expr.as_string(self.bump) {
if value == b"react" {
// Case-insensitive, like the same key in tsconfig.json.
if value.eq_ignore_ascii_case(b"react") {
jsx_runtime = api::JsxRuntime::Classic;
} else if value == b"solid" {
} else if value.eq_ignore_ascii_case(b"solid") {
jsx_runtime = api::JsxRuntime::Solid;
} else if value == b"react-jsx" {
} else if value.eq_ignore_ascii_case(b"react-jsx") {
jsx_runtime = api::JsxRuntime::Automatic;
jsx_dev = false;
} else if value == b"react-jsxDEV" {
} else if value.eq_ignore_ascii_case(b"react-jsxdev") {
jsx_runtime = api::JsxRuntime::Automatic;
jsx_dev = true;
} else {
Expand Down
34 changes: 34 additions & 0 deletions test/bundler/bundler_jsx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1363,3 +1363,37 @@ describe("bundler", () => {
});
});
});

// The bunfig `jsx` key takes the tsconfig `compilerOptions.jsx` values, and
// tsconfig matches them case-insensitively.
describe.concurrent("jsx/bunfigRuntimeSpelling", () => {
const stubs = {
"node_modules/react/package.json": `{ "name": "react", "main": "index.js" }`,
"node_modules/react/index.js": `export default { createElement() { return "createElement"; } };`,
"node_modules/react/jsx-dev-runtime.js": `export function jsxDEV() { return "jsxDEV"; }`,
"node_modules/react/jsx-runtime.js": `export function jsx() { return "jsx"; }`,
"index.tsx": `import React from "react";\nconsole.log(<a />);`,
};
test.each([
["react", "createElement"],
["React", "createElement"],
["react-jsxdev", "jsxDEV"],
["react-jsxDEV", "jsxDEV"],
["REACT-JSXDEV", "jsxDEV"],
["react-jsx", "jsx"],
["React-JSX", "jsx"],
])('jsx = "%s"', async (spelling, expected) => {
using dir = tempDir("bunfig-jsx-spelling", { ...stubs, "bunfig.toml": `jsx = "${spelling}"\n` });
await using proc = Bun.spawn({
cmd: [bunExe(), "index.tsx"],
env: { ...bunEnv, NODE_ENV: "development" },
cwd: String(dir),
stdout: "pipe",
stderr: "pipe",
});
const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
expect(stderr).toBe("");
expect(stdout).toBe(`${expected}\n`);
expect(exitCode).toBe(0);
});
});
Loading