@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.
Files changed (50) hide show
  1. package/dist/diagnostics.d.ts +1 -0
  2. package/dist/diagnostics.d.ts.map +1 -1
  3. package/dist/diagnostics.js +8 -0
  4. package/dist/diagnostics.js.map +1 -1
  5. package/dist/emit-client.js +14 -9
  6. package/dist/emit-client.js.map +1 -1
  7. package/dist/emit-compat.js +5 -1
  8. package/dist/emit-compat.js.map +1 -1
  9. package/dist/emit-server-stream.js +52 -3
  10. package/dist/emit-server-stream.js.map +1 -1
  11. package/dist/emit-server.js +51 -10
  12. package/dist/emit-server.js.map +1 -1
  13. package/dist/ir.d.ts +1 -0
  14. package/dist/ir.d.ts.map +1 -1
  15. package/dist/ir.js.map +1 -1
  16. package/dist/oxc-child-analysis.d.ts.map +1 -1
  17. package/dist/oxc-child-analysis.js +41 -7
  18. package/dist/oxc-child-analysis.js.map +1 -1
  19. package/dist/oxc-component-detection.d.ts +5 -2
  20. package/dist/oxc-component-detection.d.ts.map +1 -1
  21. package/dist/oxc-component-detection.js +80 -3
  22. package/dist/oxc-component-detection.js.map +1 -1
  23. package/dist/oxc-component-props.d.ts +1 -1
  24. package/dist/oxc-component-props.d.ts.map +1 -1
  25. package/dist/oxc-component-props.js +1 -1
  26. package/dist/oxc-component-props.js.map +1 -1
  27. package/dist/oxc-component-references.js +2 -2
  28. package/dist/oxc-component-references.js.map +1 -1
  29. package/dist/oxc-runtime-emit.d.ts.map +1 -1
  30. package/dist/oxc-runtime-emit.js +10 -2
  31. package/dist/oxc-runtime-emit.js.map +1 -1
  32. package/dist/oxc.d.ts.map +1 -1
  33. package/dist/oxc.js +109 -20
  34. package/dist/oxc.js.map +1 -1
  35. package/dist/transform.js +29 -11
  36. package/dist/transform.js.map +1 -1
  37. package/package.json +2 -2
  38. package/src/diagnostics.ts +10 -0
  39. package/src/emit-client.ts +20 -10
  40. package/src/emit-compat.ts +6 -1
  41. package/src/emit-server-stream.ts +67 -3
  42. package/src/emit-server.ts +64 -12
  43. package/src/ir.ts +1 -0
  44. package/src/oxc-child-analysis.ts +63 -18
  45. package/src/oxc-component-detection.ts +145 -2
  46. package/src/oxc-component-props.ts +2 -1
  47. package/src/oxc-component-references.ts +2 -2
  48. package/src/oxc-runtime-emit.ts +12 -2
  49. package/src/oxc.ts +167 -5
  50. package/src/transform.ts +42 -10
@@ -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
- return [
199
- `if (${node.conditionCode}) {`,
200
+ statements = [
201
+ `if (${conditionCode}) {`,
200
202
  ...whenTrueStatements.map((statement) => ` ${statement}`),
201
203
  `}`,
202
204
  ];
203
205
  }
204
- if (whenTrueStatements.length === 0) {
205
- return [
206
- `if (!(${node.conditionCode})) {`,
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
- `if (${node.conditionCode}) {`,
213
- ...whenTrueStatements.map((statement) => ` ${statement}`),
214
- `} else {`,
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
- `((${node.conditionCode}) ? ${emitHtmlExpressionFromChildren(node.whenTrue, escapeHelperName, escapeBatchHelperName, asyncComponentNames, dynamicAttributes, contextProviderHelperName, contextConsumerHelperName, reactNodeRenderHelperName)} : ${emitHtmlExpressionFromChildren(node.whenFalse, escapeHelperName, escapeBatchHelperName, asyncComponentNames, dynamicAttributes, contextProviderHelperName, contextConsumerHelperName, reactNodeRenderHelperName)})`,
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;