feat: try to implement jsxRuntime option#406
feat: try to implement jsxRuntime option#406slorber wants to merge 1 commit intoFormidableLabs:masterfrom
Conversation
|
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
| function createRequire() { | ||
| return (val: string) => { | ||
| if (val === "react/jsx-runtime") { | ||
| return require("react/jsx-runtime"); | ||
| } else if (val === "react/jsx-dev-runtime") { | ||
| return require("react/jsx-dev-runtime"); | ||
| } else { | ||
| return require(val); | ||
| } | ||
| }; | ||
| } |
There was a problem hiding this comment.
I'm not super fan of this part, any idea how to deal with the new require("react/jsx-runtime") that Sucrase adds?
The transformed code looks like this now:
const _jsxFileName = "";
("use strict");
var _jsxdevruntime = require("react/jsx-dev-runtime");
return _jsxdevruntime.jsxDEV.call(
void 0,
"div",
{ children: "Hello World!" },
void 0,
false,
{ fileName: _jsxFileName, lineNumber: 1 },
this,
);Maybe it would be better to use Sucrase to remove the require call directly, and inject a _jsxdevruntime variable in scope directly?
Can injecting a require() function in scope be a problem?
Description
Attempt to add a new
jsxRuntimeoption, forwarded to SucraseThis gets rid of a new warning under React 19 in dev mode
Fixes #405
See also https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html
Type of Change
How Has This Been Tested?
Unit tests
Checklist: (Feel free to delete this section upon completion)