gtx-cli 2.6.29 → 2.6.30-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (340) hide show
  1. package/README.md +12 -3
  2. package/dist/bin/bin-entry.js +2 -1
  3. package/dist/functions.d.ts +1 -7
  4. package/dist/functions.js +1 -6
  5. package/dist/index.d.ts +1 -4
  6. package/dist/index.js +1 -27
  7. package/dist/main.js +2 -2
  8. package/package.json +9 -60
  9. package/CHANGELOG.md +0 -1255
  10. package/dist/api/collectUserEditDiffs.d.ts +0 -9
  11. package/dist/api/collectUserEditDiffs.js +0 -159
  12. package/dist/api/downloadFileBatch.d.ts +0 -23
  13. package/dist/api/downloadFileBatch.js +0 -190
  14. package/dist/api/saveLocalEdits.d.ts +0 -6
  15. package/dist/api/saveLocalEdits.js +0 -38
  16. package/dist/cli/base.d.ts +0 -59
  17. package/dist/cli/base.js +0 -529
  18. package/dist/cli/commands/download.d.ts +0 -8
  19. package/dist/cli/commands/download.js +0 -51
  20. package/dist/cli/commands/enqueue.d.ts +0 -9
  21. package/dist/cli/commands/enqueue.js +0 -27
  22. package/dist/cli/commands/setupProject.d.ts +0 -7
  23. package/dist/cli/commands/setupProject.js +0 -37
  24. package/dist/cli/commands/stage.d.ts +0 -9
  25. package/dist/cli/commands/stage.js +0 -59
  26. package/dist/cli/commands/translate.d.ts +0 -7
  27. package/dist/cli/commands/translate.js +0 -70
  28. package/dist/cli/commands/upload.d.ts +0 -13
  29. package/dist/cli/commands/upload.js +0 -142
  30. package/dist/cli/commands/utils/validation.d.ts +0 -13
  31. package/dist/cli/commands/utils/validation.js +0 -38
  32. package/dist/cli/flags.d.ts +0 -15
  33. package/dist/cli/flags.js +0 -70
  34. package/dist/cli/inline.d.ts +0 -17
  35. package/dist/cli/inline.js +0 -135
  36. package/dist/cli/next.d.ts +0 -10
  37. package/dist/cli/next.js +0 -12
  38. package/dist/cli/node.d.ts +0 -10
  39. package/dist/cli/node.js +0 -9
  40. package/dist/cli/react.d.ts +0 -12
  41. package/dist/cli/react.js +0 -72
  42. package/dist/config/generateSettings.d.ts +0 -9
  43. package/dist/config/generateSettings.js +0 -214
  44. package/dist/config/optionPresets.d.ts +0 -3
  45. package/dist/config/optionPresets.js +0 -65
  46. package/dist/config/resolveConfig.d.ts +0 -4
  47. package/dist/config/resolveConfig.js +0 -33
  48. package/dist/config/utils.d.ts +0 -2
  49. package/dist/config/utils.js +0 -4
  50. package/dist/config/validateSettings.d.ts +0 -3
  51. package/dist/config/validateSettings.js +0 -32
  52. package/dist/console/colors.d.ts +0 -6
  53. package/dist/console/colors.js +0 -19
  54. package/dist/console/displayTranslateSummary.d.ts +0 -1
  55. package/dist/console/displayTranslateSummary.js +0 -42
  56. package/dist/console/formatting.d.ts +0 -1
  57. package/dist/console/formatting.js +0 -7
  58. package/dist/console/index.d.ts +0 -33
  59. package/dist/console/index.js +0 -44
  60. package/dist/console/logger.d.ts +0 -35
  61. package/dist/console/logger.js +0 -250
  62. package/dist/console/logging.d.ts +0 -52
  63. package/dist/console/logging.js +0 -175
  64. package/dist/formats/files/aggregateFiles.d.ts +0 -4
  65. package/dist/formats/files/aggregateFiles.js +0 -173
  66. package/dist/formats/files/collectFiles.d.ts +0 -6
  67. package/dist/formats/files/collectFiles.js +0 -49
  68. package/dist/formats/files/convertToFileTranslationData.d.ts +0 -15
  69. package/dist/formats/files/convertToFileTranslationData.js +0 -21
  70. package/dist/formats/files/fileMapping.d.ts +0 -11
  71. package/dist/formats/files/fileMapping.js +0 -115
  72. package/dist/formats/files/save.d.ts +0 -5
  73. package/dist/formats/files/save.js +0 -17
  74. package/dist/formats/files/supportedFiles.d.ts +0 -11
  75. package/dist/formats/files/supportedFiles.js +0 -20
  76. package/dist/formats/json/extractJson.d.ts +0 -15
  77. package/dist/formats/json/extractJson.js +0 -101
  78. package/dist/formats/json/flattenJson.d.ts +0 -14
  79. package/dist/formats/json/flattenJson.js +0 -64
  80. package/dist/formats/json/mergeJson.d.ts +0 -13
  81. package/dist/formats/json/mergeJson.js +0 -367
  82. package/dist/formats/json/parseJson.d.ts +0 -2
  83. package/dist/formats/json/parseJson.js +0 -109
  84. package/dist/formats/json/utils.d.ts +0 -47
  85. package/dist/formats/json/utils.js +0 -150
  86. package/dist/formats/utils.d.ts +0 -2
  87. package/dist/formats/utils.js +0 -24
  88. package/dist/formats/yaml/mergeYaml.d.ts +0 -5
  89. package/dist/formats/yaml/mergeYaml.js +0 -61
  90. package/dist/formats/yaml/parseYaml.d.ts +0 -5
  91. package/dist/formats/yaml/parseYaml.js +0 -24
  92. package/dist/formats/yaml/utils.d.ts +0 -2
  93. package/dist/formats/yaml/utils.js +0 -23
  94. package/dist/fs/clearLocaleDirs.d.ts +0 -8
  95. package/dist/fs/clearLocaleDirs.js +0 -126
  96. package/dist/fs/config/downloadedVersions.d.ts +0 -21
  97. package/dist/fs/config/downloadedVersions.js +0 -50
  98. package/dist/fs/config/loadConfig.d.ts +0 -1
  99. package/dist/fs/config/loadConfig.js +0 -9
  100. package/dist/fs/config/parseFilesConfig.d.ts +0 -27
  101. package/dist/fs/config/parseFilesConfig.js +0 -150
  102. package/dist/fs/config/setupConfig.d.ts +0 -17
  103. package/dist/fs/config/setupConfig.js +0 -50
  104. package/dist/fs/config/updateConfig.d.ts +0 -21
  105. package/dist/fs/config/updateConfig.js +0 -57
  106. package/dist/fs/config/updateVersions.d.ts +0 -11
  107. package/dist/fs/config/updateVersions.js +0 -30
  108. package/dist/fs/copyFile.d.ts +0 -7
  109. package/dist/fs/copyFile.js +0 -39
  110. package/dist/fs/createLoadTranslationsFile.d.ts +0 -1
  111. package/dist/fs/createLoadTranslationsFile.js +0 -49
  112. package/dist/fs/determineFramework.d.ts +0 -5
  113. package/dist/fs/determineFramework.js +0 -53
  114. package/dist/fs/findFilepath.d.ts +0 -36
  115. package/dist/fs/findFilepath.js +0 -90
  116. package/dist/fs/index.d.ts +0 -1
  117. package/dist/fs/index.js +0 -1
  118. package/dist/fs/loadJSON.d.ts +0 -6
  119. package/dist/fs/loadJSON.js +0 -17
  120. package/dist/fs/matchFiles.d.ts +0 -1
  121. package/dist/fs/matchFiles.js +0 -8
  122. package/dist/fs/saveJSON.d.ts +0 -1
  123. package/dist/fs/saveJSON.js +0 -7
  124. package/dist/fs/utils.d.ts +0 -1
  125. package/dist/fs/utils.js +0 -16
  126. package/dist/generated/version.d.ts +0 -1
  127. package/dist/generated/version.js +0 -2
  128. package/dist/git/branches.d.ts +0 -7
  129. package/dist/git/branches.js +0 -88
  130. package/dist/hooks/postProcess.d.ts +0 -4
  131. package/dist/hooks/postProcess.js +0 -110
  132. package/dist/locadex/setupFlow.d.ts +0 -2
  133. package/dist/locadex/setupFlow.js +0 -9
  134. package/dist/next/config/parseNextConfig.d.ts +0 -10
  135. package/dist/next/config/parseNextConfig.js +0 -53
  136. package/dist/next/jsx/utils.d.ts +0 -7
  137. package/dist/next/jsx/utils.js +0 -42
  138. package/dist/next/parse/handleInitGT.d.ts +0 -7
  139. package/dist/next/parse/handleInitGT.js +0 -157
  140. package/dist/next/parse/wrapContent.d.ts +0 -12
  141. package/dist/next/parse/wrapContent.js +0 -164
  142. package/dist/react/config/createESBuildConfig.d.ts +0 -2
  143. package/dist/react/config/createESBuildConfig.js +0 -119
  144. package/dist/react/jsx/evaluateJsx.d.ts +0 -24
  145. package/dist/react/jsx/evaluateJsx.js +0 -123
  146. package/dist/react/jsx/utils/buildImportMap.d.ts +0 -9
  147. package/dist/react/jsx/utils/buildImportMap.js +0 -30
  148. package/dist/react/jsx/utils/constants.d.ts +0 -13
  149. package/dist/react/jsx/utils/constants.js +0 -46
  150. package/dist/react/jsx/utils/getCalleeNameFromExpression.d.ts +0 -9
  151. package/dist/react/jsx/utils/getCalleeNameFromExpression.js +0 -32
  152. package/dist/react/jsx/utils/getPathsAndAliases.d.ts +0 -21
  153. package/dist/react/jsx/utils/getPathsAndAliases.js +0 -91
  154. package/dist/react/jsx/utils/isNumberLiteral.d.ts +0 -7
  155. package/dist/react/jsx/utils/isNumberLiteral.js +0 -13
  156. package/dist/react/jsx/utils/jsxParsing/addGTIdentifierToSyntaxTree.d.ts +0 -9
  157. package/dist/react/jsx/utils/jsxParsing/addGTIdentifierToSyntaxTree.js +0 -135
  158. package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.d.ts +0 -6
  159. package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.js +0 -197
  160. package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.d.ts +0 -13
  161. package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.js +0 -42
  162. package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.d.ts +0 -5
  163. package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.js +0 -69
  164. package/dist/react/jsx/utils/jsxParsing/parseJsx.d.ts +0 -33
  165. package/dist/react/jsx/utils/jsxParsing/parseJsx.js +0 -912
  166. package/dist/react/jsx/utils/jsxParsing/parseTProps.d.ts +0 -8
  167. package/dist/react/jsx/utils/jsxParsing/parseTProps.js +0 -65
  168. package/dist/react/jsx/utils/jsxParsing/removeNullChildrenFields.d.ts +0 -2
  169. package/dist/react/jsx/utils/jsxParsing/removeNullChildrenFields.js +0 -61
  170. package/dist/react/jsx/utils/jsxParsing/types.d.ts +0 -48
  171. package/dist/react/jsx/utils/jsxParsing/types.js +0 -34
  172. package/dist/react/jsx/utils/mapAttributeName.d.ts +0 -11
  173. package/dist/react/jsx/utils/mapAttributeName.js +0 -12
  174. package/dist/react/jsx/utils/parseAst.d.ts +0 -31
  175. package/dist/react/jsx/utils/parseAst.js +0 -278
  176. package/dist/react/jsx/utils/parseDeclareStatic.d.ts +0 -15
  177. package/dist/react/jsx/utils/parseDeclareStatic.js +0 -540
  178. package/dist/react/jsx/utils/parseString.d.ts +0 -25
  179. package/dist/react/jsx/utils/parseString.js +0 -540
  180. package/dist/react/jsx/utils/parseStringFunction.d.ts +0 -30
  181. package/dist/react/jsx/utils/parseStringFunction.js +0 -348
  182. package/dist/react/jsx/utils/resolveImportPath.d.ts +0 -11
  183. package/dist/react/jsx/utils/resolveImportPath.js +0 -111
  184. package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.d.ts +0 -29
  185. package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.js +0 -86
  186. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.d.ts +0 -14
  187. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.js +0 -24
  188. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.d.ts +0 -19
  189. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.js +0 -31
  190. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleStaticTranslationCall.d.ts +0 -22
  191. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleStaticTranslationCall.js +0 -51
  192. package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.d.ts +0 -18
  193. package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.js +0 -39
  194. package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.d.ts +0 -24
  195. package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.js +0 -68
  196. package/dist/react/jsx/utils/stringParsing/types.d.ts +0 -41
  197. package/dist/react/jsx/utils/stringParsing/types.js +0 -1
  198. package/dist/react/jsx/utils/types.d.ts +0 -14
  199. package/dist/react/jsx/utils/types.js +0 -1
  200. package/dist/react/jsx/utils/validateStringFunction.d.ts +0 -7
  201. package/dist/react/jsx/utils/validateStringFunction.js +0 -31
  202. package/dist/react/jsx/wrapJsx.d.ts +0 -51
  203. package/dist/react/jsx/wrapJsx.js +0 -387
  204. package/dist/react/parse/addVitePlugin/index.d.ts +0 -22
  205. package/dist/react/parse/addVitePlugin/index.js +0 -41
  206. package/dist/react/parse/addVitePlugin/installCompiler.d.ts +0 -8
  207. package/dist/react/parse/addVitePlugin/installCompiler.js +0 -22
  208. package/dist/react/parse/addVitePlugin/updateViteConfig.d.ts +0 -19
  209. package/dist/react/parse/addVitePlugin/updateViteConfig.js +0 -120
  210. package/dist/react/parse/addVitePlugin/utils/addCompilerImport.d.ts +0 -9
  211. package/dist/react/parse/addVitePlugin/utils/addCompilerImport.js +0 -34
  212. package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.d.ts +0 -11
  213. package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.js +0 -48
  214. package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.d.ts +0 -15
  215. package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.js +0 -113
  216. package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.d.ts +0 -12
  217. package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.js +0 -32
  218. package/dist/react/parse/createDictionaryUpdates.d.ts +0 -3
  219. package/dist/react/parse/createDictionaryUpdates.js +0 -187
  220. package/dist/react/parse/createInlineUpdates.d.ts +0 -13
  221. package/dist/react/parse/createInlineUpdates.js +0 -161
  222. package/dist/react/parse/wrapContent.d.ts +0 -12
  223. package/dist/react/parse/wrapContent.js +0 -162
  224. package/dist/react/utils/flattenDictionary.d.ts +0 -20
  225. package/dist/react/utils/flattenDictionary.js +0 -75
  226. package/dist/react/utils/getEntryAndMetadata.d.ts +0 -5
  227. package/dist/react/utils/getEntryAndMetadata.js +0 -11
  228. package/dist/react/utils/getVariableName.d.ts +0 -25
  229. package/dist/react/utils/getVariableName.js +0 -37
  230. package/dist/setup/agentInstructions.d.ts +0 -24
  231. package/dist/setup/agentInstructions.js +0 -138
  232. package/dist/setup/detectFramework.d.ts +0 -31
  233. package/dist/setup/detectFramework.js +0 -106
  234. package/dist/setup/frameworkUtils.d.ts +0 -3
  235. package/dist/setup/frameworkUtils.js +0 -30
  236. package/dist/setup/instructions/base.md +0 -29
  237. package/dist/setup/instructions/gt-next.md +0 -107
  238. package/dist/setup/instructions/gt-react.md +0 -98
  239. package/dist/setup/userInput.d.ts +0 -4
  240. package/dist/setup/userInput.js +0 -32
  241. package/dist/setup/wizard.d.ts +0 -3
  242. package/dist/setup/wizard.js +0 -147
  243. package/dist/state/recentDownloads.d.ts +0 -12
  244. package/dist/state/recentDownloads.js +0 -18
  245. package/dist/state/translateWarnings.d.ts +0 -10
  246. package/dist/state/translateWarnings.js +0 -13
  247. package/dist/translation/parse.d.ts +0 -17
  248. package/dist/translation/parse.js +0 -77
  249. package/dist/translation/stage.d.ts +0 -3
  250. package/dist/translation/stage.js +0 -44
  251. package/dist/translation/validate.d.ts +0 -14
  252. package/dist/translation/validate.js +0 -100
  253. package/dist/types/branch.d.ts +0 -14
  254. package/dist/types/branch.js +0 -1
  255. package/dist/types/data/json.d.ts +0 -6
  256. package/dist/types/data/json.js +0 -1
  257. package/dist/types/data.d.ts +0 -37
  258. package/dist/types/data.js +0 -1
  259. package/dist/types/files.d.ts +0 -8
  260. package/dist/types/files.js +0 -1
  261. package/dist/types/index.d.ts +0 -243
  262. package/dist/types/index.js +0 -1
  263. package/dist/types/libraries.d.ts +0 -31
  264. package/dist/types/libraries.js +0 -72
  265. package/dist/types/parsing.d.ts +0 -3
  266. package/dist/types/parsing.js +0 -1
  267. package/dist/utils/addExplicitAnchorIds.d.ts +0 -24
  268. package/dist/utils/addExplicitAnchorIds.js +0 -416
  269. package/dist/utils/constants.d.ts +0 -5
  270. package/dist/utils/constants.js +0 -6
  271. package/dist/utils/credentials.d.ts +0 -12
  272. package/dist/utils/credentials.js +0 -120
  273. package/dist/utils/flattenJsonFiles.d.ts +0 -2
  274. package/dist/utils/flattenJsonFiles.js +0 -36
  275. package/dist/utils/gitDiff.d.ts +0 -8
  276. package/dist/utils/gitDiff.js +0 -34
  277. package/dist/utils/gt.d.ts +0 -2
  278. package/dist/utils/gt.js +0 -2
  279. package/dist/utils/hash.d.ts +0 -6
  280. package/dist/utils/hash.js +0 -11
  281. package/dist/utils/headers.d.ts +0 -1
  282. package/dist/utils/headers.js +0 -14
  283. package/dist/utils/installPackage.d.ts +0 -3
  284. package/dist/utils/installPackage.js +0 -77
  285. package/dist/utils/localizeRelativeAssets.d.ts +0 -8
  286. package/dist/utils/localizeRelativeAssets.js +0 -166
  287. package/dist/utils/localizeStaticImports.d.ts +0 -15
  288. package/dist/utils/localizeStaticImports.js +0 -397
  289. package/dist/utils/localizeStaticUrls.d.ts +0 -19
  290. package/dist/utils/localizeStaticUrls.js +0 -450
  291. package/dist/utils/mintlifyTitleFallback.d.ts +0 -6
  292. package/dist/utils/mintlifyTitleFallback.js +0 -80
  293. package/dist/utils/packageInfo.d.ts +0 -3
  294. package/dist/utils/packageInfo.js +0 -17
  295. package/dist/utils/packageJson.d.ts +0 -6
  296. package/dist/utils/packageJson.js +0 -68
  297. package/dist/utils/packageManager.d.ts +0 -28
  298. package/dist/utils/packageManager.js +0 -269
  299. package/dist/utils/parse/needsCJS.d.ts +0 -20
  300. package/dist/utils/parse/needsCJS.js +0 -72
  301. package/dist/utils/persistPostprocessHashes.d.ts +0 -12
  302. package/dist/utils/persistPostprocessHashes.js +0 -39
  303. package/dist/utils/processAnchorIds.d.ts +0 -6
  304. package/dist/utils/processAnchorIds.js +0 -56
  305. package/dist/utils/processOpenApi.d.ts +0 -8
  306. package/dist/utils/processOpenApi.js +0 -651
  307. package/dist/utils/sanitizeFileContent.d.ts +0 -6
  308. package/dist/utils/sanitizeFileContent.js +0 -29
  309. package/dist/utils/sharedStaticAssets.d.ts +0 -9
  310. package/dist/utils/sharedStaticAssets.js +0 -384
  311. package/dist/utils/validateMdx.d.ts +0 -10
  312. package/dist/utils/validateMdx.js +0 -25
  313. package/dist/workflows/download.d.ts +0 -32
  314. package/dist/workflows/download.js +0 -127
  315. package/dist/workflows/enqueue.d.ts +0 -17
  316. package/dist/workflows/enqueue.js +0 -59
  317. package/dist/workflows/setupProject.d.ts +0 -13
  318. package/dist/workflows/setupProject.js +0 -48
  319. package/dist/workflows/stage.d.ts +0 -18
  320. package/dist/workflows/stage.js +0 -59
  321. package/dist/workflows/steps/BranchStep.d.ts +0 -13
  322. package/dist/workflows/steps/BranchStep.js +0 -161
  323. package/dist/workflows/steps/DownloadStep.d.ts +0 -19
  324. package/dist/workflows/steps/DownloadStep.js +0 -131
  325. package/dist/workflows/steps/EnqueueStep.d.ts +0 -15
  326. package/dist/workflows/steps/EnqueueStep.js +0 -33
  327. package/dist/workflows/steps/PollJobsStep.d.ts +0 -31
  328. package/dist/workflows/steps/PollJobsStep.js +0 -288
  329. package/dist/workflows/steps/SetupStep.d.ts +0 -16
  330. package/dist/workflows/steps/SetupStep.js +0 -72
  331. package/dist/workflows/steps/UploadSourcesStep.d.ts +0 -27
  332. package/dist/workflows/steps/UploadSourcesStep.js +0 -131
  333. package/dist/workflows/steps/UploadTranslationsStep.d.ts +0 -22
  334. package/dist/workflows/steps/UploadTranslationsStep.js +0 -71
  335. package/dist/workflows/steps/UserEditDiffsStep.d.ts +0 -11
  336. package/dist/workflows/steps/UserEditDiffsStep.js +0 -30
  337. package/dist/workflows/steps/WorkflowStep.d.ts +0 -4
  338. package/dist/workflows/steps/WorkflowStep.js +0 -2
  339. package/dist/workflows/upload.d.ts +0 -15
  340. package/dist/workflows/upload.js +0 -47
@@ -1,540 +0,0 @@
1
- import * as t from '@babel/types';
2
- import { buildImportMap } from './buildImportMap.js';
3
- import { resolveImportPath } from './resolveImportPath.js';
4
- import { parse } from '@babel/parser';
5
- import fs from 'node:fs';
6
- import { warnDeclareStaticNoResultsSync, warnFunctionNotFoundSync, warnInvalidDeclareVarNameSync, } from '../../../console/index.js';
7
- import traverseModule from '@babel/traverse';
8
- import { DECLARE_VAR_FUNCTION } from '../../jsx/utils/constants.js';
9
- import { GT_LIBRARIES } from '../../../types/libraries.js';
10
- import { declareVar } from 'generaltranslation/internal';
11
- import { isStaticExpression } from '../evaluateJsx.js';
12
- import generateModule from '@babel/generator';
13
- // Handle CommonJS/ESM interop
14
- const traverse = traverseModule.default || traverseModule;
15
- const generate = generateModule.default || generateModule;
16
- /**
17
- * Cache for resolved import paths to avoid redundant I/O operations.
18
- */
19
- const resolveImportPathCache = new Map();
20
- /**
21
- * Cache for processed functions to avoid re-parsing the same files.
22
- */
23
- const processFunctionCache = new Map();
24
- /**
25
- * Processes a string expression node and resolves any function calls within it
26
- * This handles cases like:
27
- * - "hello" (string literal)
28
- * - "hello" + world() (binary expression with function call)
29
- * - Math.random() > 0.5 ? "day" : "night" (conditional expression)
30
- * - greeting() (function call that returns string or conditional)
31
- *
32
- * @param node - The AST node to process
33
- * @param tPath - NodePath for scope resolution
34
- * @param file - Current file path
35
- * @param parsingOptions - Parsing configuration
36
- * @param warnings - Set to collect warning messages
37
- * @returns Node | null
38
- */
39
- export function parseStringExpression(node, tPath, file, parsingOptions, warnings = new Set()) {
40
- // Handle string literals
41
- if (t.isStringLiteral(node)) {
42
- return { type: 'text', text: node.value };
43
- }
44
- // Handle numeric literals
45
- if (t.isNumericLiteral(node)) {
46
- return { type: 'text', text: String(node.value) };
47
- }
48
- // Handle boolean literals
49
- if (t.isBooleanLiteral(node)) {
50
- return { type: 'text', text: String(node.value) };
51
- }
52
- // Handle null literal
53
- if (t.isNullLiteral(node)) {
54
- return { type: 'text', text: 'null' };
55
- }
56
- // Handle template literals
57
- if (t.isTemplateLiteral(node)) {
58
- const parts = [];
59
- for (let index = 0; index < node.quasis.length; index++) {
60
- const quasi = node.quasis[index];
61
- const text = quasi.value.cooked ?? quasi.value.raw ?? '';
62
- if (text) {
63
- parts.push({ type: 'text', text });
64
- }
65
- const exprNode = node.expressions[index];
66
- if (exprNode && t.isExpression(exprNode)) {
67
- const result = parseStringExpression(exprNode, tPath, file, parsingOptions, warnings);
68
- if (result === null) {
69
- return null;
70
- }
71
- parts.push(result);
72
- }
73
- }
74
- if (parts.length === 0) {
75
- return { type: 'text', text: '' };
76
- }
77
- if (parts.length === 1) {
78
- return parts[0];
79
- }
80
- return { type: 'sequence', nodes: parts };
81
- }
82
- // Handle binary expressions (e.g., "hello" + world())
83
- if (t.isBinaryExpression(node) && node.operator === '+') {
84
- if (!t.isExpression(node.left) || !t.isExpression(node.right)) {
85
- return null;
86
- }
87
- const leftResult = parseStringExpression(node.left, tPath, file, parsingOptions, warnings);
88
- const rightResult = parseStringExpression(node.right, tPath, file, parsingOptions, warnings);
89
- if (leftResult === null || rightResult === null) {
90
- return null;
91
- }
92
- return { type: 'sequence', nodes: [leftResult, rightResult] };
93
- }
94
- // Handle conditional expressions (e.g., cond ? "day" : "night")
95
- if (t.isConditionalExpression(node)) {
96
- if (!t.isExpression(node.consequent) || !t.isExpression(node.alternate)) {
97
- return null;
98
- }
99
- const consequentResult = parseStringExpression(node.consequent, tPath, file, parsingOptions, warnings);
100
- const alternateResult = parseStringExpression(node.alternate, tPath, file, parsingOptions, warnings);
101
- if (consequentResult === null || alternateResult === null) {
102
- return null;
103
- }
104
- // Create a choice node with both branches
105
- return {
106
- type: 'choice',
107
- nodes: [consequentResult, alternateResult],
108
- };
109
- }
110
- // Handle variable references (e.g., result)
111
- if (t.isIdentifier(node)) {
112
- const binding = tPath.scope.getBinding(node.name);
113
- if (!binding) {
114
- // Variable not found in scope
115
- return null;
116
- }
117
- // Check if it's a const/let/var with an initializer
118
- if (binding.path.isVariableDeclarator() && binding.path.node.init) {
119
- const init = binding.path.node.init;
120
- if (t.isExpression(init)) {
121
- // Recursively resolve the initializer
122
- return parseStringExpression(init, binding.path, file, parsingOptions, warnings);
123
- }
124
- }
125
- // Not a resolvable variable
126
- return null;
127
- }
128
- // Handle function calls (e.g., getName())
129
- if (t.isCallExpression(node) && t.isIdentifier(node.callee)) {
130
- const functionName = node.callee.name;
131
- const calleeBinding = tPath.scope.getBinding(functionName);
132
- if (!calleeBinding) {
133
- // Function not found in scope
134
- warnings.add(warnFunctionNotFoundSync(file, functionName, `${node.callee.loc?.start?.line}:${node.callee.loc?.start?.column}`));
135
- return null;
136
- }
137
- // Check if this is an imported function
138
- const programPath = tPath.scope.getProgramParent().path;
139
- const importedFunctionsMap = buildImportMap(programPath);
140
- if (importedFunctionsMap.has(functionName)) {
141
- // Function is imported - resolve cross-file
142
- let originalName;
143
- if (calleeBinding.path.isImportSpecifier()) {
144
- originalName = t.isIdentifier(calleeBinding.path.node.imported)
145
- ? calleeBinding.path.node.imported.name
146
- : calleeBinding.path.node.imported.value;
147
- }
148
- else if (calleeBinding.path.isImportDefaultSpecifier()) {
149
- originalName = calleeBinding.path.node.local.name;
150
- }
151
- else if (calleeBinding.path.isImportNamespaceSpecifier()) {
152
- originalName = calleeBinding.path.node.local.name;
153
- }
154
- const importPath = importedFunctionsMap.get(functionName);
155
- // Handle declareVar function
156
- if (originalName === DECLARE_VAR_FUNCTION &&
157
- GT_LIBRARIES.includes(importPath)) {
158
- // check for name field eg declareVar('test', { $name: 'test' })
159
- if (node.arguments.length > 1 &&
160
- t.isObjectExpression(node.arguments[1])) {
161
- const name = node.arguments[1].properties
162
- .filter((prop) => t.isObjectProperty(prop))
163
- .find((prop) => t.isIdentifier(prop.key) && prop.key.name === '$name')?.value;
164
- if (name) {
165
- if (!t.isExpression(name)) {
166
- warnings.add(warnInvalidDeclareVarNameSync(file, generate(name).code, `${node.arguments[1].loc?.start?.line}:${node.arguments[1].loc?.start?.column}`));
167
- return null;
168
- }
169
- const staticResult = isStaticExpression(name);
170
- if (!staticResult.isStatic) {
171
- warnings.add(warnInvalidDeclareVarNameSync(file, generate(name).code, `${node.arguments[1].loc?.start?.line}:${node.arguments[1].loc?.start?.column}`));
172
- return null;
173
- }
174
- return {
175
- type: 'text',
176
- text: declareVar('', { $name: staticResult.value }),
177
- };
178
- }
179
- }
180
- return {
181
- type: 'text',
182
- text: declareVar(''),
183
- };
184
- }
185
- const filePath = resolveImportPath(file, importPath, parsingOptions, resolveImportPathCache);
186
- if (filePath && originalName) {
187
- return resolveFunctionInFile(filePath, originalName, parsingOptions, warnings);
188
- }
189
- return null;
190
- }
191
- // Resolve the function locally and get its return values
192
- return resolveFunctionCall(calleeBinding, tPath, file, parsingOptions, warnings);
193
- }
194
- // Handle parenthesized expressions
195
- if (t.isParenthesizedExpression(node)) {
196
- return parseStringExpression(node.expression, tPath, file, parsingOptions, warnings);
197
- }
198
- // Handle unary expressions (e.g., -123)
199
- if (t.isUnaryExpression(node)) {
200
- let operator = '';
201
- if (node.operator === '-') {
202
- operator = node.operator;
203
- }
204
- if (t.isNumericLiteral(node.argument)) {
205
- if (node.argument.value === 0) {
206
- return { type: 'text', text: '0' };
207
- }
208
- else {
209
- return {
210
- type: 'text',
211
- text: operator + node.argument.value.toString(),
212
- };
213
- }
214
- }
215
- return null;
216
- }
217
- // Unsupported expression type
218
- return null;
219
- }
220
- /**
221
- * Resolves a function call by traversing its body and collecting return values
222
- */
223
- function resolveFunctionCall(calleeBinding, tPath, file, parsingOptions, warnings) {
224
- if (!calleeBinding) {
225
- return null;
226
- }
227
- const bindingPath = calleeBinding.path;
228
- const branches = [];
229
- // Handle function declarations: function time() { return "day"; }
230
- if (bindingPath.isFunctionDeclaration()) {
231
- bindingPath.traverse({
232
- // Don't skip nested functions - let parseStringExpression handle function calls
233
- ReturnStatement(returnPath) {
234
- // Only process return statements that are direct children of this function
235
- // Skip return statements from nested functions (they'll be handled when those functions are called)
236
- const parentFunction = returnPath.getFunctionParent();
237
- if (parentFunction?.node !== bindingPath.node) {
238
- // This return belongs to a nested function, skip it
239
- return;
240
- }
241
- const returnArg = returnPath.node.argument;
242
- if (!returnArg || !t.isExpression(returnArg)) {
243
- return;
244
- }
245
- const returnResult = parseStringExpression(returnArg, returnPath, file, parsingOptions, warnings);
246
- if (returnResult !== null) {
247
- branches.push(returnResult);
248
- }
249
- },
250
- });
251
- }
252
- // Handle arrow functions: const time = () => "day"
253
- else if (bindingPath.isVariableDeclarator()) {
254
- const init = bindingPath.get('init');
255
- if (!init.isArrowFunctionExpression()) {
256
- return null;
257
- }
258
- const body = init.get('body');
259
- // Handle expression body: () => "day"
260
- if (body.isExpression()) {
261
- const bodyResult = parseStringExpression(body.node, body, file, parsingOptions, warnings);
262
- if (bodyResult !== null) {
263
- branches.push(bodyResult);
264
- }
265
- }
266
- // Handle block body: () => { return "day"; }
267
- else if (body.isBlockStatement()) {
268
- const arrowFunction = init.node;
269
- body.traverse({
270
- // Don't skip nested functions - let parseStringExpression handle function calls
271
- ReturnStatement(returnPath) {
272
- // Only process return statements that are direct children of this function
273
- // Skip return statements from nested functions (they'll be handled when those functions are called)
274
- const parentFunction = returnPath.getFunctionParent();
275
- if (parentFunction?.node !== arrowFunction) {
276
- // This return belongs to a nested function, skip it
277
- return;
278
- }
279
- const returnArg = returnPath.node.argument;
280
- if (!returnArg || !t.isExpression(returnArg)) {
281
- return;
282
- }
283
- const returnResult = parseStringExpression(returnArg, returnPath, file, parsingOptions, warnings);
284
- if (returnResult !== null) {
285
- branches.push(returnResult);
286
- }
287
- },
288
- });
289
- }
290
- }
291
- if (branches.length === 0) {
292
- return null;
293
- }
294
- if (branches.length === 1) {
295
- return branches[0];
296
- }
297
- return { type: 'choice', nodes: branches };
298
- }
299
- /**
300
- * Resolves a function definition in an external file
301
- */
302
- function resolveFunctionInFile(filePath, functionName, parsingOptions, warnings) {
303
- // Check cache first
304
- const cacheKey = `${filePath}::${functionName}`;
305
- if (processFunctionCache.has(cacheKey)) {
306
- return processFunctionCache.get(cacheKey) ?? null;
307
- }
308
- let result = null;
309
- try {
310
- const code = fs.readFileSync(filePath, 'utf8');
311
- const ast = parse(code, {
312
- sourceType: 'module',
313
- plugins: ['jsx', 'typescript'],
314
- });
315
- traverse(ast, {
316
- // Handle re-exports: export * from './utils1'
317
- ExportAllDeclaration(path) {
318
- // Only follow re-exports if we haven't found the function yet
319
- if (result !== null)
320
- return;
321
- if (t.isStringLiteral(path.node.source)) {
322
- const reexportPath = path.node.source.value;
323
- const resolvedPath = resolveImportPath(filePath, reexportPath, parsingOptions, resolveImportPathCache);
324
- if (resolvedPath) {
325
- // Recursively resolve in the re-exported file
326
- const reexportResult = resolveFunctionInFile(resolvedPath, functionName, parsingOptions, warnings);
327
- if (reexportResult) {
328
- result = reexportResult;
329
- }
330
- }
331
- }
332
- },
333
- // Handle named re-exports: export { fn1 } from './utils'
334
- ExportNamedDeclaration(path) {
335
- // Only follow re-exports if we haven't found the function yet
336
- if (result !== null)
337
- return;
338
- // Check if this is a re-export with a source
339
- if (path.node.source && t.isStringLiteral(path.node.source)) {
340
- // Check if any of the exported specifiers match our function name
341
- const hasMatchingExport = path.node.specifiers.some((spec) => {
342
- if (t.isExportSpecifier(spec)) {
343
- const exportedName = t.isIdentifier(spec.exported)
344
- ? spec.exported.name
345
- : spec.exported.value;
346
- return exportedName === functionName;
347
- }
348
- return false;
349
- });
350
- if (hasMatchingExport) {
351
- const reexportPath = path.node.source.value;
352
- const resolvedPath = resolveImportPath(filePath, reexportPath, parsingOptions, resolveImportPathCache);
353
- if (resolvedPath) {
354
- // Find the original name in case it was renamed
355
- const specifier = path.node.specifiers.find((spec) => {
356
- if (t.isExportSpecifier(spec)) {
357
- const exportedName = t.isIdentifier(spec.exported)
358
- ? spec.exported.name
359
- : spec.exported.value;
360
- return exportedName === functionName;
361
- }
362
- return false;
363
- });
364
- let originalName = functionName;
365
- if (specifier &&
366
- t.isExportSpecifier(specifier) &&
367
- t.isIdentifier(specifier.local)) {
368
- originalName = specifier.local.name;
369
- }
370
- // Recursively resolve in the re-exported file
371
- const reexportResult = resolveFunctionInFile(resolvedPath, originalName, parsingOptions, warnings);
372
- if (reexportResult) {
373
- result = reexportResult;
374
- }
375
- }
376
- }
377
- }
378
- },
379
- // Handle function declarations: function interjection() { ... }
380
- FunctionDeclaration(path) {
381
- if (path.node.id?.name === functionName && result === null) {
382
- const branches = [];
383
- path.traverse({
384
- Function(innerPath) {
385
- // Skip nested functions
386
- innerPath.skip();
387
- },
388
- ReturnStatement(returnPath) {
389
- if (!t.isReturnStatement(returnPath.node)) {
390
- return;
391
- }
392
- const returnArg = returnPath.node.argument;
393
- if (!returnArg || !t.isExpression(returnArg)) {
394
- return;
395
- }
396
- const returnResult = parseStringExpression(returnArg, returnPath, filePath, parsingOptions, warnings);
397
- if (returnResult !== null) {
398
- branches.push(returnResult);
399
- }
400
- },
401
- });
402
- if (branches.length === 1) {
403
- result = branches[0];
404
- }
405
- else if (branches.length > 1) {
406
- result = { type: 'choice', nodes: branches };
407
- }
408
- }
409
- },
410
- // Handle variable declarations: const interjection = () => { ... }
411
- VariableDeclarator(path) {
412
- if (t.isIdentifier(path.node.id) &&
413
- path.node.id.name === functionName &&
414
- path.node.init &&
415
- (t.isArrowFunctionExpression(path.node.init) ||
416
- t.isFunctionExpression(path.node.init)) &&
417
- result === null) {
418
- const init = path.get('init');
419
- if (!init.isArrowFunctionExpression() &&
420
- !init.isFunctionExpression()) {
421
- return;
422
- }
423
- const bodyPath = init.get('body');
424
- const branches = [];
425
- // Handle expression body: () => "day"
426
- if (!Array.isArray(bodyPath) && t.isExpression(bodyPath.node)) {
427
- const bodyResult = parseStringExpression(bodyPath.node, bodyPath, filePath, parsingOptions, warnings);
428
- if (bodyResult !== null) {
429
- branches.push(bodyResult);
430
- }
431
- }
432
- // Handle block body: () => { return "day"; }
433
- else if (!Array.isArray(bodyPath) &&
434
- t.isBlockStatement(bodyPath.node)) {
435
- const arrowFunction = init.node;
436
- bodyPath.traverse({
437
- Function(innerPath) {
438
- // Skip nested functions
439
- innerPath.skip();
440
- },
441
- ReturnStatement(returnPath) {
442
- // Only process return statements that are direct children of this function
443
- const parentFunction = returnPath.getFunctionParent();
444
- if (parentFunction?.node !== arrowFunction) {
445
- return;
446
- }
447
- if (!t.isReturnStatement(returnPath.node)) {
448
- return;
449
- }
450
- const returnArg = returnPath.node.argument;
451
- if (!returnArg || !t.isExpression(returnArg)) {
452
- return;
453
- }
454
- const returnResult = parseStringExpression(returnArg, returnPath, filePath, parsingOptions, warnings);
455
- if (returnResult !== null) {
456
- branches.push(returnResult);
457
- }
458
- },
459
- });
460
- }
461
- if (branches.length === 1) {
462
- result = branches[0];
463
- }
464
- else if (branches.length > 1) {
465
- result = { type: 'choice', nodes: branches };
466
- }
467
- }
468
- },
469
- });
470
- }
471
- catch (error) {
472
- // File read or parse error - return null
473
- warnings.add(warnDeclareStaticNoResultsSync(filePath, functionName, 'file read/parse error: ' + error));
474
- result = null;
475
- }
476
- // Cache the result
477
- processFunctionCache.set(cacheKey, result);
478
- return result;
479
- }
480
- /**
481
- * Converts a Node tree to an array of all possible string combinations
482
- * This is a helper function for compatibility with existing code
483
- */
484
- export function nodeToStrings(node) {
485
- if (node === null) {
486
- return [];
487
- }
488
- // Handle TextNode
489
- if (typeof node === 'object' &&
490
- node !== null &&
491
- 'type' in node &&
492
- node.type === 'text') {
493
- return [node.text];
494
- }
495
- // Handle SequenceNode - concatenate all parts
496
- if (typeof node === 'object' &&
497
- node !== null &&
498
- 'type' in node &&
499
- node.type === 'sequence') {
500
- const partResults = node.nodes.map((n) => nodeToStrings(n));
501
- return cartesianProduct(partResults);
502
- }
503
- // Handle ChoiceNode - flatten all branches
504
- if (typeof node === 'object' &&
505
- node !== null &&
506
- 'type' in node &&
507
- node.type === 'choice') {
508
- const allStrings = [];
509
- for (const branch of node.nodes) {
510
- allStrings.push(...nodeToStrings(branch));
511
- }
512
- return [...new Set(allStrings)]; // Deduplicate
513
- }
514
- return [];
515
- }
516
- /**
517
- * Creates cartesian product of string arrays and concatenates them
518
- * @example cartesianProduct([["Hello "], ["day", "night"]]) → ["Hello day", "Hello night"]
519
- */
520
- function cartesianProduct(arrays) {
521
- if (arrays.length === 0) {
522
- return [];
523
- }
524
- if (arrays.length === 1) {
525
- return arrays[0];
526
- }
527
- // Start with first array
528
- let result = arrays[0];
529
- // Combine with each subsequent array
530
- for (let i = 1; i < arrays.length; i++) {
531
- const newResult = [];
532
- for (const prev of result) {
533
- for (const curr of arrays[i]) {
534
- newResult.push(prev + curr);
535
- }
536
- }
537
- result = newResult;
538
- }
539
- return result;
540
- }
@@ -1,30 +0,0 @@
1
- import { NodePath, Scope } from '@babel/traverse';
2
- import type { ParsingConfig, ParsingOutput } from './stringParsing/types.js';
3
- /**
4
- * Clears all caches. Useful for testing or when file system changes.
5
- */
6
- export declare function clearParsingCaches(): void;
7
- /**
8
- * Recursively resolves variable assignments to find all aliases of a translation callback parameter.
9
- * Handles cases like: const t = translate; const a = translate; const b = a; const c = b;
10
- *
11
- * @param scope The scope to search within
12
- * @param variableName The variable name to resolve
13
- * @param visited Set to track already visited variables to prevent infinite loops
14
- * @returns Array of all variable names that reference the original translation callback
15
- */
16
- export declare function resolveVariableAliases(scope: Scope, variableName: string, visited?: Set<string>): string[];
17
- /**
18
- * Main entry point for parsing translation strings from useGT() and getGT() calls.
19
- *
20
- * Supports complex patterns including:
21
- * 1. Direct calls: const t = useGT(); t('hello');
22
- * 2. Translation callback prop drilling: const t = useGT(); getInfo(t); where getInfo uses t() internally
23
- * 3. Cross-file function calls: imported functions that receive the translation callback as a parameter
24
- *
25
- * Example flow:
26
- * - const t = useGT();
27
- * - const { home } = getInfo(t); // getInfo is imported from './constants'
28
- * - This will parse constants.ts to find translation calls within getInfo function
29
- */
30
- export declare function parseStrings(importName: string, originalName: string, path: NodePath, config: ParsingConfig, output: ParsingOutput): void;