@openrewrite/recipes-angular 1.28.0 → 1.29.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 (302) hide show
  1. package/dist/index.d.ts +9 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +42 -6
  4. package/dist/index.js.map +1 -1
  5. package/dist/libraries/cdk/find-cdk-signature-changes.d.ts +0 -2
  6. package/dist/libraries/cdk/find-cdk-signature-changes.d.ts.map +1 -1
  7. package/dist/libraries/cdk/find-cdk-signature-changes.js +2 -8
  8. package/dist/libraries/cdk/find-cdk-signature-changes.js.map +1 -1
  9. package/dist/libraries/cdk/migrate-cdk-sass-imports.d.ts.map +1 -1
  10. package/dist/libraries/cdk/migrate-cdk-sass-imports.js +4 -7
  11. package/dist/libraries/cdk/migrate-cdk-sass-imports.js.map +1 -1
  12. package/dist/libraries/cdk/migrate-cdk-stepper.js +1 -1
  13. package/dist/libraries/cdk/migrate-cdk-stepper.js.map +1 -1
  14. package/dist/libraries/cdk/migrate-deprecated-overlay-sass.d.ts.map +1 -1
  15. package/dist/libraries/cdk/migrate-deprecated-overlay-sass.js +2 -4
  16. package/dist/libraries/cdk/migrate-deprecated-overlay-sass.js.map +1 -1
  17. package/dist/libraries/cdk/migrate-focus-trap-factory-create.d.ts.map +1 -1
  18. package/dist/libraries/cdk/migrate-focus-trap-factory-create.js +2 -1
  19. package/dist/libraries/cdk/migrate-focus-trap-factory-create.js.map +1 -1
  20. package/dist/libraries/cdk/remove-cdk-super-arguments.d.ts.map +1 -1
  21. package/dist/libraries/cdk/remove-cdk-super-arguments.js +1 -2
  22. package/dist/libraries/cdk/remove-cdk-super-arguments.js.map +1 -1
  23. package/dist/libraries/cdk/remove-portal-factory-resolver-arguments.d.ts.map +1 -1
  24. package/dist/libraries/cdk/remove-portal-factory-resolver-arguments.js +5 -7
  25. package/dist/libraries/cdk/remove-portal-factory-resolver-arguments.js.map +1 -1
  26. package/dist/libraries/cdk/rename-portal-template-selectors.d.ts.map +1 -1
  27. package/dist/libraries/cdk/rename-portal-template-selectors.js +3 -4
  28. package/dist/libraries/cdk/rename-portal-template-selectors.js.map +1 -1
  29. package/dist/libraries/cdk/upgrade-to-cdk.d.ts.map +1 -1
  30. package/dist/libraries/cdk/upgrade-to-cdk.js +7 -12
  31. package/dist/libraries/cdk/upgrade-to-cdk.js.map +1 -1
  32. package/dist/libraries/components/lst.d.ts +5 -1
  33. package/dist/libraries/components/lst.d.ts.map +1 -1
  34. package/dist/libraries/components/lst.js +28 -0
  35. package/dist/libraries/components/lst.js.map +1 -1
  36. package/dist/libraries/components/style-sources.d.ts +2 -5
  37. package/dist/libraries/components/style-sources.d.ts.map +1 -1
  38. package/dist/libraries/components/style-sources.js +31 -46
  39. package/dist/libraries/components/style-sources.js.map +1 -1
  40. package/dist/libraries/components/stylesheets.d.ts +1 -0
  41. package/dist/libraries/components/stylesheets.d.ts.map +1 -1
  42. package/dist/libraries/components/stylesheets.js +18 -16
  43. package/dist/libraries/components/stylesheets.js.map +1 -1
  44. package/dist/libraries/components/symbols.d.ts +4 -21
  45. package/dist/libraries/components/symbols.d.ts.map +1 -1
  46. package/dist/libraries/components/symbols.js +12 -124
  47. package/dist/libraries/components/symbols.js.map +1 -1
  48. package/dist/libraries/components/template-elements.d.ts +2 -0
  49. package/dist/libraries/components/template-elements.d.ts.map +1 -1
  50. package/dist/libraries/components/template-elements.js +6 -0
  51. package/dist/libraries/components/template-elements.js.map +1 -1
  52. package/dist/libraries/components/templates.d.ts +1 -0
  53. package/dist/libraries/components/templates.d.ts.map +1 -1
  54. package/dist/libraries/components/templates.js +43 -47
  55. package/dist/libraries/components/templates.js.map +1 -1
  56. package/dist/libraries/material/add-system-variables-prefix.d.ts +5 -3
  57. package/dist/libraries/material/add-system-variables-prefix.d.ts.map +1 -1
  58. package/dist/libraries/material/add-system-variables-prefix.js +35 -11
  59. package/dist/libraries/material/add-system-variables-prefix.js.map +1 -1
  60. package/dist/libraries/material/add-theme-base-mixins.d.ts.map +1 -1
  61. package/dist/libraries/material/add-theme-base-mixins.js +7 -7
  62. package/dist/libraries/material/add-theme-base-mixins.js.map +1 -1
  63. package/dist/libraries/material/find-chip-input-event-without-chip-input.d.ts.map +1 -1
  64. package/dist/libraries/material/find-chip-input-event-without-chip-input.js +1 -2
  65. package/dist/libraries/material/find-chip-input-event-without-chip-input.js.map +1 -1
  66. package/dist/libraries/material/find-legacy-material-usage.d.ts.map +1 -1
  67. package/dist/libraries/material/find-legacy-material-usage.js +3 -11
  68. package/dist/libraries/material/find-legacy-material-usage.js.map +1 -1
  69. package/dist/libraries/material/find-material-constructor-changes.d.ts.map +1 -1
  70. package/dist/libraries/material/find-material-constructor-changes.js +2 -3
  71. package/dist/libraries/material/find-material-constructor-changes.js.map +1 -1
  72. package/dist/libraries/material/find-mdc-breaking-changes.d.ts.map +1 -1
  73. package/dist/libraries/material/find-mdc-breaking-changes.js +4 -18
  74. package/dist/libraries/material/find-mdc-breaking-changes.js.map +1 -1
  75. package/dist/libraries/material/find-mixin-error-state-without-state-changes.js +1 -1
  76. package/dist/libraries/material/find-mixin-error-state-without-state-changes.js.map +1 -1
  77. package/dist/libraries/material/find-raw-palette-themes.d.ts.map +1 -1
  78. package/dist/libraries/material/find-raw-palette-themes.js +3 -5
  79. package/dist/libraries/material/find-raw-palette-themes.js.map +1 -1
  80. package/dist/libraries/material/find-removed-material-classes.d.ts.map +1 -1
  81. package/dist/libraries/material/find-removed-material-classes.js +4 -14
  82. package/dist/libraries/material/find-removed-material-classes.js.map +1 -1
  83. package/dist/libraries/material/find-removed-material-members.d.ts.map +1 -1
  84. package/dist/libraries/material/find-removed-material-members.js +2 -3
  85. package/dist/libraries/material/find-removed-material-members.js.map +1 -1
  86. package/dist/libraries/material/find-slide-toggle-drag-options.d.ts +5 -3
  87. package/dist/libraries/material/find-slide-toggle-drag-options.d.ts.map +1 -1
  88. package/dist/libraries/material/find-slide-toggle-drag-options.js +7 -13
  89. package/dist/libraries/material/find-slide-toggle-drag-options.js.map +1 -1
  90. package/dist/libraries/material/material-version.d.ts +16 -2
  91. package/dist/libraries/material/material-version.d.ts.map +1 -1
  92. package/dist/libraries/material/material-version.js +35 -5
  93. package/dist/libraries/material/material-version.js.map +1 -1
  94. package/dist/libraries/material/migrate-legacy-material.d.ts.map +1 -1
  95. package/dist/libraries/material/migrate-legacy-material.js +5 -11
  96. package/dist/libraries/material/migrate-legacy-material.js.map +1 -1
  97. package/dist/libraries/material/migrate-m2-theming-api.d.ts.map +1 -1
  98. package/dist/libraries/material/migrate-m2-theming-api.js +3 -6
  99. package/dist/libraries/material/migrate-m2-theming-api.js.map +1 -1
  100. package/dist/libraries/material/migrate-mat-core-to-elevation-classes.d.ts +5 -3
  101. package/dist/libraries/material/migrate-mat-core-to-elevation-classes.d.ts.map +1 -1
  102. package/dist/libraries/material/migrate-mat-core-to-elevation-classes.js +15 -3
  103. package/dist/libraries/material/migrate-mat-core-to-elevation-classes.js.map +1 -1
  104. package/dist/libraries/material/migrate-material-15-typography.d.ts.map +1 -1
  105. package/dist/libraries/material/migrate-material-15-typography.js +9 -20
  106. package/dist/libraries/material/migrate-material-15-typography.js.map +1 -1
  107. package/dist/libraries/material/migrate-material-secondary-entry-points.d.ts.map +1 -1
  108. package/dist/libraries/material/migrate-material-secondary-entry-points.js +41 -2
  109. package/dist/libraries/material/migrate-material-secondary-entry-points.js.map +1 -1
  110. package/dist/libraries/material/migrate-material-theming-api.d.ts +1 -0
  111. package/dist/libraries/material/migrate-material-theming-api.d.ts.map +1 -1
  112. package/dist/libraries/material/migrate-material-theming-api.js +33 -24
  113. package/dist/libraries/material/migrate-material-theming-api.js.map +1 -1
  114. package/dist/libraries/material/migrate-mdc-styles.d.ts.map +1 -1
  115. package/dist/libraries/material/migrate-mdc-styles.js +5 -14
  116. package/dist/libraries/material/migrate-mdc-styles.js.map +1 -1
  117. package/dist/libraries/material/migrate-mdc-templates.d.ts.map +1 -1
  118. package/dist/libraries/material/migrate-mdc-templates.js +54 -30
  119. package/dist/libraries/material/migrate-mdc-templates.js.map +1 -1
  120. package/dist/libraries/material/remove-mat-stepper-document-argument.d.ts.map +1 -1
  121. package/dist/libraries/material/remove-mat-stepper-document-argument.js +1 -2
  122. package/dist/libraries/material/remove-mat-stepper-document-argument.js.map +1 -1
  123. package/dist/libraries/material/remove-update-active-link-argument.d.ts.map +1 -1
  124. package/dist/libraries/material/remove-update-active-link-argument.js +1 -2
  125. package/dist/libraries/material/remove-update-active-link-argument.js.map +1 -1
  126. package/dist/libraries/material/rename-material-style-names.d.ts +14 -7
  127. package/dist/libraries/material/rename-material-style-names.d.ts.map +1 -1
  128. package/dist/libraries/material/rename-material-style-names.js +69 -35
  129. package/dist/libraries/material/rename-material-style-names.js.map +1 -1
  130. package/dist/libraries/material/rename-textarea-autosize-attributes.d.ts +5 -15
  131. package/dist/libraries/material/rename-textarea-autosize-attributes.d.ts.map +1 -1
  132. package/dist/libraries/material/rename-textarea-autosize-attributes.js +30 -15
  133. package/dist/libraries/material/rename-textarea-autosize-attributes.js.map +1 -1
  134. package/dist/libraries/material/upgrade-to-material.d.ts.map +1 -1
  135. package/dist/libraries/material/upgrade-to-material.js +19 -31
  136. package/dist/libraries/material/upgrade-to-material.js.map +1 -1
  137. package/dist/migration/js-support.d.ts +1 -1
  138. package/dist/migration/js-support.d.ts.map +1 -1
  139. package/dist/migration/js-support.js +2 -2
  140. package/dist/migration/js-support.js.map +1 -1
  141. package/dist/migration/json-support.d.ts +11 -0
  142. package/dist/migration/json-support.d.ts.map +1 -1
  143. package/dist/migration/json-support.js +50 -0
  144. package/dist/migration/json-support.js.map +1 -1
  145. package/dist/migration/move-common-engine-to-ssr-node.d.ts +8 -0
  146. package/dist/migration/move-common-engine-to-ssr-node.d.ts.map +1 -0
  147. package/dist/migration/move-common-engine-to-ssr-node.js +68 -0
  148. package/dist/migration/move-common-engine-to-ssr-node.js.map +1 -0
  149. package/dist/migration/remove-guard-and-resolve-interfaces.d.ts +8 -0
  150. package/dist/migration/remove-guard-and-resolve-interfaces.d.ts.map +1 -0
  151. package/dist/migration/remove-guard-and-resolve-interfaces.js +117 -0
  152. package/dist/migration/remove-guard-and-resolve-interfaces.js.map +1 -0
  153. package/dist/migration/remove-show-circular-dependencies.d.ts +8 -0
  154. package/dist/migration/remove-show-circular-dependencies.d.ts.map +1 -0
  155. package/dist/migration/remove-show-circular-dependencies.js +57 -0
  156. package/dist/migration/remove-show-circular-dependencies.js.map +1 -0
  157. package/dist/migration/rename-ssr-experimental-platform.d.ts.map +1 -1
  158. package/dist/migration/rename-ssr-experimental-platform.js +10 -47
  159. package/dist/migration/rename-ssr-experimental-platform.js.map +1 -1
  160. package/dist/migration/replace-browser-target.d.ts +8 -0
  161. package/dist/migration/replace-browser-target.d.ts.map +1 -0
  162. package/dist/migration/replace-browser-target.js +62 -0
  163. package/dist/migration/replace-browser-target.js.map +1 -0
  164. package/dist/migration/replace-default-collection.d.ts +8 -0
  165. package/dist/migration/replace-default-collection.d.ts.map +1 -0
  166. package/dist/migration/replace-default-collection.js +59 -0
  167. package/dist/migration/replace-default-collection.js.map +1 -0
  168. package/dist/migration/replace-get-current-navigation.d.ts +8 -0
  169. package/dist/migration/replace-get-current-navigation.d.ts.map +1 -0
  170. package/dist/migration/replace-get-current-navigation.js +69 -0
  171. package/dist/migration/replace-get-current-navigation.js.map +1 -0
  172. package/dist/migration/replace-initializer-providers.d.ts +8 -0
  173. package/dist/migration/replace-initializer-providers.d.ts.map +1 -0
  174. package/dist/migration/replace-initializer-providers.js +169 -0
  175. package/dist/migration/replace-initializer-providers.js.map +1 -0
  176. package/dist/migration/replace-preserve-query-params.d.ts +8 -0
  177. package/dist/migration/replace-preserve-query-params.d.ts.map +1 -0
  178. package/dist/migration/replace-preserve-query-params.js +115 -0
  179. package/dist/migration/replace-preserve-query-params.js.map +1 -0
  180. package/dist/migration/replace-provide-server-routing.d.ts +8 -0
  181. package/dist/migration/replace-provide-server-routing.d.ts.map +1 -0
  182. package/dist/migration/replace-provide-server-routing.js +98 -0
  183. package/dist/migration/replace-provide-server-routing.js.map +1 -0
  184. package/dist/migration/upgrade-angular-dependencies.d.ts +0 -2
  185. package/dist/migration/upgrade-angular-dependencies.d.ts.map +1 -1
  186. package/dist/migration/upgrade-angular-dependencies.js +0 -6
  187. package/dist/migration/upgrade-angular-dependencies.js.map +1 -1
  188. package/dist/migration/upgrade-to-angular-10.d.ts.map +1 -1
  189. package/dist/migration/upgrade-to-angular-10.js +1 -2
  190. package/dist/migration/upgrade-to-angular-10.js.map +1 -1
  191. package/dist/migration/upgrade-to-angular-11.d.ts.map +1 -1
  192. package/dist/migration/upgrade-to-angular-11.js +5 -3
  193. package/dist/migration/upgrade-to-angular-11.js.map +1 -1
  194. package/dist/migration/upgrade-to-angular-12.d.ts.map +1 -1
  195. package/dist/migration/upgrade-to-angular-12.js +1 -2
  196. package/dist/migration/upgrade-to-angular-12.js.map +1 -1
  197. package/dist/migration/upgrade-to-angular-13.d.ts.map +1 -1
  198. package/dist/migration/upgrade-to-angular-13.js +1 -2
  199. package/dist/migration/upgrade-to-angular-13.js.map +1 -1
  200. package/dist/migration/upgrade-to-angular-14.d.ts.map +1 -1
  201. package/dist/migration/upgrade-to-angular-14.js +8 -2
  202. package/dist/migration/upgrade-to-angular-14.js.map +1 -1
  203. package/dist/migration/upgrade-to-angular-15.d.ts.map +1 -1
  204. package/dist/migration/upgrade-to-angular-15.js +1 -2
  205. package/dist/migration/upgrade-to-angular-15.js.map +1 -1
  206. package/dist/migration/upgrade-to-angular-16.d.ts.map +1 -1
  207. package/dist/migration/upgrade-to-angular-16.js +4 -2
  208. package/dist/migration/upgrade-to-angular-16.js.map +1 -1
  209. package/dist/migration/upgrade-to-angular-17.d.ts.map +1 -1
  210. package/dist/migration/upgrade-to-angular-17.js +1 -2
  211. package/dist/migration/upgrade-to-angular-17.js.map +1 -1
  212. package/dist/migration/upgrade-to-angular-18.d.ts.map +1 -1
  213. package/dist/migration/upgrade-to-angular-18.js +1 -2
  214. package/dist/migration/upgrade-to-angular-18.js.map +1 -1
  215. package/dist/migration/upgrade-to-angular-19.d.ts.map +1 -1
  216. package/dist/migration/upgrade-to-angular-19.js +12 -4
  217. package/dist/migration/upgrade-to-angular-19.js.map +1 -1
  218. package/dist/migration/upgrade-to-angular-20.d.ts.map +1 -1
  219. package/dist/migration/upgrade-to-angular-20.js +12 -3
  220. package/dist/migration/upgrade-to-angular-20.js.map +1 -1
  221. package/dist/migration/upgrade-to-angular-21.d.ts.map +1 -1
  222. package/dist/migration/upgrade-to-angular-21.js +4 -2
  223. package/dist/migration/upgrade-to-angular-21.js.map +1 -1
  224. package/dist/migration/upgrade-to-angular-22.d.ts.map +1 -1
  225. package/dist/migration/upgrade-to-angular-22.js +1 -2
  226. package/dist/migration/upgrade-to-angular-22.js.map +1 -1
  227. package/dist/migration/upgrade-to-angular-8.d.ts.map +1 -1
  228. package/dist/migration/upgrade-to-angular-8.js +1 -3
  229. package/dist/migration/upgrade-to-angular-8.js.map +1 -1
  230. package/dist/migration/upgrade-to-angular-9.d.ts.map +1 -1
  231. package/dist/migration/upgrade-to-angular-9.js +1 -2
  232. package/dist/migration/upgrade-to-angular-9.js.map +1 -1
  233. package/package.json +6 -5
  234. package/src/index.ts +27 -0
  235. package/src/libraries/cdk/find-cdk-signature-changes.ts +1 -6
  236. package/src/libraries/cdk/migrate-cdk-sass-imports.ts +4 -7
  237. package/src/libraries/cdk/migrate-cdk-stepper.ts +2 -2
  238. package/src/libraries/cdk/migrate-deprecated-overlay-sass.ts +2 -4
  239. package/src/libraries/cdk/migrate-focus-trap-factory-create.ts +2 -1
  240. package/src/libraries/cdk/remove-cdk-super-arguments.ts +1 -2
  241. package/src/libraries/cdk/remove-portal-factory-resolver-arguments.ts +4 -6
  242. package/src/libraries/cdk/rename-portal-template-selectors.ts +3 -4
  243. package/src/libraries/cdk/upgrade-to-cdk.ts +7 -12
  244. package/src/libraries/components/lst.ts +17 -1
  245. package/src/libraries/components/style-sources.ts +20 -31
  246. package/src/libraries/components/stylesheets.ts +13 -10
  247. package/src/libraries/components/symbols.ts +12 -96
  248. package/src/libraries/components/template-elements.ts +5 -0
  249. package/src/libraries/components/templates.ts +32 -33
  250. package/src/libraries/material/add-system-variables-prefix.ts +27 -11
  251. package/src/libraries/material/add-theme-base-mixins.ts +7 -7
  252. package/src/libraries/material/find-chip-input-event-without-chip-input.ts +1 -2
  253. package/src/libraries/material/find-legacy-material-usage.ts +5 -11
  254. package/src/libraries/material/find-material-constructor-changes.ts +2 -3
  255. package/src/libraries/material/find-mdc-breaking-changes.ts +6 -17
  256. package/src/libraries/material/find-mixin-error-state-without-state-changes.ts +2 -2
  257. package/src/libraries/material/find-raw-palette-themes.ts +3 -5
  258. package/src/libraries/material/find-removed-material-classes.ts +6 -14
  259. package/src/libraries/material/find-removed-material-members.ts +2 -3
  260. package/src/libraries/material/find-slide-toggle-drag-options.ts +10 -13
  261. package/src/libraries/material/material-version.ts +37 -5
  262. package/src/libraries/material/migrate-legacy-material.ts +5 -11
  263. package/src/libraries/material/migrate-m2-theming-api.ts +3 -6
  264. package/src/libraries/material/migrate-mat-core-to-elevation-classes.ts +8 -5
  265. package/src/libraries/material/migrate-material-15-typography.ts +12 -20
  266. package/src/libraries/material/migrate-material-secondary-entry-points.ts +35 -3
  267. package/src/libraries/material/migrate-material-theming-api.ts +30 -22
  268. package/src/libraries/material/migrate-mdc-styles.ts +6 -13
  269. package/src/libraries/material/migrate-mdc-templates.ts +51 -28
  270. package/src/libraries/material/remove-mat-stepper-document-argument.ts +1 -2
  271. package/src/libraries/material/remove-update-active-link-argument.ts +1 -2
  272. package/src/libraries/material/rename-material-style-names.ts +79 -31
  273. package/src/libraries/material/rename-textarea-autosize-attributes.ts +24 -16
  274. package/src/libraries/material/upgrade-to-material.ts +19 -31
  275. package/src/migration/js-support.ts +2 -2
  276. package/src/migration/json-support.ts +50 -1
  277. package/src/migration/move-common-engine-to-ssr-node.ts +46 -0
  278. package/src/migration/remove-guard-and-resolve-interfaces.ts +89 -0
  279. package/src/migration/remove-show-circular-dependencies.ts +40 -0
  280. package/src/migration/rename-ssr-experimental-platform.ts +8 -49
  281. package/src/migration/replace-browser-target.ts +45 -0
  282. package/src/migration/replace-default-collection.ts +45 -0
  283. package/src/migration/replace-get-current-navigation.ts +50 -0
  284. package/src/migration/replace-initializer-providers.ts +153 -0
  285. package/src/migration/replace-preserve-query-params.ts +88 -0
  286. package/src/migration/replace-provide-server-routing.ts +79 -0
  287. package/src/migration/upgrade-angular-dependencies.ts +0 -6
  288. package/src/migration/upgrade-to-angular-10.ts +2 -3
  289. package/src/migration/upgrade-to-angular-11.ts +6 -4
  290. package/src/migration/upgrade-to-angular-12.ts +2 -3
  291. package/src/migration/upgrade-to-angular-13.ts +2 -3
  292. package/src/migration/upgrade-to-angular-14.ts +9 -3
  293. package/src/migration/upgrade-to-angular-15.ts +2 -3
  294. package/src/migration/upgrade-to-angular-16.ts +5 -3
  295. package/src/migration/upgrade-to-angular-17.ts +2 -3
  296. package/src/migration/upgrade-to-angular-18.ts +2 -3
  297. package/src/migration/upgrade-to-angular-19.ts +13 -5
  298. package/src/migration/upgrade-to-angular-20.ts +13 -4
  299. package/src/migration/upgrade-to-angular-21.ts +5 -3
  300. package/src/migration/upgrade-to-angular-22.ts +2 -3
  301. package/src/migration/upgrade-to-angular-8.ts +1 -3
  302. package/src/migration/upgrade-to-angular-9.ts +2 -3
@@ -4,12 +4,12 @@
4
4
  * Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
5
5
  */
6
6
 
7
- import {Cursor, ExecutionContext, Recipe, Tree, TreeVisitor} from "@openrewrite/rewrite";
7
+ import {ExecutionContext, Recipe, TreeVisitor} from "@openrewrite/rewrite";
8
8
  import {PlainText, PlainTextVisitor} from "@openrewrite/rewrite/text";
9
9
  import {JavaScriptVisitor} from "@openrewrite/rewrite/javascript";
10
10
  import {isLiteral, J} from "@openrewrite/rewrite/java";
11
11
  import {create} from "mutative";
12
- import {propertyName} from "./lst";
12
+ import {inSequence, propertyName} from "./lst";
13
13
  import {escapeRegExp} from "./stylesheets";
14
14
 
15
15
  /** A directive selector or input that a major version renamed, as it appears in a template attribute. */
@@ -34,39 +34,38 @@ export abstract class RenameTemplateAttributes extends Recipe {
34
34
  protected readonly exportAs: TemplateExportAsRename[] = [];
35
35
 
36
36
  async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
37
- const migrate = (template: string) => renameTemplateAttributes(template, this.attributes, this.exportAs);
38
- const html = new class extends PlainTextVisitor<ExecutionContext> {
39
- override async visitText(text: PlainText, p: ExecutionContext): Promise<PlainText | undefined> {
40
- const t = await super.visitText(text, p) as PlainText;
41
- if (!t || !t.sourcePath.endsWith('.html')) return t;
42
- const updated = migrate(t.text);
43
- return updated === t.text ? t : {...t, text: updated, snippets: []};
44
- }
45
- }();
46
- const inline = new class extends JavaScriptVisitor<ExecutionContext> {
47
- protected async visitPropertyAssignment(property: any, p: ExecutionContext): Promise<J | undefined> {
48
- const prop = await super.visitPropertyAssignment(property, p) as any;
49
- if (propertyName(prop?.name?.element) !== 'template') return prop;
37
+ return templateAttributesEditor(this.attributes, this.exportAs);
38
+ }
39
+ }
50
40
 
51
- const initializer = prop.initializer;
52
- if (!initializer || !isLiteral(initializer) || typeof initializer.value !== 'string') return prop;
53
- const valueSource = migrate(initializer.valueSource ?? '');
54
- if (valueSource === initializer.valueSource) return prop;
41
+ export function templateAttributesEditor(attributes: TemplateAttributeRename[],
42
+ exportAs: TemplateExportAsRename[] = []): TreeVisitor<any, ExecutionContext> {
43
+ const migrate = (template: string) => renameTemplateAttributes(template, attributes, exportAs);
44
+ const html = new class extends PlainTextVisitor<ExecutionContext> {
45
+ override async visitText(text: PlainText, p: ExecutionContext): Promise<PlainText | undefined> {
46
+ const t = await super.visitText(text, p) as PlainText;
47
+ if (!t || !t.sourcePath.endsWith('.html')) return t;
48
+ const updated = migrate(t.text);
49
+ return updated === t.text ? t : {...t, text: updated, snippets: []};
50
+ }
51
+ }();
52
+ const inline = new class extends JavaScriptVisitor<ExecutionContext> {
53
+ protected async visitPropertyAssignment(property: any, p: ExecutionContext): Promise<J | undefined> {
54
+ const prop = await super.visitPropertyAssignment(property, p) as any;
55
+ if (propertyName(prop?.name?.element) !== 'template') return prop;
55
56
 
56
- return create(prop, (draft: any) => {
57
- draft.initializer.valueSource = valueSource;
58
- draft.initializer.value = migrate(initializer.value as string);
59
- });
60
- }
61
- }();
62
- // Each visitor returns a source file it does not accept unchanged.
63
- return new class extends TreeVisitor<any, ExecutionContext> {
64
- async visit<R extends Tree>(tree: Tree, p: ExecutionContext, parent?: Cursor): Promise<R | undefined> {
65
- const visited = await html.visit<Tree>(tree, p, parent);
66
- return visited && await inline.visit(visited, p, parent) as R | undefined;
67
- }
68
- }();
69
- }
57
+ const initializer = prop.initializer;
58
+ if (!initializer || !isLiteral(initializer) || typeof initializer.value !== 'string') return prop;
59
+ const valueSource = migrate(initializer.valueSource ?? '');
60
+ if (valueSource === initializer.valueSource) return prop;
61
+
62
+ return create(prop, (draft: any) => {
63
+ draft.initializer.valueSource = valueSource;
64
+ draft.initializer.value = migrate(initializer.value as string);
65
+ });
66
+ }
67
+ }();
68
+ return inSequence(html, inline);
70
69
  }
71
70
 
72
71
  /** Renames attributes inside opening tags and `exportAs` values of reference variables. */
@@ -4,21 +4,25 @@
4
4
  * Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
5
5
  */
6
6
 
7
- import {StylesheetRecipe, withoutComments} from "../components/stylesheets";
7
+ import {ExecutionContext, TreeVisitor} from "@openrewrite/rewrite";
8
+ import {stylesheetEditor, withoutComments} from "../components/stylesheets";
9
+ import {MaterialVersionRecipe} from "./material-version";
8
10
 
9
11
  const KEY = 'use-system-variables';
10
12
 
11
13
  const PREFIX_KEY = 'system-variables-prefix';
12
14
 
13
- export class AddSystemVariablesPrefix extends StylesheetRecipe {
15
+ export class AddSystemVariablesPrefix extends MaterialVersionRecipe {
14
16
  readonly name = "org.openrewrite.angular.material.AddSystemVariablesPrefix";
15
17
  readonly displayName = "Add an explicit `system-variables-prefix` to themes that use system variables";
16
18
  readonly description = "Material 19 changed the default prefix of the CSS variables that themes with " +
17
19
  "`use-system-variables: true` emit. Adds `system-variables-prefix: sys` to those theme maps so the variables " +
18
20
  "keep their names. This is the system variable prefix migration of the `@angular/material` 19 `ng update`.";
19
21
 
20
- protected acceptsPath(sourcePath: string): boolean {
21
- return sourcePath.endsWith('.scss');
22
+ protected readonly version = 19;
23
+
24
+ protected async editorBeforeVersion(): Promise<TreeVisitor<any, ExecutionContext>> {
25
+ return stylesheetEditor(content => this.migrate(content), sourcePath => sourcePath.endsWith('.scss'));
22
26
  }
23
27
 
24
28
  protected migrate(content: string): string {
@@ -37,9 +41,8 @@ function addPrefix(content: string): string {
37
41
  index = content.indexOf(KEY, index + KEY.length);
38
42
  continue;
39
43
  }
40
- const value = content.slice(colon + 1, valueEnd + 1).trim();
41
- if (value.startsWith('true') && !hasPrefix(content, index)) {
42
- insertions.push({at: insertIndex(content, valueEnd), text: `${value.endsWith(',') ? '' : ','}\n ${PREFIX_KEY}: sys,`});
44
+ if (content.slice(colon + 1, valueEnd).trim() === 'true' && !hasPrefix(content, index)) {
45
+ insertions.push(prefixAfterValue(content, index, valueEnd));
43
46
  }
44
47
  index = content.indexOf(KEY, valueEnd);
45
48
  }
@@ -55,11 +58,24 @@ function endOfValue(content: string, from: number): number {
55
58
  return -1;
56
59
  }
57
60
 
58
- function insertIndex(content: string, valueEnd: number): number {
59
- for (let i = valueEnd; i < content.length; i++) {
60
- if (content[i] === '\n' || content[i] === ')') return i;
61
+ /** The prefix entry to insert after the value of the key, on a line of its own when the map spans lines. */
62
+ function prefixAfterValue(content: string, keyIndex: number, valueEnd: number): {at: number, text: string} {
63
+ const entry = `${PREFIX_KEY}: sys`;
64
+ const lineStart = content.lastIndexOf('\n', keyIndex) + 1;
65
+ const indent = content.slice(lineStart, keyIndex);
66
+ const multiline = /^\s*$/.test(indent);
67
+ const newline = content[valueEnd - 1] === '\r' ? '\r\n' : '\n';
68
+ if (content[valueEnd] === ',') {
69
+ const restOfLine = content.slice(valueEnd + 1).match(/^[ \t]*\r?(?:\n|$)/);
70
+ return restOfLine && multiline ?
71
+ {at: valueEnd + 1, text: `${newline}${indent}${entry},`} :
72
+ {at: valueEnd + 1, text: ` ${entry},`};
73
+ }
74
+ if (content[valueEnd] === '\n') {
75
+ const at = newline === '\r\n' ? valueEnd - 1 : valueEnd;
76
+ return {at, text: `,${newline}${indent}${entry}`};
61
77
  }
62
- return valueEnd;
78
+ return {at: valueEnd, text: `, ${entry}`};
63
79
  }
64
80
 
65
81
  /** Whether the map that enables system variables already sets their prefix. */
@@ -10,6 +10,7 @@ import {escapeRegExp, includePattern, maskComments, withoutComments, withSemicol
10
10
  import {beforeMaterialVersion, materialMajorScanner, materialNamespaces} from "./material-version";
11
11
  import {withMdcMixins} from "./migrate-legacy-material";
12
12
  import {hasSearchResult} from "../components/lst";
13
+ import {migrateThemingApi} from "./migrate-material-theming-api";
13
14
 
14
15
  /** The comment that the `@angular/material` 17 `ng update` puts above the base mixins it adds. */
15
16
  const PREAMBLE = `
@@ -62,12 +63,9 @@ export class AddThemeBaseMixins extends ScanningRecipe<Accumulator> {
62
63
  readonly name = "org.openrewrite.angular.material.AddThemeBaseMixins";
63
64
  readonly displayName = "Add the theme base mixins of Angular Material 17";
64
65
  readonly description = "Material 17 moved the base styles of each component out of its color, typography and " +
65
- "density mixins into a separate `base` mixin, which only the full `theme` mixin includes. When the stylesheets " +
66
- "of a project include such partial mixins, such as `mat.button-color`, but neither the matching `theme` nor " +
67
- "`base` mixin, adds the missing `base` mixins after `@include mat.core()`, or after the declaration of the theme " +
68
- "when every partial mixin uses the same theme variable. A stylesheet that includes `mat.core()` without such a " +
69
- "theme in scope is marked instead of getting `base` mixins without a theme, which would not compile. This is the " +
70
- "theme base migration of the `@angular/material` 17 `ng update`, applied to projects that are not on Material 17 yet.";
66
+ "density mixins into a `base` mixin. Where a project includes such a partial mixin, such as " +
67
+ "`mat.button-color`, without the full `theme` mixin, adds the missing `base` mixins after `mat.core()`, or " +
68
+ "marks `mat.core()` when no theme is in scope.";
71
69
 
72
70
  initialValue(_ctx: ExecutionContext): Accumulator {
73
71
  return {majors: new Map(), found: new Set(), missing: new Set(), themes: new Set()};
@@ -78,7 +76,9 @@ export class AddThemeBaseMixins extends ScanningRecipe<Accumulator> {
78
76
  const stylesheets = new class extends PlainTextVisitor<ExecutionContext> {
79
77
  override async visitText(text: PlainText, p: ExecutionContext): Promise<PlainText | undefined> {
80
78
  if (!text.sourcePath.endsWith('.scss')) return text;
81
- const content = withMdcMixins(maskComments(text.text));
79
+ // A project on Material 11 or older reaches 17 in one run, so its themes still `@import` the theming API.
80
+ // Without the declared names, a project's own mixin named like a legacy one can add a base mixin it doesn't need.
81
+ const content = withMdcMixins(migrateThemingApi(maskComments(text.text), new Set()));
82
82
  for (const ns of materialNamespaces(content)) {
83
83
  for (const set of MIXIN_SETS) {
84
84
  if (includes(content, ns, set.theme).length > 0 || includes(content, ns, set.base).length > 0) {
@@ -8,7 +8,6 @@ import {ExecutionContext, foundSearchResult, Recipe, TreeVisitor} from "@openrew
8
8
  import {JavaScriptVisitor, JS} from "@openrewrite/rewrite/javascript";
9
9
  import {isIdentifier, J} from "@openrewrite/rewrite/java";
10
10
  import {importedNames} from "../components/symbols";
11
- import {hasSearchResult} from "../components/lst";
12
11
 
13
12
  export class FindChipInputEventWithoutChipInput extends Recipe {
14
13
  readonly name = "org.openrewrite.angular.material.FindChipInputEventWithoutChipInput";
@@ -27,7 +26,7 @@ export class FindChipInputEventWithoutChipInput extends Recipe {
27
26
 
28
27
  protected async visitNewClass(newClass: J.NewClass, p: ExecutionContext): Promise<J | undefined> {
29
28
  const n = await super.visitNewClass(newClass, p) as J.NewClass;
30
- if (n.class || !n.body || hasSearchResult(n, "`MatChipInputEvent.chipInput` is required")) return n;
29
+ if (n.class || !n.body) return n;
31
30
  const declared = this.declaredType();
32
31
  if (!declared || !isIdentifier(declared) || !this.chipInputEvent.has(declared.simpleName)) return n;
33
32
  const keys = n.body.statements.map(s => s.element);
@@ -4,14 +4,14 @@
4
4
  * Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
5
5
  */
6
6
 
7
- import {Cursor, ExecutionContext, foundSearchResult, Recipe, Tree, TreeVisitor} from "@openrewrite/rewrite";
7
+ import {ExecutionContext, foundSearchResult, Recipe, TreeVisitor} from "@openrewrite/rewrite";
8
8
  import {PlainText, PlainTextVisitor} from "@openrewrite/rewrite/text";
9
9
  import {JavaScriptVisitor, JS} from "@openrewrite/rewrite/javascript";
10
10
  import {J} from "@openrewrite/rewrite/java";
11
11
  import {maskComments} from "../components/stylesheets";
12
12
  import {importedName, moduleOf} from "../components/symbols";
13
13
  import {UNMAPPED_LEGACY_HINTS} from "./migrate-legacy-material";
14
- import {hasSearchResult} from "../components/lst";
14
+ import {hasSearchResult, inSequence} from "../components/lst";
15
15
 
16
16
  const LEGACY_SASS = /@include\s+[\w-]*\.?(all-legacy-component-[\w-]+|legacy-[\w-]+)|[\w-]+\.define-legacy-typography-config\(/;
17
17
 
@@ -41,7 +41,7 @@ export class FindLegacyMaterialUsage extends Recipe {
41
41
  const stylesheets = new class extends PlainTextVisitor<ExecutionContext> {
42
42
  override async visitText(text: PlainText, p: ExecutionContext): Promise<PlainText | undefined> {
43
43
  const t = await super.visitText(text, p) as PlainText;
44
- if (!t || !t.sourcePath.endsWith('.scss') || hasSearchResult(t, "The legacy component theme mixins were removed")) return t;
44
+ if (!t || !t.sourcePath.endsWith('.scss')) return t;
45
45
  if (!LEGACY_SASS.test(maskComments(t.text))) return t;
46
46
  return foundSearchResult(t, "The legacy component theme mixins were removed in @angular/material 17. " +
47
47
  "Include the theme mixins of the MDC-based components instead, such as `mat.button-theme`.");
@@ -58,16 +58,10 @@ export class FindLegacyMaterialUsage extends Recipe {
58
58
 
59
59
  protected async visitLiteral(literal: J.Literal, p: ExecutionContext): Promise<J | undefined> {
60
60
  const l = await super.visitLiteral(literal, p) as J.Literal;
61
- if (typeof l.value !== 'string' || !l.value.startsWith('@angular/material/legacy-') || hasSearchResult(l, REMOVED_ENTRY_POINT)) return l;
61
+ if (typeof l.value !== 'string' || !l.value.startsWith('@angular/material/legacy-')) return l;
62
62
  return foundSearchResult(l, removedEntryPoint(l.value));
63
63
  }
64
64
  }();
65
- // Each visitor returns a source file it does not accept unchanged.
66
- return new class extends TreeVisitor<any, ExecutionContext> {
67
- async visit<R extends Tree>(tree: Tree, p: ExecutionContext, parent?: Cursor): Promise<R | undefined> {
68
- const visited = await stylesheets.visit<Tree>(tree, p, parent);
69
- return visited && await imports.visit(visited, p, parent) as R | undefined;
70
- }
71
- }();
65
+ return inSequence(stylesheets, imports);
72
66
  }
73
67
  }
@@ -8,8 +8,7 @@ import {ExecutionContext, foundSearchResult, ScanningRecipe, TreeVisitor} from "
8
8
  import {JavaScriptVisitor, JS} from "@openrewrite/rewrite/javascript";
9
9
  import {isIdentifier, J} from "@openrewrite/rewrite/java";
10
10
  import {importedNames} from "../components/symbols";
11
- import {extendedClassName, hasSearchResult, isSuperCall} from "../components/lst";
12
- import {argumentCount} from "../cdk/find-cdk-signature-changes";
11
+ import {argumentCount, extendedClassName, isSuperCall} from "../components/lst";
13
12
  import {beforeMaterialVersion, MATERIAL, materialMajorScanner} from "./material-version";
14
13
 
15
14
  /** The number of arguments the constructor of an `@angular/material` class accepts as of a major version. */
@@ -67,7 +66,7 @@ export abstract class FindMaterialConstructorChanges extends ScanningRecipe<Map<
67
66
  function mark<T extends J>(call: T, args: J.Container<J>, changed: ChangedConstructor): T {
68
67
  const count = argumentCount(args);
69
68
  const spread = args.elements.some(a => a.element.kind === JS.Kind.Spread);
70
- if (spread || (count >= changed.min && count <= changed.max) || hasSearchResult(call, `changed in @angular/material ${version} and takes`)) return call;
69
+ if (spread || (count >= changed.min && count <= changed.max)) return call;
71
70
  const expected = changed.min === changed.max ? `${changed.min}` : `${changed.min} to ${changed.max}`;
72
71
  return foundSearchResult(call, `The constructor of \`${changed.name}\` changed in @angular/material ${version} ` +
73
72
  `and takes ${expected} arguments. Update the arguments to match it.`);
@@ -8,10 +8,10 @@ import {Cursor, ExecutionContext, foundSearchResult, ScanningRecipe, Tree, TreeV
8
8
  import {PlainText, PlainTextVisitor} from "@openrewrite/rewrite/text";
9
9
  import {JavaScriptVisitor, JS} from "@openrewrite/rewrite/javascript";
10
10
  import {isLiteral, J} from "@openrewrite/rewrite/java";
11
- import {hasSearchResult, propertyName} from "../components/lst";
11
+ import {hasSearchResult, inSequence, propertyName} from "../components/lst";
12
12
  import {FindRemovedSymbols, RemovedSymbol} from "../components/symbols";
13
13
  import {mapOpeningTags, withoutHtmlComments} from "../components/templates";
14
- import {attributeNamed, descendants, parseElements} from "../components/template-elements";
14
+ import {attributeNamed, descendants, literalValue, parseElements} from "../components/template-elements";
15
15
  import {FindRemovedMaterialMembers, RemovedMember} from "./find-removed-material-members";
16
16
  import {beforeMaterialVersion, MaterialProjects, materialProjectScanner} from "./material-version";
17
17
 
@@ -148,7 +148,7 @@ export function placeholderLabelFields(template: string): {explicit: boolean, im
148
148
  const inside = descendants(field);
149
149
  if (inside.some(e => e.name === 'mat-label') || !inside.some(e => attributeNamed(e, 'placeholder'))) continue;
150
150
  const appearance = attributeNamed(field, 'appearance');
151
- const value = appearance?.name.startsWith('[') ? appearance.value?.trim().match(/^'(\w+)'$/)?.[1] : appearance?.value?.trim();
151
+ const value = appearance && literalValue(appearance);
152
152
  if (!appearance) result.implicit = true;
153
153
  else if (value === 'legacy' || value === 'standard') result.explicit = true;
154
154
  }
@@ -166,13 +166,8 @@ interface MdcTemplateScan extends MaterialProjects {
166
166
  export class FindMdcTemplateChanges extends ScanningRecipe<MdcTemplateScan> {
167
167
  readonly name: string = "org.openrewrite.angular.material.FindMdcTemplateChanges";
168
168
  readonly displayName: string = "Find templates affected by the Angular Material 15 MDC components";
169
- readonly description: string = "Finds `.html` templates and inline `template` metadata of projects not on Material 15 yet that use component APIs the MDC-based " +
170
- "components of Angular Material 15 changed: `<mat-chip-list>` and chip selection, the old slider markup, the " +
171
- "`legacy` and `standard` form field appearances, `floatLabel=\"never\"`, `<mat-placeholder>`, `matLine`, " +
172
- "`matListIcon` and `matListAvatar` in lists, a `mat-tab-nav-bar` without `tabPanel`, and the " +
173
- "`mat-card-content` attribute, selection on chips in a `<mat-chip-grid>`, and form fields that relied on the " +
174
- "`legacy` appearance to show the placeholder as the label, unless `MAT_FORM_FIELD_DEFAULT_OPTIONS` sets another " +
175
- "default appearance.";
169
+ readonly description: string = "Finds templates that use component APIs the MDC-based components of Angular " +
170
+ "Material 15 changed, such as `<mat-chip-list>`, `matLine` in lists and `<mat-placeholder>`.";
176
171
 
177
172
  /** Whether the recipe applies to a source file, which by default means its project is not on Material 15 yet. */
178
173
  protected appliesTo(projects: MaterialProjects, sourcePath: string): boolean {
@@ -262,12 +257,6 @@ export class FindMdcTemplateChanges extends ScanningRecipe<MdcTemplateScan> {
262
257
  return findings.length === 0 ? prop : foundSearchResult(prop, message(findings));
263
258
  }
264
259
  }();
265
- // Each visitor returns a source file it does not accept unchanged.
266
- return new class extends TreeVisitor<any, ExecutionContext> {
267
- async visit<R extends Tree>(tree: Tree, p: ExecutionContext, parent?: Cursor): Promise<R | undefined> {
268
- const visited = await html.visit<Tree>(tree, p, parent);
269
- return visited && await inline.visit(visited, p, parent) as R | undefined;
270
- }
271
- }();
260
+ return inSequence(html, inline);
272
261
  }
273
262
  }
@@ -8,7 +8,7 @@ import {ExecutionContext, foundSearchResult, Recipe, TreeVisitor} from "@openrew
8
8
  import {JavaScriptVisitor, JS} from "@openrewrite/rewrite/javascript";
9
9
  import {isIdentifier, J} from "@openrewrite/rewrite/java";
10
10
  import {importedNames} from "../components/symbols";
11
- import {extendedClassName, hasSearchResult} from "../components/lst";
11
+ import {extendedClassName} from "../components/lst";
12
12
 
13
13
  export class FindMixinErrorStateWithoutStateChanges extends Recipe {
14
14
  readonly name = "org.openrewrite.angular.material.FindMixinErrorStateWithoutStateChanges";
@@ -47,7 +47,7 @@ export class FindMixinErrorStateWithoutStateChanges extends Recipe {
47
47
  protected async visitClassDeclaration(classDecl: J.ClassDeclaration, p: ExecutionContext): Promise<J | undefined> {
48
48
  const c = await super.visitClassDeclaration(classDecl, p) as J.ClassDeclaration;
49
49
  const extended = c.extends?.element;
50
- if (!extended || declaresStateChanges(c) || hasSearchResult(c, "`mixinErrorState` no longer declares `stateChanges`")) return c;
50
+ if (!extended || declaresStateChanges(c)) return c;
51
51
  const name = extendedClassName(c);
52
52
  const base = name !== undefined && this.mixins.has(name)
53
53
  ? this.mixins.get(name)
@@ -39,11 +39,9 @@ export function unwrappedPalettes(content: string, rawPalettes: Set<string>): st
39
39
  export class FindRawPaletteThemes extends ScanningRecipe<PaletteScan> {
40
40
  readonly name: string = "org.openrewrite.angular.material.FindRawPaletteThemes";
41
41
  readonly displayName: string = "Find themes built from palette maps without `define-palette`";
42
- readonly description: string = "Finds stylesheets whose `define-light-theme` or `define-dark-theme` takes a map of " +
43
- "palette hues, such as `primary: $orange-palette`, rather than the result of `define-palette`, in projects that " +
44
- "are not on Material 15 yet. The legacy components accepted such a map, while the MDC-based components of " +
45
- "Angular Material 15 read hues that only `define-palette` adds, such as `default`, and fail the build with " +
46
- "`$color: null is not a color`.";
42
+ readonly description: string = "Finds themes built from a map of palette hues, such as `primary: " +
43
+ "$orange-palette`, instead of `define-palette`. The MDC-based components of Angular Material 15 read hues " +
44
+ "that only `define-palette` adds, and fail the build with `$color: null is not a color`.";
47
45
 
48
46
  /** Whether the recipe applies to a source file, which by default means its project is not on Material 15 yet. */
49
47
  protected appliesTo(projects: MaterialProjects, sourcePath: string): boolean {
@@ -4,7 +4,7 @@
4
4
  * Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
5
5
  */
6
6
 
7
- import {Cursor, ExecutionContext, foundSearchResult, ScanningRecipe, Tree, TreeVisitor} from "@openrewrite/rewrite";
7
+ import {ExecutionContext, foundSearchResult, ScanningRecipe, TreeVisitor} from "@openrewrite/rewrite";
8
8
  import {PlainText, PlainTextVisitor} from "@openrewrite/rewrite/text";
9
9
  import {JavaScriptVisitor, JS} from "@openrewrite/rewrite/javascript";
10
10
  import {J} from "@openrewrite/rewrite/java";
@@ -12,7 +12,7 @@ import {isStylesheet, maskComments} from "../components/stylesheets";
12
12
  import {beforeMaterialVersion, MaterialProjects, materialProjects, materialProjectScanner} from "./material-version";
13
13
  import {withoutHtmlComments} from "../components/templates";
14
14
  import {REMOVED_CLASSES, RENAMED_TYPOGRAPHY_CLASSES} from "./material-15-classes";
15
- import {hasSearchResult} from "../components/lst";
15
+ import {hasSearchResult, inSequence} from "../components/lst";
16
16
 
17
17
  /** The removed or renamed Material classes that a stylesheet selects, such as `.mat-form-field-wrapper`. */
18
18
  function selectedClasses(content: string): string[] {
@@ -72,11 +72,9 @@ function describe(classes: string[], elements: string[]): string {
72
72
  export class FindRemovedMaterialClasses extends ScanningRecipe<MaterialProjects> {
73
73
  readonly name: string = "org.openrewrite.angular.material.FindRemovedMaterialClasses";
74
74
  readonly displayName: string = "Find styles targeting classes removed by the MDC components";
75
- readonly description: string = "Finds stylesheets, templates and TypeScript strings that select or apply classes of the " +
76
- "pre-MDC components, such as `.mat-form-field-wrapper` or `.mat-card`, which the MDC-based components of " +
77
- "Angular Material 15 no longer apply, and the typography classes Material 15 renamed, such as `mat-title`, in " +
78
- "projects that are not on Material 15 yet, along with selectors of the elements Material 15 no longer " +
79
- "renders, such as `mat-chip-list`. The marker names the replacement where there is one.";
75
+ readonly description: string = "Finds styles, templates and strings that select or apply classes the MDC-based " +
76
+ "components of Angular Material 15 no longer apply, such as `.mat-form-field-wrapper`, or elements they no " +
77
+ "longer render, such as `mat-chip-list`. The marker names the replacement where there is one.";
80
78
 
81
79
  /** Whether the recipe applies to a source file, which by default means its project is not on Material 15 yet. */
82
80
  protected appliesTo(projects: MaterialProjects, sourcePath: string): boolean {
@@ -116,12 +114,6 @@ export class FindRemovedMaterialClasses extends ScanningRecipe<MaterialProjects>
116
114
  return classes.length === 0 && elements.length === 0 ? l : foundSearchResult(l, describe(classes, elements));
117
115
  }
118
116
  }();
119
- // Each visitor returns a source file it does not accept unchanged.
120
- return new class extends TreeVisitor<any, ExecutionContext> {
121
- async visit<R extends Tree>(tree: Tree, p: ExecutionContext, parent?: Cursor): Promise<R | undefined> {
122
- const visited = await files.visit<Tree>(tree, p, parent);
123
- return visited && await literals.visit(visited, p, parent) as R | undefined;
124
- }
125
- }();
117
+ return inSequence(files, literals);
126
118
  }
127
119
  }
@@ -9,7 +9,6 @@ import {JavaScriptVisitor, JS} from "@openrewrite/rewrite/javascript";
9
9
  import {J} from "@openrewrite/rewrite/java";
10
10
  import {accessesMaterialClass, isMaterialClass} from "./rename-material-members";
11
11
  import {beforeMaterialVersion, MaterialProjects, materialProjects, materialProjectScanner} from "./material-version";
12
- import {hasSearchResult} from "../components/lst";
13
12
 
14
13
  /** A method or property of `@angular/material` classes that a major version removed or changed without a drop-in replacement. */
15
14
  export interface RemovedMember {
@@ -53,14 +52,14 @@ export abstract class FindRemovedMaterialMembers extends ScanningRecipe<Material
53
52
  protected async visitMethodInvocation(method: J.MethodInvocation, p: ExecutionContext): Promise<J | undefined> {
54
53
  const m = await super.visitMethodInvocation(method, p) as J.MethodInvocation;
55
54
  const member = removed(m.methodType?.declaringType, m.name.simpleName);
56
- return member && !hasSearchResult(m, member.message) ? foundSearchResult(m, member.message) : m;
55
+ return member ? foundSearchResult(m, member.message) : m;
57
56
  }
58
57
 
59
58
  protected async visitFieldAccess(fieldAccess: J.FieldAccess, p: ExecutionContext): Promise<J | undefined> {
60
59
  const f = await super.visitFieldAccess(fieldAccess, p) as J.FieldAccess;
61
60
  const name = f.name.element.simpleName;
62
61
  const member = members.find(m => m.name === name && m.classNames.some(c => accessesMaterialClass(f, c)));
63
- return member && !hasSearchResult(f, member.message) ? foundSearchResult(f, member.message) : f;
62
+ return member ? foundSearchResult(f, member.message) : f;
64
63
  }
65
64
  }();
66
65
  }
@@ -4,12 +4,13 @@
4
4
  * Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
5
5
  */
6
6
 
7
- import {Cursor, ExecutionContext, foundSearchResult, Recipe, Tree, TreeVisitor} from "@openrewrite/rewrite";
7
+ import {ExecutionContext, foundSearchResult, TreeVisitor} from "@openrewrite/rewrite";
8
8
  import {PlainText, PlainTextVisitor} from "@openrewrite/rewrite/text";
9
9
  import {JavaScriptVisitor, JS} from "@openrewrite/rewrite/javascript";
10
10
  import {isIdentifier, isLiteral, J} from "@openrewrite/rewrite/java";
11
11
  import {moduleOf} from "../components/symbols";
12
- import {hasSearchResult} from "../components/lst";
12
+ import {MaterialVersionRecipe} from "./material-version";
13
+ import {inSequence} from "../components/lst";
13
14
 
14
15
  const DRAG_CHANGE_BINDING = /\(dragChange\)\s*=/;
15
16
 
@@ -19,19 +20,21 @@ const OPTION_MESSAGE = "`disableDragValue` was removed from `MatSlideToggleDefau
19
20
  const BINDING_MESSAGE = "`MatSlideToggle.dragChange` was removed in @angular/material 10, since the thumb can no longer " +
20
21
  "be dragged. Bind to `(change)` instead.";
21
22
 
22
- export class FindSlideToggleDragOptions extends Recipe {
23
+ export class FindSlideToggleDragOptions extends MaterialVersionRecipe {
23
24
  readonly name = "org.openrewrite.angular.material.FindSlideToggleDragOptions";
24
25
  readonly displayName = "Find slide toggle drag options and bindings";
25
26
  readonly description = "Finds `disableDragValue` in the slide toggle default options and `(dragChange)` bindings " +
26
27
  "in `.html` templates and inline `template` metadata, which Angular Material 10 removed together with dragging " +
27
28
  "the slide toggle thumb.";
28
29
 
29
- async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
30
+ protected readonly version = 10;
31
+
32
+ protected async editorBeforeVersion(): Promise<TreeVisitor<any, ExecutionContext>> {
30
33
  const html = new class extends PlainTextVisitor<ExecutionContext> {
31
34
  override async visitText(text: PlainText, p: ExecutionContext): Promise<PlainText | undefined> {
32
35
  const t = await super.visitText(text, p) as PlainText;
33
36
  if (!t || !t.sourcePath.endsWith('.html') || !DRAG_CHANGE_BINDING.test(t.text)) return t;
34
- return hasSearchResult(t, BINDING_MESSAGE) ? t : foundSearchResult(t, BINDING_MESSAGE);
37
+ return foundSearchResult(t, BINDING_MESSAGE);
35
38
  }
36
39
  }();
37
40
  const typescript = new class extends JavaScriptVisitor<ExecutionContext> {
@@ -46,7 +49,7 @@ export class FindSlideToggleDragOptions extends Recipe {
46
49
  protected async visitPropertyAssignment(property: JS.PropertyAssignment, p: ExecutionContext): Promise<J | undefined> {
47
50
  const prop = await super.visitPropertyAssignment(property, p) as JS.PropertyAssignment;
48
51
  const name = prop.name.element;
49
- if (!isIdentifier(name) || hasSearchResult(prop, OPTION_MESSAGE) || hasSearchResult(prop, BINDING_MESSAGE)) return prop;
52
+ if (!isIdentifier(name)) return prop;
50
53
  if (name.simpleName === 'disableDragValue' && this.importsSlideToggle) {
51
54
  return foundSearchResult(prop, OPTION_MESSAGE);
52
55
  }
@@ -58,12 +61,6 @@ export class FindSlideToggleDragOptions extends Recipe {
58
61
  return prop;
59
62
  }
60
63
  }();
61
- // Each visitor returns a source file it does not accept unchanged.
62
- return new class extends TreeVisitor<any, ExecutionContext> {
63
- async visit<R extends Tree>(tree: Tree, p: ExecutionContext, parent?: Cursor): Promise<R | undefined> {
64
- const visited = await html.visit<Tree>(tree, p, parent);
65
- return visited && await typescript.visit(visited, p, parent) as R | undefined;
66
- }
67
- }();
64
+ return inSequence(html, typescript);
68
65
  }
69
66
  }
@@ -4,7 +4,7 @@
4
4
  * Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
5
5
  */
6
6
 
7
- import {Cursor, ExecutionContext, Tree, TreeVisitor} from "@openrewrite/rewrite";
7
+ import {Cursor, ExecutionContext, isSourceFile, ScanningRecipe, Tree, TreeVisitor} from "@openrewrite/rewrite";
8
8
  import {findNodeResolutionResult, JavaScriptVisitor, JS, NodeResolutionResultQueries} from "@openrewrite/rewrite/javascript";
9
9
  import {J} from "@openrewrite/rewrite/java";
10
10
  import {PlainText, PlainTextVisitor} from "@openrewrite/rewrite/text";
@@ -63,16 +63,48 @@ export function materialMajorScanner(record: (directory: string, major: number)
63
63
  }();
64
64
  }
65
65
 
66
- /** Whether a source file belongs to a project that is not on the given `@angular/material` major or later yet. */
66
+ /**
67
+ * Whether a source file belongs to a project that declares an `@angular/material` major before the given one. A project
68
+ * that declares none, or a version without a number such as `catalog:`, may already be on it.
69
+ */
67
70
  export function beforeMaterialVersion(majors: Map<string, number>, sourcePath: string, version: number): boolean {
68
71
  const major = majorFor(majors, sourcePath);
69
- return major === undefined || major < version;
72
+ return major !== undefined && major < version;
73
+ }
74
+
75
+ /** A recipe that edits only the files of projects that declare an `@angular/material` major before {@link version}. */
76
+ export abstract class MaterialVersionRecipe extends ScanningRecipe<Map<string, number>> {
77
+ /** The first `@angular/material` major that the recipe no longer applies to. */
78
+ protected abstract readonly version: number;
79
+
80
+ protected abstract editorBeforeVersion(): Promise<TreeVisitor<any, ExecutionContext>>;
81
+
82
+ initialValue(_ctx: ExecutionContext): Map<string, number> {
83
+ return new Map();
84
+ }
85
+
86
+ async scanner(majors: Map<string, number>): Promise<TreeVisitor<any, ExecutionContext>> {
87
+ return materialMajorScanner((directory, major) => majors.set(directory, major));
88
+ }
89
+
90
+ async editorWithData(majors: Map<string, number>): Promise<TreeVisitor<any, ExecutionContext>> {
91
+ const editor = await this.editorBeforeVersion();
92
+ const version = this.version;
93
+ return new class extends TreeVisitor<any, ExecutionContext> {
94
+ async visit<R extends Tree>(tree: Tree, p: ExecutionContext, parent?: Cursor): Promise<R | undefined> {
95
+ return isSourceFile(tree) && beforeMaterialVersion(majors, tree.sourcePath, version) ?
96
+ editor.visit<R>(tree, p, parent) : tree as R;
97
+ }
98
+ }();
99
+ }
70
100
  }
71
101
 
72
102
  /** The `@angular/material` majors of a repository and the source files that still use the `legacy-*` components. */
73
103
  export interface MaterialProjects {
74
104
  majors: Map<string, number>;
75
105
  legacyPaths: Set<string>;
106
+ /** The projects of `legacyPaths`, derived on first use, once the scan has found every `package.json`. */
107
+ legacyProjects?: Set<string>;
76
108
  }
77
109
 
78
110
  export function materialProjects(): MaterialProjects {
@@ -137,6 +169,6 @@ function projectOf(majors: Map<string, number>, sourcePath: string): string {
137
169
 
138
170
  /** Whether a source file belongs to a project that still uses the `legacy-*` components of Material 15 and 16. */
139
171
  export function usesLegacyComponents(projects: MaterialProjects, sourcePath: string): boolean {
140
- const project = projectOf(projects.majors, sourcePath);
141
- return [...projects.legacyPaths].some(path => projectOf(projects.majors, path) === project);
172
+ projects.legacyProjects ??= new Set([...projects.legacyPaths].map(path => projectOf(projects.majors, path)));
173
+ return projects.legacyProjects.has(projectOf(projects.majors, sourcePath));
142
174
  }
@@ -42,12 +42,9 @@ function mdcModule(legacyModule: string): string {
42
42
  export class MigrateLegacyMaterialImports extends Recipe {
43
43
  readonly name = "org.openrewrite.angular.material.MigrateLegacyMaterialImports";
44
44
  readonly displayName = "Move legacy Angular Material imports to the MDC components";
45
- readonly description = "Material 17 removed the `@angular/material/legacy-*` entry points that the Material 15 " +
46
- "`ng update` moved imports to. Moves each imported symbol to the MDC-based entry point, such as " +
47
- "`MatLegacyButtonModule` from `@angular/material/legacy-button` to `MatButtonModule` from " +
48
- "`@angular/material/button`, and renames its uses, as the `mdc-migration` schematic of Material 15 does. " +
49
- "Symbols that the MDC-based entry points do not export, such as `MatLegacyChipList`, stay for " +
50
- "`FindLegacyMaterialUsage` to mark.";
45
+ readonly description = "Material 17 removed the `@angular/material/legacy-*` entry points. Moves each imported " +
46
+ "symbol to the MDC-based entry point, such as `MatLegacyButtonModule` from `@angular/material/legacy-button` " +
47
+ "to `MatButtonModule` from `@angular/material/button`.";
51
48
 
52
49
  async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
53
50
  return new class extends JavaScriptVisitor<ExecutionContext> {
@@ -147,11 +144,8 @@ export class MigrateLegacyMaterialTemplates extends MigrateMdcTemplates {
147
144
  export class MigrateLegacyMaterialStyles extends MigrateMdcStyles {
148
145
  readonly name = "org.openrewrite.angular.material.MigrateLegacyMaterialStyles";
149
146
  readonly displayName = "Move legacy Angular Material styles to the MDC components";
150
- readonly description = "Rewrites stylesheets and inline `styles` " + LEGACY_GATE + ", as the `mdc-migration` " +
151
- "schematic does: replaces the `legacy-*` mixins with the MDC-based ones, such as `mat.legacy-button-theme` " +
152
- "with `mat.button-theme`, `mat.fab-theme` and `mat.icon-button-theme`, and `mat.legacy-core` with `mat.core`, " +
153
- "moves `mat.define-legacy-typography-config` to `mat.define-typography-config` with the levels of the 2018 type " +
154
- "scale, and renames the selectors of classes the MDC components renamed, such as `.mat-form-field` to " +
147
+ readonly description = "Moves stylesheets and inline `styles` to the MDC-based components " + LEGACY_GATE + ", such as " +
148
+ "`mat.legacy-button-theme` to `mat.button-theme` and `.mat-form-field` to " +
155
149
  "`.mat-mdc-form-field`.";
156
150
 
157
151
  protected appliesTo(projects: MaterialProjects, sourcePath: string): boolean {