@oddo/lang 0.0.12 → 0.0.14

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/index.mjs CHANGED
@@ -3467,7 +3467,6 @@ function decodeHTMLEntities(text) {
3467
3467
  });
3468
3468
  }
3469
3469
  function convertJSXChildren(childrenCST) {
3470
- var _a;
3471
3470
  if (!childrenCST || childrenCST.length === 0) return [];
3472
3471
  const childrenWithOffsets = childrenCST.map((child) => {
3473
3472
  const firstOffset = getFirstTokenOffset(child);
@@ -3478,14 +3477,32 @@ function convertJSXChildren(childrenCST) {
3478
3477
  const result = [];
3479
3478
  for (let i = 0; i < childrenWithOffsets.length; i++) {
3480
3479
  const current = childrenWithOffsets[i];
3481
- const prevEnd = i > 0 ? childrenWithOffsets[i - 1].lastOffset + 1 : void 0;
3482
- const nextStart = (_a = childrenWithOffsets[i + 1]) == null ? void 0 : _a.firstOffset;
3483
- const converted = convertJSXChild(current.cst, prevEnd, nextStart);
3480
+ if (i > 0 && sourceText) {
3481
+ const prev = childrenWithOffsets[i - 1];
3482
+ const gapStart = prev.lastOffset + 1;
3483
+ const gapEnd = current.firstOffset;
3484
+ if (gapEnd > gapStart) {
3485
+ const gap = sourceText.slice(gapStart, gapEnd);
3486
+ if (gap.length > 0 && gap.trim() === "" && !gap.includes("\n")) {
3487
+ result.push({ type: "jsxText", value: " " });
3488
+ }
3489
+ }
3490
+ }
3491
+ const converted = convertJSXChild(current.cst);
3484
3492
  if (converted !== null) {
3485
3493
  result.push(converted);
3486
3494
  }
3487
3495
  }
3488
- return result;
3496
+ const merged = [];
3497
+ for (const child of result) {
3498
+ const prev = merged[merged.length - 1];
3499
+ if (child.type === "jsxText" && (prev == null ? void 0 : prev.type) === "jsxText") {
3500
+ prev.value += child.value;
3501
+ } else {
3502
+ merged.push(child);
3503
+ }
3504
+ }
3505
+ return merged;
3489
3506
  }
3490
3507
  function getLastTokenOffset(node) {
3491
3508
  if (!node) return void 0;
@@ -3513,7 +3530,7 @@ function getLastTokenOffset(node) {
3513
3530
  }
3514
3531
  return lastOffset;
3515
3532
  }
3516
- function convertJSXChild(cst, startBoundary, endBoundary) {
3533
+ function convertJSXChild(cst) {
3517
3534
  if (cst.children.jsxElement) {
3518
3535
  return convertJSXElement(getFirstChild(cst, "jsxElement"));
3519
3536
  }
@@ -3549,16 +3566,10 @@ function convertJSXChild(cst, startBoundary, endBoundary) {
3549
3566
  const firstToken = allTokens2[0];
3550
3567
  const lastToken = allTokens2[allTokens2.length - 1];
3551
3568
  const lastTokenEnd = lastToken.token.endOffset !== void 0 ? lastToken.token.endOffset : lastToken.token.startOffset + lastToken.token.image.length - 1;
3552
- if (sourceText && (startBoundary !== void 0 || endBoundary !== void 0)) {
3553
- const textStart = startBoundary ?? firstToken.offset;
3554
- const textEnd = endBoundary ?? lastTokenEnd + 1;
3555
- const textValue2 = sourceText.slice(textStart, textEnd);
3569
+ if (sourceText) {
3570
+ const textValue2 = sourceText.slice(firstToken.offset, lastTokenEnd + 1);
3556
3571
  if (textValue2) {
3557
- const decodedValue2 = decodeHTMLEntities(textValue2);
3558
- return {
3559
- type: "jsxText",
3560
- value: decodedValue2
3561
- };
3572
+ return { type: "jsxText", value: decodeHTMLEntities(textValue2) };
3562
3573
  }
3563
3574
  return null;
3564
3575
  }
@@ -4559,7 +4570,7 @@ function convertExpressionStatement2(stmt) {
4559
4570
  if (stmt.expression) {
4560
4571
  const isPlainExpr = stmt.expression.type !== "variableDeclaration" && stmt.expression.type !== "assignment" && stmt.expression.type !== "arraySliceAssignment";
4561
4572
  if (isPlainExpr) {
4562
- const allIdentifiers = collectOddoIdentifiersOnly(stmt.expression);
4573
+ const allIdentifiers = collectOddoIdentifiersOnly(stmt.expression, /* @__PURE__ */ new Set(), false, true);
4563
4574
  const reactiveDeps = allIdentifiers.filter((id) => isReactive(id));
4564
4575
  if (reactiveDeps.length > 0) {
4565
4576
  const savedScope = currentScope;
@@ -4832,20 +4843,23 @@ function convertReactiveContainer(expr) {
4832
4843
  currentScope = savedScope;
4833
4844
  return t.functionExpression(null, params, body);
4834
4845
  }
4835
- function collectOddoIdentifiersOnly(node, names = /* @__PURE__ */ new Set(), stopAtJsxExpressions = false) {
4846
+ function collectOddoIdentifiersOnly(node, names = /* @__PURE__ */ new Set(), stopAtJsxExpressions = false, stopAtArrowFunctions = false) {
4836
4847
  if (!node || typeof node !== "object") return Array.from(names);
4837
4848
  if (stopAtJsxExpressions && node.type === "jsxExpression") {
4838
4849
  return Array.from(names);
4839
4850
  }
4851
+ if (stopAtArrowFunctions && node.type === "arrowFunction") {
4852
+ return Array.from(names);
4853
+ }
4840
4854
  if (node.type === "identifier") {
4841
4855
  names.add(node.name);
4842
4856
  }
4843
4857
  if (node.type === "property") {
4844
4858
  if (node.computed && node.key) {
4845
- collectOddoIdentifiersOnly(node.key, names, stopAtJsxExpressions);
4859
+ collectOddoIdentifiersOnly(node.key, names, stopAtJsxExpressions, stopAtArrowFunctions);
4846
4860
  }
4847
4861
  if (node.value) {
4848
- collectOddoIdentifiersOnly(node.value, names, stopAtJsxExpressions);
4862
+ collectOddoIdentifiersOnly(node.value, names, stopAtJsxExpressions, stopAtArrowFunctions);
4849
4863
  }
4850
4864
  return Array.from(names);
4851
4865
  }
@@ -4853,9 +4867,9 @@ function collectOddoIdentifiersOnly(node, names = /* @__PURE__ */ new Set(), sto
4853
4867
  if (key === "type") continue;
4854
4868
  const val = node[key];
4855
4869
  if (Array.isArray(val)) {
4856
- val.forEach((item) => collectOddoIdentifiersOnly(item, names, stopAtJsxExpressions));
4870
+ val.forEach((item) => collectOddoIdentifiersOnly(item, names, stopAtJsxExpressions, stopAtArrowFunctions));
4857
4871
  } else if (val && typeof val === "object") {
4858
- collectOddoIdentifiersOnly(val, names, stopAtJsxExpressions);
4872
+ collectOddoIdentifiersOnly(val, names, stopAtJsxExpressions, stopAtArrowFunctions);
4859
4873
  }
4860
4874
  }
4861
4875
  return Array.from(names);