@weglot/translate-react 0.0.0-stage → 0.1.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 (292) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +6 -0
  3. package/README.md +190 -2
  4. package/build/_virtual/rolldown_runtime.cjs +29 -0
  5. package/build/_virtual/rolldown_runtime.mjs +7 -0
  6. package/build/index.cjs +0 -0
  7. package/build/index.d.cts +2 -0
  8. package/build/index.d.mts +2 -0
  9. package/build/index.mjs +1 -0
  10. package/build/locale.d.cts +6 -0
  11. package/build/locale.d.cts.map +1 -0
  12. package/build/locale.d.mts +6 -0
  13. package/build/locale.d.mts.map +1 -0
  14. package/build/metadata/manager.cjs +119 -0
  15. package/build/metadata/manager.mjs +114 -0
  16. package/build/metadata/manager.mjs.map +1 -0
  17. package/build/plugin/build-translator.cjs +207 -0
  18. package/build/plugin/build-translator.mjs +205 -0
  19. package/build/plugin/build-translator.mjs.map +1 -0
  20. package/build/plugin/cleanup.cjs +20 -0
  21. package/build/plugin/cleanup.mjs +20 -0
  22. package/build/plugin/cleanup.mjs.map +1 -0
  23. package/build/plugin/index.cjs +0 -0
  24. package/build/plugin/index.d.cts +2 -0
  25. package/build/plugin/index.d.mts +2 -0
  26. package/build/plugin/index.mjs +1 -0
  27. package/build/plugin/next-compiler-loader.cjs +40 -0
  28. package/build/plugin/next-compiler-loader.d.cts +12 -0
  29. package/build/plugin/next-compiler-loader.d.cts.map +1 -0
  30. package/build/plugin/next-compiler-loader.d.mts +13 -0
  31. package/build/plugin/next-compiler-loader.d.mts.map +1 -0
  32. package/build/plugin/next-compiler-loader.mjs +41 -0
  33. package/build/plugin/next-compiler-loader.mjs.map +1 -0
  34. package/build/plugin/next-config-loader.cjs +13 -0
  35. package/build/plugin/next-config-loader.d.cts +8 -0
  36. package/build/plugin/next-config-loader.d.cts.map +1 -0
  37. package/build/plugin/next-config-loader.d.mts +9 -0
  38. package/build/plugin/next-config-loader.d.mts.map +1 -0
  39. package/build/plugin/next-config-loader.mjs +14 -0
  40. package/build/plugin/next-config-loader.mjs.map +1 -0
  41. package/build/plugin/next-locale-client-loader.cjs +9 -0
  42. package/build/plugin/next-locale-client-loader.d.cts +8 -0
  43. package/build/plugin/next-locale-client-loader.d.cts.map +1 -0
  44. package/build/plugin/next-locale-client-loader.d.mts +9 -0
  45. package/build/plugin/next-locale-client-loader.d.mts.map +1 -0
  46. package/build/plugin/next-locale-client-loader.mjs +10 -0
  47. package/build/plugin/next-locale-client-loader.mjs.map +1 -0
  48. package/build/plugin/next-locale-server-loader.cjs +9 -0
  49. package/build/plugin/next-locale-server-loader.d.cts +8 -0
  50. package/build/plugin/next-locale-server-loader.d.cts.map +1 -0
  51. package/build/plugin/next-locale-server-loader.d.mts +9 -0
  52. package/build/plugin/next-locale-server-loader.d.mts.map +1 -0
  53. package/build/plugin/next-locale-server-loader.mjs +10 -0
  54. package/build/plugin/next-locale-server-loader.mjs.map +1 -0
  55. package/build/plugin/next.cjs +226 -0
  56. package/build/plugin/next.d.cts +9 -0
  57. package/build/plugin/next.d.cts.map +1 -0
  58. package/build/plugin/next.d.mts +9 -0
  59. package/build/plugin/next.d.mts.map +1 -0
  60. package/build/plugin/next.mjs +228 -0
  61. package/build/plugin/next.mjs.map +1 -0
  62. package/build/plugin/transform/babel-compat.cjs +13 -0
  63. package/build/plugin/transform/babel-compat.mjs +10 -0
  64. package/build/plugin/transform/babel-compat.mjs.map +1 -0
  65. package/build/plugin/transform/expression-strings.cjs +145 -0
  66. package/build/plugin/transform/expression-strings.mjs +140 -0
  67. package/build/plugin/transform/expression-strings.mjs.map +1 -0
  68. package/build/plugin/transform/index.cjs +45 -0
  69. package/build/plugin/transform/index.mjs +43 -0
  70. package/build/plugin/transform/index.mjs.map +1 -0
  71. package/build/plugin/transform/metadata.cjs +142 -0
  72. package/build/plugin/transform/metadata.mjs +141 -0
  73. package/build/plugin/transform/metadata.mjs.map +1 -0
  74. package/build/plugin/transform/process-file.cjs +525 -0
  75. package/build/plugin/transform/process-file.mjs +524 -0
  76. package/build/plugin/transform/process-file.mjs.map +1 -0
  77. package/build/plugin/transform/use-i18n.cjs +8 -0
  78. package/build/plugin/transform/use-i18n.mjs +7 -0
  79. package/build/plugin/transform/use-i18n.mjs.map +1 -0
  80. package/build/plugin/transform/utils.cjs +237 -0
  81. package/build/plugin/transform/utils.mjs +219 -0
  82. package/build/plugin/transform/utils.mjs.map +1 -0
  83. package/build/plugin/unplugin.cjs +188 -0
  84. package/build/plugin/unplugin.d.cts +8 -0
  85. package/build/plugin/unplugin.d.cts.map +1 -0
  86. package/build/plugin/unplugin.d.mts +8 -0
  87. package/build/plugin/unplugin.d.mts.map +1 -0
  88. package/build/plugin/unplugin.mjs +188 -0
  89. package/build/plugin/unplugin.mjs.map +1 -0
  90. package/build/plugin/vite.cjs +27 -0
  91. package/build/plugin/vite.d.cts +9 -0
  92. package/build/plugin/vite.d.cts.map +1 -0
  93. package/build/plugin/vite.d.mts +9 -0
  94. package/build/plugin/vite.d.mts.map +1 -0
  95. package/build/plugin/vite.mjs +28 -0
  96. package/build/plugin/vite.mjs.map +1 -0
  97. package/build/plugin/webpack.cjs +26 -0
  98. package/build/plugin/webpack.d.cts +8 -0
  99. package/build/plugin/webpack.d.cts.map +1 -0
  100. package/build/plugin/webpack.d.mts +8 -0
  101. package/build/plugin/webpack.d.mts.map +1 -0
  102. package/build/plugin/webpack.mjs +27 -0
  103. package/build/plugin/webpack.mjs.map +1 -0
  104. package/build/react/client/index.cjs +9 -0
  105. package/build/react/client/index.d.cts +5 -0
  106. package/build/react/client/index.d.mts +5 -0
  107. package/build/react/client/index.mjs +6 -0
  108. package/build/react/client/useTranslation.cjs +71 -0
  109. package/build/react/client/useTranslation.d.cts +42 -0
  110. package/build/react/client/useTranslation.d.cts.map +1 -0
  111. package/build/react/client/useTranslation.d.mts +42 -0
  112. package/build/react/client/useTranslation.d.mts.map +1 -0
  113. package/build/react/client/useTranslation.mjs +71 -0
  114. package/build/react/client/useTranslation.mjs.map +1 -0
  115. package/build/react/next/client.cjs +25 -0
  116. package/build/react/next/client.d.cts +9 -0
  117. package/build/react/next/client.d.cts.map +1 -0
  118. package/build/react/next/client.d.mts +9 -0
  119. package/build/react/next/client.d.mts.map +1 -0
  120. package/build/react/next/client.mjs +24 -0
  121. package/build/react/next/client.mjs.map +1 -0
  122. package/build/react/next/cookie-locale-resolver.cjs +29 -0
  123. package/build/react/next/cookie-locale-resolver.d.cts +33 -0
  124. package/build/react/next/cookie-locale-resolver.d.cts.map +1 -0
  125. package/build/react/next/cookie-locale-resolver.d.mts +33 -0
  126. package/build/react/next/cookie-locale-resolver.d.mts.map +1 -0
  127. package/build/react/next/cookie-locale-resolver.mjs +29 -0
  128. package/build/react/next/cookie-locale-resolver.mjs.map +1 -0
  129. package/build/react/next/server.cjs +21 -0
  130. package/build/react/next/server.d.cts +13 -0
  131. package/build/react/next/server.d.cts.map +1 -0
  132. package/build/react/next/server.d.mts +14 -0
  133. package/build/react/next/server.d.mts.map +1 -0
  134. package/build/react/next/server.mjs +20 -0
  135. package/build/react/next/server.mjs.map +1 -0
  136. package/build/react/server/ServerWeglotProvider.cjs +19 -0
  137. package/build/react/server/ServerWeglotProvider.d.cts +12 -0
  138. package/build/react/server/ServerWeglotProvider.d.cts.map +1 -0
  139. package/build/react/server/ServerWeglotProvider.d.mts +12 -0
  140. package/build/react/server/ServerWeglotProvider.d.mts.map +1 -0
  141. package/build/react/server/ServerWeglotProvider.mjs +19 -0
  142. package/build/react/server/ServerWeglotProvider.mjs.map +1 -0
  143. package/build/react/server/index.cjs +7 -0
  144. package/build/react/server/index.d.cts +4 -0
  145. package/build/react/server/index.d.mts +4 -0
  146. package/build/react/server/index.mjs +5 -0
  147. package/build/react/server/useTranslation.cjs +60 -0
  148. package/build/react/server/useTranslation.d.cts +36 -0
  149. package/build/react/server/useTranslation.d.cts.map +1 -0
  150. package/build/react/server/useTranslation.d.mts +36 -0
  151. package/build/react/server/useTranslation.d.mts.map +1 -0
  152. package/build/react/server/useTranslation.mjs +60 -0
  153. package/build/react/server/useTranslation.mjs.map +1 -0
  154. package/build/react/server-only/index.cjs +42 -0
  155. package/build/react/server-only/index.d.cts +38 -0
  156. package/build/react/server-only/index.d.cts.map +1 -0
  157. package/build/react/server-only/index.d.mts +38 -0
  158. package/build/react/server-only/index.d.mts.map +1 -0
  159. package/build/react/server-only/index.mjs +42 -0
  160. package/build/react/server-only/index.mjs.map +1 -0
  161. package/build/react/server-only/translations.cjs +86 -0
  162. package/build/react/server-only/translations.mjs +86 -0
  163. package/build/react/server-only/translations.mjs.map +1 -0
  164. package/build/react/shared/LocaleSwitcher.cjs +61 -0
  165. package/build/react/shared/LocaleSwitcher.d.cts +71 -0
  166. package/build/react/shared/LocaleSwitcher.d.cts.map +1 -0
  167. package/build/react/shared/LocaleSwitcher.d.mts +71 -0
  168. package/build/react/shared/LocaleSwitcher.d.mts.map +1 -0
  169. package/build/react/shared/LocaleSwitcher.mjs +61 -0
  170. package/build/react/shared/LocaleSwitcher.mjs.map +1 -0
  171. package/build/react/shared/WeglotContext.cjs +14 -0
  172. package/build/react/shared/WeglotContext.d.cts +34 -0
  173. package/build/react/shared/WeglotContext.d.cts.map +1 -0
  174. package/build/react/shared/WeglotContext.d.mts +34 -0
  175. package/build/react/shared/WeglotContext.d.mts.map +1 -0
  176. package/build/react/shared/WeglotContext.mjs +13 -0
  177. package/build/react/shared/WeglotContext.mjs.map +1 -0
  178. package/build/react/shared/WeglotProvider.cjs +250 -0
  179. package/build/react/shared/WeglotProvider.d.cts +60 -0
  180. package/build/react/shared/WeglotProvider.d.cts.map +1 -0
  181. package/build/react/shared/WeglotProvider.d.mts +60 -0
  182. package/build/react/shared/WeglotProvider.d.mts.map +1 -0
  183. package/build/react/shared/WeglotProvider.mjs +250 -0
  184. package/build/react/shared/WeglotProvider.mjs.map +1 -0
  185. package/build/react/shared/render-rich-text.cjs +56 -0
  186. package/build/react/shared/render-rich-text.d.cts +16 -0
  187. package/build/react/shared/render-rich-text.d.cts.map +1 -0
  188. package/build/react/shared/render-rich-text.d.mts +16 -0
  189. package/build/react/shared/render-rich-text.d.mts.map +1 -0
  190. package/build/react/shared/render-rich-text.mjs +55 -0
  191. package/build/react/shared/render-rich-text.mjs.map +1 -0
  192. package/build/react/shared/utils.cjs +34 -0
  193. package/build/react/shared/utils.mjs +35 -0
  194. package/build/react/shared/utils.mjs.map +1 -0
  195. package/build/react/types.d.cts +16 -0
  196. package/build/react/types.d.cts.map +1 -0
  197. package/build/react/types.d.mts +16 -0
  198. package/build/react/types.d.mts.map +1 -0
  199. package/build/runtime/html/segmenter.cjs +226 -0
  200. package/build/runtime/html/segmenter.mjs +225 -0
  201. package/build/runtime/html/segmenter.mjs.map +1 -0
  202. package/build/runtime/index.cjs +6 -0
  203. package/build/runtime/index.d.cts +2 -0
  204. package/build/runtime/index.d.mts +2 -0
  205. package/build/runtime/index.mjs +3 -0
  206. package/build/runtime/translate-dynamic.cjs +142 -0
  207. package/build/runtime/translate-dynamic.d.cts +29 -0
  208. package/build/runtime/translate-dynamic.d.cts.map +1 -0
  209. package/build/runtime/translate-dynamic.d.mts +29 -0
  210. package/build/runtime/translate-dynamic.d.mts.map +1 -0
  211. package/build/runtime/translate-dynamic.mjs +139 -0
  212. package/build/runtime/translate-dynamic.mjs.map +1 -0
  213. package/build/translation-server/logger.cjs +37 -0
  214. package/build/translation-server/logger.mjs +37 -0
  215. package/build/translation-server/logger.mjs.map +1 -0
  216. package/build/translation-server/translation-server.cjs +451 -0
  217. package/build/translation-server/translation-server.mjs +448 -0
  218. package/build/translation-server/translation-server.mjs.map +1 -0
  219. package/build/translators/api.cjs +12 -0
  220. package/build/translators/api.mjs +12 -0
  221. package/build/translators/api.mjs.map +1 -0
  222. package/build/translators/cache-factory.cjs +26 -0
  223. package/build/translators/cache-factory.mjs +27 -0
  224. package/build/translators/cache-factory.mjs.map +1 -0
  225. package/build/translators/local-cache.cjs +132 -0
  226. package/build/translators/local-cache.mjs +130 -0
  227. package/build/translators/local-cache.mjs.map +1 -0
  228. package/build/translators/translation-service.cjs +137 -0
  229. package/build/translators/translation-service.mjs +138 -0
  230. package/build/translators/translation-service.mjs.map +1 -0
  231. package/build/translators/weglot/api-client.cjs +79 -0
  232. package/build/translators/weglot/api-client.mjs +79 -0
  233. package/build/translators/weglot/api-client.mjs.map +1 -0
  234. package/build/translators/weglot/definitions/definitions.generated.cjs +53 -0
  235. package/build/translators/weglot/definitions/definitions.generated.mjs +52 -0
  236. package/build/translators/weglot/definitions/definitions.generated.mjs.map +1 -0
  237. package/build/translators/weglot/engine.cjs +46 -0
  238. package/build/translators/weglot/engine.mjs +43 -0
  239. package/build/translators/weglot/engine.mjs.map +1 -0
  240. package/build/translators/weglot/translator.cjs +61 -0
  241. package/build/translators/weglot/translator.mjs +62 -0
  242. package/build/translators/weglot/translator.mjs.map +1 -0
  243. package/build/translators/weglot/wire-format.cjs +128 -0
  244. package/build/translators/weglot/wire-format.mjs +129 -0
  245. package/build/translators/weglot/wire-format.mjs.map +1 -0
  246. package/build/types.d.cts +143 -0
  247. package/build/types.d.cts.map +1 -0
  248. package/build/types.d.mts +143 -0
  249. package/build/types.d.mts.map +1 -0
  250. package/build/utils/config-factory.cjs +86 -0
  251. package/build/utils/config-factory.mjs +83 -0
  252. package/build/utils/config-factory.mjs.map +1 -0
  253. package/build/utils/hash.cjs +17 -0
  254. package/build/utils/hash.mjs +16 -0
  255. package/build/utils/hash.mjs.map +1 -0
  256. package/build/utils/is-valid-locale.cjs +13 -0
  257. package/build/utils/is-valid-locale.mjs +13 -0
  258. package/build/utils/is-valid-locale.mjs.map +1 -0
  259. package/build/utils/logger.cjs +51 -0
  260. package/build/utils/logger.mjs +50 -0
  261. package/build/utils/logger.mjs.map +1 -0
  262. package/build/utils/path-helpers.cjs +49 -0
  263. package/build/utils/path-helpers.mjs +47 -0
  264. package/build/utils/path-helpers.mjs.map +1 -0
  265. package/build/utils/timeout.cjs +42 -0
  266. package/build/utils/timeout.mjs +41 -0
  267. package/build/utils/timeout.mjs.map +1 -0
  268. package/build/virtual/code-generator.cjs +56 -0
  269. package/build/virtual/code-generator.mjs +55 -0
  270. package/build/virtual/code-generator.mjs.map +1 -0
  271. package/build/virtual/config.cjs +16 -0
  272. package/build/virtual/config.d.cts +13 -0
  273. package/build/virtual/config.d.cts.map +1 -0
  274. package/build/virtual/config.d.mts +13 -0
  275. package/build/virtual/config.d.mts.map +1 -0
  276. package/build/virtual/config.mjs +12 -0
  277. package/build/virtual/config.mjs.map +1 -0
  278. package/build/virtual/locale/client.cjs +23 -0
  279. package/build/virtual/locale/client.d.cts +19 -0
  280. package/build/virtual/locale/client.d.cts.map +1 -0
  281. package/build/virtual/locale/client.d.mts +19 -0
  282. package/build/virtual/locale/client.d.mts.map +1 -0
  283. package/build/virtual/locale/client.mjs +22 -0
  284. package/build/virtual/locale/client.mjs.map +1 -0
  285. package/build/virtual/locale/server.cjs +13 -0
  286. package/build/virtual/locale/server.d.cts +13 -0
  287. package/build/virtual/locale/server.d.cts.map +1 -0
  288. package/build/virtual/locale/server.d.mts +13 -0
  289. package/build/virtual/locale/server.d.mts.map +1 -0
  290. package/build/virtual/locale/server.mjs +13 -0
  291. package/build/virtual/locale/server.mjs.map +1 -0
  292. package/package.json +260 -4
@@ -0,0 +1,524 @@
1
+ import { logger } from "../../utils/logger.mjs";
2
+ import { INLINE_TAGS } from "../../translators/weglot/engine.mjs";
3
+ import { DEFAULT_TRANSLATOR, buildTranslationCall, comstructUnifiedImport, constructServerImport, constructTranslationCall, createTranslationEntry, escapeTextForICU, hasUseI18nDirective, inferComponentName, injectServerHook, injectUnifiedHook, isComponentName, isNestedComponent, isReactComponent, isVoidElement, normalizeWhitespace, translatorNameFor } from "./utils.mjs";
4
+ import { processNextDynamicMetadata, processNextStaticMetadata } from "./metadata.mjs";
5
+ import { traverse } from "./babel-compat.mjs";
6
+ import { collectConstantReferences, collectLiteralPaths, isTranslatablePosition, isTranslatableText, templateToMessage } from "./expression-strings.mjs";
7
+ import * as t from "@babel/types";
8
+
9
+ //#region src/plugin/transform/process-file.ts
10
+ /**
11
+ * Keep mutations to the current node and children. Do not mutate program inserting imports when processing the component.
12
+ * This should be done in the end.
13
+ * The overall idea is that state is used for side effect tracking. When we exit relevant points, we check if we need to make extra changes at this level.
14
+ * e.g. when we transform elements to insert translations, we record their hashes and add the translation hook call when leaving the component.
15
+ */
16
+ function updateWithMetadataState(state, newState) {
17
+ state.newEntries = [...state.newEntries, ...newState.newEntries];
18
+ state.needsAsyncImport = state.needsAsyncImport || newState.needsAsyncImport;
19
+ return state;
20
+ }
21
+ const SKIP_ATTRIBUTE = "data-weglot-skip";
22
+ /**
23
+ * Elements whose content should not be translated by default.
24
+ * These are typically code-related or technical elements where translation
25
+ * would break functionality or meaning.
26
+ */
27
+ const NON_TRANSLATABLE_ELEMENTS = new Set([
28
+ "code",
29
+ "pre",
30
+ "script",
31
+ "style",
32
+ "kbd",
33
+ "samp",
34
+ "var"
35
+ ]);
36
+ const TRANSLATABLE_ATTRIBUTES = new Set([
37
+ "title",
38
+ "aria-label",
39
+ "aria-description",
40
+ "alt",
41
+ "label",
42
+ "description",
43
+ "placeholder",
44
+ "content",
45
+ "subtitle"
46
+ ]);
47
+ /** The key in `translatableAttributes` whose deltas apply to every element. */
48
+ const ANY_ELEMENT = "*";
49
+ /** Component props are camelCase, HTML attributes lowercase; both mean the same prop. */
50
+ function normalizeAttributeName(name) {
51
+ return name.toLowerCase();
52
+ }
53
+ function collectImportAliases(ast) {
54
+ const aliases = {};
55
+ const body = ast.type === "File" ? ast.program.body : [];
56
+ for (const statement of body) {
57
+ if (statement.type !== "ImportDeclaration") continue;
58
+ for (const specifier of statement.specifiers) if (specifier.type === "ImportSpecifier" && specifier.imported.type === "Identifier" && specifier.imported.name !== specifier.local.name) aliases[specifier.local.name] = specifier.imported.name;
59
+ }
60
+ return aliases;
61
+ }
62
+ /** Keys an element answers to, least specific first so a later match wins:
63
+ * `<Select.Option>` answers to `Option` then `Select.Option`. */
64
+ function elementKeysFor(name, aliases) {
65
+ const canonical = (local) => aliases[local] ?? local;
66
+ if (name.type === "JSXIdentifier") return [...new Set([canonical(name.name), name.name])];
67
+ if (name.type === "JSXMemberExpression") {
68
+ const property = name.property.name;
69
+ const object = name.object.type === "JSXIdentifier" ? name.object.name : void 0;
70
+ if (!object) return [property];
71
+ return [...new Set([
72
+ property,
73
+ `${canonical(object)}.${property}`,
74
+ `${object}.${property}`
75
+ ])];
76
+ }
77
+ return [];
78
+ }
79
+ const reportedCasingMismatches = /* @__PURE__ */ new Set();
80
+ /** A mis-cased key is silently inert, and nothing else tells it apart from a
81
+ * key for a component this file never renders. */
82
+ function warnOnCasingMismatch(elementKeys, configured) {
83
+ for (const key of elementKeys) {
84
+ if (configured[key]) continue;
85
+ for (const configuredKey of Object.keys(configured)) if (configuredKey !== ANY_ELEMENT && configuredKey.toLowerCase() === key.toLowerCase() && !reportedCasingMismatches.has(configuredKey)) {
86
+ reportedCasingMismatches.add(configuredKey);
87
+ logger.warn(`translatableAttributes key "${configuredKey}" does not match the element <${key}>; element keys are case-sensitive.`);
88
+ }
89
+ }
90
+ }
91
+ /** `"*"` deltas apply first, then the element's own, so a component can re-add
92
+ * what `"*"` removed. */
93
+ function translatableAttributesFor(elementKeys, configured) {
94
+ const deltas = [...configured[ANY_ELEMENT] ?? [], ...elementKeys.flatMap((key) => configured[key] ?? [])];
95
+ if (deltas.length === 0) {
96
+ warnOnCasingMismatch(elementKeys, configured);
97
+ return TRANSLATABLE_ATTRIBUTES;
98
+ }
99
+ const effective = new Set(TRANSLATABLE_ATTRIBUTES);
100
+ for (const delta of deltas) {
101
+ const removed = delta.startsWith("!");
102
+ const name = normalizeAttributeName(removed ? delta.slice(1) : delta);
103
+ if (removed) effective.delete(name);
104
+ else effective.add(name);
105
+ }
106
+ return effective;
107
+ }
108
+ /**
109
+ * Check if a JSX element should skip translation based on:
110
+ * 1. Element type (code, pre, script, style, etc.)
111
+ * 2. translate="no" attribute (HTML standard)
112
+ * 3. data-weglot-skip attribute
113
+ */
114
+ /** Every branch is registered at build time, so a component asks for each label
115
+ * it might render, not only the first. */
116
+ function translateExpressionStrings(path, state) {
117
+ const component = state.componentsStack.at(-1);
118
+ if (!component) return;
119
+ const enclosing = path.parent.type === "JSXAttribute" ? path.parentPath?.parentPath?.node : void 0;
120
+ if (!isTranslatablePosition(path, translatableAttributesFor(enclosing && enclosing.type === "JSXOpeningElement" ? elementKeysFor(enclosing.name, state.importAliases) : [], state.translatableAttributes))) return;
121
+ if ((path.parent.type === "JSXElement" || path.parent.type === "JSXFragment") && shouldSkipTranslationForElement(path.parent)) return;
122
+ const expression = path.get("expression");
123
+ if (expression.node.type === "JSXEmptyExpression") return;
124
+ for (const reference of collectConstantReferences(expression)) reference.path.replaceWith(t.cloneNode(reference.replacement, true));
125
+ for (const literalPath of collectLiteralPaths(expression)) {
126
+ const message = literalPath.isTemplateLiteral() ? templateToMessage(literalPath.node) : null;
127
+ let text;
128
+ if (literalPath.isTemplateLiteral()) {
129
+ if (!message) continue;
130
+ text = normalizeWhitespace(message.text);
131
+ } else {
132
+ text = normalizeWhitespace(literalPath.node.value);
133
+ if (!isTranslatableText(text)) continue;
134
+ }
135
+ const entry = createTranslationEntry("content", text, { componentName: component.name }, state.filePath, literalPath.node.loc?.start.line, literalPath.node.loc?.start.column);
136
+ registerEntry(entry, state, component.name);
137
+ literalPath.replaceWith(buildTranslationCall(entry.hash, text, component.translator, message ?? void 0));
138
+ }
139
+ }
140
+ function shouldSkipTranslationForElement(element) {
141
+ if (element.type === "JSXFragment") return false;
142
+ const openingElement = element.openingElement;
143
+ if (openingElement.name.type === "JSXIdentifier") {
144
+ if (NON_TRANSLATABLE_ELEMENTS.has(openingElement.name.name.toLowerCase())) return true;
145
+ }
146
+ for (const attr of openingElement.attributes) if (attr.type === "JSXAttribute" && attr.name.type === "JSXIdentifier") {
147
+ if (attr.name.name === "translate") {
148
+ if (attr.value?.type === "StringLiteral" && attr.value.value === "no") return true;
149
+ }
150
+ if (attr.name.name === SKIP_ATTRIBUTE) return true;
151
+ }
152
+ return false;
153
+ }
154
+ function translateAttributes(node, state) {
155
+ const openingElement = node.openingElement;
156
+ const component = state.componentsStack.at(-1);
157
+ if (!component) return;
158
+ const translatable = translatableAttributesFor(elementKeysFor(openingElement.name, state.importAliases), state.translatableAttributes);
159
+ for (const attr of openingElement.attributes) if (attr.type === "JSXAttribute" && attr.name.type === "JSXIdentifier" && translatable.has(normalizeAttributeName(attr.name.name)) && attr.value?.type === "StringLiteral") {
160
+ const text = normalizeWhitespace(attr.value.value);
161
+ if (!isTranslatableText(text)) continue;
162
+ const entry = createTranslationEntry("attribute", text, {
163
+ attributeName: attr.name.name,
164
+ componentName: component.name
165
+ }, state.filePath, node.loc?.start.line, node.loc?.start.column);
166
+ registerEntry(entry, state, component.name);
167
+ attr.value = constructTranslationCall(entry.hash, text, void 0, component.translator);
168
+ }
169
+ }
170
+ /**
171
+ * Check if a JSX element has mixed content that needs rich text translation
172
+ * Mixed content = text nodes + expressions + nested JSX elements (excluding void elements)
173
+ */
174
+ function hasMixedContent(element) {
175
+ const children = element.children;
176
+ if (children.length === 0) return false;
177
+ let state = 0;
178
+ for (const child of children) if (child.type === "JSXText") {
179
+ if (child.value.trim().length > 0) switch (state) {
180
+ case 0:
181
+ state = 1;
182
+ break;
183
+ case 1: break;
184
+ case 2: return true;
185
+ case 3: return true;
186
+ }
187
+ } else if (child.type === "JSXExpressionContainer") switch (state) {
188
+ case 0:
189
+ state = 2;
190
+ break;
191
+ case 1: return true;
192
+ case 2: break;
193
+ case 3: return true;
194
+ }
195
+ else if (child.type === "JSXElement") if (!isVoidElement(child)) switch (state) {
196
+ case 0:
197
+ state = 2;
198
+ break;
199
+ case 1: return true;
200
+ case 2: break;
201
+ case 3: return true;
202
+ }
203
+ else switch (state) {
204
+ case 0: break;
205
+ case 1:
206
+ state = 3;
207
+ break;
208
+ case 2: break;
209
+ case 3: break;
210
+ }
211
+ return hasMergeableSiblings(children);
212
+ }
213
+ function hostElementName(child) {
214
+ const name = child.openingElement.name;
215
+ return name.type === "JSXIdentifier" ? name.name.toLowerCase() : null;
216
+ }
217
+ function holdsLiteralText(element) {
218
+ return element.children.some((child) => child.type === "JSXText" && child.value.trim().length > 0 || child.type === "JSXElement" && holdsLiteralText(child));
219
+ }
220
+ /** `<span>Hello </span><span>world</span>` is one sentence, and the state machine
221
+ * above only sees text interleaved with elements. The HTML segmenter merges it too. */
222
+ function hasMergeableSiblings(children) {
223
+ let withText = 0;
224
+ for (const child of children) {
225
+ if (child.type === "JSXText") {
226
+ if (child.value.trim().length > 0) return false;
227
+ continue;
228
+ }
229
+ if (child.type === "JSXExpressionContainer") continue;
230
+ if (child.type !== "JSXElement") return false;
231
+ const name = hostElementName(child);
232
+ if (name === null || !INLINE_TAGS.has(name)) return false;
233
+ if (holdsLiteralText(child)) withText++;
234
+ }
235
+ return withText > 1;
236
+ }
237
+ /**
238
+ * Serialize JSX children to a translation string with placeholders
239
+ */
240
+ function serializeJSXChildren(children, state, elementCounts = /* @__PURE__ */ new Map()) {
241
+ let text = "";
242
+ const variables = [];
243
+ const expressions = /* @__PURE__ */ new Map();
244
+ const components = /* @__PURE__ */ new Map();
245
+ for (const child of children) if (child.type === "JSXText") {
246
+ let normalized = normalizeWhitespace(child.value);
247
+ const keepsBoundary = (whitespace) => whitespace.length > 0 && !whitespace.includes("\n");
248
+ const leading = /^\s*/.exec(child.value)?.[0] ?? "";
249
+ const trailing = /\s*$/.exec(child.value)?.[0] ?? "";
250
+ if (text.length > 0 && keepsBoundary(leading) && normalized.length > 0 && !text.endsWith(" ")) normalized = ` ${normalized}`;
251
+ if (normalized.length > 0 && keepsBoundary(trailing)) normalized = `${normalized} `;
252
+ text += escapeTextForICU(normalized);
253
+ } else if (child.type === "JSXExpressionContainer") {
254
+ const expr = child.expression;
255
+ if (expr.type === "Identifier") {
256
+ text += `{${expr.name}}`;
257
+ if (!variables.includes(expr.name)) variables.push(expr.name);
258
+ } else if (expr.type === "StringLiteral") text += escapeTextForICU(expr.value);
259
+ else if (expr.type !== "JSXEmptyExpression") {
260
+ const name = `expression${expressions.size}`;
261
+ text += `{${name}}`;
262
+ expressions.set(name, expr);
263
+ }
264
+ } else if (child.type === "JSXElement") {
265
+ let shouldTranslate = true;
266
+ if (isVoidElement(child)) shouldTranslate = false;
267
+ if (shouldSkipTranslationForElement(child)) shouldTranslate = false;
268
+ const openingElement = child.openingElement;
269
+ let elementName = "";
270
+ if (openingElement.name.type === "JSXIdentifier") elementName = openingElement.name.name;
271
+ else elementName = "element";
272
+ const count = elementCounts.get(elementName) || 0;
273
+ elementCounts.set(elementName, count + 1);
274
+ const tagName = `${elementName}${count}`;
275
+ translateAttributes(child, state);
276
+ if (shouldTranslate) {
277
+ const nested = serializeJSXChildren(child.children, state, elementCounts);
278
+ text += `<${tagName}>${nested.text}</${tagName}>`;
279
+ for (const v of nested.variables) if (!variables.includes(v)) variables.push(v);
280
+ for (const [nestedTag, nestedElement] of nested.components) components.set(nestedTag, nestedElement);
281
+ } else {
282
+ text += `<${tagName}></${tagName}>`;
283
+ child.extra = {
284
+ ...child.extra,
285
+ shouldTranslate: false
286
+ };
287
+ }
288
+ components.set(tagName, child);
289
+ }
290
+ return {
291
+ text,
292
+ variables,
293
+ expressions,
294
+ components
295
+ };
296
+ }
297
+ function transformVoidElement(node, state) {
298
+ translateAttributes(node, state);
299
+ }
300
+ function getTranslationScope(node, state) {
301
+ if (hasMixedContent(node)) {
302
+ const serialized = serializeJSXChildren(node.children, state);
303
+ const text$1 = serialized.text.trim();
304
+ if (text$1.length === 0) return null;
305
+ return {
306
+ kind: "mixed",
307
+ text: text$1,
308
+ args: {
309
+ variables: serialized.variables,
310
+ expressions: serialized.expressions,
311
+ components: serialized.components
312
+ }
313
+ };
314
+ }
315
+ const textNodeIndex = node.children.findIndex((child) => child.type === "JSXText" && child.value.trim().length > 0);
316
+ if (textNodeIndex === -1) return null;
317
+ if (!node.children.every((child) => child.type === "JSXText" || child.type === "JSXElement" && isVoidElement(child))) return null;
318
+ const textNode = node.children[textNodeIndex];
319
+ const text = normalizeWhitespace(textNode.value);
320
+ if (text.length === 0) return null;
321
+ return {
322
+ kind: "text",
323
+ text,
324
+ textNodeIndex
325
+ };
326
+ }
327
+ function registerEntry(entry, state, componentName) {
328
+ state.newEntries.push(entry);
329
+ const hashes = state.componentHashes.get(componentName) ?? [];
330
+ hashes.push(entry.hash);
331
+ state.componentHashes.set(componentName, hashes);
332
+ }
333
+ function rewriteChildren(path, state, translationScope, entryHash) {
334
+ const translator = state.componentsStack.at(-1)?.translator ?? DEFAULT_TRANSLATOR;
335
+ if (translationScope.kind === "mixed") {
336
+ path.node.children = [constructTranslationCall(entryHash, translationScope.text, translationScope.args, translator)];
337
+ return;
338
+ }
339
+ const { textNodeIndex, text } = translationScope;
340
+ path.node.children = path.node.children.map((child, index) => {
341
+ if (index === textNodeIndex) return constructTranslationCall(entryHash, text, void 0, translator);
342
+ if (child.type === "JSXElement") transformVoidElement(child, state);
343
+ return child;
344
+ });
345
+ }
346
+ function processJSXElement(path, state) {
347
+ const component = state.componentsStack.at(-1);
348
+ if (!component) return;
349
+ const scope = getTranslationScope(path.node, state);
350
+ if (!scope) return;
351
+ const entry = createTranslationEntry("content", scope.text, { componentName: component.name }, state.filePath, path.node.loc?.start.line, path.node.loc?.start.column);
352
+ registerEntry(entry, state, component.name);
353
+ rewriteChildren(path, state, scope, entry.hash);
354
+ path.skip();
355
+ }
356
+ /**
357
+ * Inject dynamic locale attribute into <html> elements
358
+ * Transforms: <html> → <html lang={locale}>
359
+ *
360
+ * Only injects if:
361
+ * 1. Element is <html>
362
+ * 2. No existing lang/language attribute
363
+ * 3. We're inside a React component (has locale context)
364
+ */
365
+ function injectHtmlLangAttribute(node, state) {
366
+ const openingElement = node.openingElement;
367
+ if (openingElement.name.type !== "JSXIdentifier" || openingElement.name.name !== "html") return;
368
+ if (openingElement.attributes.some((attr) => {
369
+ return attr.type === "JSXAttribute" && attr.name.type === "JSXIdentifier" && (attr.name.name === "lang" || attr.name.name === "language");
370
+ })) return;
371
+ const component = state.componentsStack.at(-1);
372
+ if (!component) return;
373
+ const langAttr = t.jsxAttribute(t.jsxIdentifier("lang"), t.jsxExpressionContainer(t.identifier("locale")));
374
+ openingElement.attributes.push(langAttr);
375
+ logger.debug(`Injected locale attribute into <html> element in component: ${component.name}`);
376
+ state.componentsNeedingLocale.add(component.name);
377
+ }
378
+ /**
379
+ * Inject translation hook into a component when it's done processing
380
+ * Called when popping component from stack
381
+ */
382
+ function injectTranslationHook(path, component, state) {
383
+ const needsLocale = state.componentsNeedingLocale.has(component.name);
384
+ const collected = state.componentHashes.get(component.name);
385
+ const hashes = collected && [...new Set(collected)];
386
+ if ((!hashes || hashes.length === 0) && !needsLocale) return;
387
+ if (component.isAsync) {
388
+ injectServerHook(path, hashes ?? [], needsLocale, component.translator);
389
+ state.needsAsyncImport = true;
390
+ } else {
391
+ injectUnifiedHook(path, hashes ?? [], needsLocale, component.translator);
392
+ state.needsUnifiedImport = true;
393
+ }
394
+ }
395
+ /**
396
+ * Add translation imports at the top of the file
397
+ * Called on Program exit after all components have been processed
398
+ */
399
+ function addTranslationImports(programPath, state) {
400
+ if (state.needsAsyncImport) programPath.node.body.unshift(constructServerImport());
401
+ if (state.needsUnifiedImport) programPath.node.body.unshift(comstructUnifiedImport());
402
+ }
403
+ /**
404
+ * Handle component function detection and state update
405
+ */
406
+ function processComponentFunction(path, state) {
407
+ if (!isReactComponent(path)) {
408
+ path.skip();
409
+ logger.debug(`Skipping non-React component: ${path.node.type}`);
410
+ return;
411
+ }
412
+ const componentName = inferComponentName(path);
413
+ if (!componentName) {
414
+ path.skip();
415
+ return;
416
+ }
417
+ if (state.componentsStack.length > 0 && !isComponentName(componentName)) {
418
+ logger.debug(`Folding helper ${componentName} into its component`);
419
+ return;
420
+ }
421
+ if (!state.componentHashes.has(componentName)) state.componentHashes.set(componentName, []);
422
+ const componentEntry = {
423
+ name: componentName,
424
+ isAsync: path.node.async,
425
+ translator: translatorNameFor(path)
426
+ };
427
+ state.componentsStack.push(componentEntry);
428
+ logger.debug(`Component ${JSON.stringify(componentEntry)} entered`);
429
+ path.setData("componentName", componentName);
430
+ path.traverse(expressionStringVisitors, { visitorState: state });
431
+ path.traverse(componentVisitors, { visitorState: state });
432
+ const component = state.componentsStack.pop();
433
+ if (component) injectTranslationHook(path, component, state);
434
+ path.skip();
435
+ }
436
+ const expressionStringVisitors = {
437
+ JSXExpressionContainer(path) {
438
+ translateExpressionStrings(path, this.visitorState);
439
+ },
440
+ FunctionDeclaration(path) {
441
+ if (isNestedComponent(path)) path.skip();
442
+ },
443
+ ArrowFunctionExpression(path) {
444
+ if (isNestedComponent(path)) path.skip();
445
+ },
446
+ FunctionExpression(path) {
447
+ if (isNestedComponent(path)) path.skip();
448
+ }
449
+ };
450
+ const componentVisitors = {
451
+ FunctionDeclaration(path) {
452
+ processComponentFunction(path, this.visitorState);
453
+ },
454
+ ArrowFunctionExpression(path) {
455
+ processComponentFunction(path, this.visitorState);
456
+ },
457
+ FunctionExpression(path) {
458
+ processComponentFunction(path, this.visitorState);
459
+ },
460
+ JSXFragment(path) {
461
+ processJSXElement(path, this.visitorState);
462
+ },
463
+ JSXElement(path) {
464
+ translateAttributes(path.node, this.visitorState);
465
+ injectHtmlLangAttribute(path.node, this.visitorState);
466
+ if (shouldSkipTranslationForElement(path.node)) {
467
+ path.skip();
468
+ return;
469
+ }
470
+ processJSXElement(path, this.visitorState);
471
+ }
472
+ };
473
+ const fileVisitors = {
474
+ ExportNamedDeclaration(path) {
475
+ const metadataState = processNextStaticMetadata(path, { filePath: this.visitorState.filePath });
476
+ if (metadataState) updateWithMetadataState(this.visitorState, metadataState);
477
+ },
478
+ FunctionDeclaration(path) {
479
+ const metadataState = processNextDynamicMetadata(path, { filePath: this.visitorState.filePath });
480
+ if (metadataState) updateWithMetadataState(this.visitorState, metadataState);
481
+ processComponentFunction(path, this.visitorState);
482
+ },
483
+ ArrowFunctionExpression(path) {
484
+ processComponentFunction(path, this.visitorState);
485
+ },
486
+ FunctionExpression(path) {
487
+ processComponentFunction(path, this.visitorState);
488
+ }
489
+ };
490
+ /**
491
+ * Create Babel visitors for auto-translation (single-pass transformation)
492
+ */
493
+ const programVisitor = { Program: {
494
+ enter(path) {
495
+ if (this.visitorState.needsDirective && !hasUseI18nDirective(path)) {
496
+ path.skip();
497
+ return;
498
+ }
499
+ path.traverse(fileVisitors, { visitorState: this.visitorState });
500
+ },
501
+ exit(path) {
502
+ if (this.visitorState.needsUnifiedImport || this.visitorState.needsAsyncImport) addTranslationImports(path, this.visitorState);
503
+ }
504
+ } };
505
+ function processFile(ast, options) {
506
+ const state = {
507
+ needsDirective: options.needsDirective,
508
+ filePath: options.relativeFilePath,
509
+ newEntries: [],
510
+ componentsStack: [],
511
+ componentHashes: /* @__PURE__ */ new Map(),
512
+ needsUnifiedImport: false,
513
+ needsAsyncImport: false,
514
+ componentsNeedingLocale: /* @__PURE__ */ new Set(),
515
+ translatableAttributes: options.translatableAttributes ?? {},
516
+ importAliases: collectImportAliases(ast)
517
+ };
518
+ traverse(ast, programVisitor, void 0, { visitorState: state });
519
+ return state.newEntries;
520
+ }
521
+
522
+ //#endregion
523
+ export { processFile };
524
+ //# sourceMappingURL=process-file.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-file.mjs","names":["aliases: Record<string, string>","text: string","variables: string[]","text","componentEntry: ComponentEntry","state: VisitorsInternalState"],"sources":["../../../src/plugin/transform/process-file.ts"],"sourcesContent":["/**\n * Keep mutations to the current node and children. Do not mutate program inserting imports when processing the component.\n * This should be done in the end.\n * The overall idea is that state is used for side effect tracking. When we exit relevant points, we check if we need to make extra changes at this level.\n * e.g. when we transform elements to insert translations, we record their hashes and add the translation hook call when leaving the component.\n */\nimport * as t from \"@babel/types\";\nimport { INLINE_TAGS } from \"../../translators/weglot/engine\";\nimport type { NodePath, TraverseOptions } from \"@babel/traverse\";\nimport type { TranslationEntry } from \"../../types\";\nimport { logger } from \"../../utils/logger\";\nimport {\n DEFAULT_TRANSLATOR,\n comstructUnifiedImport,\n constructServerImport,\n buildTranslationCall,\n constructTranslationCall,\n createTranslationEntry,\n escapeTextForICU,\n hasUseI18nDirective,\n inferComponentName,\n isComponentName,\n isNestedComponent,\n injectServerHook,\n injectUnifiedHook,\n translatorNameFor,\n isReactComponent,\n isVoidElement,\n normalizeWhitespace,\n} from \"./utils\";\nimport {\n type MetadataOutputState,\n processNextDynamicMetadata,\n processNextStaticMetadata,\n} from \"./metadata\";\nimport { traverse } from \"./babel-compat\";\nimport {\n collectConstantReferences,\n collectLiteralPaths,\n isTranslatablePosition,\n isTranslatableText,\n templateToMessage,\n} from \"./expression-strings\";\n\ntype ComponentEntry = {\n name: string;\n isAsync: boolean;\n /** Name the injected translator binds to; not `t` when the component has its own. */\n translator: string;\n};\n\n/**\n * State shared between all the visitors.\n */\nexport interface VisitorsInternalState {\n needsDirective: boolean;\n filePath: string;\n newEntries: TranslationEntry[];\n /** Stores component encountered up the tree at the current point, to avoid lookups. */\n componentsStack: ComponentEntry[];\n /** Map component names to their translation hashes */\n componentHashes: Map<string, string[]>;\n /** Track metadata functions that need translation */\n /** Track if we need the unified hook import */\n needsUnifiedImport: boolean;\n /** Track if we need the async API import */\n needsAsyncImport: boolean;\n /** Track which components need locale from hook (for <html> lang attribute) */\n componentsNeedingLocale: Set<string>;\n /** Configured deltas on the built-in translatable-attribute list. */\n translatableAttributes: Record<string, string[]>;\n /** Local name of each aliased import mapped to its exported name. */\n importAliases: Record<string, string>;\n}\n\nfunction updateWithMetadataState(\n state: VisitorsInternalState,\n newState: MetadataOutputState,\n): VisitorsInternalState {\n state.newEntries = [...state.newEntries, ...newState.newEntries];\n state.needsAsyncImport = state.needsAsyncImport || newState.needsAsyncImport;\n return state;\n}\n\nconst SKIP_ATTRIBUTE = \"data-weglot-skip\";\n\n/**\n * Elements whose content should not be translated by default.\n * These are typically code-related or technical elements where translation\n * would break functionality or meaning.\n */\nconst NON_TRANSLATABLE_ELEMENTS = new Set([\n \"code\",\n \"pre\",\n \"script\",\n \"style\",\n \"kbd\",\n \"samp\",\n \"var\",\n]);\n\nconst TRANSLATABLE_ATTRIBUTES = new Set([\n \"title\",\n \"aria-label\",\n \"aria-description\",\n \"alt\",\n \"label\",\n \"description\",\n \"placeholder\",\n \"content\",\n \"subtitle\",\n]);\n\n/** The key in `translatableAttributes` whose deltas apply to every element. */\nconst ANY_ELEMENT = \"*\";\n\n/** Component props are camelCase, HTML attributes lowercase; both mean the same prop. */\nfunction normalizeAttributeName(name: string): string {\n return name.toLowerCase();\n}\n\nexport function collectImportAliases(ast: t.Node): Record<string, string> {\n const aliases: Record<string, string> = {};\n const body = ast.type === \"File\" ? ast.program.body : [];\n for (const statement of body) {\n if (statement.type !== \"ImportDeclaration\") continue;\n for (const specifier of statement.specifiers) {\n if (\n specifier.type === \"ImportSpecifier\" &&\n specifier.imported.type === \"Identifier\" &&\n specifier.imported.name !== specifier.local.name\n ) {\n aliases[specifier.local.name] = specifier.imported.name;\n }\n }\n }\n return aliases;\n}\n\n/** Keys an element answers to, least specific first so a later match wins:\n * `<Select.Option>` answers to `Option` then `Select.Option`. */\nfunction elementKeysFor(\n name: t.JSXOpeningElement[\"name\"],\n aliases: Record<string, string>,\n): string[] {\n const canonical = (local: string) => aliases[local] ?? local;\n\n if (name.type === \"JSXIdentifier\") {\n return [...new Set([canonical(name.name), name.name])];\n }\n if (name.type === \"JSXMemberExpression\") {\n const property = name.property.name;\n const object =\n name.object.type === \"JSXIdentifier\" ? name.object.name : undefined;\n if (!object) return [property];\n return [\n ...new Set([\n property,\n `${canonical(object)}.${property}`,\n `${object}.${property}`,\n ]),\n ];\n }\n return [];\n}\n\nconst reportedCasingMismatches = new Set<string>();\n\n/** A mis-cased key is silently inert, and nothing else tells it apart from a\n * key for a component this file never renders. */\nfunction warnOnCasingMismatch(\n elementKeys: string[],\n configured: Record<string, string[]>,\n): void {\n for (const key of elementKeys) {\n if (configured[key]) continue;\n for (const configuredKey of Object.keys(configured)) {\n if (\n configuredKey !== ANY_ELEMENT &&\n configuredKey.toLowerCase() === key.toLowerCase() &&\n !reportedCasingMismatches.has(configuredKey)\n ) {\n reportedCasingMismatches.add(configuredKey);\n logger.warn(\n `translatableAttributes key \"${configuredKey}\" does not match the element <${key}>; element keys are case-sensitive.`,\n );\n }\n }\n }\n}\n\n/** `\"*\"` deltas apply first, then the element's own, so a component can re-add\n * what `\"*\"` removed. */\nfunction translatableAttributesFor(\n elementKeys: string[],\n configured: Record<string, string[]>,\n): ReadonlySet<string> {\n const deltas = [\n ...(configured[ANY_ELEMENT] ?? []),\n ...elementKeys.flatMap((key) => configured[key] ?? []),\n ];\n if (deltas.length === 0) {\n warnOnCasingMismatch(elementKeys, configured);\n return TRANSLATABLE_ATTRIBUTES;\n }\n\n const effective = new Set(TRANSLATABLE_ATTRIBUTES);\n for (const delta of deltas) {\n const removed = delta.startsWith(\"!\");\n const name = normalizeAttributeName(removed ? delta.slice(1) : delta);\n if (removed) effective.delete(name);\n else effective.add(name);\n }\n return effective;\n}\n\n/**\n * Check if a JSX element should skip translation based on:\n * 1. Element type (code, pre, script, style, etc.)\n * 2. translate=\"no\" attribute (HTML standard)\n * 3. data-weglot-skip attribute\n */\n/** Every branch is registered at build time, so a component asks for each label\n * it might render, not only the first. */\nfunction translateExpressionStrings(\n path: NodePath<t.JSXExpressionContainer>,\n state: VisitorsInternalState,\n): void {\n const component = state.componentsStack.at(-1);\n if (!component) return;\n const enclosing =\n path.parent.type === \"JSXAttribute\"\n ? (path.parentPath?.parentPath?.node as t.JSXOpeningElement | undefined)\n : undefined;\n if (\n !isTranslatablePosition(\n path,\n translatableAttributesFor(\n enclosing && enclosing.type === \"JSXOpeningElement\"\n ? elementKeysFor(enclosing.name, state.importAliases)\n : [],\n state.translatableAttributes,\n ),\n )\n )\n return;\n\n if (\n (path.parent.type === \"JSXElement\" || path.parent.type === \"JSXFragment\") &&\n shouldSkipTranslationForElement(path.parent)\n ) {\n return;\n }\n\n const expression = path.get(\"expression\");\n if (expression.node.type === \"JSXEmptyExpression\") return;\n\n // Copied to the read site so its strings sit where the hook is in scope.\n for (const reference of collectConstantReferences(expression as NodePath<t.Node>)) {\n reference.path.replaceWith(t.cloneNode(reference.replacement, true));\n }\n\n for (const literalPath of collectLiteralPaths(expression as NodePath<t.Node>)) {\n const message = literalPath.isTemplateLiteral()\n ? templateToMessage(literalPath.node)\n : null;\n\n let text: string;\n if (literalPath.isTemplateLiteral()) {\n if (!message) continue;\n text = normalizeWhitespace(message.text);\n } else {\n text = normalizeWhitespace((literalPath.node as t.StringLiteral).value);\n if (!isTranslatableText(text)) continue;\n }\n\n const entry = createTranslationEntry(\n \"content\",\n text,\n { componentName: component.name },\n state.filePath,\n literalPath.node.loc?.start.line,\n literalPath.node.loc?.start.column,\n );\n registerEntry(entry, state, component.name);\n literalPath.replaceWith(\n buildTranslationCall(\n entry.hash,\n text,\n component.translator,\n message ?? undefined,\n ),\n );\n }\n}\n\nfunction shouldSkipTranslationForElement(\n element: t.JSXElement | t.JSXFragment,\n): boolean {\n // We always translate fragments\n if (element.type === \"JSXFragment\") {\n return false;\n }\n const openingElement = element.openingElement;\n\n // Matched lowercased: <Script> and <Code> hold the same content as their HTML tags.\n if (openingElement.name.type === \"JSXIdentifier\") {\n if (NON_TRANSLATABLE_ELEMENTS.has(openingElement.name.name.toLowerCase())) {\n return true;\n }\n }\n\n for (const attr of openingElement.attributes) {\n if (attr.type === \"JSXAttribute\" && attr.name.type === \"JSXIdentifier\") {\n // Check for translate=\"no\" (HTML standard)\n if (attr.name.name === \"translate\") {\n if (attr.value?.type === \"StringLiteral\" && attr.value.value === \"no\") {\n return true;\n }\n }\n\n if (attr.name.name === SKIP_ATTRIBUTE) {\n return true;\n }\n }\n }\n\n return false;\n}\n\n// Called even on the element which are not translatable.\nfunction translateAttributes(\n node: t.JSXElement,\n state: VisitorsInternalState,\n): void {\n const openingElement = node.openingElement;\n\n const component = state.componentsStack.at(-1);\n if (!component) return;\n\n const translatable = translatableAttributesFor(\n elementKeysFor(openingElement.name, state.importAliases),\n state.translatableAttributes,\n );\n\n for (const attr of openingElement.attributes) {\n if (\n attr.type === \"JSXAttribute\" &&\n attr.name.type === \"JSXIdentifier\" &&\n translatable.has(normalizeAttributeName(attr.name.name)) &&\n attr.value?.type === \"StringLiteral\"\n ) {\n const text = normalizeWhitespace(attr.value.value);\n if (!isTranslatableText(text)) continue;\n\n const entry = createTranslationEntry(\n \"attribute\",\n text,\n {\n attributeName: attr.name.name,\n componentName: component.name,\n },\n state.filePath,\n node.loc?.start.line,\n node.loc?.start.column,\n );\n registerEntry(entry, state, component.name);\n\n attr.value = constructTranslationCall(\n entry.hash,\n text,\n undefined,\n component.translator,\n );\n }\n }\n}\n\n/**\n * Check if a JSX element has mixed content that needs rich text translation\n * Mixed content = text nodes + expressions + nested JSX elements (excluding void elements)\n */\nfunction hasMixedContent(element: t.JSXElement | t.JSXFragment): boolean {\n const children = element.children;\n if (children.length === 0) return false;\n // 001\n // 221\n // 101\n // States:\n // 0 - no text or translatable nodes\n // 1 - text node\n // 2 - expression or translatable element\n // 3 - interrupted text node\n // 4 - mixed\n //\n let state = 0;\n\n for (const child of children) {\n if (child.type === \"JSXText\") {\n if (child.value.trim().length > 0) {\n switch (state) {\n case 0:\n state = 1;\n break;\n case 1:\n break;\n case 2:\n return true;\n case 3:\n return true;\n }\n }\n // Expressions require a substitution of the placeholder and are usually a part of the text so should be translated in one context\n } else if (child.type === \"JSXExpressionContainer\") {\n switch (state) {\n case 0:\n state = 2;\n break;\n case 1:\n return true;\n case 2:\n break;\n case 3:\n return true;\n }\n } else if (child.type === \"JSXElement\") {\n if (!isVoidElement(child)) {\n switch (state) {\n case 0:\n state = 2;\n break;\n case 1:\n return true;\n case 2:\n break;\n case 3:\n return true;\n }\n } else {\n switch (state) {\n case 0:\n break;\n case 1:\n state = 3;\n break;\n case 2:\n break;\n case 3:\n break;\n }\n }\n }\n }\n return hasMergeableSiblings(children);\n}\n\nfunction hostElementName(child: t.JSXElement): string | null {\n const name = child.openingElement.name;\n // A component or member name owns its children and is never merged into a sentence.\n return name.type === \"JSXIdentifier\" ? name.name.toLowerCase() : null;\n}\n\nfunction holdsLiteralText(element: t.JSXElement): boolean {\n return element.children.some(\n (child) =>\n (child.type === \"JSXText\" && child.value.trim().length > 0) ||\n (child.type === \"JSXElement\" && holdsLiteralText(child)),\n );\n}\n\n/** `<span>Hello </span><span>world</span>` is one sentence, and the state machine\n * above only sees text interleaved with elements. The HTML segmenter merges it too. */\nfunction hasMergeableSiblings(\n children: (t.JSXElement | t.JSXFragment)[\"children\"],\n): boolean {\n let withText = 0;\n\n for (const child of children) {\n if (child.type === \"JSXText\") {\n // Text among the siblings is the state machine's case.\n if (child.value.trim().length > 0) return false;\n continue;\n }\n if (child.type === \"JSXExpressionContainer\") continue;\n if (child.type !== \"JSXElement\") return false;\n\n const name = hostElementName(child);\n if (name === null || !INLINE_TAGS.has(name)) return false;\n if (holdsLiteralText(child)) withText++;\n }\n\n return withText > 1;\n}\n\n/**\n * Result of serializing JSX children to a translation string\n */\ninterface SerializedJSX {\n /** The serialized string with placeholders, e.g. \"Hello {name}, you have <strong0>{count}</strong0> messages\" */\n text: string;\n /** Variable identifiers extracted from expressions, e.g. [\"name\", \"count\"] */\n variables: string[];\n expressions: Map<string, t.Expression>;\n /** Component mappings for nested elements, e.g. { strong0: <strong>...</strong> } */\n components: Map<string, t.JSXElement>;\n}\n\n/**\n * Serialize JSX children to a translation string with placeholders\n */\nfunction serializeJSXChildren(\n children: Array<\n | t.JSXText\n | t.JSXExpressionContainer\n | t.JSXElement\n | t.JSXSpreadChild\n | t.JSXFragment\n >,\n state: VisitorsInternalState,\n // Shared across nesting levels: the renderer looks components up by tag name.\n elementCounts: Map<string, number> = new Map(),\n): SerializedJSX {\n let text = \"\";\n const variables: string[] = [];\n const expressions = new Map<string, t.Expression>();\n const components = new Map<string, t.JSXElement>();\n\n for (const child of children) {\n if (child.type === \"JSXText\") {\n // Normalize whitespace within this text node\n let normalized = normalizeWhitespace(child.value);\n\n // JSX drops boundary whitespace spanning a line break, keeps the rest as one space.\n const keepsBoundary = (whitespace: string) =>\n whitespace.length > 0 && !whitespace.includes(\"\\n\");\n const leading = /^\\s*/.exec(child.value)?.[0] ?? \"\";\n const trailing = /\\s*$/.exec(child.value)?.[0] ?? \"\";\n\n if (\n text.length > 0 &&\n keepsBoundary(leading) &&\n normalized.length > 0 &&\n !text.endsWith(\" \")\n ) {\n normalized = ` ${normalized}`;\n }\n\n if (normalized.length > 0 && keepsBoundary(trailing)) {\n normalized = `${normalized} `;\n }\n\n text += escapeTextForICU(normalized);\n } else if (child.type === \"JSXExpressionContainer\") {\n // Extract variable name from expression\n const expr = child.expression;\n if (expr.type === \"Identifier\") {\n text += `{${expr.name}}`;\n if (!variables.includes(expr.name)) {\n variables.push(expr.name);\n }\n } else if (expr.type === \"StringLiteral\") {\n // String literal (like {\" \"}) - include the literal text directly\n text += escapeTextForICU(expr.value);\n } else if (expr.type !== \"JSXEmptyExpression\") {\n const name = `expression${expressions.size}`;\n text += `{${name}}`;\n expressions.set(name, expr);\n }\n } else if (child.type === \"JSXElement\") {\n let shouldTranslate = true;\n // Skip void elements (they cannot have children and shouldn't be in rich text)\n if (isVoidElement(child)) {\n // Void elements are ignored in the translation string\n // They will remain in their original position in the JSX tree\n shouldTranslate = false;\n }\n\n // Skip elements that should not be translated (code, pre, etc.)\n // These elements remain in the JSX tree but are not included in translation\n if (shouldSkipTranslationForElement(child)) {\n shouldTranslate = false;\n }\n\n // Get element name\n const openingElement = child.openingElement;\n let elementName = \"\";\n if (openingElement.name.type === \"JSXIdentifier\") {\n elementName = openingElement.name.name;\n } else {\n // TODO (AleksandrSl 02/12/2025): What is this corner case?\n // I thought it may be a fragment, but it seems that fragment is a separate JSXFragment node.\n elementName = \"element\";\n }\n\n // Generate unique tag name with index\n const count = elementCounts.get(elementName) || 0;\n elementCounts.set(elementName, count + 1);\n const tagName = `${elementName}${count}`;\n\n translateAttributes(child, state);\n\n if (shouldTranslate) {\n // Recursively serialize nested content\n const nested = serializeJSXChildren(child.children, state, elementCounts);\n text += `<${tagName}>${nested.text}</${tagName}>`;\n\n // Merge nested variables\n for (const v of nested.variables) {\n if (!variables.includes(v)) {\n variables.push(v);\n }\n }\n\n for (const [nestedTag, nestedElement] of nested.components) {\n components.set(nestedTag, nestedElement);\n }\n } else {\n // There is no support for self-closing tags in format js, so we should generate empty ones.\n text += `<${tagName}></${tagName}>`;\n child.extra = {\n ...child.extra,\n shouldTranslate: false,\n };\n }\n\n // Store component mapping\n components.set(tagName, child);\n }\n }\n\n return { text, variables, expressions, components };\n}\n\nfunction transformVoidElement(\n node: t.JSXElement,\n state: VisitorsInternalState,\n) {\n translateAttributes(node, state);\n}\n\ntype TranslationScope =\n | { kind: \"mixed\"; text: string; args: any }\n | { kind: \"text\"; text: string; textNodeIndex: number };\n\nfunction getTranslationScope(\n node: t.JSXElement | t.JSXFragment,\n state: VisitorsInternalState,\n): TranslationScope | null {\n if (hasMixedContent(node)) {\n const serialized = serializeJSXChildren(node.children, state);\n const text = serialized.text.trim();\n if (text.length === 0) return null;\n\n return {\n kind: \"mixed\",\n text,\n args: {\n variables: serialized.variables,\n expressions: serialized.expressions,\n components: serialized.components,\n },\n };\n }\n\n // Non-mixed: allow exactly one meaningful JSXText + optional void elements + whitespace\n const textNodeIndex = node.children.findIndex(\n (child) => child.type === \"JSXText\" && child.value.trim().length > 0,\n );\n if (textNodeIndex === -1) return null;\n\n const allowed = node.children.every(\n (child) =>\n child.type === \"JSXText\" ||\n (child.type === \"JSXElement\" && isVoidElement(child)),\n );\n if (!allowed) return null;\n\n const textNode = node.children[textNodeIndex] as t.JSXText;\n const text = normalizeWhitespace(textNode.value);\n if (text.length === 0) return null;\n\n return { kind: \"text\", text, textNodeIndex };\n}\n\nfunction registerEntry(\n entry: ReturnType<typeof createTranslationEntry>,\n state: VisitorsInternalState,\n componentName: string,\n) {\n state.newEntries.push(entry);\n\n const hashes = state.componentHashes.get(componentName) ?? [];\n hashes.push(entry.hash);\n state.componentHashes.set(componentName, hashes);\n}\n\nfunction rewriteChildren(\n path: NodePath<t.JSXElement | t.JSXFragment>,\n state: VisitorsInternalState,\n translationScope: TranslationScope,\n entryHash: string,\n) {\n const translator =\n state.componentsStack.at(-1)?.translator ?? DEFAULT_TRANSLATOR;\n\n if (translationScope.kind === \"mixed\") {\n path.node.children = [\n constructTranslationCall(\n entryHash,\n translationScope.text,\n translationScope.args,\n translator,\n ),\n ];\n return;\n }\n\n const { textNodeIndex, text } = translationScope;\n\n path.node.children = path.node.children.map((child, index) => {\n if (index === textNodeIndex) {\n return constructTranslationCall(entryHash, text, undefined, translator);\n }\n if (child.type === \"JSXElement\") {\n transformVoidElement(child, state);\n }\n return child;\n });\n}\n\nfunction processJSXElement(\n path: NodePath<t.JSXElement | t.JSXFragment>,\n state: VisitorsInternalState,\n): void {\n const component = state.componentsStack.at(-1);\n if (!component) return;\n\n const scope = getTranslationScope(path.node, state);\n if (!scope) return;\n\n const entry = createTranslationEntry(\n \"content\",\n scope.text,\n { componentName: component.name },\n state.filePath,\n path.node.loc?.start.line,\n path.node.loc?.start.column,\n );\n\n registerEntry(entry, state, component.name);\n rewriteChildren(path, state, scope, entry.hash);\n\n path.skip();\n}\n\n/**\n * Inject dynamic locale attribute into <html> elements\n * Transforms: <html> → <html lang={locale}>\n *\n * Only injects if:\n * 1. Element is <html>\n * 2. No existing lang/language attribute\n * 3. We're inside a React component (has locale context)\n */\nfunction injectHtmlLangAttribute(\n node: t.JSXElement,\n state: VisitorsInternalState,\n): void {\n const openingElement = node.openingElement;\n\n if (\n openingElement.name.type !== \"JSXIdentifier\" ||\n openingElement.name.name !== \"html\"\n ) {\n return;\n }\n\n // Check if lang attribute already exists\n const hasLangAttr = openingElement.attributes.some((attr) => {\n return (\n attr.type === \"JSXAttribute\" &&\n attr.name.type === \"JSXIdentifier\" &&\n (attr.name.name === \"lang\" || attr.name.name === \"language\")\n );\n });\n\n if (hasLangAttr) {\n // Already has lang attribute, don't inject\n return;\n }\n\n // Check if we're inside a component (has access to locale context)\n const component = state.componentsStack.at(-1);\n if (!component) {\n // Not inside a component, can't inject locale\n return;\n }\n\n // Inject lang={locale} attribute\n // This creates: <html lang={locale}>\n const langAttr = t.jsxAttribute(\n t.jsxIdentifier(\"lang\"),\n t.jsxExpressionContainer(t.identifier(\"locale\")),\n );\n\n openingElement.attributes.push(langAttr);\n\n logger.debug(\n `Injected locale attribute into <html> element in component: ${component.name}`,\n );\n\n // Mark that this component needs locale destructured from the hook\n state.componentsNeedingLocale.add(component.name);\n}\n\n/**\n * Inject translation hook into a component when it's done processing\n * Called when popping component from stack\n */\nexport function injectTranslationHook(\n path: NodePath<\n t.FunctionDeclaration | t.FunctionExpression | t.ArrowFunctionExpression\n >,\n component: ComponentEntry,\n state: VisitorsInternalState,\n): void {\n const needsLocale = state.componentsNeedingLocale.has(component.name);\n const collected = state.componentHashes.get(component.name);\n // A constant read in two places registers its strings twice.\n const hashes = collected && [...new Set(collected)];\n if ((!hashes || hashes.length === 0) && !needsLocale) {\n return; // No translations needed\n }\n\n if (component.isAsync) {\n // Async component uses getServerTranslations\n injectServerHook(path, hashes ?? [], needsLocale, component.translator);\n state.needsAsyncImport = true;\n } else {\n // Non-async component uses unified hook (useTranslation)\n injectUnifiedHook(path, hashes ?? [], needsLocale, component.translator);\n state.needsUnifiedImport = true;\n }\n}\n\n/**\n * Add translation imports at the top of the file\n * Called on Program exit after all components have been processed\n */\nfunction addTranslationImports(\n programPath: NodePath<t.Program>,\n state: VisitorsInternalState,\n): void {\n // A file can have both async and non-async components!\n if (state.needsAsyncImport) {\n programPath.node.body.unshift(constructServerImport());\n }\n if (state.needsUnifiedImport) {\n programPath.node.body.unshift(comstructUnifiedImport());\n }\n}\n\n/**\n * Handle component function detection and state update\n */\nfunction processComponentFunction(\n path: NodePath<\n t.FunctionDeclaration | t.FunctionExpression | t.ArrowFunctionExpression\n >,\n state: VisitorsInternalState,\n): void {\n if (!isReactComponent(path)) {\n path.skip();\n logger.debug(`Skipping non-React component: ${path.node.type}`);\n return;\n }\n\n const componentName = inferComponentName(path);\n if (!componentName) {\n path.skip();\n return;\n }\n\n // A lowercase nested function is a helper, not a component: a hook of its own\n // would be invalid. Unpushed, its strings go through the enclosing component.\n if (state.componentsStack.length > 0 && !isComponentName(componentName)) {\n logger.debug(`Folding helper ${componentName} into its component`);\n return;\n }\n\n // Store component info for later hook injection\n if (!state.componentHashes.has(componentName)) {\n state.componentHashes.set(componentName, []);\n }\n\n // Push component to stack with async info and path reference\n const componentEntry: ComponentEntry = {\n name: componentName,\n isAsync: path.node.async,\n translator: translatorNameFor(path),\n };\n state.componentsStack.push(componentEntry);\n logger.debug(`Component ${JSON.stringify(componentEntry)} entered`);\n\n path.setData(\"componentName\", componentName);\n // Before rich text, which would otherwise lift a conditional into a parameter\n // before its branches were seen.\n path.traverse(expressionStringVisitors, { visitorState: state });\n path.traverse(componentVisitors, { visitorState: state });\n const component = state.componentsStack.pop();\n if (component) {\n injectTranslationHook(path, component, state);\n }\n // We have already traversed the path's children so the main traverse can skip it.\n path.skip();\n}\n\nconst expressionStringVisitors = {\n JSXExpressionContainer(path: NodePath<t.JSXExpressionContainer>) {\n translateExpressionStrings(path, this.visitorState);\n },\n // A nested component runs its own pass; a helper's literals belong to its component.\n FunctionDeclaration(path: NodePath<t.FunctionDeclaration>) {\n if (isNestedComponent(path)) path.skip();\n },\n ArrowFunctionExpression(path: NodePath<t.ArrowFunctionExpression>) {\n if (isNestedComponent(path)) path.skip();\n },\n FunctionExpression(path: NodePath<t.FunctionExpression>) {\n if (isNestedComponent(path)) path.skip();\n },\n} satisfies TraverseOptions<{ visitorState: VisitorsInternalState }>;\n\nconst componentVisitors = {\n // 1. Handle nested components. FunctionDeclaration|FunctionExpression|ArrowFunctionExpression unfortunately doesn't give the correct type signature for the path.\n FunctionDeclaration(path: NodePath<t.FunctionDeclaration>) {\n processComponentFunction(path, this.visitorState);\n },\n ArrowFunctionExpression(path: NodePath<t.ArrowFunctionExpression>) {\n processComponentFunction(path, this.visitorState);\n },\n FunctionExpression(path: NodePath<t.FunctionExpression>) {\n processComponentFunction(path, this.visitorState);\n },\n // 2. Fragments are separate from other JSX elements. Both <> and <Fragment> are the same AST node type.\n JSXFragment(path: NodePath<t.JSXFragment>) {\n // No attributes to translate on the fragment, so we only check if it has mixed content. If it doesn't, go ahead and its children will be checked.\n // We also do not check for translation skip, because fragments are mostly used to make the bare text translatable.\n // But if we want to support <Fragment data-weglot-skip>Text</Fragment> we should do it here.\n processJSXElement(path, this.visitorState);\n },\n\n // Transform JSX elements with mixed content (text + expressions or nested elements)\n JSXElement(path: NodePath<t.JSXElement>) {\n translateAttributes(path.node, this.visitorState);\n\n // Inject locale attribute into <html> elements for Next.js\n injectHtmlLangAttribute(path.node, this.visitorState);\n\n if (shouldSkipTranslationForElement(path.node)) {\n path.skip();\n return;\n }\n processJSXElement(path, this.visitorState);\n },\n} satisfies TraverseOptions<{ visitorState: VisitorsInternalState }>;\n\nconst fileVisitors = {\n // Handle static metadata exports: export const metadata = { ... }\n ExportNamedDeclaration(path: NodePath<t.ExportNamedDeclaration>) {\n // Check if the export is a metadata export and converts it to a function\n const metadataState = processNextStaticMetadata(path, {\n filePath: this.visitorState.filePath,\n });\n\n if (metadataState) {\n updateWithMetadataState(this.visitorState, metadataState);\n }\n },\n\n // All component function types share the same handler\n FunctionDeclaration(path: NodePath<t.FunctionDeclaration>) {\n const metadataState = processNextDynamicMetadata(path, {\n filePath: this.visitorState.filePath,\n });\n if (metadataState) {\n updateWithMetadataState(this.visitorState, metadataState);\n }\n\n // Otherwise, handle as component\n processComponentFunction(path, this.visitorState);\n },\n\n // export const MyComponent = () => {}\n ArrowFunctionExpression(path: NodePath<t.ArrowFunctionExpression>) {\n processComponentFunction(path, this.visitorState);\n },\n\n // All these are considered function expressions\n // const myFunction = function() {\n // return 'hello';\n // };\n //\n // const myFunction2 = function namedFunc() {\n // return 'hello';\n // };\n //\n // setTimeout(function() {\n // console.log('hello');\n // }, 1000);\n // While\n // export default function() {}\n // is not\n FunctionExpression(path: NodePath<t.FunctionExpression>) {\n processComponentFunction(path, this.visitorState);\n },\n} satisfies TraverseOptions<{ visitorState: VisitorsInternalState }>;\n\n/**\n * Create Babel visitors for auto-translation (single-pass transformation)\n */\nconst programVisitor = {\n Program: {\n enter(path: NodePath<t.Program>) {\n // We do the check on the loader level, but since they could be false positive, accepting the files we don't need to process, we do the check here as well.\n if (this.visitorState.needsDirective && !hasUseI18nDirective(path)) {\n path.skip();\n return;\n }\n\n path.traverse(fileVisitors, {\n visitorState: this.visitorState,\n });\n },\n\n exit(path: NodePath<t.Program>) {\n if (\n this.visitorState.needsUnifiedImport ||\n this.visitorState.needsAsyncImport\n ) {\n addTranslationImports(path, this.visitorState);\n }\n },\n },\n} satisfies TraverseOptions<{ visitorState: VisitorsInternalState }>;\n\nexport function processFile(\n ast: t.Node,\n options: {\n relativeFilePath: string;\n needsDirective: boolean;\n translatableAttributes?: Record<string, string[]>;\n },\n) {\n const state: VisitorsInternalState = {\n needsDirective: options.needsDirective,\n filePath: options.relativeFilePath,\n newEntries: [],\n componentsStack: [],\n componentHashes: new Map<string, string[]>(),\n needsUnifiedImport: false,\n needsAsyncImport: false,\n componentsNeedingLocale: new Set<string>(),\n translatableAttributes: options.translatableAttributes ?? {},\n importAliases: collectImportAliases(ast),\n };\n\n traverse(ast, programVisitor, undefined, { visitorState: state });\n\n return state.newEntries;\n}\n"],"mappings":";;;;;;;;;;;;;;;AA2EA,SAAS,wBACP,OACA,UACuB;AACvB,OAAM,aAAa,CAAC,GAAG,MAAM,YAAY,GAAG,SAAS,WAAW;AAChE,OAAM,mBAAmB,MAAM,oBAAoB,SAAS;AAC5D,QAAO;;AAGT,MAAM,iBAAiB;;;;;;AAOvB,MAAM,4BAA4B,IAAI,IAAI;CACxC;CACA;CACA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,MAAM,iBAAiB,EACrB,SAAS;CACP,MAAM,MAA2B;AAE/B,MAAI,KAAK,aAAa,kBAAkB,CAAC,oBAAoB,KAAK,EAAE;AAClE,QAAK,MAAM;AACX;;AAGF,OAAK,SAAS,cAAc,EAC1B,cAAc,KAAK,cACpB,CAAC;;CAGJ,KAAK,MAA2B;AAC9B,MACE,KAAK,aAAa,sBAClB,KAAK,aAAa,iBAElB,uBAAsB,MAAM,KAAK,aAAa;;CAGnD,EACF;AAED,SAAgB,YACd,KACA,SAKA;CACA,MAAMC,QAA+B;EACnC,gBAAgB,QAAQ;EACxB,UAAU,QAAQ;EAClB,YAAY,EAAE;EACd,iBAAiB,EAAE;EACnB,iCAAiB,IAAI,KAAuB;EAC5C,oBAAoB;EACpB,kBAAkB;EAClB,yCAAyB,IAAI,KAAa;EAC1C,wBAAwB,QAAQ,0BAA0B,EAAE;EAC5D,eAAe,qBAAqB,IAAI;EACzC;AAED,UAAS,KAAK,gBAAgB,QAAW,EAAE,cAAc,OAAO,CAAC;AAEjE,QAAO,MAAM"}
@@ -0,0 +1,8 @@
1
+
2
+ //#region src/plugin/transform/use-i18n.ts
3
+ const useI18n = "use i18n";
4
+ const useI18nRegex = /* @__PURE__ */ new RegExp(`["']${useI18n}["']`);
5
+
6
+ //#endregion
7
+ exports.useI18n = useI18n;
8
+ exports.useI18nRegex = useI18nRegex;
@@ -0,0 +1,7 @@
1
+ //#region src/plugin/transform/use-i18n.ts
2
+ const useI18n = "use i18n";
3
+ const useI18nRegex = /* @__PURE__ */ new RegExp(`["']${useI18n}["']`);
4
+
5
+ //#endregion
6
+ export { useI18n, useI18nRegex };
7
+ //# sourceMappingURL=use-i18n.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-i18n.mjs","names":[],"sources":["../../../src/plugin/transform/use-i18n.ts"],"sourcesContent":["export const useI18n = \"use i18n\";\nexport const useI18nRegex = new RegExp(`[\"']${useI18n}[\"']`);\n"],"mappings":";AAAA,MAAa,UAAU;AACvB,MAAa,+BAAe,IAAI,OAAO,OAAO,QAAQ,MAAM"}