@openrewrite/recipes-react 0.20.0 → 0.22.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 (276) hide show
  1. package/dist/i18n/translate-hard-coded-strings.d.ts +67 -0
  2. package/dist/i18n/translate-hard-coded-strings.d.ts.map +1 -0
  3. package/dist/i18n/translate-hard-coded-strings.js +439 -0
  4. package/dist/i18n/translate-hard-coded-strings.js.map +1 -0
  5. package/dist/index.d.ts +3 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +37 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/mui/adapt-v4-theme.d.ts +8 -0
  10. package/dist/mui/adapt-v4-theme.d.ts.map +1 -0
  11. package/dist/mui/adapt-v4-theme.js +65 -0
  12. package/dist/mui/adapt-v4-theme.js.map +1 -0
  13. package/dist/mui/add-component-prop.d.ts +18 -0
  14. package/dist/mui/add-component-prop.d.ts.map +1 -0
  15. package/dist/mui/add-component-prop.js +53 -0
  16. package/dist/mui/add-component-prop.js.map +1 -0
  17. package/dist/mui/add-emotion-prepend.d.ts +8 -0
  18. package/dist/mui/add-emotion-prepend.d.ts.map +1 -0
  19. package/dist/mui/add-emotion-prepend.js +71 -0
  20. package/dist/mui/add-emotion-prepend.js.map +1 -0
  21. package/dist/mui/change-module-specifier.d.ts +14 -0
  22. package/dist/mui/change-module-specifier.d.ts.map +1 -0
  23. package/dist/mui/change-module-specifier.js +95 -0
  24. package/dist/mui/change-module-specifier.js.map +1 -0
  25. package/dist/mui/convert-mui-imports.d.ts +14 -0
  26. package/dist/mui/convert-mui-imports.d.ts.map +1 -0
  27. package/dist/mui/convert-mui-imports.js +195 -0
  28. package/dist/mui/convert-mui-imports.js.map +1 -0
  29. package/dist/mui/convert-prop-to-sx.d.ts +22 -0
  30. package/dist/mui/convert-prop-to-sx.d.ts.map +1 -0
  31. package/dist/mui/convert-prop-to-sx.js +99 -0
  32. package/dist/mui/convert-prop-to-sx.js.map +1 -0
  33. package/dist/mui/index.d.ts +32 -0
  34. package/dist/mui/index.d.ts.map +1 -0
  35. package/dist/mui/index.js +67 -0
  36. package/dist/mui/index.js.map +1 -0
  37. package/dist/mui/jsx-attributes.d.ts +27 -0
  38. package/dist/mui/jsx-attributes.d.ts.map +1 -0
  39. package/dist/mui/jsx-attributes.js +140 -0
  40. package/dist/mui/jsx-attributes.js.map +1 -0
  41. package/dist/mui/mark-manual-migration.d.ts +16 -0
  42. package/dist/mui/mark-manual-migration.d.ts.map +1 -0
  43. package/dist/mui/mark-manual-migration.js +73 -0
  44. package/dist/mui/mark-manual-migration.js.map +1 -0
  45. package/dist/mui/mark-palette-mode-usage.d.ts +12 -0
  46. package/dist/mui/mark-palette-mode-usage.d.ts.map +1 -0
  47. package/dist/mui/mark-palette-mode-usage.js +50 -0
  48. package/dist/mui/mark-palette-mode-usage.js.map +1 -0
  49. package/dist/mui/move-component-prop-to-slot.d.ts +22 -0
  50. package/dist/mui/move-component-prop-to-slot.d.ts.map +1 -0
  51. package/dist/mui/move-component-prop-to-slot.js +87 -0
  52. package/dist/mui/move-component-prop-to-slot.js.map +1 -0
  53. package/dist/mui/move-primary-text-to-children.d.ts +12 -0
  54. package/dist/mui/move-primary-text-to-children.d.ts.map +1 -0
  55. package/dist/mui/move-primary-text-to-children.js +52 -0
  56. package/dist/mui/move-primary-text-to-children.js.map +1 -0
  57. package/dist/mui/move-system-props-to-sx.d.ts +16 -0
  58. package/dist/mui/move-system-props-to-sx.d.ts.map +1 -0
  59. package/dist/mui/move-system-props-to-sx.js +122 -0
  60. package/dist/mui/move-system-props-to-sx.js.map +1 -0
  61. package/dist/mui/mui-components.d.ts +8 -0
  62. package/dist/mui/mui-components.d.ts.map +1 -0
  63. package/dist/mui/mui-components.js +41 -0
  64. package/dist/mui/mui-components.js.map +1 -0
  65. package/dist/mui/mui-tag-visitor.d.ts +5 -0
  66. package/dist/mui/mui-tag-visitor.d.ts.map +1 -0
  67. package/dist/mui/mui-tag-visitor.js +54 -0
  68. package/dist/mui/mui-tag-visitor.js.map +1 -0
  69. package/dist/mui/pre-v5-recipe.d.ts +14 -0
  70. package/dist/mui/pre-v5-recipe.d.ts.map +1 -0
  71. package/dist/mui/pre-v5-recipe.js +88 -0
  72. package/dist/mui/pre-v5-recipe.js.map +1 -0
  73. package/dist/mui/remove-component-prop.d.ts +18 -0
  74. package/dist/mui/remove-component-prop.d.ts.map +1 -0
  75. package/dist/mui/remove-component-prop.js +55 -0
  76. package/dist/mui/remove-component-prop.js.map +1 -0
  77. package/dist/mui/remove-root-ref.d.ts +8 -0
  78. package/dist/mui/remove-root-ref.d.ts.map +1 -0
  79. package/dist/mui/remove-root-ref.js +61 -0
  80. package/dist/mui/remove-root-ref.js.map +1 -0
  81. package/dist/mui/remove-spacing-px-suffix.d.ts +8 -0
  82. package/dist/mui/remove-spacing-px-suffix.d.ts.map +1 -0
  83. package/dist/mui/remove-spacing-px-suffix.js +62 -0
  84. package/dist/mui/remove-spacing-px-suffix.js.map +1 -0
  85. package/dist/mui/rename-component-prop.d.ts +20 -0
  86. package/dist/mui/rename-component-prop.d.ts.map +1 -0
  87. package/dist/mui/rename-component-prop.js +66 -0
  88. package/dist/mui/rename-component-prop.js.map +1 -0
  89. package/dist/mui/rename-joy-css-variables.d.ts +8 -0
  90. package/dist/mui/rename-joy-css-variables.d.ts.map +1 -0
  91. package/dist/mui/rename-joy-css-variables.js +51 -0
  92. package/dist/mui/rename-joy-css-variables.js.map +1 -0
  93. package/dist/mui/rename-theme-palette-type.d.ts +8 -0
  94. package/dist/mui/rename-theme-palette-type.d.ts.map +1 -0
  95. package/dist/mui/rename-theme-palette-type.js +61 -0
  96. package/dist/mui/rename-theme-palette-type.js.map +1 -0
  97. package/dist/mui/replace-box-border-radius.d.ts +10 -0
  98. package/dist/mui/replace-box-border-radius.d.ts.map +1 -0
  99. package/dist/mui/replace-box-border-radius.js +50 -0
  100. package/dist/mui/replace-box-border-radius.js.map +1 -0
  101. package/dist/mui/replace-breakpoints-width.d.ts +8 -0
  102. package/dist/mui/replace-breakpoints-width.d.ts.map +1 -0
  103. package/dist/mui/replace-breakpoints-width.js +46 -0
  104. package/dist/mui/replace-breakpoints-width.js.map +1 -0
  105. package/dist/mui/replace-component-class.d.ts +18 -0
  106. package/dist/mui/replace-component-class.d.ts.map +1 -0
  107. package/dist/mui/replace-component-class.js +126 -0
  108. package/dist/mui/replace-component-class.js.map +1 -0
  109. package/dist/mui/replace-components-with-slots.d.ts +14 -0
  110. package/dist/mui/replace-components-with-slots.d.ts.map +1 -0
  111. package/dist/mui/replace-components-with-slots.js +69 -0
  112. package/dist/mui/replace-components-with-slots.js.map +1 -0
  113. package/dist/mui/replace-import-paths.d.ts +14 -0
  114. package/dist/mui/replace-import-paths.d.ts.map +1 -0
  115. package/dist/mui/replace-import-paths.js +101 -0
  116. package/dist/mui/replace-import-paths.js.map +1 -0
  117. package/dist/mui/replace-in-string-literals.d.ts +15 -0
  118. package/dist/mui/replace-in-string-literals.d.ts.map +1 -0
  119. package/dist/mui/replace-in-string-literals.js +62 -0
  120. package/dist/mui/replace-in-string-literals.js.map +1 -0
  121. package/dist/mui/replace-list-item-button-prop.d.ts +12 -0
  122. package/dist/mui/replace-list-item-button-prop.d.ts.map +1 -0
  123. package/dist/mui/replace-list-item-button-prop.js +80 -0
  124. package/dist/mui/replace-list-item-button-prop.js.map +1 -0
  125. package/dist/mui/replace-tabs-scroll-buttons.d.ts +8 -0
  126. package/dist/mui/replace-tabs-scroll-buttons.d.ts.map +1 -0
  127. package/dist/mui/replace-tabs-scroll-buttons.js +41 -0
  128. package/dist/mui/replace-tabs-scroll-buttons.js.map +1 -0
  129. package/dist/mui/replace-theme-color-functions.d.ts +8 -0
  130. package/dist/mui/replace-theme-color-functions.d.ts.map +1 -0
  131. package/dist/mui/replace-theme-color-functions.js +72 -0
  132. package/dist/mui/replace-theme-color-functions.js.map +1 -0
  133. package/dist/mui/replace-theme-spacing-unit.d.ts +8 -0
  134. package/dist/mui/replace-theme-spacing-unit.d.ts.map +1 -0
  135. package/dist/mui/replace-theme-spacing-unit.js +77 -0
  136. package/dist/mui/replace-theme-spacing-unit.js.map +1 -0
  137. package/dist/mui/replace-typography-round.d.ts +8 -0
  138. package/dist/mui/replace-typography-round.d.ts.map +1 -0
  139. package/dist/mui/replace-typography-round.js +44 -0
  140. package/dist/mui/replace-typography-round.js.map +1 -0
  141. package/dist/mui/shift-hidden-down-props.d.ts +10 -0
  142. package/dist/mui/shift-hidden-down-props.d.ts.map +1 -0
  143. package/dist/mui/shift-hidden-down-props.js +49 -0
  144. package/dist/mui/shift-hidden-down-props.js.map +1 -0
  145. package/dist/mui/theme-access.d.ts +5 -0
  146. package/dist/mui/theme-access.d.ts.map +1 -0
  147. package/dist/mui/theme-access.js +21 -0
  148. package/dist/mui/theme-access.js.map +1 -0
  149. package/dist/mui/update-theme-breakpoints.d.ts +10 -0
  150. package/dist/mui/update-theme-breakpoints.d.ts.map +1 -0
  151. package/dist/mui/update-theme-breakpoints.js +58 -0
  152. package/dist/mui/update-theme-breakpoints.js.map +1 -0
  153. package/dist/mui/upgrade-grid-props.d.ts +16 -0
  154. package/dist/mui/upgrade-grid-props.d.ts.map +1 -0
  155. package/dist/mui/upgrade-grid-props.js +90 -0
  156. package/dist/mui/upgrade-grid-props.js.map +1 -0
  157. package/dist/search/find-enzyme-usage.d.ts +8 -0
  158. package/dist/search/find-enzyme-usage.d.ts.map +1 -1
  159. package/dist/search/find-enzyme-usage.js +119 -8
  160. package/dist/search/find-enzyme-usage.js.map +1 -1
  161. package/dist/search/find-hard-coded-strings.d.ts +110 -0
  162. package/dist/search/find-hard-coded-strings.d.ts.map +1 -0
  163. package/dist/search/find-hard-coded-strings.js +987 -0
  164. package/dist/search/find-hard-coded-strings.js.map +1 -0
  165. package/dist/search/find-missing-use-client-directive.d.ts +2 -0
  166. package/dist/search/find-missing-use-client-directive.d.ts.map +1 -1
  167. package/dist/search/find-missing-use-client-directive.js +1 -0
  168. package/dist/search/find-missing-use-client-directive.js.map +1 -1
  169. package/dist/testing/enzyme-host-components.d.ts +12 -0
  170. package/dist/testing/enzyme-host-components.d.ts.map +1 -1
  171. package/dist/testing/enzyme-host-components.js +100 -0
  172. package/dist/testing/enzyme-host-components.js.map +1 -1
  173. package/dist/testing/enzyme-portals.d.ts +3 -5
  174. package/dist/testing/enzyme-portals.d.ts.map +1 -1
  175. package/dist/testing/enzyme-portals.js +8 -39
  176. package/dist/testing/enzyme-portals.js.map +1 -1
  177. package/dist/testing/enzyme-render-blockers.d.ts +19 -0
  178. package/dist/testing/enzyme-render-blockers.d.ts.map +1 -0
  179. package/dist/testing/enzyme-render-blockers.js +275 -0
  180. package/dist/testing/enzyme-render-blockers.js.map +1 -0
  181. package/dist/testing/enzyme-to-react-testing-library.d.ts +17 -3
  182. package/dist/testing/enzyme-to-react-testing-library.d.ts.map +1 -1
  183. package/dist/testing/enzyme-to-react-testing-library.js +237 -27
  184. package/dist/testing/enzyme-to-react-testing-library.js.map +1 -1
  185. package/dist/testing/enzyme-usage.d.ts +9 -0
  186. package/dist/testing/enzyme-usage.d.ts.map +1 -1
  187. package/dist/testing/enzyme-usage.js +36 -3
  188. package/dist/testing/enzyme-usage.js.map +1 -1
  189. package/dist/testing/enzyme-wrapper-scope.d.ts +8 -1
  190. package/dist/testing/enzyme-wrapper-scope.d.ts.map +1 -1
  191. package/dist/testing/enzyme-wrapper-scope.js +26 -5
  192. package/dist/testing/enzyme-wrapper-scope.js.map +1 -1
  193. package/dist/util/json-and-javascript.d.ts +4 -0
  194. package/dist/util/json-and-javascript.d.ts.map +1 -0
  195. package/dist/util/json-and-javascript.js +37 -0
  196. package/dist/util/json-and-javascript.js.map +1 -0
  197. package/dist/util/module-imports.d.ts +36 -0
  198. package/dist/util/module-imports.d.ts.map +1 -1
  199. package/dist/util/module-imports.js +216 -0
  200. package/dist/util/module-imports.js.map +1 -1
  201. package/dist/util/test-source.d.ts +2 -0
  202. package/dist/util/test-source.d.ts.map +1 -0
  203. package/dist/util/test-source.js +5 -0
  204. package/dist/util/test-source.js.map +1 -0
  205. package/dist/zustand/entry-store.d.ts +9 -0
  206. package/dist/zustand/entry-store.d.ts.map +1 -0
  207. package/dist/zustand/entry-store.js +136 -0
  208. package/dist/zustand/entry-store.js.map +1 -0
  209. package/dist/zustand/redux-stores.d.ts +7 -4
  210. package/dist/zustand/redux-stores.d.ts.map +1 -1
  211. package/dist/zustand/redux-stores.js +128 -11
  212. package/dist/zustand/redux-stores.js.map +1 -1
  213. package/dist/zustand/redux-to-zustand.d.ts +11 -2
  214. package/dist/zustand/redux-to-zustand.d.ts.map +1 -1
  215. package/dist/zustand/redux-to-zustand.js +147 -46
  216. package/dist/zustand/redux-to-zustand.js.map +1 -1
  217. package/dist/zustand/zustand-plan.d.ts +14 -5
  218. package/dist/zustand/zustand-plan.d.ts.map +1 -1
  219. package/dist/zustand/zustand-plan.js +226 -52
  220. package/dist/zustand/zustand-plan.js.map +1 -1
  221. package/package.json +1 -1
  222. package/src/i18n/translate-hard-coded-strings.ts +442 -0
  223. package/src/index.ts +17 -0
  224. package/src/mui/adapt-v4-theme.ts +43 -0
  225. package/src/mui/add-component-prop.ts +43 -0
  226. package/src/mui/add-emotion-prepend.ts +48 -0
  227. package/src/mui/change-module-specifier.ts +71 -0
  228. package/src/mui/convert-mui-imports.ts +184 -0
  229. package/src/mui/convert-prop-to-sx.ts +89 -0
  230. package/src/mui/index.ts +31 -0
  231. package/src/mui/jsx-attributes.ts +133 -0
  232. package/src/mui/mark-manual-migration.ts +53 -0
  233. package/src/mui/mark-palette-mode-usage.ts +36 -0
  234. package/src/mui/move-component-prop-to-slot.ts +84 -0
  235. package/src/mui/move-primary-text-to-children.ts +41 -0
  236. package/src/mui/move-system-props-to-sx.ts +118 -0
  237. package/src/mui/mui-components.ts +40 -0
  238. package/src/mui/mui-tag-visitor.ts +36 -0
  239. package/src/mui/pre-v5-recipe.ts +82 -0
  240. package/src/mui/remove-component-prop.ts +43 -0
  241. package/src/mui/remove-root-ref.ts +41 -0
  242. package/src/mui/remove-spacing-px-suffix.ts +43 -0
  243. package/src/mui/rename-component-prop.ts +55 -0
  244. package/src/mui/rename-joy-css-variables.ts +41 -0
  245. package/src/mui/rename-theme-palette-type.ts +42 -0
  246. package/src/mui/replace-box-border-radius.ts +42 -0
  247. package/src/mui/replace-breakpoints-width.ts +28 -0
  248. package/src/mui/replace-component-class.ts +97 -0
  249. package/src/mui/replace-components-with-slots.ts +61 -0
  250. package/src/mui/replace-import-paths.ts +100 -0
  251. package/src/mui/replace-in-string-literals.ts +44 -0
  252. package/src/mui/replace-list-item-button-prop.ts +59 -0
  253. package/src/mui/replace-tabs-scroll-buttons.ts +31 -0
  254. package/src/mui/replace-theme-color-functions.ts +55 -0
  255. package/src/mui/replace-theme-spacing-unit.ts +59 -0
  256. package/src/mui/replace-typography-round.ts +29 -0
  257. package/src/mui/shift-hidden-down-props.ts +44 -0
  258. package/src/mui/theme-access.ts +18 -0
  259. package/src/mui/update-theme-breakpoints.ts +47 -0
  260. package/src/mui/upgrade-grid-props.ts +82 -0
  261. package/src/search/find-enzyme-usage.ts +109 -12
  262. package/src/search/find-hard-coded-strings.ts +1006 -0
  263. package/src/search/find-missing-use-client-directive.ts +1 -1
  264. package/src/testing/enzyme-host-components.ts +110 -0
  265. package/src/testing/enzyme-portals.ts +4 -44
  266. package/src/testing/enzyme-render-blockers.ts +278 -0
  267. package/src/testing/enzyme-to-react-testing-library.ts +240 -34
  268. package/src/testing/enzyme-usage.ts +48 -2
  269. package/src/testing/enzyme-wrapper-scope.ts +35 -3
  270. package/src/util/json-and-javascript.ts +26 -0
  271. package/src/util/module-imports.ts +223 -0
  272. package/src/util/test-source.ts +2 -0
  273. package/src/zustand/entry-store.ts +131 -0
  274. package/src/zustand/redux-stores.ts +131 -12
  275. package/src/zustand/redux-to-zustand.ts +179 -52
  276. package/src/zustand/zustand-plan.ts +256 -49
@@ -0,0 +1,987 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
+ return new (P || (P = Promise))(function (resolve, reject) {
11
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
15
+ });
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.HardCodedStringsVisitor = exports.FindHardCodedStrings = exports.FUNCTION_KINDS = exports.HardCodedStringRow = exports.ImportedRenders = exports.HARD_CODED_STRINGS_TABLE = void 0;
19
+ exports.tagName = tagName;
20
+ exports.functionName = functionName;
21
+ exports.stringValue = stringValue;
22
+ exports.dependencyNames = dependencyNames;
23
+ exports.propertyPath = propertyPath;
24
+ exports.jsxText = jsxText;
25
+ const rewrite_1 = require("@openrewrite/rewrite");
26
+ const javascript_1 = require("@openrewrite/rewrite/javascript");
27
+ const json_1 = require("@openrewrite/rewrite/json");
28
+ const java_1 = require("@openrewrite/rewrite/java");
29
+ const json_and_javascript_1 = require("../util/json-and-javascript");
30
+ const module_imports_1 = require("../util/module-imports");
31
+ const test_source_1 = require("../util/test-source");
32
+ const tree_search_1 = require("../util/tree-search");
33
+ exports.HARD_CODED_STRINGS_TABLE = "org.openrewrite.react.search.HardCodedStrings";
34
+ class ImportedRenders {
35
+ constructor() {
36
+ this.sources = new Set();
37
+ this.packages = new Map();
38
+ this.configs = new Map();
39
+ this.exports = new Map();
40
+ this.renders = new Map();
41
+ this.componentRenders = new Map();
42
+ this.forwards = [];
43
+ this.passes = [];
44
+ this.aliases = [];
45
+ this.modules = new Map();
46
+ }
47
+ addRender(from, specifier, name, path, site) {
48
+ const key = [from, specifier, name, path].join("\0");
49
+ if (!this.renders.has(key))
50
+ this.renders.set(key, { from, specifier, name, path, site });
51
+ }
52
+ addComponentRender(file, component, path, site) {
53
+ var _a;
54
+ const key = `${file}\0${component}`;
55
+ const paths = (_a = this.componentRenders.get(key)) !== null && _a !== void 0 ? _a : new Map();
56
+ if (!paths.has(path))
57
+ paths.set(path, site);
58
+ this.componentRenders.set(key, paths);
59
+ }
60
+ addForward(file, component, path, child, prop) {
61
+ this.forwards.push({ file, component, path, child, prop });
62
+ }
63
+ addPass(child, prop, constant, path) {
64
+ this.passes.push({ child, prop, constant, path });
65
+ }
66
+ addAlias(file, constant, path, target) {
67
+ this.aliases.push({ file, constant, path, target });
68
+ }
69
+ rendersProp(child, prop) {
70
+ var _a;
71
+ const component = this.locate(child);
72
+ return !!component && !!((_a = this.componentPaths().get(`${component.file}\0${component.local}`)) === null || _a === void 0 ? void 0 : _a.has(prop));
73
+ }
74
+ siteOf(file, local, path) {
75
+ var _a;
76
+ (_a = this.resolved) !== null && _a !== void 0 ? _a : (this.resolved = this.resolveConstants());
77
+ return this.resolved.get([file, local, path].join("\0"));
78
+ }
79
+ resolveConstants() {
80
+ var _a;
81
+ const resolved = new Map();
82
+ const add = (file, local, path, site) => {
83
+ const key = [file, local, path].join("\0");
84
+ if (!resolved.has(key))
85
+ resolved.set(key, site);
86
+ };
87
+ for (const { from, specifier, name, path, site } of this.renders.values()) {
88
+ const constant = this.locate({ file: from, specifier, name });
89
+ if (constant)
90
+ add(constant.file, constant.local, path, site);
91
+ }
92
+ const paths = this.componentPaths();
93
+ for (const { child, prop, constant, path } of this.passes) {
94
+ const component = this.locate(child);
95
+ const target = this.locate(constant);
96
+ if (!component || !target)
97
+ continue;
98
+ for (const [rendered, site] of (_a = paths.get(`${component.file}\0${component.local}`)) !== null && _a !== void 0 ? _a : []) {
99
+ const rest = pathAfter(rendered, prop);
100
+ if (rest !== undefined)
101
+ add(target.file, target.local, joinPath(path, rest), site);
102
+ }
103
+ }
104
+ for (let changed = true, rounds = 0; changed && rounds < 5; rounds++) {
105
+ changed = false;
106
+ for (const { file, constant, path, target } of this.aliases) {
107
+ for (const [key, site] of [...resolved]) {
108
+ const [keyFile, keyLocal, keyPath] = key.split("\0");
109
+ const rest = keyFile === file && keyLocal === constant ? pathAfter(keyPath, path) : undefined;
110
+ const aliased = rest !== undefined ? [file, target, rest.replace(/^\./, "")].join("\0") : undefined;
111
+ if (aliased && !resolved.has(aliased)) {
112
+ resolved.set(aliased, site);
113
+ changed = true;
114
+ }
115
+ }
116
+ }
117
+ }
118
+ return resolved;
119
+ }
120
+ componentPaths() {
121
+ var _a;
122
+ if (this.rendered)
123
+ return this.rendered;
124
+ const rendered = new Map([...this.componentRenders].map(([key, paths]) => [key, new Map(paths)]));
125
+ for (let changed = true, rounds = 0; changed && rounds < 10; rounds++) {
126
+ changed = false;
127
+ for (const { file, component, path, child, prop } of this.forwards) {
128
+ const target = this.locate(child);
129
+ const childPaths = target && rendered.get(`${target.file}\0${target.local}`);
130
+ if (!childPaths)
131
+ continue;
132
+ const key = `${file}\0${component}`;
133
+ const paths = (_a = rendered.get(key)) !== null && _a !== void 0 ? _a : new Map();
134
+ for (const [childPath, site] of [...childPaths]) {
135
+ const rest = pathAfter(childPath, prop);
136
+ const own = rest !== undefined ? joinPath(path, rest) : undefined;
137
+ if (own !== undefined && !paths.has(own)) {
138
+ paths.set(own, site);
139
+ changed = true;
140
+ }
141
+ }
142
+ rendered.set(key, paths);
143
+ }
144
+ }
145
+ return this.rendered = rendered;
146
+ }
147
+ locate(ref) {
148
+ if (ref.specifier === undefined)
149
+ return { file: ref.file, local: ref.name };
150
+ const target = this.resolveModule(ref.file, ref.specifier);
151
+ return target ? this.exported(target, ref.name, 0) : undefined;
152
+ }
153
+ exported(file, name, hops) {
154
+ const exports = this.exports.get(file);
155
+ const local = exports === null || exports === void 0 ? void 0 : exports.locals.get(name);
156
+ if (local !== undefined)
157
+ return { file, local };
158
+ if (!exports || hops >= 3)
159
+ return undefined;
160
+ for (const { module, names } of exports.reExports) {
161
+ const imported = names === "*" ? (name === "default" ? undefined : name) : names.get(name);
162
+ const target = imported !== undefined ? this.resolveModule(file, module) : undefined;
163
+ const found = target && this.exported(target, imported, hops + 1);
164
+ if (found)
165
+ return found;
166
+ }
167
+ return undefined;
168
+ }
169
+ resolveModule(from, specifier) {
170
+ const key = `${from}\0${specifier}`;
171
+ if (!this.modules.has(key)) {
172
+ const roots = [...this.packages.keys()].filter(root => from.startsWith(root)).sort((a, b) => b.length - a.length);
173
+ const declares = (name) => roots.some(root => this.packages.get(root).has(name));
174
+ const configured = (0, module_imports_1.isAliasSpecifier)(specifier) ? (0, module_imports_1.resolveModule)(from, specifier, this.sources, this.configs) : undefined;
175
+ this.modules.set(key, configured !== null && configured !== void 0 ? configured : (0, module_imports_1.aliasResolver)(this.sources, [...new Set([...roots, ""])], declares)(from, specifier));
176
+ }
177
+ return this.modules.get(key);
178
+ }
179
+ }
180
+ exports.ImportedRenders = ImportedRenders;
181
+ class HardCodedStringRow {
182
+ }
183
+ exports.HardCodedStringRow = HardCodedStringRow;
184
+ __decorate([
185
+ (0, rewrite_1.Column)({ displayName: "Source path", description: "The file containing the string." })
186
+ ], HardCodedStringRow.prototype, "sourcePath", void 0);
187
+ __decorate([
188
+ (0, rewrite_1.Column)({ displayName: "Element", description: "The JSX element the string renders in, empty for a fragment." })
189
+ ], HardCodedStringRow.prototype, "element", void 0);
190
+ __decorate([
191
+ (0, rewrite_1.Column)({ displayName: "Attribute", description: "The attribute holding the string, empty for element text." })
192
+ ], HardCodedStringRow.prototype, "attribute", void 0);
193
+ __decorate([
194
+ (0, rewrite_1.Column)({
195
+ displayName: "Kind",
196
+ description: "`TEXT` for element text, `ATTRIBUTE` for an attribute value, or `MIXED` for a string that needs interpolation or a `<Trans>` component rather than a plain key: a sentence of text with expressions or elements, reported once for the element holding it, or a string with interpolations."
197
+ })
198
+ ], HardCodedStringRow.prototype, "kind", void 0);
199
+ __decorate([
200
+ (0, rewrite_1.Column)({
201
+ displayName: "Context",
202
+ description: "Where the string is rendered from, which decides how it can be translated: `JSX` for element text and attributes, `CALL` for a notification call such as `toast(...)`, `METADATA` for a Next.js `metadata` export, or `VARIABLE` for a variable, object property or array element shown elsewhere, possibly through components' props, whose `element` and `attribute` describe where it is shown, possibly in another file."
203
+ })
204
+ ], HardCodedStringRow.prototype, "context", void 0);
205
+ __decorate([
206
+ (0, rewrite_1.Column)({
207
+ displayName: "Text",
208
+ description: "The string as React renders its whitespace, with HTML entities left as written. A sentence is written as react-i18next's `<Trans>` reads its children, " +
209
+ "such as `Hello <1>{{name}}</1>, read the <3>terms</3>`; a template literal's interpolations as `{0}`, `{1}`."
210
+ })
211
+ ], HardCodedStringRow.prototype, "text", void 0);
212
+ const COMPONENT_TEXT_PROP = /^(?:heading|subheading|subtitle|caption|description|message|tooltip|hint|text|helperText)$|(?:Label|Title|Text|Heading|Caption|Description|Message|Tooltip|Hint|Placeholder)$/;
213
+ const NEXT_METADATA_FILE = /(^|\/)app\/(.*\/)?(page|layout)\.[jt]sx?$/;
214
+ const METADATA_SECTIONS = new Set(["title", "description", "openGraph", "twitter"]);
215
+ const METADATA_TEXT_KEYS = new Set(["title", "description", "default", "absolute"]);
216
+ const TOAST_MODULE = /^(?:sonner|react-hot-toast|react-toastify)$|(?:^|\/)(?:use-)?toast$/;
217
+ const TOAST_METHODS = new Set(["success", "error", "info", "warning", "warn", "loading", "message", "promise"]);
218
+ const TOAST_TEXT_KEYS = new Set(["title", "description", "loading", "success", "error"]);
219
+ const TOAST_BUTTONS = new Set(["action", "cancel"]);
220
+ const OBJECT_WRAPPERS = new Set([java_1.J.Kind.Block, java_1.J.Kind.Parentheses, javascript_1.JS.Kind.SatisfiesExpression, javascript_1.JS.Kind.As]);
221
+ exports.FUNCTION_KINDS = new Set([java_1.J.Kind.MethodDeclaration, java_1.J.Kind.Lambda, javascript_1.JS.Kind.ArrowFunction]);
222
+ const USER_FACING_ATTRIBUTES = new Set([
223
+ "alt", "title", "placeholder", "label",
224
+ "aria-label", "aria-description", "aria-placeholder", "aria-roledescription", "aria-valuetext",
225
+ ]);
226
+ const VERBATIM_ELEMENTS = new Set(["code", "pre", "kbd", "script", "style"]);
227
+ const I18N_MODULE = /^(?:@lingui\/|@formatjs\/|react-intl$|react-i18next$|next-i18next$|next-intl(?:\/|$))/;
228
+ const NON_PRODUCT_SOURCE = /(^|\/)(examples?|__dev__|dev-?tools|\.storybook|__fixtures__|fixtures|developer|debug)(\/|$)|(^|\/)[^/]*playground[^/]*(\/|$)|(^|\/)(developer|[^/]*debug[^/]*)\.[cm]?[jt]sx?$|\.mocks?(-data)?\.[cm]?[jt]sx?$/i;
229
+ const LETTERS = /\p{L}/gu;
230
+ const IDEOGRAPHIC = /[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]/u;
231
+ const IDENTIFIER_LIKE = /^(?:[a-z]+(?:[A-Z][a-z\d]*)+|[a-z\d]+(?:_[a-z\d]+)+|[A-Z\d]+(?:_[A-Z\d]+)+)$/;
232
+ const ENTITY = /&(?:#\d+|#x[\da-f]+|[a-z][a-z\d]*);/gi;
233
+ const URL_EMAIL_DOMAIN_OR_PATH = /^(?:[a-z][\w+.-]*:\/\/\S*|[^\s@]+@[^\s@]+\.[^\s@]+|\.?[\w-]+(?:\.[\w-]+)+\/?|\/[\w./-]*|#[\da-f]{3,8})$/i;
234
+ class FindHardCodedStrings extends rewrite_1.ScanningRecipe {
235
+ constructor() {
236
+ super(...arguments);
237
+ this.name = "org.openrewrite.react.search.find-hard-coded-strings";
238
+ this.displayName = "Find hard-coded user-facing strings";
239
+ this.description = "Finds hard-coded strings that React apps show to users, as a starting point for internationalization. " +
240
+ "Reports JSX text; string and template literal values of user-facing attributes (`alt`, `title`, `placeholder`, `label`, text-bearing `aria-*`) " +
241
+ "and of component text props such as `heading`, `text` or names ending in `Label`, `Title`, `Text` or `Message`; " +
242
+ "strings in variables, and in properties and array elements of objects, that the same file or an importing file shows, " +
243
+ "directly or through the props of the components it renders, `.map` callbacks included; string props a component shows; " +
244
+ "following relative, `baseUrl` and `@/` alias imports of named, default and namespace exports through up to three re-exports; " +
245
+ "titles and descriptions in Next.js `metadata` and `generateMetadata`; " +
246
+ "and messages passed to `toast(...)` from sonner, react-hot-toast, react-toastify or a local `toast`/`use-toast` module. " +
247
+ "Strings that need interpolation or `<Trans>` are marked `MIXED`; a sentence split by expressions or elements is one row, written as `<Trans>` reads it. " +
248
+ "Skips test, story, mock-data, example-app, playground, developer and debug sources; " +
249
+ "anything inside `<Trans>` or components imported from Lingui, react-intl, react-i18next, next-i18next or next-intl; " +
250
+ "text in `<code>`, `<pre>`, `<kbd>`, `<script>` and `<style>`; strings without a word (two letters, or one ideograph); " +
251
+ "and strings made of a single URL, email address, domain, path, hex colour, or camelCase, snake_case or CONSTANT_CASE identifier. " +
252
+ "Strings whose way to the screen goes through state, context or functions other than array callbacks are not followed.";
253
+ this.table = new rewrite_1.DataTable(exports.HARD_CODED_STRINGS_TABLE, "Hard-coded strings", "Hard-coded strings that React components render to users.", HardCodedStringRow);
254
+ }
255
+ initialValue() {
256
+ return new ImportedRenders();
257
+ }
258
+ scanner(acc) {
259
+ return __awaiter(this, void 0, void 0, function* () {
260
+ const sources = yield (0, rewrite_1.check)((0, rewrite_1.not)((0, javascript_1.isVendoredOrBundled)()), new HardCodedStringsVisitor(acc));
261
+ const manifests = new class extends json_1.JsonVisitor {
262
+ visitDocument(doc) {
263
+ return __awaiter(this, void 0, void 0, function* () {
264
+ if (!acc)
265
+ return doc;
266
+ if (/(^|\/)package\.json$/.test(doc.sourcePath))
267
+ acc.packages.set(doc.sourcePath.slice(0, -"package.json".length), dependencyNames(doc));
268
+ yield (0, module_imports_1.addPathsConfig)(acc.configs, doc);
269
+ return doc;
270
+ });
271
+ }
272
+ }();
273
+ return (0, json_and_javascript_1.jsonAndJavaScript)(manifests, sources);
274
+ });
275
+ }
276
+ editorWithData(acc) {
277
+ return __awaiter(this, void 0, void 0, function* () {
278
+ return (0, rewrite_1.check)((0, rewrite_1.not)((0, javascript_1.isVendoredOrBundled)()), new HardCodedStringsVisitor(acc, this.table));
279
+ });
280
+ }
281
+ }
282
+ exports.FindHardCodedStrings = FindHardCodedStrings;
283
+ class HardCodedStringsVisitor extends javascript_1.JavaScriptVisitor {
284
+ constructor(acc, table) {
285
+ super();
286
+ this.acc = acc;
287
+ this.table = table;
288
+ this.sourcePath = "";
289
+ this.nextMetadataFile = false;
290
+ this.toastNames = new Set();
291
+ this.i18nComponents = new Set();
292
+ this.translated = 0;
293
+ this.verbatim = 0;
294
+ this.covered = new Set();
295
+ this.imports = new Map();
296
+ this.namespaces = new Map();
297
+ this.constants = [];
298
+ this.rendered = new Map();
299
+ }
300
+ visitJsCompilationUnit(cu, ctx) {
301
+ const _super = Object.create(null, {
302
+ visitJsCompilationUnit: { get: () => super.visitJsCompilationUnit }
303
+ });
304
+ return __awaiter(this, void 0, void 0, function* () {
305
+ var _a, _b;
306
+ if (test_source_1.TEST_SOURCE.test(cu.sourcePath) || NON_PRODUCT_SOURCE.test(cu.sourcePath))
307
+ return cu;
308
+ this.sourcePath = cu.sourcePath;
309
+ this.nextMetadataFile = NEXT_METADATA_FILE.test(cu.sourcePath);
310
+ const imports = (0, module_imports_1.importBindings)(cu);
311
+ this.imports = new Map(imports.map(b => [b.local, { module: b.module, name: b.name }]));
312
+ this.namespaces = (0, module_imports_1.namespaceImportModules)(cu);
313
+ this.i18nComponents = new Set(imports.filter(b => I18N_MODULE.test(b.module)).map(b => b.local));
314
+ const toastImports = imports.filter(b => TOAST_MODULE.test(b.module));
315
+ this.toastNames = new Set(toastImports.filter(b => b.name === "toast" || b.name === "default").map(b => b.local));
316
+ if (toastImports.some(b => /^use[A-Z]/.test(b.name)))
317
+ this.toastNames.add("toast");
318
+ this.constants = [];
319
+ this.rendered = new Map();
320
+ this.covered = new Set();
321
+ if (!this.table) {
322
+ (_a = this.acc) === null || _a === void 0 ? void 0 : _a.sources.add(cu.sourcePath);
323
+ (_b = this.acc) === null || _b === void 0 ? void 0 : _b.exports.set(cu.sourcePath, (0, module_imports_1.moduleExports)(cu));
324
+ return _super.visitJsCompilationUnit.call(this, cu, ctx);
325
+ }
326
+ const visited = yield _super.visitJsCompilationUnit.call(this, cu, ctx);
327
+ return this.reportConstants(visited, ctx);
328
+ });
329
+ }
330
+ visitJsxTag(tag, ctx) {
331
+ const _super = Object.create(null, {
332
+ visitJsxTag: { get: () => super.visitJsxTag }
333
+ });
334
+ return __awaiter(this, void 0, void 0, function* () {
335
+ const segments = tagName(tag).split(".");
336
+ const translated = +(this.i18nComponents.has(segments[0]) || segments[segments.length - 1] === "Trans");
337
+ const verbatim = +VERBATIM_ELEMENTS.has(segments[0]);
338
+ this.translated += translated;
339
+ this.verbatim += verbatim;
340
+ try {
341
+ const sentence = this.table && this.translated === 0 && this.verbatim === 0 && isSentenceRoot(tag, this.cursor) ? transContent(tag.children, this.covered) : undefined;
342
+ if (sentence !== undefined && isTranslatable(transPlainText(sentence))) {
343
+ this.insertRow(ctx, { element: tagName(tag), attribute: "", mixed: true, context: "JSX" }, sentence, true, tag);
344
+ return (0, rewrite_1.foundSearchResult)(yield _super.visitJsxTag.call(this, tag, ctx));
345
+ }
346
+ return yield _super.visitJsxTag.call(this, tag, ctx);
347
+ }
348
+ finally {
349
+ this.translated -= translated;
350
+ this.verbatim -= verbatim;
351
+ }
352
+ });
353
+ }
354
+ visitLiteral(literal, ctx) {
355
+ return __awaiter(this, void 0, void 0, function* () {
356
+ var _a;
357
+ const value = stringValue(literal);
358
+ if (!this.table || value === undefined || this.translated > 0 || this.covered.has(literal.id) || !isTranslatable(value.trim()))
359
+ return literal;
360
+ const site = (_a = this.siteOf()) !== null && _a !== void 0 ? _a : this.interpolationSite();
361
+ if (!site) {
362
+ this.collectConstant(literal, value.trim(), false);
363
+ return literal;
364
+ }
365
+ const text = site.attribute ? value.trim() : jsxText(value).replace(/^ +| +$/g, "");
366
+ return this.report(ctx, literal, site, text, false);
367
+ });
368
+ }
369
+ visitIdentifier(identifier, ctx) {
370
+ const _super = Object.create(null, {
371
+ visitIdentifier: { get: () => super.visitIdentifier }
372
+ });
373
+ return __awaiter(this, void 0, void 0, function* () {
374
+ var _a;
375
+ if (this.translated === 0 && (this.table || this.imports.has(identifier.simpleName))) {
376
+ const site = (_a = this.siteOf()) !== null && _a !== void 0 ? _a : this.interpolationSite();
377
+ if (site)
378
+ this.markRendered(identifier, site, "");
379
+ }
380
+ if (this.translated === 0 && !this.table) {
381
+ this.recordPropFlow(identifier, [], this.cursor);
382
+ this.recordAlias(identifier);
383
+ }
384
+ return _super.visitIdentifier.call(this, identifier, ctx);
385
+ });
386
+ }
387
+ visitFieldAccess(fieldAccess, ctx) {
388
+ const _super = Object.create(null, {
389
+ visitFieldAccess: { get: () => super.visitFieldAccess }
390
+ });
391
+ return __awaiter(this, void 0, void 0, function* () {
392
+ var _a;
393
+ const chain = memberChain(fieldAccess, this.cursor);
394
+ const root = chain === null || chain === void 0 ? void 0 : chain.root.simpleName;
395
+ if (chain && this.translated === 0 && (this.table || this.imports.has(root) || this.namespaces.has(root))) {
396
+ const site = (_a = this.siteOf()) !== null && _a !== void 0 ? _a : this.interpolationSite();
397
+ if (site)
398
+ this.markRendered(chain.root, site, chain.names.join("."), chain.holder);
399
+ }
400
+ if (chain && this.translated === 0 && !this.table)
401
+ this.recordPropFlow(chain.root, chain.names, chain.holder);
402
+ return _super.visitFieldAccess.call(this, fieldAccess, ctx);
403
+ });
404
+ }
405
+ visitTemplateExpression(template, ctx) {
406
+ const _super = Object.create(null, {
407
+ visitTemplateExpression: { get: () => super.visitTemplateExpression }
408
+ });
409
+ return __awaiter(this, void 0, void 0, function* () {
410
+ const t = yield _super.visitTemplateExpression.call(this, template, ctx);
411
+ if (!this.table)
412
+ return t;
413
+ const parts = [t.head, ...t.spans.map(span => span.element.tail)].map(part => { var _a; return (_a = stringValue(part)) !== null && _a !== void 0 ? _a : ""; });
414
+ if (this.translated > 0 || !isTranslatable(parts.join("").trim()))
415
+ return t;
416
+ const text = parts.map((part, i) => (i > 0 ? `{${i - 1}}` : "") + part).join("").trim();
417
+ const site = this.siteOf();
418
+ if (!site) {
419
+ this.collectConstant(t, text, t.spans.length > 0);
420
+ return t;
421
+ }
422
+ return this.report(ctx, t, site, text, t.spans.length > 0);
423
+ });
424
+ }
425
+ collectConstant(node, text, interpolated) {
426
+ var _a, _b;
427
+ const { keys, owner, object } = objectPath(this.cursor);
428
+ const declaration = owner === null || owner === void 0 ? void 0 : owner.value;
429
+ const declared = (declaration === null || declaration === void 0 ? void 0 : declaration.kind) === java_1.J.Kind.NamedVariable && (keys.length === 0 || ((_a = declaration.initializer) === null || _a === void 0 ? void 0 : _a.element) === object.value) ?
430
+ declaration.name :
431
+ keys.length === 0 && (declaration === null || declaration === void 0 ? void 0 : declaration.kind) === javascript_1.JS.Kind.BindingElement && ((_b = declaration.initializer) === null || _b === void 0 ? void 0 : _b.element) === object.value ?
432
+ declaration.name :
433
+ undefined;
434
+ if (!declared || !(0, java_1.isIdentifier)(declared))
435
+ return;
436
+ const scope = (0, javascript_1.scopeOf)(owner).declaringScope(declared.simpleName);
437
+ if (!scope)
438
+ return;
439
+ this.constants.push({
440
+ binding: `${scope.id}:${declared.simpleName}`, name: declared.simpleName, path: joinKeys(keys),
441
+ topLevel: scope.kind === javascript_1.JS.Kind.CompilationUnit, id: node.id, text, interpolated
442
+ });
443
+ }
444
+ recordPropFlow(root, names, holder) {
445
+ var _a, _b;
446
+ if (!this.acc)
447
+ return;
448
+ const site = (_a = this.siteOf()) !== null && _a !== void 0 ? _a : this.interpolationSite();
449
+ const passed = this.passedToComponent();
450
+ if (!site && !passed)
451
+ return;
452
+ const suffix = names.map(name => `.${name}`).join("");
453
+ const prop = propRoot(root, holder);
454
+ if (prop && site)
455
+ this.acc.addComponentRender(this.sourcePath, prop.component, joinPath(prop.path, suffix), site);
456
+ if (!passed)
457
+ return;
458
+ if (prop) {
459
+ this.acc.addForward(this.sourcePath, prop.component, joinPath(prop.path, suffix), passed.child, passed.prop);
460
+ return;
461
+ }
462
+ if (((_b = (0, javascript_1.resolve)(holder, root)) === null || _b === void 0 ? void 0 : _b.kind) !== javascript_1.JS.Kind.CompilationUnit)
463
+ return;
464
+ const imported = this.imports.get(root.simpleName);
465
+ const namespace = this.namespaces.get(root.simpleName);
466
+ if (imported)
467
+ this.acc.addPass(passed.child, passed.prop, { file: this.sourcePath, specifier: imported.module, name: imported.name }, joinPath("", suffix));
468
+ else if (namespace && names.length > 0) {
469
+ this.acc.addPass(passed.child, passed.prop, { file: this.sourcePath, specifier: namespace, name: names[0] }, joinPath("", names.slice(1).map(name => `.${name}`).join("")));
470
+ }
471
+ else if (!namespace)
472
+ this.acc.addPass(passed.child, passed.prop, { file: this.sourcePath, name: root.simpleName }, joinPath("", suffix));
473
+ }
474
+ recordAlias(identifier) {
475
+ var _a, _b, _c;
476
+ const { keys, owner, object } = objectPath(this.cursor);
477
+ const declaration = owner === null || owner === void 0 ? void 0 : owner.value;
478
+ if (keys.length === 0 || (declaration === null || declaration === void 0 ? void 0 : declaration.kind) !== java_1.J.Kind.NamedVariable)
479
+ return;
480
+ const { name, initializer } = declaration;
481
+ if (!(0, java_1.isIdentifier)(name) || (initializer === null || initializer === void 0 ? void 0 : initializer.element) !== object.value || ((_a = (0, javascript_1.resolve)(this.cursor, identifier)) === null || _a === void 0 ? void 0 : _a.kind) !== javascript_1.JS.Kind.CompilationUnit)
482
+ return;
483
+ if (((_b = (0, javascript_1.scopeOf)(owner).declaringScope(name.simpleName)) === null || _b === void 0 ? void 0 : _b.kind) === javascript_1.JS.Kind.CompilationUnit) {
484
+ (_c = this.acc) === null || _c === void 0 ? void 0 : _c.addAlias(this.sourcePath, name.simpleName, joinKeys(keys), identifier.simpleName);
485
+ }
486
+ }
487
+ passedToComponent() {
488
+ const attribute = renderedFrom(this.cursor).parentTree();
489
+ if ((attribute === null || attribute === void 0 ? void 0 : attribute.value.kind) !== javascript_1.JS.Kind.JsxAttribute || !(0, java_1.isIdentifier)(attribute.value.key))
490
+ return undefined;
491
+ const child = this.componentRef(attribute.firstEnclosing((t) => t.kind === javascript_1.JS.Kind.JsxTag));
492
+ return child && { child, prop: attribute.value.key.simpleName };
493
+ }
494
+ componentRef(tag) {
495
+ const name = tag.openName.element;
496
+ if (!(0, java_1.isIdentifier)(name) || !/^[A-Z]/.test(name.simpleName))
497
+ return undefined;
498
+ const imported = this.imports.get(name.simpleName);
499
+ return imported ? { file: this.sourcePath, specifier: imported.module, name: imported.name } : { file: this.sourcePath, name: name.simpleName };
500
+ }
501
+ markRendered(identifier, site, path, holder = this.cursor) {
502
+ const owner = (0, javascript_1.resolve)(holder, identifier);
503
+ if (!owner)
504
+ return;
505
+ if (!this.table) {
506
+ if (owner.kind !== javascript_1.JS.Kind.CompilationUnit || !this.acc)
507
+ return;
508
+ const imported = this.imports.get(identifier.simpleName);
509
+ const namespace = this.namespaces.get(identifier.simpleName);
510
+ if (imported)
511
+ this.acc.addRender(this.sourcePath, imported.module, imported.name, path, site);
512
+ else if (namespace && path) {
513
+ const [name, ...rest] = path.split(".");
514
+ this.acc.addRender(this.sourcePath, namespace, name, rest.join("."), site);
515
+ }
516
+ return;
517
+ }
518
+ const binding = `${owner.id}:${identifier.simpleName}|${path}`;
519
+ if (!this.rendered.has(binding))
520
+ this.rendered.set(binding, site);
521
+ }
522
+ reportConstants(cu, ctx) {
523
+ return __awaiter(this, void 0, void 0, function* () {
524
+ var _a, _b;
525
+ const found = new Set();
526
+ for (const { binding, name, path, topLevel, id, text, interpolated } of this.constants) {
527
+ const site = (_a = this.rendered.get(`${binding}|${path}`)) !== null && _a !== void 0 ? _a : (topLevel ? (_b = this.acc) === null || _b === void 0 ? void 0 : _b.siteOf(this.sourcePath, name, path) : undefined);
528
+ if (!site)
529
+ continue;
530
+ this.insertRow(ctx, Object.assign(Object.assign({}, site), { context: "VARIABLE" }), text, interpolated);
531
+ found.add(id);
532
+ }
533
+ if (found.size === 0)
534
+ return cu;
535
+ return new class extends javascript_1.JavaScriptVisitor {
536
+ visitLiteral(literal) {
537
+ return __awaiter(this, void 0, void 0, function* () {
538
+ return found.has(literal.id) ? (0, rewrite_1.foundSearchResult)(literal) : literal;
539
+ });
540
+ }
541
+ visitTemplateExpression(template, ctx) {
542
+ const _super = Object.create(null, {
543
+ visitTemplateExpression: { get: () => super.visitTemplateExpression }
544
+ });
545
+ return __awaiter(this, void 0, void 0, function* () {
546
+ const t = yield _super.visitTemplateExpression.call(this, template, ctx);
547
+ return found.has(t.id) ? (0, rewrite_1.foundSearchResult)(t) : t;
548
+ });
549
+ }
550
+ }().visit(cu, ctx);
551
+ });
552
+ }
553
+ siteOf(cursor = this.cursor) {
554
+ var _a, _b;
555
+ return (_b = (_a = this.jsxSite(cursor)) !== null && _a !== void 0 ? _a : this.metadataSite(cursor)) !== null && _b !== void 0 ? _b : this.callSite(cursor);
556
+ }
557
+ interpolationSite() {
558
+ const child = renderedFrom(this.cursor);
559
+ const span = child.parentTree();
560
+ if ((span === null || span === void 0 ? void 0 : span.value.kind) !== javascript_1.JS.Kind.TemplateExpressionSpan || span.value.expression !== child.value)
561
+ return undefined;
562
+ const site = this.siteOf(span.parentTree());
563
+ return site && Object.assign(Object.assign({}, site), { mixed: true });
564
+ }
565
+ jsxSite(cursor = this.cursor) {
566
+ var _a;
567
+ const child = renderedFrom(cursor);
568
+ const parent = child.parentTree();
569
+ if ((parent === null || parent === void 0 ? void 0 : parent.value.kind) === javascript_1.JS.Kind.JsxAttribute) {
570
+ const attr = parent.value;
571
+ const tag = parent.firstEnclosing((t) => t.kind === javascript_1.JS.Kind.JsxTag);
572
+ const element = tagName(tag);
573
+ const component = this.table && (0, java_1.isIdentifier)(attr.key) ? this.componentRef(tag) : undefined;
574
+ const shown = isUserFacing(attr, element) || !!component && !!((_a = this.acc) === null || _a === void 0 ? void 0 : _a.rendersProp(component, attr.key.simpleName));
575
+ return shown ? { element, attribute: attr.key.simpleName, mixed: false, context: "JSX" } : undefined;
576
+ }
577
+ if (this.verbatim > 0 || !childOfTag(parent, child))
578
+ return undefined;
579
+ const tag = parent.value;
580
+ return { element: tagName(tag), attribute: "", mixed: hasOtherContent(tag, child.value) || sharesSentence(parent), context: "JSX" };
581
+ }
582
+ metadataSite(cursor) {
583
+ if (!this.nextMetadataFile)
584
+ return undefined;
585
+ const { keys, owner, object } = objectPath(cursor);
586
+ const element = owner && metadataExport(owner, object);
587
+ const known = element && METADATA_SECTIONS.has(keys[0]) && METADATA_TEXT_KEYS.has(keys[keys.length - 1]);
588
+ return known ? { element, attribute: keys.join("."), mixed: false, context: "METADATA" } : undefined;
589
+ }
590
+ callSite(cursor) {
591
+ if (this.toastNames.size === 0)
592
+ return undefined;
593
+ const { keys, owner, object } = objectPath(cursor);
594
+ const textOption = keys.length === 0 || keys.length === 1 && TOAST_TEXT_KEYS.has(keys[0]) ||
595
+ keys.length === 2 && TOAST_BUTTONS.has(keys[0]) && keys[1] === "label";
596
+ if (!textOption || (owner === null || owner === void 0 ? void 0 : owner.value.kind) !== java_1.J.Kind.MethodInvocation)
597
+ return undefined;
598
+ const call = owner.value;
599
+ const element = toastCallName(call, this.toastNames);
600
+ const argument = call.arguments.elements.some(a => a.element === object.value);
601
+ return element && argument ? { element, attribute: keys.join("."), mixed: false, context: "CALL" } : undefined;
602
+ }
603
+ report(ctx, node, site, text, interpolated) {
604
+ this.insertRow(ctx, site, text, interpolated, node);
605
+ return (0, rewrite_1.foundSearchResult)(node);
606
+ }
607
+ insertRow(ctx, site, text, interpolated, node) {
608
+ var _a;
609
+ const kind = interpolated || site.mixed ? "MIXED" : site.attribute ? "ATTRIBUTE" : "TEXT";
610
+ (_a = this.table) === null || _a === void 0 ? void 0 : _a.insertRow(ctx, { sourcePath: this.sourcePath, element: site.element, attribute: site.attribute, kind, context: site.context, text }, node, this.cursor);
611
+ }
612
+ }
613
+ exports.HardCodedStringsVisitor = HardCodedStringsVisitor;
614
+ function tagName(tag) {
615
+ const name = tag.openName.element;
616
+ if ((0, java_1.isIdentifier)(name))
617
+ return name.simpleName;
618
+ if (name.kind === java_1.J.Kind.FieldAccess) {
619
+ const fa = name;
620
+ return `${(0, java_1.isIdentifier)(fa.target) ? fa.target.simpleName + "." : ""}${fa.name.element.simpleName}`;
621
+ }
622
+ return "";
623
+ }
624
+ function toastCallName(call, names) {
625
+ const name = call.name.simpleName;
626
+ if (!call.select)
627
+ return names.has(name) ? name : undefined;
628
+ const target = call.select.element;
629
+ return (0, java_1.isIdentifier)(target) && names.has(target.simpleName) && TOAST_METHODS.has(name) ? `${target.simpleName}.${name}` : undefined;
630
+ }
631
+ function objectPath(cursor) {
632
+ const keys = [];
633
+ let object = renderedFrom(cursor);
634
+ let child = object;
635
+ for (let parent = child.parentTree(); parent; child = parent, parent = parent.parentTree()) {
636
+ const node = parent.value;
637
+ if (node.kind === javascript_1.JS.Kind.PropertyAssignment) {
638
+ const { name, initializer } = node;
639
+ const key = (0, java_1.isIdentifier)(name.element) ? name.element.simpleName : stringValue(name.element);
640
+ if (initializer !== child.value || key === undefined)
641
+ return { keys: [], object, owner: undefined };
642
+ keys.unshift(key);
643
+ }
644
+ else if (node.kind === java_1.J.Kind.NewArray) {
645
+ keys.unshift("[]");
646
+ object = parent;
647
+ }
648
+ else if (node.kind === java_1.J.Kind.NewClass && !node.class || OBJECT_WRAPPERS.has(node.kind)) {
649
+ if (node.kind !== java_1.J.Kind.Block)
650
+ object = parent;
651
+ }
652
+ else {
653
+ return { keys, object, owner: parent };
654
+ }
655
+ }
656
+ return { keys, object, owner: undefined };
657
+ }
658
+ function metadataExport(owner, object) {
659
+ var _a;
660
+ const node = owner.value;
661
+ if (node.kind === java_1.J.Kind.NamedVariable) {
662
+ return (0, tree_search_1.isIdentifierNamed)(node.name, "metadata") && ((_a = node.initializer) === null || _a === void 0 ? void 0 : _a.element) === object.value ? "metadata" : undefined;
663
+ }
664
+ const fn = node.kind === java_1.J.Kind.Return ? enclosingFunction(owner) : exports.FUNCTION_KINDS.has(node.kind) ? owner : undefined;
665
+ return fn && functionName(fn) === "generateMetadata" ? "generateMetadata" : undefined;
666
+ }
667
+ function enclosingFunction(cursor) {
668
+ for (let c = cursor.parentTree(); c; c = c.parentTree()) {
669
+ if (exports.FUNCTION_KINDS.has(c.value.kind))
670
+ return c;
671
+ }
672
+ return undefined;
673
+ }
674
+ function functionName(fn) {
675
+ if (fn.value.kind === java_1.J.Kind.MethodDeclaration)
676
+ return fn.value.name.simpleName;
677
+ let c = fn;
678
+ while (c && (exports.FUNCTION_KINDS.has(c.value.kind) || c.value.kind === java_1.J.Kind.Parentheses))
679
+ c = c.parentTree();
680
+ const name = (c === null || c === void 0 ? void 0 : c.value.kind) === java_1.J.Kind.NamedVariable ? c.value.name : undefined;
681
+ return name && (0, java_1.isIdentifier)(name) ? name.simpleName : undefined;
682
+ }
683
+ function isUserFacing(attr, element) {
684
+ if (!(0, java_1.isIdentifier)(attr.key))
685
+ return false;
686
+ const name = attr.key.simpleName;
687
+ return USER_FACING_ATTRIBUTES.has(name) || /^[A-Z]|\./.test(element) && COMPONENT_TEXT_PROP.test(name);
688
+ }
689
+ function renderedFrom(cursor) {
690
+ let child = cursor;
691
+ for (let parent = child.parentTree(); parent && rendersChild(parent.value, child.value); parent = child.parentTree())
692
+ child = parent;
693
+ return child;
694
+ }
695
+ function rendersChild(parent, child) {
696
+ switch (parent.kind) {
697
+ case java_1.J.Kind.Parentheses:
698
+ case javascript_1.JS.Kind.JsxEmbeddedExpression:
699
+ return true;
700
+ case java_1.J.Kind.Ternary:
701
+ return parent.condition !== child;
702
+ case java_1.J.Kind.Binary: {
703
+ const { operator, right } = parent;
704
+ return operator.element === "Or" || operator.element === "And" && right === child;
705
+ }
706
+ case javascript_1.JS.Kind.Binary:
707
+ return parent.operator.element === "QuestionQuestion";
708
+ default:
709
+ return false;
710
+ }
711
+ }
712
+ function sharesSentence(tagCursor) {
713
+ const child = renderedFrom(tagCursor);
714
+ const outer = child.parentTree();
715
+ if (!childOfTag(outer, child))
716
+ return false;
717
+ const tag = outer.value;
718
+ return hasText(tag) || !hasOtherContent(tag, child.value) && sharesSentence(outer);
719
+ }
720
+ function childOfTag(cursor, child) {
721
+ var _a;
722
+ return (cursor === null || cursor === void 0 ? void 0 : cursor.value.kind) === javascript_1.JS.Kind.JsxTag && !!((_a = cursor.value.children) === null || _a === void 0 ? void 0 : _a.includes(child.value));
723
+ }
724
+ function unwrap(expr) {
725
+ return (expr === null || expr === void 0 ? void 0 : expr.kind) === javascript_1.JS.Kind.JsxEmbeddedExpression ? expr.expression.element : expr;
726
+ }
727
+ function stringValue(expr) {
728
+ return (expr === null || expr === void 0 ? void 0 : expr.kind) === java_1.J.Kind.Literal && typeof expr.value === "string" ? expr.value : undefined;
729
+ }
730
+ function isBlank(child) {
731
+ var _a, _b, _c;
732
+ switch (child.kind) {
733
+ case java_1.J.Kind.Empty:
734
+ return true;
735
+ case javascript_1.JS.Kind.JsxTag:
736
+ return (_b = (_a = child.children) === null || _a === void 0 ? void 0 : _a.every(isBlank)) !== null && _b !== void 0 ? _b : true;
737
+ case javascript_1.JS.Kind.JsxEmbeddedExpression:
738
+ return isBlank(child.expression.element);
739
+ case java_1.J.Kind.Parentheses:
740
+ return isBlank(child.tree.element);
741
+ case java_1.J.Kind.Ternary:
742
+ return isBlank(child.truePart.element) && isBlank(child.falsePart.element);
743
+ case java_1.J.Kind.Binary:
744
+ return child.operator.element === "And" && isBlank(child.right);
745
+ default:
746
+ return ((_c = stringValue(child)) === null || _c === void 0 ? void 0 : _c.trim()) === "";
747
+ }
748
+ }
749
+ function hasOtherContent(tag, self) {
750
+ var _a;
751
+ return !!((_a = tag.children) === null || _a === void 0 ? void 0 : _a.some(c => c !== self && !isBlank(c)));
752
+ }
753
+ function hasText(tag) {
754
+ var _a;
755
+ return !!((_a = tag.children) === null || _a === void 0 ? void 0 : _a.some(c => {
756
+ const value = stringValue(unwrap(c));
757
+ return value !== undefined && hasLetters(value);
758
+ }));
759
+ }
760
+ function isTranslatable(text) {
761
+ return hasLetters(text) && !URL_EMAIL_DOMAIN_OR_PATH.test(text) && !IDENTIFIER_LIKE.test(text);
762
+ }
763
+ function hasLetters(text) {
764
+ var _a, _b;
765
+ const plain = text.replace(ENTITY, "");
766
+ return IDEOGRAPHIC.test(plain) || ((_b = (_a = plain.match(LETTERS)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) >= 2;
767
+ }
768
+ function memberChain(access, cursor) {
769
+ const names = [];
770
+ let holder = cursor;
771
+ let node = access;
772
+ for (;;) {
773
+ const current = node;
774
+ names.unshift(current.name.element.simpleName);
775
+ if ((0, java_1.isIdentifier)(current.target))
776
+ return { root: current.target, names, holder };
777
+ if (current.target.kind !== java_1.J.Kind.FieldAccess)
778
+ return undefined;
779
+ node = current.target;
780
+ holder = new rewrite_1.Cursor(node, holder);
781
+ }
782
+ }
783
+ function dependencyNames(doc) {
784
+ var _a, _b, _c, _d, _e, _f, _g, _h;
785
+ const resolution = (0, javascript_1.findNodeResolutionResult)(doc);
786
+ const names = new Set([...(_a = resolution === null || resolution === void 0 ? void 0 : resolution.dependencies) !== null && _a !== void 0 ? _a : [], ...(_b = resolution === null || resolution === void 0 ? void 0 : resolution.devDependencies) !== null && _b !== void 0 ? _b : [],
787
+ ...(_c = resolution === null || resolution === void 0 ? void 0 : resolution.optionalDependencies) !== null && _c !== void 0 ? _c : [], ...(_d = resolution === null || resolution === void 0 ? void 0 : resolution.peerDependencies) !== null && _d !== void 0 ? _d : []].map(dependency => dependency.name));
788
+ for (const { element: member } of (_e = doc.value.members) !== null && _e !== void 0 ? _e : []) {
789
+ const { key, value } = member;
790
+ if (!/^(dev|peer|optional)?[dD]ependencies$/.test((_f = jsonKey(key.element)) !== null && _f !== void 0 ? _f : ""))
791
+ continue;
792
+ for (const { element: dependency } of (_g = value.members) !== null && _g !== void 0 ? _g : []) {
793
+ const name = jsonKey((_h = dependency.key) === null || _h === void 0 ? void 0 : _h.element);
794
+ if (name)
795
+ names.add(name);
796
+ }
797
+ }
798
+ return names;
799
+ }
800
+ function jsonKey(key) {
801
+ return (key === null || key === void 0 ? void 0 : key.kind) === json_1.Json.Kind.Literal ? String(key.value) : (key === null || key === void 0 ? void 0 : key.kind) === json_1.Json.Kind.Identifier ? key.name : undefined;
802
+ }
803
+ function isSentenceRoot(tag, cursor) {
804
+ var _a;
805
+ return hasText(tag) && ((_a = tag.children) !== null && _a !== void 0 ? _a : []).filter(child => !isBlank(child)).length >= 2 && !sharesSentence(cursor);
806
+ }
807
+ const TRANS_KEPT_ELEMENTS = new Set(["br", "strong", "i", "p"]);
808
+ function transContent(children, covered, names = new Map()) {
809
+ let text = "";
810
+ let index = 0;
811
+ for (const child of children !== null && children !== void 0 ? children : []) {
812
+ const piece = transChild(child, index, covered, names);
813
+ if (piece === undefined)
814
+ continue;
815
+ text += piece;
816
+ index++;
817
+ }
818
+ return text;
819
+ }
820
+ function transChild(child, index, covered, names) {
821
+ var _a;
822
+ if (child.kind === java_1.J.Kind.Literal) {
823
+ const text = jsxText((_a = stringValue(child)) !== null && _a !== void 0 ? _a : "");
824
+ if (text)
825
+ covered.add(child.id);
826
+ return text || undefined;
827
+ }
828
+ if (child.kind === javascript_1.JS.Kind.JsxTag)
829
+ return transElement(child, index, covered, names);
830
+ if (child.kind !== javascript_1.JS.Kind.JsxEmbeddedExpression)
831
+ return undefined;
832
+ const value = child.expression.element;
833
+ if (value.kind === java_1.J.Kind.Empty)
834
+ return undefined;
835
+ const string = stringValue(value);
836
+ if (string !== undefined) {
837
+ covered.add(value.id);
838
+ return string;
839
+ }
840
+ if ((0, java_1.isIdentifier)(value))
841
+ return `{{${placeholder(value.simpleName, value.simpleName, names)}}}`;
842
+ if (value.kind === java_1.J.Kind.FieldAccess) {
843
+ const path = propertyPath(value);
844
+ return `{{${placeholder(value.name.element.simpleName, path !== null && path !== void 0 ? path : `#${value.id}`, names)}}}`;
845
+ }
846
+ const shorthand = objectProperties(value);
847
+ if ((shorthand === null || shorthand === void 0 ? void 0 : shorthand.length) === 1)
848
+ return `{{${shorthand[0]}}}`;
849
+ if (value.kind === java_1.J.Kind.Binary && value.operator.element === "And" && value.right.kind === javascript_1.JS.Kind.JsxTag) {
850
+ return transElement(value.right, index, covered, names);
851
+ }
852
+ return `{{${index}}}`;
853
+ }
854
+ function transElement(tag, index, covered, names) {
855
+ const name = tagName(tag);
856
+ const content = transContent(tag.children, covered, names);
857
+ const attributes = tag.attributes.filter(({ element }) => element.kind !== javascript_1.JS.Kind.JsxAttribute ||
858
+ !(0, java_1.isIdentifier)(element.key) || !["key", "ref"].includes(element.key.simpleName)).length;
859
+ const props = attributes + (content ? 1 : 0);
860
+ const kept = TRANS_KEPT_ELEMENTS.has(name);
861
+ if (!content)
862
+ return kept && props === 0 ? `<${name}/>` : `<${index}></${index}>`;
863
+ return kept && props <= 1 ? `<${name}>${content}</${name}>` : `<${index}>${content}</${index}>`;
864
+ }
865
+ function placeholder(name, value, names) {
866
+ const taken = names.get(name);
867
+ if (taken === undefined || taken === value) {
868
+ names.set(name, value);
869
+ return name;
870
+ }
871
+ let n = 2;
872
+ while (names.has(`${name}${n}`) && names.get(`${name}${n}`) !== value)
873
+ n++;
874
+ names.set(`${name}${n}`, value);
875
+ return `${name}${n}`;
876
+ }
877
+ function propertyPath(access) {
878
+ const names = [];
879
+ let node = access;
880
+ while (node.kind === java_1.J.Kind.FieldAccess) {
881
+ names.unshift(node.name.element.simpleName);
882
+ node = node.target;
883
+ }
884
+ return (0, java_1.isIdentifier)(node) ? [node.simpleName, ...names].join(".") : undefined;
885
+ }
886
+ function objectProperties(value) {
887
+ if (value.kind !== java_1.J.Kind.NewClass || value.class || !value.body)
888
+ return undefined;
889
+ const names = [];
890
+ for (const { element } of value.body.statements) {
891
+ if (element.kind !== javascript_1.JS.Kind.PropertyAssignment)
892
+ return undefined;
893
+ const name = element.name.element;
894
+ if (!(0, java_1.isIdentifier)(name))
895
+ return undefined;
896
+ names.push(name.simpleName);
897
+ }
898
+ return names;
899
+ }
900
+ function transPlainText(text) {
901
+ return text.replace(/\{\{[^}]*\}\}|<\/?(?:\d+|[a-z]+)\/?>/g, " ").trim();
902
+ }
903
+ function jsxText(raw) {
904
+ const lines = raw.split(/\r\n|\n|\r/);
905
+ let last = 0;
906
+ lines.forEach((line, i) => {
907
+ if (/[^ \t]/.test(line))
908
+ last = i;
909
+ });
910
+ let text = "";
911
+ lines.forEach((line, i) => {
912
+ let trimmed = line.replace(/\t/g, " ");
913
+ if (i > 0)
914
+ trimmed = trimmed.replace(/^[ ]+/, "");
915
+ if (i < lines.length - 1)
916
+ trimmed = trimmed.replace(/[ ]+$/, "");
917
+ if (trimmed)
918
+ text += i === last ? trimmed : trimmed + " ";
919
+ });
920
+ return text;
921
+ }
922
+ const ELEMENT_CALLBACKS = new Set(["map", "flatMap", "forEach"]);
923
+ const ELEMENT_PRESERVING = new Set(["filter", "slice", "sort", "toSorted", "reverse", "toReversed"]);
924
+ function propRoot(identifier, holder) {
925
+ var _a;
926
+ const owner = (0, javascript_1.resolve)(holder, identifier);
927
+ if (!owner || !exports.FUNCTION_KINDS.has(owner.kind))
928
+ return undefined;
929
+ let fn = holder;
930
+ while (fn && fn.value !== owner)
931
+ fn = fn.parentTree();
932
+ const bound = fn && parameterPath(firstParameter(owner), identifier.simpleName);
933
+ if (!fn || bound === undefined)
934
+ return undefined;
935
+ const component = functionName(fn);
936
+ if (component && /^[A-Z]/.test(component))
937
+ return { component, path: bound };
938
+ const call = fn.parentTree();
939
+ const invocation = call === null || call === void 0 ? void 0 : call.value;
940
+ if ((invocation === null || invocation === void 0 ? void 0 : invocation.kind) !== java_1.J.Kind.MethodInvocation || !ELEMENT_CALLBACKS.has(invocation.name.simpleName) ||
941
+ ((_a = invocation.arguments.elements[0]) === null || _a === void 0 ? void 0 : _a.element) !== owner || !invocation.select)
942
+ return undefined;
943
+ const receiver = expressionRoot(invocation.select.element, call);
944
+ return receiver && { component: receiver.component, path: joinPath(`${receiver.path}[]`, bound ? `.${bound}` : "") };
945
+ }
946
+ function expressionRoot(expression, holder) {
947
+ if ((0, java_1.isIdentifier)(expression))
948
+ return propRoot(expression, holder);
949
+ const cursor = new rewrite_1.Cursor(expression, holder);
950
+ if (expression.kind === java_1.J.Kind.FieldAccess) {
951
+ const chain = memberChain(expression, cursor);
952
+ const root = chain && propRoot(chain.root, chain.holder);
953
+ return root && { component: root.component, path: joinPath(root.path, chain.names.map(name => `.${name}`).join("")) };
954
+ }
955
+ const call = expression;
956
+ return call.kind === java_1.J.Kind.MethodInvocation && ELEMENT_PRESERVING.has(call.name.simpleName) && call.select ? expressionRoot(call.select.element, cursor) : undefined;
957
+ }
958
+ function firstParameter(fn) {
959
+ var _a, _b;
960
+ const parameters = fn.kind === java_1.J.Kind.MethodDeclaration ? fn.parameters.elements :
961
+ fn.kind === javascript_1.JS.Kind.ArrowFunction ? fn.lambda.parameters.parameters :
962
+ fn.kind === java_1.J.Kind.Lambda ? fn.parameters.parameters : [];
963
+ const first = (_a = parameters[0]) === null || _a === void 0 ? void 0 : _a.element;
964
+ return (first === null || first === void 0 ? void 0 : first.kind) === java_1.J.Kind.VariableDeclarations ? (_b = first.variables[0]) === null || _b === void 0 ? void 0 : _b.element.name : first;
965
+ }
966
+ function parameterPath(parameter, name) {
967
+ var _a;
968
+ if (!parameter)
969
+ return undefined;
970
+ if ((0, java_1.isIdentifier)(parameter))
971
+ return parameter.simpleName === name ? "" : undefined;
972
+ return (_a = (0, javascript_1.bindingNames)(parameter).find(binding => binding.name === name)) === null || _a === void 0 ? void 0 : _a.member;
973
+ }
974
+ function joinKeys(keys) {
975
+ return keys.reduce((path, key) => key === "[]" ? `${path}[]` : path ? `${path}.${key}` : key, "");
976
+ }
977
+ function joinPath(path, rest) {
978
+ return path ? path + rest : rest.replace(/^\./, "");
979
+ }
980
+ function pathAfter(path, prefix) {
981
+ if (path === prefix)
982
+ return "";
983
+ if (!prefix)
984
+ return path.startsWith("[") ? path : `.${path}`;
985
+ return path.startsWith(`${prefix}.`) || path.startsWith(`${prefix}[`) ? path.slice(prefix.length) : undefined;
986
+ }
987
+ //# sourceMappingURL=find-hard-coded-strings.js.map