-
Notifications
You must be signed in to change notification settings - Fork 9
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
jsx formats that cannot be handled. #36
Comments
I noticed... But we can still improve this by relaxing the limitation of requiring an Here are some improvements that can be made:
$ht.s(edt).render(<i.StrictMode children={<Qht />} />);
$ht.s(edt).render(
<i.StrictMode>
<Qht />
</i.StrictMode>
);
|
Found another example of JSX not parsing how I would have expected. Would this also be resolved by the above? DetailsSource: var r = require(4337);
var a = require(35250);
var i = require(70079);
var s = require(34303);
var o = require(64135);
var l = require(88038);
var u = require(13282);
function d() {
var e = (0, r._)(["bg-black rounded-md"]);
d = function () {
return e;
};
return e;
}
function c() {
var e = (0, r._)([
"flex items-center relative text-gray-200 bg-gray-800 px-4 py-2 text-xs font-sans justify-between rounded-t-md ",
"",
]);
c = function () {
return e;
};
return e;
}
function f() {
var e = (0, r._)(["p-4 overflow-y-auto"]);
f = function () {
return e;
};
return e;
}
function h() {
var e = (0, r._)(["", ""]);
h = function () {
return e;
};
return e;
}
var g = s.Z.div(d());
var m = s.Z.div(c(), function (e) {
return e.$isMessageRedesign && "dark:bg-gray-900";
});
var p = s.Z.div(f());
var v = s.Z.code(h(), function (e) {
return e.$shouldWrap ? "!whitespace-pre-wrap" : "!whitespace-pre";
});
function x(e) {
var t = e.children;
var n = e.className;
var r = e.language;
var s = e.content;
var o = (0, i.useCallback)(
function () {
navigator.clipboard.writeText(s);
},
[s]
);
return (0, a.jsx)(b, {
title: r,
headerDecoration: (0, a.jsx)(u.Z, { buttonText: "Copy code", onCopy: o }),
className: "mb-4",
codeClassName: n,
children: t,
});
}
function b(e) {
var t = e.children;
var n = e.title;
var r = e.headerDecoration;
var i = e.shouldWrapCode;
var s = e.className;
var u = e.codeClassName;
var d = (0, o.hz)().has(l.FZ);
return (0, a.jsxs)(g, {
className: s,
children: [
(0, a.jsxs)(m, {
$isMessageRedesign: d,
children: [n && (0, a.jsx)("span", { children: n }), r],
}),
(0, a.jsx)(p, {
children: (0, a.jsx)(v, {
$shouldWrap: void 0 !== i && i,
className: u,
children: t,
}),
}),
],
});
}
module.exports = {
$: b,
Z: x,
}; Transformed: import u from "module-13282.js";
const { _ } = require(4337);
const { jsx, jsxs } = require(35250);
const { useCallback } = require(70079);
const s = require(34303);
const { hz } = require(64135);
const l = require(88038);
function d() {
const e = _(["bg-black rounded-md"]);
d = () => e;
return e;
}
function c() {
const e = _([
"flex items-center relative text-gray-200 bg-gray-800 px-4 py-2 text-xs font-sans justify-between rounded-t-md ",
"",
]);
c = () => e;
return e;
}
function f() {
const e = _(["p-4 overflow-y-auto"]);
f = () => e;
return e;
}
function h() {
const e = _(["", ""]);
h = () => e;
return e;
}
const g = s.Z.div(d());
const m = s.Z.div(c(), (e) => e.$isMessageRedesign && "dark:bg-gray-900");
const p = s.Z.div(f());
const v = s.Z.code(h(), (e) =>
e.$shouldWrap ? "!whitespace-pre-wrap" : "!whitespace-pre"
);
function x(e) {
const { children, className, language, content } = e;
const o = useCallback(() => {
navigator.clipboard.writeText(content);
}, [content]);
return jsx(b, {
title: language,
headerDecoration: <u.Z buttonText="Copy code" onCopy={o} />,
className: "mb-4",
codeClassName: className,
children: children,
});
}
function b(e) {
const {
children,
title,
headerDecoration,
shouldWrapCode,
className,
codeClassName,
} = e;
const d = hz().has(l.FZ);
return jsxs(g, {
className: className,
children: [
jsxs(m, {
$isMessageRedesign: d,
children: [title && <span children={title} />, headerDecoration],
}),
jsx(p, {
children: jsx(v, {
$shouldWrap: shouldWrapCode !== undefined && shouldWrapCode,
className: codeClassName,
children: children,
}),
}),
],
});
}
export default {
$: b,
Z: x,
}; |
@0xdevalias A few places can be fixed
jsx(p, , {
children: jsx(v, {
$shouldWrap: shouldWrapCode !== undefined && shouldWrapCode,
className: codeClassName,
children: children,
}),
}),
so a fix should be introduced to auto rename that v to things like V or VComp .
|
@0xdevalias Your example should be good now. return (
<G className={className}>
<M $isMessageRedesign={d}>
{title && <span>{title}</span>}
{headerDecoration}
</M>
<P>
{
<V
$shouldWrap={shouldWrapCode !== undefined && shouldWrapCode}
className={codeClassName}
>
{children}
</V>
}
</P>
</G> |
As a rule of thumb, react projects that use tailwind are likely to use a classname helper class like clsx. |
@pionxzh Amazing, thankyou! Using the same source as before (You can get the full webpack module code i'm unpacking here, and then once unpacked, it's DetailsTransformed: import u from "module-13282.js";
const { _ } = require(4337);
const { jsx, jsxs } = require(35250);
const { useCallback } = require(70079);
const s = require(34303);
const { hz } = require(64135);
const l = require(88038);
function d() {
const e = _(["bg-black rounded-md"]);
d = () => e;
return e;
}
function c() {
const e = _([
"flex items-center relative text-gray-200 bg-gray-800 px-4 py-2 text-xs font-sans justify-between rounded-t-md ",
"",
]);
c = () => e;
return e;
}
function f() {
const e = _(["p-4 overflow-y-auto"]);
f = () => e;
return e;
}
function h() {
const e = _(["", ""]);
h = () => e;
return e;
}
const G = s.Z.div(d());
const M = s.Z.div(c(), (e) => e.$isMessageRedesign && "dark:bg-gray-900");
const P = s.Z.div(f());
const V = s.Z.code(h(), (e) =>
e.$shouldWrap ? "!whitespace-pre-wrap" : "!whitespace-pre"
);
function x(e) {
const { children, className, language, content } = e;
const o = useCallback(() => {
navigator.clipboard.writeText(content);
}, [content]);
return (
<B
title={language}
headerDecoration={<u.Z buttonText="Copy code" onCopy={o} />}
className="mb-4"
codeClassName={className}
>
{children}
</B>
);
}
function B(e) {
const {
children,
title,
headerDecoration,
shouldWrapCode,
className,
codeClassName,
} = e;
const d = hz().has(l.FZ);
return (
<G className={className}>
<M $isMessageRedesign={d}>
{title && <span>{title}</span>}
{headerDecoration}
</M>
<P>
{
<V
$shouldWrap={shouldWrapCode !== undefined && shouldWrapCode}
className={codeClassName}
>
{children}
</V>
}
</P>
</G>
);
}
export default {
$: B,
Z: x,
}; While this is definitely improved from the original, and seems to have fixed the JSX parts, I wonder if there's anything clever that can be done about this sort of pattern (which is probably off topic for this issue): // ..snip..
function d() {
const e = _(["bg-black rounded-md"]);
d = () => e;
return e;
}
function c() {
const e = _([
"flex items-center relative text-gray-200 bg-gray-800 px-4 py-2 text-xs font-sans justify-between rounded-t-md ",
"",
]);
c = () => e;
return e;
}
// ..snip..
const G = s.Z.div(d());
const M = s.Z.div(c(), (e) => e.$isMessageRedesign && "dark:bg-gray-900");
// ..snip.. The usage of the
And the general pattern of the const d = (() => {
let memoizedValue;
return () => {
if (memoizedValue === undefined) {
// Compute the value only once
cachedValue = _(["bg-black rounded-md"]);
}
return cachedValue;
};
})(); Edit: For a far deeper dive into exploring the above code and trying to figure it out, see the following issue: Edit 2: Further insights about this pattern are explained in the below comment: |
These clsx similar library would require module detection, let's move it to another issue. Thans for the insight on those functions, not sure where they from👀 |
@pionxzh No problem :) I also ended up doing a deeeeep dive into this in the following issue: Which seemed to identify the library/related libraries; though not fully figure out how all of the code there relates.
@pionxzh Sounds like a good idea. |
Another deep dive the other day turned up some more info on exactly how these functions work/where they come from. See the following comment + issue for notes/references/exploration:
|
Summarising what I think is left 'outstanding' in this issue:
Based on the above, I think the only thing potentially remaining before this issue can be closed is:
|
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
@pionxzh Sure :) Opened the following and tried to fit the details into the template fields: |
using this code:
I get this result:
Probably the original code:
The text was updated successfully, but these errors were encountered: