@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
package/dist/emit-server.js
CHANGED
|
@@ -189,30 +189,43 @@ function collectHtmlStatements(node, outVar, escapeHelperName, escapeBatchHelper
|
|
|
189
189
|
return [`${outVar} += ${escapeHelperName}(${node.code});`];
|
|
190
190
|
}
|
|
191
191
|
if (node.kind === "conditional") {
|
|
192
|
+
const conditionCode = node.conditionValueName ?? node.conditionCode;
|
|
192
193
|
const whenTrueStatements = node.whenTrue.flatMap((child) => collectHtmlStatements(child, outVar, escapeHelperName, escapeBatchHelperName, asyncComponentNames, dynamicAttributes, contextProviderHelperName, contextConsumerHelperName, reactNodeRenderHelperName));
|
|
193
194
|
const whenFalseStatements = node.whenFalse.flatMap((child) => collectHtmlStatements(child, outVar, escapeHelperName, escapeBatchHelperName, asyncComponentNames, dynamicAttributes, contextProviderHelperName, contextConsumerHelperName, reactNodeRenderHelperName));
|
|
194
195
|
if (whenTrueStatements.length === 0 && whenFalseStatements.length === 0) {
|
|
195
196
|
return [];
|
|
196
197
|
}
|
|
198
|
+
let statements;
|
|
197
199
|
if (whenFalseStatements.length === 0) {
|
|
198
|
-
|
|
199
|
-
`if (${
|
|
200
|
+
statements = [
|
|
201
|
+
`if (${conditionCode}) {`,
|
|
200
202
|
...whenTrueStatements.map((statement) => ` ${statement}`),
|
|
201
203
|
`}`,
|
|
202
204
|
];
|
|
203
205
|
}
|
|
204
|
-
if (whenTrueStatements.length === 0) {
|
|
205
|
-
|
|
206
|
-
`if (!(${
|
|
206
|
+
else if (whenTrueStatements.length === 0) {
|
|
207
|
+
statements = [
|
|
208
|
+
`if (!(${conditionCode})) {`,
|
|
207
209
|
...whenFalseStatements.map((statement) => ` ${statement}`),
|
|
208
210
|
`}`,
|
|
209
211
|
];
|
|
210
212
|
}
|
|
213
|
+
else {
|
|
214
|
+
statements = [
|
|
215
|
+
`if (${conditionCode}) {`,
|
|
216
|
+
...whenTrueStatements.map((statement) => ` ${statement}`),
|
|
217
|
+
`} else {`,
|
|
218
|
+
...whenFalseStatements.map((statement) => ` ${statement}`),
|
|
219
|
+
`}`,
|
|
220
|
+
];
|
|
221
|
+
}
|
|
222
|
+
if (node.conditionValueName === undefined) {
|
|
223
|
+
return statements;
|
|
224
|
+
}
|
|
211
225
|
return [
|
|
212
|
-
`
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
...whenFalseStatements.map((statement) => ` ${statement}`),
|
|
226
|
+
`{`,
|
|
227
|
+
` const ${node.conditionValueName} = (${node.conditionCode});`,
|
|
228
|
+
...statements.map((statement) => ` ${statement}`),
|
|
216
229
|
`}`,
|
|
217
230
|
];
|
|
218
231
|
}
|
|
@@ -356,8 +369,12 @@ function collectHtmlParts(node, escapeHelperName, escapeBatchHelperName, asyncCo
|
|
|
356
369
|
return [`${escapeHelperName}(${node.code})`];
|
|
357
370
|
}
|
|
358
371
|
if (node.kind === "conditional") {
|
|
372
|
+
const whenTrue = emitHtmlExpressionFromChildren(node.whenTrue, escapeHelperName, escapeBatchHelperName, asyncComponentNames, dynamicAttributes, contextProviderHelperName, contextConsumerHelperName, reactNodeRenderHelperName);
|
|
373
|
+
const whenFalse = emitHtmlExpressionFromChildren(node.whenFalse, escapeHelperName, escapeBatchHelperName, asyncComponentNames, dynamicAttributes, contextProviderHelperName, contextConsumerHelperName, reactNodeRenderHelperName);
|
|
359
374
|
return [
|
|
360
|
-
|
|
375
|
+
node.conditionValueName === undefined
|
|
376
|
+
? `((${node.conditionCode}) ? ${whenTrue} : ${whenFalse})`
|
|
377
|
+
: `(() => { const ${node.conditionValueName} = (${node.conditionCode}); return ${node.conditionValueName} ? ${whenTrue} : ${whenFalse}; })()`,
|
|
361
378
|
];
|
|
362
379
|
}
|
|
363
380
|
if (node.kind === "list") {
|
|
@@ -505,6 +522,9 @@ function collectHtmlAttributeParts(tagName, attr, escapeHelperName, escapeBatchH
|
|
|
505
522
|
return [emitDynamicAttributeExpression(htmlName, attr.code, escapeHelperName)];
|
|
506
523
|
}
|
|
507
524
|
function collectElementAttributeParts(tagName, attrs, escapeHelperName, escapeBatchHelperName, dynamicAttributes, attributeScan = scanElementAttributes(tagName, attrs)) {
|
|
525
|
+
if (dynamicAttributes === "emit" && attrs.some((attr) => attr.kind === "spread-attr")) {
|
|
526
|
+
return [emitMergedSpreadAttributeExpression(tagName, attrs, attributeScan)];
|
|
527
|
+
}
|
|
508
528
|
return attrs.flatMap((attr) => attr.kind !== "spread-attr" &&
|
|
509
529
|
((tagName === "input" &&
|
|
510
530
|
((attr.name === "defaultValue" && attributeScan.hasExplicitInputValue) ||
|
|
@@ -514,6 +534,27 @@ function collectElementAttributeParts(tagName, attrs, escapeHelperName, escapeBa
|
|
|
514
534
|
? []
|
|
515
535
|
: collectHtmlAttributeParts(tagName, attr, escapeHelperName, escapeBatchHelperName, dynamicAttributes));
|
|
516
536
|
}
|
|
537
|
+
function emitMergedSpreadAttributeExpression(tagName, attrs, attributeScan) {
|
|
538
|
+
const statements = attrs.flatMap((attr) => {
|
|
539
|
+
if (attr.kind !== "spread-attr" &&
|
|
540
|
+
((tagName === "input" &&
|
|
541
|
+
((attr.name === "defaultValue" && attributeScan.hasExplicitInputValue) ||
|
|
542
|
+
(attr.name === "defaultChecked" && attributeScan.hasExplicitInputChecked))) ||
|
|
543
|
+
((tagName === "textarea" || tagName === "select") &&
|
|
544
|
+
(attr.name === "value" || attr.name === "defaultValue")))) {
|
|
545
|
+
return [];
|
|
546
|
+
}
|
|
547
|
+
if (attr.kind === "spread-attr") {
|
|
548
|
+
return [`Object.assign(_props, (${attr.code}) ?? {});`];
|
|
549
|
+
}
|
|
550
|
+
if (attr.kind === "event" || attr.name === "key" || attr.name === "dangerouslySetInnerHTML") {
|
|
551
|
+
return [];
|
|
552
|
+
}
|
|
553
|
+
const valueCode = attr.kind === "static-attr" ? stringLiteral(attr.value) : `(${attr.code})`;
|
|
554
|
+
return [`_props[${stringLiteral(attr.name)}] = ${valueCode};`];
|
|
555
|
+
});
|
|
556
|
+
return `(() => { const _props = {}; ${statements.join(" ")} return ${currentSpreadAttributesHelperName}(${stringLiteral(tagName)}, _props); })()`;
|
|
557
|
+
}
|
|
517
558
|
function scanElementAttributes(tagName, attrs) {
|
|
518
559
|
let hasExplicitInputValue = false;
|
|
519
560
|
let hasExplicitInputChecked = false;
|