@openrewrite/recipes-react 0.21.0 → 0.23.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 (243) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +27 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/migration/change-component-prop-value.d.ts.map +1 -1
  6. package/dist/migration/change-component-prop-value.js +14 -4
  7. package/dist/migration/change-component-prop-value.js.map +1 -1
  8. package/dist/mui/adapt-v4-theme.d.ts +8 -0
  9. package/dist/mui/adapt-v4-theme.d.ts.map +1 -0
  10. package/dist/mui/adapt-v4-theme.js +65 -0
  11. package/dist/mui/adapt-v4-theme.js.map +1 -0
  12. package/dist/mui/add-component-prop.d.ts +18 -0
  13. package/dist/mui/add-component-prop.d.ts.map +1 -0
  14. package/dist/mui/add-component-prop.js +53 -0
  15. package/dist/mui/add-component-prop.js.map +1 -0
  16. package/dist/mui/add-emotion-prepend.d.ts +8 -0
  17. package/dist/mui/add-emotion-prepend.d.ts.map +1 -0
  18. package/dist/mui/add-emotion-prepend.js +71 -0
  19. package/dist/mui/add-emotion-prepend.js.map +1 -0
  20. package/dist/mui/change-module-specifier.d.ts +14 -0
  21. package/dist/mui/change-module-specifier.d.ts.map +1 -0
  22. package/dist/mui/change-module-specifier.js +95 -0
  23. package/dist/mui/change-module-specifier.js.map +1 -0
  24. package/dist/mui/convert-mui-imports.d.ts +14 -0
  25. package/dist/mui/convert-mui-imports.d.ts.map +1 -0
  26. package/dist/mui/convert-mui-imports.js +195 -0
  27. package/dist/mui/convert-mui-imports.js.map +1 -0
  28. package/dist/mui/convert-prop-to-sx.d.ts +22 -0
  29. package/dist/mui/convert-prop-to-sx.d.ts.map +1 -0
  30. package/dist/mui/convert-prop-to-sx.js +99 -0
  31. package/dist/mui/convert-prop-to-sx.js.map +1 -0
  32. package/dist/mui/index.d.ts +32 -0
  33. package/dist/mui/index.d.ts.map +1 -0
  34. package/dist/mui/index.js +67 -0
  35. package/dist/mui/index.js.map +1 -0
  36. package/dist/mui/jsx-attributes.d.ts +27 -0
  37. package/dist/mui/jsx-attributes.d.ts.map +1 -0
  38. package/dist/mui/jsx-attributes.js +140 -0
  39. package/dist/mui/jsx-attributes.js.map +1 -0
  40. package/dist/mui/mark-manual-migration.d.ts +16 -0
  41. package/dist/mui/mark-manual-migration.d.ts.map +1 -0
  42. package/dist/mui/mark-manual-migration.js +73 -0
  43. package/dist/mui/mark-manual-migration.js.map +1 -0
  44. package/dist/mui/mark-palette-mode-usage.d.ts +12 -0
  45. package/dist/mui/mark-palette-mode-usage.d.ts.map +1 -0
  46. package/dist/mui/mark-palette-mode-usage.js +50 -0
  47. package/dist/mui/mark-palette-mode-usage.js.map +1 -0
  48. package/dist/mui/move-component-prop-to-slot.d.ts +22 -0
  49. package/dist/mui/move-component-prop-to-slot.d.ts.map +1 -0
  50. package/dist/mui/move-component-prop-to-slot.js +87 -0
  51. package/dist/mui/move-component-prop-to-slot.js.map +1 -0
  52. package/dist/mui/move-primary-text-to-children.d.ts +12 -0
  53. package/dist/mui/move-primary-text-to-children.d.ts.map +1 -0
  54. package/dist/mui/move-primary-text-to-children.js +52 -0
  55. package/dist/mui/move-primary-text-to-children.js.map +1 -0
  56. package/dist/mui/move-system-props-to-sx.d.ts +16 -0
  57. package/dist/mui/move-system-props-to-sx.d.ts.map +1 -0
  58. package/dist/mui/move-system-props-to-sx.js +122 -0
  59. package/dist/mui/move-system-props-to-sx.js.map +1 -0
  60. package/dist/mui/mui-components.d.ts +8 -0
  61. package/dist/mui/mui-components.d.ts.map +1 -0
  62. package/dist/mui/mui-components.js +41 -0
  63. package/dist/mui/mui-components.js.map +1 -0
  64. package/dist/mui/mui-tag-visitor.d.ts +5 -0
  65. package/dist/mui/mui-tag-visitor.d.ts.map +1 -0
  66. package/dist/mui/mui-tag-visitor.js +54 -0
  67. package/dist/mui/mui-tag-visitor.js.map +1 -0
  68. package/dist/mui/pre-v5-recipe.d.ts +14 -0
  69. package/dist/mui/pre-v5-recipe.d.ts.map +1 -0
  70. package/dist/mui/pre-v5-recipe.js +88 -0
  71. package/dist/mui/pre-v5-recipe.js.map +1 -0
  72. package/dist/mui/remove-component-prop.d.ts +18 -0
  73. package/dist/mui/remove-component-prop.d.ts.map +1 -0
  74. package/dist/mui/remove-component-prop.js +55 -0
  75. package/dist/mui/remove-component-prop.js.map +1 -0
  76. package/dist/mui/remove-root-ref.d.ts +8 -0
  77. package/dist/mui/remove-root-ref.d.ts.map +1 -0
  78. package/dist/mui/remove-root-ref.js +61 -0
  79. package/dist/mui/remove-root-ref.js.map +1 -0
  80. package/dist/mui/remove-spacing-px-suffix.d.ts +8 -0
  81. package/dist/mui/remove-spacing-px-suffix.d.ts.map +1 -0
  82. package/dist/mui/remove-spacing-px-suffix.js +62 -0
  83. package/dist/mui/remove-spacing-px-suffix.js.map +1 -0
  84. package/dist/mui/rename-component-prop.d.ts +20 -0
  85. package/dist/mui/rename-component-prop.d.ts.map +1 -0
  86. package/dist/mui/rename-component-prop.js +66 -0
  87. package/dist/mui/rename-component-prop.js.map +1 -0
  88. package/dist/mui/rename-joy-css-variables.d.ts +8 -0
  89. package/dist/mui/rename-joy-css-variables.d.ts.map +1 -0
  90. package/dist/mui/rename-joy-css-variables.js +51 -0
  91. package/dist/mui/rename-joy-css-variables.js.map +1 -0
  92. package/dist/mui/rename-theme-palette-type.d.ts +8 -0
  93. package/dist/mui/rename-theme-palette-type.d.ts.map +1 -0
  94. package/dist/mui/rename-theme-palette-type.js +61 -0
  95. package/dist/mui/rename-theme-palette-type.js.map +1 -0
  96. package/dist/mui/replace-box-border-radius.d.ts +10 -0
  97. package/dist/mui/replace-box-border-radius.d.ts.map +1 -0
  98. package/dist/mui/replace-box-border-radius.js +50 -0
  99. package/dist/mui/replace-box-border-radius.js.map +1 -0
  100. package/dist/mui/replace-breakpoints-width.d.ts +8 -0
  101. package/dist/mui/replace-breakpoints-width.d.ts.map +1 -0
  102. package/dist/mui/replace-breakpoints-width.js +46 -0
  103. package/dist/mui/replace-breakpoints-width.js.map +1 -0
  104. package/dist/mui/replace-component-class.d.ts +18 -0
  105. package/dist/mui/replace-component-class.d.ts.map +1 -0
  106. package/dist/mui/replace-component-class.js +126 -0
  107. package/dist/mui/replace-component-class.js.map +1 -0
  108. package/dist/mui/replace-components-with-slots.d.ts +14 -0
  109. package/dist/mui/replace-components-with-slots.d.ts.map +1 -0
  110. package/dist/mui/replace-components-with-slots.js +69 -0
  111. package/dist/mui/replace-components-with-slots.js.map +1 -0
  112. package/dist/mui/replace-import-paths.d.ts +14 -0
  113. package/dist/mui/replace-import-paths.d.ts.map +1 -0
  114. package/dist/mui/replace-import-paths.js +101 -0
  115. package/dist/mui/replace-import-paths.js.map +1 -0
  116. package/dist/mui/replace-in-string-literals.d.ts +15 -0
  117. package/dist/mui/replace-in-string-literals.d.ts.map +1 -0
  118. package/dist/mui/replace-in-string-literals.js +62 -0
  119. package/dist/mui/replace-in-string-literals.js.map +1 -0
  120. package/dist/mui/replace-list-item-button-prop.d.ts +12 -0
  121. package/dist/mui/replace-list-item-button-prop.d.ts.map +1 -0
  122. package/dist/mui/replace-list-item-button-prop.js +80 -0
  123. package/dist/mui/replace-list-item-button-prop.js.map +1 -0
  124. package/dist/mui/replace-tabs-scroll-buttons.d.ts +8 -0
  125. package/dist/mui/replace-tabs-scroll-buttons.d.ts.map +1 -0
  126. package/dist/mui/replace-tabs-scroll-buttons.js +41 -0
  127. package/dist/mui/replace-tabs-scroll-buttons.js.map +1 -0
  128. package/dist/mui/replace-theme-color-functions.d.ts +8 -0
  129. package/dist/mui/replace-theme-color-functions.d.ts.map +1 -0
  130. package/dist/mui/replace-theme-color-functions.js +72 -0
  131. package/dist/mui/replace-theme-color-functions.js.map +1 -0
  132. package/dist/mui/replace-theme-spacing-unit.d.ts +8 -0
  133. package/dist/mui/replace-theme-spacing-unit.d.ts.map +1 -0
  134. package/dist/mui/replace-theme-spacing-unit.js +77 -0
  135. package/dist/mui/replace-theme-spacing-unit.js.map +1 -0
  136. package/dist/mui/replace-typography-round.d.ts +8 -0
  137. package/dist/mui/replace-typography-round.d.ts.map +1 -0
  138. package/dist/mui/replace-typography-round.js +44 -0
  139. package/dist/mui/replace-typography-round.js.map +1 -0
  140. package/dist/mui/shift-hidden-down-props.d.ts +10 -0
  141. package/dist/mui/shift-hidden-down-props.d.ts.map +1 -0
  142. package/dist/mui/shift-hidden-down-props.js +49 -0
  143. package/dist/mui/shift-hidden-down-props.js.map +1 -0
  144. package/dist/mui/theme-access.d.ts +5 -0
  145. package/dist/mui/theme-access.d.ts.map +1 -0
  146. package/dist/mui/theme-access.js +21 -0
  147. package/dist/mui/theme-access.js.map +1 -0
  148. package/dist/mui/update-theme-breakpoints.d.ts +10 -0
  149. package/dist/mui/update-theme-breakpoints.d.ts.map +1 -0
  150. package/dist/mui/update-theme-breakpoints.js +58 -0
  151. package/dist/mui/update-theme-breakpoints.js.map +1 -0
  152. package/dist/mui/upgrade-grid-props.d.ts +16 -0
  153. package/dist/mui/upgrade-grid-props.d.ts.map +1 -0
  154. package/dist/mui/upgrade-grid-props.js +90 -0
  155. package/dist/mui/upgrade-grid-props.js.map +1 -0
  156. package/dist/react19/use-context-hook.d.ts.map +1 -1
  157. package/dist/react19/use-context-hook.js +2 -0
  158. package/dist/react19/use-context-hook.js.map +1 -1
  159. package/dist/search/find-enzyme-usage.d.ts +4 -0
  160. package/dist/search/find-enzyme-usage.d.ts.map +1 -1
  161. package/dist/search/find-enzyme-usage.js +91 -7
  162. package/dist/search/find-enzyme-usage.js.map +1 -1
  163. package/dist/testing/enzyme-host-components.d.ts +12 -0
  164. package/dist/testing/enzyme-host-components.d.ts.map +1 -1
  165. package/dist/testing/enzyme-host-components.js +100 -0
  166. package/dist/testing/enzyme-host-components.js.map +1 -1
  167. package/dist/testing/enzyme-render-blockers.d.ts +13 -4
  168. package/dist/testing/enzyme-render-blockers.d.ts.map +1 -1
  169. package/dist/testing/enzyme-render-blockers.js +162 -6
  170. package/dist/testing/enzyme-render-blockers.js.map +1 -1
  171. package/dist/testing/enzyme-to-react-testing-library.d.ts +9 -2
  172. package/dist/testing/enzyme-to-react-testing-library.d.ts.map +1 -1
  173. package/dist/testing/enzyme-to-react-testing-library.js +163 -16
  174. package/dist/testing/enzyme-to-react-testing-library.js.map +1 -1
  175. package/dist/testing/enzyme-usage.d.ts +7 -0
  176. package/dist/testing/enzyme-usage.d.ts.map +1 -1
  177. package/dist/testing/enzyme-usage.js +8 -1
  178. package/dist/testing/enzyme-usage.js.map +1 -1
  179. package/dist/testing/enzyme-wrapper-scope.d.ts +8 -5
  180. package/dist/testing/enzyme-wrapper-scope.d.ts.map +1 -1
  181. package/dist/testing/enzyme-wrapper-scope.js +16 -4
  182. package/dist/testing/enzyme-wrapper-scope.js.map +1 -1
  183. package/dist/zustand/redux-stores.d.ts +2 -0
  184. package/dist/zustand/redux-stores.d.ts.map +1 -1
  185. package/dist/zustand/redux-stores.js +120 -6
  186. package/dist/zustand/redux-stores.js.map +1 -1
  187. package/dist/zustand/redux-to-zustand.d.ts.map +1 -1
  188. package/dist/zustand/redux-to-zustand.js +10 -4
  189. package/dist/zustand/redux-to-zustand.js.map +1 -1
  190. package/dist/zustand/zustand-plan.d.ts +7 -0
  191. package/dist/zustand/zustand-plan.d.ts.map +1 -1
  192. package/dist/zustand/zustand-plan.js +141 -21
  193. package/dist/zustand/zustand-plan.js.map +1 -1
  194. package/package.json +2 -2
  195. package/src/index.ts +10 -0
  196. package/src/migration/change-component-prop-value.ts +19 -8
  197. package/src/mui/adapt-v4-theme.ts +43 -0
  198. package/src/mui/add-component-prop.ts +43 -0
  199. package/src/mui/add-emotion-prepend.ts +48 -0
  200. package/src/mui/change-module-specifier.ts +71 -0
  201. package/src/mui/convert-mui-imports.ts +184 -0
  202. package/src/mui/convert-prop-to-sx.ts +89 -0
  203. package/src/mui/index.ts +31 -0
  204. package/src/mui/jsx-attributes.ts +133 -0
  205. package/src/mui/mark-manual-migration.ts +53 -0
  206. package/src/mui/mark-palette-mode-usage.ts +36 -0
  207. package/src/mui/move-component-prop-to-slot.ts +84 -0
  208. package/src/mui/move-primary-text-to-children.ts +41 -0
  209. package/src/mui/move-system-props-to-sx.ts +118 -0
  210. package/src/mui/mui-components.ts +40 -0
  211. package/src/mui/mui-tag-visitor.ts +36 -0
  212. package/src/mui/pre-v5-recipe.ts +82 -0
  213. package/src/mui/remove-component-prop.ts +43 -0
  214. package/src/mui/remove-root-ref.ts +41 -0
  215. package/src/mui/remove-spacing-px-suffix.ts +43 -0
  216. package/src/mui/rename-component-prop.ts +55 -0
  217. package/src/mui/rename-joy-css-variables.ts +41 -0
  218. package/src/mui/rename-theme-palette-type.ts +42 -0
  219. package/src/mui/replace-box-border-radius.ts +42 -0
  220. package/src/mui/replace-breakpoints-width.ts +28 -0
  221. package/src/mui/replace-component-class.ts +97 -0
  222. package/src/mui/replace-components-with-slots.ts +61 -0
  223. package/src/mui/replace-import-paths.ts +100 -0
  224. package/src/mui/replace-in-string-literals.ts +44 -0
  225. package/src/mui/replace-list-item-button-prop.ts +59 -0
  226. package/src/mui/replace-tabs-scroll-buttons.ts +31 -0
  227. package/src/mui/replace-theme-color-functions.ts +55 -0
  228. package/src/mui/replace-theme-spacing-unit.ts +59 -0
  229. package/src/mui/replace-typography-round.ts +29 -0
  230. package/src/mui/shift-hidden-down-props.ts +44 -0
  231. package/src/mui/theme-access.ts +18 -0
  232. package/src/mui/update-theme-breakpoints.ts +47 -0
  233. package/src/mui/upgrade-grid-props.ts +82 -0
  234. package/src/react19/use-context-hook.ts +2 -0
  235. package/src/search/find-enzyme-usage.ts +80 -7
  236. package/src/testing/enzyme-host-components.ts +110 -0
  237. package/src/testing/enzyme-render-blockers.ts +174 -9
  238. package/src/testing/enzyme-to-react-testing-library.ts +159 -25
  239. package/src/testing/enzyme-usage.ts +13 -0
  240. package/src/testing/enzyme-wrapper-scope.ts +27 -6
  241. package/src/zustand/redux-stores.ts +119 -5
  242. package/src/zustand/redux-to-zustand.ts +12 -5
  243. package/src/zustand/zustand-plan.ts +159 -18
@@ -0,0 +1,29 @@
1
+ import {ExecutionContext, Recipe, TreeVisitor, check, not} from "@openrewrite/rewrite";
2
+ import {JavaScriptVisitor, isVendoredOrBundled, template} from "@openrewrite/rewrite/javascript";
3
+ import {J} from "@openrewrite/rewrite/java";
4
+ import {endsWithName} from "./theme-access";
5
+
6
+ /**
7
+ * Replaces `theme.typography.round(x)`, which v5 removed, with its definition.
8
+ *
9
+ * Before: `theme.typography.round(16 / 14)`
10
+ * After: `Math.round(16 / 14 * 1e5) / 1e5`
11
+ *
12
+ * @see https://mui.com/material-ui/migration/v5-component-changes/#theme
13
+ */
14
+ export class ReplaceTypographyRound extends Recipe {
15
+ readonly name = "org.openrewrite.react.mui.replace-typography-round";
16
+ readonly displayName: string = "Replace `theme.typography.round()`";
17
+ readonly description: string = "Replaces `theme.typography.round(x)` with `Math.round(x * 1e5) / 1e5`.";
18
+
19
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
20
+ return check(not(isVendoredOrBundled()), new class extends JavaScriptVisitor<ExecutionContext> {
21
+ override async visitMethodInvocation(invocation: J.MethodInvocation, ctx: ExecutionContext): Promise<J | undefined> {
22
+ const visited = await super.visitMethodInvocation(invocation, ctx) as J.MethodInvocation;
23
+ if (visited.name.simpleName !== "round" || visited.arguments.elements.length !== 1 || !endsWithName(visited.select?.element, "typography")) return visited;
24
+ const replaced = await template`Math.round(${visited.arguments.elements[0].element} * 1e5) / 1e5`.apply(visited, this.cursor);
25
+ return replaced ? {...replaced, prefix: visited.prefix} as J : visited;
26
+ }
27
+ }());
28
+ }
29
+ }
@@ -0,0 +1,44 @@
1
+ import {ExecutionContext, TreeVisitor} from "@openrewrite/rewrite";
2
+ import {PreV5Recipe} from "./pre-v5-recipe";
3
+ import {J} from "@openrewrite/rewrite/java";
4
+ import {attributeName} from "./mui-components";
5
+ import {muiTagEditor} from "./mui-tag-visitor";
6
+
7
+ const SHIFT: Record<string, string> = {xsDown: "smDown", smDown: "mdDown", mdDown: "lgDown", lgDown: "xlDown"};
8
+
9
+ /**
10
+ * Shifts the `...Down` props of `Hidden` one breakpoint up, since v5 reads them as "below" where v4 read "up to".
11
+ *
12
+ * Before: `<Hidden xsDown />`, `<Hidden lgDown />`
13
+ * After: `<Hidden smDown />`, `<Hidden xlDown />`
14
+ *
15
+ * Every prop of a tag is shifted once, in one step, so that `smDown` that was `xsDown` is not shifted again.
16
+ *
17
+ * @see https://mui.com/material-ui/migration/v5-component-changes/#hidden
18
+ */
19
+ export class ShiftHiddenDownProps extends PreV5Recipe {
20
+ readonly name = "org.openrewrite.react.mui.shift-hidden-down-props";
21
+ readonly displayName: string = "Shift the `Hidden` `...Down` props one breakpoint up";
22
+ readonly description: string = "Renames `xsDown` to `smDown`, `smDown` to `mdDown`, `mdDown` to `lgDown` and `lgDown` to `xlDown` on `Hidden`, each prop once.";
23
+
24
+ /** The tags this recipe shifted, which the instance keeps across cycles, since a second cycle would shift them again. */
25
+ private readonly shifted = new Set<string>();
26
+
27
+ protected async v4Editor(): Promise<TreeVisitor<any, ExecutionContext>> {
28
+ const shifted = this.shifted;
29
+ return muiTagEditor("Hidden", undefined, async tag => {
30
+ if (shifted.has(tag.id)) return tag;
31
+ let changed = false;
32
+ const attributes = tag.attributes.map(a => {
33
+ const name = attributeName(a.element);
34
+ if (!name || !(name in SHIFT) || a.element.kind !== "org.openrewrite.javascript.tree.JSX$Attribute") return a;
35
+ changed = true;
36
+ const attribute = a.element as any;
37
+ return {...a, element: {...attribute, key: {...(attribute.key as J.Identifier), simpleName: SHIFT[name]}}};
38
+ });
39
+ if (!changed) return tag;
40
+ shifted.add(tag.id);
41
+ return {...tag, attributes} as typeof tag;
42
+ });
43
+ }
44
+ }
@@ -0,0 +1,18 @@
1
+ import {isIdentifier, J} from "@openrewrite/rewrite/java";
2
+
3
+ /** Whether an expression is `name` or ends with `.name`, such as `theme.breakpoints` for `breakpoints`. */
4
+ export function endsWithName(expression: J | undefined, name: string): boolean {
5
+ if (!expression) return false;
6
+ if (isIdentifier(expression)) return expression.simpleName === name;
7
+ return expression.kind === J.Kind.FieldAccess && (expression as J.FieldAccess).name.element.simpleName === name;
8
+ }
9
+
10
+ /** The text of a plain string literal, or undefined. */
11
+ export const stringValue = (e: J | undefined): string | undefined =>
12
+ e?.kind === J.Kind.Literal && typeof (e as J.Literal).value === "string" ? (e as J.Literal).value as string : undefined;
13
+
14
+ /** The literal with its text replaced, in the quotes it already has. */
15
+ export function withString(literal: J.Literal, text: string): J.Literal {
16
+ const quote = literal.valueSource?.charAt(0) ?? "'";
17
+ return {...literal, value: text, valueSource: `${quote}${text}${quote}`} as J.Literal;
18
+ }
@@ -0,0 +1,47 @@
1
+ import {ExecutionContext, TreeVisitor, check, not} from "@openrewrite/rewrite";
2
+ import {JavaScriptVisitor, isVendoredOrBundled} from "@openrewrite/rewrite/javascript";
3
+ import {PreV5Recipe} from "./pre-v5-recipe";
4
+ import {J} from "@openrewrite/rewrite/java";
5
+ import {endsWithName, stringValue, withString} from "./theme-access";
6
+
7
+ const NEXT = new Map([["xs", "sm"], ["sm", "md"], ["md", "lg"], ["lg", "xl"], ["xl", "xl"]]);
8
+
9
+ /**
10
+ * Moves the breakpoint values of `theme.breakpoints.down()` and the end of `between()` up one step, since v5 reads
11
+ * them as exclusive.
12
+ *
13
+ * Before: `theme.breakpoints.down('sm')`, `theme.breakpoints.between('sm', 'md')`
14
+ * After: `theme.breakpoints.down('md')`, `theme.breakpoints.between('sm', 'lg')`
15
+ *
16
+ * It is not idempotent: run it once.
17
+ *
18
+ * @see https://mui.com/material-ui/migration/v5-component-changes/#theme
19
+ */
20
+ export class UpdateThemeBreakpoints extends PreV5Recipe {
21
+ readonly name = "org.openrewrite.react.mui.update-theme-breakpoints";
22
+ readonly displayName: string = "Update theme breakpoint values for v5";
23
+ readonly description: string = "Moves the breakpoint passed to `theme.breakpoints.down()`, and the second one passed to `between()`, up one step to match the v5 logic. Not idempotent: run it once.";
24
+
25
+ /** The literals shifted so far in a run, which the recipe instance keeps across cycles, since a second cycle would shift them again. */
26
+ private readonly shifted = new Set<string>();
27
+
28
+ protected async v4Editor(): Promise<TreeVisitor<any, ExecutionContext>> {
29
+ const shifted = this.shifted;
30
+ return check(not(isVendoredOrBundled()), new class extends JavaScriptVisitor<ExecutionContext> {
31
+ override async visitMethodInvocation(invocation: J.MethodInvocation, ctx: ExecutionContext): Promise<J | undefined> {
32
+ const visited = await super.visitMethodInvocation(invocation, ctx) as J.MethodInvocation;
33
+ const name = visited.name.simpleName;
34
+ if ((name !== "down" && name !== "between") || !endsWithName(visited.select?.element, "breakpoints")) return visited;
35
+ const elements = visited.arguments.elements.map((a, i) => {
36
+ const value = stringValue(a.element);
37
+ const next = value && NEXT.get(value);
38
+ if (!next || !(name === "down" || i === 1) || shifted.has(a.element.id)) return a;
39
+ shifted.add(a.element.id);
40
+ return {...a, element: withString(a.element as J.Literal, next)};
41
+ });
42
+ if (elements.every((e, i) => e === visited.arguments.elements[i])) return visited;
43
+ return {...visited, arguments: {...visited.arguments, elements}} as J.MethodInvocation;
44
+ }
45
+ }());
46
+ }
47
+ }
@@ -0,0 +1,82 @@
1
+ import {Cursor, ExecutionContext, Option, Recipe, TreeVisitor} from "@openrewrite/rewrite";
2
+ import {JSX} from "@openrewrite/rewrite/javascript";
3
+ import {J} from "@openrewrite/rewrite/java";
4
+ import {
5
+ appendProperty, attributeExpression, bare, hasSpread, newAttribute, newObject, newProperty, sourceExpression, withAttributes
6
+ } from "./jsx-attributes";
7
+ import {attributeName} from "./mui-components";
8
+ import {muiTagEditor} from "./mui-tag-visitor";
9
+
10
+ const DEFAULT_BREAKPOINTS = ["xs", "sm", "md", "lg", "xl"];
11
+
12
+ /**
13
+ * Moves the breakpoint props of the responsive `Grid` into its `size` and `offset` props, and drops `item` and
14
+ * `zeroMinWidth`.
15
+ *
16
+ * Before: `<Grid item xs={12} sm={6} xsOffset={2} />`
17
+ * After: `<Grid size={{ xs: 12, sm: 6 }} offset={2} />`
18
+ *
19
+ * A prop without a value, such as a bare `xs`, becomes `"grow"`. A tag with a spread attribute is left alone.
20
+ *
21
+ * @see https://mui.com/material-ui/migration/upgrade-to-grid-v2/
22
+ */
23
+ export class UpgradeGridProps extends Recipe {
24
+ readonly name = "org.openrewrite.react.mui.upgrade-grid-props";
25
+ readonly displayName: string = "Upgrade the props of Grid to `size` and `offset`";
26
+ readonly description: string = "Moves the breakpoint props of the responsive Grid, `xs={12}` and `xsOffset={2}`, into its `size` and `offset` props, and removes `item` and `zeroMinWidth`. Tags with a spread attribute are left alone.";
27
+
28
+ @Option({displayName: "Component name", description: "The Grid component, `Grid` or `Grid2`.", example: "Grid"})
29
+ componentName!: string;
30
+
31
+ @Option({displayName: "Breakpoints", description: "The breakpoints of the theme, separated by commas.", example: "xs,sm,md,lg,xl", required: false})
32
+ breakpoints?: string;
33
+
34
+ @Option({displayName: "Package name", description: "A package that re-exports Material UI.", example: "@org/ui", required: false})
35
+ packageName?: string;
36
+
37
+ constructor(options?: { componentName?: string; breakpoints?: string; packageName?: string }) {
38
+ super(options);
39
+ }
40
+
41
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
42
+ const component = this.componentName;
43
+ const breakpoints = this.breakpoints ? this.breakpoints.split(",").map(s => s.trim()) : DEFAULT_BREAKPOINTS;
44
+
45
+ return muiTagEditor(component, this.packageName, async (visited, cursor) => {
46
+ if (hasSpread(visited)) return visited;
47
+ const attributes = visited.attributes.map(a => a.element as JSX.Attribute);
48
+ const sizes = attributes.filter(a => breakpoints.includes(attributeName(a) ?? ""));
49
+ const offsets = attributes.filter(a => breakpoints.includes((attributeName(a) ?? "").replace(/Offset$/, "")) && attributeName(a)!.endsWith("Offset"));
50
+ const obsolete = attributes.filter(a => ["item", "zeroMinWidth"].includes(attributeName(a) ?? ""));
51
+ if (!sizes.length && !offsets.length && !obsolete.length) return visited;
52
+
53
+ const created = new Map<JSX.Attribute, JSX.Attribute>();
54
+ for (const [group, name, suffix] of [[sizes, "size", ""], [offsets, "offset", "Offset"]] as const) {
55
+ if (!group.length) continue;
56
+ const entries: [string, J][] = [];
57
+ for (const attribute of group) {
58
+ const value = attribute.value ? attributeExpression(attribute) : undefined;
59
+ const isTrue = value?.kind === J.Kind.Literal && (value as J.Literal).value === true;
60
+ entries.push([attributeName(attribute)!.slice(0, attributeName(attribute)!.length - suffix.length),
61
+ !value || isTrue ? await sourceExpression(cursor, visited, '"grow"') : bare(value)]);
62
+ }
63
+ created.set(group[0], await build(cursor, visited, name, entries));
64
+ }
65
+ const removed = new Set<unknown>([...sizes, ...offsets, ...obsolete]);
66
+ return withAttributes(visited, visited.attributes.flatMap(a => {
67
+ const attribute = a.element as JSX.Attribute;
68
+ const replacement = created.get(attribute);
69
+ if (replacement) return [{...a, element: {...replacement, prefix: attribute.prefix}}];
70
+ return removed.has(attribute) ? [] : [a];
71
+ }));
72
+ });
73
+ }
74
+ }
75
+
76
+ /** `name={value}` for a lone `xs`, and `name={{ xs: a, md: b }}` otherwise. */
77
+ async function build(cursor: Cursor, tag: JSX.Tag, name: string, entries: [string, J][]): Promise<JSX.Attribute> {
78
+ if (entries.length === 1 && entries[0][0] === "xs") return newAttribute(cursor, tag, name, entries[0][1]);
79
+ let object = await newObject(cursor, tag, entries[0][0], entries[0][1]);
80
+ for (const [key, value] of entries.slice(1)) object = appendProperty(object, await newProperty(cursor, tag, key, value));
81
+ return newAttribute(cursor, tag, name, object);
82
+ }
@@ -58,6 +58,8 @@ export class UseContextHook extends Recipe {
58
58
  override async visitMethodInvocation(method: J.MethodInvocation, p: ExecutionContext): Promise<J | undefined> {
59
59
  let m = await super.visitMethodInvocation(method, p) as J.MethodInvocation;
60
60
 
61
+ // `use` has no type argument to carry over: dropping `useContext<any>` would retype every consumer from the context's default
62
+ if (m.typeParameters) return m;
61
63
  const result = await rule.tryOn(this.cursor, m!, {visitor: this});
62
64
  if (result) {
63
65
  maybeRemoveImport(this, "react", "useContext");
@@ -1,7 +1,7 @@
1
1
  import {and, check, not, or, DataTable, ExecutionContext, foundSearchResult, Recipe, RecipeRef, TreeVisitor} from "@openrewrite/rewrite";
2
2
  import {isObjectLiteral, isVendoredOrBundled, JavaScriptVisitor, JS, usesMethod, usesType} from "@openrewrite/rewrite/javascript";
3
3
  import {isIdentifier, J, Type, TypedTree} from "@openrewrite/rewrite/java";
4
- import {enclosingScope, ENZYME_GUIDE, ENZYME_USAGE_TABLE, enzymeMethod, enzymeModule, enzymeWrapper, EnzymeUsageRow, EventKind, FILE_BLOCKER, migrationReason, RENDER_BLOCKERS, SelectorKind} from "../testing/enzyme-usage";
4
+ import {enclosingScope, ENZYME_GUIDE, ENZYME_USAGE_TABLE, enzymeMethod, enzymeModule, enzymeWrapper, EnzymeUsageRow, EventKind, FILE_BLOCKER, migrationReason, RENDER_BLOCKERS, SELECTOR_VALUES, SelectorKind, unreadSelector} from "../testing/enzyme-usage";
5
5
  import {domSelector, objectProperties, simulatedEvent} from "../testing/enzyme-wrapper-scope";
6
6
 
7
7
  const LENGTH_ACTION = "Use the `length` of the `querySelectorAll` or `getAllBy*` result. For a component selector, count the elements the component renders.";
@@ -39,14 +39,18 @@ export function eventKind(api: string, [name, mock]: J[]): EventKind | undefined
39
39
  return ["mouseEnter", "mouseLeave", "mouseOver", "mouseOut"].includes(event) ? "hover" : "event";
40
40
  }
41
41
 
42
+ /** What a selector string matches by. */
43
+ export function stringSelectorKind(value: string): SelectorKind {
44
+ // Enzyme reads a selector starting with a capital as a component's display name
45
+ return /^[A-Z]/.test(value) ? "component" : domSelector(value) ? "dom" : "enzyme";
46
+ }
47
+
42
48
  export function selectorKind(api: string, selector: J | undefined): SelectorKind | undefined {
43
49
  if (api === "findWhere" || api === "filterWhere") return "predicate";
44
50
  if (api !== "find" || !selector) return undefined;
45
51
  if (selector.kind === J.Kind.Literal) {
46
52
  const value = (selector as J.Literal).value;
47
- if (typeof value !== "string") return undefined;
48
- // Enzyme reads a selector starting with a capital as a component's display name
49
- return /^[A-Z]/.test(value) ? "component" : domSelector(value) ? "dom" : "enzyme";
53
+ return typeof value === "string" ? stringSelectorKind(value) : undefined;
50
54
  }
51
55
  if (isObjectLiteral(selector)) return "props";
52
56
  const name = isIdentifier(selector) ? selector.simpleName :
@@ -54,6 +58,68 @@ export function selectorKind(api: string, selector: J | undefined): SelectorKind
54
58
  return name && /^[A-Z]/.test(name) && TypedTree.getType(selector) !== Type.Primitive.String ? "component" : undefined;
55
59
  }
56
60
 
61
+ const IMPORT_REVIEW = "Review this import and its consumers; unresolved or indirect calls require manual inspection. Keep it while Enzyme consumers remain.";
62
+
63
+ function moduleOf(imp: JS.Import): string | undefined {
64
+ const module = imp.moduleSpecifier?.element;
65
+ return module?.kind === J.Kind.Literal ? (module as J.Literal).value as string : undefined;
66
+ }
67
+
68
+ /** The local names an import binds: its default, named and type-only specifiers, and a namespace. */
69
+ export function importedLocals(imp: JS.Import): string[] {
70
+ const clause = imp.importClause;
71
+ if (!clause) return [];
72
+ const names = clause.name ? [clause.name.element.simpleName] : [];
73
+ const bindings = clause.namedBindings;
74
+ if (bindings?.kind === JS.Kind.Alias && isIdentifier((bindings as JS.Alias).alias)) names.push(((bindings as JS.Alias).alias as J.Identifier).simpleName);
75
+ if (bindings?.kind === JS.Kind.NamedImports) {
76
+ for (const {element: imported} of (bindings as JS.NamedImports).elements.elements) {
77
+ if (imported.kind !== JS.Kind.ImportSpecifier) continue;
78
+ const named = (imported as JS.ImportSpecifier).specifier;
79
+ if (isIdentifier(named)) names.push(named.simpleName);
80
+ else if (named.kind === JS.Kind.Alias && isIdentifier((named as JS.Alias).alias)) names.push(((named as JS.Alias).alias as J.Identifier).simpleName);
81
+ }
82
+ }
83
+ return names;
84
+ }
85
+
86
+ /** How often the source refers to each of `names` outside its imports, leaving out member names such as `wrapper.mount()`. */
87
+ async function referencesTo(cu: JS.CompilationUnit, names: ReadonlySet<string>, ctx: ExecutionContext): Promise<Map<string, number>> {
88
+ const counts = new Map<string, number>();
89
+ if (names.size === 0) return counts;
90
+ await new class extends JavaScriptVisitor<ExecutionContext> {
91
+ override async visitImportDeclaration(imp: JS.Import): Promise<J | undefined> {
92
+ return imp;
93
+ }
94
+
95
+ override async visitIdentifier(identifier: J.Identifier, p: ExecutionContext): Promise<J | undefined> {
96
+ if (names.has(identifier.simpleName)) {
97
+ const parent = this.cursor.parentTree()?.value as J | undefined;
98
+ const member = parent?.kind === J.Kind.FieldAccess && (parent as J.FieldAccess).name.element === identifier ||
99
+ parent?.kind === J.Kind.MethodInvocation && (parent as J.MethodInvocation).name === identifier && (parent as J.MethodInvocation).select !== undefined;
100
+ if (!member) counts.set(identifier.simpleName, (counts.get(identifier.simpleName) ?? 0) + 1);
101
+ }
102
+ return super.visitIdentifier(identifier, p);
103
+ }
104
+ }().visit(cu, ctx);
105
+ return counts;
106
+ }
107
+
108
+ /** What to do with an Enzyme import: which of its names the source still uses, and how often, or that it uses none. */
109
+ export function importAction(locals: readonly string[], references: ReadonlyMap<string, number>): string {
110
+ if (locals.length === 0) return IMPORT_REVIEW;
111
+ const quoted = (names: string[]) => names.map(name => `\`${name}\``).join(", ");
112
+ const used = locals.filter(name => (references.get(name) ?? 0) > 0);
113
+ const unused = locals.filter(name => !used.includes(name));
114
+ if (used.length === 0) return `This file uses none of the names this import binds, ${quoted(unused)}: remove the import.`;
115
+ const kept = used.map(name => {
116
+ const count = references.get(name)!;
117
+ return `\`${name}\` (${count} ${count === 1 ? "use" : "uses"})`;
118
+ }).join(", ");
119
+ const rest = unused.length === 0 ? "" : ` This file doesn't use ${quoted(unused)}, so remove ${unused.length === 1 ? "it" : "them"} from the import.`;
120
+ return `Kept for ${kept} in this file. Remove a name from this import once no use of it remains.${rest}`;
121
+ }
122
+
57
123
  /**
58
124
  * Inventories imports/setup even when types are unavailable; calls and wrapper fields are
59
125
  * attributed to Enzyme by declaring type, not by names such as `find` or `state`.
@@ -81,9 +147,12 @@ export class FindEnzymeUsage extends Recipe {
81
147
  );
82
148
  return check(and(not(isVendoredOrBundled()), relevant), new class extends JavaScriptVisitor<ExecutionContext> {
83
149
  private sourcePath = "";
150
+ private references = new Map<string, number>();
84
151
 
85
152
  override async visitJsCompilationUnit(cu: JS.CompilationUnit, ctx: ExecutionContext): Promise<J | undefined> {
86
153
  this.sourcePath = cu.sourcePath;
154
+ this.references = await referencesTo(cu, new Set(cu.statements.flatMap(({element}) => element.kind === JS.Kind.Import &&
155
+ enzymeModule(moduleOf(element as JS.Import)) ? importedLocals(element as JS.Import) : [])), ctx);
87
156
  return super.visitJsCompilationUnit(cu, ctx);
88
157
  }
89
158
 
@@ -92,8 +161,7 @@ export class FindEnzymeUsage extends Recipe {
92
161
  const moduleName = module?.kind === J.Kind.Literal ? (module as J.Literal).value : undefined;
93
162
  const result = await super.visitImportDeclaration(imp, ctx) as JS.Import;
94
163
  if (!enzymeModule(moduleName)) return result;
95
- return this.report(result, moduleName, "MODULE_REFERENCE",
96
- "Review this import and its consumers; unresolved or indirect calls require manual inspection. Keep it while Enzyme consumers remain.", ctx);
164
+ return this.report(result, moduleName, "MODULE_REFERENCE", importAction(importedLocals(imp), this.references), ctx);
97
165
  }
98
166
 
99
167
  override async visitExportDeclaration(exp: JS.ExportDeclaration, ctx: ExecutionContext): Promise<J | undefined> {
@@ -121,7 +189,12 @@ export class FindEnzymeUsage extends Recipe {
121
189
  }
122
190
  const api = enzymeMethod(method);
123
191
  if (!api) return result;
124
- const {reason, suggestedAction} = migrationReason(api, selectorKind(api, args[0]), eventKind(api, args));
192
+ // The converter, run before this, read the string a selector other than a literal holds, where it could
193
+ const read = api === "find" ? SELECTOR_VALUES.get(this.sourcePath)?.get(method.id) : undefined;
194
+ const selector = read && "value" in read ? stringSelectorKind(read.value) : selectorKind(api, args[0]);
195
+ const migration = migrationReason(api, selector, eventKind(api, args));
196
+ const {reason} = migration;
197
+ const suggestedAction = read && "unread" in read ? unreadSelector(read.unread) : migration.suggestedAction;
125
198
  // The converter, run before this, says what kept a render it left on Enzyme
126
199
  const blocker = reason === "RENDER_REVIEW" || reason === "SHALLOW_RENDERING" ? (RENDER_BLOCKERS.get(this.sourcePath)?.get(method.id) ?? RENDER_BLOCKERS.get(this.sourcePath)?.get(FILE_BLOCKER)) : undefined;
127
200
  if (blocker) return this.report(result, api, reason, blocker, ctx);
@@ -31,6 +31,9 @@ const SAME_IN_SHALLOW = new Set(["useState", "useReducer", "useMemo", "useCallba
31
31
 
32
32
  const HOOK = /^use[A-Z0-9]/;
33
33
 
34
+ // Of RENDERS_OTHERWISE, what runs only in a full render rather than creating elements a JSX tag doesn't show
35
+ const RUNS_OTHERWISE = new Set(["useEffect", "useLayoutEffect", "useInsertionEffect", "ref"]);
36
+
34
37
  const FRAGMENT = new Set(["Fragment"]);
35
38
 
36
39
  /** A lowercase tag is an intrinsic element and an empty one a fragment, which renders its children. */
@@ -320,3 +323,110 @@ export function rendersHostElements(element: J, imports: ReadonlyMap<string, Imp
320
323
  (tag.children ?? []).every(child => hostElementsOnly(child, testImports) &&
321
324
  (child.kind !== JS.Kind.JsxEmbeddedExpression || rendersAsHost((child as JSX.EmbeddedExpression).expression.element, testImports)));
322
325
  }
326
+
327
+ /** What a component renders that `shallow` leaves out or doesn't run, and the code that names it, such as "`<Button>` from `@patternfly/react-core`". */
328
+ export interface ShallowMiss {
329
+ kind: "child" | "effect" | "hook" | "wrapped" | "package" | "passed";
330
+ detail: string;
331
+ }
332
+
333
+ /** Each source's first {@link ShallowMiss}, and its exports that are a call, such as `memo(...)`, with the callee. */
334
+ export interface CompositeFacts {
335
+ miss?: ShallowMiss;
336
+ wrapped: ReadonlyMap<string, string>;
337
+ }
338
+
339
+ export type Composites = Map<string, CompositeFacts>;
340
+
341
+ function tagName(tag: JSX.Tag): string | undefined {
342
+ const name = tag.openName.element;
343
+ return isIdentifier(name) ? name.simpleName : name.kind === J.Kind.FieldAccess ? `${rootName(name as J.FieldAccess)}.${(name as J.FieldAccess).name.element.simpleName}` : undefined;
344
+ }
345
+
346
+ /** `name` as code, with the module its root is imported from, such as "`<Button>` from `@patternfly/react-core`". */
347
+ function named(name: string, bindings: ReturnType<typeof importBindings>, shown = name): string {
348
+ const module = bindings.find(({local}) => local === name.split(".")[0])?.module;
349
+ return module ? `\`${shown}\` from \`${module}\`` : `\`${shown}\``;
350
+ }
351
+
352
+ /** The callee of a call, such as `forwardRef`, `styled.div` or `withSize`, for `withSize()(Actions)`. */
353
+ function callee(node: J): string | undefined {
354
+ if (node.kind !== J.Kind.MethodInvocation) return undefined;
355
+ const call = node as J.MethodInvocation;
356
+ const select = call.select?.element;
357
+ if (select?.kind === J.Kind.MethodInvocation) return callee(select);
358
+ return select && rootName(select as Expression) ? `${rootName(select as Expression)}.${call.name.simpleName}` : call.name.simpleName;
359
+ }
360
+
361
+ /**
362
+ * Why the components a source declares may render what `shallow` leaves out: the first element of a component, effect or
363
+ * hook that {@link hostElementsOnly} rejects, and each export that wraps a component in a call. Undefined where it declares none.
364
+ */
365
+ export function compositeFacts(cu: JS.CompilationUnit): CompositeFacts | undefined {
366
+ const wrapped = new Map<string, string>();
367
+ for (const {element} of cu.statements) {
368
+ const statement = element.kind === JS.Kind.ExportDeclaration ? undefined : element;
369
+ if (statement?.kind !== J.Kind.VariableDeclarations) continue;
370
+ const declaration = statement as J.VariableDeclarations;
371
+ const variable = declaration.variables.length === 1 ? declaration.variables[0].element : undefined;
372
+ const initializer = variable?.initializer?.element;
373
+ const exported = variable && isIdentifier(variable.name) ? exportName(declaration, variable.name.simpleName) : undefined;
374
+ const wrapper = initializer && callee(initializer);
375
+ if (exported && wrapper) wrapped.set(exported, wrapper);
376
+ }
377
+ for (const {element} of cu.statements) {
378
+ if (element.kind !== JS.Kind.ExportAssignment || (element as JS.ExportAssignment).exportEquals) continue;
379
+ const wrapper = callee((element as JS.ExportAssignment).expression.element);
380
+ if (wrapper) wrapped.set("default", wrapper);
381
+ }
382
+ if (wrapped.size === 0 && componentExports(cu).size === 0) return undefined;
383
+ const bindings = importBindings(cu);
384
+ let miss: ShallowMiss | undefined;
385
+ const hook = bindings.find(({local, module}) => HOOK.test(local) && module !== "react");
386
+ if (hook) miss = {kind: "hook", detail: named(hook.local, bindings)};
387
+ walk(cu, tree => {
388
+ if (miss) return false;
389
+ if (tree.kind === J.Kind.Identifier && RENDERS_OTHERWISE.has((tree as J.Identifier).simpleName)) {
390
+ const name = (tree as J.Identifier).simpleName;
391
+ miss = {kind: RUNS_OTHERWISE.has(name) ? "effect" : "child", detail: `\`${name}\``};
392
+ } else if (tree.kind === J.Kind.MethodInvocation && HOOK.test((tree as J.MethodInvocation).name.simpleName) &&
393
+ !SAME_IN_SHALLOW.has((tree as J.MethodInvocation).name.simpleName)) {
394
+ const name = (tree as J.MethodInvocation).name.simpleName;
395
+ miss = RUNS_OTHERWISE.has(name) ? {kind: "effect", detail: `\`${name}\``} : {kind: "hook", detail: named(name, bindings)};
396
+ } else if (tree.kind === JS.Kind.JsxTag && !hostTag(tree as JSX.Tag)) {
397
+ const name = tagName(tree as JSX.Tag);
398
+ if (name) miss = {kind: "child", detail: named(name, bindings, `<${name}>`)};
399
+ }
400
+ return !miss;
401
+ });
402
+ return {miss, wrapped};
403
+ }
404
+
405
+ /**
406
+ * What a `shallow` of `element` leaves out where {@link rendersHostElements} rejects it: an element of a component passed in
407
+ * its props or children, a component from a package, or what the component's own source renders. Undefined where it can't tell.
408
+ */
409
+ export function shallowMiss(element: J, imports: ReadonlyMap<string, ImportedExport>, components: HostComponents, composites: Composites,
410
+ bindings: ReturnType<typeof importBindings>): ShallowMiss | undefined {
411
+ if (element.kind !== JS.Kind.JsxTag) return undefined;
412
+ const tag = element as JSX.Tag;
413
+ const name = tag.openName.element;
414
+ if (!isIdentifier(name)) return undefined;
415
+ const source = imports.get(name.simpleName);
416
+ if (!source) {
417
+ const module = bindings.find(({local}) => local === name.simpleName)?.module;
418
+ return module && !module.startsWith(".") ? {kind: "package", detail: named(name.simpleName, bindings, `<${name.simpleName}>`)} : undefined;
419
+ }
420
+ if (components.get(source.path)?.has(source.name)) {
421
+ let passed: string | undefined;
422
+ walk(tag, tree => {
423
+ if (passed) return false;
424
+ if (tree !== tag && tree.kind === JS.Kind.JsxTag && !hostTag(tree as JSX.Tag)) passed = tagName(tree as JSX.Tag);
425
+ return !passed;
426
+ });
427
+ return passed ? {kind: "passed", detail: named(passed, bindings, `<${passed}>`)} : undefined;
428
+ }
429
+ const facts = composites.get(source.path);
430
+ const wrapper = facts?.wrapped.get(source.name);
431
+ return wrapper ? {kind: "wrapped", detail: `\`${wrapper}\``} : facts?.miss;
432
+ }