@intlayer/chokidar 8.1.2 → 8.1.3

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