@reckona/mreact-compiler 0.0.97 → 0.0.99
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/diagnostics.d.ts +1 -0
- package/dist/diagnostics.d.ts.map +1 -1
- package/dist/diagnostics.js +8 -0
- package/dist/diagnostics.js.map +1 -1
- package/dist/emit-client.js +14 -9
- package/dist/emit-client.js.map +1 -1
- package/dist/emit-compat.js +5 -1
- package/dist/emit-compat.js.map +1 -1
- package/dist/emit-server-stream.js +52 -3
- package/dist/emit-server-stream.js.map +1 -1
- package/dist/emit-server.js +51 -10
- package/dist/emit-server.js.map +1 -1
- package/dist/ir.d.ts +1 -0
- package/dist/ir.d.ts.map +1 -1
- package/dist/ir.js.map +1 -1
- package/dist/oxc-child-analysis.d.ts.map +1 -1
- package/dist/oxc-child-analysis.js +41 -7
- package/dist/oxc-child-analysis.js.map +1 -1
- package/dist/oxc-component-detection.d.ts +5 -2
- package/dist/oxc-component-detection.d.ts.map +1 -1
- package/dist/oxc-component-detection.js +80 -3
- package/dist/oxc-component-detection.js.map +1 -1
- package/dist/oxc-component-props.d.ts +1 -1
- package/dist/oxc-component-props.d.ts.map +1 -1
- package/dist/oxc-component-props.js +1 -1
- package/dist/oxc-component-props.js.map +1 -1
- package/dist/oxc-component-references.js +2 -2
- package/dist/oxc-component-references.js.map +1 -1
- package/dist/oxc-runtime-emit.d.ts.map +1 -1
- package/dist/oxc-runtime-emit.js +10 -2
- package/dist/oxc-runtime-emit.js.map +1 -1
- package/dist/oxc.d.ts.map +1 -1
- package/dist/oxc.js +109 -20
- package/dist/oxc.js.map +1 -1
- package/dist/transform.js +29 -11
- package/dist/transform.js.map +1 -1
- package/package.json +2 -2
- package/src/diagnostics.ts +10 -0
- package/src/emit-client.ts +20 -10
- package/src/emit-compat.ts +6 -1
- package/src/emit-server-stream.ts +67 -3
- package/src/emit-server.ts +64 -12
- package/src/ir.ts +1 -0
- package/src/oxc-child-analysis.ts +63 -18
- package/src/oxc-component-detection.ts +145 -2
- package/src/oxc-component-props.ts +2 -1
- package/src/oxc-component-references.ts +2 -2
- package/src/oxc-runtime-emit.ts +12 -2
- package/src/oxc.ts +167 -5
- package/src/transform.ts +42 -10
|
@@ -348,10 +348,23 @@ function emitAppendStatements(node, sinkName, escapeHelperName, asyncBoundaryHel
|
|
|
348
348
|
if (whenTrue.length === 0 && whenFalse.length === 0) {
|
|
349
349
|
return [];
|
|
350
350
|
}
|
|
351
|
+
const conditionCode = node.conditionValueName ?? node.conditionCode;
|
|
352
|
+
let statements;
|
|
351
353
|
if (whenFalse.length === 0) {
|
|
352
|
-
|
|
354
|
+
statements = [` if (${conditionCode}) {`, ...whenTrue, ` }`];
|
|
353
355
|
}
|
|
354
|
-
|
|
356
|
+
else {
|
|
357
|
+
statements = [` if (${conditionCode}) {`, ...whenTrue, ` } else {`, ...whenFalse, ` }`];
|
|
358
|
+
}
|
|
359
|
+
if (node.conditionValueName === undefined) {
|
|
360
|
+
return statements;
|
|
361
|
+
}
|
|
362
|
+
return [
|
|
363
|
+
` {`,
|
|
364
|
+
` const ${node.conditionValueName} = (${node.conditionCode});`,
|
|
365
|
+
...statements.map((statement) => ` ${statement}`),
|
|
366
|
+
` }`,
|
|
367
|
+
];
|
|
355
368
|
}
|
|
356
369
|
const collectState = {
|
|
357
370
|
dynamicAttributes,
|
|
@@ -577,6 +590,9 @@ function tryEmitPartAsStringExpression(part, compatRenderToStringHelperName) {
|
|
|
577
590
|
}
|
|
578
591
|
return `${stringLiteral(`<!--mreact-h:start:${encodeURIComponent(part.hydrationId)}-->`)} + ${rendered} + ${stringLiteral(`<!--mreact-h:end:${encodeURIComponent(part.hydrationId)}-->`)}`;
|
|
579
592
|
}
|
|
593
|
+
if (part.kind === "component" && part.hydrationId === undefined) {
|
|
594
|
+
return `${part.name}(${emitPropsObject(part.props, part.children, part.escapeHelperName)})`;
|
|
595
|
+
}
|
|
580
596
|
// Non-compat component parts require `await sink-write`; lists with
|
|
581
597
|
// sink-needing children also can't collapse. Signal fallback.
|
|
582
598
|
return undefined;
|
|
@@ -672,10 +688,14 @@ function collectHtmlParts(node, escapeHelperName, asyncBoundaryHelperName, outOf
|
|
|
672
688
|
return [{ kind: "dynamic", code: node.code, escapeHelperName }];
|
|
673
689
|
}
|
|
674
690
|
if (node.kind === "conditional") {
|
|
691
|
+
const whenTrue = emitHtmlExpressionFromChildren(node.whenTrue, escapeHelperName);
|
|
692
|
+
const whenFalse = emitHtmlExpressionFromChildren(node.whenFalse, escapeHelperName);
|
|
675
693
|
return [
|
|
676
694
|
{
|
|
677
695
|
kind: "raw-dynamic",
|
|
678
|
-
code:
|
|
696
|
+
code: node.conditionValueName === undefined
|
|
697
|
+
? `((${node.conditionCode}) ? ${whenTrue} : ${whenFalse})`
|
|
698
|
+
: `(() => { const ${node.conditionValueName} = (${node.conditionCode}); return ${node.conditionValueName} ? ${whenTrue} : ${whenFalse}; })()`,
|
|
679
699
|
},
|
|
680
700
|
];
|
|
681
701
|
}
|
|
@@ -945,6 +965,14 @@ function collectHtmlAttributeParts(tagName, attr, escapeHelperName, escapeBatchH
|
|
|
945
965
|
}
|
|
946
966
|
function collectElementAttributeParts(tagName, attrs, escapeHelperName, state, attributeScan = scanElementAttributes(tagName, attrs)) {
|
|
947
967
|
const escapeBatchHelperName = state.escapeBatchHelperName;
|
|
968
|
+
if (state.dynamicAttributes === "emit" && attrs.some((attr) => attr.kind === "spread-attr")) {
|
|
969
|
+
return [
|
|
970
|
+
{
|
|
971
|
+
kind: "raw-dynamic",
|
|
972
|
+
code: emitMergedSpreadAttributeExpression(tagName, attrs, attributeScan),
|
|
973
|
+
},
|
|
974
|
+
];
|
|
975
|
+
}
|
|
948
976
|
return attrs.flatMap((attr) => attr.kind !== "spread-attr" &&
|
|
949
977
|
((tagName === "input" &&
|
|
950
978
|
((attr.name === "defaultValue" && attributeScan.hasExplicitInputValue) ||
|
|
@@ -954,6 +982,27 @@ function collectElementAttributeParts(tagName, attrs, escapeHelperName, state, a
|
|
|
954
982
|
? []
|
|
955
983
|
: collectHtmlAttributeParts(tagName, attr, escapeHelperName, escapeBatchHelperName, state.dynamicAttributes));
|
|
956
984
|
}
|
|
985
|
+
function emitMergedSpreadAttributeExpression(tagName, attrs, attributeScan) {
|
|
986
|
+
const statements = attrs.flatMap((attr) => {
|
|
987
|
+
if (attr.kind !== "spread-attr" &&
|
|
988
|
+
((tagName === "input" &&
|
|
989
|
+
((attr.name === "defaultValue" && attributeScan.hasExplicitInputValue) ||
|
|
990
|
+
(attr.name === "defaultChecked" && attributeScan.hasExplicitInputChecked))) ||
|
|
991
|
+
((tagName === "textarea" || tagName === "select") &&
|
|
992
|
+
(attr.name === "value" || attr.name === "defaultValue")))) {
|
|
993
|
+
return [];
|
|
994
|
+
}
|
|
995
|
+
if (attr.kind === "spread-attr") {
|
|
996
|
+
return [`Object.assign(_props, (${attr.code}) ?? {});`];
|
|
997
|
+
}
|
|
998
|
+
if (attr.kind === "event" || attr.name === "key" || attr.name === "dangerouslySetInnerHTML") {
|
|
999
|
+
return [];
|
|
1000
|
+
}
|
|
1001
|
+
const valueCode = attr.kind === "static-attr" ? stringLiteral(attr.value) : `(${attr.code})`;
|
|
1002
|
+
return [`_props[${stringLiteral(attr.name)}] = ${valueCode};`];
|
|
1003
|
+
});
|
|
1004
|
+
return `(() => { const _props = {}; ${statements.join(" ")} return ${currentSpreadAttributesHelperName}(${stringLiteral(tagName)}, _props); })()`;
|
|
1005
|
+
}
|
|
957
1006
|
function scanElementAttributes(tagName, attrs) {
|
|
958
1007
|
let hasExplicitInputValue = false;
|
|
959
1008
|
let hasExplicitInputChecked = false;
|