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,912 +0,0 @@
1
- import { randomUUID } from 'node:crypto';
2
- import generateModule from '@babel/generator';
3
- // Handle CommonJS/ESM interop
4
- const generate = generateModule.default || generateModule;
5
- import * as t from '@babel/types';
6
- import fs from 'node:fs';
7
- import { parse } from '@babel/parser';
8
- import addGTIdentifierToSyntaxTree from './addGTIdentifierToSyntaxTree.js';
9
- import { warnHasUnwrappedExpressionSync, warnNestedTComponent, warnFunctionNotFoundSync, warnMissingReturnSync, warnDuplicateFunctionDefinitionSync, warnInvalidStaticInitSync, warnRecursiveFunctionCallSync, } from '../../../../console/index.js';
10
- import { isAcceptedPluralForm } from 'generaltranslation/internal';
11
- import { isStaticExpression } from '../../evaluateJsx.js';
12
- import { STATIC_COMPONENT, TRANSLATION_COMPONENT, VARIABLE_COMPONENTS, } from '../constants.js';
13
- import { HTML_CONTENT_PROPS } from 'generaltranslation/types';
14
- import { resolveImportPath } from '../resolveImportPath.js';
15
- import traverseModule from '@babel/traverse';
16
- import { buildImportMap } from '../buildImportMap.js';
17
- import { getPathsAndAliases } from '../getPathsAndAliases.js';
18
- import { parseTProps } from './parseTProps.js';
19
- import { handleChildrenWhitespace } from './handleChildrenWhitespace.js';
20
- import { isElementNode } from './types.js';
21
- import { multiplyJsxTree } from './multiplication/multiplyJsxTree.js';
22
- import { removeNullChildrenFields } from './removeNullChildrenFields.js';
23
- import path from 'node:path';
24
- // Handle CommonJS/ESM interop
25
- const traverse = traverseModule.default || traverseModule;
26
- // TODO: currently we cover VariableDeclaration and FunctionDeclaration nodes, but are there others we should cover as well?
27
- /**
28
- * Cache for resolved import paths to avoid redundant I/O operations.
29
- * Key: `${currentFile}::${importPath}`
30
- * Value: resolved absolute path or null
31
- */
32
- const resolveImportPathCache = new Map();
33
- /**
34
- * Cache for processed functions to avoid re-parsing the same files.
35
- * Key: `${filePath}::${functionName}::${argIndex}`
36
- * Value: boolean indicating whether the function was found and processed
37
- */
38
- const processFunctionCache = new Map();
39
- /**
40
- * Entry point for JSX parsing
41
- */
42
- export function parseTranslationComponent({ originalName, localName, path, updates, config, output, }) {
43
- // First, collect all imports in this file to track cross-file function calls
44
- const importedFunctionsMap = buildImportMap(path.scope.getProgramParent().path);
45
- const referencePaths = path.scope.bindings[localName]?.referencePaths || [];
46
- for (const refPath of referencePaths) {
47
- // Only start at opening tag
48
- if (!t.isJSXOpeningElement(refPath.parent) ||
49
- !refPath.parentPath?.parentPath) {
50
- continue;
51
- }
52
- // Get the JSX element NodePath
53
- const jsxElementPath = refPath.parentPath
54
- ?.parentPath;
55
- // Parse <T> component
56
- parseJSXElement({
57
- scopeNode: jsxElementPath,
58
- node: jsxElementPath.node,
59
- originalName,
60
- updates,
61
- config,
62
- state: {
63
- visited: null,
64
- callStack: [],
65
- staticTracker: { isStatic: false },
66
- importedFunctionsMap,
67
- },
68
- output,
69
- });
70
- }
71
- }
72
- /**
73
- * Builds a JSX tree from a given node, recursively handling children.
74
- * @param node - The node to build the tree from
75
- * @param helperPath - NodePath for AST traversal
76
- * @param scopeNode - Scope node for binding resolution
77
- * @param insideT - Whether the current node is inside a <T> component
78
- * @param inStatic - Whether we're inside a Static component
79
- * @param config - Immutable configuration options
80
- * @param state - Mutable state tracking
81
- * @param output - Error/warning collectors
82
- * @returns The built JSX tree
83
- */
84
- function buildJSXTree({ node, helperPath, scopeNode, insideT, inStatic, config, state, output, }) {
85
- if (t.isJSXExpressionContainer(node)) {
86
- // Skip JSX comments
87
- if (t.isJSXEmptyExpression(node.expression)) {
88
- return null;
89
- }
90
- if (inStatic) {
91
- return processStaticExpression({
92
- config,
93
- state,
94
- output,
95
- expressionNodePath: helperPath.get('expression'),
96
- scopeNode,
97
- });
98
- }
99
- const expr = node.expression;
100
- if (t.isJSXElement(expr) || t.isJSXFragment(expr)) {
101
- return buildJSXTree({
102
- node: expr,
103
- insideT,
104
- inStatic,
105
- scopeNode,
106
- helperPath: helperPath.get('expression'),
107
- config,
108
- state,
109
- output,
110
- });
111
- }
112
- const staticAnalysis = isStaticExpression(expr, true);
113
- if (staticAnalysis.isStatic && staticAnalysis.value !== undefined) {
114
- // Preserve the exact whitespace for static string expressions
115
- return {
116
- nodeType: 'expression',
117
- result: staticAnalysis.value,
118
- };
119
- }
120
- // Keep existing behavior for non-static expressions
121
- const code = generate(node).code;
122
- output.unwrappedExpressions.push(code); // Keep track of unwrapped expressions for error reporting
123
- return code;
124
- }
125
- else if (t.isJSXText(node)) {
126
- // Updated JSX Text handling
127
- // JSX Text handling following React's rules
128
- const text = node.value;
129
- return text;
130
- }
131
- else if (t.isJSXElement(node)) {
132
- const element = node;
133
- const elementName = element.openingElement.name;
134
- let typeName;
135
- if (t.isJSXIdentifier(elementName)) {
136
- typeName = elementName.name;
137
- }
138
- else if (t.isJSXMemberExpression(elementName)) {
139
- typeName = generate(elementName).code;
140
- }
141
- else {
142
- typeName = null;
143
- }
144
- // Convert from alias to original name
145
- const componentType = config.importAliases[typeName ?? ''];
146
- if (componentType === TRANSLATION_COMPONENT && insideT) {
147
- // Add warning: Nested <T> components are allowed, but they are advised against
148
- output.warnings.add(warnNestedTComponent(config.file, `${element.loc?.start?.line}:${element.loc?.start?.column}`));
149
- }
150
- // If this JSXElement is one of the recognized variable components,
151
- const elementIsVariable = VARIABLE_COMPONENTS.includes(componentType);
152
- const props = {};
153
- const elementIsPlural = componentType === 'Plural';
154
- const elementIsBranch = componentType === 'Branch';
155
- element.openingElement.attributes.forEach((attr, index) => {
156
- const helperAttribute = helperPath
157
- .get('openingElement')
158
- .get('attributes')[index];
159
- if (t.isJSXAttribute(attr)) {
160
- const attrName = typeof attr.name.name === 'string'
161
- ? attr.name.name
162
- : attr.name.name.name;
163
- let attrValue = null;
164
- if (attr.value) {
165
- if (t.isStringLiteral(attr.value)) {
166
- attrValue = attr.value.value;
167
- }
168
- else if (t.isJSXExpressionContainer(attr.value)) {
169
- const helperValue = helperAttribute.get('value');
170
- // Check if this is an HTML content prop (title, placeholder, alt, etc.)
171
- const isHtmlContentProp = Object.values(HTML_CONTENT_PROPS).includes(attrName);
172
- // If its a plural or branch prop
173
- if ((elementIsPlural && isAcceptedPluralForm(attrName)) ||
174
- (elementIsBranch && attrName !== 'branch')) {
175
- // Make sure that variable strings like {`I have ${count} book`} are invalid!
176
- if (t.isTemplateLiteral(attr.value.expression) &&
177
- !isStaticExpression(attr.value.expression, true).isStatic) {
178
- output.unwrappedExpressions.push(generate(attr.value).code);
179
- }
180
- // If it's an array, flag as an unwrapped expression
181
- if (t.isArrayExpression(attr.value.expression)) {
182
- output.unwrappedExpressions.push(generate(attr.value.expression).code);
183
- }
184
- attrValue = buildJSXTree({
185
- node: attr.value,
186
- insideT: true,
187
- inStatic,
188
- scopeNode,
189
- helperPath: helperValue,
190
- config,
191
- state,
192
- output,
193
- });
194
- }
195
- // For HTML content props, only accept static string expressions
196
- else if (isHtmlContentProp) {
197
- const staticAnalysis = isStaticExpression(attr.value.expression, true);
198
- if (staticAnalysis.isStatic &&
199
- staticAnalysis.value !== undefined) {
200
- attrValue = staticAnalysis.value;
201
- }
202
- // Otherwise attrValue stays null and won't be included
203
- }
204
- }
205
- }
206
- props[attrName] = attrValue;
207
- }
208
- });
209
- if (elementIsVariable) {
210
- if (componentType === STATIC_COMPONENT) {
211
- const helperElement = helperPath.get('children');
212
- const results = {
213
- nodeType: 'element',
214
- type: STATIC_COMPONENT,
215
- props,
216
- };
217
- // Create children array if necessary
218
- const childrenArray = [];
219
- if (state.visited === null) {
220
- state.visited = new Set();
221
- }
222
- for (let index = 0; index < element.children.length; index++) {
223
- const helperChild = helperElement[index];
224
- const result = buildJSXTree({
225
- node: helperChild.node,
226
- insideT: true,
227
- inStatic: true,
228
- scopeNode,
229
- helperPath: helperChild,
230
- config,
231
- state,
232
- output,
233
- });
234
- childrenArray.push(result);
235
- }
236
- if (childrenArray.length) {
237
- results.props.children = childrenArray;
238
- }
239
- return results;
240
- }
241
- return {
242
- nodeType: 'element',
243
- // if componentType is undefined, use typeName
244
- // Basically, if componentType is not a GT component, use typeName such as <div>
245
- type: componentType ?? typeName ?? '',
246
- props,
247
- };
248
- }
249
- const children = element.children
250
- .map((child, index) => buildJSXTree({
251
- node: child,
252
- insideT: true,
253
- inStatic,
254
- scopeNode,
255
- helperPath: helperPath.get('children')[index],
256
- config,
257
- state,
258
- output,
259
- }))
260
- .filter((child) => child !== null && child !== '');
261
- if (children.length === 1) {
262
- props.children = children[0];
263
- }
264
- else if (children.length > 1) {
265
- props.children = children;
266
- }
267
- return {
268
- nodeType: 'element',
269
- // if componentType is undefined, use typeName
270
- // Basically, if componentType is not a GT component, use typeName such as <div>
271
- type: componentType ?? typeName,
272
- props,
273
- };
274
- }
275
- // If it's a JSX fragment
276
- else if (t.isJSXFragment(node)) {
277
- const children = node.children
278
- .map((child, index) => buildJSXTree({
279
- node: child,
280
- insideT: true,
281
- inStatic,
282
- scopeNode,
283
- helperPath: helperPath.get('children')[index],
284
- config,
285
- state,
286
- output,
287
- }))
288
- .filter((child) => child !== null && child !== '');
289
- const props = {};
290
- if (children.length === 1) {
291
- props.children = children[0];
292
- }
293
- else if (children.length > 1) {
294
- props.children = children;
295
- }
296
- return {
297
- nodeType: 'element',
298
- type: '',
299
- props,
300
- };
301
- }
302
- // If it's a string literal (standalone)
303
- else if (t.isStringLiteral(node)) {
304
- return node.value;
305
- }
306
- // If it's a template literal
307
- else if (t.isTemplateLiteral(node)) {
308
- // We've already checked that it's static, and and added a warning if it's not, this check is just for fallback behavior
309
- if (!isStaticExpression(node, true).isStatic ||
310
- node.quasis[0].value.cooked === undefined) {
311
- return generate(node).code;
312
- }
313
- return node.quasis[0].value.cooked;
314
- }
315
- else if (t.isNullLiteral(node)) {
316
- // If it's null, return null
317
- return null;
318
- }
319
- else if (t.isBooleanLiteral(node)) {
320
- // If it's a boolean, return the boolean
321
- return node.value;
322
- }
323
- else if (t.isNumericLiteral(node)) {
324
- // If it's a number, return the number
325
- return node.value.toString();
326
- }
327
- // Negative
328
- else if (t.isUnaryExpression(node)) {
329
- // If it's a unary expression, return the expression
330
- const staticAnalysis = isStaticExpression(node, true);
331
- if (staticAnalysis.isStatic && staticAnalysis.value !== undefined) {
332
- return staticAnalysis.value;
333
- }
334
- return generate(node).code;
335
- }
336
- else if ((t.isCallExpression(node) && t.isIdentifier(node.callee)) ||
337
- (t.isAwaitExpression(node) &&
338
- t.isCallExpression(node.argument) &&
339
- t.isIdentifier(node.argument.callee))) {
340
- if (inStatic) {
341
- const callExpression = (node.type === 'AwaitExpression' ? node.argument : node);
342
- const callee = callExpression.callee;
343
- const calleeBinding = scopeNode.scope.getBinding(callee.name);
344
- if (!calleeBinding) {
345
- output.warnings.add(warnFunctionNotFoundSync(config.file, callee.name, `${callee.loc?.start?.line}:${callee.loc?.start?.column}`));
346
- return null;
347
- }
348
- return resolveStaticFunctionInvocationFromBinding({
349
- calleeBinding,
350
- callee,
351
- config,
352
- state,
353
- output,
354
- });
355
- }
356
- else {
357
- output.unwrappedExpressions.push(generate(node).code);
358
- }
359
- }
360
- else if (t.isParenthesizedExpression(node)) {
361
- const child = node.expression;
362
- return buildJSXTree({
363
- node: child,
364
- insideT,
365
- inStatic,
366
- scopeNode,
367
- helperPath: helperPath.get('expression'),
368
- config,
369
- state,
370
- output,
371
- });
372
- }
373
- // If it's some other JS expression
374
- else if (t.isIdentifier(node) ||
375
- t.isMemberExpression(node) ||
376
- t.isCallExpression(node) ||
377
- t.isBinaryExpression(node) ||
378
- t.isLogicalExpression(node) ||
379
- t.isConditionalExpression(node)) {
380
- output.unwrappedExpressions.push(generate(node).code);
381
- }
382
- else {
383
- if (node === undefined || node === null) {
384
- output.unwrappedExpressions.push(String(node));
385
- }
386
- else {
387
- output.unwrappedExpressions.push(generate(node).code);
388
- }
389
- }
390
- return null;
391
- }
392
- // end buildJSXTree
393
- // Parses a JSX element and adds it to the updates array
394
- function parseJSXElement({ node, originalName, scopeNode, updates, config, state, output, }) {
395
- const openingElement = node.openingElement;
396
- const name = openingElement.name;
397
- // Only proceed if it's <T> ...
398
- // TODO: i don't think this condition is needed anymore
399
- if (!(name.type === 'JSXIdentifier' && originalName === TRANSLATION_COMPONENT)) {
400
- return;
401
- }
402
- const componentErrors = [];
403
- const componentWarnings = new Set();
404
- const metadata = {};
405
- const relativeFilepath = path.relative(process.cwd(), config.file);
406
- metadata.filePaths = [relativeFilepath];
407
- // We'll track this flag to know if any unwrapped {variable} is found in children
408
- const unwrappedExpressions = [];
409
- // Gather <T>'s props
410
- parseTProps({
411
- openingElement,
412
- metadata,
413
- componentErrors,
414
- file: config.file,
415
- });
416
- // Flag for if contains static content
417
- const staticTracker = {
418
- isStatic: false,
419
- };
420
- // Build the JSX tree for this component
421
- const treeResult = buildJSXTree({
422
- node,
423
- scopeNode,
424
- insideT: false,
425
- inStatic: false,
426
- helperPath: scopeNode,
427
- config,
428
- state: {
429
- visited: null,
430
- callStack: [],
431
- staticTracker,
432
- importedFunctionsMap: state.importedFunctionsMap,
433
- },
434
- output: {
435
- unwrappedExpressions,
436
- errors: componentErrors,
437
- warnings: componentWarnings,
438
- },
439
- });
440
- // Strip the outer <T> component if necessary
441
- const jsxTree = isElementNode(treeResult) && treeResult.props?.children
442
- ? // We know this b/c the direct children of <T> will never be a multiplication node
443
- treeResult.props.children
444
- : treeResult;
445
- // Update warnings
446
- if (componentWarnings.size > 0) {
447
- componentWarnings.forEach((warning) => output.warnings.add(warning));
448
- }
449
- // Update errors
450
- if (componentErrors.length > 0) {
451
- output.errors.push(...componentErrors);
452
- return;
453
- }
454
- // Handle whitespace in children
455
- const whitespaceHandledTree = handleChildrenWhitespace(jsxTree);
456
- // Multiply the tree
457
- const multipliedTrees = multiplyJsxTree(whitespaceHandledTree);
458
- // Add GT identifiers to the tree
459
- // TODO: do this in parallel
460
- const minifiedTress = [];
461
- for (const multipliedTree of multipliedTrees) {
462
- const minifiedTree = addGTIdentifierToSyntaxTree(multipliedTree);
463
- minifiedTress.push(Array.isArray(minifiedTree) && minifiedTree.length === 1
464
- ? minifiedTree[0]
465
- : minifiedTree);
466
- }
467
- // If we found an unwrapped expression, skip
468
- if (unwrappedExpressions.length > 0) {
469
- output.errors.push(warnHasUnwrappedExpressionSync(config.file, unwrappedExpressions, metadata.id, `${node.loc?.start?.line}:${node.loc?.start?.column}`));
470
- return;
471
- }
472
- // Create a temporary unique flag for static content
473
- const temporaryStaticId = `static-temp-id-${randomUUID()}`;
474
- const isStatic = staticTracker.isStatic;
475
- // <T> is valid here
476
- for (const minifiedTree of minifiedTress) {
477
- // Clean the tree by removing null 'c' fields from JsxElements
478
- const cleanedTree = removeNullChildrenFields(minifiedTree);
479
- updates.push({
480
- dataFormat: 'JSX',
481
- source: cleanedTree,
482
- metadata: {
483
- // eslint-disable-next-line no-undef
484
- ...structuredClone(metadata),
485
- ...(isStatic && { staticId: temporaryStaticId }),
486
- },
487
- });
488
- }
489
- }
490
- function resolveStaticFunctionInvocationFromBinding({ calleeBinding, callee, config, state, output, }) {
491
- function withRecusionGuard({ cb, filename, functionName, }) {
492
- const cacheKey = `${filename}::${functionName}`;
493
- if (state.callStack.includes(cacheKey)) {
494
- output.errors.push(warnRecursiveFunctionCallSync(config.file, functionName));
495
- return null;
496
- }
497
- state.callStack.push(cacheKey);
498
- const result = cb();
499
- state.callStack.pop();
500
- return result;
501
- }
502
- // check for recursive calls
503
- if (calleeBinding.path.isFunctionDeclaration()) {
504
- // Handle function declarations: function getSubject() { ... }
505
- const functionName = callee.name;
506
- const path = calleeBinding.path;
507
- return withRecusionGuard({
508
- filename: config.file,
509
- functionName,
510
- cb: () => processFunctionDeclarationNodePath({
511
- config,
512
- state,
513
- output,
514
- path,
515
- }),
516
- });
517
- }
518
- else if (calleeBinding.path.isVariableDeclarator() &&
519
- calleeBinding.path.node.init &&
520
- (t.isArrowFunctionExpression(calleeBinding.path.node.init) ||
521
- t.isFunctionExpression(calleeBinding.path.node.init))) {
522
- // Handle arrow functions assigned to variables: const getData = (t) => {...}
523
- const functionName = callee.name;
524
- const path = calleeBinding.path;
525
- return withRecusionGuard({
526
- filename: config.file,
527
- functionName,
528
- cb: () => processVariableDeclarationNodePath({
529
- config,
530
- state,
531
- output,
532
- functionName,
533
- path,
534
- }),
535
- });
536
- }
537
- else if (state.importedFunctionsMap.has(callee.name)) {
538
- // Get the original function name
539
- let originalName;
540
- if (calleeBinding.path.isImportSpecifier()) {
541
- originalName = t.isIdentifier(calleeBinding.path.node.imported)
542
- ? calleeBinding.path.node.imported.name
543
- : calleeBinding.path.node.imported.value;
544
- }
545
- else if (calleeBinding.path.isImportDefaultSpecifier()) {
546
- originalName = calleeBinding.path.node.local.name;
547
- }
548
- else if (calleeBinding.path.isImportNamespaceSpecifier()) {
549
- originalName = calleeBinding.path.node.local.name;
550
- }
551
- // Function is being imported
552
- const importPath = state.importedFunctionsMap.get(callee.name);
553
- const filePath = resolveImportPath(config.file, importPath, config.parsingOptions, resolveImportPathCache);
554
- if (filePath && originalName) {
555
- const result = withRecusionGuard({
556
- filename: filePath,
557
- functionName: originalName,
558
- cb: () => processFunctionInFile({
559
- config,
560
- state,
561
- output,
562
- filePath,
563
- functionName: originalName,
564
- }),
565
- });
566
- if (result !== null) {
567
- return result;
568
- }
569
- }
570
- }
571
- output.warnings.add(warnFunctionNotFoundSync(config.file, callee.name, `${callee.loc?.start?.line}:${callee.loc?.start?.column}`));
572
- return null;
573
- }
574
- /**
575
- * Searches for a specific user-defined function in a file.
576
- * This is the resolution logic
577
- *
578
- * Handles multiple function declaration patterns:
579
- * - function getInfo() { ... }
580
- * - export function getInfo() { ... }
581
- * - const getInfo = () => { ... }
582
- *
583
- * If the function is not found in the file, follows re-exports (export * from './other')
584
- */
585
- function processFunctionInFile({ config, state, output, filePath, functionName, }) {
586
- // Create a custom key for the function call
587
- const cacheKey = `${filePath}::${functionName}`;
588
- // Check cache first to avoid redundant parsing
589
- if (processFunctionCache.has(cacheKey)) {
590
- return processFunctionCache.get(cacheKey) ?? null;
591
- }
592
- // Prevent infinite loops from circular re-exports
593
- if (state.visited && state.visited.has(filePath)) {
594
- return null;
595
- }
596
- if (state.visited) {
597
- state.visited.add(filePath);
598
- }
599
- let result = undefined;
600
- try {
601
- const code = fs.readFileSync(filePath, 'utf8');
602
- const ast = parse(code, {
603
- sourceType: 'module',
604
- plugins: ['jsx', 'typescript'],
605
- });
606
- const { importAliases } = getPathsAndAliases(ast, config.pkgs);
607
- // Collect all imports in this file to track cross-file function calls
608
- let importedFunctionsMap = new Map();
609
- traverse(ast, {
610
- Program(path) {
611
- importedFunctionsMap = buildImportMap(path);
612
- },
613
- });
614
- const reExports = [];
615
- const warnDuplicateFuncDef = (path) => {
616
- output.warnings.add(warnDuplicateFunctionDefinitionSync(filePath, functionName, `${path.node.loc?.start?.line}:${path.node.loc?.start?.column}`));
617
- };
618
- traverse(ast, {
619
- // Handle function declarations: function getInfo() { ... }
620
- FunctionDeclaration(path) {
621
- if (path.node.id?.name === functionName) {
622
- if (result !== undefined)
623
- return warnDuplicateFuncDef(path);
624
- result = processFunctionDeclarationNodePath({
625
- config: {
626
- importAliases,
627
- parsingOptions: config.parsingOptions,
628
- pkgs: config.pkgs,
629
- file: filePath,
630
- },
631
- state: {
632
- ...state,
633
- importedFunctionsMap,
634
- },
635
- output,
636
- path,
637
- });
638
- }
639
- },
640
- // Handle variable declarations: const getInfo = () => { ... }
641
- VariableDeclarator(path) {
642
- if (t.isIdentifier(path.node.id) &&
643
- path.node.id.name === functionName &&
644
- path.node.init &&
645
- (t.isArrowFunctionExpression(path.node.init) ||
646
- t.isFunctionExpression(path.node.init))) {
647
- if (result !== undefined)
648
- return warnDuplicateFuncDef(path);
649
- result = processVariableDeclarationNodePath({
650
- config: {
651
- importAliases,
652
- parsingOptions: config.parsingOptions,
653
- pkgs: config.pkgs,
654
- file: filePath,
655
- },
656
- state: {
657
- ...state,
658
- importedFunctionsMap,
659
- },
660
- output,
661
- functionName,
662
- path,
663
- });
664
- }
665
- },
666
- // Collect re-exports: export * from './other'
667
- ExportAllDeclaration(path) {
668
- if (t.isStringLiteral(path.node.source)) {
669
- reExports.push(path.node.source.value);
670
- }
671
- },
672
- // Collect named re-exports: export { foo } from './other'
673
- ExportNamedDeclaration(path) {
674
- if (path.node.source && t.isStringLiteral(path.node.source)) {
675
- // Check if this export includes our function
676
- const exportsFunction = path.node.specifiers.some((spec) => {
677
- if (t.isExportSpecifier(spec)) {
678
- const exportedName = t.isIdentifier(spec.exported)
679
- ? spec.exported.name
680
- : spec.exported.value;
681
- return exportedName === functionName;
682
- }
683
- return false;
684
- });
685
- if (exportsFunction) {
686
- reExports.push(path.node.source.value);
687
- }
688
- }
689
- },
690
- });
691
- // If function not found, follow re-exports
692
- if (result === undefined && reExports.length > 0) {
693
- for (const reExportPath of reExports) {
694
- const resolvedPath = resolveImportPath(filePath, reExportPath, config.parsingOptions, resolveImportPathCache);
695
- if (resolvedPath) {
696
- const foundResult = processFunctionInFile({
697
- config: {
698
- importAliases,
699
- parsingOptions: config.parsingOptions,
700
- pkgs: config.pkgs,
701
- file: filePath,
702
- },
703
- state: {
704
- ...state,
705
- importedFunctionsMap,
706
- },
707
- output,
708
- filePath: resolvedPath,
709
- functionName,
710
- });
711
- if (foundResult != null) {
712
- result = foundResult;
713
- break;
714
- }
715
- }
716
- }
717
- }
718
- // Mark this function search as processed in the cache
719
- processFunctionCache.set(cacheKey, result !== undefined ? result : null);
720
- }
721
- catch {
722
- // Silently skip files that can't be parsed or accessed
723
- // Still mark as processed to avoid retrying failed parses
724
- processFunctionCache.set(cacheKey, null);
725
- }
726
- return result !== undefined ? result : null;
727
- }
728
- /**
729
- * Process a function declaration
730
- * function getInfo() { ... }
731
- */
732
- function processFunctionDeclarationNodePath({ config, state, output, path, }) {
733
- const result = {
734
- nodeType: 'multiplication',
735
- branches: [],
736
- };
737
- path.traverse({
738
- Function(path) {
739
- path.skip();
740
- },
741
- ReturnStatement(returnPath) {
742
- const returnNodePath = returnPath.get('argument');
743
- if (!returnNodePath.isExpression()) {
744
- return;
745
- }
746
- result.branches.push(processStaticExpression({
747
- config,
748
- state,
749
- output,
750
- expressionNodePath: returnNodePath,
751
- scopeNode: returnPath,
752
- }));
753
- },
754
- });
755
- if (result.branches.length === 0) {
756
- return null;
757
- }
758
- return result;
759
- }
760
- /**
761
- * Process a variable declaration of a function
762
- * const getInfo = () => { ... }
763
- *
764
- * IMPORTANT: the RHand value must be the function definition, or this will fail
765
- */
766
- function processVariableDeclarationNodePath({ config, state, output, functionName, path, }) {
767
- const result = {
768
- nodeType: 'multiplication',
769
- branches: [],
770
- };
771
- // Enforce the Rhand is a function definition
772
- const arrowFunctionPath = path.get('init');
773
- if (!arrowFunctionPath.isArrowFunctionExpression()) {
774
- output.errors.push(warnInvalidStaticInitSync(config.file, functionName, `${path.node.loc?.start?.line}:${path.node.loc?.start?.column}`));
775
- return null;
776
- }
777
- const bodyNodePath = arrowFunctionPath.get('body');
778
- if (bodyNodePath.isExpression()) {
779
- // process expression return
780
- result.branches.push(processStaticExpression({
781
- config,
782
- state,
783
- output,
784
- expressionNodePath: bodyNodePath,
785
- scopeNode: arrowFunctionPath,
786
- }));
787
- }
788
- else {
789
- // search for a return statement
790
- bodyNodePath.traverse({
791
- Function(path) {
792
- path.skip();
793
- },
794
- ReturnStatement(returnPath) {
795
- const returnNodePath = returnPath.get('argument');
796
- if (!returnNodePath.isExpression()) {
797
- return;
798
- }
799
- result.branches.push(processStaticExpression({
800
- config,
801
- state,
802
- output,
803
- expressionNodePath: returnNodePath,
804
- scopeNode: returnPath,
805
- }));
806
- },
807
- });
808
- }
809
- if (result.branches.length === 0) {
810
- output.errors.push(warnMissingReturnSync(config.file, functionName, `${path.node.loc?.start?.line}:${path.node.loc?.start?.column}`));
811
- return null;
812
- }
813
- return result;
814
- }
815
- /**
816
- * Process a <Static> expression
817
- */
818
- function processStaticExpression({ config, state, output, expressionNodePath, scopeNode, }) {
819
- // Mark the static tracker as true
820
- state.staticTracker.isStatic = true;
821
- // Remove parentheses if they exist
822
- if (t.isParenthesizedExpression(expressionNodePath.node)) {
823
- // ex: return (value)
824
- return processStaticExpression({
825
- config,
826
- state,
827
- output,
828
- scopeNode,
829
- expressionNodePath: expressionNodePath.get('expression'),
830
- });
831
- }
832
- else if (t.isCallExpression(expressionNodePath.node) &&
833
- t.isIdentifier(expressionNodePath.node.callee)) {
834
- // ex: return someFunc()
835
- const callee = expressionNodePath.node.callee;
836
- const calleeBinding = scopeNode.scope.getBinding(callee.name);
837
- if (!calleeBinding) {
838
- output.warnings.add(warnFunctionNotFoundSync(config.file, callee.name, `${callee.loc?.start?.line}:${callee.loc?.start?.column}`));
839
- return null;
840
- }
841
- // Function is found
842
- return resolveStaticFunctionInvocationFromBinding({
843
- calleeBinding,
844
- callee,
845
- config,
846
- state,
847
- output,
848
- });
849
- }
850
- else if (t.isAwaitExpression(expressionNodePath.node) &&
851
- t.isCallExpression(expressionNodePath.node.argument) &&
852
- t.isIdentifier(expressionNodePath.node.argument.callee)) {
853
- // ex: return await someFunc()
854
- const callee = expressionNodePath.node.argument.callee;
855
- const calleeBinding = scopeNode.scope.getBinding(callee.name);
856
- if (!calleeBinding) {
857
- output.warnings.add(warnFunctionNotFoundSync(config.file, callee.name, `${callee.loc?.start?.line}:${callee.loc?.start?.column}`));
858
- return null;
859
- }
860
- // Function is found
861
- return resolveStaticFunctionInvocationFromBinding({
862
- calleeBinding,
863
- callee,
864
- config,
865
- state,
866
- output,
867
- });
868
- }
869
- else if (t.isJSXElement(expressionNodePath.node) ||
870
- t.isJSXFragment(expressionNodePath.node)) {
871
- // ex: return <div>Jsx content</div>
872
- return buildJSXTree({
873
- node: expressionNodePath.node,
874
- helperPath: expressionNodePath,
875
- scopeNode,
876
- insideT: true,
877
- inStatic: true,
878
- config,
879
- state,
880
- output,
881
- });
882
- }
883
- else if (t.isConditionalExpression(expressionNodePath.node)) {
884
- // ex: return condition ? <div>Jsx content</div> : <div>Jsx content</div>
885
- // since two options here we must construct a new multiplication node
886
- const consequentNodePath = expressionNodePath.get('consequent');
887
- const alternateNodePath = expressionNodePath.get('alternate');
888
- const result = {
889
- nodeType: 'multiplication',
890
- branches: [consequentNodePath, alternateNodePath].map((expressionNodePath) => processStaticExpression({
891
- config,
892
- state,
893
- output,
894
- scopeNode,
895
- expressionNodePath,
896
- })),
897
- };
898
- return result;
899
- }
900
- else {
901
- return buildJSXTree({
902
- node: expressionNodePath.node,
903
- helperPath: expressionNodePath,
904
- scopeNode,
905
- insideT: true,
906
- inStatic: true,
907
- config,
908
- state,
909
- output,
910
- });
911
- }
912
- }