-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Fix: transpiling React.createElement into Preact h behavior #7435
Fix: transpiling React.createElement into Preact h behavior #7435
Conversation
|
dc89141
to
ca600b4
Compare
@@ -126,6 +126,37 @@ const SCRIPT_ERRORS = { | |||
}, | |||
}; | |||
|
|||
function convertAliasReactIntoPragma( |
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.
In order to convert preact/compat
into preact
pragma, I made a function to do it, but I feel this approach is a little muddy. If you have another idea to implement this, I will be happy if you comment on it.
I think this approach is wrong. I thought #7433 behavior is caused by this line(https://github.com/parcel-bundler/parcel/blob/v2/packages/transformers/js/src/JSTransformer.js#L160) in which reactLib is fixed to I think the cause is not this line, but these line(https://github.com/parcel-bundler/parcel/blob/v2/packages/transformers/js/src/JSTransformer.js#L201). In these line, It's 3am in my timezone, so once I back this PR to draft and sleep, and I’ll work tomorrow 🙇. |
I fixed 👍 |
Does the current version still have the problem that I think something like this should work. The other react-like libraries don't support this automatic runtime anyway --- packages/transformers/js/src/JSTransformer.js
+++ packages/transformers/js/src/JSTransformer.js
@@ -199,11 +199,15 @@ export default (new Transformer({
jsxImportSource = compilerOptions?.jsxImportSource;
automaticJSXRuntime = true;
} else if (reactLib) {
- let automaticVersion = JSX_PRAGMA[reactLib]?.automatic;
+ let effectiveReactLib =
+ (pkg?.alias && pkg.alias['react']) === 'preact/compat'
+ ? 'preact'
+ : reactLib;
+ let automaticVersion = JSX_PRAGMA[effectiveReactLib]?.automatic;
let reactLibVersion =
- pkg?.dependencies?.[reactLib] ||
- pkg?.devDependencies?.[reactLib] ||
- pkg?.peerDependencies?.[reactLib];
+ pkg?.dependencies?.[effectiveReactLib] ||
+ pkg?.devDependencies?.[effectiveReactLib] ||
+ pkg?.peerDependencies?.[effectiveReactLib];
let minReactLibVersion =
reactLibVersion != null && reactLibVersion !== '*'
? semver.minVersion(reactLibVersion)?.toString() |
As you say, it's not Thank you for helping! |
let file = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8'); | ||
assert(file.includes('_jsxRuntime.jsx("div"')); |
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 think we should also add this to make sure it's actually importing from React (using a Regex because react/jsx-runtime
is a substring of preact/jsx-runtime
).
let file = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8'); | |
assert(file.includes('_jsxRuntime.jsx("div"')); | |
let file = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8'); | |
assert(/\Wreact\/jsx-runtime\W/.test(file)); | |
assert(file.includes('_jsxRuntime.jsx("div"')); |
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.
Sure. I fixed in 4efec78 👍 Thanks!
… from react/jsx-runtime
…b.com/Shinyaigeek/parcel into fix/correct-jsx-runtime-import-source
↪️ Pull Request
Hi team 👋
Fixes: #7433
jsxImportSource
will be determined withreactLib
variable, butreactLib
variable is always “react” string literal ifalias.react is setted
. I thinkjsx-runtime
(and automatic transformation) is not related.I fixed this
💻 Examples
package.json
🚨 Test instructions
I made a test case to check jsx runtime transformation with preact with
alias.react
package.json.✔️ PR Todo