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