oxfmt 0.49.0 → 0.50.0

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 (38) hide show
  1. package/configuration_schema.json +2 -2
  2. package/dist/{acorn-ay2Aj6GQ.js → acorn-sBRpswSh.js} +1 -1
  3. package/dist/{angular-z1ZEe5V_.js → angular-DtI-eDW8.js} +1 -1
  4. package/dist/{apis-By1xj7IP.js → apis-CKvPKBJI.js} +42 -7
  5. package/dist/{babel-Cs312VeV.js → babel-DaNjvh9L.js} +1 -1
  6. package/dist/{bindings-Cdg_nxGV.js → bindings-Dj_YoR0Z.js} +26 -26
  7. package/dist/cli-worker.js +1 -1
  8. package/dist/cli.js +5 -5
  9. package/dist/{dist-Bbs0xV9H.js → dist-D_YbN99t.js} +14 -17
  10. package/dist/{estree-DZBnPYMx.js → estree-CzfNsl8m.js} +1 -1
  11. package/dist/{flow-ChhAFZSt.js → flow-c9AjoQam.js} +1 -1
  12. package/dist/{glimmer-Cg8KQipT.js → glimmer-D_zkI0w_.js} +1 -1
  13. package/dist/{graphql-DsP-ifm0.js → graphql-BFXkB4Nq.js} +1 -1
  14. package/dist/{html-7pWx9LND.js → html-DkcPxRXg.js} +1 -1
  15. package/dist/index.d.ts +1 -1
  16. package/dist/index.js +2 -2
  17. package/dist/{init-BbKOMZ57.js → init-C3nxU_Wc.js} +1 -1
  18. package/dist/{jiti-Bb1dT6Cw-DezGRPD7.js → jiti-Bb1dT6Cw-C0N20Za1.js} +2 -2
  19. package/dist/{markdown-CCrs3bBt.js → markdown-DVLNmbQg.js} +1 -1
  20. package/dist/{meriyah-TC7VDz8E.js → meriyah-BGPf00Rn.js} +1 -1
  21. package/dist/{migrate-biome-BMqs7-eg.js → migrate-biome-DclTzwKW.js} +1 -1
  22. package/dist/{migrate-prettier-Bze9N_6F.js → migrate-prettier-DLfviW85.js} +2 -2
  23. package/dist/{plugin-CwlqDRt_.js → plugin-DOdiccQR.js} +72 -28
  24. package/dist/{postcss-ZbUej7DN.js → postcss-D-ql-dm8.js} +1 -1
  25. package/dist/{prettier-s1WPCGVk.js → prettier-Cw36juP9.js} +15 -15
  26. package/dist/{prettier-plugin-oxfmt-BjdgYnLg.js → prettier-plugin-oxfmt-BlJcmKAv.js} +37 -3
  27. package/dist/{resolve-pWjAK-4f-BnquIxPb.js → sorter-BZkvDMjt-DpGe0QK9.js} +325 -4
  28. package/dist/{sorter-l2HyESZg.js → sorter-w0dgpoFw.js} +1 -2
  29. package/dist/{typescript-Cgpjcksz.js → typescript-C_eN_ThF.js} +1 -1
  30. package/dist/{v3-D-mr2VVh-Bw8A9MXh.js → v3-D-mr2VVh-CU7hQIit.js} +3 -4
  31. package/dist/{v4-C-HWEQJm-B81QD_Ac.js → v4-C-HWEQJm-C8EWwksG.js} +3 -4
  32. package/dist/{yaml-DLZBHI7f.js → yaml-Bqxyk-13.js} +1 -1
  33. package/package.json +20 -20
  34. package/dist/chunk-DSjvVL_1-B3jw0SMn.js +0 -36
  35. package/dist/chunk-HkwdBwDg.js +0 -37
  36. package/dist/sorter-BZkvDMjt-y2u_e1ZW.js +0 -212
  37. package/dist/utils-D8dQkKEd-Dgy5UIHl.js +0 -81
  38. /package/dist/{shared-BTEY2VsW.js → shared-BtJbjkue.js} +0 -0
@@ -1,7 +1,7 @@
1
- import { a as __toCommonJS, i as __require, t as __commonJSMin } from "./chunk-HkwdBwDg.js";
2
- import { n as init_babel, t as babel_exports } from "./babel-Cs312VeV.js";
3
- import { n as prettier_exports, t as init_prettier } from "./prettier-s1WPCGVk.js";
4
- //#region ../../node_modules/.pnpm/prettier-plugin-svelte@3.5.1_prettier@3.8.3_svelte@5.55.5_@typescript-eslint+types@8.59.2_/node_modules/prettier-plugin-svelte/plugin.js
1
+ import { l as __require, o as __commonJSMin, u as __toCommonJS } from "./apis-CKvPKBJI.js";
2
+ import { n as init_babel, t as babel_exports } from "./babel-DaNjvh9L.js";
3
+ import { n as prettier_exports, t as init_prettier } from "./prettier-Cw36juP9.js";
4
+ //#region ../../node_modules/.pnpm/prettier-plugin-svelte@3.5.2_prettier@3.8.3_svelte@5.55.5_@typescript-eslint+types@8.59.2_/node_modules/prettier-plugin-svelte/plugin.js
5
5
  var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  var prettierPluginBabel = (init_babel(), __toCommonJS(babel_exports));
@@ -386,9 +386,35 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
386
386
  }
387
387
  /**
388
388
  * `(foo = bar)` => `foo = bar`
389
+ * Also handles leading comments and line breaks before "(".
389
390
  */
390
391
  function removeParentheses(doc) {
391
- return trim([doc], (_doc) => _doc === "(" || _doc === ")")[0];
392
+ if (!Array.isArray(doc)) return trim([doc], (_doc) => _doc === "(" || _doc === ")")[0];
393
+ const transformed = [];
394
+ let i = 0;
395
+ let opened = false;
396
+ for (; i < doc.length; i++) {
397
+ const part = doc[i];
398
+ if (typeof part === "string" && part.startsWith("//")) transformed.push(part);
399
+ else if (typeof part === "string" && part.startsWith("/*")) {
400
+ transformed.push(part);
401
+ opened = true;
402
+ } else if (opened) {
403
+ transformed.push(part);
404
+ opened = typeof part !== "string" || !part.trim().endsWith("*/");
405
+ } else if (transformed.length > 0 && isLine(part)) {
406
+ transformed.push(part);
407
+ i++;
408
+ const next = doc[i];
409
+ if (typeof next !== "string" && !Array.isArray(next) && next.type === "break-parent") {
410
+ transformed.push(next);
411
+ i++;
412
+ }
413
+ break;
414
+ } else break;
415
+ }
416
+ transformed.push(...trim(doc.slice(i), (_doc) => _doc === "(" || _doc === ")"));
417
+ return transformed;
392
418
  }
393
419
  const unsupportedLanguages = [
394
420
  "coffee",
@@ -397,6 +423,18 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
397
423
  "stylus",
398
424
  "sass"
399
425
  ];
426
+ /**
427
+ * Characters treated as interchangeable/collapsible HTML whitespace for layout.
428
+ * Excludes NBSP (U+00A0) and other Unicode separators — see prettier/prettier#5796.
429
+ */
430
+ const ONLY_HTML_COLLAPSE_WHITESPACE_RE = /^[\t\n\f\r ]*$/;
431
+ const STARTS_WITH_HTML_COLLAPSE_WHITESPACE_RE = /^[\t\n\f\r ]/;
432
+ const ENDS_WITH_HTML_COLLAPSE_WHITESPACE_RE = /[\t\n\f\r ]$/;
433
+ const LEADING_HTML_COLLAPSE_WHITESPACE_RE = /^[\t\n\f\r ]+/;
434
+ const TRAILING_HTML_COLLAPSE_WHITESPACE_RE = /[\t\n\f\r ]+$/;
435
+ function isOnlyHtmlCollapseWhitespace(text) {
436
+ return ONLY_HTML_COLLAPSE_WHITESPACE_RE.test(text);
437
+ }
400
438
  function isInlineElement(path, options, node) {
401
439
  return node && node.type === "Element" && !isBlockElement(node, options) && !isPreTagContent(path);
402
440
  }
@@ -472,7 +510,7 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
472
510
  return !!root.html && !!root.html.children && root.html.children.includes(node);
473
511
  }
474
512
  function isEmptyTextNode(node) {
475
- return !!node && node.type === "Text" && getUnencodedText(node).trim() === "";
513
+ return !!node && node.type === "Text" && isOnlyHtmlCollapseWhitespace(getUnencodedText(node));
476
514
  }
477
515
  function isIgnoreDirective(node) {
478
516
  return !!node && node.type === "Comment" && node.data.trim() === "prettier-ignore";
@@ -584,18 +622,18 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
584
622
  return new RegExp(`(\\n[\\t\\f\\r ]*){${nrLines}}$`).test(text);
585
623
  }
586
624
  function isTextNodeStartingWithWhitespace(node) {
587
- return node.type === "Text" && /^\s/.test(getUnencodedText(node));
625
+ return node.type === "Text" && STARTS_WITH_HTML_COLLAPSE_WHITESPACE_RE.test(getUnencodedText(node));
588
626
  }
589
627
  function isTextNodeEndingWithWhitespace(node) {
590
- return node.type === "Text" && /\s$/.test(getUnencodedText(node));
628
+ return node.type === "Text" && ENDS_WITH_HTML_COLLAPSE_WHITESPACE_RE.test(getUnencodedText(node));
591
629
  }
592
630
  function trimTextNodeRight(node) {
593
- node.raw = node.raw && node.raw.trimRight();
594
- node.data = node.data && node.data.trimRight();
631
+ node.raw = node.raw && node.raw.replace(TRAILING_HTML_COLLAPSE_WHITESPACE_RE, "");
632
+ node.data = node.data && node.data.replace(TRAILING_HTML_COLLAPSE_WHITESPACE_RE, "");
595
633
  }
596
634
  function trimTextNodeLeft(node) {
597
- node.raw = node.raw && node.raw.trimLeft();
598
- node.data = node.data && node.data.trimLeft();
635
+ node.raw = node.raw && node.raw.replace(LEADING_HTML_COLLAPSE_WHITESPACE_RE, "");
636
+ node.data = node.data && node.data.replace(LEADING_HTML_COLLAPSE_WHITESPACE_RE, "");
599
637
  }
600
638
  /**
601
639
  * Remove all leading whitespace up until the first non-empty text node,
@@ -660,7 +698,7 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
660
698
  const parentOpeningEnd = options.originalText.lastIndexOf("}", firstChild.start);
661
699
  if (parentOpeningEnd > 0 && firstChild.start > parentOpeningEnd + 1) {
662
700
  const textBetween = options.originalText.substring(parentOpeningEnd + 1, firstChild.start);
663
- if (textBetween.trim() === "") return startsWithLinebreak(textBetween) ? "line" : "space";
701
+ if (ONLY_HTML_COLLAPSE_WHITESPACE_RE.test(textBetween)) return startsWithLinebreak(textBetween) ? "line" : "space";
664
702
  }
665
703
  return "none";
666
704
  }
@@ -677,7 +715,7 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
677
715
  const parentClosingStart = options.originalText.indexOf("{", lastChild.end);
678
716
  if (parentClosingStart > 0 && lastChild.end < parentClosingStart) {
679
717
  const textBetween = options.originalText.substring(lastChild.end, parentClosingStart);
680
- if (textBetween.trim() === "") return endsWithLinebreak(textBetween) ? "line" : "space";
718
+ if (ONLY_HTML_COLLAPSE_WHITESPACE_RE.test(textBetween)) return endsWithLinebreak(textBetween) ? "line" : "space";
681
719
  }
682
720
  return "none";
683
721
  }
@@ -696,7 +734,7 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
696
734
  */
697
735
  function hugsStartOfNextNode(node, options) {
698
736
  if (node.end === options.originalText.length) return false;
699
- return !options.originalText.substring(node.end).match(/^\s/);
737
+ return !STARTS_WITH_HTML_COLLAPSE_WHITESPACE_RE.test(options.originalText.substring(node.end));
700
738
  }
701
739
  function isLastChildWithinParentBlockElement(path, options) {
702
740
  const parent = path.getParentNode();
@@ -772,15 +810,16 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
772
810
  if (children.length === 0 || children.every(isEmptyTextNode)) return "";
773
811
  if (!isPreTagContent(path)) {
774
812
  trimChildren(node.children, path);
775
- const output = trim([printChildren(path, print, options)], (n) => isLine(n) || typeof n === "string" && n.trim() === "" || n === breakParent);
813
+ const output = trim([printChildren(path, print, options)], (n) => isLine(n) || typeof n === "string" && isOnlyHtmlCollapseWhitespace(n) || n === breakParent);
776
814
  if (output.every((doc) => isEmptyDoc(doc))) return "";
777
815
  return group([...output, hardline]);
778
816
  } else return group(path.map(print, "children"));
779
817
  case "Text": if (!isPreTagContent(path)) {
780
818
  if (isEmptyTextNode(node)) {
781
- const hasWhiteSpace = getUnencodedText(node).trim().length < getUnencodedText(node).length;
782
- const hasOneOrMoreNewlines = /\n/.test(getUnencodedText(node));
783
- if (/\n\r?\s*\n\r?/.test(getUnencodedText(node))) return [hardline, hardline];
819
+ const text = getUnencodedText(node);
820
+ const hasWhiteSpace = text.length > 0;
821
+ const hasOneOrMoreNewlines = /\n/.test(text);
822
+ if (/\n\r?[\t\n\f\r ]*\n\r?/.test(text)) return [hardline, hardline];
784
823
  if (hasOneOrMoreNewlines) return hardline;
785
824
  if (hasWhiteSpace) return line;
786
825
  return "";
@@ -1438,24 +1477,29 @@ var require_plugin = /* @__PURE__ */ __commonJSMin(((exports) => {
1438
1477
  return path.call(print, name);
1439
1478
  }
1440
1479
  function expandNode(node, original) {
1441
- let str = _expandNode(node);
1480
+ let str = _expandNode(node, original);
1442
1481
  if (node === null || node === void 0 ? void 0 : node.typeAnnotation) str += ": " + original.slice(node.typeAnnotation.typeAnnotation.start, node.typeAnnotation.typeAnnotation.end);
1443
1482
  return str;
1444
1483
  }
1445
- function _expandNode(node, parent) {
1484
+ function _expandNode(node, original, parent) {
1485
+ var _a, _b;
1446
1486
  if (node === null) return "";
1447
1487
  if (typeof node === "string") return " " + node;
1448
1488
  switch (node.type) {
1449
1489
  case "ArrayExpression":
1450
- case "ArrayPattern": return " [" + node.elements.map((el) => el === null ? " " : _expandNode(el)).join(",").slice(1) + "]";
1451
- case "AssignmentPattern": return _expandNode(node.left) + " =" + _expandNode(node.right);
1490
+ case "ArrayPattern": return " [" + node.elements.map((el) => el === null ? " " : _expandNode(el, original)).join(",").slice(1) + "]";
1491
+ case "AssignmentPattern": return _expandNode(node.left, original) + " =" + _expandNode(node.right, original);
1452
1492
  case "Identifier": return " " + node.name;
1453
1493
  case "Literal": return " " + node.raw;
1454
- case "ObjectExpression": return " {" + node.properties.map((p) => _expandNode(p, node)).join(",") + " }";
1455
- case "ObjectPattern": return " {" + node.properties.map(_expandNode).join(",") + " }";
1456
- case "Property": if (node.value.type === "ObjectPattern" || node.value.type === "ArrayPattern") return " " + node.key.name + ":" + _expandNode(node.value);
1457
- else if (node.value.type === "Identifier" && node.key.name !== node.value.name || parent && parent.type === "ObjectExpression") return _expandNode(node.key) + ":" + _expandNode(node.value);
1458
- else return _expandNode(node.value);
1494
+ case "ObjectExpression": return " {" + node.properties.map((p) => _expandNode(p, original, node)).join(",") + " }";
1495
+ case "ObjectPattern": return " {" + node.properties.map((p) => _expandNode(p, original)).join(",") + " }";
1496
+ case "Property": {
1497
+ let computedKeyInner = "";
1498
+ if (node.computed) computedKeyInner = typeof ((_a = node.key) === null || _a === void 0 ? void 0 : _a.start) === "number" && typeof ((_b = node.key) === null || _b === void 0 ? void 0 : _b.end) === "number" ? original.slice(node.key.start, node.key.end) : _expandNode(node.key, original).trim();
1499
+ if (node.value.type === "ObjectPattern" || node.value.type === "ArrayPattern") return (node.computed ? " [" + computedKeyInner + "]" : " " + node.key.name) + ":" + _expandNode(node.value, original);
1500
+ else if (node.value.type === "Identifier" && node.key.name !== node.value.name || parent && parent.type === "ObjectExpression") return (node.computed ? " [" + computedKeyInner + "]" : _expandNode(node.key, original)) + ":" + _expandNode(node.value, original);
1501
+ else return _expandNode(node.value, original);
1502
+ }
1459
1503
  case "RestElement": return " ..." + node.argument.name;
1460
1504
  }
1461
1505
  console.error(JSON.stringify(node, null, 4));
@@ -1,4 +1,4 @@
1
- import { n as __esmMin, r as __exportAll } from "./chunk-HkwdBwDg.js";
1
+ import { c as __exportAll, s as __esmMin } from "./apis-CKvPKBJI.js";
2
2
  //#region ../../node_modules/.pnpm/prettier@3.8.3/node_modules/prettier/plugins/postcss.mjs
3
3
  var postcss_exports = /* @__PURE__ */ __exportAll({
4
4
  default: () => _l,
@@ -1,4 +1,4 @@
1
- import { n as __esmMin, r as __exportAll } from "./chunk-HkwdBwDg.js";
1
+ import { c as __exportAll, s as __esmMin } from "./apis-CKvPKBJI.js";
2
2
  import { builtinModules, createRequire } from "module";
3
3
  import * as url from "url";
4
4
  import url2, { fileURLToPath, pathToFileURL } from "url";
@@ -2402,7 +2402,7 @@ async function loadConfigFromPackageYaml(file) {
2402
2402
  }
2403
2403
  async function loadYaml(file) {
2404
2404
  const content = await read_file_default(file);
2405
- if (!parseYaml) ({__parsePrettierYamlConfig: parseYaml} = await import("./yaml-DLZBHI7f.js"));
2405
+ if (!parseYaml) ({__parsePrettierYamlConfig: parseYaml} = await import("./yaml-Bqxyk-13.js"));
2406
2406
  try {
2407
2407
  return parseYaml(content);
2408
2408
  } catch (error) {
@@ -15380,7 +15380,7 @@ ${codeblock}`, options8);
15380
15380
  proseWrap: common_options_evaluate_default.proseWrap
15381
15381
  };
15382
15382
  estreePlugin = createParsersAndPrinters([{
15383
- importPlugin: () => import("./estree-DZBnPYMx.js"),
15383
+ importPlugin: () => import("./estree-CzfNsl8m.js"),
15384
15384
  printers: ["estree", "estree-json"]
15385
15385
  }]);
15386
15386
  options7 = {
@@ -15403,11 +15403,11 @@ ${codeblock}`, options8);
15403
15403
  ];
15404
15404
  ({parsers, printers} = createParsersAndPrinters([
15405
15405
  {
15406
- importPlugin: () => import("./acorn-ay2Aj6GQ.js"),
15406
+ importPlugin: () => import("./acorn-sBRpswSh.js"),
15407
15407
  parsers: ["acorn", "espree"]
15408
15408
  },
15409
15409
  {
15410
- importPlugin: () => import("./angular-z1ZEe5V_.js"),
15410
+ importPlugin: () => import("./angular-DtI-eDW8.js"),
15411
15411
  parsers: [
15412
15412
  "__ng_action",
15413
15413
  "__ng_binding",
@@ -15416,7 +15416,7 @@ ${codeblock}`, options8);
15416
15416
  ]
15417
15417
  },
15418
15418
  {
15419
- importPlugin: () => import("./babel-Cs312VeV.js"),
15419
+ importPlugin: () => import("./babel-DaNjvh9L.js"),
15420
15420
  parsers: [
15421
15421
  "babel",
15422
15422
  "babel-flow",
@@ -15435,21 +15435,21 @@ ${codeblock}`, options8);
15435
15435
  ]
15436
15436
  },
15437
15437
  {
15438
- importPlugin: () => import("./flow-ChhAFZSt.js"),
15438
+ importPlugin: () => import("./flow-c9AjoQam.js"),
15439
15439
  parsers: ["flow"]
15440
15440
  },
15441
15441
  {
15442
- importPlugin: () => import("./glimmer-Cg8KQipT.js"),
15442
+ importPlugin: () => import("./glimmer-D_zkI0w_.js"),
15443
15443
  parsers: ["glimmer"],
15444
15444
  printers: ["glimmer"]
15445
15445
  },
15446
15446
  {
15447
- importPlugin: () => import("./graphql-DsP-ifm0.js"),
15447
+ importPlugin: () => import("./graphql-BFXkB4Nq.js"),
15448
15448
  parsers: ["graphql"],
15449
15449
  printers: ["graphql"]
15450
15450
  },
15451
15451
  {
15452
- importPlugin: () => import("./html-7pWx9LND.js"),
15452
+ importPlugin: () => import("./html-DkcPxRXg.js"),
15453
15453
  parsers: [
15454
15454
  "html",
15455
15455
  "angular",
@@ -15460,7 +15460,7 @@ ${codeblock}`, options8);
15460
15460
  printers: ["html"]
15461
15461
  },
15462
15462
  {
15463
- importPlugin: () => import("./markdown-CCrs3bBt.js"),
15463
+ importPlugin: () => import("./markdown-DVLNmbQg.js"),
15464
15464
  parsers: [
15465
15465
  "markdown",
15466
15466
  "mdx",
@@ -15469,11 +15469,11 @@ ${codeblock}`, options8);
15469
15469
  printers: ["mdast"]
15470
15470
  },
15471
15471
  {
15472
- importPlugin: () => import("./meriyah-TC7VDz8E.js"),
15472
+ importPlugin: () => import("./meriyah-BGPf00Rn.js"),
15473
15473
  parsers: ["meriyah"]
15474
15474
  },
15475
15475
  {
15476
- importPlugin: () => import("./postcss-ZbUej7DN.js"),
15476
+ importPlugin: () => import("./postcss-D-ql-dm8.js"),
15477
15477
  parsers: [
15478
15478
  "css",
15479
15479
  "less",
@@ -15482,11 +15482,11 @@ ${codeblock}`, options8);
15482
15482
  printers: ["postcss"]
15483
15483
  },
15484
15484
  {
15485
- importPlugin: () => import("./typescript-Cgpjcksz.js"),
15485
+ importPlugin: () => import("./typescript-C_eN_ThF.js"),
15486
15486
  parsers: ["typescript"]
15487
15487
  },
15488
15488
  {
15489
- importPlugin: () => import("./yaml-DLZBHI7f.js"),
15489
+ importPlugin: () => import("./yaml-Bqxyk-13.js"),
15490
15490
  parsers: ["yaml"],
15491
15491
  printers: ["yaml"]
15492
15492
  }
@@ -2,11 +2,45 @@ import { jsTextToDoc } from "./index.js";
2
2
  //#region src-js/libs/prettier-plugin-oxfmt/text-to-doc.ts
3
3
  const textToDoc = async (embeddedSourceText, textToDocOptions) => {
4
4
  const { parser, parentParser, filepath, _oxfmtPluginOptionsJson } = textToDocOptions;
5
- const doc = await jsTextToDoc(parser === "typescript" || parser === "babel-ts" ? filepath?.endsWith(".tsx") ? "tsx" : "ts" : "jsx", embeddedSourceText, _oxfmtPluginOptionsJson, detectParentContext(parentParser, textToDocOptions));
6
- if (doc === null) throw new Error("`oxfmt::textToDoc()` failed. Use `OXC_LOG` env var to see Rust-side logs.");
7
- return JSON.parse(doc);
5
+ const docJSON = await jsTextToDoc(parser === "typescript" || parser === "babel-ts" ? filepath?.endsWith(".tsx") ? "tsx" : "ts" : "jsx", embeddedSourceText, _oxfmtPluginOptionsJson, detectParentContext(parentParser, textToDocOptions));
6
+ if (docJSON === null) throw new Error("`oxfmt::textToDoc()` failed. Use `OXC_LOG` env var to see Rust-side logs.");
7
+ const { doc, refs } = JSON.parse(docJSON);
8
+ if (refs.length === 0) return doc;
9
+ return resolveRefs(doc, refs, Array.from({ length: refs.length }));
8
10
  };
9
11
  /**
12
+ * Rust emits `Interned` sub-trees once into `refs` and references them via `{ _REF: <id> }` placeholders,
13
+ * preventing exponential JSON blowup when the same sub-tree is duplicated variants.
14
+ *
15
+ * Restore shared object references so Prettier sees the original (memory-shared) structure.
16
+ * Identity does not affect output because Prettier identifies groups by their `id` field,
17
+ * not by JS object identity.
18
+ *
19
+ * The `_REF` key (uppercase, prefixed) is chosen to never collide with valid Prettier Doc node keys,
20
+ * so the `typeof obj._REF === "number"` check uniquely identifies placeholders.
21
+ *
22
+ * Refs are resolved on-demand with memoization.
23
+ * A ref `i` may reference any other ref `j` (including `j < i`) because Rust caches `Interned` by pointer
24
+ * and an earlier-encountered `Interned` (smaller id) can also appear inside a later one's content.
25
+ * Topological / reverse-order resolution would observe `undefined` holes, so we recurse lazily.
26
+ */
27
+ function resolveRefs(node, rawRefs, cache) {
28
+ if (node === null || typeof node !== "object") return node;
29
+ if (Array.isArray(node)) return node.map((n) => resolveRefs(n, rawRefs, cache));
30
+ const obj = node;
31
+ if (typeof obj._REF === "number") {
32
+ const id = obj._REF;
33
+ const cached = cache[id];
34
+ if (cached !== void 0) return cached;
35
+ const resolved = resolveRefs(rawRefs[id], rawRefs, cache);
36
+ cache[id] = resolved;
37
+ return resolved;
38
+ }
39
+ const out = {};
40
+ for (const k in obj) out[k] = resolveRefs(obj[k], rawRefs, cache);
41
+ return out;
42
+ }
43
+ /**
10
44
  * Detects Vue fragment mode from Prettier's internal flags.
11
45
  *
12
46
  * When Prettier formats Vue SFC templates, it calls textToDoc with special flags: