@oddo/lang 0.0.13 → 0.0.15

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
@@ -3004,7 +3004,9 @@ function convertTemplateLiteralFromToken(token) {
3004
3004
  if (braceDepth === 0) {
3005
3005
  const exprText = text.substring(exprStart, pos);
3006
3006
  try {
3007
+ const savedSourceText = sourceText;
3007
3008
  const exprAST = parseOddoExpression(exprText);
3009
+ sourceText = savedSourceText;
3008
3010
  expressions.push(exprAST);
3009
3011
  } catch (e) {
3010
3012
  expressions.push({
@@ -3467,7 +3469,6 @@ function decodeHTMLEntities(text) {
3467
3469
  });
3468
3470
  }
3469
3471
  function convertJSXChildren(childrenCST) {
3470
- var _a;
3471
3472
  if (!childrenCST || childrenCST.length === 0) return [];
3472
3473
  const childrenWithOffsets = childrenCST.map((child) => {
3473
3474
  const firstOffset = getFirstTokenOffset(child);
@@ -3478,14 +3479,32 @@ function convertJSXChildren(childrenCST) {
3478
3479
  const result = [];
3479
3480
  for (let i = 0; i < childrenWithOffsets.length; i++) {
3480
3481
  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);
3482
+ if (i > 0 && sourceText) {
3483
+ const prev = childrenWithOffsets[i - 1];
3484
+ const gapStart = prev.lastOffset + 1;
3485
+ const gapEnd = current.firstOffset;
3486
+ if (gapEnd > gapStart) {
3487
+ const gap = sourceText.slice(gapStart, gapEnd);
3488
+ if (gap.length > 0 && gap.trim() === "" && !gap.includes("\n")) {
3489
+ result.push({ type: "jsxText", value: " " });
3490
+ }
3491
+ }
3492
+ }
3493
+ const converted = convertJSXChild(current.cst);
3484
3494
  if (converted !== null) {
3485
3495
  result.push(converted);
3486
3496
  }
3487
3497
  }
3488
- return result;
3498
+ const merged = [];
3499
+ for (const child of result) {
3500
+ const prev = merged[merged.length - 1];
3501
+ if (child.type === "jsxText" && (prev == null ? void 0 : prev.type) === "jsxText") {
3502
+ prev.value += child.value;
3503
+ } else {
3504
+ merged.push(child);
3505
+ }
3506
+ }
3507
+ return merged;
3489
3508
  }
3490
3509
  function getLastTokenOffset(node) {
3491
3510
  if (!node) return void 0;
@@ -3513,7 +3532,7 @@ function getLastTokenOffset(node) {
3513
3532
  }
3514
3533
  return lastOffset;
3515
3534
  }
3516
- function convertJSXChild(cst, startBoundary, endBoundary) {
3535
+ function convertJSXChild(cst) {
3517
3536
  if (cst.children.jsxElement) {
3518
3537
  return convertJSXElement(getFirstChild(cst, "jsxElement"));
3519
3538
  }
@@ -3549,16 +3568,10 @@ function convertJSXChild(cst, startBoundary, endBoundary) {
3549
3568
  const firstToken = allTokens2[0];
3550
3569
  const lastToken = allTokens2[allTokens2.length - 1];
3551
3570
  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);
3571
+ if (sourceText) {
3572
+ const textValue2 = sourceText.slice(firstToken.offset, lastTokenEnd + 1);
3556
3573
  if (textValue2) {
3557
- const decodedValue2 = decodeHTMLEntities(textValue2);
3558
- return {
3559
- type: "jsxText",
3560
- value: decodedValue2
3561
- };
3574
+ return { type: "jsxText", value: decodeHTMLEntities(textValue2) };
3562
3575
  }
3563
3576
  return null;
3564
3577
  }