@intlayer/chokidar 6.1.6 → 7.0.0-canary.1

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 (464) hide show
  1. package/dist/{cjs → assets}/getContentDeclarationFileTemplate/cjsTemplate.txt +3 -2
  2. package/dist/{cjs → assets}/getContentDeclarationFileTemplate/esmTemplate.txt +2 -1
  3. package/dist/{cjs → assets}/getContentDeclarationFileTemplate/jsonTemplate.txt +2 -1
  4. package/dist/{cjs → assets}/getContentDeclarationFileTemplate/tsTemplate.txt +2 -1
  5. package/dist/cjs/_virtual/_utils_asset.cjs +104 -0
  6. package/dist/cjs/_virtual/rolldown_runtime.cjs +25 -0
  7. package/dist/cjs/buildIntlayerDictionary/buildIntlayerDictionary.cjs +42 -80
  8. package/dist/cjs/buildIntlayerDictionary/buildIntlayerDictionary.cjs.map +1 -1
  9. package/dist/cjs/buildIntlayerDictionary/index.cjs +5 -25
  10. package/dist/cjs/buildIntlayerDictionary/processContentDeclaration.cjs +21 -42
  11. package/dist/cjs/buildIntlayerDictionary/processContentDeclaration.cjs.map +1 -1
  12. package/dist/cjs/buildIntlayerDictionary/writeDynamicDictionary.cjs +79 -116
  13. package/dist/cjs/buildIntlayerDictionary/writeDynamicDictionary.cjs.map +1 -1
  14. package/dist/cjs/buildIntlayerDictionary/writeFetchDictionary.cjs +62 -86
  15. package/dist/cjs/buildIntlayerDictionary/writeFetchDictionary.cjs.map +1 -1
  16. package/dist/cjs/buildIntlayerDictionary/writeMergedDictionary.cjs +48 -69
  17. package/dist/cjs/buildIntlayerDictionary/writeMergedDictionary.cjs.map +1 -1
  18. package/dist/cjs/buildIntlayerDictionary/writeRemoteDictionary.cjs +42 -52
  19. package/dist/cjs/buildIntlayerDictionary/writeRemoteDictionary.cjs.map +1 -1
  20. package/dist/cjs/buildIntlayerDictionary/writeUnmergedDictionary.cjs +60 -82
  21. package/dist/cjs/buildIntlayerDictionary/writeUnmergedDictionary.cjs.map +1 -1
  22. package/dist/cjs/cleanOutputDir.cjs +20 -60
  23. package/dist/cjs/cleanOutputDir.cjs.map +1 -1
  24. package/dist/cjs/createDictionaryEntryPoint/createDictionaryEntryPoint.cjs +64 -103
  25. package/dist/cjs/createDictionaryEntryPoint/createDictionaryEntryPoint.cjs.map +1 -1
  26. package/dist/cjs/createDictionaryEntryPoint/generateDictionaryListContent.cjs +41 -73
  27. package/dist/cjs/createDictionaryEntryPoint/generateDictionaryListContent.cjs.map +1 -1
  28. package/dist/cjs/createDictionaryEntryPoint/getBuiltDictionariesPath.cjs +19 -49
  29. package/dist/cjs/createDictionaryEntryPoint/getBuiltDictionariesPath.cjs.map +1 -1
  30. package/dist/cjs/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.cjs +20 -50
  31. package/dist/cjs/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.cjs.map +1 -1
  32. package/dist/cjs/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.cjs +20 -50
  33. package/dist/cjs/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.cjs.map +1 -1
  34. package/dist/cjs/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.cjs +19 -49
  35. package/dist/cjs/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.cjs.map +1 -1
  36. package/dist/cjs/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.cjs +19 -49
  37. package/dist/cjs/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.cjs.map +1 -1
  38. package/dist/cjs/createDictionaryEntryPoint/index.cjs +15 -35
  39. package/dist/cjs/createType/createModuleAugmentation.cjs +56 -108
  40. package/dist/cjs/createType/createModuleAugmentation.cjs.map +1 -1
  41. package/dist/cjs/createType/createType.cjs +29 -58
  42. package/dist/cjs/createType/createType.cjs.map +1 -1
  43. package/dist/cjs/createType/index.cjs +7 -25
  44. package/dist/cjs/fetchDistantDictionaries.cjs +49 -77
  45. package/dist/cjs/fetchDistantDictionaries.cjs.map +1 -1
  46. package/dist/cjs/filterInvalidDictionaries.cjs +26 -59
  47. package/dist/cjs/filterInvalidDictionaries.cjs.map +1 -1
  48. package/dist/cjs/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.cjs +32 -68
  49. package/dist/cjs/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.cjs.map +1 -1
  50. package/dist/cjs/handleAdditionalContentDeclarationFile.cjs +32 -51
  51. package/dist/cjs/handleAdditionalContentDeclarationFile.cjs.map +1 -1
  52. package/dist/cjs/handleContentDeclarationFileChange.cjs +35 -56
  53. package/dist/cjs/handleContentDeclarationFileChange.cjs.map +1 -1
  54. package/dist/cjs/handleUnlinkedContentDeclarationFile.cjs +36 -0
  55. package/dist/cjs/handleUnlinkedContentDeclarationFile.cjs.map +1 -0
  56. package/dist/cjs/index.cjs +103 -156
  57. package/dist/cjs/listDictionariesPath.cjs +27 -59
  58. package/dist/cjs/listDictionariesPath.cjs.map +1 -1
  59. package/dist/cjs/listGitFiles.cjs +93 -162
  60. package/dist/cjs/listGitFiles.cjs.map +1 -1
  61. package/dist/cjs/loadDictionaries/getIntlayerBundle.cjs +70 -0
  62. package/dist/cjs/loadDictionaries/getIntlayerBundle.cjs.map +1 -0
  63. package/dist/cjs/loadDictionaries/index.cjs +11 -29
  64. package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs +68 -90
  65. package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs.map +1 -1
  66. package/dist/cjs/loadDictionaries/loadDictionaries.cjs +111 -166
  67. package/dist/cjs/loadDictionaries/loadDictionaries.cjs.map +1 -1
  68. package/dist/cjs/loadDictionaries/loadLocalDictionaries.cjs +27 -53
  69. package/dist/cjs/loadDictionaries/loadLocalDictionaries.cjs.map +1 -1
  70. package/dist/cjs/loadDictionaries/loadRemoteDictionaries.cjs +60 -102
  71. package/dist/cjs/loadDictionaries/loadRemoteDictionaries.cjs.map +1 -1
  72. package/dist/cjs/loadDictionaries/log.cjs +107 -182
  73. package/dist/cjs/loadDictionaries/log.cjs.map +1 -1
  74. package/dist/cjs/prepareIntlayer.cjs +73 -130
  75. package/dist/cjs/prepareIntlayer.cjs.map +1 -1
  76. package/dist/cjs/reduceDictionaryContent/applyMask.cjs +27 -61
  77. package/dist/cjs/reduceDictionaryContent/applyMask.cjs.map +1 -1
  78. package/dist/cjs/reduceDictionaryContent/reduceDictionaryContent.cjs +10 -32
  79. package/dist/cjs/reduceDictionaryContent/reduceDictionaryContent.cjs.map +1 -1
  80. package/dist/cjs/utils/chunkJSON.cjs +329 -0
  81. package/dist/cjs/utils/chunkJSON.cjs.map +1 -0
  82. package/dist/cjs/utils/extractErrorMessage.cjs +92 -135
  83. package/dist/cjs/utils/extractErrorMessage.cjs.map +1 -1
  84. package/dist/cjs/utils/formatter.cjs +19 -49
  85. package/dist/cjs/utils/formatter.cjs.map +1 -1
  86. package/dist/cjs/utils/getChunk.cjs +34 -0
  87. package/dist/cjs/utils/getChunk.cjs.map +1 -0
  88. package/dist/cjs/utils/getFileHash.cjs +9 -40
  89. package/dist/cjs/utils/getFileHash.cjs.map +1 -1
  90. package/dist/cjs/utils/getFormatFromExtension.cjs +23 -54
  91. package/dist/cjs/utils/getFormatFromExtension.cjs.map +1 -1
  92. package/dist/cjs/utils/kebabCaseToCamelCase.cjs +11 -36
  93. package/dist/cjs/utils/kebabCaseToCamelCase.cjs.map +1 -1
  94. package/dist/cjs/utils/pLimit.cjs +128 -0
  95. package/dist/cjs/utils/pLimit.cjs.map +1 -0
  96. package/dist/cjs/utils/parallelize.cjs +10 -169
  97. package/dist/cjs/utils/parallelize.cjs.map +1 -1
  98. package/dist/cjs/utils/parallelizeGlobal.cjs +29 -0
  99. package/dist/cjs/utils/parallelizeGlobal.cjs.map +1 -0
  100. package/dist/cjs/utils/reduceObjectFormat.cjs +31 -0
  101. package/dist/cjs/utils/reduceObjectFormat.cjs.map +1 -0
  102. package/dist/cjs/utils/resolveObjectPromises.cjs +18 -48
  103. package/dist/cjs/utils/resolveObjectPromises.cjs.map +1 -1
  104. package/dist/cjs/utils/runOnce.cjs +80 -57
  105. package/dist/cjs/utils/runOnce.cjs.map +1 -1
  106. package/dist/cjs/utils/runParallel.cjs +163 -74
  107. package/dist/cjs/utils/runParallel.cjs.map +1 -1
  108. package/dist/cjs/utils/sortAlphabetically.cjs +5 -27
  109. package/dist/cjs/utils/sortAlphabetically.cjs.map +1 -1
  110. package/dist/cjs/utils/splitTextByLine.cjs +11 -0
  111. package/dist/cjs/utils/splitTextByLine.cjs.map +1 -0
  112. package/dist/cjs/utils/verifyIdenticObjectFormat copy.cjs +54 -0
  113. package/dist/cjs/utils/verifyIdenticObjectFormat copy.cjs.map +1 -0
  114. package/dist/cjs/utils/verifyIdenticObjectFormat.cjs +60 -0
  115. package/dist/cjs/utils/verifyIdenticObjectFormat.cjs.map +1 -0
  116. package/dist/cjs/watcher.cjs +61 -83
  117. package/dist/cjs/watcher.cjs.map +1 -1
  118. package/dist/cjs/writeConfiguration/index.cjs +15 -35
  119. package/dist/cjs/writeConfiguration/index.cjs.map +1 -1
  120. package/dist/cjs/writeContentDeclaration/detectExportedComponentName.cjs +25 -51
  121. package/dist/cjs/writeContentDeclaration/detectExportedComponentName.cjs.map +1 -1
  122. package/dist/cjs/writeContentDeclaration/dictionaryStatus.cjs +0 -17
  123. package/dist/cjs/writeContentDeclaration/index.cjs +9 -33
  124. package/dist/cjs/writeContentDeclaration/processContentDeclarationContent.cjs +77 -0
  125. package/dist/cjs/writeContentDeclaration/processContentDeclarationContent.cjs.map +1 -0
  126. package/dist/cjs/writeContentDeclaration/transformJSFile.cjs +1731 -755
  127. package/dist/cjs/writeContentDeclaration/transformJSFile.cjs.map +1 -1
  128. package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs +113 -112
  129. package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs.map +1 -1
  130. package/dist/cjs/writeContentDeclaration/writeJSFile.cjs +56 -66
  131. package/dist/cjs/writeContentDeclaration/writeJSFile.cjs.map +1 -1
  132. package/dist/cjs/writeFileIfChanged.cjs +10 -43
  133. package/dist/cjs/writeFileIfChanged.cjs.map +1 -1
  134. package/dist/cjs/writeJsonIfChanged.cjs +14 -31
  135. package/dist/cjs/writeJsonIfChanged.cjs.map +1 -1
  136. package/dist/esm/_virtual/_utils_asset.mjs +100 -0
  137. package/dist/esm/_virtual/rolldown_runtime.mjs +8 -0
  138. package/dist/esm/buildIntlayerDictionary/buildIntlayerDictionary.mjs +35 -54
  139. package/dist/esm/buildIntlayerDictionary/buildIntlayerDictionary.mjs.map +1 -1
  140. package/dist/esm/buildIntlayerDictionary/index.mjs +4 -3
  141. package/dist/esm/buildIntlayerDictionary/processContentDeclaration.mjs +18 -17
  142. package/dist/esm/buildIntlayerDictionary/processContentDeclaration.mjs.map +1 -1
  143. package/dist/esm/buildIntlayerDictionary/writeDynamicDictionary.mjs +69 -91
  144. package/dist/esm/buildIntlayerDictionary/writeDynamicDictionary.mjs.map +1 -1
  145. package/dist/esm/buildIntlayerDictionary/writeFetchDictionary.mjs +53 -61
  146. package/dist/esm/buildIntlayerDictionary/writeFetchDictionary.mjs.map +1 -1
  147. package/dist/esm/buildIntlayerDictionary/writeMergedDictionary.mjs +40 -42
  148. package/dist/esm/buildIntlayerDictionary/writeMergedDictionary.mjs.map +1 -1
  149. package/dist/esm/buildIntlayerDictionary/writeRemoteDictionary.mjs +35 -25
  150. package/dist/esm/buildIntlayerDictionary/writeRemoteDictionary.mjs.map +1 -1
  151. package/dist/esm/buildIntlayerDictionary/writeUnmergedDictionary.mjs +53 -56
  152. package/dist/esm/buildIntlayerDictionary/writeUnmergedDictionary.mjs.map +1 -1
  153. package/dist/esm/cleanOutputDir.mjs +17 -36
  154. package/dist/esm/cleanOutputDir.mjs.map +1 -1
  155. package/dist/esm/createDictionaryEntryPoint/createDictionaryEntryPoint.mjs +51 -70
  156. package/dist/esm/createDictionaryEntryPoint/createDictionaryEntryPoint.mjs.map +1 -1
  157. package/dist/esm/createDictionaryEntryPoint/generateDictionaryListContent.mjs +36 -47
  158. package/dist/esm/createDictionaryEntryPoint/generateDictionaryListContent.mjs.map +1 -1
  159. package/dist/esm/createDictionaryEntryPoint/getBuiltDictionariesPath.mjs +14 -14
  160. package/dist/esm/createDictionaryEntryPoint/getBuiltDictionariesPath.mjs.map +1 -1
  161. package/dist/esm/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.mjs +15 -15
  162. package/dist/esm/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.mjs.map +1 -1
  163. package/dist/esm/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.mjs +15 -15
  164. package/dist/esm/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.mjs.map +1 -1
  165. package/dist/esm/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.mjs +14 -14
  166. package/dist/esm/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.mjs.map +1 -1
  167. package/dist/esm/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.mjs +14 -14
  168. package/dist/esm/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.mjs.map +1 -1
  169. package/dist/esm/createDictionaryEntryPoint/index.mjs +9 -8
  170. package/dist/esm/createType/createModuleAugmentation.mjs +48 -71
  171. package/dist/esm/createType/createModuleAugmentation.mjs.map +1 -1
  172. package/dist/esm/createType/createType.mjs +24 -35
  173. package/dist/esm/createType/createType.mjs.map +1 -1
  174. package/dist/esm/createType/index.mjs +4 -3
  175. package/dist/esm/fetchDistantDictionaries.mjs +45 -52
  176. package/dist/esm/fetchDistantDictionaries.mjs.map +1 -1
  177. package/dist/esm/filterInvalidDictionaries.mjs +22 -37
  178. package/dist/esm/filterInvalidDictionaries.mjs.map +1 -1
  179. package/dist/esm/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.mjs +31 -42
  180. package/dist/esm/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.mjs.map +1 -1
  181. package/dist/esm/handleAdditionalContentDeclarationFile.mjs +27 -24
  182. package/dist/esm/handleAdditionalContentDeclarationFile.mjs.map +1 -1
  183. package/dist/esm/handleContentDeclarationFileChange.mjs +30 -29
  184. package/dist/esm/handleContentDeclarationFileChange.mjs.map +1 -1
  185. package/dist/esm/handleUnlinkedContentDeclarationFile.mjs +34 -0
  186. package/dist/esm/handleUnlinkedContentDeclarationFile.mjs.map +1 -0
  187. package/dist/esm/index.mjs +39 -99
  188. package/dist/esm/listDictionariesPath.mjs +24 -24
  189. package/dist/esm/listDictionariesPath.mjs.map +1 -1
  190. package/dist/esm/listGitFiles.mjs +83 -124
  191. package/dist/esm/listGitFiles.mjs.map +1 -1
  192. package/dist/esm/loadDictionaries/getIntlayerBundle.mjs +66 -0
  193. package/dist/esm/loadDictionaries/getIntlayerBundle.mjs.map +1 -0
  194. package/dist/esm/loadDictionaries/index.mjs +6 -5
  195. package/dist/esm/loadDictionaries/loadContentDeclaration.mjs +61 -70
  196. package/dist/esm/loadDictionaries/loadContentDeclaration.mjs.map +1 -1
  197. package/dist/esm/loadDictionaries/loadDictionaries.mjs +105 -146
  198. package/dist/esm/loadDictionaries/loadDictionaries.mjs.map +1 -1
  199. package/dist/esm/loadDictionaries/loadLocalDictionaries.mjs +23 -31
  200. package/dist/esm/loadDictionaries/loadLocalDictionaries.mjs.map +1 -1
  201. package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs +52 -74
  202. package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs.map +1 -1
  203. package/dist/esm/loadDictionaries/log.mjs +105 -165
  204. package/dist/esm/loadDictionaries/log.mjs.map +1 -1
  205. package/dist/esm/prepareIntlayer.mjs +64 -97
  206. package/dist/esm/prepareIntlayer.mjs.map +1 -1
  207. package/dist/esm/reduceDictionaryContent/applyMask.mjs +26 -37
  208. package/dist/esm/reduceDictionaryContent/applyMask.mjs.map +1 -1
  209. package/dist/esm/reduceDictionaryContent/reduceDictionaryContent.mjs +7 -7
  210. package/dist/esm/reduceDictionaryContent/reduceDictionaryContent.mjs.map +1 -1
  211. package/dist/esm/utils/chunkJSON.mjs +327 -0
  212. package/dist/esm/utils/chunkJSON.mjs.map +1 -0
  213. package/dist/esm/utils/extractErrorMessage.mjs +91 -111
  214. package/dist/esm/utils/extractErrorMessage.mjs.map +1 -1
  215. package/dist/esm/utils/formatter.mjs +10 -12
  216. package/dist/esm/utils/formatter.mjs.map +1 -1
  217. package/dist/esm/utils/getChunk.mjs +34 -0
  218. package/dist/esm/utils/getChunk.mjs.map +1 -0
  219. package/dist/esm/utils/getFileHash.mjs +6 -5
  220. package/dist/esm/utils/getFileHash.mjs.map +1 -1
  221. package/dist/esm/utils/getFormatFromExtension.mjs +21 -29
  222. package/dist/esm/utils/getFormatFromExtension.mjs.map +1 -1
  223. package/dist/esm/utils/kebabCaseToCamelCase.mjs +10 -12
  224. package/dist/esm/utils/kebabCaseToCamelCase.mjs.map +1 -1
  225. package/dist/esm/utils/pLimit.mjs +126 -0
  226. package/dist/esm/utils/pLimit.mjs.map +1 -0
  227. package/dist/esm/utils/parallelize.mjs +10 -144
  228. package/dist/esm/utils/parallelize.mjs.map +1 -1
  229. package/dist/esm/utils/parallelizeGlobal.mjs +27 -0
  230. package/dist/esm/utils/parallelizeGlobal.mjs.map +1 -0
  231. package/dist/esm/utils/reduceObjectFormat.mjs +30 -0
  232. package/dist/esm/utils/reduceObjectFormat.mjs.map +1 -0
  233. package/dist/esm/utils/resolveObjectPromises.mjs +17 -24
  234. package/dist/esm/utils/resolveObjectPromises.mjs.map +1 -1
  235. package/dist/esm/utils/runOnce.mjs +76 -33
  236. package/dist/esm/utils/runOnce.mjs.map +1 -1
  237. package/dist/esm/utils/runParallel.mjs +160 -40
  238. package/dist/esm/utils/runParallel.mjs.map +1 -1
  239. package/dist/esm/utils/sortAlphabetically.mjs +4 -3
  240. package/dist/esm/utils/sortAlphabetically.mjs.map +1 -1
  241. package/dist/esm/utils/splitTextByLine.mjs +10 -0
  242. package/dist/esm/utils/splitTextByLine.mjs.map +1 -0
  243. package/dist/esm/utils/verifyIdenticObjectFormat copy.mjs +53 -0
  244. package/dist/esm/utils/verifyIdenticObjectFormat copy.mjs.map +1 -0
  245. package/dist/esm/utils/verifyIdenticObjectFormat.mjs +59 -0
  246. package/dist/esm/utils/verifyIdenticObjectFormat.mjs.map +1 -0
  247. package/dist/esm/watcher.mjs +53 -58
  248. package/dist/esm/watcher.mjs.map +1 -1
  249. package/dist/esm/writeConfiguration/index.mjs +11 -10
  250. package/dist/esm/writeConfiguration/index.mjs.map +1 -1
  251. package/dist/esm/writeContentDeclaration/detectExportedComponentName.mjs +24 -27
  252. package/dist/esm/writeContentDeclaration/detectExportedComponentName.mjs.map +1 -1
  253. package/dist/esm/writeContentDeclaration/dictionaryStatus.mjs +0 -1
  254. package/dist/esm/writeContentDeclaration/index.mjs +6 -7
  255. package/dist/esm/writeContentDeclaration/processContentDeclarationContent.mjs +71 -0
  256. package/dist/esm/writeContentDeclaration/processContentDeclarationContent.mjs.map +1 -0
  257. package/dist/esm/writeContentDeclaration/transformJSFile.mjs +1726 -735
  258. package/dist/esm/writeContentDeclaration/transformJSFile.mjs.map +1 -1
  259. package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs +105 -76
  260. package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs.map +1 -1
  261. package/dist/esm/writeContentDeclaration/writeJSFile.mjs +48 -46
  262. package/dist/esm/writeContentDeclaration/writeJSFile.mjs.map +1 -1
  263. package/dist/esm/writeFileIfChanged.mjs +7 -18
  264. package/dist/esm/writeFileIfChanged.mjs.map +1 -1
  265. package/dist/esm/writeJsonIfChanged.mjs +14 -7
  266. package/dist/esm/writeJsonIfChanged.mjs.map +1 -1
  267. package/dist/types/buildIntlayerDictionary/buildIntlayerDictionary.d.ts +14 -7
  268. package/dist/types/buildIntlayerDictionary/buildIntlayerDictionary.d.ts.map +1 -1
  269. package/dist/types/buildIntlayerDictionary/index.d.ts +3 -3
  270. package/dist/types/buildIntlayerDictionary/processContentDeclaration.d.ts +7 -2
  271. package/dist/types/buildIntlayerDictionary/processContentDeclaration.d.ts.map +1 -1
  272. package/dist/types/buildIntlayerDictionary/writeDynamicDictionary.d.ts +14 -10
  273. package/dist/types/buildIntlayerDictionary/writeDynamicDictionary.d.ts.map +1 -1
  274. package/dist/types/buildIntlayerDictionary/writeFetchDictionary.d.ts +8 -3
  275. package/dist/types/buildIntlayerDictionary/writeFetchDictionary.d.ts.map +1 -1
  276. package/dist/types/buildIntlayerDictionary/writeMergedDictionary.d.ts +12 -7
  277. package/dist/types/buildIntlayerDictionary/writeMergedDictionary.d.ts.map +1 -1
  278. package/dist/types/buildIntlayerDictionary/writeRemoteDictionary.d.ts +8 -2
  279. package/dist/types/buildIntlayerDictionary/writeRemoteDictionary.d.ts.map +1 -1
  280. package/dist/types/buildIntlayerDictionary/writeUnmergedDictionary.d.ts +10 -6
  281. package/dist/types/buildIntlayerDictionary/writeUnmergedDictionary.d.ts.map +1 -1
  282. package/dist/types/cleanOutputDir.d.ts +6 -1
  283. package/dist/types/cleanOutputDir.d.ts.map +1 -1
  284. package/dist/types/createDictionaryEntryPoint/createDictionaryEntryPoint.d.ts +6 -1
  285. package/dist/types/createDictionaryEntryPoint/createDictionaryEntryPoint.d.ts.map +1 -1
  286. package/dist/types/createDictionaryEntryPoint/generateDictionaryListContent.d.ts +6 -1
  287. package/dist/types/createDictionaryEntryPoint/generateDictionaryListContent.d.ts.map +1 -1
  288. package/dist/types/createDictionaryEntryPoint/getBuiltDictionariesPath.d.ts +7 -1
  289. package/dist/types/createDictionaryEntryPoint/getBuiltDictionariesPath.d.ts.map +1 -1
  290. package/dist/types/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.d.ts +7 -1
  291. package/dist/types/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.d.ts.map +1 -1
  292. package/dist/types/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.d.ts +7 -1
  293. package/dist/types/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.d.ts.map +1 -1
  294. package/dist/types/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.d.ts +7 -1
  295. package/dist/types/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.d.ts.map +1 -1
  296. package/dist/types/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.d.ts +7 -1
  297. package/dist/types/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.d.ts.map +1 -1
  298. package/dist/types/createDictionaryEntryPoint/index.d.ts +8 -8
  299. package/dist/types/createType/createModuleAugmentation.d.ts +8 -5
  300. package/dist/types/createType/createModuleAugmentation.d.ts.map +1 -1
  301. package/dist/types/createType/createType.d.ts +7 -4
  302. package/dist/types/createType/createType.d.ts.map +1 -1
  303. package/dist/types/createType/index.d.ts +3 -3
  304. package/dist/types/fetchDistantDictionaries.d.ts +10 -7
  305. package/dist/types/fetchDistantDictionaries.d.ts.map +1 -1
  306. package/dist/types/filterInvalidDictionaries.d.ts +7 -4
  307. package/dist/types/filterInvalidDictionaries.d.ts.map +1 -1
  308. package/dist/types/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.d.ts +6 -2
  309. package/dist/types/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.d.ts.map +1 -1
  310. package/dist/types/handleAdditionalContentDeclarationFile.d.ts +6 -2
  311. package/dist/types/handleAdditionalContentDeclarationFile.d.ts.map +1 -1
  312. package/dist/types/handleContentDeclarationFileChange.d.ts +6 -2
  313. package/dist/types/handleContentDeclarationFileChange.d.ts.map +1 -1
  314. package/dist/types/handleUnlinkedContentDeclarationFile.d.ts +7 -0
  315. package/dist/types/handleUnlinkedContentDeclarationFile.d.ts.map +1 -0
  316. package/dist/types/index.d.ts +49 -33
  317. package/dist/types/listDictionariesPath.d.ts +7 -2
  318. package/dist/types/listDictionariesPath.d.ts.map +1 -1
  319. package/dist/types/listGitFiles.d.ts +24 -12
  320. package/dist/types/listGitFiles.d.ts.map +1 -1
  321. package/dist/types/loadDictionaries/getIntlayerBundle.d.ts +11 -0
  322. package/dist/types/loadDictionaries/getIntlayerBundle.d.ts.map +1 -0
  323. package/dist/types/loadDictionaries/index.d.ts +5 -5
  324. package/dist/types/loadDictionaries/loadContentDeclaration.d.ts +8 -5
  325. package/dist/types/loadDictionaries/loadContentDeclaration.d.ts.map +1 -1
  326. package/dist/types/loadDictionaries/loadDictionaries.d.ts +18 -14
  327. package/dist/types/loadDictionaries/loadDictionaries.d.ts.map +1 -1
  328. package/dist/types/loadDictionaries/loadLocalDictionaries.d.ts +6 -3
  329. package/dist/types/loadDictionaries/loadLocalDictionaries.d.ts.map +1 -1
  330. package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts +13 -8
  331. package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts.map +1 -1
  332. package/dist/types/loadDictionaries/log.d.ts +28 -24
  333. package/dist/types/loadDictionaries/log.d.ts.map +1 -1
  334. package/dist/types/prepareIntlayer.d.ts +12 -2
  335. package/dist/types/prepareIntlayer.d.ts.map +1 -1
  336. package/dist/types/reduceDictionaryContent/applyMask.d.ts +6 -2
  337. package/dist/types/reduceDictionaryContent/applyMask.d.ts.map +1 -1
  338. package/dist/types/reduceDictionaryContent/reduceDictionaryContent.d.ts +6 -2
  339. package/dist/types/reduceDictionaryContent/reduceDictionaryContent.d.ts.map +1 -1
  340. package/dist/types/utils/chunkJSON.d.ts +56 -0
  341. package/dist/types/utils/chunkJSON.d.ts.map +1 -0
  342. package/dist/types/utils/extractErrorMessage.d.ts +4 -1
  343. package/dist/types/utils/extractErrorMessage.d.ts.map +1 -1
  344. package/dist/types/utils/formatter.d.ts +8 -3
  345. package/dist/types/utils/formatter.d.ts.map +1 -1
  346. package/dist/types/utils/getChunk.d.ts +11 -0
  347. package/dist/types/utils/getChunk.d.ts.map +1 -0
  348. package/dist/types/utils/getFileHash.d.ts +4 -1
  349. package/dist/types/utils/getFileHash.d.ts.map +1 -1
  350. package/dist/types/utils/getFormatFromExtension.d.ts +7 -4
  351. package/dist/types/utils/getFormatFromExtension.d.ts.map +1 -1
  352. package/dist/types/utils/kebabCaseToCamelCase.d.ts +4 -1
  353. package/dist/types/utils/kebabCaseToCamelCase.d.ts.map +1 -1
  354. package/dist/types/utils/pLimit.d.ts +16 -0
  355. package/dist/types/utils/pLimit.d.ts.map +1 -0
  356. package/dist/types/utils/parallelize.d.ts +4 -13
  357. package/dist/types/utils/parallelize.d.ts.map +1 -1
  358. package/dist/types/utils/parallelizeGlobal.d.ts +22 -0
  359. package/dist/types/utils/parallelizeGlobal.d.ts.map +1 -0
  360. package/dist/types/utils/reduceObjectFormat.d.ts +17 -0
  361. package/dist/types/utils/reduceObjectFormat.d.ts.map +1 -0
  362. package/dist/types/utils/resolveObjectPromises.d.ts +4 -1
  363. package/dist/types/utils/resolveObjectPromises.d.ts.map +1 -1
  364. package/dist/types/utils/runOnce.d.ts +23 -2
  365. package/dist/types/utils/runOnce.d.ts.map +1 -1
  366. package/dist/types/utils/runParallel.d.ts +9 -6
  367. package/dist/types/utils/runParallel.d.ts.map +1 -1
  368. package/dist/types/utils/sortAlphabetically.d.ts +4 -1
  369. package/dist/types/utils/sortAlphabetically.d.ts.map +1 -1
  370. package/dist/types/utils/splitTextByLine.d.ts +5 -0
  371. package/dist/types/utils/splitTextByLine.d.ts.map +1 -0
  372. package/dist/types/utils/verifyIdenticObjectFormat copy.d.ts +23 -0
  373. package/dist/types/utils/verifyIdenticObjectFormat copy.d.ts.map +1 -0
  374. package/dist/types/utils/verifyIdenticObjectFormat.d.ts +23 -0
  375. package/dist/types/utils/verifyIdenticObjectFormat.d.ts.map +1 -0
  376. package/dist/types/watcher.d.ts +13 -9
  377. package/dist/types/watcher.d.ts.map +1 -1
  378. package/dist/types/writeConfiguration/index.d.ts +6 -2
  379. package/dist/types/writeConfiguration/index.d.ts.map +1 -1
  380. package/dist/types/writeContentDeclaration/detectExportedComponentName.d.ts +4 -1
  381. package/dist/types/writeContentDeclaration/detectExportedComponentName.d.ts.map +1 -1
  382. package/dist/types/writeContentDeclaration/dictionaryStatus.d.ts +4 -1
  383. package/dist/types/writeContentDeclaration/dictionaryStatus.d.ts.map +1 -1
  384. package/dist/types/writeContentDeclaration/index.d.ts +6 -7
  385. package/dist/types/writeContentDeclaration/processContentDeclarationContent.d.ts +7 -0
  386. package/dist/types/writeContentDeclaration/processContentDeclarationContent.d.ts.map +1 -0
  387. package/dist/types/writeContentDeclaration/transformJSFile.d.ts +33 -6
  388. package/dist/types/writeContentDeclaration/transformJSFile.d.ts.map +1 -1
  389. package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts +14 -6
  390. package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts.map +1 -1
  391. package/dist/types/writeContentDeclaration/writeJSFile.d.ts +7 -3
  392. package/dist/types/writeContentDeclaration/writeJSFile.d.ts.map +1 -1
  393. package/dist/types/writeFileIfChanged.d.ts +7 -2
  394. package/dist/types/writeFileIfChanged.d.ts.map +1 -1
  395. package/dist/types/writeJsonIfChanged.d.ts +7 -2
  396. package/dist/types/writeJsonIfChanged.d.ts.map +1 -1
  397. package/package.json +48 -54
  398. package/LICENSE +0 -202
  399. package/dist/cjs/buildIntlayerDictionary/index.cjs.map +0 -1
  400. package/dist/cjs/createDictionaryEntryPoint/index.cjs.map +0 -1
  401. package/dist/cjs/createType/index.cjs.map +0 -1
  402. package/dist/cjs/handleUnlikedContentDeclarationFile.cjs +0 -57
  403. package/dist/cjs/handleUnlikedContentDeclarationFile.cjs.map +0 -1
  404. package/dist/cjs/index.cjs.map +0 -1
  405. package/dist/cjs/loadDictionaries/index.cjs.map +0 -1
  406. package/dist/cjs/mergeDictionaries.cjs +0 -143
  407. package/dist/cjs/mergeDictionaries.cjs.map +0 -1
  408. package/dist/cjs/orderDictionaries.cjs +0 -71
  409. package/dist/cjs/orderDictionaries.cjs.map +0 -1
  410. package/dist/cjs/prepareContentDeclaration.cjs +0 -93
  411. package/dist/cjs/prepareContentDeclaration.cjs.map +0 -1
  412. package/dist/cjs/processPerLocaleDictionary.cjs +0 -49
  413. package/dist/cjs/processPerLocaleDictionary.cjs.map +0 -1
  414. package/dist/cjs/utils/getExtention.cjs +0 -37
  415. package/dist/cjs/utils/getExtention.cjs.map +0 -1
  416. package/dist/cjs/writeContentDeclaration/dictionaryStatus.cjs.map +0 -1
  417. package/dist/cjs/writeContentDeclaration/formatCode.cjs +0 -78
  418. package/dist/cjs/writeContentDeclaration/formatCode.cjs.map +0 -1
  419. package/dist/cjs/writeContentDeclaration/index.cjs.map +0 -1
  420. package/dist/esm/buildIntlayerDictionary/index.mjs.map +0 -1
  421. package/dist/esm/createDictionaryEntryPoint/index.mjs.map +0 -1
  422. package/dist/esm/createType/index.mjs.map +0 -1
  423. package/dist/esm/getContentDeclarationFileTemplate/cjsTemplate.txt +0 -9
  424. package/dist/esm/getContentDeclarationFileTemplate/esmTemplate.txt +0 -9
  425. package/dist/esm/getContentDeclarationFileTemplate/jsonTemplate.txt +0 -5
  426. package/dist/esm/getContentDeclarationFileTemplate/tsTemplate.txt +0 -8
  427. package/dist/esm/handleUnlikedContentDeclarationFile.mjs +0 -33
  428. package/dist/esm/handleUnlikedContentDeclarationFile.mjs.map +0 -1
  429. package/dist/esm/index.mjs.map +0 -1
  430. package/dist/esm/loadDictionaries/index.mjs.map +0 -1
  431. package/dist/esm/mergeDictionaries.mjs +0 -109
  432. package/dist/esm/mergeDictionaries.mjs.map +0 -1
  433. package/dist/esm/orderDictionaries.mjs +0 -37
  434. package/dist/esm/orderDictionaries.mjs.map +0 -1
  435. package/dist/esm/prepareContentDeclaration.mjs +0 -72
  436. package/dist/esm/prepareContentDeclaration.mjs.map +0 -1
  437. package/dist/esm/processPerLocaleDictionary.mjs +0 -25
  438. package/dist/esm/processPerLocaleDictionary.mjs.map +0 -1
  439. package/dist/esm/utils/getExtention.mjs +0 -13
  440. package/dist/esm/utils/getExtention.mjs.map +0 -1
  441. package/dist/esm/writeContentDeclaration/dictionaryStatus.mjs.map +0 -1
  442. package/dist/esm/writeContentDeclaration/formatCode.mjs +0 -44
  443. package/dist/esm/writeContentDeclaration/formatCode.mjs.map +0 -1
  444. package/dist/esm/writeContentDeclaration/index.mjs.map +0 -1
  445. package/dist/types/buildIntlayerDictionary/index.d.ts.map +0 -1
  446. package/dist/types/createDictionaryEntryPoint/index.d.ts.map +0 -1
  447. package/dist/types/createType/index.d.ts.map +0 -1
  448. package/dist/types/handleUnlikedContentDeclarationFile.d.ts +0 -3
  449. package/dist/types/handleUnlikedContentDeclarationFile.d.ts.map +0 -1
  450. package/dist/types/index.d.ts.map +0 -1
  451. package/dist/types/loadDictionaries/index.d.ts.map +0 -1
  452. package/dist/types/mergeDictionaries.d.ts +0 -3
  453. package/dist/types/mergeDictionaries.d.ts.map +0 -1
  454. package/dist/types/orderDictionaries.d.ts +0 -10
  455. package/dist/types/orderDictionaries.d.ts.map +0 -1
  456. package/dist/types/prepareContentDeclaration.d.ts +0 -3
  457. package/dist/types/prepareContentDeclaration.d.ts.map +0 -1
  458. package/dist/types/processPerLocaleDictionary.d.ts +0 -32
  459. package/dist/types/processPerLocaleDictionary.d.ts.map +0 -1
  460. package/dist/types/utils/getExtention.d.ts +0 -3
  461. package/dist/types/utils/getExtention.d.ts.map +0 -1
  462. package/dist/types/writeContentDeclaration/formatCode.d.ts +0 -2
  463. package/dist/types/writeContentDeclaration/formatCode.d.ts.map +0 -1
  464. package/dist/types/writeContentDeclaration/index.d.ts.map +0 -1
@@ -1,770 +1,1746 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var transformJSFile_exports = {};
20
- __export(transformJSFile_exports, {
21
- transformJSFile: () => transformJSFile
22
- });
23
- module.exports = __toCommonJS(transformJSFile_exports);
24
- var import_core = require("@intlayer/core");
25
- var import_ts_morph = require("ts-morph");
26
- const isTranslationNode = (value) => {
27
- if (!value || typeof value !== "object") return false;
28
- const v = value;
29
- const hasNodeTypeTranslation = v.nodeType === import_core.NodeType.Translation;
30
- const hasTranslationObject = v[import_core.NodeType.Translation] && typeof v[import_core.NodeType.Translation] === "object";
31
- return Boolean(hasTranslationObject || hasNodeTypeTranslation);
32
- };
33
- const isEnumerationNode = (value) => {
34
- if (!value || typeof value !== "object") return false;
35
- const v = value;
36
- return v.nodeType === import_core.NodeType.Enumeration || v[import_core.NodeType.Enumeration] && typeof v[import_core.NodeType.Enumeration] === "object";
37
- };
38
- const isConditionNode = (value) => {
39
- if (!value || typeof value !== "object") return false;
40
- const v = value;
41
- return v.nodeType === import_core.NodeType.Condition || v[import_core.NodeType.Condition] && typeof v[import_core.NodeType.Condition] === "object";
42
- };
43
- const isGenderNode = (value) => {
44
- if (!value || typeof value !== "object") return false;
45
- const v = value;
46
- return v.nodeType === import_core.NodeType.Gender || v[import_core.NodeType.Gender] && typeof v[import_core.NodeType.Gender] === "object";
47
- };
48
- const isInsertionNode = (value) => {
49
- if (!value || typeof value !== "object") return false;
50
- const v = value;
51
- return v.nodeType === import_core.NodeType.Insertion || import_core.NodeType.Insertion in v;
52
- };
53
- const isMarkdownNode = (value) => {
54
- if (!value || typeof value !== "object") return false;
55
- const v = value;
56
- return v.nodeType === import_core.NodeType.Markdown || import_core.NodeType.Markdown in v;
57
- };
58
- const isFileNode = (value) => {
59
- if (!value || typeof value !== "object") return false;
60
- const v = value;
61
- return v.nodeType === import_core.NodeType.File || typeof v[import_core.NodeType.File] === "string";
62
- };
63
- const isNestedNode = (value) => {
64
- if (!value || typeof value !== "object") return false;
65
- const v = value;
66
- return v.nodeType === import_core.NodeType.Nested || import_core.NodeType.Nested in v;
67
- };
68
- const buildTranslationInitializer = (translationMap) => {
69
- const entries = Object.entries(translationMap).sort(([a], [b]) => a.localeCompare(b));
70
- const parts = [];
71
- for (const [lang, val] of entries) {
72
- const isValidIdentifier = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(lang);
73
- const keyText = isValidIdentifier ? lang : JSON.stringify(lang);
74
- if (typeof val === "string") {
75
- parts.push(`${keyText}: ${JSON.stringify(val)}`);
76
- } else {
77
- parts.push(`${keyText}: ${JSON.stringify(val)}`);
78
- }
79
- }
80
- return `t({ ${parts.join(", ")} })`;
81
- };
82
- const stringifyKey = (key) => {
83
- const isValidIdentifier = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key);
84
- if (!isValidIdentifier) return JSON.stringify(key);
85
- if (key === "true" || key === "false") return JSON.stringify(key);
86
- return key;
87
- };
88
- const buildEnumerationInitializer = (map) => {
89
- const parts = [];
90
- for (const [k, v] of Object.entries(map)) {
91
- if (typeof v !== "string") return "";
92
- parts.push(`${stringifyKey(k)}: ${JSON.stringify(v)}`);
93
- }
94
- return `enu({ ${parts.join(", ")} })`;
95
- };
96
- const buildConditionInitializer = (map) => {
97
- const parts = [];
98
- for (const [k, v] of Object.entries(map)) {
99
- if (typeof v !== "string") return "";
100
- parts.push(`${stringifyKey(k)}: ${JSON.stringify(v)}`);
101
- }
102
- return `cond({ ${parts.join(", ")} })`;
103
- };
104
- const buildGenderInitializer = (map) => {
105
- const parts = [];
106
- for (const [k, v] of Object.entries(map)) {
107
- if (typeof v !== "string") return "";
108
- parts.push(`${stringifyKey(k)}: ${JSON.stringify(v)}`);
109
- }
110
- return `gender({ ${parts.join(", ")} })`;
111
- };
112
- const buildInsertionInitializer = (content) => {
113
- if (typeof content === "string") return `insert(${JSON.stringify(content)})`;
114
- if (isTranslationNode(content)) {
115
- const translations = content.translation ?? content["translation"] ?? {};
116
- const allStrings = Object.values(translations).every(
117
- (v) => typeof v === "string"
118
- );
119
- if (!allStrings) return void 0;
120
- return `insert(${buildTranslationInitializer(
121
- translations
122
- )})`;
123
- }
124
- return void 0;
125
- };
126
- const buildFileInitializer = (path) => {
127
- if (typeof path === "string") return `file(${JSON.stringify(path)})`;
128
- return void 0;
129
- };
130
- const buildMarkdownInitializer = (content) => {
131
- if (typeof content === "string") return `md(${JSON.stringify(content)})`;
132
- if (isFileNode(content)) {
133
- const p = content[import_core.NodeType.File];
134
- const fileInit = buildFileInitializer(p);
135
- if (!fileInit) return void 0;
136
- return `md(${fileInit})`;
137
- }
138
- return void 0;
139
- };
140
- const buildNestedInitializer = (obj) => {
141
- const data = obj?.[import_core.NodeType.Nested];
142
- if (!data || typeof data.dictionaryKey !== "string") return void 0;
143
- if (data.path && typeof data.path === "string") {
144
- return `nest(${JSON.stringify(data.dictionaryKey)}, ${JSON.stringify(data.path)})`;
145
- }
146
- return `nest(${JSON.stringify(data.dictionaryKey)})`;
147
- };
148
- const readExistingTranslationMap = (contentObject, propName) => {
149
- const prop = contentObject.getProperty(propName);
150
- if (!prop || !import_ts_morph.Node.isPropertyAssignment(prop)) return void 0;
151
- const init = prop.getInitializer();
152
- if (!init) return void 0;
153
- if (!import_ts_morph.Node.isCallExpression(init)) return void 0;
154
- const exp = init.getExpression();
155
- if (!import_ts_morph.Node.isIdentifier(exp) || exp.getText() !== "t") return void 0;
156
- const arg = init.getArguments()[0];
157
- if (!arg || !import_ts_morph.Node.isObjectLiteralExpression(arg)) return void 0;
158
- const map = {};
159
- for (const p of arg.getProperties()) {
160
- if (!import_ts_morph.Node.isPropertyAssignment(p)) continue;
161
- const nameNode = p.getNameNode();
162
- const rawName = nameNode.getText();
163
- const name = rawName.replace(/^['"]|['"]$/g, "");
164
- const valueInit = p.getInitializer();
165
- if (valueInit && import_ts_morph.Node.isStringLiteral(valueInit)) {
166
- map[name] = valueInit.getLiteralValue();
167
- }
168
- }
169
- return map;
170
- };
171
- const readExistingMapFromCall = (contentObject, propName, callee) => {
172
- const prop = contentObject.getProperty(propName);
173
- if (!prop || !import_ts_morph.Node.isPropertyAssignment(prop)) return void 0;
174
- const init = prop.getInitializer();
175
- if (!init || !import_ts_morph.Node.isCallExpression(init)) return void 0;
176
- const exp = init.getExpression();
177
- if (!import_ts_morph.Node.isIdentifier(exp) || exp.getText() !== callee) return void 0;
178
- const arg = init.getArguments()[0];
179
- if (!arg || !import_ts_morph.Node.isObjectLiteralExpression(arg)) return void 0;
180
- const map = {};
181
- for (const p of arg.getProperties()) {
182
- if (!import_ts_morph.Node.isPropertyAssignment(p)) continue;
183
- const nameNode = p.getNameNode();
184
- const rawName = nameNode.getText();
185
- const name = rawName.replace(/^['"]|['"]$/g, "");
186
- const valueInit = p.getInitializer();
187
- if (valueInit && import_ts_morph.Node.isStringLiteral(valueInit)) {
188
- map[name] = valueInit.getLiteralValue();
189
- }
190
- }
191
- return map;
192
- };
193
- const areStringMapsEqual = (a, b) => {
194
- if (!b) return false;
195
- const aEntries = Object.entries(a).filter(
196
- ([, v]) => typeof v === "string"
197
- );
198
- if (aEntries.length !== Object.keys(a).length) return false;
199
- if (aEntries.length !== Object.keys(b).length) return false;
200
- for (const [k, v] of aEntries) {
201
- if (!(k in b)) return false;
202
- if (b[k] !== v) return false;
203
- }
204
- return true;
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ let __intlayer_core = require("@intlayer/core");
3
+ __intlayer_core = require_rolldown_runtime.__toESM(__intlayer_core);
4
+ let __intlayer_types = require("@intlayer/types");
5
+ __intlayer_types = require_rolldown_runtime.__toESM(__intlayer_types);
6
+ let ts_morph = require("ts-morph");
7
+ ts_morph = require_rolldown_runtime.__toESM(ts_morph);
8
+
9
+ //#region src/writeContentDeclaration/transformJSFile.ts
10
+ /**
11
+ * Builds a translation initializer string for the 't' function call.
12
+ * Creates a properly formatted translation object with locale keys and values.
13
+ *
14
+ * @param translationMap - Map of locale codes to translation values
15
+ * @param typeArgumentsText - Optional generic type arguments for the translation function
16
+ * @returns Formatted string for the translation function call
17
+ */
18
+ const buildTranslationInitializer = (translationMap, typeArgumentsText) => {
19
+ const translationEntries = Object.entries(translationMap).sort(([firstKey], [secondKey]) => firstKey.localeCompare(secondKey));
20
+ const translationParts = [];
21
+ for (const [localeCode, translationValue] of translationEntries) {
22
+ const formattedLocaleKey = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(localeCode) ? localeCode : JSON.stringify(localeCode);
23
+ if (typeof translationValue === "string") translationParts.push(`${formattedLocaleKey}: ${JSON.stringify(translationValue)}`);
24
+ else if (Array.isArray(translationValue)) {
25
+ const serializedArrayElements = translationValue.map((arrayElement) => JSON.stringify(arrayElement)).join(", ");
26
+ translationParts.push(`${formattedLocaleKey}: [ ${serializedArrayElements} ]`);
27
+ } else translationParts.push(`${formattedLocaleKey}: ${JSON.stringify(translationValue)}`);
28
+ }
29
+ return `t${typeArgumentsText ?? ""}({ ${translationParts.join(", ")} })`;
30
+ };
31
+ /**
32
+ * Synchronizes numeric suffixes across locales to maintain consistency.
33
+ * When updating a fallback locale's numeric suffix, this function updates
34
+ * the corresponding numeric suffixes in other locales to match.
35
+ *
36
+ * This is useful for maintaining numbered lists across translations,
37
+ * e.g., "Hello 1" / "Bonjour 1" when updating to "Hello 3".
38
+ *
39
+ * @param existingTranslationMap - Current translation map with locale values
40
+ * @param fallbackLocaleCode - The locale being updated (fallback)
41
+ * @param newFallbackValue - The new value for the fallback locale
42
+ * @returns Updated translation map with synchronized numeric suffixes
43
+ */
44
+ const syncNumericSuffixAcrossLocales = (existingTranslationMap, fallbackLocaleCode, newFallbackValue) => {
45
+ const updatedTranslationMap = {
46
+ ...existingTranslationMap,
47
+ [fallbackLocaleCode]: newFallbackValue
48
+ };
49
+ const trailingNumberMatch = newFallbackValue.match(/\d+(?!.*\d)/);
50
+ if (!trailingNumberMatch) return updatedTranslationMap;
51
+ const newTrailingNumber = trailingNumberMatch[0];
52
+ for (const [localeCode, currentValue] of Object.entries(existingTranslationMap)) {
53
+ if (localeCode === fallbackLocaleCode) continue;
54
+ if (!currentValue.match(/\d+(?!.*\d)/)) continue;
55
+ updatedTranslationMap[localeCode] = currentValue.replace(/(\d+)(?!.*\d)/, newTrailingNumber);
56
+ }
57
+ return updatedTranslationMap;
58
+ };
59
+ /**
60
+ * Safely formats a key for use in object literals.
61
+ * Handles special cases like reserved keywords and non-identifier keys.
62
+ *
63
+ * @param objectKey - The key to format
64
+ * @returns Properly formatted key string
65
+ */
66
+ const stringifyKey = (objectKey) => {
67
+ if (!/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(objectKey)) return JSON.stringify(objectKey);
68
+ if (objectKey === "true" || objectKey === "false") return JSON.stringify(objectKey);
69
+ return objectKey;
70
+ };
71
+ /**
72
+ * Builds an enumeration initializer string for the 'enu' function call.
73
+ * Creates a properly formatted enumeration object with key-value pairs.
74
+ *
75
+ * @param enumerationMap - Map of enumeration keys to string values
76
+ * @returns Formatted string for the enumeration function call, or empty string if invalid
77
+ */
78
+ const buildEnumerationInitializer = (enumerationMap) => {
79
+ const enumerationParts = [];
80
+ for (const [enumerationKey, enumerationValue] of Object.entries(enumerationMap)) {
81
+ if (typeof enumerationValue !== "string") return "";
82
+ enumerationParts.push(`${stringifyKey(enumerationKey)}: ${JSON.stringify(enumerationValue)}`);
83
+ }
84
+ return `enu({ ${enumerationParts.join(", ")} })`;
85
+ };
86
+ /**
87
+ * Builds a condition initializer string for the 'cond' function call.
88
+ * Creates a properly formatted condition object with key-value pairs.
89
+ *
90
+ * @param conditionMap - Map of condition keys to string values
91
+ * @returns Formatted string for the condition function call, or empty string if invalid
92
+ */
93
+ const buildConditionInitializer = (conditionMap) => {
94
+ const conditionParts = [];
95
+ for (const [conditionKey, conditionValue] of Object.entries(conditionMap)) {
96
+ if (typeof conditionValue !== "string") return "";
97
+ conditionParts.push(`${stringifyKey(conditionKey)}: ${JSON.stringify(conditionValue)}`);
98
+ }
99
+ return `cond({ ${conditionParts.join(", ")} })`;
100
+ };
101
+ /**
102
+ * Builds a gender initializer string for the 'gender' function call.
103
+ * Creates a properly formatted gender object with key-value pairs.
104
+ *
105
+ * @param genderMap - Map of gender keys to string values
106
+ * @returns Formatted string for the gender function call, or empty string if invalid
107
+ */
108
+ const buildGenderInitializer = (genderMap) => {
109
+ const genderParts = [];
110
+ for (const [genderKey, genderValue] of Object.entries(genderMap)) {
111
+ if (typeof genderValue !== "string") return "";
112
+ genderParts.push(`${stringifyKey(genderKey)}: ${JSON.stringify(genderValue)}`);
113
+ }
114
+ return `gender({ ${genderParts.join(", ")} })`;
115
+ };
116
+ /**
117
+ * Builds an insertion initializer string for the 'insert' function call.
118
+ * Handles both string content and translation content for insertions.
119
+ *
120
+ * @param insertionContent - The content to be inserted (string or translation)
121
+ * @returns Formatted string for the insertion function call, or undefined if invalid
122
+ */
123
+ const buildInsertionInitializer = (insertionContent) => {
124
+ if (typeof insertionContent === "string") return `insert(${JSON.stringify(insertionContent)})`;
125
+ if ((0, __intlayer_core.getNodeType)(insertionContent) === __intlayer_types.NodeType.Translation) {
126
+ const translationMap = insertionContent[__intlayer_types.NodeType.Translation] ?? {};
127
+ if (!Object.values(translationMap).every((translationValue) => typeof translationValue === "string")) return void 0;
128
+ return `insert(${buildTranslationInitializer(translationMap)})`;
129
+ }
130
+ };
131
+ /**
132
+ * Builds a file initializer string for the 'file' function call.
133
+ * Creates a properly formatted file path reference.
134
+ *
135
+ * @param filePath - The file path to reference
136
+ * @returns Formatted string for the file function call, or undefined if invalid
137
+ */
138
+ const buildFileInitializer = (filePath) => {
139
+ if (typeof filePath === "string") return `file(${JSON.stringify(filePath)})`;
140
+ };
141
+ /**
142
+ * Builds a markdown initializer string for the 'md' function call.
143
+ * Handles string content, translation content, and file references for markdown.
144
+ *
145
+ * @param markdownContent - The markdown content (string, translation, or file reference)
146
+ * @returns Formatted string for the markdown function call, or undefined if invalid
147
+ */
148
+ const buildMarkdownInitializer = (markdownContent) => {
149
+ if (typeof markdownContent === "string") return `md(${JSON.stringify(markdownContent)})`;
150
+ if ((0, __intlayer_core.getNodeType)(markdownContent) === __intlayer_types.NodeType.Translation) {
151
+ const translationMap = markdownContent[__intlayer_types.NodeType.Translation] ?? {};
152
+ if (!Object.values(translationMap).every((translationValue) => typeof translationValue === "string")) return void 0;
153
+ return `md(${buildTranslationInitializer(translationMap)})`;
154
+ }
155
+ if ((0, __intlayer_core.getNodeType)(markdownContent) === __intlayer_types.NodeType.File) {
156
+ const filePath = markdownContent[__intlayer_types.NodeType.File];
157
+ const fileInitializer = buildFileInitializer(filePath);
158
+ if (!fileInitializer) return void 0;
159
+ return `md(${fileInitializer})`;
160
+ }
161
+ };
162
+ /**
163
+ * Builds a nested initializer string for the 'nest' function call.
164
+ * Creates a properly formatted nested dictionary reference.
165
+ *
166
+ * @param nestedContent - The nested content with dictionary key and optional path
167
+ * @returns Formatted string for the nested function call, or undefined if invalid
168
+ */
169
+ const buildNestedInitializer = (nestedContent) => {
170
+ if (!nestedContent || typeof nestedContent.dictionaryKey !== "string") return void 0;
171
+ if (nestedContent.path && typeof nestedContent.path === "string") return `nest(${JSON.stringify(nestedContent.dictionaryKey)}, ${JSON.stringify(nestedContent.path)})`;
172
+ return `nest(${JSON.stringify(nestedContent.dictionaryKey)})`;
173
+ };
174
+ /**
175
+ * Reads an existing translation map from a property in a content object.
176
+ * Parses the 't' function call and extracts the translation key-value pairs.
177
+ *
178
+ * @param contentObject - The object containing the property
179
+ * @param propertyName - The name of the property to read
180
+ * @returns Translation map with locale keys and values, or undefined if not found
181
+ */
182
+ const readExistingTranslationMap = (contentObject, propertyName) => {
183
+ const property = contentObject.getProperty(propertyName);
184
+ if (!property || !ts_morph.Node.isPropertyAssignment(property)) return void 0;
185
+ const propertyInitializer = property.getInitializer();
186
+ if (!propertyInitializer) return void 0;
187
+ if (!ts_morph.Node.isCallExpression(propertyInitializer)) return void 0;
188
+ const callExpression = propertyInitializer.getExpression();
189
+ if (!ts_morph.Node.isIdentifier(callExpression) || callExpression.getText() !== "t") return void 0;
190
+ const translationArgument = propertyInitializer.getArguments()[0];
191
+ if (!translationArgument || !ts_morph.Node.isObjectLiteralExpression(translationArgument)) return void 0;
192
+ const translationMap = {};
193
+ for (const propertyAssignment of translationArgument.getProperties()) {
194
+ if (!ts_morph.Node.isPropertyAssignment(propertyAssignment)) continue;
195
+ const cleanPropertyName = propertyAssignment.getNameNode().getText().replace(/^['"]|['"]$/g, "");
196
+ const valueInitializer = propertyAssignment.getInitializer();
197
+ if (valueInitializer && ts_morph.Node.isStringLiteral(valueInitializer)) translationMap[cleanPropertyName] = valueInitializer.getLiteralValue();
198
+ else if (valueInitializer && ts_morph.Node.isArrayLiteralExpression(valueInitializer)) {
199
+ const stringArray = [];
200
+ for (const arrayElement of valueInitializer.getElements()) {
201
+ if (!ts_morph.Node.isStringLiteral(arrayElement)) return void 0;
202
+ stringArray.push(arrayElement.getLiteralValue());
203
+ }
204
+ translationMap[cleanPropertyName] = stringArray;
205
+ } else return;
206
+ }
207
+ return translationMap;
208
+ };
209
+ /**
210
+ * Reads an existing map from a function call (enu, cond, or gender).
211
+ * Parses the function call and extracts the key-value pairs.
212
+ *
213
+ * @param contentObject - The object containing the property
214
+ * @param propertyName - The name of the property to read
215
+ * @param functionName - The name of the function to look for ('enu', 'cond', or 'gender')
216
+ * @returns Map with keys and string values, or undefined if not found
217
+ */
218
+ const readExistingMapFromCall = (contentObject, propertyName, functionName) => {
219
+ const property = contentObject.getProperty(propertyName);
220
+ if (!property || !ts_morph.Node.isPropertyAssignment(property)) return void 0;
221
+ const propertyInitializer = property.getInitializer();
222
+ if (!propertyInitializer || !ts_morph.Node.isCallExpression(propertyInitializer)) return void 0;
223
+ const callExpression = propertyInitializer.getExpression();
224
+ if (!ts_morph.Node.isIdentifier(callExpression) || callExpression.getText() !== functionName) return void 0;
225
+ const functionArgument = propertyInitializer.getArguments()[0];
226
+ if (!functionArgument || !ts_morph.Node.isObjectLiteralExpression(functionArgument)) return void 0;
227
+ const keyValueMap = {};
228
+ for (const propertyAssignment of functionArgument.getProperties()) {
229
+ if (!ts_morph.Node.isPropertyAssignment(propertyAssignment)) continue;
230
+ const cleanPropertyName = propertyAssignment.getNameNode().getText().replace(/^['"]|['"]$/g, "");
231
+ const valueInitializer = propertyAssignment.getInitializer();
232
+ if (valueInitializer && ts_morph.Node.isStringLiteral(valueInitializer)) keyValueMap[cleanPropertyName] = valueInitializer.getLiteralValue();
233
+ }
234
+ return keyValueMap;
235
+ };
236
+ /**
237
+ * Extracts generic type arguments text from a call expression.
238
+ * Returns the type arguments as a string (e.g., "<string[]>").
239
+ *
240
+ * @param callExpression - The call expression to extract type arguments from
241
+ * @returns Type arguments as a string, or undefined if none found
242
+ */
243
+ const getCallExpressionTypeArgsText = (callExpression) => {
244
+ try {
245
+ const typeArguments = callExpression.getTypeArguments();
246
+ if (!typeArguments || typeArguments.length === 0) return void 0;
247
+ return `<${typeArguments.map((typeArgument) => typeArgument.getText()).join(", ")}>`;
248
+ } catch {
249
+ return;
250
+ }
251
+ };
252
+ /**
253
+ * Reads existing type arguments used in a specific property call.
254
+ * Supports both direct calls and nested calls (e.g., md(t<...>(...))).
255
+ *
256
+ * @param contentObject - The object containing the property
257
+ * @param propertyName - The name of the property to read
258
+ * @param functionName - The name of the function to look for
259
+ * @returns Type arguments as a string, or undefined if not found
260
+ */
261
+ const readExistingTypeArgsForCall = (contentObject, propertyName, functionName) => {
262
+ const property = contentObject.getProperty(propertyName);
263
+ if (!property || !ts_morph.Node.isPropertyAssignment(property)) return void 0;
264
+ const propertyInitializer = property.getInitializer();
265
+ if (!propertyInitializer || !ts_morph.Node.isCallExpression(propertyInitializer)) return void 0;
266
+ const callExpression = propertyInitializer.getExpression();
267
+ if (ts_morph.Node.isIdentifier(callExpression) && callExpression.getText() === functionName) return getCallExpressionTypeArgsText(propertyInitializer);
268
+ if (functionName === "t" && ts_morph.Node.isIdentifier(callExpression) && callExpression.getText() === "md") {
269
+ const markdownArgument = propertyInitializer.getArguments()[0];
270
+ if (markdownArgument && ts_morph.Node.isCallExpression(markdownArgument)) {
271
+ const innerExpression = markdownArgument.getExpression();
272
+ if (ts_morph.Node.isIdentifier(innerExpression) && innerExpression.getText() === "t") return getCallExpressionTypeArgsText(markdownArgument);
273
+ }
274
+ }
275
+ };
276
+ /**
277
+ * Compares two string maps for equality.
278
+ * Filters out non-string values from the first map before comparison.
279
+ *
280
+ * @param firstMap - First map to compare (may contain non-string values)
281
+ * @param secondMap - Second map to compare (should contain only strings)
282
+ * @returns True if the string values in both maps are equal
283
+ */
284
+ const areStringMapsEqual = (firstMap, secondMap) => {
285
+ if (!secondMap) return false;
286
+ const firstMapStringEntries = Object.entries(firstMap).filter(([, value]) => typeof value === "string");
287
+ if (firstMapStringEntries.length !== Object.keys(firstMap).length) return false;
288
+ if (firstMapStringEntries.length !== Object.keys(secondMap).length) return false;
289
+ for (const [key, value] of firstMapStringEntries) {
290
+ if (!(key in secondMap)) return false;
291
+ if (secondMap[key] !== value) return false;
292
+ }
293
+ return true;
294
+ };
295
+ /**
296
+ * Compares translation maps for equality.
297
+ * Handles both string and array values in translations.
298
+ *
299
+ * @param desiredTranslationMap - The desired translation map
300
+ * @param existingTranslationMap - The existing translation map to compare against
301
+ * @returns True if both translation maps are equal
302
+ */
303
+ const areTranslationsEqual = (desiredTranslationMap, existingTranslationMap) => {
304
+ if (!existingTranslationMap) return false;
305
+ for (const [localeCode, desiredValue] of Object.entries(desiredTranslationMap)) {
306
+ if (!(localeCode in existingTranslationMap)) return false;
307
+ const existingValue = existingTranslationMap[localeCode];
308
+ if (typeof desiredValue === "string") {
309
+ if (typeof existingValue !== "string") return false;
310
+ if (existingValue !== desiredValue) return false;
311
+ } else if (Array.isArray(desiredValue)) {
312
+ if (!Array.isArray(existingValue)) return false;
313
+ if (existingValue.length !== desiredValue.length) return false;
314
+ for (let arrayIndex = 0; arrayIndex < desiredValue.length; arrayIndex++) if (existingValue[arrayIndex] !== desiredValue[arrayIndex]) return false;
315
+ } else return false;
316
+ }
317
+ return true;
318
+ };
319
+ /**
320
+ * Gets existing property names from the content object.
321
+ * Handles both regular property assignments and shorthand properties.
322
+ *
323
+ * @param contentObject - The object literal expression to extract property names from
324
+ * @returns Set of existing property names
325
+ */
326
+ const getExistingPropertyNames = (contentObject) => {
327
+ const existingPropertyNames = /* @__PURE__ */ new Set();
328
+ for (const property of contentObject.getProperties()) {
329
+ if (ts_morph.Node.isPropertyAssignment(property)) {
330
+ const propertyName = property.getName();
331
+ if (propertyName) existingPropertyNames.add(propertyName.replace(/^['"]|['"]$/g, ""));
332
+ continue;
333
+ }
334
+ if (ts_morph.Node.isShorthandPropertyAssignment(property)) {
335
+ const shorthandPropertyName = property.getNameNode().getText();
336
+ if (shorthandPropertyName) existingPropertyNames.add(shorthandPropertyName);
337
+ }
338
+ }
339
+ return existingPropertyNames;
340
+ };
341
+ /**
342
+ * Processes array content entries.
343
+ * Handles arrays of various content types including strings, objects, and complex content nodes.
344
+ * Supports nested objects within arrays and maintains existing translation structures.
345
+ *
346
+ * @param contentObject - The object containing the array property
347
+ * @param propertyKey - The key of the array property
348
+ * @param arrayValue - The array of values to process
349
+ * @param existingPropertyKeys - Set of existing property names in the content object
350
+ * @param effectiveFallbackLocale - The fallback locale for translations
351
+ * @param requiredImports - Set to track required imports
352
+ * @param sourceFile - The source file being processed
353
+ * @returns True if the content was modified
354
+ */
355
+ const processArrayContent = (contentObject, propertyKey, arrayValue, existingPropertyKeys, effectiveFallbackLocale, requiredImports, sourceFile) => {
356
+ if (!existingPropertyKeys.has(propertyKey)) {
357
+ const spreadTargetObject = findSpreadTargetObjectForKey(contentObject, propertyKey, sourceFile);
358
+ if (spreadTargetObject) return processArrayContent(spreadTargetObject, propertyKey, arrayValue, getExistingPropertyNames(spreadTargetObject), effectiveFallbackLocale, requiredImports, sourceFile);
359
+ }
360
+ const serializedArrayElements = [];
361
+ let hasUnsupportedContent = false;
362
+ let existingArrayElements;
363
+ let existingArrayHasTranslation = false;
364
+ let existingArrayTypeArguments;
365
+ let arrayWasChanged = false;
366
+ const existingProperty = contentObject.getProperty(propertyKey);
367
+ if (existingProperty && ts_morph.Node.isPropertyAssignment(existingProperty)) {
368
+ const propertyInitializer = existingProperty.getInitializer();
369
+ let existingPropertyTypeArguments;
370
+ const areAllDesiredValuesStrings = arrayValue.every((arrayElement) => typeof arrayElement === "string");
371
+ if (propertyInitializer && ts_morph.Node.isCallExpression(propertyInitializer) && ts_morph.Node.isIdentifier(propertyInitializer.getExpression()) && propertyInitializer.getExpression().getText() === "t" && areAllDesiredValuesStrings) {
372
+ existingPropertyTypeArguments = getCallExpressionTypeArgsText(propertyInitializer);
373
+ const existingTranslationMap = readExistingTranslationMap(contentObject, propertyKey);
374
+ if (existingTranslationMap) {
375
+ const translationInitializerText = buildTranslationInitializer({
376
+ ...existingTranslationMap,
377
+ [effectiveFallbackLocale]: arrayValue
378
+ }, existingPropertyTypeArguments);
379
+ requiredImports.add("t");
380
+ const property$1 = contentObject.getProperty(propertyKey);
381
+ if (property$1 && ts_morph.Node.isPropertyAssignment(property$1)) {
382
+ if (property$1.getInitializer()?.getText() !== translationInitializerText) {
383
+ property$1.setInitializer(translationInitializerText);
384
+ return true;
385
+ }
386
+ }
387
+ return false;
388
+ }
389
+ }
390
+ if (propertyInitializer && ts_morph.Node.isArrayLiteralExpression(propertyInitializer)) {
391
+ existingArrayElements = propertyInitializer.getElements();
392
+ existingArrayHasTranslation = propertyInitializer.getElements().some((arrayElement) => {
393
+ if (!ts_morph.Node.isCallExpression(arrayElement)) return false;
394
+ const callExpression = arrayElement.getExpression();
395
+ return ts_morph.Node.isIdentifier(callExpression) && callExpression.getText() === "t";
396
+ });
397
+ if (existingArrayHasTranslation) {
398
+ for (const arrayElement of existingArrayElements) if (ts_morph.Node.isCallExpression(arrayElement)) {
399
+ const callExpression = arrayElement.getExpression();
400
+ if (ts_morph.Node.isIdentifier(callExpression) && callExpression.getText() === "t") {
401
+ existingArrayTypeArguments = getCallExpressionTypeArgsText(arrayElement);
402
+ if (existingArrayTypeArguments) break;
403
+ }
404
+ }
405
+ }
406
+ }
407
+ }
408
+ for (let elementIndex = 0; elementIndex < arrayValue.length; elementIndex++) {
409
+ const currentElement = arrayValue[elementIndex];
410
+ if (currentElement === null || currentElement === void 0 || typeof currentElement === "string" || typeof currentElement === "number" || typeof currentElement === "boolean") {
411
+ let serializedElementValue = serializeValue(currentElement);
412
+ if (typeof currentElement === "string" && existingArrayElements && elementIndex < existingArrayElements.length) {
413
+ const existingArrayElement = existingArrayElements[elementIndex];
414
+ if (ts_morph.Node.isCallExpression(existingArrayElement)) {
415
+ const callExpression = existingArrayElement.getExpression();
416
+ if (ts_morph.Node.isIdentifier(callExpression) && callExpression.getText() === "t") {
417
+ const translationArgument = existingArrayElement.getArguments()[0];
418
+ if (translationArgument && ts_morph.Node.isObjectLiteralExpression(translationArgument)) {
419
+ const translationMap = {};
420
+ for (const propertyAssignment of translationArgument.getProperties()) {
421
+ if (!ts_morph.Node.isPropertyAssignment(propertyAssignment)) continue;
422
+ const cleanPropertyName = propertyAssignment.getNameNode().getText().replace(/^['"]|['"]$/g, "");
423
+ const propertyValue = propertyAssignment.getInitializer();
424
+ if (propertyValue && ts_morph.Node.isStringLiteral(propertyValue)) translationMap[cleanPropertyName] = propertyValue.getLiteralValue();
425
+ }
426
+ serializedElementValue = buildTranslationInitializer(syncNumericSuffixAcrossLocales(translationMap, effectiveFallbackLocale, currentElement), getCallExpressionTypeArgsText(existingArrayElement));
427
+ requiredImports.add("t");
428
+ }
429
+ }
430
+ }
431
+ }
432
+ if (typeof currentElement === "string" && existingArrayHasTranslation && serializedElementValue && serializedElementValue.startsWith("\"")) {
433
+ serializedElementValue = buildTranslationInitializer({ [effectiveFallbackLocale]: currentElement }, existingArrayTypeArguments);
434
+ requiredImports.add("t");
435
+ }
436
+ if (serializedElementValue === void 0) {
437
+ hasUnsupportedContent = true;
438
+ break;
439
+ }
440
+ serializedArrayElements.push(serializedElementValue);
441
+ } else if (typeof currentElement === "object" && currentElement !== null) {
442
+ if (existingArrayElements && elementIndex < existingArrayElements.length) {
443
+ const existingArrayElement = existingArrayElements[elementIndex];
444
+ if (ts_morph.Node.isObjectLiteralExpression(existingArrayElement)) {
445
+ if (processContentEntries(existingArrayElement, currentElement, effectiveFallbackLocale, requiredImports, sourceFile)) arrayWasChanged = true;
446
+ serializedArrayElements.push(existingArrayElement.getText());
447
+ } else {
448
+ const serializedElementValue = serializeValue(currentElement);
449
+ if (serializedElementValue === void 0) {
450
+ hasUnsupportedContent = true;
451
+ break;
452
+ }
453
+ serializedArrayElements.push(serializedElementValue);
454
+ }
455
+ } else {
456
+ const serializedElementValue = serializeValue(currentElement);
457
+ if (serializedElementValue === void 0) {
458
+ hasUnsupportedContent = true;
459
+ break;
460
+ }
461
+ serializedArrayElements.push(serializedElementValue);
462
+ }
463
+ const elementNodeType = (0, __intlayer_core.getNodeType)(currentElement);
464
+ if (elementNodeType === __intlayer_types.NodeType.Translation) requiredImports.add("t");
465
+ else if (elementNodeType === __intlayer_types.NodeType.Enumeration) requiredImports.add("enu");
466
+ else if (elementNodeType === __intlayer_types.NodeType.Condition) requiredImports.add("cond");
467
+ else if (elementNodeType === __intlayer_types.NodeType.Gender) requiredImports.add("gender");
468
+ else if (elementNodeType === __intlayer_types.NodeType.Insertion) {
469
+ requiredImports.add("insert");
470
+ const insertionContent = currentElement[__intlayer_types.NodeType.Insertion];
471
+ if (typeof insertionContent === "object" && insertionContent !== null && (0, __intlayer_core.getNodeType)(insertionContent) === __intlayer_types.NodeType.Translation) requiredImports.add("t");
472
+ } else if (elementNodeType === __intlayer_types.NodeType.Markdown) {
473
+ requiredImports.add("md");
474
+ const markdownContent = currentElement[__intlayer_types.NodeType.Markdown];
475
+ if (typeof markdownContent === "object" && markdownContent !== null && (0, __intlayer_core.getNodeType)(markdownContent) === __intlayer_types.NodeType.File) requiredImports.add("file");
476
+ } else if (elementNodeType === __intlayer_types.NodeType.File) requiredImports.add("file");
477
+ else if (elementNodeType === __intlayer_types.NodeType.Nested) requiredImports.add("nest");
478
+ } else {
479
+ hasUnsupportedContent = true;
480
+ break;
481
+ }
482
+ }
483
+ if (hasUnsupportedContent) return false;
484
+ if (arrayWasChanged) return true;
485
+ const arrayInitializerText = `[ ${serializedArrayElements.join(", ")} ]`;
486
+ if (!existingPropertyKeys.has(propertyKey)) {
487
+ contentObject.addPropertyAssignment({
488
+ name: propertyKey,
489
+ initializer: arrayInitializerText
490
+ });
491
+ return true;
492
+ }
493
+ const property = contentObject.getProperty(propertyKey);
494
+ if (property && ts_morph.Node.isPropertyAssignment(property)) {
495
+ const existingSerializedArray = readExistingArraySerialized(contentObject, propertyKey);
496
+ if (!(existingSerializedArray !== void 0 && existingSerializedArray.length === serializedArrayElements.length && existingSerializedArray.every((existingElement, elementIndex) => existingElement === serializedArrayElements[elementIndex]))) {
497
+ property.setInitializer(arrayInitializerText);
498
+ return true;
499
+ }
500
+ }
501
+ return false;
502
+ };
503
+ /**
504
+ * Processes primitive content entries (string, number, boolean, null).
505
+ * Handles simple value types and updates existing translation maps when appropriate.
506
+ *
507
+ * @param contentObject - The object containing the property
508
+ * @param propertyKey - The key of the property to process
509
+ * @param primitiveValue - The primitive value to process
510
+ * @param existingPropertyKeys - Set of existing property names
511
+ * @param effectiveFallbackLocale - The fallback locale for translations
512
+ * @param requiredImports - Set to track required imports
513
+ * @param sourceFile - The source file being processed
514
+ * @returns True if the content was modified
515
+ */
516
+ const processPrimitiveContent = (contentObject, propertyKey, primitiveValue, existingPropertyKeys, effectiveFallbackLocale, requiredImports, sourceFile) => {
517
+ if (typeof primitiveValue === "string" && existingPropertyKeys.has(propertyKey)) {
518
+ const property$1 = contentObject.getProperty(propertyKey);
519
+ if (property$1 && ts_morph.Node.isPropertyAssignment(property$1)) {
520
+ const propertyInitializer = property$1.getInitializer();
521
+ if (propertyInitializer && !ts_morph.Node.isStringLiteral(propertyInitializer) && !ts_morph.Node.isCallExpression(propertyInitializer)) {
522
+ console.log(`Skipping update for key "${propertyKey}" because existing value is not a string literal`);
523
+ return false;
524
+ }
525
+ }
526
+ const existingTranslationMap = readExistingTranslationMap(contentObject, propertyKey);
527
+ if (existingTranslationMap) {
528
+ const translationInitializerText = buildTranslationInitializer({
529
+ ...existingTranslationMap,
530
+ [effectiveFallbackLocale]: primitiveValue
531
+ }, readExistingTypeArgsForCall(contentObject, propertyKey, "t"));
532
+ requiredImports.add("t");
533
+ if (property$1 && ts_morph.Node.isPropertyAssignment(property$1)) {
534
+ property$1.setInitializer(translationInitializerText);
535
+ return true;
536
+ }
537
+ return false;
538
+ }
539
+ }
540
+ if (!existingPropertyKeys.has(propertyKey)) {
541
+ const spreadTargetObject = findSpreadTargetObjectForKey(contentObject, propertyKey, sourceFile);
542
+ if (spreadTargetObject) return processPrimitiveContent(spreadTargetObject, propertyKey, primitiveValue, getExistingPropertyNames(spreadTargetObject), effectiveFallbackLocale, requiredImports, sourceFile);
543
+ contentObject.addPropertyAssignment({
544
+ name: propertyKey,
545
+ initializer: typeof primitiveValue === "string" ? JSON.stringify(primitiveValue) : String(primitiveValue)
546
+ });
547
+ return true;
548
+ }
549
+ const property = contentObject.getProperty(propertyKey);
550
+ if (property && ts_morph.Node.isPropertyAssignment(property)) {
551
+ const propertyInitializer = property.getInitializer();
552
+ const isPrimitiveLiteral = propertyInitializer && (ts_morph.Node.isStringLiteral(propertyInitializer) || ts_morph.Node.isNumericLiteral(propertyInitializer) || propertyInitializer.getKind() === ts_morph.SyntaxKind.TrueKeyword || propertyInitializer.getKind() === ts_morph.SyntaxKind.FalseKeyword || ts_morph.Node.isNullLiteral(propertyInitializer) || ts_morph.Node.isCallExpression(propertyInitializer));
553
+ if (propertyInitializer && !isPrimitiveLiteral) {
554
+ console.log(`Skipping update for key "${propertyKey}" because existing value is not a primitive literal`);
555
+ return false;
556
+ }
557
+ const currentInitializerText = propertyInitializer?.getText();
558
+ const desiredInitializerText = typeof primitiveValue === "string" ? JSON.stringify(primitiveValue) : String(primitiveValue);
559
+ if (currentInitializerText !== desiredInitializerText) {
560
+ property.setInitializer(desiredInitializerText);
561
+ return true;
562
+ }
563
+ }
564
+ return false;
565
+ };
566
+ /**
567
+ * Processes complex content entries (translation, enumeration, condition, etc.).
568
+ * Routes content to the appropriate specialized processor based on node type.
569
+ *
570
+ * @param contentObject - The object containing the property
571
+ * @param propertyKey - The key of the property to process
572
+ * @param contentNode - The complex content node to process
573
+ * @param existingPropertyKeys - Set of existing property names
574
+ * @param effectiveFallbackLocale - The fallback locale for translations
575
+ * @param requiredImports - Set to track required imports
576
+ * @param sourceFile - The source file being processed
577
+ * @returns True if the content was modified
578
+ */
579
+ const processComplexContent = (contentObject, propertyKey, contentNode, existingPropertyKeys, effectiveFallbackLocale, requiredImports, sourceFile) => {
580
+ switch ((0, __intlayer_core.getNodeType)(contentNode)) {
581
+ case __intlayer_types.NodeType.Translation: return processTranslationContent(contentObject, propertyKey, contentNode, existingPropertyKeys, requiredImports, sourceFile);
582
+ case __intlayer_types.NodeType.Enumeration: return processEnumerationContent(contentObject, propertyKey, contentNode, existingPropertyKeys, requiredImports, sourceFile);
583
+ case __intlayer_types.NodeType.Condition: return processConditionContent(contentObject, propertyKey, contentNode, existingPropertyKeys, requiredImports, sourceFile);
584
+ case __intlayer_types.NodeType.Gender: return processGenderContent(contentObject, propertyKey, contentNode, existingPropertyKeys, requiredImports, sourceFile);
585
+ case __intlayer_types.NodeType.Insertion: return processInsertionContent(contentObject, propertyKey, contentNode, existingPropertyKeys, requiredImports, sourceFile);
586
+ case __intlayer_types.NodeType.Markdown: return processMarkdownContent(contentObject, propertyKey, contentNode, existingPropertyKeys, effectiveFallbackLocale, requiredImports, sourceFile);
587
+ case __intlayer_types.NodeType.File: return processFileContent(contentObject, propertyKey, contentNode, existingPropertyKeys, requiredImports, sourceFile);
588
+ case __intlayer_types.NodeType.Nested: return processNestedContent(contentObject, propertyKey, contentNode, existingPropertyKeys, requiredImports, sourceFile);
589
+ default: return false;
590
+ }
591
+ };
592
+ /**
593
+ * Processes translation content.
594
+ * Handles translation objects with locale keys and string/array values.
595
+ *
596
+ * @param contentObject - The object containing the property
597
+ * @param propertyKey - The key of the property to process
598
+ * @param contentNode - The translation content node
599
+ * @param existingPropertyKeys - Set of existing property names
600
+ * @param requiredImports - Set to track required imports
601
+ * @param sourceFile - The source file being processed
602
+ * @returns True if the content was modified
603
+ */
604
+ const processTranslationContent = (contentObject, propertyKey, contentNode, existingPropertyKeys, requiredImports, sourceFile) => {
605
+ const translationMap = contentNode[__intlayer_types.NodeType.Translation] ?? {};
606
+ const areAllValuesStringsOrArrays = Object.values(translationMap).every((translationValue) => typeof translationValue === "string" || Array.isArray(translationValue));
607
+ if (Object.values(translationMap).some((translationValue) => typeof translationValue === "object" && translationValue !== null && !Array.isArray(translationValue) && (0, __intlayer_core.getNodeType)(translationValue) !== __intlayer_types.NodeType.Text) && !areAllValuesStringsOrArrays) {
608
+ if (!existingPropertyKeys.has(propertyKey)) {
609
+ const spreadTargetObject = findSpreadTargetObjectForKey(contentObject, propertyKey, sourceFile);
610
+ if (spreadTargetObject) return processTranslationContent(spreadTargetObject, propertyKey, contentNode, getExistingPropertyNames(spreadTargetObject), requiredImports, sourceFile);
611
+ }
612
+ const translationParts$1 = [];
613
+ let hasUnsupportedValue = false;
614
+ for (const [localeCode, translationValue] of Object.entries(translationMap)) {
615
+ const formattedLocaleKey = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(localeCode) ? localeCode : JSON.stringify(localeCode);
616
+ if (typeof translationValue === "object" && translationValue !== null && !Array.isArray(translationValue)) {
617
+ const serializedValue = serializeValue(translationValue);
618
+ if (serializedValue === void 0) {
619
+ hasUnsupportedValue = true;
620
+ break;
621
+ }
622
+ translationParts$1.push(`${formattedLocaleKey}: ${serializedValue}`);
623
+ const nodeType = (0, __intlayer_core.getNodeType)(translationValue);
624
+ if (nodeType === __intlayer_types.NodeType.Markdown) {
625
+ requiredImports.add("md");
626
+ const markdownContent = translationValue[__intlayer_types.NodeType.Markdown];
627
+ if (typeof markdownContent === "object" && markdownContent !== null && (0, __intlayer_core.getNodeType)(markdownContent) === __intlayer_types.NodeType.File) requiredImports.add("file");
628
+ } else if (nodeType === __intlayer_types.NodeType.File) requiredImports.add("file");
629
+ else if (nodeType === __intlayer_types.NodeType.Insertion) requiredImports.add("insert");
630
+ else if (nodeType === __intlayer_types.NodeType.Enumeration) requiredImports.add("enu");
631
+ else if (nodeType === __intlayer_types.NodeType.Condition) requiredImports.add("cond");
632
+ else if (nodeType === __intlayer_types.NodeType.Gender) requiredImports.add("gender");
633
+ else if (nodeType === __intlayer_types.NodeType.Nested) requiredImports.add("nest");
634
+ } else if (typeof translationValue === "string") translationParts$1.push(`${formattedLocaleKey}: ${JSON.stringify(translationValue)}`);
635
+ else if (Array.isArray(translationValue)) {
636
+ const serializedArrayElements = translationValue.map((arrayElement) => JSON.stringify(arrayElement)).join(", ");
637
+ translationParts$1.push(`${formattedLocaleKey}: [ ${serializedArrayElements} ]`);
638
+ }
639
+ }
640
+ if (hasUnsupportedValue) return false;
641
+ const translationInitializerText$1 = `t${readExistingTypeArgsForCall(contentObject, propertyKey, "t") ?? ""}({ ${translationParts$1.join(", ")} })`;
642
+ if (!existingPropertyKeys.has(propertyKey)) {
643
+ requiredImports.add("t");
644
+ contentObject.addPropertyAssignment({
645
+ name: propertyKey,
646
+ initializer: translationInitializerText$1
647
+ });
648
+ return true;
649
+ }
650
+ const property = contentObject.getProperty(propertyKey);
651
+ if (property && ts_morph.Node.isPropertyAssignment(property)) {
652
+ if (property.getInitializer()?.getText() !== translationInitializerText$1) {
653
+ requiredImports.add("t");
654
+ property.setInitializer(translationInitializerText$1);
655
+ return true;
656
+ }
657
+ }
658
+ return false;
659
+ }
660
+ if (!areAllValuesStringsOrArrays) return false;
661
+ if (!existingPropertyKeys.has(propertyKey)) {
662
+ const spreadTargetObject = findSpreadTargetObjectForKey(contentObject, propertyKey, sourceFile);
663
+ if (spreadTargetObject) return processTranslationContent(spreadTargetObject, propertyKey, contentNode, getExistingPropertyNames(spreadTargetObject), requiredImports, sourceFile);
664
+ }
665
+ const translationParts = [];
666
+ for (const [localeCode, translationValue] of Object.entries(translationMap)) {
667
+ const formattedLocaleKey = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(localeCode) ? localeCode : JSON.stringify(localeCode);
668
+ if (typeof translationValue === "string") translationParts.push(`${formattedLocaleKey}: ${JSON.stringify(translationValue)}`);
669
+ else if (Array.isArray(translationValue)) {
670
+ const serializedArrayElements = translationValue.map((arrayElement) => JSON.stringify(arrayElement)).join(", ");
671
+ translationParts.push(`${formattedLocaleKey}: [ ${serializedArrayElements} ]`);
672
+ }
673
+ }
674
+ const translationInitializerText = `t${readExistingTypeArgsForCall(contentObject, propertyKey, "t") ?? ""}({ ${translationParts.join(", ")} })`;
675
+ if (!existingPropertyKeys.has(propertyKey)) {
676
+ requiredImports.add("t");
677
+ contentObject.addPropertyAssignment({
678
+ name: propertyKey,
679
+ initializer: translationInitializerText
680
+ });
681
+ return true;
682
+ }
683
+ if (!areTranslationsEqual(translationMap, readExistingTranslationMap(contentObject, propertyKey))) {
684
+ requiredImports.add("t");
685
+ const property = contentObject.getProperty(propertyKey);
686
+ if (property && ts_morph.Node.isPropertyAssignment(property)) {
687
+ property.setInitializer(translationInitializerText);
688
+ return true;
689
+ }
690
+ }
691
+ return false;
692
+ };
693
+ /**
694
+ * Processes enumeration content.
695
+ * Handles enumeration objects with key-value string pairs.
696
+ *
697
+ * @param contentObject - The object containing the property
698
+ * @param propertyKey - The key of the property to process
699
+ * @param contentNode - The enumeration content node
700
+ * @param existingPropertyKeys - Set of existing property names
701
+ * @param requiredImports - Set to track required imports
702
+ * @param sourceFile - The source file being processed
703
+ * @returns True if the content was modified
704
+ */
705
+ const processEnumerationContent = (contentObject, propertyKey, contentNode, existingPropertyKeys, requiredImports, sourceFile) => {
706
+ const enumerationMap = contentNode[__intlayer_types.NodeType.Enumeration];
707
+ if (!Object.values(enumerationMap).every((enumerationValue) => typeof enumerationValue === "string")) return false;
708
+ const enumerationInitializerText = buildEnumerationInitializer(enumerationMap);
709
+ if (!enumerationInitializerText) return false;
710
+ if (!existingPropertyKeys.has(propertyKey)) {
711
+ const spreadTargetObject = findSpreadTargetObjectForKey(contentObject, propertyKey, sourceFile);
712
+ if (spreadTargetObject) return processEnumerationContent(spreadTargetObject, propertyKey, contentNode, getExistingPropertyNames(spreadTargetObject), requiredImports, sourceFile);
713
+ requiredImports.add("enu");
714
+ contentObject.addPropertyAssignment({
715
+ name: propertyKey,
716
+ initializer: enumerationInitializerText
717
+ });
718
+ return true;
719
+ }
720
+ if (!areStringMapsEqual(enumerationMap, readExistingMapFromCall(contentObject, propertyKey, "enu"))) {
721
+ requiredImports.add("enu");
722
+ const property = contentObject.getProperty(propertyKey);
723
+ if (property && ts_morph.Node.isPropertyAssignment(property)) {
724
+ property.setInitializer(enumerationInitializerText);
725
+ return true;
726
+ }
727
+ }
728
+ return false;
729
+ };
730
+ /**
731
+ * Processes condition content.
732
+ * Handles condition objects with key-value string pairs.
733
+ *
734
+ * @param contentObject - The object containing the property
735
+ * @param propertyKey - The key of the property to process
736
+ * @param contentNode - The condition content node
737
+ * @param existingPropertyKeys - Set of existing property names
738
+ * @param requiredImports - Set to track required imports
739
+ * @param sourceFile - The source file being processed
740
+ * @returns True if the content was modified
741
+ */
742
+ const processConditionContent = (contentObject, propertyKey, contentNode, existingPropertyKeys, requiredImports, sourceFile) => {
743
+ const conditionMap = contentNode[__intlayer_types.NodeType.Condition];
744
+ if (Object.values(conditionMap).every((conditionValue) => typeof conditionValue === "string")) {
745
+ const conditionInitializerText = buildConditionInitializer(conditionMap);
746
+ if (!conditionInitializerText) return false;
747
+ if (!existingPropertyKeys.has(propertyKey)) {
748
+ const spreadTargetObject = findSpreadTargetObjectForKey(contentObject, propertyKey, sourceFile);
749
+ if (spreadTargetObject) return processConditionContent(spreadTargetObject, propertyKey, contentNode, getExistingPropertyNames(spreadTargetObject), requiredImports, sourceFile);
750
+ requiredImports.add("cond");
751
+ contentObject.addPropertyAssignment({
752
+ name: propertyKey,
753
+ initializer: conditionInitializerText
754
+ });
755
+ return true;
756
+ }
757
+ if (!areStringMapsEqual(conditionMap, readExistingMapFromCall(contentObject, propertyKey, "cond"))) {
758
+ requiredImports.add("cond");
759
+ const property$1 = contentObject.getProperty(propertyKey);
760
+ if (property$1 && ts_morph.Node.isPropertyAssignment(property$1)) {
761
+ property$1.setInitializer(conditionInitializerText);
762
+ return true;
763
+ }
764
+ }
765
+ return false;
766
+ }
767
+ if (!existingPropertyKeys.has(propertyKey)) {
768
+ const spreadTargetObject = findSpreadTargetObjectForKey(contentObject, propertyKey, sourceFile);
769
+ if (spreadTargetObject) return processConditionContent(spreadTargetObject, propertyKey, contentNode, getExistingPropertyNames(spreadTargetObject), requiredImports, sourceFile);
770
+ return false;
771
+ }
772
+ const property = contentObject.getProperty(propertyKey);
773
+ if (!property || !ts_morph.Node.isPropertyAssignment(property)) return false;
774
+ const propertyInitializer = property.getInitializer();
775
+ if (!propertyInitializer || !ts_morph.Node.isCallExpression(propertyInitializer)) return false;
776
+ const callExpression = propertyInitializer.getExpression();
777
+ if (!ts_morph.Node.isIdentifier(callExpression) || callExpression.getText() !== "cond") return false;
778
+ const condArgument = propertyInitializer.getArguments()[0];
779
+ if (!condArgument || !ts_morph.Node.isObjectLiteralExpression(condArgument)) return false;
780
+ requiredImports.add("cond");
781
+ let hasModifications = false;
782
+ for (const [conditionKey, conditionValue] of Object.entries(conditionMap)) {
783
+ const nodeType = (0, __intlayer_core.getNodeType)(conditionValue);
784
+ if (!nodeType) continue;
785
+ let condProperty = condArgument.getProperty(conditionKey);
786
+ if (!condProperty) condProperty = condArgument.getProperty(stringifyKey(conditionKey));
787
+ if (!condProperty || !ts_morph.Node.isPropertyAssignment(condProperty)) continue;
788
+ const condValueInitializer = condProperty.getInitializer();
789
+ if (!condValueInitializer) continue;
790
+ if (nodeType === __intlayer_types.NodeType.Translation) {
791
+ if (!ts_morph.Node.isCallExpression(condValueInitializer)) continue;
792
+ const tCallExpression = condValueInitializer.getExpression();
793
+ if (!ts_morph.Node.isIdentifier(tCallExpression) || tCallExpression.getText() !== "t") continue;
794
+ const tArgument = condValueInitializer.getArguments()[0];
795
+ if (!tArgument || !ts_morph.Node.isObjectLiteralExpression(tArgument)) continue;
796
+ const translationMap = conditionValue[__intlayer_types.NodeType.Translation];
797
+ if (!translationMap || typeof translationMap !== "object") continue;
798
+ const existingTranslationMap = {};
799
+ for (const propertyAssignment of tArgument.getProperties()) {
800
+ if (!ts_morph.Node.isPropertyAssignment(propertyAssignment)) continue;
801
+ const cleanPropertyName = propertyAssignment.getNameNode().getText().replace(/^['"]|['"]$/g, "");
802
+ const valueInitializer = propertyAssignment.getInitializer();
803
+ if (valueInitializer && ts_morph.Node.isStringLiteral(valueInitializer)) existingTranslationMap[cleanPropertyName] = valueInitializer.getLiteralValue();
804
+ else if (valueInitializer && ts_morph.Node.isArrayLiteralExpression(valueInitializer)) {
805
+ const stringArray = [];
806
+ for (const arrayElement of valueInitializer.getElements()) if (ts_morph.Node.isStringLiteral(arrayElement)) stringArray.push(arrayElement.getLiteralValue());
807
+ existingTranslationMap[cleanPropertyName] = stringArray;
808
+ }
809
+ }
810
+ if (!areTranslationsEqual(translationMap, existingTranslationMap)) {
811
+ requiredImports.add("t");
812
+ for (const [locale, localeValue] of Object.entries(translationMap)) {
813
+ const isLocaleCodeValidIdentifier = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(locale);
814
+ const formattedLocaleKey = isLocaleCodeValidIdentifier ? locale : JSON.stringify(locale);
815
+ let existingProperty = tArgument.getProperty(locale);
816
+ if (!existingProperty && !isLocaleCodeValidIdentifier) existingProperty = tArgument.getProperty(JSON.stringify(locale));
817
+ if (existingProperty && ts_morph.Node.isPropertyAssignment(existingProperty)) {
818
+ const currentValue = existingProperty.getInitializer();
819
+ const newValue = Array.isArray(localeValue) ? `[${localeValue.map((v) => JSON.stringify(v)).join(", ")}]` : JSON.stringify(localeValue);
820
+ if (currentValue?.getText() !== newValue) {
821
+ existingProperty.setInitializer(newValue);
822
+ hasModifications = true;
823
+ }
824
+ } else if (!existingProperty) {
825
+ const newValue = Array.isArray(localeValue) ? `[${localeValue.map((v) => JSON.stringify(v)).join(", ")}]` : JSON.stringify(localeValue);
826
+ tArgument.addPropertyAssignment({
827
+ name: formattedLocaleKey,
828
+ initializer: newValue
829
+ });
830
+ hasModifications = true;
831
+ }
832
+ }
833
+ }
834
+ }
835
+ }
836
+ return hasModifications;
837
+ };
838
+ /**
839
+ * Processes gender content.
840
+ * Handles gender objects with key-value string pairs.
841
+ *
842
+ * @param contentObject - The object containing the property
843
+ * @param propertyKey - The key of the property to process
844
+ * @param contentNode - The gender content node
845
+ * @param existingPropertyKeys - Set of existing property names
846
+ * @param requiredImports - Set to track required imports
847
+ * @param sourceFile - The source file being processed
848
+ * @returns True if the content was modified
849
+ */
850
+ const processGenderContent = (contentObject, propertyKey, contentNode, existingPropertyKeys, requiredImports, sourceFile) => {
851
+ const genderMap = contentNode[__intlayer_types.NodeType.Gender];
852
+ if (!Object.values(genderMap).every((genderValue) => typeof genderValue === "string")) return false;
853
+ const genderInitializerText = buildGenderInitializer(genderMap);
854
+ if (!genderInitializerText) return false;
855
+ if (!existingPropertyKeys.has(propertyKey)) {
856
+ const spreadTargetObject = findSpreadTargetObjectForKey(contentObject, propertyKey, sourceFile);
857
+ if (spreadTargetObject) return processGenderContent(spreadTargetObject, propertyKey, contentNode, getExistingPropertyNames(spreadTargetObject), requiredImports, sourceFile);
858
+ requiredImports.add("gender");
859
+ contentObject.addPropertyAssignment({
860
+ name: propertyKey,
861
+ initializer: genderInitializerText
862
+ });
863
+ return true;
864
+ }
865
+ if (!areStringMapsEqual(genderMap, readExistingMapFromCall(contentObject, propertyKey, "gender"))) {
866
+ requiredImports.add("gender");
867
+ const property = contentObject.getProperty(propertyKey);
868
+ if (property && ts_morph.Node.isPropertyAssignment(property)) {
869
+ property.setInitializer(genderInitializerText);
870
+ return true;
871
+ }
872
+ }
873
+ return false;
874
+ };
875
+ /**
876
+ * Processes insertion content.
877
+ * Handles insertion objects with string or translation content.
878
+ *
879
+ * @param contentObject - The object containing the property
880
+ * @param propertyKey - The key of the property to process
881
+ * @param contentNode - The insertion content node
882
+ * @param existingPropertyKeys - Set of existing property names
883
+ * @param requiredImports - Set to track required imports
884
+ * @param sourceFile - The source file being processed
885
+ * @returns True if the content was modified
886
+ */
887
+ const processInsertionContent = (contentObject, propertyKey, contentNode, existingPropertyKeys, requiredImports, sourceFile) => {
888
+ const insertionContent = contentNode[__intlayer_types.NodeType.Insertion];
889
+ const insertionInitializerText = buildInsertionInitializer(insertionContent);
890
+ if (!insertionInitializerText) return false;
891
+ if (!existingPropertyKeys.has(propertyKey)) {
892
+ const spreadTargetObject = findSpreadTargetObjectForKey(contentObject, propertyKey, sourceFile);
893
+ if (spreadTargetObject) return processInsertionContent(spreadTargetObject, propertyKey, contentNode, getExistingPropertyNames(spreadTargetObject), requiredImports, sourceFile);
894
+ requiredImports.add("insert");
895
+ if (typeof insertionContent === "object" && insertionContent !== null && (0, __intlayer_core.getNodeType)(insertionContent) === __intlayer_types.NodeType.Translation) requiredImports.add("t");
896
+ contentObject.addPropertyAssignment({
897
+ name: propertyKey,
898
+ initializer: insertionInitializerText
899
+ });
900
+ return true;
901
+ }
902
+ const existingInsertion = readExistingInsertion(contentObject, propertyKey);
903
+ if (!(typeof insertionContent === "string" && existingInsertion?.kind === "string" && existingInsertion.value === insertionContent || typeof insertionContent === "object" && insertionContent !== null && (0, __intlayer_core.getNodeType)(insertionContent) === __intlayer_types.NodeType.Translation && existingInsertion?.kind === "translation" && areStringMapsEqual(insertionContent[__intlayer_types.NodeType.Translation] ?? {}, existingInsertion.map))) {
904
+ requiredImports.add("insert");
905
+ if (typeof insertionContent === "object" && insertionContent !== null && (0, __intlayer_core.getNodeType)(insertionContent) === __intlayer_types.NodeType.Translation) requiredImports.add("t");
906
+ const property = contentObject.getProperty(propertyKey);
907
+ if (property && ts_morph.Node.isPropertyAssignment(property)) {
908
+ property.setInitializer(insertionInitializerText);
909
+ return true;
910
+ }
911
+ }
912
+ return false;
913
+ };
914
+ /**
915
+ * Processes markdown content.
916
+ * Handles markdown objects with string, translation, or file content.
917
+ *
918
+ * @param contentObject - The object containing the property
919
+ * @param propertyKey - The key of the property to process
920
+ * @param contentNode - The markdown content node
921
+ * @param existingPropertyKeys - Set of existing property names
922
+ * @param effectiveFallbackLocale - The fallback locale for translations
923
+ * @param requiredImports - Set to track required imports
924
+ * @param sourceFile - The source file being processed
925
+ * @returns True if the content was modified
926
+ */
927
+ const processMarkdownContent = (contentObject, propertyKey, contentNode, existingPropertyKeys, effectiveFallbackLocale, requiredImports, sourceFile) => {
928
+ const markdownContent = contentNode[__intlayer_types.NodeType.Markdown];
929
+ const markdownInitializerText = buildMarkdownInitializer(markdownContent);
930
+ if (!markdownInitializerText) return false;
931
+ if (!existingPropertyKeys.has(propertyKey)) {
932
+ const spreadTargetObject = findSpreadTargetObjectForKey(contentObject, propertyKey, sourceFile);
933
+ if (spreadTargetObject) return processMarkdownContent(spreadTargetObject, propertyKey, contentNode, getExistingPropertyNames(spreadTargetObject), effectiveFallbackLocale, requiredImports, sourceFile);
934
+ requiredImports.add("md");
935
+ const markdownNodeType$1 = (0, __intlayer_core.getNodeType)(markdownContent);
936
+ if (markdownNodeType$1 === __intlayer_types.NodeType.File) requiredImports.add("file");
937
+ else if (markdownNodeType$1 === __intlayer_types.NodeType.Translation) requiredImports.add("t");
938
+ contentObject.addPropertyAssignment({
939
+ name: propertyKey,
940
+ initializer: markdownInitializerText
941
+ });
942
+ return true;
943
+ }
944
+ const markdownNodeType = (0, __intlayer_core.getNodeType)(markdownContent);
945
+ const existingSimpleMarkdown = readExistingMarkdown(contentObject, propertyKey);
946
+ const existingMarkdownTranslationMap = readExistingMarkdownTranslationMap(contentObject, propertyKey);
947
+ const existingTranslationTypeArguments = readExistingTypeArgsForCall(contentObject, propertyKey, "t");
948
+ if (typeof markdownContent === "string" && existingMarkdownTranslationMap && effectiveFallbackLocale) {
949
+ const updatedTranslationMap = {
950
+ ...existingMarkdownTranslationMap,
951
+ [effectiveFallbackLocale]: markdownContent
952
+ };
953
+ requiredImports.add("md");
954
+ requiredImports.add("t");
955
+ const property = contentObject.getProperty(propertyKey);
956
+ if (property && ts_morph.Node.isPropertyAssignment(property)) {
957
+ property.setInitializer(`md(${buildTranslationInitializer(updatedTranslationMap, existingTranslationTypeArguments)})`);
958
+ return true;
959
+ }
960
+ return false;
961
+ }
962
+ if (markdownNodeType === __intlayer_types.NodeType.Translation) {
963
+ const markdownTranslationMap = markdownContent[__intlayer_types.NodeType.Translation];
964
+ if (!Object.values(markdownTranslationMap).every((translationValue) => typeof translationValue === "string")) return false;
965
+ if (!areStringMapsEqual(markdownTranslationMap, existingMarkdownTranslationMap)) {
966
+ requiredImports.add("md");
967
+ requiredImports.add("t");
968
+ const property = contentObject.getProperty(propertyKey);
969
+ if (property && ts_morph.Node.isPropertyAssignment(property)) {
970
+ property.setInitializer(`md(${buildTranslationInitializer(markdownTranslationMap, existingTranslationTypeArguments)})`);
971
+ return true;
972
+ }
973
+ }
974
+ return false;
975
+ }
976
+ if (!(typeof markdownContent === "string" && existingSimpleMarkdown?.kind === "string" && existingSimpleMarkdown.value === markdownContent || markdownNodeType === __intlayer_types.NodeType.File && existingSimpleMarkdown?.kind === "file" && existingSimpleMarkdown.path === markdownContent[__intlayer_types.NodeType.File])) {
977
+ requiredImports.add("md");
978
+ if (markdownNodeType === __intlayer_types.NodeType.File) requiredImports.add("file");
979
+ const property = contentObject.getProperty(propertyKey);
980
+ if (property && ts_morph.Node.isPropertyAssignment(property)) {
981
+ property.setInitializer(markdownInitializerText);
982
+ return true;
983
+ }
984
+ }
985
+ return false;
986
+ };
987
+ /**
988
+ * Processes file content.
989
+ * Handles file objects with file path references.
990
+ *
991
+ * @param contentObject - The object containing the property
992
+ * @param propertyKey - The key of the property to process
993
+ * @param contentNode - The file content node
994
+ * @param existingPropertyKeys - Set of existing property names
995
+ * @param requiredImports - Set to track required imports
996
+ * @param sourceFile - The source file being processed
997
+ * @returns True if the content was modified
998
+ */
999
+ const processFileContent = (contentObject, propertyKey, contentNode, existingPropertyKeys, requiredImports, sourceFile) => {
1000
+ const filePath = contentNode[__intlayer_types.NodeType.File];
1001
+ const fileInitializerText = buildFileInitializer(filePath);
1002
+ if (!fileInitializerText) return false;
1003
+ if (!existingPropertyKeys.has(propertyKey)) {
1004
+ const spreadTargetObject = findSpreadTargetObjectForKey(contentObject, propertyKey, sourceFile);
1005
+ if (spreadTargetObject) return processFileContent(spreadTargetObject, propertyKey, contentNode, getExistingPropertyNames(spreadTargetObject), requiredImports, sourceFile);
1006
+ requiredImports.add("file");
1007
+ contentObject.addPropertyAssignment({
1008
+ name: propertyKey,
1009
+ initializer: fileInitializerText
1010
+ });
1011
+ return true;
1012
+ }
1013
+ if (readExistingFilePath(contentObject, propertyKey) !== filePath) {
1014
+ requiredImports.add("file");
1015
+ const property = contentObject.getProperty(propertyKey);
1016
+ if (property && ts_morph.Node.isPropertyAssignment(property)) {
1017
+ property.setInitializer(fileInitializerText);
1018
+ return true;
1019
+ }
1020
+ }
1021
+ return false;
1022
+ };
1023
+ /**
1024
+ * Processes nested content.
1025
+ * Handles nested objects with dictionary key and optional path references.
1026
+ *
1027
+ * @param contentObject - The object containing the property
1028
+ * @param propertyKey - The key of the property to process
1029
+ * @param contentNode - The nested content node
1030
+ * @param existingPropertyKeys - Set of existing property names
1031
+ * @param requiredImports - Set to track required imports
1032
+ * @param sourceFile - The source file being processed
1033
+ * @returns True if the content was modified
1034
+ */
1035
+ const processNestedContent = (contentObject, propertyKey, contentNode, existingPropertyKeys, requiredImports, sourceFile) => {
1036
+ const nestedContent = contentNode[__intlayer_types.NodeType.Nested];
1037
+ const nestedInitializerText = buildNestedInitializer(nestedContent);
1038
+ if (!nestedInitializerText) return false;
1039
+ if (!existingPropertyKeys.has(propertyKey)) {
1040
+ const spreadTargetObject = findSpreadTargetObjectForKey(contentObject, propertyKey, sourceFile);
1041
+ if (spreadTargetObject) return processNestedContent(spreadTargetObject, propertyKey, contentNode, getExistingPropertyNames(spreadTargetObject), requiredImports, sourceFile);
1042
+ requiredImports.add("nest");
1043
+ contentObject.addPropertyAssignment({
1044
+ name: propertyKey,
1045
+ initializer: nestedInitializerText
1046
+ });
1047
+ return true;
1048
+ }
1049
+ const existingNestedContent = readExistingNest(contentObject, propertyKey);
1050
+ if (!(!!nestedContent && existingNestedContent?.dictionaryKey === nestedContent.dictionaryKey && existingNestedContent?.path === nestedContent.path)) {
1051
+ requiredImports.add("nest");
1052
+ const property = contentObject.getProperty(propertyKey);
1053
+ if (property && ts_morph.Node.isPropertyAssignment(property)) {
1054
+ property.setInitializer(nestedInitializerText);
1055
+ return true;
1056
+ }
1057
+ }
1058
+ return false;
1059
+ };
1060
+ /**
1061
+ * Processes nested object content.
1062
+ * Handles nested objects within content structures.
1063
+ *
1064
+ * @param contentObject - The object containing the property
1065
+ * @param propertyKey - The key of the property to process
1066
+ * @param nestedObjectValue - The nested object value to process
1067
+ * @param _existingPropertyKeys - Set of existing property names (unused)
1068
+ * @param effectiveFallbackLocale - The fallback locale for translations
1069
+ * @param requiredImports - Set to track required imports
1070
+ * @param sourceFile - The source file being processed
1071
+ * @returns True if the content was modified
1072
+ */
1073
+ const processNestedObjectContent = (contentObject, propertyKey, nestedObjectValue, _existingPropertyKeys, effectiveFallbackLocale, requiredImports, sourceFile) => {
1074
+ let childObject;
1075
+ const existingProperty = contentObject.getProperty(propertyKey);
1076
+ if (existingProperty && ts_morph.Node.isPropertyAssignment(existingProperty)) childObject = existingProperty.getInitializerIfKind(ts_morph.SyntaxKind.ObjectLiteralExpression);
1077
+ if (!childObject) {
1078
+ const shorthandProperty = contentObject.getProperty(propertyKey);
1079
+ if (shorthandProperty && ts_morph.Node.isShorthandPropertyAssignment(shorthandProperty)) childObject = resolveNameToObjectLiteral(contentObject.getSourceFile(), propertyKey);
1080
+ else if (existingProperty && ts_morph.Node.isPropertyAssignment(existingProperty)) {
1081
+ const propertyInitializer = existingProperty.getInitializer();
1082
+ if (propertyInitializer) {
1083
+ if (ts_morph.Node.isIdentifier(propertyInitializer)) childObject = resolveNameToObjectLiteral(sourceFile, propertyInitializer.getText());
1084
+ else if (ts_morph.Node.isPropertyAccessExpression(propertyInitializer)) childObject = resolveExpressionToObjectLiteral(sourceFile, propertyInitializer);
1085
+ }
1086
+ }
1087
+ }
1088
+ if (!childObject) {
1089
+ const spreadTargetObject = findSpreadTargetObjectForKey(contentObject, propertyKey, sourceFile);
1090
+ if (spreadTargetObject) return processNestedObjectContent(spreadTargetObject, propertyKey, nestedObjectValue, getExistingPropertyNames(spreadTargetObject), effectiveFallbackLocale, requiredImports, sourceFile);
1091
+ contentObject.addPropertyAssignment({
1092
+ name: propertyKey,
1093
+ initializer: "{ }"
1094
+ });
1095
+ const newProperty = contentObject.getProperty(propertyKey);
1096
+ if (newProperty && ts_morph.Node.isPropertyAssignment(newProperty)) childObject = newProperty.getInitializerIfKind(ts_morph.SyntaxKind.ObjectLiteralExpression);
1097
+ }
1098
+ if (childObject) return processContentEntries(childObject, nestedObjectValue, effectiveFallbackLocale, requiredImports, sourceFile);
1099
+ return false;
1100
+ };
1101
+ /**
1102
+ * Processes content entries in a dictionary object.
1103
+ * Routes different content types to appropriate processors.
1104
+ *
1105
+ * @param contentObject - The object containing the content
1106
+ * @param dictionaryContent - The dictionary content to process
1107
+ * @param effectiveFallbackLocale - The fallback locale for translations
1108
+ * @param requiredImports - Set to track required imports
1109
+ * @param sourceFile - The source file being processed
1110
+ * @returns True if any content was modified
1111
+ */
1112
+ const processContentEntries = (contentObject, dictionaryContent, effectiveFallbackLocale, requiredImports, sourceFile) => {
1113
+ let contentWasChanged = false;
1114
+ const existingPropertyKeys = getExistingPropertyNames(contentObject);
1115
+ for (const [propertyKey, propertyValue] of Object.entries(dictionaryContent)) {
1116
+ if (Array.isArray(propertyValue)) {
1117
+ if (processArrayContent(contentObject, propertyKey, propertyValue, existingPropertyKeys, effectiveFallbackLocale, requiredImports, sourceFile)) contentWasChanged = true;
1118
+ continue;
1119
+ }
1120
+ if (typeof propertyValue === "string" || typeof propertyValue === "number" || typeof propertyValue === "boolean" || propertyValue === null) {
1121
+ if (processPrimitiveContent(contentObject, propertyKey, propertyValue, existingPropertyKeys, effectiveFallbackLocale, requiredImports, sourceFile)) contentWasChanged = true;
1122
+ continue;
1123
+ }
1124
+ const nodeType = (0, __intlayer_core.getNodeType)(propertyValue);
1125
+ if (nodeType !== __intlayer_types.NodeType.Text && nodeType !== __intlayer_types.NodeType.Number && nodeType !== __intlayer_types.NodeType.Boolean && nodeType !== __intlayer_types.NodeType.Null) {
1126
+ if (processComplexContent(contentObject, propertyKey, propertyValue, existingPropertyKeys, effectiveFallbackLocale, requiredImports, sourceFile)) {
1127
+ contentWasChanged = true;
1128
+ continue;
1129
+ }
1130
+ }
1131
+ if (propertyValue && typeof propertyValue === "object" && !Array.isArray(propertyValue) && !propertyValue.nodeType) {
1132
+ if (processNestedObjectContent(contentObject, propertyKey, propertyValue, existingPropertyKeys, effectiveFallbackLocale, requiredImports, sourceFile)) contentWasChanged = true;
1133
+ }
1134
+ }
1135
+ return contentWasChanged;
205
1136
  };
206
1137
  const readExistingInsertion = (contentObject, propName) => {
207
- const prop = contentObject.getProperty(propName);
208
- if (!prop || !import_ts_morph.Node.isPropertyAssignment(prop)) return void 0;
209
- const init = prop.getInitializer();
210
- if (!init || !import_ts_morph.Node.isCallExpression(init)) return void 0;
211
- const exp = init.getExpression();
212
- if (!import_ts_morph.Node.isIdentifier(exp) || exp.getText() !== "insert") return void 0;
213
- const arg = init.getArguments()[0];
214
- if (!arg) return void 0;
215
- if (import_ts_morph.Node.isStringLiteral(arg)) {
216
- return { kind: "string", value: arg.getLiteralValue() };
217
- }
218
- if (import_ts_morph.Node.isCallExpression(arg)) {
219
- const aexp = arg.getExpression();
220
- if (import_ts_morph.Node.isIdentifier(aexp) && aexp.getText() === "t") {
221
- const tArg = arg.getArguments()[0];
222
- if (tArg && import_ts_morph.Node.isObjectLiteralExpression(tArg)) {
223
- const map = {};
224
- for (const p of tArg.getProperties()) {
225
- if (!import_ts_morph.Node.isPropertyAssignment(p)) continue;
226
- const nameNode = p.getNameNode();
227
- const rawName = nameNode.getText();
228
- const name = rawName.replace(/^['"]|['"]$/g, "");
229
- const valueInit = p.getInitializer();
230
- if (valueInit && import_ts_morph.Node.isStringLiteral(valueInit)) {
231
- map[name] = valueInit.getLiteralValue();
232
- }
233
- }
234
- return { kind: "translation", map };
235
- }
236
- }
237
- }
238
- return void 0;
1138
+ const prop = contentObject.getProperty(propName);
1139
+ if (!prop || !ts_morph.Node.isPropertyAssignment(prop)) return void 0;
1140
+ const init = prop.getInitializer();
1141
+ if (!init || !ts_morph.Node.isCallExpression(init)) return void 0;
1142
+ const exp = init.getExpression();
1143
+ if (!ts_morph.Node.isIdentifier(exp) || exp.getText() !== "insert") return void 0;
1144
+ const argument = init.getArguments()[0];
1145
+ if (!argument) return void 0;
1146
+ if (ts_morph.Node.isStringLiteral(argument)) return {
1147
+ kind: "string",
1148
+ value: argument.getLiteralValue()
1149
+ };
1150
+ if (ts_morph.Node.isCallExpression(argument)) {
1151
+ const argumentExpression = argument.getExpression();
1152
+ if (ts_morph.Node.isIdentifier(argumentExpression) && argumentExpression.getText() === "t") {
1153
+ const translationArgument = argument.getArguments()[0];
1154
+ if (translationArgument && ts_morph.Node.isObjectLiteralExpression(translationArgument)) {
1155
+ const map = {};
1156
+ for (const propertyAssignment of translationArgument.getProperties()) {
1157
+ if (!ts_morph.Node.isPropertyAssignment(propertyAssignment)) continue;
1158
+ const name = propertyAssignment.getNameNode().getText().replace(/^['"]|['"]$/g, "");
1159
+ const valueInitializer = propertyAssignment.getInitializer();
1160
+ if (valueInitializer && ts_morph.Node.isStringLiteral(valueInitializer)) map[name] = valueInitializer.getLiteralValue();
1161
+ }
1162
+ return {
1163
+ kind: "translation",
1164
+ map
1165
+ };
1166
+ }
1167
+ }
1168
+ }
239
1169
  };
240
1170
  const readExistingMarkdown = (contentObject, propName) => {
241
- const prop = contentObject.getProperty(propName);
242
- if (!prop || !import_ts_morph.Node.isPropertyAssignment(prop)) return void 0;
243
- const init = prop.getInitializer();
244
- if (!init || !import_ts_morph.Node.isCallExpression(init)) return void 0;
245
- const exp = init.getExpression();
246
- if (!import_ts_morph.Node.isIdentifier(exp) || exp.getText() !== "md") return void 0;
247
- const arg = init.getArguments()[0];
248
- if (!arg) return void 0;
249
- if (import_ts_morph.Node.isStringLiteral(arg)) {
250
- return { kind: "string", value: arg.getLiteralValue() };
251
- }
252
- if (import_ts_morph.Node.isCallExpression(arg)) {
253
- const aexp = arg.getExpression();
254
- if (import_ts_morph.Node.isIdentifier(aexp) && aexp.getText() === "file") {
255
- const fArg = arg.getArguments()[0];
256
- if (fArg && import_ts_morph.Node.isStringLiteral(fArg)) {
257
- return { kind: "file", path: fArg.getLiteralValue() };
258
- }
259
- }
260
- }
261
- return void 0;
1171
+ const property = contentObject.getProperty(propName);
1172
+ if (!property || !ts_morph.Node.isPropertyAssignment(property)) return void 0;
1173
+ const initializer = property.getInitializer();
1174
+ if (!initializer) return void 0;
1175
+ if (ts_morph.Node.isCallExpression(initializer)) {
1176
+ const expression = initializer.getExpression();
1177
+ if (!ts_morph.Node.isIdentifier(expression)) return void 0;
1178
+ if (expression.getText() === "md") {
1179
+ const argument = initializer.getArguments()[0];
1180
+ if (!argument) return void 0;
1181
+ if (ts_morph.Node.isStringLiteral(argument)) return {
1182
+ kind: "string",
1183
+ value: argument.getLiteralValue()
1184
+ };
1185
+ if (ts_morph.Node.isCallExpression(argument)) {
1186
+ const argumentExpression = argument.getExpression();
1187
+ if (ts_morph.Node.isIdentifier(argumentExpression) && argumentExpression.getText() === "file") {
1188
+ const fileArgument = argument.getArguments()[0];
1189
+ if (fileArgument && ts_morph.Node.isStringLiteral(fileArgument)) return {
1190
+ kind: "file",
1191
+ path: fileArgument.getLiteralValue()
1192
+ };
1193
+ }
1194
+ }
1195
+ }
1196
+ }
262
1197
  };
263
1198
  const readExistingFilePath = (contentObject, propName) => {
264
- const prop = contentObject.getProperty(propName);
265
- if (!prop || !import_ts_morph.Node.isPropertyAssignment(prop)) return void 0;
266
- const init = prop.getInitializer();
267
- if (!init || !import_ts_morph.Node.isCallExpression(init)) return void 0;
268
- const exp = init.getExpression();
269
- if (!import_ts_morph.Node.isIdentifier(exp) || exp.getText() !== "file") return void 0;
270
- const arg = init.getArguments()[0];
271
- if (arg && import_ts_morph.Node.isStringLiteral(arg)) return arg.getLiteralValue();
272
- return void 0;
1199
+ const property = contentObject.getProperty(propName);
1200
+ if (!property || !ts_morph.Node.isPropertyAssignment(property)) return void 0;
1201
+ const initializer = property.getInitializer();
1202
+ if (!initializer || !ts_morph.Node.isCallExpression(initializer)) return void 0;
1203
+ const expression = initializer.getExpression();
1204
+ if (!ts_morph.Node.isIdentifier(expression) || expression.getText() !== "file") return void 0;
1205
+ const argument = initializer.getArguments()[0];
1206
+ if (argument && ts_morph.Node.isStringLiteral(argument)) return argument.getLiteralValue();
1207
+ };
1208
+ const readExistingMarkdownTranslationMap = (contentObject, propName) => {
1209
+ const property = contentObject.getProperty(propName);
1210
+ if (!property || !ts_morph.Node.isPropertyAssignment(property)) return void 0;
1211
+ const initializer = property.getInitializer();
1212
+ if (!initializer) return void 0;
1213
+ if (ts_morph.Node.isCallExpression(initializer)) {
1214
+ const exp = initializer.getExpression();
1215
+ if (ts_morph.Node.isIdentifier(exp) && exp.getText() === "md") {
1216
+ const arg = initializer.getArguments()[0];
1217
+ if (arg && ts_morph.Node.isCallExpression(arg)) {
1218
+ const tExp = arg.getExpression();
1219
+ if (ts_morph.Node.isIdentifier(tExp) && tExp.getText() === "t") {
1220
+ const tArg = arg.getArguments()[0];
1221
+ if (tArg && ts_morph.Node.isObjectLiteralExpression(tArg)) {
1222
+ const map = {};
1223
+ for (const prop of tArg.getProperties()) {
1224
+ if (!ts_morph.Node.isPropertyAssignment(prop)) continue;
1225
+ const name = prop.getNameNode().getText().replace(/^['"]|['"]$/g, "");
1226
+ const valueInit = prop.getInitializer();
1227
+ if (valueInit && ts_morph.Node.isStringLiteral(valueInit)) map[name] = valueInit.getLiteralValue();
1228
+ else return;
1229
+ }
1230
+ return map;
1231
+ }
1232
+ }
1233
+ }
1234
+ }
1235
+ }
1236
+ if (ts_morph.Node.isCallExpression(initializer)) {
1237
+ const exp = initializer.getExpression();
1238
+ if (ts_morph.Node.isIdentifier(exp) && exp.getText() === "t") {
1239
+ const tArg = initializer.getArguments()[0];
1240
+ if (tArg && ts_morph.Node.isObjectLiteralExpression(tArg)) {
1241
+ const map = {};
1242
+ for (const prop of tArg.getProperties()) {
1243
+ if (!ts_morph.Node.isPropertyAssignment(prop)) continue;
1244
+ const name = prop.getNameNode().getText().replace(/^['"]|['"]$/g, "");
1245
+ const valueInit = prop.getInitializer();
1246
+ if (valueInit && ts_morph.Node.isCallExpression(valueInit) && ts_morph.Node.isIdentifier(valueInit.getExpression()) && valueInit.getExpression().getText() === "md") {
1247
+ const mdArg = valueInit.getArguments()[0];
1248
+ if (mdArg && ts_morph.Node.isStringLiteral(mdArg)) map[name] = mdArg.getLiteralValue();
1249
+ else return;
1250
+ } else return;
1251
+ }
1252
+ return map;
1253
+ }
1254
+ }
1255
+ }
273
1256
  };
274
1257
  const readExistingNest = (contentObject, propName) => {
275
- const prop = contentObject.getProperty(propName);
276
- if (!prop || !import_ts_morph.Node.isPropertyAssignment(prop)) return void 0;
277
- let init = prop.getInitializer();
278
- if (!init) return void 0;
279
- let safetyCounter = 0;
280
- while (safetyCounter++ < 5) {
281
- if (import_ts_morph.Node.isCallExpression(init)) break;
282
- const anyInit = init;
283
- const nextExpr = anyInit.getExpression?.();
284
- if (nextExpr && typeof nextExpr === "object" && nextExpr !== init) {
285
- init = nextExpr;
286
- continue;
287
- }
288
- break;
289
- }
290
- if (!import_ts_morph.Node.isCallExpression(init)) return void 0;
291
- const exp = init.getExpression();
292
- if (!import_ts_morph.Node.isIdentifier(exp) || exp.getText() !== "nest") return void 0;
293
- const [arg1, arg2] = init.getArguments();
294
- if (!arg1 || !import_ts_morph.Node.isStringLiteral(arg1)) return void 0;
295
- const dictionaryKey = arg1.getLiteralValue();
296
- let path;
297
- if (arg2 && import_ts_morph.Node.isStringLiteral(arg2)) path = arg2.getLiteralValue();
298
- return { dictionaryKey, path };
1258
+ const property = contentObject.getProperty(propName);
1259
+ if (!property || !ts_morph.Node.isPropertyAssignment(property)) return void 0;
1260
+ let initializer = property.getInitializer();
1261
+ if (!initializer) return void 0;
1262
+ let safetyCounter = 0;
1263
+ while (safetyCounter++ < 5) {
1264
+ if (ts_morph.Node.isCallExpression(initializer)) break;
1265
+ const nextExpression = initializer.getExpression?.();
1266
+ if (nextExpression && typeof nextExpression === "object" && nextExpression !== initializer) {
1267
+ initializer = nextExpression;
1268
+ continue;
1269
+ }
1270
+ break;
1271
+ }
1272
+ if (!ts_morph.Node.isCallExpression(initializer)) return void 0;
1273
+ const expression = initializer.getExpression();
1274
+ if (!ts_morph.Node.isIdentifier(expression) || expression.getText() !== "nest") return void 0;
1275
+ const [firstArgument, secondArgument] = initializer.getArguments();
1276
+ if (!firstArgument || !ts_morph.Node.isStringLiteral(firstArgument)) return void 0;
1277
+ const dictionaryKey = firstArgument.getLiteralValue();
1278
+ let path;
1279
+ if (secondArgument && ts_morph.Node.isStringLiteral(secondArgument)) path = secondArgument.getLiteralValue();
1280
+ return {
1281
+ dictionaryKey,
1282
+ path
1283
+ };
299
1284
  };
300
1285
  const unwrapToObjectLiteral = (node) => {
301
- if (!node || typeof node !== "object") return void 0;
302
- let current = node;
303
- let safetyCounter = 0;
304
- while (safetyCounter++ < 8) {
305
- if (import_ts_morph.Node.isObjectLiteralExpression(current)) return current;
306
- const next = current?.getExpression?.();
307
- if (next && typeof next === "object" && next !== current) {
308
- current = next;
309
- continue;
310
- }
311
- break;
312
- }
313
- return void 0;
1286
+ if (!node || typeof node !== "object") return void 0;
1287
+ let current = node;
1288
+ let safetyCounter = 0;
1289
+ while (safetyCounter++ < 8) {
1290
+ if (ts_morph.Node.isObjectLiteralExpression(current)) return current;
1291
+ const next = current?.getExpression?.();
1292
+ if (next && typeof next === "object" && next !== current) {
1293
+ current = next;
1294
+ continue;
1295
+ }
1296
+ break;
1297
+ }
1298
+ };
1299
+ const resolveNameToObjectLiteral = (sourceFile, name) => {
1300
+ const varDecl = sourceFile.getVariableDeclaration(name);
1301
+ if (varDecl) {
1302
+ const obj = unwrapToObjectLiteral(varDecl.getInitializer());
1303
+ if (obj) return obj;
1304
+ }
1305
+ const decl = sourceFile.getDescendants().find((n) => {
1306
+ return ts_morph.Node.isIdentifier(n) && n.getText() === name;
1307
+ })?.getSymbol()?.getDeclarations()?.[0];
1308
+ if (decl && ts_morph.Node.isVariableDeclaration(decl)) {
1309
+ const obj = unwrapToObjectLiteral(decl.getInitializer());
1310
+ if (obj) return obj;
1311
+ }
1312
+ };
1313
+ const resolveExpressionToObjectLiteral = (sourceFile, expr) => {
1314
+ if (ts_morph.Node.isIdentifier(expr)) return resolveNameToObjectLiteral(sourceFile, expr.getText());
1315
+ if (ts_morph.Node.isPropertyAccessExpression(expr)) {
1316
+ const leftResolved = resolveExpressionToObjectLiteral(sourceFile, expr.getExpression());
1317
+ if (!leftResolved) return void 0;
1318
+ const propName = expr.getName();
1319
+ const prop = leftResolved.getProperty(propName);
1320
+ if (prop && ts_morph.Node.isPropertyAssignment(prop)) {
1321
+ const init = prop.getInitializer();
1322
+ const obj = unwrapToObjectLiteral(init);
1323
+ if (obj) return obj;
1324
+ if (init && ts_morph.Node.isIdentifier(init)) return resolveNameToObjectLiteral(sourceFile, init.getText());
1325
+ }
1326
+ }
1327
+ };
1328
+ const getSpreadSourceObjects = (contentObject, sourceFile) => {
1329
+ const spreads = [];
1330
+ for (const prop of contentObject.getProperties()) if (ts_morph.Node.isSpreadAssignment(prop)) {
1331
+ const resolved = resolveExpressionToObjectLiteral(sourceFile, prop.getExpression());
1332
+ if (resolved) spreads.push(resolved);
1333
+ }
1334
+ return spreads;
1335
+ };
1336
+ const findSpreadTargetObjectForKey = (contentObject, key, sourceFile) => {
1337
+ const spreads = getSpreadSourceObjects(contentObject, sourceFile);
1338
+ for (let i = spreads.length - 1; i >= 0; i--) {
1339
+ const spreadObj = spreads[i];
1340
+ const prop = spreadObj.getProperty(key);
1341
+ if (prop && ts_morph.Node.isPropertyAssignment(prop)) return spreadObj;
1342
+ }
314
1343
  };
315
1344
  const readExistingArraySerialized = (contentObject, propName) => {
316
- const prop = contentObject.getProperty(propName);
317
- if (!prop || !import_ts_morph.Node.isPropertyAssignment(prop)) return void 0;
318
- const init = prop.getInitializer();
319
- if (!init || !import_ts_morph.Node.isArrayLiteralExpression(init)) return void 0;
320
- const serialized = [];
321
- for (const el of init.getElements()) {
322
- if (import_ts_morph.Node.isStringLiteral(el)) {
323
- serialized.push(JSON.stringify(el.getLiteralValue()));
324
- continue;
325
- }
326
- if (import_ts_morph.Node.isNumericLiteral(el)) {
327
- serialized.push(el.getText());
328
- continue;
329
- }
330
- if (el.getKind() === import_ts_morph.SyntaxKind.TrueKeyword || el.getKind() === import_ts_morph.SyntaxKind.FalseKeyword) {
331
- serialized.push(el.getText());
332
- continue;
333
- }
334
- if (import_ts_morph.Node.isNullLiteral(el)) {
335
- serialized.push("null");
336
- continue;
337
- }
338
- if (import_ts_morph.Node.isCallExpression(el)) {
339
- const exp = el.getExpression();
340
- if (import_ts_morph.Node.isIdentifier(exp) && exp.getText() === "t") {
341
- const arg = el.getArguments()[0];
342
- if (arg && import_ts_morph.Node.isObjectLiteralExpression(arg)) {
343
- const map = {};
344
- for (const p of arg.getProperties()) {
345
- if (!import_ts_morph.Node.isPropertyAssignment(p)) return void 0;
346
- const nameNode = p.getNameNode();
347
- const rawName = nameNode.getText();
348
- const name = rawName.replace(/^['"]|['"]$/g, "");
349
- const valueInit = p.getInitializer();
350
- if (valueInit && import_ts_morph.Node.isStringLiteral(valueInit)) {
351
- map[name] = valueInit.getLiteralValue();
352
- } else {
353
- return void 0;
354
- }
355
- }
356
- serialized.push(buildTranslationInitializer(map));
357
- continue;
358
- }
359
- }
360
- }
361
- return void 0;
362
- }
363
- return serialized;
1345
+ const property = contentObject.getProperty(propName);
1346
+ if (!property || !ts_morph.Node.isPropertyAssignment(property)) return void 0;
1347
+ const initializer = property.getInitializer();
1348
+ if (!initializer || !ts_morph.Node.isArrayLiteralExpression(initializer)) return void 0;
1349
+ const serialized = [];
1350
+ for (const element of initializer.getElements()) {
1351
+ if (ts_morph.Node.isStringLiteral(element)) {
1352
+ serialized.push(JSON.stringify(element.getLiteralValue()));
1353
+ continue;
1354
+ }
1355
+ if (ts_morph.Node.isNumericLiteral(element)) {
1356
+ serialized.push(element.getText());
1357
+ continue;
1358
+ }
1359
+ if (element.getKind() === ts_morph.SyntaxKind.TrueKeyword || element.getKind() === ts_morph.SyntaxKind.FalseKeyword) {
1360
+ serialized.push(element.getText());
1361
+ continue;
1362
+ }
1363
+ if (ts_morph.Node.isNullLiteral(element)) {
1364
+ serialized.push("null");
1365
+ continue;
1366
+ }
1367
+ if (ts_morph.Node.isCallExpression(element)) {
1368
+ const expression = element.getExpression();
1369
+ if (ts_morph.Node.isIdentifier(expression) && expression.getText() === "t") {
1370
+ const argument = element.getArguments()[0];
1371
+ if (argument && ts_morph.Node.isObjectLiteralExpression(argument)) {
1372
+ const map = {};
1373
+ for (const propertyAssignment of argument.getProperties()) {
1374
+ if (!ts_morph.Node.isPropertyAssignment(propertyAssignment)) return void 0;
1375
+ const name = propertyAssignment.getNameNode().getText().replace(/^['"]|['"]$/g, "");
1376
+ const valueInitializer = propertyAssignment.getInitializer();
1377
+ if (valueInitializer && ts_morph.Node.isStringLiteral(valueInitializer)) map[name] = valueInitializer.getLiteralValue();
1378
+ else return;
1379
+ }
1380
+ serialized.push(buildTranslationInitializer(map));
1381
+ continue;
1382
+ }
1383
+ }
1384
+ }
1385
+ return;
1386
+ }
1387
+ return serialized;
364
1388
  };
365
1389
  const serializeValue = (value) => {
366
- if (typeof value === "string") return JSON.stringify(value);
367
- if (typeof value === "number" || typeof value === "boolean")
368
- return String(value);
369
- if (value === null) return "null";
370
- if (isTranslationNode(value)) {
371
- const translations = value.translation ?? value["translation"] ?? {};
372
- const allStrings = Object.values(translations).every(
373
- (v) => typeof v === "string"
374
- );
375
- if (!allStrings) return void 0;
376
- return buildTranslationInitializer(translations);
377
- }
378
- if (isEnumerationNode(value)) {
379
- const map = value[import_core.NodeType.Enumeration];
380
- const init = buildEnumerationInitializer(map);
381
- return init || void 0;
382
- }
383
- if (isConditionNode(value)) {
384
- const map = value[import_core.NodeType.Condition];
385
- const init = buildConditionInitializer(map);
386
- return init || void 0;
387
- }
388
- if (isGenderNode(value)) {
389
- const map = value[import_core.NodeType.Gender];
390
- const init = buildGenderInitializer(map);
391
- return init || void 0;
392
- }
393
- if (isInsertionNode(value)) {
394
- const content = value[import_core.NodeType.Insertion];
395
- return buildInsertionInitializer(content);
396
- }
397
- if (isMarkdownNode(value)) {
398
- const content = value[import_core.NodeType.Markdown];
399
- return buildMarkdownInitializer(content);
400
- }
401
- if (isFileNode(value)) {
402
- const path = value[import_core.NodeType.File];
403
- return buildFileInitializer(path);
404
- }
405
- if (isNestedNode(value)) {
406
- return buildNestedInitializer(value);
407
- }
408
- return void 0;
409
- };
410
- const transformJSFile = async (fileContent, dictionary) => {
411
- try {
412
- if (!dictionary || typeof dictionary !== "object" || !dictionary.content) {
413
- return fileContent;
414
- }
415
- const project = new import_ts_morph.Project({
416
- useInMemoryFileSystem: true,
417
- skipAddingFilesFromTsConfig: true,
418
- skipFileDependencyResolution: true,
419
- compilerOptions: {
420
- allowJs: true,
421
- jsx: import_ts_morph.ts.JsxEmit.Preserve
422
- }
423
- });
424
- const sourceFile = project.createSourceFile("file.tsx", fileContent, {
425
- overwrite: true
426
- });
427
- let rootObject;
428
- const exportAssignment = sourceFile.getExportAssignment((_) => true);
429
- if (exportAssignment) {
430
- const expr = exportAssignment.getExpression();
431
- if (import_ts_morph.Node.isIdentifier(expr)) {
432
- const declFromSymbol = expr.getSymbol()?.getDeclarations()?.[0];
433
- const declByName = declFromSymbol ?? sourceFile.getVariableDeclaration(expr.getText());
434
- if (declByName && import_ts_morph.Node.isVariableDeclaration(declByName)) {
435
- const initAny = declByName.getInitializer();
436
- const obj = unwrapToObjectLiteral(initAny);
437
- if (obj) rootObject = obj;
438
- }
439
- } else if (import_ts_morph.Node.isObjectLiteralExpression(expr)) {
440
- rootObject = expr;
441
- }
442
- }
443
- if (!rootObject) {
444
- const varDecl = sourceFile.getVariableDeclaration((v) => {
445
- try {
446
- const typeText = v.getType().getText();
447
- return typeText.includes("Dictionary") || v.getName() === "content" || v.getName().toLowerCase().includes("dictionary");
448
- } catch {
449
- return v.getName() === "content";
450
- }
451
- });
452
- if (varDecl) {
453
- const obj = unwrapToObjectLiteral(varDecl.getInitializer());
454
- if (obj) rootObject = obj;
455
- }
456
- }
457
- if (!rootObject) {
458
- for (const stmt of sourceFile.getStatements()) {
459
- if (!import_ts_morph.Node.isExpressionStatement(stmt)) continue;
460
- const expr = stmt.getExpression();
461
- if (!import_ts_morph.Node.isBinaryExpression(expr)) continue;
462
- const operator = expr.getOperatorToken();
463
- if (operator.getText() !== "=") continue;
464
- const left = expr.getLeft();
465
- if (!import_ts_morph.Node.isPropertyAccessExpression(left)) continue;
466
- const leftExpr = left.getExpression();
467
- const leftName = left.getName();
468
- const isModuleExports = import_ts_morph.Node.isIdentifier(leftExpr) && leftExpr.getText() === "module" && leftName === "exports";
469
- const isExportsDefault = import_ts_morph.Node.isIdentifier(leftExpr) && leftExpr.getText() === "exports" && leftName === "default";
470
- if (!isModuleExports && !isExportsDefault) continue;
471
- const right = expr.getRight();
472
- if (import_ts_morph.Node.isObjectLiteralExpression(right)) {
473
- rootObject = right;
474
- break;
475
- }
476
- if (import_ts_morph.Node.isIdentifier(right)) {
477
- const decl = right.getSymbol()?.getDeclarations()?.[0];
478
- if (decl && import_ts_morph.Node.isVariableDeclaration(decl)) {
479
- const obj = unwrapToObjectLiteral(decl.getInitializer());
480
- if (obj) {
481
- rootObject = obj;
482
- break;
483
- }
484
- }
485
- }
486
- }
487
- }
488
- if (!rootObject) {
489
- return fileContent;
490
- }
491
- const contentProp = rootObject.getProperty("content");
492
- let contentObject;
493
- if (contentProp && import_ts_morph.Node.isPropertyAssignment(contentProp)) {
494
- contentObject = contentProp.getInitializerIfKind(
495
- import_ts_morph.SyntaxKind.ObjectLiteralExpression
496
- );
497
- }
498
- if (!contentObject || !dictionary.content) {
499
- return fileContent;
500
- }
501
- const existingKeys = /* @__PURE__ */ new Set();
502
- for (const prop of contentObject.getProperties()) {
503
- if (import_ts_morph.Node.isPropertyAssignment(prop)) {
504
- const name = prop.getName();
505
- if (name) existingKeys.add(name.replace(/^['"]|['"]$/g, ""));
506
- }
507
- }
508
- let changed = false;
509
- const dictContent = dictionary.content || {};
510
- const areTranslationsEqual = (desired, existing) => {
511
- if (!existing) return false;
512
- for (const [lang, val] of Object.entries(desired)) {
513
- if (typeof val !== "string") return false;
514
- if (!(lang in existing)) return false;
515
- if (existing[lang] !== val) return false;
516
- }
517
- return true;
518
- };
519
- for (const [key, value] of Object.entries(dictContent)) {
520
- if (Array.isArray(value)) {
521
- const serializedElements = [];
522
- let unsupported = false;
523
- for (const el of value) {
524
- const s = serializeValue(el);
525
- if (s === void 0) {
526
- unsupported = true;
527
- break;
528
- }
529
- serializedElements.push(s);
530
- }
531
- if (unsupported) {
532
- continue;
533
- }
534
- const initializerText = `[ ${serializedElements.join(", ")} ]`;
535
- if (!existingKeys.has(key)) {
536
- contentObject.addPropertyAssignment({
537
- name: key,
538
- initializer: initializerText
539
- });
540
- changed = true;
541
- continue;
542
- }
543
- const prop = contentObject.getProperty(key);
544
- if (prop && import_ts_morph.Node.isPropertyAssignment(prop)) {
545
- const existingSerialized = readExistingArraySerialized(
546
- contentObject,
547
- key
548
- );
549
- const arraysEqual = existingSerialized !== void 0 && existingSerialized.length === serializedElements.length && existingSerialized.every((v, i) => v === serializedElements[i]);
550
- if (!arraysEqual) {
551
- prop.setInitializer(initializerText);
552
- changed = true;
553
- }
554
- }
555
- continue;
556
- }
557
- if (typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value === null) {
558
- if (!existingKeys.has(key)) {
559
- contentObject.addPropertyAssignment({
560
- name: key,
561
- initializer: typeof value === "string" ? JSON.stringify(value) : String(value)
562
- });
563
- changed = true;
564
- continue;
565
- }
566
- const prop = contentObject.getProperty(key);
567
- if (prop && import_ts_morph.Node.isPropertyAssignment(prop)) {
568
- const init = prop.getInitializer();
569
- const currentText = init?.getText();
570
- const desiredText = typeof value === "string" ? JSON.stringify(value) : String(value);
571
- if (currentText !== desiredText) {
572
- prop.setInitializer(desiredText);
573
- changed = true;
574
- }
575
- }
576
- continue;
577
- }
578
- if (isTranslationNode(value)) {
579
- const translations = value.translation ?? value["translation"] ?? {};
580
- const allStrings = Object.values(translations).every(
581
- (v) => typeof v === "string"
582
- );
583
- if (!allStrings) {
584
- continue;
585
- }
586
- const initializerText = buildTranslationInitializer(
587
- translations
588
- );
589
- if (!existingKeys.has(key)) {
590
- contentObject.addPropertyAssignment({
591
- name: key,
592
- initializer: initializerText
593
- });
594
- changed = true;
595
- continue;
596
- }
597
- const existingMap = readExistingTranslationMap(contentObject, key);
598
- if (!areTranslationsEqual(translations, existingMap)) {
599
- const prop = contentObject.getProperty(key);
600
- if (prop && import_ts_morph.Node.isPropertyAssignment(prop)) {
601
- prop.setInitializer(initializerText);
602
- changed = true;
603
- }
604
- }
605
- } else if (isEnumerationNode(value)) {
606
- const map = value[import_core.NodeType.Enumeration];
607
- if (!Object.values(map).every((v) => typeof v === "string")) continue;
608
- const initializerText = buildEnumerationInitializer(map);
609
- if (!initializerText) continue;
610
- if (!existingKeys.has(key)) {
611
- contentObject.addPropertyAssignment({
612
- name: key,
613
- initializer: initializerText
614
- });
615
- changed = true;
616
- continue;
617
- }
618
- const existingMap = readExistingMapFromCall(contentObject, key, "enu");
619
- if (!areStringMapsEqual(map, existingMap)) {
620
- const prop = contentObject.getProperty(key);
621
- if (prop && import_ts_morph.Node.isPropertyAssignment(prop)) {
622
- prop.setInitializer(initializerText);
623
- changed = true;
624
- }
625
- }
626
- } else if (isConditionNode(value)) {
627
- const map = value[import_core.NodeType.Condition];
628
- if (!Object.values(map).every((v) => typeof v === "string")) continue;
629
- const initializerText = buildConditionInitializer(map);
630
- if (!initializerText) continue;
631
- if (!existingKeys.has(key)) {
632
- contentObject.addPropertyAssignment({
633
- name: key,
634
- initializer: initializerText
635
- });
636
- changed = true;
637
- continue;
638
- }
639
- const existingMap = readExistingMapFromCall(contentObject, key, "cond");
640
- if (!areStringMapsEqual(map, existingMap)) {
641
- const prop = contentObject.getProperty(key);
642
- if (prop && import_ts_morph.Node.isPropertyAssignment(prop)) {
643
- prop.setInitializer(initializerText);
644
- changed = true;
645
- }
646
- }
647
- } else if (isGenderNode(value)) {
648
- const map = value[import_core.NodeType.Gender];
649
- if (!Object.values(map).every((v) => typeof v === "string")) continue;
650
- const initializerText = buildGenderInitializer(map);
651
- if (!initializerText) continue;
652
- if (!existingKeys.has(key)) {
653
- contentObject.addPropertyAssignment({
654
- name: key,
655
- initializer: initializerText
656
- });
657
- changed = true;
658
- continue;
659
- }
660
- const existingMap = readExistingMapFromCall(
661
- contentObject,
662
- key,
663
- "gender"
664
- );
665
- if (!areStringMapsEqual(map, existingMap)) {
666
- const prop = contentObject.getProperty(key);
667
- if (prop && import_ts_morph.Node.isPropertyAssignment(prop)) {
668
- prop.setInitializer(initializerText);
669
- changed = true;
670
- }
671
- }
672
- } else if (isInsertionNode(value)) {
673
- const desired = value[import_core.NodeType.Insertion];
674
- const initializerText = buildInsertionInitializer(desired);
675
- if (!initializerText) continue;
676
- if (!existingKeys.has(key)) {
677
- contentObject.addPropertyAssignment({
678
- name: key,
679
- initializer: initializerText
680
- });
681
- changed = true;
682
- continue;
683
- }
684
- const existing = readExistingInsertion(contentObject, key);
685
- const isSame = typeof desired === "string" && existing?.kind === "string" && existing.value === desired || isTranslationNode(desired) && existing?.kind === "translation" && areStringMapsEqual(
686
- desired[import_core.NodeType.Translation] ?? {},
687
- existing.map
688
- );
689
- if (!isSame) {
690
- const prop = contentObject.getProperty(key);
691
- if (prop && import_ts_morph.Node.isPropertyAssignment(prop)) {
692
- prop.setInitializer(initializerText);
693
- changed = true;
694
- }
695
- }
696
- } else if (isMarkdownNode(value)) {
697
- const desired = value[import_core.NodeType.Markdown];
698
- const initializerText = buildMarkdownInitializer(desired);
699
- if (!initializerText) continue;
700
- if (!existingKeys.has(key)) {
701
- contentObject.addPropertyAssignment({
702
- name: key,
703
- initializer: initializerText
704
- });
705
- changed = true;
706
- continue;
707
- }
708
- const existing = readExistingMarkdown(contentObject, key);
709
- const isSame = typeof desired === "string" && existing?.kind === "string" && existing.value === desired || isFileNode(desired) && existing?.kind === "file" && existing.path === desired[import_core.NodeType.File];
710
- if (!isSame) {
711
- const prop = contentObject.getProperty(key);
712
- if (prop && import_ts_morph.Node.isPropertyAssignment(prop)) {
713
- prop.setInitializer(initializerText);
714
- changed = true;
715
- }
716
- }
717
- } else if (isFileNode(value)) {
718
- const desired = value[import_core.NodeType.File];
719
- const initializerText = buildFileInitializer(desired);
720
- if (!initializerText) continue;
721
- if (!existingKeys.has(key)) {
722
- contentObject.addPropertyAssignment({
723
- name: key,
724
- initializer: initializerText
725
- });
726
- changed = true;
727
- continue;
728
- }
729
- const existing = readExistingFilePath(contentObject, key);
730
- if (existing !== desired) {
731
- const prop = contentObject.getProperty(key);
732
- if (prop && import_ts_morph.Node.isPropertyAssignment(prop)) {
733
- prop.setInitializer(initializerText);
734
- changed = true;
735
- }
736
- }
737
- } else if (isNestedNode(value)) {
738
- const initializerText = buildNestedInitializer(value);
739
- if (!initializerText) continue;
740
- if (!existingKeys.has(key)) {
741
- contentObject.addPropertyAssignment({
742
- name: key,
743
- initializer: initializerText
744
- });
745
- changed = true;
746
- continue;
747
- }
748
- const existing = readExistingNest(contentObject, key);
749
- const desired = value[import_core.NodeType.Nested];
750
- const isSame = !!desired && existing?.dictionaryKey === desired.dictionaryKey && existing?.path === desired.path;
751
- if (!isSame) {
752
- const prop = contentObject.getProperty(key);
753
- if (prop && import_ts_morph.Node.isPropertyAssignment(prop)) {
754
- prop.setInitializer(initializerText);
755
- changed = true;
756
- }
757
- }
758
- }
759
- }
760
- if (!changed) return fileContent;
761
- return sourceFile.getFullText();
762
- } catch {
763
- return fileContent;
764
- }
765
- };
766
- // Annotate the CommonJS export names for ESM import in node:
767
- 0 && (module.exports = {
768
- transformJSFile
769
- });
1390
+ const nodeType = (0, __intlayer_core.getNodeType)(value);
1391
+ if (nodeType === __intlayer_types.NodeType.Text) return JSON.stringify(value);
1392
+ if (nodeType === __intlayer_types.NodeType.Number || nodeType === __intlayer_types.NodeType.Boolean) return String(value);
1393
+ if (nodeType === __intlayer_types.NodeType.Null) return "null";
1394
+ if (nodeType === __intlayer_types.NodeType.Translation) {
1395
+ const translations = value[__intlayer_types.NodeType.Translation] ?? {};
1396
+ if (!Object.values(translations).every((v) => typeof v === "string")) return void 0;
1397
+ return buildTranslationInitializer(translations);
1398
+ }
1399
+ if (nodeType === __intlayer_types.NodeType.Enumeration) {
1400
+ const map = value[__intlayer_types.NodeType.Enumeration];
1401
+ return buildEnumerationInitializer(map);
1402
+ }
1403
+ if (nodeType === __intlayer_types.NodeType.Condition) {
1404
+ const map = value[__intlayer_types.NodeType.Condition];
1405
+ return buildConditionInitializer(map);
1406
+ }
1407
+ if (nodeType === __intlayer_types.NodeType.Gender) {
1408
+ const map = value[__intlayer_types.NodeType.Gender];
1409
+ return buildGenderInitializer(map);
1410
+ }
1411
+ if (nodeType === __intlayer_types.NodeType.Insertion) {
1412
+ const content = value[__intlayer_types.NodeType.Insertion];
1413
+ return buildInsertionInitializer(content);
1414
+ }
1415
+ if (nodeType === __intlayer_types.NodeType.Markdown) {
1416
+ const content = value[__intlayer_types.NodeType.Markdown];
1417
+ return buildMarkdownInitializer(content);
1418
+ }
1419
+ if (nodeType === __intlayer_types.NodeType.File) {
1420
+ const path = value[__intlayer_types.NodeType.File];
1421
+ return buildFileInitializer(path);
1422
+ }
1423
+ if (nodeType === __intlayer_types.NodeType.Nested) {
1424
+ const content = value[__intlayer_types.NodeType.Nested];
1425
+ return buildNestedInitializer(content);
1426
+ }
1427
+ };
1428
+ /**
1429
+ * Gets the existing imports from @intlayer/core in the source file
1430
+ */
1431
+ const getExistingIntlayerImports = (sourceFile) => {
1432
+ const imported = /* @__PURE__ */ new Set();
1433
+ for (const importDecl of sourceFile.getImportDeclarations()) {
1434
+ const moduleSpecifier = importDecl.getModuleSpecifierValue();
1435
+ if (moduleSpecifier === "intlayer") {
1436
+ const namedImports = importDecl.getNamedImports();
1437
+ for (const namedImport of namedImports) imported.add(namedImport.getName());
1438
+ }
1439
+ if (moduleSpecifier === "intlayer/file") {
1440
+ const namedImports = importDecl.getNamedImports();
1441
+ for (const namedImport of namedImports) {
1442
+ const alias = namedImport.getAliasNode();
1443
+ imported.add(alias ? alias.getText() : namedImport.getName());
1444
+ }
1445
+ }
1446
+ }
1447
+ return imported;
1448
+ };
1449
+ /**
1450
+ * Adds missing imports to the source file
1451
+ */
1452
+ const addMissingImports = (sourceFile, requiredImports) => {
1453
+ if (requiredImports.size === 0) return false;
1454
+ const existingImports = getExistingIntlayerImports(sourceFile);
1455
+ const missingImports = [...requiredImports].filter((imp) => !existingImports.has(imp));
1456
+ if (missingImports.length === 0) return false;
1457
+ const hasMissingFile = missingImports.includes("file");
1458
+ const otherMissingImports = missingImports.filter((imp) => imp !== "file");
1459
+ if (otherMissingImports.length > 0) {
1460
+ const coreImport = sourceFile.getImportDeclarations().find((imp) => imp.getModuleSpecifierValue() === "intlayer");
1461
+ if (coreImport) {
1462
+ const existingNamedImports = coreImport.getNamedImports().map((ni) => ni.getName());
1463
+ const allImports = [...new Set([...existingNamedImports, ...otherMissingImports])].sort();
1464
+ coreImport.removeNamedImports();
1465
+ coreImport.addNamedImports(allImports.map((name) => ({ name })));
1466
+ } else sourceFile.insertImportDeclaration(0, {
1467
+ moduleSpecifier: "intlayer",
1468
+ namedImports: otherMissingImports.sort().map((name) => ({ name }))
1469
+ });
1470
+ }
1471
+ if (hasMissingFile) {
1472
+ if (!sourceFile.getImportDeclarations().find((imp) => imp.getModuleSpecifierValue() === "intlayer/file")) {
1473
+ const coreImportIndex = sourceFile.getImportDeclarations().findIndex((imp) => imp.getModuleSpecifierValue() === "intlayer");
1474
+ const insertIndex = coreImportIndex >= 0 ? coreImportIndex + 1 : 0;
1475
+ sourceFile.insertImportDeclaration(insertIndex, {
1476
+ moduleSpecifier: "intlayer/file",
1477
+ namedImports: [{ name: "file" }]
1478
+ });
1479
+ }
1480
+ }
1481
+ return true;
1482
+ };
1483
+ /**
1484
+ * Detect whether the current source file is written in CommonJS style.
1485
+ * Prefers ESM when import/export syntax is present; otherwise detects CJS via require/module.exports.
1486
+ */
1487
+ const isCommonJS = (sourceFile) => {
1488
+ if (sourceFile.getImportDeclarations().length > 0) return false;
1489
+ if (sourceFile.getExportDeclarations().length > 0) return false;
1490
+ if (sourceFile.getExportAssignments().length > 0) return false;
1491
+ for (const statement of sourceFile.getStatements()) {
1492
+ if (!ts_morph.Node.isExpressionStatement(statement)) continue;
1493
+ const expression = statement.getExpression();
1494
+ if (!ts_morph.Node.isBinaryExpression(expression)) continue;
1495
+ const leftSide = expression.getLeft();
1496
+ if (!ts_morph.Node.isPropertyAccessExpression(leftSide)) continue;
1497
+ const leftExpression = leftSide.getExpression();
1498
+ const leftName = leftSide.getName();
1499
+ const isModuleExports = ts_morph.Node.isIdentifier(leftExpression) && leftExpression.getText() === "module" && leftName === "exports";
1500
+ const isExportsDefault = ts_morph.Node.isIdentifier(leftExpression) && leftExpression.getText() === "exports";
1501
+ if (isModuleExports || isExportsDefault) return true;
1502
+ }
1503
+ return sourceFile.getDescendantsOfKind(ts_morph.SyntaxKind.CallExpression).some((call) => {
1504
+ const exp = call.getExpression();
1505
+ return ts_morph.Node.isIdentifier(exp) && exp.getText() === "require";
1506
+ });
1507
+ };
1508
+ /**
1509
+ * Adds missing CommonJS requires for intlayer helpers.
1510
+ * - Core helpers (t, md, insert, enu, cond, gender, nest) come from require('intlayer') via destructuring
1511
+ * - file helper comes from require('intlayer/file') via destructuring
1512
+ * Existing destructured requires are respected to avoid duplicates.
1513
+ */
1514
+ const addMissingRequires = (sourceFile, requiredImports) => {
1515
+ if (requiredImports.size === 0) return false;
1516
+ const existingCoreNames = /* @__PURE__ */ new Set();
1517
+ let hasFileHelper = false;
1518
+ for (const varDecl of sourceFile.getVariableDeclarations()) {
1519
+ const init = varDecl.getInitializer();
1520
+ if (!init || !ts_morph.Node.isCallExpression(init)) continue;
1521
+ const callee = init.getExpression();
1522
+ if (!ts_morph.Node.isIdentifier(callee) || callee.getText() !== "require") continue;
1523
+ const arg = init.getArguments()[0];
1524
+ if (!arg || !ts_morph.Node.isStringLiteral(arg)) continue;
1525
+ const spec = arg.getLiteralValue();
1526
+ const nameNode = varDecl.getNameNode();
1527
+ if (spec === "intlayer") {
1528
+ if (ts_morph.Node.isObjectBindingPattern(nameNode)) for (const el of nameNode.getElements()) existingCoreNames.add(el.getNameNode().getText());
1529
+ }
1530
+ if (spec === "intlayer/file") {
1531
+ if (ts_morph.Node.isObjectBindingPattern(nameNode)) {
1532
+ for (const el of nameNode.getElements()) if (el.getNameNode().getText() === "file") hasFileHelper = true;
1533
+ } else if (ts_morph.Node.isIdentifier(nameNode) && nameNode.getText() === "file") hasFileHelper = true;
1534
+ }
1535
+ }
1536
+ const missingCore = Array.from(requiredImports).filter((n) => n !== "file").filter((n) => !existingCoreNames.has(n));
1537
+ const needsFile = requiredImports.has("file") && !hasFileHelper;
1538
+ if (missingCore.length === 0 && !needsFile) return false;
1539
+ let insertIndex = 0;
1540
+ const statements = sourceFile.getStatements();
1541
+ for (const st of statements) {
1542
+ if (ts_morph.Node.isExpressionStatement(st)) {
1543
+ const expr = st.getExpression();
1544
+ if (ts_morph.Node.isStringLiteral(expr)) {
1545
+ insertIndex += 1;
1546
+ continue;
1547
+ }
1548
+ }
1549
+ break;
1550
+ }
1551
+ const lines = [];
1552
+ if (missingCore.length > 0) {
1553
+ const sorted = Array.from(new Set(missingCore)).sort();
1554
+ lines.push(`const { ${sorted.join(", ")} } = require('intlayer');`);
1555
+ }
1556
+ if (needsFile) lines.push("const { file } = require('intlayer/file');");
1557
+ if (lines.length > 0) {
1558
+ sourceFile.insertStatements(insertIndex, lines.join("\n"));
1559
+ return true;
1560
+ }
1561
+ return false;
1562
+ };
1563
+ /**
1564
+ * Updates dictionary metadata properties (title, description, tags) in the root object
1565
+ */
1566
+ const updateDictionaryMetadata = (rootObject, dictionary) => {
1567
+ let changed = false;
1568
+ if (dictionary.title !== void 0) {
1569
+ const titleProperty = rootObject.getProperty("title");
1570
+ const titleValue = JSON.stringify(dictionary.title);
1571
+ if (titleProperty && ts_morph.Node.isPropertyAssignment(titleProperty)) {
1572
+ if (titleProperty.getInitializer()?.getText() !== titleValue) {
1573
+ titleProperty.setInitializer(titleValue);
1574
+ changed = true;
1575
+ }
1576
+ } else {
1577
+ rootObject.addPropertyAssignment({
1578
+ name: "title",
1579
+ initializer: titleValue
1580
+ });
1581
+ changed = true;
1582
+ }
1583
+ }
1584
+ if (dictionary.description !== void 0) {
1585
+ const descriptionProperty = rootObject.getProperty("description");
1586
+ const descriptionValue = JSON.stringify(dictionary.description);
1587
+ if (descriptionProperty && ts_morph.Node.isPropertyAssignment(descriptionProperty)) {
1588
+ if (descriptionProperty.getInitializer()?.getText() !== descriptionValue) {
1589
+ descriptionProperty.setInitializer(descriptionValue);
1590
+ changed = true;
1591
+ }
1592
+ } else {
1593
+ rootObject.addPropertyAssignment({
1594
+ name: "description",
1595
+ initializer: descriptionValue
1596
+ });
1597
+ changed = true;
1598
+ }
1599
+ }
1600
+ if (dictionary.tags !== void 0) {
1601
+ const tagsProperty = rootObject.getProperty("tags");
1602
+ const tagsValue = `[${dictionary.tags.map((tag) => JSON.stringify(tag)).join(", ")}]`;
1603
+ if (tagsProperty && ts_morph.Node.isPropertyAssignment(tagsProperty)) {
1604
+ if (tagsProperty.getInitializer()?.getText() !== tagsValue) {
1605
+ tagsProperty.setInitializer(tagsValue);
1606
+ changed = true;
1607
+ }
1608
+ } else {
1609
+ rootObject.addPropertyAssignment({
1610
+ name: "tags",
1611
+ initializer: tagsValue
1612
+ });
1613
+ changed = true;
1614
+ }
1615
+ }
1616
+ return changed;
1617
+ };
1618
+ /**
1619
+ * Locates the root dictionary object in the source file
1620
+ */
1621
+ const findRootDictionaryObject = (sourceFile) => {
1622
+ const exportAssignment = sourceFile.getExportAssignment((_) => true);
1623
+ if (exportAssignment) {
1624
+ const expression = exportAssignment.getExpression();
1625
+ if (ts_morph.Node.isIdentifier(expression)) {
1626
+ const declarationByName = expression.getSymbol()?.getDeclarations()?.[0] ?? sourceFile.getVariableDeclaration(expression.getText());
1627
+ if (declarationByName && ts_morph.Node.isVariableDeclaration(declarationByName)) {
1628
+ const objectLiteral = unwrapToObjectLiteral(declarationByName.getInitializer());
1629
+ if (objectLiteral) return objectLiteral;
1630
+ }
1631
+ } else {
1632
+ const objectLiteral = unwrapToObjectLiteral(expression);
1633
+ if (objectLiteral) return objectLiteral;
1634
+ }
1635
+ }
1636
+ const variableDeclaration = sourceFile.getVariableDeclaration((variable) => {
1637
+ try {
1638
+ return variable.getType().getText().includes("Dictionary") || variable.getName() === "content" || variable.getName().toLowerCase().includes("dictionary");
1639
+ } catch {
1640
+ return variable.getName() === "content";
1641
+ }
1642
+ });
1643
+ if (variableDeclaration) {
1644
+ const objectLiteral = unwrapToObjectLiteral(variableDeclaration.getInitializer());
1645
+ if (objectLiteral) return objectLiteral;
1646
+ }
1647
+ for (const statement of sourceFile.getStatements()) {
1648
+ if (!ts_morph.Node.isExpressionStatement(statement)) continue;
1649
+ const expression = statement.getExpression();
1650
+ if (!ts_morph.Node.isBinaryExpression(expression)) continue;
1651
+ if (expression.getOperatorToken().getText() !== "=") continue;
1652
+ const leftSide = expression.getLeft();
1653
+ if (!ts_morph.Node.isPropertyAccessExpression(leftSide)) continue;
1654
+ const leftExpression = leftSide.getExpression();
1655
+ const leftName = leftSide.getName();
1656
+ const isModuleExports = ts_morph.Node.isIdentifier(leftExpression) && leftExpression.getText() === "module" && leftName === "exports";
1657
+ const isExportsDefault = ts_morph.Node.isIdentifier(leftExpression) && leftExpression.getText() === "exports" && leftName === "default";
1658
+ if (!isModuleExports && !isExportsDefault) continue;
1659
+ const rightSide = expression.getRight();
1660
+ if (ts_morph.Node.isObjectLiteralExpression(rightSide)) return rightSide;
1661
+ if (ts_morph.Node.isIdentifier(rightSide)) {
1662
+ const declaration = rightSide.getSymbol()?.getDeclarations()?.[0];
1663
+ if (declaration && ts_morph.Node.isVariableDeclaration(declaration)) {
1664
+ const objectLiteral = unwrapToObjectLiteral(declaration.getInitializer());
1665
+ if (objectLiteral) return objectLiteral;
1666
+ }
1667
+ }
1668
+ }
1669
+ };
1670
+ /**
1671
+ * Updates a JavaScript/TypeScript file based on the provided dictionary.
1672
+ * It targets a specific dictionary object within the file and updates its
1673
+ * metadata (title, description, tags) and content entries.
1674
+ *
1675
+ * This function now supports inserting translation keys into nested objects
1676
+ * within arrays. For example, if you have:
1677
+ * ```
1678
+ * content: [
1679
+ * { question: t({ en: '...', fr: '...' }) }
1680
+ * ]
1681
+ * ```
1682
+ *
1683
+ * You can add a new locale (e.g., 'pl') by providing a dictionary with:
1684
+ * ```
1685
+ * {
1686
+ * content: [
1687
+ * { question: { [NodeType.Translation]: { en: '...', fr: '...', pl: '...' } } }
1688
+ * ]
1689
+ * }
1690
+ * ```
1691
+ *
1692
+ * The function will:
1693
+ * 1. Detect the existing array structure
1694
+ * 2. Navigate into each array element (if it's an object)
1695
+ * 3. Recursively process nested properties
1696
+ * 4. Update translation maps while preserving existing locales
1697
+ */
1698
+ const transformJSFile = async (fileContent, dictionary, fallbackLocale) => {
1699
+ try {
1700
+ if (!dictionary || typeof dictionary !== "object") return fileContent;
1701
+ const sourceFile = new ts_morph.Project({
1702
+ useInMemoryFileSystem: true,
1703
+ skipAddingFilesFromTsConfig: true,
1704
+ skipFileDependencyResolution: true,
1705
+ compilerOptions: {
1706
+ allowJs: true,
1707
+ jsx: ts_morph.ts.JsxEmit.Preserve
1708
+ },
1709
+ manipulationSettings: {
1710
+ indentationText: ts_morph.IndentationText.TwoSpaces,
1711
+ quoteKind: ts_morph.QuoteKind.Double,
1712
+ newLineKind: ts_morph.NewLineKind.LineFeed
1713
+ }
1714
+ }).createSourceFile("file.tsx", fileContent, { overwrite: true });
1715
+ const rootObject = findRootDictionaryObject(sourceFile);
1716
+ if (!rootObject) return fileContent;
1717
+ let changed = false;
1718
+ const requiredImports = /* @__PURE__ */ new Set();
1719
+ if (updateDictionaryMetadata(rootObject, dictionary)) changed = true;
1720
+ if (dictionary.content) {
1721
+ const contentProperty = rootObject.getProperty("content");
1722
+ let contentObject;
1723
+ let isContentArrayInSource = false;
1724
+ if (contentProperty && ts_morph.Node.isPropertyAssignment(contentProperty)) {
1725
+ contentObject = contentProperty.getInitializerIfKind(ts_morph.SyntaxKind.ObjectLiteralExpression);
1726
+ isContentArrayInSource = !!contentProperty.getInitializerIfKind(ts_morph.SyntaxKind.ArrayLiteralExpression);
1727
+ }
1728
+ const effectiveFallbackLocale = fallbackLocale ?? "en";
1729
+ if (contentObject && !Array.isArray(dictionary.content)) {
1730
+ const dictContent = dictionary.content ?? {};
1731
+ if (processContentEntries(contentObject, dictContent, effectiveFallbackLocale, requiredImports, sourceFile)) changed = true;
1732
+ } else if (Array.isArray(dictionary.content) && isContentArrayInSource) {
1733
+ if (processArrayContent(rootObject, "content", dictionary.content ?? [], getExistingPropertyNames(rootObject), effectiveFallbackLocale, requiredImports, sourceFile)) changed = true;
1734
+ }
1735
+ }
1736
+ if (!changed) return fileContent;
1737
+ if ((isCommonJS(sourceFile) ? addMissingRequires(sourceFile, requiredImports) : addMissingImports(sourceFile, requiredImports)) || changed) return sourceFile.getFullText();
1738
+ return fileContent;
1739
+ } catch {
1740
+ return fileContent;
1741
+ }
1742
+ };
1743
+
1744
+ //#endregion
1745
+ exports.transformJSFile = transformJSFile;
770
1746
  //# sourceMappingURL=transformJSFile.cjs.map