@reckona/mreact-compiler 0.0.161 → 0.0.162
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/emit-server-stream.d.ts.map +1 -1
- package/dist/emit-server-stream.js +70 -4
- package/dist/emit-server-stream.js.map +1 -1
- package/dist/oxc-compat-create-element.d.ts +2 -0
- package/dist/oxc-compat-create-element.d.ts.map +1 -1
- package/dist/oxc-compat-create-element.js +93 -18
- package/dist/oxc-compat-create-element.js.map +1 -1
- package/dist/oxc.d.ts.map +1 -1
- package/dist/oxc.js +177 -21
- package/dist/oxc.js.map +1 -1
- package/package.json +2 -2
- package/src/emit-server-stream.ts +103 -8
- package/src/oxc-compat-create-element.ts +132 -25
- package/src/oxc.ts +326 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emit-server-stream.d.ts","sourceRoot":"","sources":["../src/emit-server-stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAMV,QAAQ,EACT,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AA2B1F,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,aAAa,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,uBAAuB;IACtC,iBAAiB,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACpC,eAAe,CAAC,EAAE,mBAAmB,CAAC;IACtC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,MAAM,CAAC,EAAE,mBAAmB,GAAG,SAAS,CAAC;IACzC,4BAA4B,CAAC,EAAE,MAAM,CAAC;CACvC;
|
|
1
|
+
{"version":3,"file":"emit-server-stream.d.ts","sourceRoot":"","sources":["../src/emit-server-stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAMV,QAAQ,EACT,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AA2B1F,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,aAAa,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,uBAAuB;IACtC,iBAAiB,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACpC,eAAe,CAAC,EAAE,mBAAmB,CAAC;IACtC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,MAAM,CAAC,EAAE,mBAAmB,GAAG,SAAS,CAAC;IACzC,4BAA4B,CAAC,EAAE,MAAM,CAAC;CACvC;AAeD,wBAAgB,gBAAgB,CAC9B,EAAE,EAAE,QAAQ,EACZ,OAAO,GAAE,uBAA4B,GACpC,sBAAsB,CA8IxB"}
|
|
@@ -13,6 +13,7 @@ let currentOutOfOrderBoundaryHelperName = "_renderOutOfOrderBoundary";
|
|
|
13
13
|
let currentReactSuspenseBoundaryHelperName = "_renderReactSuspenseBoundary";
|
|
14
14
|
let currentReactSuspenseOutOfOrderBoundaryHelperName = "_renderReactSuspenseOutOfOrderBoundary";
|
|
15
15
|
let currentCompatRenderToStringHelperName = "_renderCompatToString";
|
|
16
|
+
let currentCompatChildHelperName;
|
|
16
17
|
let currentPropChildrenCollectState;
|
|
17
18
|
export function emitServerStream(ir, options = {}) {
|
|
18
19
|
const serverBootstrap = options.serverBootstrap ?? "none";
|
|
@@ -24,6 +25,9 @@ export function emitServerStream(ir, options = {}) {
|
|
|
24
25
|
const reactSuspenseBoundaryHelperName = allocateHelperName(ir, "_renderReactSuspenseBoundary");
|
|
25
26
|
const reactSuspenseOutOfOrderBoundaryHelperName = allocateHelperName(ir, "_renderReactSuspenseOutOfOrderBoundary");
|
|
26
27
|
const compatRenderToStringHelperName = allocateHelperName(ir, "_renderCompatToString");
|
|
28
|
+
const compatChildHelperName = usesCompatChildRender(ir)
|
|
29
|
+
? allocateHelperName(ir, "_renderCompatChild")
|
|
30
|
+
: undefined;
|
|
27
31
|
const streamNodeHelperName = allocateHelperName(ir, "_renderStreamNode");
|
|
28
32
|
const clientBoundaryHelperName = usesClientBoundary(ir, options.serverHydration === true)
|
|
29
33
|
? allocateHelperName(ir, "_renderClientBoundary")
|
|
@@ -40,6 +44,7 @@ export function emitServerStream(ir, options = {}) {
|
|
|
40
44
|
currentReactSuspenseBoundaryHelperName = reactSuspenseBoundaryHelperName;
|
|
41
45
|
currentReactSuspenseOutOfOrderBoundaryHelperName = reactSuspenseOutOfOrderBoundaryHelperName;
|
|
42
46
|
currentCompatRenderToStringHelperName = compatRenderToStringHelperName;
|
|
47
|
+
currentCompatChildHelperName = compatChildHelperName;
|
|
43
48
|
const helper = emitEscapeHtmlHelper(escapeHelperName);
|
|
44
49
|
const urlSafeHelper = [
|
|
45
50
|
`function ${urlSafeHelperName}(name, value) {`,
|
|
@@ -92,6 +97,9 @@ export function emitServerStream(ir, options = {}) {
|
|
|
92
97
|
renderReactSuspenseBoundary: reactSuspenseBoundaryHelperName,
|
|
93
98
|
renderReactSuspenseOutOfOrderBoundary: reactSuspenseOutOfOrderBoundaryHelperName,
|
|
94
99
|
renderToString: compatRenderToStringHelperName,
|
|
100
|
+
...(compatChildHelperName === undefined
|
|
101
|
+
? {}
|
|
102
|
+
: { renderChildToString: compatChildHelperName }),
|
|
95
103
|
};
|
|
96
104
|
const importLine = imports
|
|
97
105
|
.map((runtimeImport) => `import { ${runtimeImport.specifiers
|
|
@@ -150,10 +158,16 @@ function collectImports(ir, serverBootstrap) {
|
|
|
150
158
|
specifiers: serverSpecifiers,
|
|
151
159
|
});
|
|
152
160
|
}
|
|
153
|
-
|
|
161
|
+
const compatSpecifiers = [
|
|
162
|
+
...(hasCompatComponentReference(ir) || hasReactNodeRender(ir) || hasRawJsxDynamicRender(ir)
|
|
163
|
+
? ["renderToString"]
|
|
164
|
+
: []),
|
|
165
|
+
...(usesCompatChildRender(ir) ? ["renderChildToString"] : []),
|
|
166
|
+
];
|
|
167
|
+
if (compatSpecifiers.length > 0) {
|
|
154
168
|
imports.push({
|
|
155
169
|
source: "@reckona/mreact-compat",
|
|
156
|
-
specifiers:
|
|
170
|
+
specifiers: compatSpecifiers,
|
|
157
171
|
});
|
|
158
172
|
}
|
|
159
173
|
return imports;
|
|
@@ -695,6 +709,9 @@ function collectHtmlParts(node, escapeHelperName, asyncBoundaryHelperName, outOf
|
|
|
695
709
|
if (node.renderMode === "stream-node") {
|
|
696
710
|
return [{ kind: "stream-node", code: node.code, escapeHelperName }];
|
|
697
711
|
}
|
|
712
|
+
if (node.renderMode === "compat-child" && currentCompatChildHelperName !== undefined) {
|
|
713
|
+
return [{ kind: "raw-dynamic", code: `${currentCompatChildHelperName}(${node.code})` }];
|
|
714
|
+
}
|
|
698
715
|
return [{ kind: "dynamic", code: node.code, escapeHelperName }];
|
|
699
716
|
}
|
|
700
717
|
if (node.kind === "conditional") {
|
|
@@ -958,7 +975,9 @@ function collectHtmlAttributeParts(tagName, attr, escapeHelperName, escapeBatchH
|
|
|
958
975
|
return [
|
|
959
976
|
{
|
|
960
977
|
kind: "raw-dynamic",
|
|
961
|
-
code:
|
|
978
|
+
code: attr.serialization === "compat"
|
|
979
|
+
? emitCompatDynamicStyleAttributeExpression(attr.code, escapeHelperName)
|
|
980
|
+
: emitDynamicStyleAttributeExpression(attr.code, escapeHelperName, escapeBatchHelperName),
|
|
962
981
|
},
|
|
963
982
|
];
|
|
964
983
|
}
|
|
@@ -974,7 +993,9 @@ function collectHtmlAttributeParts(tagName, attr, escapeHelperName, escapeBatchH
|
|
|
974
993
|
return [
|
|
975
994
|
{
|
|
976
995
|
kind: "raw-dynamic",
|
|
977
|
-
code:
|
|
996
|
+
code: attr.serialization === "compat" && !isUrlAttribute(dynamicHtmlName)
|
|
997
|
+
? emitCompatDynamicAttributeExpression(dynamicHtmlName, attr.code, escapeHelperName)
|
|
998
|
+
: emitDynamicAttributeExpression(dynamicHtmlName, attr.code, escapeHelperName),
|
|
978
999
|
},
|
|
979
1000
|
];
|
|
980
1001
|
}
|
|
@@ -1070,6 +1091,22 @@ function emitDynamicAttributeExpression(name, code, escapeHelperName) {
|
|
|
1070
1091
|
? `(() => { const _value = (${code}); return _value == null ? "" : ${stringLiteral(` ${name}="`)} + ${escapeHelperName}(_value) + ${stringLiteral('"')}; })()`
|
|
1071
1092
|
: `(() => { const _value = (${code}); return _value == null || _value === false ? "" : ${stringLiteral(` ${name}="`)} + ${escapeHelperName}(_value === true ? "" : _value) + ${stringLiteral('"')}; })()`;
|
|
1072
1093
|
}
|
|
1094
|
+
function emitCompatDynamicAttributeExpression(name, code, escapeHelperName) {
|
|
1095
|
+
const lowerCased = name.toLowerCase();
|
|
1096
|
+
const booleanishOrData = lowerCased.startsWith("aria-") ||
|
|
1097
|
+
lowerCased.startsWith("data-") ||
|
|
1098
|
+
lowerCased === "contenteditable" ||
|
|
1099
|
+
lowerCased === "draggable" ||
|
|
1100
|
+
lowerCased === "spellcheck";
|
|
1101
|
+
const booleanBranch = booleanishOrData
|
|
1102
|
+
? `return ${stringLiteral(` ${name}="`)} + (_value ? "true" : "false") + ${stringLiteral('"')};`
|
|
1103
|
+
: `return _value ? ${stringLiteral(` ${name}=""`)} : "";`;
|
|
1104
|
+
return `(() => { const _value = (${code}); if (_value == null || typeof _value === "function") return ""; if (typeof _value === "boolean") { ${booleanBranch} } if (typeof _value === "object") return ""; return ${stringLiteral(` ${name}="`)} + ${escapeHelperName}(_value) + ${stringLiteral('"')}; })()`;
|
|
1105
|
+
}
|
|
1106
|
+
function emitCompatDynamicStyleAttributeExpression(code, escapeHelperName) {
|
|
1107
|
+
const unitlessCheck = '_styleName === "flex" || _styleName === "fontWeight" || _styleName === "lineHeight" || _styleName === "opacity" || _styleName === "order" || _styleName === "zIndex" || _styleName === "zoom"';
|
|
1108
|
+
return `(() => { const _value = (${code}); if (_value == null || typeof _value !== "object") return ""; let _style = ""; for (const _styleName in _value) { const _styleValue = _value[_styleName]; if (_styleValue == null || typeof _styleValue === "boolean" || _styleValue === "") continue; const _cssName = _styleName.startsWith("--") ? _styleName : _styleName.replace(/[A-Z]/g, (_char) => "-" + _char.toLowerCase()); const _css = typeof _styleValue !== "number" || _styleValue === 0 || (${unitlessCheck}) ? String(_styleValue) : _styleValue + "px"; _style += (_style === "" ? "" : ";") + ${escapeHelperName}(_cssName) + ":" + ${escapeHelperName}(_css); } return _style === "" ? "" : ${stringLiteral(' style="')} + _style + ${stringLiteral('"')}; })()`;
|
|
1109
|
+
}
|
|
1073
1110
|
function emitDynamicStyleAttributeExpression(code, escapeHelperName, escapeBatchHelperName) {
|
|
1074
1111
|
const staticStyleExpression = emitStaticStyleObjectAttributeExpression(code, escapeHelperName);
|
|
1075
1112
|
if (staticStyleExpression !== undefined) {
|
|
@@ -1516,6 +1553,35 @@ function containsReactNodeRender(node) {
|
|
|
1516
1553
|
}
|
|
1517
1554
|
return false;
|
|
1518
1555
|
}
|
|
1556
|
+
function usesCompatChildRender(ir) {
|
|
1557
|
+
return ir.components.some((component) => containsCompatChildRender(component.root));
|
|
1558
|
+
}
|
|
1559
|
+
function containsCompatChildRender(node) {
|
|
1560
|
+
if (node.kind === "expr") {
|
|
1561
|
+
return node.renderMode === "compat-child";
|
|
1562
|
+
}
|
|
1563
|
+
if (node.kind === "component") {
|
|
1564
|
+
return (node.children.some(containsCompatChildRender) ||
|
|
1565
|
+
node.props.some((prop) => prop.kind === "render-prop" && prop.children.some(containsCompatChildRender)));
|
|
1566
|
+
}
|
|
1567
|
+
if (node.kind === "conditional") {
|
|
1568
|
+
return [...node.whenTrue, ...node.whenFalse].some(containsCompatChildRender);
|
|
1569
|
+
}
|
|
1570
|
+
if (node.kind === "list") {
|
|
1571
|
+
return node.children.some(containsCompatChildRender);
|
|
1572
|
+
}
|
|
1573
|
+
if (node.kind === "element" || node.kind === "fragment") {
|
|
1574
|
+
return node.children.some(containsCompatChildRender);
|
|
1575
|
+
}
|
|
1576
|
+
if (node.kind === "async-boundary") {
|
|
1577
|
+
return [
|
|
1578
|
+
...node.children,
|
|
1579
|
+
...(node.placeholderChildren ?? []),
|
|
1580
|
+
...(node.catchChildren ?? []),
|
|
1581
|
+
].some(containsCompatChildRender);
|
|
1582
|
+
}
|
|
1583
|
+
return false;
|
|
1584
|
+
}
|
|
1519
1585
|
function containsRawJsxDynamicRender(node) {
|
|
1520
1586
|
if (node.kind === "expr") {
|
|
1521
1587
|
return node.renderMode !== "react-node" && looksLikeRawJsxExpression(node.code);
|