-
Notifications
You must be signed in to change notification settings - Fork 244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: try to implement jsxRuntime option #406
base: master
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
jsxRuntime
option, 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)