intlayer-editor 8.12.2 → 8.12.3

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 (158) hide show
  1. package/client/dist/assets/{CodeBlockClient-b-yeqFuz.js → CodeBlockClient-BQMC5gqu.js} +3 -3
  2. package/client/dist/assets/{CodeBlockShiki-CKm7rixD.js → CodeBlockShiki-DB7ndrOR.js} +2 -2
  3. package/client/dist/assets/{MarkDownRender-EQEw6Grf.js → MarkDownRender-BQwPctN-.js} +3 -3
  4. package/client/dist/assets/{bundle-web-DofprJDj.js → bundle-web-C4HpQhJS.js} +1 -1
  5. package/client/dist/assets/{dist-BFhKwA67.js → dist-GH_AdANR.js} +1 -1
  6. package/client/dist/assets/index-DIJj_-IN.css +2 -0
  7. package/client/dist/assets/index-DJVEpj0g.js +189 -0
  8. package/client/dist/assets/purify.es-6-uFcs4-.js +3 -0
  9. package/client/dist/index.html +2 -2
  10. package/package.json +15 -15
  11. package/server/dist/@intlayer/chokidar/dist/types/build.d.ts +1 -0
  12. package/server/dist/@intlayer/chokidar/dist/types/buildIntlayerDictionary/buildIntlayerDictionary.d.ts +2 -0
  13. package/server/dist/@intlayer/chokidar/dist/types/buildIntlayerDictionary/processContentDeclaration.d.ts +2 -0
  14. package/server/dist/@intlayer/chokidar/dist/types/buildIntlayerDictionary/writeDynamicDictionary.d.ts +2 -0
  15. package/server/dist/@intlayer/chokidar/dist/types/buildIntlayerDictionary/writeMergedDictionary.d.ts +2 -0
  16. package/server/dist/@intlayer/chokidar/dist/types/buildIntlayerDictionary/writeUnmergedDictionary.d.ts +2 -0
  17. package/server/dist/@intlayer/chokidar/dist/types/cleanOutputDir.d.ts +1 -0
  18. package/server/dist/@intlayer/chokidar/dist/types/createDictionaryEntryPoint/createDictionaryEntryPoint.d.ts +1 -0
  19. package/server/dist/@intlayer/chokidar/dist/types/createDictionaryEntryPoint/generateDictionaryListContent.d.ts +1 -0
  20. package/server/dist/@intlayer/chokidar/dist/types/createDictionaryEntryPoint/getBuiltDictionariesPath.d.ts +1 -0
  21. package/server/dist/@intlayer/chokidar/dist/types/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.d.ts +1 -0
  22. package/server/dist/@intlayer/chokidar/dist/types/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.d.ts +1 -0
  23. package/server/dist/@intlayer/chokidar/dist/types/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.d.ts +1 -0
  24. package/server/dist/@intlayer/chokidar/dist/types/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.d.ts +1 -0
  25. package/server/dist/@intlayer/chokidar/dist/types/createType/createModuleAugmentation.d.ts +1 -0
  26. package/server/dist/@intlayer/chokidar/dist/types/createType/createType.d.ts +2 -0
  27. package/server/dist/@intlayer/chokidar/dist/types/formatDictionary.d.ts +1 -0
  28. package/server/dist/@intlayer/chokidar/dist/types/intlayer/dist/types/index.d.ts +1 -0
  29. package/server/dist/@intlayer/chokidar/dist/types/loadDictionaries/loadContentDeclaration.d.ts +2 -0
  30. package/server/dist/@intlayer/chokidar/dist/types/loadDictionaries/loadDictionaries.d.ts +2 -0
  31. package/server/dist/@intlayer/chokidar/dist/types/loadDictionaries/loadLocalDictionaries.d.ts +2 -0
  32. package/server/dist/@intlayer/chokidar/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts +1 -0
  33. package/server/dist/@intlayer/chokidar/dist/types/prepareIntlayer.d.ts +1 -0
  34. package/server/dist/@intlayer/chokidar/dist/types/writeConfiguration/index.d.ts +1 -0
  35. package/server/dist/@intlayer/chokidar/dist/types/writeContentDeclaration/dictionaryStatus.d.ts +6 -0
  36. package/server/dist/@intlayer/chokidar/dist/types/writeContentDeclaration/transformJSFile.d.ts +1 -0
  37. package/server/dist/@intlayer/chokidar/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts +2 -0
  38. package/server/dist/@intlayer/chokidar/dist/types/writeContentDeclaration/writeJSFile.d.ts +2 -0
  39. package/server/dist/@intlayer/core/dist/types/messageFormat/ICU.d.ts +1 -0
  40. package/server/dist/@intlayer/core/dist/types/messageFormat/i18next.d.ts +1 -0
  41. package/server/dist/@intlayer/core/dist/types/messageFormat/index.d.ts +1 -0
  42. package/server/dist/@intlayer/core/dist/types/messageFormat/po.d.ts +1 -0
  43. package/server/dist/@intlayer/core/dist/types/messageFormat/vue-i18n.d.ts +1 -0
  44. package/server/dist/controllers/configuration.controller.cjs +1 -0
  45. package/server/dist/controllers/configuration.controller.cjs.map +1 -1
  46. package/server/dist/controllers/configuration.controller.mjs.map +1 -1
  47. package/server/dist/controllers/dictionary.controller.cjs +1 -0
  48. package/server/dist/controllers/dictionary.controller.cjs.map +1 -1
  49. package/server/dist/controllers/dictionary.controller.mjs.map +1 -1
  50. package/server/dist/index.cjs.map +1 -1
  51. package/server/dist/index.mjs.map +1 -1
  52. package/server/dist/packages/@intlayer/chokidar/dist/esm/detectFormatCommand.cjs +32 -0
  53. package/server/dist/packages/@intlayer/chokidar/dist/esm/detectFormatCommand.cjs.map +1 -0
  54. package/server/dist/packages/@intlayer/chokidar/dist/esm/detectFormatCommand.mjs +31 -0
  55. package/server/dist/packages/@intlayer/chokidar/dist/esm/detectFormatCommand.mjs.map +1 -0
  56. package/server/dist/packages/@intlayer/chokidar/dist/esm/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.cjs +82 -0
  57. package/server/dist/packages/@intlayer/chokidar/dist/esm/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.cjs.map +1 -0
  58. package/server/dist/packages/@intlayer/chokidar/dist/esm/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.mjs +81 -0
  59. package/server/dist/packages/@intlayer/chokidar/dist/esm/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.mjs.map +1 -0
  60. package/server/dist/packages/@intlayer/chokidar/dist/esm/utils/getFormatFromExtension.cjs +26 -0
  61. package/server/dist/packages/@intlayer/chokidar/dist/esm/utils/getFormatFromExtension.cjs.map +1 -0
  62. package/server/dist/packages/@intlayer/chokidar/dist/esm/utils/getFormatFromExtension.mjs +25 -0
  63. package/server/dist/packages/@intlayer/chokidar/dist/esm/utils/getFormatFromExtension.mjs.map +1 -0
  64. package/server/dist/packages/@intlayer/chokidar/dist/esm/utils/readDictionariesFromDisk.cjs +24 -0
  65. package/server/dist/packages/@intlayer/chokidar/dist/esm/utils/readDictionariesFromDisk.cjs.map +1 -0
  66. package/server/dist/packages/@intlayer/chokidar/dist/esm/utils/readDictionariesFromDisk.mjs +23 -0
  67. package/server/dist/packages/@intlayer/chokidar/dist/esm/utils/readDictionariesFromDisk.mjs.map +1 -0
  68. package/server/dist/packages/@intlayer/chokidar/dist/esm/writeContentDeclaration/processContentDeclarationContent.cjs +94 -0
  69. package/server/dist/packages/@intlayer/chokidar/dist/esm/writeContentDeclaration/processContentDeclarationContent.cjs.map +1 -0
  70. package/server/dist/packages/@intlayer/chokidar/dist/esm/writeContentDeclaration/processContentDeclarationContent.mjs +92 -0
  71. package/server/dist/packages/@intlayer/chokidar/dist/esm/writeContentDeclaration/processContentDeclarationContent.mjs.map +1 -0
  72. package/server/dist/packages/@intlayer/chokidar/dist/esm/writeContentDeclaration/transformJSFile.cjs +416 -0
  73. package/server/dist/packages/@intlayer/chokidar/dist/esm/writeContentDeclaration/transformJSFile.cjs.map +1 -0
  74. package/server/dist/packages/@intlayer/chokidar/dist/esm/writeContentDeclaration/transformJSFile.mjs +412 -0
  75. package/server/dist/packages/@intlayer/chokidar/dist/esm/writeContentDeclaration/transformJSFile.mjs.map +1 -0
  76. package/server/dist/packages/@intlayer/chokidar/dist/esm/writeContentDeclaration/transformJSONFile.cjs +127 -0
  77. package/server/dist/packages/@intlayer/chokidar/dist/esm/writeContentDeclaration/transformJSONFile.cjs.map +1 -0
  78. package/server/dist/packages/@intlayer/chokidar/dist/esm/writeContentDeclaration/transformJSONFile.mjs +125 -0
  79. package/server/dist/packages/@intlayer/chokidar/dist/esm/writeContentDeclaration/transformJSONFile.mjs.map +1 -0
  80. package/server/dist/packages/@intlayer/chokidar/dist/esm/writeContentDeclaration/writeContentDeclaration.cjs +164 -0
  81. package/server/dist/packages/@intlayer/chokidar/dist/esm/writeContentDeclaration/writeContentDeclaration.cjs.map +1 -0
  82. package/server/dist/packages/@intlayer/chokidar/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs +163 -0
  83. package/server/dist/packages/@intlayer/chokidar/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs.map +1 -0
  84. package/server/dist/packages/@intlayer/chokidar/dist/esm/writeContentDeclaration/writeJSFile.cjs +92 -0
  85. package/server/dist/packages/@intlayer/chokidar/dist/esm/writeContentDeclaration/writeJSFile.cjs.map +1 -0
  86. package/server/dist/packages/@intlayer/chokidar/dist/esm/writeContentDeclaration/writeJSFile.mjs +91 -0
  87. package/server/dist/packages/@intlayer/chokidar/dist/esm/writeContentDeclaration/writeJSFile.mjs.map +1 -0
  88. package/server/dist/packages/@intlayer/chokidar/dist/esm/writeContentDeclaration/writeMarkdownFile.cjs +65 -0
  89. package/server/dist/packages/@intlayer/chokidar/dist/esm/writeContentDeclaration/writeMarkdownFile.cjs.map +1 -0
  90. package/server/dist/packages/@intlayer/chokidar/dist/esm/writeContentDeclaration/writeMarkdownFile.mjs +64 -0
  91. package/server/dist/packages/@intlayer/chokidar/dist/esm/writeContentDeclaration/writeMarkdownFile.mjs.map +1 -0
  92. package/server/dist/packages/@intlayer/chokidar/dist/esm/writeContentDeclaration/writeYamlFile.cjs +43 -0
  93. package/server/dist/packages/@intlayer/chokidar/dist/esm/writeContentDeclaration/writeYamlFile.cjs.map +1 -0
  94. package/server/dist/packages/@intlayer/chokidar/dist/esm/writeContentDeclaration/writeYamlFile.mjs +42 -0
  95. package/server/dist/packages/@intlayer/chokidar/dist/esm/writeContentDeclaration/writeYamlFile.mjs.map +1 -0
  96. package/server/dist/packages/@intlayer/core/dist/esm/deepTransformPlugins/getFilteredLocalesContent.cjs +45 -0
  97. package/server/dist/packages/@intlayer/core/dist/esm/deepTransformPlugins/getFilteredLocalesContent.cjs.map +1 -0
  98. package/server/dist/packages/@intlayer/core/dist/esm/deepTransformPlugins/getFilteredLocalesContent.mjs +43 -0
  99. package/server/dist/packages/@intlayer/core/dist/esm/deepTransformPlugins/getFilteredLocalesContent.mjs.map +1 -0
  100. package/server/dist/packages/@intlayer/core/dist/esm/deepTransformPlugins/getLocalizedContent.cjs +32 -0
  101. package/server/dist/packages/@intlayer/core/dist/esm/deepTransformPlugins/getLocalizedContent.cjs.map +1 -0
  102. package/server/dist/packages/@intlayer/core/dist/esm/deepTransformPlugins/getLocalizedContent.mjs +32 -0
  103. package/server/dist/packages/@intlayer/core/dist/esm/deepTransformPlugins/getLocalizedContent.mjs.map +1 -0
  104. package/server/dist/packages/@intlayer/core/dist/esm/dictionaryManipulator/getNodeType.cjs +56 -0
  105. package/server/dist/packages/@intlayer/core/dist/esm/dictionaryManipulator/getNodeType.cjs.map +1 -0
  106. package/server/dist/packages/@intlayer/core/dist/esm/dictionaryManipulator/getNodeType.mjs +54 -0
  107. package/server/dist/packages/@intlayer/core/dist/esm/dictionaryManipulator/getNodeType.mjs.map +1 -0
  108. package/server/dist/packages/@intlayer/core/dist/esm/interpreter/getCondition.cjs +27 -0
  109. package/server/dist/packages/@intlayer/core/dist/esm/interpreter/getCondition.cjs.map +1 -0
  110. package/server/dist/packages/@intlayer/core/dist/esm/interpreter/getCondition.mjs +26 -0
  111. package/server/dist/packages/@intlayer/core/dist/esm/interpreter/getCondition.mjs.map +1 -0
  112. package/server/dist/packages/@intlayer/core/dist/esm/interpreter/getContent/deepTransform.cjs +58 -0
  113. package/server/dist/packages/@intlayer/core/dist/esm/interpreter/getContent/deepTransform.cjs.map +1 -0
  114. package/server/dist/packages/@intlayer/core/dist/esm/interpreter/getContent/deepTransform.mjs +56 -0
  115. package/server/dist/packages/@intlayer/core/dist/esm/interpreter/getContent/deepTransform.mjs.map +1 -0
  116. package/server/dist/packages/@intlayer/core/dist/esm/interpreter/getContent/plugins.cjs +160 -0
  117. package/server/dist/packages/@intlayer/core/dist/esm/interpreter/getContent/plugins.cjs.map +1 -0
  118. package/server/dist/packages/@intlayer/core/dist/esm/interpreter/getContent/plugins.mjs +158 -0
  119. package/server/dist/packages/@intlayer/core/dist/esm/interpreter/getContent/plugins.mjs.map +1 -0
  120. package/server/dist/packages/@intlayer/core/dist/esm/interpreter/getEnumeration.cjs +71 -0
  121. package/server/dist/packages/@intlayer/core/dist/esm/interpreter/getEnumeration.cjs.map +1 -0
  122. package/server/dist/packages/@intlayer/core/dist/esm/interpreter/getEnumeration.mjs +70 -0
  123. package/server/dist/packages/@intlayer/core/dist/esm/interpreter/getEnumeration.mjs.map +1 -0
  124. package/server/dist/packages/@intlayer/core/dist/esm/interpreter/getGender.cjs +38 -0
  125. package/server/dist/packages/@intlayer/core/dist/esm/interpreter/getGender.cjs.map +1 -0
  126. package/server/dist/packages/@intlayer/core/dist/esm/interpreter/getGender.mjs +37 -0
  127. package/server/dist/packages/@intlayer/core/dist/esm/interpreter/getGender.mjs.map +1 -0
  128. package/server/dist/packages/@intlayer/core/dist/esm/interpreter/getInsertion.cjs +22 -0
  129. package/server/dist/packages/@intlayer/core/dist/esm/interpreter/getInsertion.cjs.map +1 -0
  130. package/server/dist/packages/@intlayer/core/dist/esm/interpreter/getInsertion.mjs +21 -0
  131. package/server/dist/packages/@intlayer/core/dist/esm/interpreter/getInsertion.mjs.map +1 -0
  132. package/server/dist/packages/@intlayer/core/dist/esm/interpreter/getTranslation.cjs +87 -0
  133. package/server/dist/packages/@intlayer/core/dist/esm/interpreter/getTranslation.cjs.map +1 -0
  134. package/server/dist/packages/@intlayer/core/dist/esm/interpreter/getTranslation.mjs +86 -0
  135. package/server/dist/packages/@intlayer/core/dist/esm/interpreter/getTranslation.mjs.map +1 -0
  136. package/server/dist/packages/@intlayer/core/dist/esm/utils/isValidReactElement.cjs +14 -0
  137. package/server/dist/packages/@intlayer/core/dist/esm/utils/isValidReactElement.cjs.map +1 -0
  138. package/server/dist/packages/@intlayer/core/dist/esm/utils/isValidReactElement.mjs +13 -0
  139. package/server/dist/packages/@intlayer/core/dist/esm/utils/isValidReactElement.mjs.map +1 -0
  140. package/server/dist/packages/@intlayer/core/dist/esm/utils/stringifyYaml.cjs +58 -0
  141. package/server/dist/packages/@intlayer/core/dist/esm/utils/stringifyYaml.cjs.map +1 -0
  142. package/server/dist/packages/@intlayer/core/dist/esm/utils/stringifyYaml.mjs +57 -0
  143. package/server/dist/packages/@intlayer/core/dist/esm/utils/stringifyYaml.mjs.map +1 -0
  144. package/server/dist/routes/config.routes.cjs +1 -0
  145. package/server/dist/routes/config.routes.cjs.map +1 -1
  146. package/server/dist/routes/config.routes.mjs.map +1 -1
  147. package/server/dist/routes/dictionary.routes.cjs +1 -0
  148. package/server/dist/routes/dictionary.routes.cjs.map +1 -1
  149. package/server/dist/routes/dictionary.routes.mjs.map +1 -1
  150. package/server/dist/utils/checkPortAvailability.cjs.map +1 -1
  151. package/server/dist/utils/checkPortAvailability.mjs.map +1 -1
  152. package/server/dist/utils/httpStatusCodes.cjs.map +1 -1
  153. package/server/dist/utils/httpStatusCodes.mjs.map +1 -1
  154. package/server/dist/utils/responseData.cjs.map +1 -1
  155. package/server/dist/utils/responseData.mjs.map +1 -1
  156. package/client/dist/assets/index-CTSrsWZb.css +0 -2
  157. package/client/dist/assets/index-bVSusa0N.js +0 -185
  158. package/client/dist/assets/purify.es-Dt2VzQ8a.js +0 -3
@@ -0,0 +1,412 @@
1
+ import { getNodeType } from "../../../../core/dist/esm/dictionaryManipulator/getNodeType.mjs";
2
+ import * as NodeTypes from "@intlayer/types/nodeType";
3
+ import * as recast from "/Users/aymericpineau/Documents/intlayer_/node_modules/.bun/recast@0.23.11/node_modules/recast/main.js";
4
+ import * as babelTsParser from "/Users/aymericpineau/Documents/intlayer_/node_modules/.bun/recast@0.23.11/node_modules/recast/parsers/babel-ts.js";
5
+
6
+ //#region ../../@intlayer/chokidar/dist/esm/writeContentDeclaration/transformJSFile.mjs
7
+ const b = recast.types.builders;
8
+ const n = recast.types.namedTypes;
9
+ /**
10
+ * Unwraps TypeScript/Babel expression wrappers (satisfies, as, !, <Type>).
11
+ * Uses string fallbacks to bypass outdated ast-types definitions.
12
+ */
13
+ const unwrap = (node) => {
14
+ while (node && (n.TSSatisfiesExpression?.check(node) || n.TSAsExpression?.check(node) || n.TSTypeAssertion?.check(node) || n.TSNonNullExpression?.check(node) || [
15
+ "TSSatisfiesExpression",
16
+ "TSAsExpression",
17
+ "TSTypeAssertion",
18
+ "TSNonNullExpression"
19
+ ].includes(node.type))) node = node.expression;
20
+ return node;
21
+ };
22
+ /**
23
+ * Robustly finds a property in a recast ObjectExpression.
24
+ * Handles quoted ("key") or unquoted (key) properties.
25
+ */
26
+ const getMatchingProperty = (node, key) => {
27
+ return node.properties.find((prop) => {
28
+ if (n.Property.check(prop) || n.ObjectProperty.check(prop)) {
29
+ if (n.Identifier.check(prop.key) && prop.key.name === key) return true;
30
+ if (n.StringLiteral.check(prop.key) && prop.key.value === key) return true;
31
+ if (n.Literal.check(prop.key) && prop.key.value === key) return true;
32
+ }
33
+ return false;
34
+ });
35
+ };
36
+ /**
37
+ * Synchronizes numeric suffixes across locales.
38
+ * E.g. "Hello 1" -> "Hello 3" updates "Bonjour 1" to "Bonjour 3".
39
+ */
40
+ const syncNumericSuffixAcrossLocales = (existingNode, fallbackLocaleCode, newFallbackValue) => {
41
+ const trailingNumberMatch = newFallbackValue.match(/\d+(?!.*\d)/);
42
+ if (!trailingNumberMatch) return;
43
+ const newTrailingNumber = trailingNumberMatch[0];
44
+ if (n.ObjectExpression.check(existingNode)) {
45
+ for (const prop of existingNode.properties) if (n.Property.check(prop) || n.ObjectProperty.check(prop)) {
46
+ let propName = "";
47
+ if (n.Identifier.check(prop.key)) propName = prop.key.name;
48
+ else if (n.Literal.check(prop.key) && typeof prop.key.value === "string") propName = prop.key.value;
49
+ else if (n.StringLiteral.check(prop.key)) propName = prop.key.value;
50
+ if (propName && propName !== fallbackLocaleCode) {
51
+ if (n.Literal.check(prop.value) && typeof prop.value.value === "string") {
52
+ const currentValue = prop.value.value;
53
+ if (currentValue.match(/\d+(?!.*\d)/)) prop.value = b.literal(currentValue.replace(/(\d+)(?!.*\d)/, newTrailingNumber));
54
+ } else if (n.StringLiteral.check(prop.value)) {
55
+ const currentValue = prop.value.value;
56
+ if (currentValue.match(/\d+(?!.*\d)/)) prop.value = b.stringLiteral(currentValue.replace(/(\d+)(?!.*\d)/, newTrailingNumber));
57
+ }
58
+ }
59
+ }
60
+ }
61
+ };
62
+ /**
63
+ * Checks if a value represents a multilingual Intlayer node.
64
+ * A node is multilingual if it is a Translation node, or if it is a specialized node
65
+ * (Markdown, HTML, etc.) that contains a Translation node.
66
+ */
67
+ const isMultilingualNode = (val) => {
68
+ if (typeof val !== "object" || val === null || Array.isArray(val)) return false;
69
+ const nodeType = getNodeType(val);
70
+ if (nodeType === NodeTypes.TRANSLATION) return true;
71
+ if (nodeType === NodeTypes.MARKDOWN || nodeType === NodeTypes.HTML || nodeType === NodeTypes.INSERTION) return isMultilingualNode(val[nodeType]);
72
+ if (nodeType === NodeTypes.ENUMERATION || nodeType === NodeTypes.PLURAL || nodeType === NodeTypes.CONDITION || nodeType === NodeTypes.GENDER) {
73
+ const data = val[nodeType];
74
+ if (data && typeof data === "object") return Object.values(data).some((v) => isMultilingualNode(v));
75
+ }
76
+ return false;
77
+ };
78
+ /**
79
+ * Recursively builds or updates an AST node for a given dictionary value.
80
+ */
81
+ const buildNodeForValue = (val, existingNode, fallbackLocale, requiredImports) => {
82
+ const unwrappedExisting = unwrap(existingNode);
83
+ if (unwrappedExisting) {
84
+ if (!(n.Literal.check(unwrappedExisting) || n.StringLiteral.check(unwrappedExisting) || n.NumericLiteral.check(unwrappedExisting) || n.BooleanLiteral.check(unwrappedExisting) || n.TemplateLiteral.check(unwrappedExisting) || n.ObjectExpression.check(unwrappedExisting) || n.ArrayExpression.check(unwrappedExisting) || n.CallExpression.check(unwrappedExisting) && n.Identifier.check(unwrappedExisting.callee) && [
85
+ "t",
86
+ "enu",
87
+ "plural",
88
+ "cond",
89
+ "gender",
90
+ "insert",
91
+ "md",
92
+ "html",
93
+ "file",
94
+ "nest"
95
+ ].includes(unwrappedExisting.callee.name))) return existingNode;
96
+ }
97
+ if (fallbackLocale && !existingNode && !isMultilingualNode(val)) {
98
+ if (val === null) return b.literal(null);
99
+ if (typeof val === "string" || typeof val === "number" || typeof val === "boolean") {
100
+ if (typeof val === "string" && val.includes("\n")) return b.templateLiteral([b.templateElement({
101
+ raw: val,
102
+ cooked: val
103
+ }, true)], []);
104
+ return b.literal(val);
105
+ }
106
+ }
107
+ if (fallbackLocale && existingNode && !isMultilingualNode(val)) {
108
+ if (n.CallExpression.check(existingNode) && n.Identifier.check(existingNode.callee) && existingNode.callee.name === "t") {
109
+ const arg = unwrap(existingNode.arguments[0]);
110
+ if (n.ObjectExpression.check(arg)) {
111
+ if (typeof val === "string") syncNumericSuffixAcrossLocales(arg, fallbackLocale, val);
112
+ updateObjectLiteral(arg, { [fallbackLocale]: val }, fallbackLocale, requiredImports);
113
+ if (!fallbackLocale) requiredImports.add("t");
114
+ return existingNode;
115
+ }
116
+ }
117
+ if ((!val || typeof val !== "object") && n.CallExpression.check(existingNode) && n.Identifier.check(existingNode.callee) && existingNode.callee.name === "md") {
118
+ const innerArg = existingNode.arguments[0];
119
+ if (n.CallExpression.check(innerArg) && n.Identifier.check(innerArg.callee) && innerArg.callee.name === "t") {
120
+ const tArg = unwrap(innerArg.arguments[0]);
121
+ if (n.ObjectExpression.check(tArg)) {
122
+ if (typeof val === "string") syncNumericSuffixAcrossLocales(tArg, fallbackLocale, val);
123
+ updateObjectLiteral(tArg, { [fallbackLocale]: val }, fallbackLocale, requiredImports);
124
+ requiredImports.add("md");
125
+ requiredImports.add("t");
126
+ return existingNode;
127
+ }
128
+ }
129
+ }
130
+ }
131
+ if (val === null) return b.literal(null);
132
+ if (typeof val === "string" || typeof val === "number" || typeof val === "boolean") {
133
+ if (unwrappedExisting) {
134
+ if (n.TemplateLiteral.check(unwrappedExisting) && unwrappedExisting.expressions.length === 0) {
135
+ unwrappedExisting.quasis[0].value.raw = String(val);
136
+ unwrappedExisting.quasis[0].value.cooked = String(val);
137
+ return existingNode;
138
+ }
139
+ if (n.Literal.check(unwrappedExisting) || n.StringLiteral.check(unwrappedExisting)) {
140
+ unwrappedExisting.value = val;
141
+ return existingNode;
142
+ }
143
+ }
144
+ if (typeof val === "string" && val.includes("\n")) return b.templateLiteral([b.templateElement({
145
+ raw: val,
146
+ cooked: val
147
+ }, true)], []);
148
+ return b.literal(val);
149
+ }
150
+ if (Array.isArray(val)) if (unwrappedExisting && n.ArrayExpression.check(unwrappedExisting)) {
151
+ const elements = [...unwrappedExisting.elements];
152
+ val.forEach((item, i) => {
153
+ elements[i] = buildNodeForValue(item, elements[i], fallbackLocale, requiredImports);
154
+ });
155
+ if (elements.length > val.length) elements.length = val.length;
156
+ unwrappedExisting.elements = elements;
157
+ return existingNode;
158
+ } else return b.arrayExpression(val.map((item) => buildNodeForValue(item, null, fallbackLocale, requiredImports)));
159
+ const nodeType = val && typeof val === "object" && !Array.isArray(val) ? getNodeType(val) : null;
160
+ if (nodeType && [
161
+ NodeTypes.TRANSLATION,
162
+ NodeTypes.ENUMERATION,
163
+ NodeTypes.PLURAL,
164
+ NodeTypes.CONDITION,
165
+ NodeTypes.GENDER,
166
+ NodeTypes.INSERTION,
167
+ NodeTypes.MARKDOWN,
168
+ NodeTypes.HTML,
169
+ NodeTypes.FILE,
170
+ NodeTypes.NESTED,
171
+ NodeTypes.ARRAY,
172
+ NodeTypes.OBJECT,
173
+ NodeTypes.REACT_NODE,
174
+ NodeTypes.NUMBER,
175
+ NodeTypes.BOOLEAN,
176
+ NodeTypes.NULL,
177
+ NodeTypes.UNKNOWN
178
+ ].includes(nodeType) && nodeType !== NodeTypes.TEXT) {
179
+ const nodeData = val[nodeType];
180
+ let calleeName = "";
181
+ if (nodeType === NodeTypes.TRANSLATION) calleeName = "t";
182
+ else if (nodeType === NodeTypes.ENUMERATION) calleeName = "enu";
183
+ else if (nodeType === NodeTypes.PLURAL) calleeName = "plural";
184
+ else if (nodeType === NodeTypes.CONDITION) calleeName = "cond";
185
+ else if (nodeType === NodeTypes.GENDER) calleeName = "gender";
186
+ else if (nodeType === NodeTypes.INSERTION) calleeName = "insert";
187
+ else if (nodeType === NodeTypes.MARKDOWN) calleeName = "md";
188
+ else if (nodeType === NodeTypes.HTML) calleeName = "html";
189
+ else if (nodeType === NodeTypes.FILE) calleeName = "file";
190
+ else if (nodeType === NodeTypes.NESTED) calleeName = "nest";
191
+ if (calleeName) requiredImports.add(calleeName);
192
+ const isMatchingCall = existingNode && n.CallExpression.check(existingNode) && n.Identifier.check(existingNode.callee) && existingNode.callee.name === calleeName;
193
+ if ([
194
+ "t",
195
+ "enu",
196
+ "plural",
197
+ "cond",
198
+ "gender"
199
+ ].includes(calleeName)) {
200
+ let objArg = null;
201
+ if (isMatchingCall && existingNode.arguments.length > 0 && n.ObjectExpression.check(existingNode.arguments[0])) objArg = existingNode.arguments[0];
202
+ else objArg = b.objectExpression([]);
203
+ updateObjectLiteral(objArg, nodeData, fallbackLocale, requiredImports);
204
+ return isMatchingCall ? existingNode : b.callExpression(b.identifier(calleeName), [objArg]);
205
+ }
206
+ if ([
207
+ "md",
208
+ "html",
209
+ "insert",
210
+ "file"
211
+ ].includes(calleeName)) {
212
+ const argNode = buildNodeForValue(nodeData, isMatchingCall && existingNode.arguments.length > 0 ? existingNode.arguments[0] : null, fallbackLocale, requiredImports);
213
+ if (isMatchingCall) {
214
+ existingNode.arguments[0] = argNode;
215
+ return existingNode;
216
+ }
217
+ return b.callExpression(b.identifier(calleeName), [argNode]);
218
+ }
219
+ if (calleeName === "nest") {
220
+ const args = [b.literal(nodeData.dictionaryKey)];
221
+ if (nodeData.path) args.push(b.literal(nodeData.path));
222
+ if (isMatchingCall) {
223
+ existingNode.arguments = args;
224
+ return existingNode;
225
+ }
226
+ return b.callExpression(b.identifier("nest"), args);
227
+ }
228
+ }
229
+ const objNode = unwrappedExisting && n.ObjectExpression.check(unwrappedExisting) ? unwrappedExisting : b.objectExpression([]);
230
+ updateObjectLiteral(objNode, val, fallbackLocale, requiredImports);
231
+ return existingNode && unwrappedExisting === existingNode ? objNode : existingNode || objNode;
232
+ };
233
+ /**
234
+ * Recursively updates the AST object literal properties.
235
+ */
236
+ const updateObjectLiteral = (node, data, fallbackLocale, requiredImports) => {
237
+ for (const [key, val] of Object.entries(data)) {
238
+ if (val === void 0) continue;
239
+ const existingProp = getMatchingProperty(node, key);
240
+ if (existingProp) existingProp.value = buildNodeForValue(val, existingProp.value, fallbackLocale, requiredImports);
241
+ else {
242
+ const keyNode = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key) ? b.identifier(key) : b.literal(key);
243
+ const valueNode = buildNodeForValue(val, null, fallbackLocale, requiredImports);
244
+ node.properties.push(b.property("init", keyNode, valueNode));
245
+ }
246
+ }
247
+ };
248
+ /**
249
+ * Modifies the AST's top-level imports to inject dynamically needed helper utilities seamlessly.
250
+ */
251
+ const addImports = (ast, requiredImports, isESM) => {
252
+ if (requiredImports.size === 0) return;
253
+ const existingCoreImports = /* @__PURE__ */ new Set();
254
+ let coreImportPath = null;
255
+ recast.visit(ast, {
256
+ visitImportDeclaration(path) {
257
+ if (path.node.source.value === "intlayer") {
258
+ coreImportPath = path;
259
+ path.node.specifiers?.forEach((spec) => {
260
+ if (n.ImportSpecifier.check(spec) && typeof spec.imported.name === "string") existingCoreImports.add(spec.imported.name);
261
+ });
262
+ }
263
+ return false;
264
+ },
265
+ visitVariableDeclaration(path) {
266
+ path.node.declarations.forEach((decl) => {
267
+ if (n.VariableDeclarator.check(decl) && n.CallExpression.check(decl.init) && n.Identifier.check(decl.init.callee) && decl.init.callee.name === "require") {
268
+ const arg = decl.init.arguments[0];
269
+ if (n.Literal.check(arg)) {
270
+ if (arg.value === "intlayer") {
271
+ if (n.ObjectPattern.check(decl.id)) decl.id.properties.forEach((prop) => {
272
+ if (n.Property.check(prop) && (n.Identifier.check(prop.key) || n.Identifier.check(prop.value))) {
273
+ const name = n.Identifier.check(prop.key) ? prop.key.name : prop.value.name;
274
+ existingCoreImports.add(name);
275
+ }
276
+ });
277
+ else if (n.Identifier.check(decl.id)) existingCoreImports.add(decl.id.name);
278
+ }
279
+ }
280
+ }
281
+ });
282
+ return false;
283
+ }
284
+ });
285
+ const missingCore = Array.from(requiredImports).filter((imp) => !existingCoreImports.has(imp));
286
+ if (missingCore.length === 0) return;
287
+ if (isESM) if (coreImportPath) {
288
+ missingCore.forEach((imp) => {
289
+ coreImportPath.node.specifiers.push(b.importSpecifier(b.identifier(imp)));
290
+ });
291
+ coreImportPath.node.specifiers.sort((a, b) => a.imported.name.localeCompare(b.imported.name));
292
+ } else {
293
+ const specifiers = missingCore.sort().map((imp) => b.importSpecifier(b.identifier(imp)));
294
+ const newImport = b.importDeclaration(specifiers, b.literal("intlayer"));
295
+ ast.program.body.unshift(newImport);
296
+ }
297
+ else {
298
+ let insertIndex = 0;
299
+ if (ast.program.body.length > 0 && n.ExpressionStatement.check(ast.program.body[0]) && n.Literal.check(ast.program.body[0].expression)) insertIndex = 1;
300
+ const cjsLines = [];
301
+ const properties = missingCore.sort().map((imp) => {
302
+ const prop = b.property("init", b.identifier(imp), b.identifier(imp));
303
+ prop.shorthand = true;
304
+ return prop;
305
+ });
306
+ cjsLines.push(b.variableDeclaration("const", [b.variableDeclarator(b.objectPattern(properties), b.callExpression(b.identifier("require"), [b.literal("intlayer")]))]));
307
+ ast.program.body.splice(insertIndex, 0, ...cjsLines);
308
+ }
309
+ };
310
+ /**
311
+ * Updates a JS/TS file seamlessly to map new localization keys, arrays, complex nodes and nested dictionaries gracefully using AST updates via Recast parser.
312
+ */
313
+ const transformJSFile = async (fileContent, dictionary, fallbackLocale, noMetadata) => {
314
+ if (!dictionary || typeof dictionary !== "object") return fileContent;
315
+ let ast;
316
+ try {
317
+ ast = recast.parse(fileContent, { parser: babelTsParser });
318
+ } catch (error) {
319
+ console.error({ error });
320
+ return fileContent;
321
+ }
322
+ let rootObject = null;
323
+ let isESM = false;
324
+ recast.visit(ast, {
325
+ visitExportDefaultDeclaration() {
326
+ isESM = true;
327
+ return false;
328
+ },
329
+ visitImportDeclaration() {
330
+ isESM = true;
331
+ return false;
332
+ }
333
+ });
334
+ recast.visit(ast, {
335
+ visitExportDefaultDeclaration(path) {
336
+ const decl = path.node.declaration;
337
+ const unwrappedDecl = unwrap(decl);
338
+ if (n.ObjectExpression.check(unwrappedDecl)) rootObject = unwrappedDecl;
339
+ else if (n.Identifier.check(unwrappedDecl)) {
340
+ const varName = unwrappedDecl.name;
341
+ recast.visit(ast, { visitVariableDeclarator(vp) {
342
+ const unwrappedInit = unwrap(vp.node.init);
343
+ if (n.Identifier.check(vp.node.id) && vp.node.id.name === varName && n.ObjectExpression.check(unwrappedInit)) rootObject = unwrappedInit;
344
+ return false;
345
+ } });
346
+ }
347
+ return false;
348
+ },
349
+ visitAssignmentExpression(path) {
350
+ const left = path.node.left;
351
+ if (n.MemberExpression.check(left)) {
352
+ if (n.Identifier.check(left.object) && left.object.name === "module" && n.Identifier.check(left.property) && left.property.name === "exports") {
353
+ const unwrappedRight = unwrap(path.node.right);
354
+ if (n.ObjectExpression.check(unwrappedRight)) rootObject = unwrappedRight;
355
+ }
356
+ if (n.Identifier.check(left.object) && left.object.name === "exports" && n.Identifier.check(left.property) && left.property.name === "default") {
357
+ const unwrappedRight = unwrap(path.node.right);
358
+ if (n.ObjectExpression.check(unwrappedRight)) rootObject = unwrappedRight;
359
+ }
360
+ }
361
+ this.traverse(path);
362
+ }
363
+ });
364
+ if (!rootObject) recast.visit(ast, { visitVariableDeclarator(path) {
365
+ const unwrappedInit = unwrap(path.node.init);
366
+ if (!rootObject && n.ObjectExpression.check(unwrappedInit)) rootObject = unwrappedInit;
367
+ return false;
368
+ } });
369
+ if (!rootObject) return fileContent;
370
+ const requiredImports = /* @__PURE__ */ new Set();
371
+ const effectiveFallbackLocale = fallbackLocale ?? "en";
372
+ const metadataProperties = [
373
+ "id",
374
+ "locale",
375
+ "filled",
376
+ "fill",
377
+ "title",
378
+ "description",
379
+ "tags",
380
+ "version",
381
+ "priority",
382
+ "contentAutoTransformation"
383
+ ];
384
+ if (noMetadata) {
385
+ rootObject.properties = rootObject.properties.filter((prop) => {
386
+ if (n.Property.check(prop) || n.ObjectProperty.check(prop)) {
387
+ let propName = "";
388
+ if (n.Identifier.check(prop.key)) propName = prop.key.name;
389
+ else if (n.StringLiteral.check(prop.key)) propName = prop.key.value;
390
+ else if (n.Literal.check(prop.key)) propName = String(prop.key.value);
391
+ return ![
392
+ "key",
393
+ "content",
394
+ ...metadataProperties
395
+ ].includes(propName);
396
+ }
397
+ return true;
398
+ });
399
+ recast.visit(ast, { visitNode(path) {
400
+ const node = path.node;
401
+ if ((n.TSSatisfiesExpression?.check(node) || node.type === "TSSatisfiesExpression") && node.typeAnnotation && n.TSTypeReference.check(node.typeAnnotation) && n.Identifier.check(node.typeAnnotation.typeName) && node.typeAnnotation.typeName.name === "Dictionary") node.typeAnnotation = b.tsIndexedAccessType(b.tsTypeReference(b.identifier("Dictionary")), b.tsLiteralType(b.stringLiteral("content")));
402
+ this.traverse(path);
403
+ } });
404
+ } else for (const prop of metadataProperties) if (dictionary[prop] !== void 0) updateObjectLiteral(rootObject, { [prop]: dictionary[prop] }, void 0, requiredImports);
405
+ if (dictionary.content !== void 0) updateObjectLiteral(rootObject, noMetadata ? dictionary.content : { content: dictionary.content }, effectiveFallbackLocale, requiredImports);
406
+ addImports(ast, requiredImports, isESM);
407
+ return recast.print(ast).code;
408
+ };
409
+
410
+ //#endregion
411
+ export { transformJSFile };
412
+ //# sourceMappingURL=transformJSFile.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transformJSFile.mjs","names":[],"sources":["../../../../../../../../../@intlayer/chokidar/dist/esm/writeContentDeclaration/transformJSFile.mjs"],"sourcesContent":["import { getNodeType } from \"@intlayer/core/dictionaryManipulator\";\nimport * as NodeTypes from \"@intlayer/types/nodeType\";\nimport * as recast from \"recast\";\nimport * as babelTsParser from \"recast/parsers/babel-ts.js\";\n\n//#region src/writeContentDeclaration/transformJSFile.ts\nconst b = recast.types.builders;\nconst n = recast.types.namedTypes;\n/**\n* Unwraps TypeScript/Babel expression wrappers (satisfies, as, !, <Type>).\n* Uses string fallbacks to bypass outdated ast-types definitions.\n*/\nconst unwrap = (node) => {\n\twhile (node && (n.TSSatisfiesExpression?.check(node) || n.TSAsExpression?.check(node) || n.TSTypeAssertion?.check(node) || n.TSNonNullExpression?.check(node) || [\n\t\t\"TSSatisfiesExpression\",\n\t\t\"TSAsExpression\",\n\t\t\"TSTypeAssertion\",\n\t\t\"TSNonNullExpression\"\n\t].includes(node.type))) node = node.expression;\n\treturn node;\n};\n/**\n* Robustly finds a property in a recast ObjectExpression.\n* Handles quoted (\"key\") or unquoted (key) properties.\n*/\nconst getMatchingProperty = (node, key) => {\n\treturn node.properties.find((prop) => {\n\t\tif (n.Property.check(prop) || n.ObjectProperty.check(prop)) {\n\t\t\tif (n.Identifier.check(prop.key) && prop.key.name === key) return true;\n\t\t\tif (n.StringLiteral.check(prop.key) && prop.key.value === key) return true;\n\t\t\tif (n.Literal.check(prop.key) && prop.key.value === key) return true;\n\t\t}\n\t\treturn false;\n\t});\n};\n/**\n* Synchronizes numeric suffixes across locales.\n* E.g. \"Hello 1\" -> \"Hello 3\" updates \"Bonjour 1\" to \"Bonjour 3\".\n*/\nconst syncNumericSuffixAcrossLocales = (existingNode, fallbackLocaleCode, newFallbackValue) => {\n\tconst trailingNumberMatch = newFallbackValue.match(/\\d+(?!.*\\d)/);\n\tif (!trailingNumberMatch) return;\n\tconst newTrailingNumber = trailingNumberMatch[0];\n\tif (n.ObjectExpression.check(existingNode)) {\n\t\tfor (const prop of existingNode.properties) if (n.Property.check(prop) || n.ObjectProperty.check(prop)) {\n\t\t\tlet propName = \"\";\n\t\t\tif (n.Identifier.check(prop.key)) propName = prop.key.name;\n\t\t\telse if (n.Literal.check(prop.key) && typeof prop.key.value === \"string\") propName = prop.key.value;\n\t\t\telse if (n.StringLiteral.check(prop.key)) propName = prop.key.value;\n\t\t\tif (propName && propName !== fallbackLocaleCode) {\n\t\t\t\tif (n.Literal.check(prop.value) && typeof prop.value.value === \"string\") {\n\t\t\t\t\tconst currentValue = prop.value.value;\n\t\t\t\t\tif (currentValue.match(/\\d+(?!.*\\d)/)) prop.value = b.literal(currentValue.replace(/(\\d+)(?!.*\\d)/, newTrailingNumber));\n\t\t\t\t} else if (n.StringLiteral.check(prop.value)) {\n\t\t\t\t\tconst currentValue = prop.value.value;\n\t\t\t\t\tif (currentValue.match(/\\d+(?!.*\\d)/)) prop.value = b.stringLiteral(currentValue.replace(/(\\d+)(?!.*\\d)/, newTrailingNumber));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n};\n/**\n* Checks if a value represents a multilingual Intlayer node.\n* A node is multilingual if it is a Translation node, or if it is a specialized node\n* (Markdown, HTML, etc.) that contains a Translation node.\n*/\nconst isMultilingualNode = (val) => {\n\tif (typeof val !== \"object\" || val === null || Array.isArray(val)) return false;\n\tconst nodeType = getNodeType(val);\n\tif (nodeType === NodeTypes.TRANSLATION) return true;\n\tif (nodeType === NodeTypes.MARKDOWN || nodeType === NodeTypes.HTML || nodeType === NodeTypes.INSERTION) return isMultilingualNode(val[nodeType]);\n\tif (nodeType === NodeTypes.ENUMERATION || nodeType === NodeTypes.PLURAL || nodeType === NodeTypes.CONDITION || nodeType === NodeTypes.GENDER) {\n\t\tconst data = val[nodeType];\n\t\tif (data && typeof data === \"object\") return Object.values(data).some((v) => isMultilingualNode(v));\n\t}\n\treturn false;\n};\n/**\n* Recursively builds or updates an AST node for a given dictionary value.\n*/\nconst buildNodeForValue = (val, existingNode, fallbackLocale, requiredImports) => {\n\tconst unwrappedExisting = unwrap(existingNode);\n\tif (unwrappedExisting) {\n\t\tif (!(n.Literal.check(unwrappedExisting) || n.StringLiteral.check(unwrappedExisting) || n.NumericLiteral.check(unwrappedExisting) || n.BooleanLiteral.check(unwrappedExisting) || n.TemplateLiteral.check(unwrappedExisting) || n.ObjectExpression.check(unwrappedExisting) || n.ArrayExpression.check(unwrappedExisting) || n.CallExpression.check(unwrappedExisting) && n.Identifier.check(unwrappedExisting.callee) && [\n\t\t\t\"t\",\n\t\t\t\"enu\",\n\t\t\t\"plural\",\n\t\t\t\"cond\",\n\t\t\t\"gender\",\n\t\t\t\"insert\",\n\t\t\t\"md\",\n\t\t\t\"html\",\n\t\t\t\"file\",\n\t\t\t\"nest\"\n\t\t].includes(unwrappedExisting.callee.name))) return existingNode;\n\t}\n\tif (fallbackLocale && !existingNode && !isMultilingualNode(val)) {\n\t\tif (val === null) return b.literal(null);\n\t\tif (typeof val === \"string\" || typeof val === \"number\" || typeof val === \"boolean\") {\n\t\t\tif (typeof val === \"string\" && val.includes(\"\\n\")) return b.templateLiteral([b.templateElement({\n\t\t\t\traw: val,\n\t\t\t\tcooked: val\n\t\t\t}, true)], []);\n\t\t\treturn b.literal(val);\n\t\t}\n\t}\n\tif (fallbackLocale && existingNode && !isMultilingualNode(val)) {\n\t\tif (n.CallExpression.check(existingNode) && n.Identifier.check(existingNode.callee) && existingNode.callee.name === \"t\") {\n\t\t\tconst arg = unwrap(existingNode.arguments[0]);\n\t\t\tif (n.ObjectExpression.check(arg)) {\n\t\t\t\tif (typeof val === \"string\") syncNumericSuffixAcrossLocales(arg, fallbackLocale, val);\n\t\t\t\tupdateObjectLiteral(arg, { [fallbackLocale]: val }, fallbackLocale, requiredImports);\n\t\t\t\tif (!fallbackLocale) requiredImports.add(\"t\");\n\t\t\t\treturn existingNode;\n\t\t\t}\n\t\t}\n\t\tif ((!val || typeof val !== \"object\") && n.CallExpression.check(existingNode) && n.Identifier.check(existingNode.callee) && existingNode.callee.name === \"md\") {\n\t\t\tconst innerArg = existingNode.arguments[0];\n\t\t\tif (n.CallExpression.check(innerArg) && n.Identifier.check(innerArg.callee) && innerArg.callee.name === \"t\") {\n\t\t\t\tconst tArg = unwrap(innerArg.arguments[0]);\n\t\t\t\tif (n.ObjectExpression.check(tArg)) {\n\t\t\t\t\tif (typeof val === \"string\") syncNumericSuffixAcrossLocales(tArg, fallbackLocale, val);\n\t\t\t\t\tupdateObjectLiteral(tArg, { [fallbackLocale]: val }, fallbackLocale, requiredImports);\n\t\t\t\t\trequiredImports.add(\"md\");\n\t\t\t\t\trequiredImports.add(\"t\");\n\t\t\t\t\treturn existingNode;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tif (val === null) return b.literal(null);\n\tif (typeof val === \"string\" || typeof val === \"number\" || typeof val === \"boolean\") {\n\t\tif (unwrappedExisting) {\n\t\t\tif (n.TemplateLiteral.check(unwrappedExisting) && unwrappedExisting.expressions.length === 0) {\n\t\t\t\tunwrappedExisting.quasis[0].value.raw = String(val);\n\t\t\t\tunwrappedExisting.quasis[0].value.cooked = String(val);\n\t\t\t\treturn existingNode;\n\t\t\t}\n\t\t\tif (n.Literal.check(unwrappedExisting) || n.StringLiteral.check(unwrappedExisting)) {\n\t\t\t\tunwrappedExisting.value = val;\n\t\t\t\treturn existingNode;\n\t\t\t}\n\t\t}\n\t\tif (typeof val === \"string\" && val.includes(\"\\n\")) return b.templateLiteral([b.templateElement({\n\t\t\traw: val,\n\t\t\tcooked: val\n\t\t}, true)], []);\n\t\treturn b.literal(val);\n\t}\n\tif (Array.isArray(val)) if (unwrappedExisting && n.ArrayExpression.check(unwrappedExisting)) {\n\t\tconst elements = [...unwrappedExisting.elements];\n\t\tval.forEach((item, i) => {\n\t\t\telements[i] = buildNodeForValue(item, elements[i], fallbackLocale, requiredImports);\n\t\t});\n\t\tif (elements.length > val.length) elements.length = val.length;\n\t\tunwrappedExisting.elements = elements;\n\t\treturn existingNode;\n\t} else return b.arrayExpression(val.map((item) => buildNodeForValue(item, null, fallbackLocale, requiredImports)));\n\tconst nodeType = val && typeof val === \"object\" && !Array.isArray(val) ? getNodeType(val) : null;\n\tif (nodeType && [\n\t\tNodeTypes.TRANSLATION,\n\t\tNodeTypes.ENUMERATION,\n\t\tNodeTypes.PLURAL,\n\t\tNodeTypes.CONDITION,\n\t\tNodeTypes.GENDER,\n\t\tNodeTypes.INSERTION,\n\t\tNodeTypes.MARKDOWN,\n\t\tNodeTypes.HTML,\n\t\tNodeTypes.FILE,\n\t\tNodeTypes.NESTED,\n\t\tNodeTypes.ARRAY,\n\t\tNodeTypes.OBJECT,\n\t\tNodeTypes.REACT_NODE,\n\t\tNodeTypes.NUMBER,\n\t\tNodeTypes.BOOLEAN,\n\t\tNodeTypes.NULL,\n\t\tNodeTypes.UNKNOWN\n\t].includes(nodeType) && nodeType !== NodeTypes.TEXT) {\n\t\tconst nodeData = val[nodeType];\n\t\tlet calleeName = \"\";\n\t\tif (nodeType === NodeTypes.TRANSLATION) calleeName = \"t\";\n\t\telse if (nodeType === NodeTypes.ENUMERATION) calleeName = \"enu\";\n\t\telse if (nodeType === NodeTypes.PLURAL) calleeName = \"plural\";\n\t\telse if (nodeType === NodeTypes.CONDITION) calleeName = \"cond\";\n\t\telse if (nodeType === NodeTypes.GENDER) calleeName = \"gender\";\n\t\telse if (nodeType === NodeTypes.INSERTION) calleeName = \"insert\";\n\t\telse if (nodeType === NodeTypes.MARKDOWN) calleeName = \"md\";\n\t\telse if (nodeType === NodeTypes.HTML) calleeName = \"html\";\n\t\telse if (nodeType === NodeTypes.FILE) calleeName = \"file\";\n\t\telse if (nodeType === NodeTypes.NESTED) calleeName = \"nest\";\n\t\tif (calleeName) requiredImports.add(calleeName);\n\t\tconst isMatchingCall = existingNode && n.CallExpression.check(existingNode) && n.Identifier.check(existingNode.callee) && existingNode.callee.name === calleeName;\n\t\tif ([\n\t\t\t\"t\",\n\t\t\t\"enu\",\n\t\t\t\"plural\",\n\t\t\t\"cond\",\n\t\t\t\"gender\"\n\t\t].includes(calleeName)) {\n\t\t\tlet objArg = null;\n\t\t\tif (isMatchingCall && existingNode.arguments.length > 0 && n.ObjectExpression.check(existingNode.arguments[0])) objArg = existingNode.arguments[0];\n\t\t\telse objArg = b.objectExpression([]);\n\t\t\tupdateObjectLiteral(objArg, nodeData, fallbackLocale, requiredImports);\n\t\t\treturn isMatchingCall ? existingNode : b.callExpression(b.identifier(calleeName), [objArg]);\n\t\t}\n\t\tif ([\n\t\t\t\"md\",\n\t\t\t\"html\",\n\t\t\t\"insert\",\n\t\t\t\"file\"\n\t\t].includes(calleeName)) {\n\t\t\tconst argNode = buildNodeForValue(nodeData, isMatchingCall && existingNode.arguments.length > 0 ? existingNode.arguments[0] : null, fallbackLocale, requiredImports);\n\t\t\tif (isMatchingCall) {\n\t\t\t\texistingNode.arguments[0] = argNode;\n\t\t\t\treturn existingNode;\n\t\t\t}\n\t\t\treturn b.callExpression(b.identifier(calleeName), [argNode]);\n\t\t}\n\t\tif (calleeName === \"nest\") {\n\t\t\tconst args = [b.literal(nodeData.dictionaryKey)];\n\t\t\tif (nodeData.path) args.push(b.literal(nodeData.path));\n\t\t\tif (isMatchingCall) {\n\t\t\t\texistingNode.arguments = args;\n\t\t\t\treturn existingNode;\n\t\t\t}\n\t\t\treturn b.callExpression(b.identifier(\"nest\"), args);\n\t\t}\n\t}\n\tconst objNode = unwrappedExisting && n.ObjectExpression.check(unwrappedExisting) ? unwrappedExisting : b.objectExpression([]);\n\tupdateObjectLiteral(objNode, val, fallbackLocale, requiredImports);\n\treturn existingNode && unwrappedExisting === existingNode ? objNode : existingNode || objNode;\n};\n/**\n* Recursively updates the AST object literal properties.\n*/\nconst updateObjectLiteral = (node, data, fallbackLocale, requiredImports) => {\n\tfor (const [key, val] of Object.entries(data)) {\n\t\tif (val === void 0) continue;\n\t\tconst existingProp = getMatchingProperty(node, key);\n\t\tif (existingProp) existingProp.value = buildNodeForValue(val, existingProp.value, fallbackLocale, requiredImports);\n\t\telse {\n\t\t\tconst keyNode = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key) ? b.identifier(key) : b.literal(key);\n\t\t\tconst valueNode = buildNodeForValue(val, null, fallbackLocale, requiredImports);\n\t\t\tnode.properties.push(b.property(\"init\", keyNode, valueNode));\n\t\t}\n\t}\n};\n/**\n* Modifies the AST's top-level imports to inject dynamically needed helper utilities seamlessly.\n*/\nconst addImports = (ast, requiredImports, isESM) => {\n\tif (requiredImports.size === 0) return;\n\tconst existingCoreImports = /* @__PURE__ */ new Set();\n\tlet coreImportPath = null;\n\trecast.visit(ast, {\n\t\tvisitImportDeclaration(path) {\n\t\t\tif (path.node.source.value === \"intlayer\") {\n\t\t\t\tcoreImportPath = path;\n\t\t\t\tpath.node.specifiers?.forEach((spec) => {\n\t\t\t\t\tif (n.ImportSpecifier.check(spec) && typeof spec.imported.name === \"string\") existingCoreImports.add(spec.imported.name);\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn false;\n\t\t},\n\t\tvisitVariableDeclaration(path) {\n\t\t\tpath.node.declarations.forEach((decl) => {\n\t\t\t\tif (n.VariableDeclarator.check(decl) && n.CallExpression.check(decl.init) && n.Identifier.check(decl.init.callee) && decl.init.callee.name === \"require\") {\n\t\t\t\t\tconst arg = decl.init.arguments[0];\n\t\t\t\t\tif (n.Literal.check(arg)) {\n\t\t\t\t\t\tif (arg.value === \"intlayer\") {\n\t\t\t\t\t\t\tif (n.ObjectPattern.check(decl.id)) decl.id.properties.forEach((prop) => {\n\t\t\t\t\t\t\t\tif (n.Property.check(prop) && (n.Identifier.check(prop.key) || n.Identifier.check(prop.value))) {\n\t\t\t\t\t\t\t\t\tconst name = n.Identifier.check(prop.key) ? prop.key.name : prop.value.name;\n\t\t\t\t\t\t\t\t\texistingCoreImports.add(name);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\telse if (n.Identifier.check(decl.id)) existingCoreImports.add(decl.id.name);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t\treturn false;\n\t\t}\n\t});\n\tconst missingCore = Array.from(requiredImports).filter((imp) => !existingCoreImports.has(imp));\n\tif (missingCore.length === 0) return;\n\tif (isESM) if (coreImportPath) {\n\t\tmissingCore.forEach((imp) => {\n\t\t\tcoreImportPath.node.specifiers.push(b.importSpecifier(b.identifier(imp)));\n\t\t});\n\t\tcoreImportPath.node.specifiers.sort((a, b) => a.imported.name.localeCompare(b.imported.name));\n\t} else {\n\t\tconst specifiers = missingCore.sort().map((imp) => b.importSpecifier(b.identifier(imp)));\n\t\tconst newImport = b.importDeclaration(specifiers, b.literal(\"intlayer\"));\n\t\tast.program.body.unshift(newImport);\n\t}\n\telse {\n\t\tlet insertIndex = 0;\n\t\tif (ast.program.body.length > 0 && n.ExpressionStatement.check(ast.program.body[0]) && n.Literal.check(ast.program.body[0].expression)) insertIndex = 1;\n\t\tconst cjsLines = [];\n\t\tconst properties = missingCore.sort().map((imp) => {\n\t\t\tconst prop = b.property(\"init\", b.identifier(imp), b.identifier(imp));\n\t\t\tprop.shorthand = true;\n\t\t\treturn prop;\n\t\t});\n\t\tcjsLines.push(b.variableDeclaration(\"const\", [b.variableDeclarator(b.objectPattern(properties), b.callExpression(b.identifier(\"require\"), [b.literal(\"intlayer\")]))]));\n\t\tast.program.body.splice(insertIndex, 0, ...cjsLines);\n\t}\n};\n/**\n* Updates a JS/TS file seamlessly to map new localization keys, arrays, complex nodes and nested dictionaries gracefully using AST updates via Recast parser.\n*/\nconst transformJSFile = async (fileContent, dictionary, fallbackLocale, noMetadata) => {\n\tif (!dictionary || typeof dictionary !== \"object\") return fileContent;\n\tlet ast;\n\ttry {\n\t\tast = recast.parse(fileContent, { parser: babelTsParser });\n\t} catch (error) {\n\t\tconsole.error({ error });\n\t\treturn fileContent;\n\t}\n\tlet rootObject = null;\n\tlet isESM = false;\n\trecast.visit(ast, {\n\t\tvisitExportDefaultDeclaration() {\n\t\t\tisESM = true;\n\t\t\treturn false;\n\t\t},\n\t\tvisitImportDeclaration() {\n\t\t\tisESM = true;\n\t\t\treturn false;\n\t\t}\n\t});\n\trecast.visit(ast, {\n\t\tvisitExportDefaultDeclaration(path) {\n\t\t\tconst decl = path.node.declaration;\n\t\t\tconst unwrappedDecl = unwrap(decl);\n\t\t\tif (n.ObjectExpression.check(unwrappedDecl)) rootObject = unwrappedDecl;\n\t\t\telse if (n.Identifier.check(unwrappedDecl)) {\n\t\t\t\tconst varName = unwrappedDecl.name;\n\t\t\t\trecast.visit(ast, { visitVariableDeclarator(vp) {\n\t\t\t\t\tconst unwrappedInit = unwrap(vp.node.init);\n\t\t\t\t\tif (n.Identifier.check(vp.node.id) && vp.node.id.name === varName && n.ObjectExpression.check(unwrappedInit)) rootObject = unwrappedInit;\n\t\t\t\t\treturn false;\n\t\t\t\t} });\n\t\t\t}\n\t\t\treturn false;\n\t\t},\n\t\tvisitAssignmentExpression(path) {\n\t\t\tconst left = path.node.left;\n\t\t\tif (n.MemberExpression.check(left)) {\n\t\t\t\tif (n.Identifier.check(left.object) && left.object.name === \"module\" && n.Identifier.check(left.property) && left.property.name === \"exports\") {\n\t\t\t\t\tconst unwrappedRight = unwrap(path.node.right);\n\t\t\t\t\tif (n.ObjectExpression.check(unwrappedRight)) rootObject = unwrappedRight;\n\t\t\t\t}\n\t\t\t\tif (n.Identifier.check(left.object) && left.object.name === \"exports\" && n.Identifier.check(left.property) && left.property.name === \"default\") {\n\t\t\t\t\tconst unwrappedRight = unwrap(path.node.right);\n\t\t\t\t\tif (n.ObjectExpression.check(unwrappedRight)) rootObject = unwrappedRight;\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.traverse(path);\n\t\t}\n\t});\n\tif (!rootObject) recast.visit(ast, { visitVariableDeclarator(path) {\n\t\tconst unwrappedInit = unwrap(path.node.init);\n\t\tif (!rootObject && n.ObjectExpression.check(unwrappedInit)) rootObject = unwrappedInit;\n\t\treturn false;\n\t} });\n\tif (!rootObject) return fileContent;\n\tconst requiredImports = /* @__PURE__ */ new Set();\n\tconst effectiveFallbackLocale = fallbackLocale ?? \"en\";\n\tconst metadataProperties = [\n\t\t\"id\",\n\t\t\"locale\",\n\t\t\"filled\",\n\t\t\"fill\",\n\t\t\"title\",\n\t\t\"description\",\n\t\t\"tags\",\n\t\t\"version\",\n\t\t\"priority\",\n\t\t\"contentAutoTransformation\"\n\t];\n\tif (noMetadata) {\n\t\trootObject.properties = rootObject.properties.filter((prop) => {\n\t\t\tif (n.Property.check(prop) || n.ObjectProperty.check(prop)) {\n\t\t\t\tlet propName = \"\";\n\t\t\t\tif (n.Identifier.check(prop.key)) propName = prop.key.name;\n\t\t\t\telse if (n.StringLiteral.check(prop.key)) propName = prop.key.value;\n\t\t\t\telse if (n.Literal.check(prop.key)) propName = String(prop.key.value);\n\t\t\t\treturn ![\n\t\t\t\t\t\"key\",\n\t\t\t\t\t\"content\",\n\t\t\t\t\t...metadataProperties\n\t\t\t\t].includes(propName);\n\t\t\t}\n\t\t\treturn true;\n\t\t});\n\t\trecast.visit(ast, { visitNode(path) {\n\t\t\tconst node = path.node;\n\t\t\tif ((n.TSSatisfiesExpression?.check(node) || node.type === \"TSSatisfiesExpression\") && node.typeAnnotation && n.TSTypeReference.check(node.typeAnnotation) && n.Identifier.check(node.typeAnnotation.typeName) && node.typeAnnotation.typeName.name === \"Dictionary\") node.typeAnnotation = b.tsIndexedAccessType(b.tsTypeReference(b.identifier(\"Dictionary\")), b.tsLiteralType(b.stringLiteral(\"content\")));\n\t\t\tthis.traverse(path);\n\t\t} });\n\t} else for (const prop of metadataProperties) if (dictionary[prop] !== void 0) updateObjectLiteral(rootObject, { [prop]: dictionary[prop] }, void 0, requiredImports);\n\tif (dictionary.content !== void 0) updateObjectLiteral(rootObject, noMetadata ? dictionary.content : { content: dictionary.content }, effectiveFallbackLocale, requiredImports);\n\taddImports(ast, requiredImports, isESM);\n\treturn recast.print(ast).code;\n};\n\n//#endregion\nexport { transformJSFile };\n//# sourceMappingURL=transformJSFile.mjs.map"],"mappings":";;;;;;AAMA,MAAM,IA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AAS,SAAS,aAAc,MAAK,iBAAiB,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,WAAW,aAAa,CAAC,EAAE,EAAE,cAAc,EAAE,cAAc,UAAU,CAAC,CAAC;AAC7Y,QAAK,SAAS,KAAK;KACjB,CAAC;OACE,MAAK,MAAM,QAAQ,mBAAoB,KAAI,WAAW,UAAU,KAAK,EAAG,qBAAoB,YAAY,GAAG,OAAO,WAAW,OAAO,EAAE,KAAK,GAAG,gBAAgB;AACrK,KAAI,WAAW,YAAY,KAAK,EAAG,qBAAoB,YAAY,aAAa,WAAW,UAAU,EAAE,SAAS,WAAW,SAAS,EAAE,yBAAyB,gBAAgB;AAC/K,YAAW,KAAK,iBAAiB,MAAM;AACvC,QAAO,OAAO,MAAM,IAAI,CAAC"}
@@ -0,0 +1,127 @@
1
+ const require_runtime = require('../../../../../../_virtual/_rolldown/runtime.cjs');
2
+ let _Users_aymericpineau_Documents_intlayer__node_modules__bun_recast_0_23_11_node_modules_recast_main_js = require("/Users/aymericpineau/Documents/intlayer_/node_modules/.bun/recast@0.23.11/node_modules/recast/main.js");
3
+ _Users_aymericpineau_Documents_intlayer__node_modules__bun_recast_0_23_11_node_modules_recast_main_js = require_runtime.__toESM(_Users_aymericpineau_Documents_intlayer__node_modules__bun_recast_0_23_11_node_modules_recast_main_js, 1);
4
+
5
+ //#region ../../@intlayer/chokidar/dist/esm/writeContentDeclaration/transformJSONFile.mjs
6
+ const b = _Users_aymericpineau_Documents_intlayer__node_modules__bun_recast_0_23_11_node_modules_recast_main_js.types.builders;
7
+ const n = _Users_aymericpineau_Documents_intlayer__node_modules__bun_recast_0_23_11_node_modules_recast_main_js.types.namedTypes;
8
+ /**
9
+ * Checks if a value is a plain object (and not null/array)
10
+ */
11
+ const isPlainObject = (value) => {
12
+ return typeof value === "object" && value !== null && !Array.isArray(value);
13
+ };
14
+ /**
15
+ * Checks if a recast AST node value matches the incoming primitive value.
16
+ */
17
+ const isPrimitiveEqual = (astNode, val) => {
18
+ if (val === null) return n.Literal.check(astNode) && astNode.value === null;
19
+ if (typeof val === "string" || typeof val === "number" || typeof val === "boolean") return (n.Literal.check(astNode) || n.StringLiteral.check(astNode) || n.NumericLiteral.check(astNode) || n.BooleanLiteral.check(astNode)) && astNode.value === val;
20
+ return false;
21
+ };
22
+ /**
23
+ * Robustly finds a property in a recast ObjectExpression.
24
+ * Handles quoted ("key") or unquoted (key) properties.
25
+ */
26
+ const getMatchingProperty = (node, key) => {
27
+ return node.properties.find((prop) => {
28
+ if (n.Property.check(prop) || n.ObjectProperty.check(prop)) {
29
+ if (n.Identifier.check(prop.key) && prop.key.name === key) return true;
30
+ if (n.StringLiteral.check(prop.key) && prop.key.value === key) return true;
31
+ if (n.Literal.check(prop.key) && prop.key.value === key) return true;
32
+ }
33
+ return false;
34
+ });
35
+ };
36
+ /**
37
+ * Recursively builds a clean recast AST node from a plain JS value.
38
+ * Because these nodes lack `loc` tracking, recast is forced to pretty-print them.
39
+ */
40
+ const buildASTNode = (val) => {
41
+ if (val === null) return b.literal(null);
42
+ if (typeof val === "string" || typeof val === "number" || typeof val === "boolean") return b.literal(val);
43
+ if (Array.isArray(val)) return b.arrayExpression(val.map((item) => buildASTNode(item)));
44
+ if (isPlainObject(val)) return b.objectExpression(Object.entries(val).filter(([, v]) => v !== void 0).map(([k, v]) => b.property("init", b.stringLiteral(k), buildASTNode(v))));
45
+ return b.literal(null);
46
+ };
47
+ /**
48
+ * Recursively updates the AST object literal with new data.
49
+ */
50
+ const updateObjectLiteral = (node, data) => {
51
+ for (const [key, val] of Object.entries(data)) {
52
+ if (val === void 0) continue;
53
+ const existingProp = getMatchingProperty(node, key);
54
+ if (existingProp?.comments) existingProp.comments.forEach((c) => {
55
+ if ((c.type === "Line" || c.type === "CommentLine") && c.trailing) {
56
+ c.type = c.type === "Line" ? "Block" : "CommentBlock";
57
+ c.value = `__INLINE_LINE__${c.value}`;
58
+ c.leading = false;
59
+ c.trailing = true;
60
+ }
61
+ });
62
+ if (isPlainObject(val)) if (existingProp && n.ObjectExpression.check(existingProp.value)) updateObjectLiteral(existingProp.value, val);
63
+ else if (existingProp) {
64
+ if (!(n.Literal.check(existingProp.value) && existingProp.value.value === val)) existingProp.value = buildASTNode(val);
65
+ } else node.properties.push(b.property("init", b.stringLiteral(key), buildASTNode(val)));
66
+ else if (existingProp) {
67
+ if (!isPrimitiveEqual(existingProp.value, val)) existingProp.value = buildASTNode(val);
68
+ } else node.properties.push(b.property("init", b.stringLiteral(key), buildASTNode(val)));
69
+ }
70
+ };
71
+ const transformJSONFile = (fileContent, dictionary, noMetadata) => {
72
+ const wrappedContent = `const _config = ${fileContent.trim() || "{}"};`;
73
+ let ast;
74
+ try {
75
+ ast = _Users_aymericpineau_Documents_intlayer__node_modules__bun_recast_0_23_11_node_modules_recast_main_js.parse(wrappedContent);
76
+ } catch {
77
+ return JSON.stringify(noMetadata ? dictionary.content : dictionary, null, 2);
78
+ }
79
+ const declaration = ast.program.body[0];
80
+ let objectLiteral;
81
+ if (n.VariableDeclaration.check(declaration) && declaration.declarations.length > 0 && n.VariableDeclarator.check(declaration.declarations[0]) && n.ObjectExpression.check(declaration.declarations[0].init)) objectLiteral = declaration.declarations[0].init;
82
+ if (noMetadata) {
83
+ const metadataProperties = [
84
+ "id",
85
+ "locale",
86
+ "filled",
87
+ "fill",
88
+ "title",
89
+ "description",
90
+ "tags",
91
+ "version",
92
+ "priority",
93
+ "contentAutoTransformation",
94
+ "$schema"
95
+ ];
96
+ for (let i = objectLiteral.properties.length - 1; i >= 0; i--) {
97
+ const prop = objectLiteral.properties[i];
98
+ if (n.Property.check(prop) || n.ObjectProperty.check(prop)) {
99
+ let propName = "";
100
+ if (n.Identifier.check(prop.key)) propName = prop.key.name;
101
+ else if (n.StringLiteral.check(prop.key)) propName = prop.key.value;
102
+ else if (n.Literal.check(prop.key)) propName = String(prop.key.value);
103
+ if ([
104
+ "key",
105
+ "content",
106
+ ...metadataProperties
107
+ ].includes(propName)) objectLiteral.properties.splice(i, 1);
108
+ }
109
+ }
110
+ }
111
+ updateObjectLiteral(objectLiteral, noMetadata ? dictionary.content : dictionary);
112
+ const printedCode = _Users_aymericpineau_Documents_intlayer__node_modules__bun_recast_0_23_11_node_modules_recast_main_js.print(ast, {
113
+ tabWidth: 2,
114
+ quote: "double",
115
+ trailingComma: false
116
+ }).code;
117
+ const startIndex = printedCode.indexOf("{");
118
+ const endIndex = printedCode.lastIndexOf("}");
119
+ let finalOutput = printedCode.substring(startIndex, endIndex + 1);
120
+ finalOutput = finalOutput.replace(/\s*\/\*__INLINE_LINE__(.*?)\*\/(\s*,?)/g, "$2 //$1");
121
+ finalOutput = finalOutput.replace(/\n[ \t]*\n/g, "\n");
122
+ return finalOutput;
123
+ };
124
+
125
+ //#endregion
126
+ exports.transformJSONFile = transformJSONFile;
127
+ //# sourceMappingURL=transformJSONFile.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transformJSONFile.cjs","names":["recast"],"sources":["../../../../../../../../../@intlayer/chokidar/dist/esm/writeContentDeclaration/transformJSONFile.mjs"],"sourcesContent":["import * as recast from \"recast\";\n\n//#region src/writeContentDeclaration/transformJSONFile.ts\nconst b = recast.types.builders;\nconst n = recast.types.namedTypes;\n/**\n* Checks if a value is a plain object (and not null/array)\n*/\nconst isPlainObject = (value) => {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n};\n/**\n* Checks if a recast AST node value matches the incoming primitive value.\n*/\nconst isPrimitiveEqual = (astNode, val) => {\n\tif (val === null) return n.Literal.check(astNode) && astNode.value === null;\n\tif (typeof val === \"string\" || typeof val === \"number\" || typeof val === \"boolean\") return (n.Literal.check(astNode) || n.StringLiteral.check(astNode) || n.NumericLiteral.check(astNode) || n.BooleanLiteral.check(astNode)) && astNode.value === val;\n\treturn false;\n};\n/**\n* Robustly finds a property in a recast ObjectExpression.\n* Handles quoted (\"key\") or unquoted (key) properties.\n*/\nconst getMatchingProperty = (node, key) => {\n\treturn node.properties.find((prop) => {\n\t\tif (n.Property.check(prop) || n.ObjectProperty.check(prop)) {\n\t\t\tif (n.Identifier.check(prop.key) && prop.key.name === key) return true;\n\t\t\tif (n.StringLiteral.check(prop.key) && prop.key.value === key) return true;\n\t\t\tif (n.Literal.check(prop.key) && prop.key.value === key) return true;\n\t\t}\n\t\treturn false;\n\t});\n};\n/**\n* Recursively builds a clean recast AST node from a plain JS value.\n* Because these nodes lack `loc` tracking, recast is forced to pretty-print them.\n*/\nconst buildASTNode = (val) => {\n\tif (val === null) return b.literal(null);\n\tif (typeof val === \"string\" || typeof val === \"number\" || typeof val === \"boolean\") return b.literal(val);\n\tif (Array.isArray(val)) return b.arrayExpression(val.map((item) => buildASTNode(item)));\n\tif (isPlainObject(val)) return b.objectExpression(Object.entries(val).filter(([, v]) => v !== void 0).map(([k, v]) => b.property(\"init\", b.stringLiteral(k), buildASTNode(v))));\n\treturn b.literal(null);\n};\n/**\n* Recursively updates the AST object literal with new data.\n*/\nconst updateObjectLiteral = (node, data) => {\n\tfor (const [key, val] of Object.entries(data)) {\n\t\tif (val === void 0) continue;\n\t\tconst existingProp = getMatchingProperty(node, key);\n\t\tif (existingProp?.comments) existingProp.comments.forEach((c) => {\n\t\t\tif ((c.type === \"Line\" || c.type === \"CommentLine\") && c.trailing) {\n\t\t\t\tc.type = c.type === \"Line\" ? \"Block\" : \"CommentBlock\";\n\t\t\t\tc.value = `__INLINE_LINE__${c.value}`;\n\t\t\t\tc.leading = false;\n\t\t\t\tc.trailing = true;\n\t\t\t}\n\t\t});\n\t\tif (isPlainObject(val)) if (existingProp && n.ObjectExpression.check(existingProp.value)) updateObjectLiteral(existingProp.value, val);\n\t\telse if (existingProp) {\n\t\t\tif (!(n.Literal.check(existingProp.value) && existingProp.value.value === val)) existingProp.value = buildASTNode(val);\n\t\t} else node.properties.push(b.property(\"init\", b.stringLiteral(key), buildASTNode(val)));\n\t\telse if (existingProp) {\n\t\t\tif (!isPrimitiveEqual(existingProp.value, val)) existingProp.value = buildASTNode(val);\n\t\t} else node.properties.push(b.property(\"init\", b.stringLiteral(key), buildASTNode(val)));\n\t}\n};\nconst transformJSONFile = (fileContent, dictionary, noMetadata) => {\n\tconst wrappedContent = `const _config = ${fileContent.trim() || \"{}\"};`;\n\tlet ast;\n\ttry {\n\t\tast = recast.parse(wrappedContent);\n\t} catch {\n\t\treturn JSON.stringify(noMetadata ? dictionary.content : dictionary, null, 2);\n\t}\n\tconst declaration = ast.program.body[0];\n\tlet objectLiteral;\n\tif (n.VariableDeclaration.check(declaration) && declaration.declarations.length > 0 && n.VariableDeclarator.check(declaration.declarations[0]) && n.ObjectExpression.check(declaration.declarations[0].init)) objectLiteral = declaration.declarations[0].init;\n\tif (noMetadata) {\n\t\tconst metadataProperties = [\n\t\t\t\"id\",\n\t\t\t\"locale\",\n\t\t\t\"filled\",\n\t\t\t\"fill\",\n\t\t\t\"title\",\n\t\t\t\"description\",\n\t\t\t\"tags\",\n\t\t\t\"version\",\n\t\t\t\"priority\",\n\t\t\t\"contentAutoTransformation\",\n\t\t\t\"$schema\"\n\t\t];\n\t\tfor (let i = objectLiteral.properties.length - 1; i >= 0; i--) {\n\t\t\tconst prop = objectLiteral.properties[i];\n\t\t\tif (n.Property.check(prop) || n.ObjectProperty.check(prop)) {\n\t\t\t\tlet propName = \"\";\n\t\t\t\tif (n.Identifier.check(prop.key)) propName = prop.key.name;\n\t\t\t\telse if (n.StringLiteral.check(prop.key)) propName = prop.key.value;\n\t\t\t\telse if (n.Literal.check(prop.key)) propName = String(prop.key.value);\n\t\t\t\tif ([\n\t\t\t\t\t\"key\",\n\t\t\t\t\t\"content\",\n\t\t\t\t\t...metadataProperties\n\t\t\t\t].includes(propName)) objectLiteral.properties.splice(i, 1);\n\t\t\t}\n\t\t}\n\t}\n\tupdateObjectLiteral(objectLiteral, noMetadata ? dictionary.content : dictionary);\n\tconst printedCode = recast.print(ast, {\n\t\ttabWidth: 2,\n\t\tquote: \"double\",\n\t\ttrailingComma: false\n\t}).code;\n\tconst startIndex = printedCode.indexOf(\"{\");\n\tconst endIndex = printedCode.lastIndexOf(\"}\");\n\tlet finalOutput = printedCode.substring(startIndex, endIndex + 1);\n\tfinalOutput = finalOutput.replace(/\\s*\\/\\*__INLINE_LINE__(.*?)\\*\\/(\\s*,?)/g, \"$2 //$1\");\n\tfinalOutput = finalOutput.replace(/\\n[ \\t]*\\n/g, \"\\n\");\n\treturn finalOutput;\n};\n\n//#endregion\nexport { transformJSONFile };\n//# sourceMappingURL=transformJSONFile.mjs.map"],"mappings":";;;;;AAGA,MAAM,IAAIA,sGAAO,MAAM;AACvB,MAAM,IAAIA,sGAAO,MAAM;;;;AAIvB,MAAM,iBAAiB,UAAU;AAChC,QAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,MAAM;;;;;AAK5E,MAAM,oBAAoB,SAAS,QAAQ;AAC1C,KAAI,QAAQ,KAAM,QAAO,EAAE,QAAQ,MAAM,QAAQ,IAAI,QAAQ,UAAU;AACvE,KAAI,OAAO,QAAQ,YAAY,OAAO,QAAQ,YAAY,OAAO,QAAQ,UAAW,SAAQ,EAAE,QAAQ,MAAM,QAAQ,IAAI,EAAE,cAAc,MAAM,QAAQ,IAAI,EAAE,eAAe,MAAM,QAAQ,IAAI,EAAE,eAAe,MAAM,QAAQ,KAAK,QAAQ,UAAU;AACnP,QAAO;;;;;;AAMR,MAAM,uBAAuB,MAAM,QAAQ;AAC1C,QAAO,KAAK,WAAW,MAAM,SAAS;AACrC,MAAI,EAAE,SAAS,MAAM,KAAK,IAAI,EAAE,eAAe,MAAM,KAAK,EAAE;AAC3D,OAAI,EAAE,WAAW,MAAM,KAAK,IAAI,IAAI,KAAK,IAAI,SAAS,IAAK,QAAO;AAClE,OAAI,EAAE,cAAc,MAAM,KAAK,IAAI,IAAI,KAAK,IAAI,UAAU,IAAK,QAAO;AACtE,OAAI,EAAE,QAAQ,MAAM,KAAK,IAAI,IAAI,KAAK,IAAI,UAAU,IAAK,QAAO;;AAEjE,SA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