@braze/sanity-plugin-ai-translation 0.2.61 → 0.2.63

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.js CHANGED
@@ -1701,8 +1701,22 @@ const globalTransformRegistry = new TransformRegistry(), callGPT5 = async (apiKe
1701
1701
  continue;
1702
1702
  }
1703
1703
  const closeMatch = trimmed.match(/^<\/(field|block|span)>/);
1704
- if (closeMatch && stack.length > 0) {
1705
- matchedPatternCount++;
1704
+ if (closeMatch) {
1705
+ if (stack.length === 0) {
1706
+ devLog.warn("Closing tag found but stack is empty", {
1707
+ line: i,
1708
+ tagName: closeMatch[1],
1709
+ trimmed
1710
+ });
1711
+ continue;
1712
+ }
1713
+ matchedPatternCount++, devLog.debug("Matched closing tag", {
1714
+ line: i,
1715
+ tagName: closeMatch[1],
1716
+ trimmed,
1717
+ stackLength: stack.length,
1718
+ stackTopName: stack[stack.length - 1]?.name
1719
+ });
1706
1720
  const node = stack.pop();
1707
1721
  if (node)
1708
1722
  if (stack.length > 0) {
@@ -1753,14 +1767,41 @@ const globalTransformRegistry = new TransformRegistry(), callGPT5 = async (apiKe
1753
1767
  }
1754
1768
  continue;
1755
1769
  }
1770
+ if (trimmed.startsWith("</")) {
1771
+ const attemptedCloseMatch = trimmed.match(/^<\/(field|block|span)>/);
1772
+ attemptedCloseMatch ? stack.length === 0 && devLog.warn("Closing tag matched but stack is empty (unmatched closing tag)", {
1773
+ line: i,
1774
+ tagName: attemptedCloseMatch[1],
1775
+ trimmed
1776
+ }) : devLog.warn("Line starts with </ but did not match closing tag pattern", {
1777
+ line: i,
1778
+ trimmed,
1779
+ stackLength: stack.length,
1780
+ stackTopName: stack[stack.length - 1]?.name,
1781
+ stackTopType: stack[stack.length - 1]?.type
1782
+ });
1783
+ }
1756
1784
  processedLineCount <= 20 && devLog.debug("Line did not match any pattern", {
1757
1785
  line: i,
1758
1786
  trimmed,
1759
1787
  startsWithLessThan: trimmed.startsWith("<"),
1760
1788
  startsWithField: trimmed.startsWith("<field"),
1761
- startsWithBacktick: trimmed.startsWith("`")
1789
+ startsWithBacktick: trimmed.startsWith("`"),
1790
+ startsWithClosingTag: trimmed.startsWith("</")
1762
1791
  });
1763
1792
  }
1793
+ if (stack.length > 0)
1794
+ for (devLog.warn("Nodes remaining in stack after parsing complete", {
1795
+ stackLength: stack.length,
1796
+ remainingNodes: stack.map((n) => ({
1797
+ type: n.type,
1798
+ name: n.name,
1799
+ attributes: n.attributes
1800
+ }))
1801
+ }); stack.length > 0; ) {
1802
+ const node = stack.pop();
1803
+ node && root.push(node);
1804
+ }
1764
1805
  return devLog.debug("Parse complete", {
1765
1806
  totalLines: lines.length,
1766
1807
  processedLines: processedLineCount,
@@ -1808,8 +1849,28 @@ const globalTransformRegistry = new TransformRegistry(), callGPT5 = async (apiKe
1808
1849
  return;
1809
1850
  }
1810
1851
  if (node.attributes.type === "object") {
1811
- for (const child of node.children)
1812
- child.name && applyFieldChanges(doc, [...path, child.name], child);
1852
+ const currentValue = get(doc, path);
1853
+ if (currentValue && typeof currentValue == "object" && !Array.isArray(currentValue)) {
1854
+ const currentValueObj = currentValue;
1855
+ for (const child of node.children)
1856
+ if (child.name) {
1857
+ const childValue = currentValueObj[child.name];
1858
+ if (/^\d+$/.test(child.name) && childValue === void 0) {
1859
+ devLog.warn("Skipping numeric child name in object field - field does not exist (likely parsing error)", {
1860
+ path: path.join("."),
1861
+ childName: child.name,
1862
+ availableKeys: Object.keys(currentValueObj),
1863
+ childType: child.attributes.type
1864
+ });
1865
+ continue;
1866
+ }
1867
+ applyFieldChanges(doc, [...path, child.name], child);
1868
+ }
1869
+ } else
1870
+ devLog.warn("Object field type but value is not an object", {
1871
+ path: path.join("."),
1872
+ actualType: Array.isArray(currentValue) ? "array" : typeof currentValue
1873
+ });
1813
1874
  return;
1814
1875
  }
1815
1876
  if (node.children.some((c) => c.type === "block")) {