@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
@@ -69,12 +69,9 @@ export function migrateM2ThemingApi(content: string): string {
69
69
  export class MigrateM2ThemingApi extends ScanningRecipe<Map<string, number>> {
70
70
  readonly name = "org.openrewrite.angular.material.MigrateM2ThemingApi";
71
71
  readonly displayName = "Rename the M2 theming API of Angular Material 18";
72
- readonly description = "Material 18 made Material 3 the default and renamed the Material 2 theming functions and " +
73
- "palettes with an `m2-` prefix, such as `mat.define-palette` to `mat.m2-define-palette` and `mat.$indigo-palette` " +
74
- "to `mat.$m2-indigo-palette`. Some old palette names, such as `mat.$red-palette`, are M3 palettes now, so this " +
75
- "only applies to projects that are not on Material 18 yet. Also moves the M3 APIs of " +
76
- "`@angular/material-experimental` to `@angular/material`. This is the M2 theming migration of the " +
77
- "`@angular/material` 18 `ng update`.";
72
+ readonly description = "Material 18 made Material 3 the default and gave the Material 2 theming functions and " +
73
+ "palettes an `m2-` prefix. Renames them, such as `mat.define-palette` to `mat.m2-define-palette`, and moves " +
74
+ "the M3 APIs of `@angular/material-experimental` to `@angular/material`.";
78
75
 
79
76
  initialValue(_ctx: ExecutionContext): Map<string, number> {
80
77
  return new Map();
@@ -4,18 +4,21 @@
4
4
  * Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
5
5
  */
6
6
 
7
- import {includePattern, StylesheetRecipe, withoutComments} from "../components/stylesheets";
8
- import {materialNamespaces} from "./material-version";
7
+ import {ExecutionContext, TreeVisitor} from "@openrewrite/rewrite";
8
+ import {includePattern, stylesheetEditor, withoutComments} from "../components/stylesheets";
9
+ import {MaterialVersionRecipe, materialNamespaces} from "./material-version";
9
10
 
10
- export class MigrateMatCoreToElevationClasses extends StylesheetRecipe {
11
+ export class MigrateMatCoreToElevationClasses extends MaterialVersionRecipe {
11
12
  readonly name = "org.openrewrite.angular.material.MigrateMatCoreToElevationClasses";
12
13
  readonly displayName = "Replace `mat.core()` with `mat.elevation-classes()` and `mat.app-background()`";
13
14
  readonly description = "Material 19 deprecated `mat.core()`. Replaces `@include mat.core()` with the two mixins " +
14
15
  "that it still emitted, `mat.elevation-classes()` and `mat.app-background()`. This is the `mat.core` migration " +
15
16
  "of the `@angular/material` 19 `ng update`.";
16
17
 
17
- protected acceptsPath(sourcePath: string): boolean {
18
- return sourcePath.endsWith('.scss');
18
+ protected readonly version = 19;
19
+
20
+ protected async editorBeforeVersion(): Promise<TreeVisitor<any, ExecutionContext>> {
21
+ return stylesheetEditor(content => this.migrate(content), sourcePath => sourcePath.endsWith('.scss'));
19
22
  }
20
23
 
21
24
  protected migrate(content: string): string {
@@ -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 {migrateInlineStyle} from "../components/style-sources";
12
12
  import {escapeRegExp, includePattern, maskComments, SASS_ARGUMENTS, withoutComments} from "../components/stylesheets";
13
13
  import {beforeMaterialVersion, materialMajorScanner, materialNamespaces} from "./material-version";
14
14
  import {RENAMED_TYPOGRAPHY_CLASSES} from "./material-15-classes";
15
- import {hasSearchResult} from "../components/lst";
15
+ import {hasSearchResult, inSequence} from "../components/lst";
16
16
 
17
17
  /**
18
18
  * Splits `mat.core($config)` into `mat.all-component-typographies($config)` and `mat.core()`, and adds the default
@@ -31,16 +31,15 @@ export function migrateCoreTypography(content: string): string {
31
31
  return migrated;
32
32
  }
33
33
 
34
+ const SETS_AMBIGUOUS_LEVELS = "This stylesheet sets `$body-1` or `$body-2` in a typography config";
35
+ const BUILDS_PRE_15_CONFIG = "This stylesheet builds a typography config with the levels of the pre-15 type scale";
36
+
34
37
  export class MigrateMaterial15Typography extends ScanningRecipe<Map<string, number>> {
35
38
  readonly name = "org.openrewrite.angular.material.MigrateMaterial15Typography";
36
39
  readonly displayName = "Migrate the typography of Angular Material 15";
37
- readonly description = "Material 15 removed the typography config parameter of `mat.core()`, stopped emitting " +
38
- "component typography from it, and moved typography configs to the 2018 Material Design type scale. Replaces " +
39
- "`@include mat.core($config)` with `@include mat.all-component-typographies($config)` followed by " +
40
- "`@include mat.core()`, adds `mat.all-component-typographies()` before a plain `mat.core()` unless the " +
41
- "stylesheet includes it already, and renames the levels of `mat.define-typography-config` and of the level " +
42
- "arguments of the typography functions, such as `title` to `headline-6`, with `input` merged into `body-1`, " +
43
- "in stylesheets and inline `styles` of projects that are not on Material 15 yet.";
40
+ readonly description = "Material 15 removed the typography config parameter of `mat.core()` and moved " +
41
+ "typography to the 2018 type scale. Includes `mat.all-component-typographies()` where `mat.core()` emitted " +
42
+ "the typography, and renames the type scale levels, such as `title` to `headline-6`.";
44
43
 
45
44
  initialValue(_ctx: ExecutionContext): Map<string, number> {
46
45
  return new Map();
@@ -58,16 +57,15 @@ export class MigrateMaterial15Typography extends ScanningRecipe<Map<string, numb
58
57
  if (!t || !t.sourcePath.endsWith('.scss') || !beforeMaterialVersion(majors, t.sourcePath, 15)) return t;
59
58
  const updated = migrate(t.text);
60
59
  const migrated = updated === t.text ? t : {...t, text: updated, snippets: []};
61
- if (hasSearchResult(migrated, "typography config")) return migrated;
60
+ if (hasSearchResult(migrated, SETS_AMBIGUOUS_LEVELS) || hasSearchResult(migrated, BUILDS_PRE_15_CONFIG)) return migrated;
62
61
  if (setsAmbiguousBodyLevels(maskComments(t.text))) {
63
- return foundSearchResult(migrated, "This stylesheet sets `$body-1` or `$body-2` in a typography config, which " +
62
+ return foundSearchResult(migrated, SETS_AMBIGUOUS_LEVELS + ", which " +
64
63
  "exist in both type scales with different meanings. If the config was written for the pre-15 type scale, " +
65
64
  "rename `body-2` to `subtitle-2` and then `body-1` to `body-2`.");
66
65
  }
67
66
  const oldLevels = customOldLevels(maskComments(updated));
68
67
  if (oldLevels.length < 2) return migrated;
69
- return foundSearchResult(migrated, `This stylesheet builds a typography config with the levels of the pre-15 ` +
70
- `type scale, such as ${oldLevels.slice(0, 3).map(l => `\`${l}\``).join(', ')}, which Material 15 ` +
68
+ return foundSearchResult(migrated, `${BUILDS_PRE_15_CONFIG}, such as ${oldLevels.slice(0, 3).map(l => `\`${l}\``).join(', ')}, which Material 15 ` +
71
69
  "typography no longer reads. Rename them to the 2018 levels, such as `display-4` to `headline-1`, " +
72
70
  "`title` to `headline-6`, `subheading-1` to `body-1` and `body-1` to `body-2`, with `input` merged into " +
73
71
  "`body-1`, or create the config with `mat.define-typography-config`.");
@@ -82,13 +80,7 @@ export class MigrateMaterial15Typography extends ScanningRecipe<Map<string, numb
82
80
  return migrateInlineStyle(await super.visitLiteral(literal, p) as J.Literal, this.cursor, migrate);
83
81
  }
84
82
  }();
85
- // Each visitor returns a source file it does not accept unchanged.
86
- return new class extends TreeVisitor<any, ExecutionContext> {
87
- async visit<R extends Tree>(tree: Tree, p: ExecutionContext, parent?: Cursor): Promise<R | undefined> {
88
- const visited = await files.visit<Tree>(tree, p, parent);
89
- return visited && await literals.visit(visited, p, parent) as R | undefined;
90
- }
91
- }();
83
+ return inSequence(files, literals);
92
84
  }
93
85
  }
94
86
 
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  import {ExecutionContext, foundSearchResult, randomId, Recipe, TreeVisitor} from "@openrewrite/rewrite";
8
- import {JavaScriptVisitor, JS} from "@openrewrite/rewrite/javascript";
8
+ import {JavaScriptVisitor, JS, maybeRebind} from "@openrewrite/rewrite/javascript";
9
9
  import {J} from "@openrewrite/rewrite/java";
10
10
  import {MATERIAL_ENTRY_POINTS} from "./material-entry-points";
11
11
  import {importedName, moduleOf} from "../components/symbols";
@@ -22,12 +22,16 @@ export class MigrateMaterialSecondaryEntryPoints extends Recipe {
22
22
  readonly name = "org.openrewrite.angular.material.MigrateMaterialSecondaryEntryPoints";
23
23
  readonly displayName = "Import Angular Material symbols from their entry points";
24
24
  readonly description = "Material 9 removed the `@angular/material` primary entry point. Splits each named import " +
25
- "from `@angular/material` into one import per secondary entry point, such as `@angular/material/button`, and " +
26
- "marks imports that it cannot split, such as namespace imports and symbols it does not know.";
25
+ "and re-export from `@angular/material` into one per secondary entry point, such as `@angular/material/button`, " +
26
+ "and marks those it cannot split, such as namespace imports, `export *` and symbols it does not know.";
27
27
 
28
28
  async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
29
29
  return new class extends JavaScriptVisitor<ExecutionContext> {
30
30
  protected async visitJsCompilationUnit(cu: JS.CompilationUnit, p: ExecutionContext): Promise<J | undefined> {
31
+ for (const name of reExportedNames(cu)) {
32
+ const entryPoint = ENTRY_POINT_OF.get(name);
33
+ if (entryPoint) maybeRebind(this, {from: {module: MATERIAL, member: name}, to: {module: `${MATERIAL}/${entryPoint}`, member: name}});
34
+ }
31
35
  const c = await super.visitJsCompilationUnit(cu, p) as JS.CompilationUnit;
32
36
  const spacing = braceSpacing(c);
33
37
  let changed = false;
@@ -60,10 +64,38 @@ export class MigrateMaterialSecondaryEntryPoints extends Recipe {
60
64
  });
61
65
  return changed ? withElements(imp, named, elements) : imp;
62
66
  }
67
+
68
+ protected async visitExportDeclaration(exportDeclaration: JS.ExportDeclaration, p: ExecutionContext): Promise<J | undefined> {
69
+ const e = await super.visitExportDeclaration(exportDeclaration, p) as JS.ExportDeclaration;
70
+ if (moduleOf(e) !== MATERIAL) return e;
71
+ if (e.exportClause?.kind !== JS.Kind.NamedExports) {
72
+ return foundSearchResult(e, ENTRY_POINT_REMOVED + " " +
73
+ "Re-export each symbol by name from its entry point, such as `@angular/material/button`.");
74
+ }
75
+ const named = e.exportClause as JS.NamedExports;
76
+ const elements = named.elements.elements.map(element => {
77
+ const name = element.element.kind === JS.Kind.ExportSpecifier ? importedName(element.element as JS.ExportSpecifier) : undefined;
78
+ if (!name || ENTRY_POINT_OF.has(name)) return element;
79
+ const marked = foundSearchResult(element.element, `\`${name}\` ${NOT_EXPORTED}. Re-export it from where it is declared now.`);
80
+ return marked === element.element ? element : {...element, element: marked};
81
+ });
82
+ return elements.some((element, i) => element !== named.elements.elements[i])
83
+ ? {...e, exportClause: {...named, elements: {...named.elements, elements}}} as JS.ExportDeclaration
84
+ : e;
85
+ }
63
86
  }();
64
87
  }
65
88
  }
66
89
 
90
+ /** The names a file re-exports by name from `@angular/material`. */
91
+ function reExportedNames(cu: JS.CompilationUnit): string[] {
92
+ return cu.statements.map(s => s.element)
93
+ .filter((s): s is JS.ExportDeclaration => s.kind === JS.Kind.ExportDeclaration && moduleOf(s as JS.ExportDeclaration) === MATERIAL)
94
+ .flatMap(e => e.exportClause?.kind === JS.Kind.NamedExports ? (e.exportClause as JS.NamedExports).elements.elements : [])
95
+ .flatMap(element => element.element.kind === JS.Kind.ExportSpecifier ? [importedName(element.element as JS.ExportSpecifier)] : [])
96
+ .filter((name): name is string => name !== undefined);
97
+ }
98
+
67
99
  /** The whitespace inside the braces of a single-line named import. */
68
100
  interface BraceSpacing {
69
101
  open: string;
@@ -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 {ExecutionContext, foundSearchResult, ScanningRecipe, TreeVisitor} from "@openrewrite/rewrite";
7
+ import {Cursor, ExecutionContext, foundSearchResult, ScanningRecipe, Tree, TreeVisitor} from "@openrewrite/rewrite";
8
8
  import {PlainText, PlainTextVisitor} from "@openrewrite/rewrite/text";
9
9
  import {escapeRegExp, maskComments, withoutComments} from "../components/stylesheets";
10
10
  import {hasSearchResult} from "../components/lst";
@@ -21,11 +21,13 @@ import {
21
21
  UNPREFIXED_MATERIAL_MIXINS,
22
22
  UNPREFIXED_REMOVED_VARIABLES
23
23
  } from "./material-theming-api";
24
+ import {beforeMaterialVersion, materialMajorScanner} from "./material-version";
24
25
 
25
- /** `@import` or `@use` of a file inside `@angular/material` or `@angular/cdk`, also through `node_modules`, other than a prebuilt theme. */
26
- function legacyImports(pkg: 'material' | 'cdk'): RegExp {
27
- return new RegExp(`^[ \\t]*@(import|use)\\s+(['"])(?:~|~?(?:\\.\\.?\\/)*node_modules\\/)?@angular\\/${pkg}\\/(?!prebuilt-themes|[\\w-]*-prebuilt)([^'"]*)\\2(?:\\s+as\\s+([\\w-]+))?\\s*;?[ \\t]*(?:\\r?\\n|$)`, 'gm');
28
- }
26
+ /**
27
+ * `@import` or `@use` of a file inside `@angular/material`, also through `node_modules`, other than a prebuilt theme.
28
+ * Imports of `@angular/cdk` entry points are left to `MigrateCdkSassImports`, which knows all the members they expose.
29
+ */
30
+ const LEGACY_IMPORT = /^[ \t]*@(import|use)\s+(['"])(?:~|~?(?:\.\.?\/)*node_modules\/)?@angular\/material\/(?!prebuilt-themes|[\w-]*-prebuilt)([^'"]*)\2(?:\s+as\s+([\w-]+))?\s*;?[ \t]*(?:\r?\n|$)/gm;
29
31
 
30
32
  const MATERIAL_USE = /@use\s+(['"])~?@angular\/material\1(?:\s+as\s+([\w-]+|\*))?/;
31
33
  const CDK_USE = /@use\s+(['"])~?@angular\/cdk\1(?:\s+as\s+([\w-]+|\*))?/;
@@ -33,26 +35,24 @@ const CDK_USE = /@use\s+(['"])~?@angular\/cdk\1(?:\s+as\s+([\w-]+|\*))?/;
33
35
  interface Accumulator {
34
36
  /** Mixins, functions and variables that stylesheets of the project declare themselves. */
35
37
  declared: Set<string>;
38
+ majors: Map<string, number>;
36
39
  }
37
40
 
38
41
  export class MigrateMaterialThemingApi extends ScanningRecipe<Accumulator> {
39
42
  readonly name = "org.openrewrite.angular.material.MigrateMaterialThemingApi";
40
43
  readonly displayName = "Migrate the Angular Material theming API to `@use`";
41
- readonly description = "Material 12 introduced the `@use '@angular/material'` Sass module and Material 17 deleted " +
42
- "the `@angular/material/theming` file that `@import` loaded. Replaces `@import` of `@angular/material/theming` " +
43
- "with `@use '@angular/material' as mat`, and renames the prefixed mixins, functions and variables it exposed, " +
44
- "such as `@include mat-core()` and `mat-palette(...)`, to the members of the `mat` module, and the CDK members " +
45
- "such as `cdk-overlay` to the `cdk` module. Variables the module dropped are replaced by their values. Names a " +
46
- "stylesheet of the project declares itself keep referring to that declaration, and stylesheets that override a " +
47
- "theming variable the Material styles read are marked. This is the theming API migration of the " +
48
- "`@angular/material` 12 `ng update`.";
44
+ readonly description = "Material 17 deleted the `@angular/material/theming` file. Replaces its `@import` with " +
45
+ "`@use '@angular/material' as mat` and renames the members it exposed, such as `mat-palette(...)` to " +
46
+ "`mat.define-palette(...)`. Stylesheets that override a theming variable the Material styles read are " +
47
+ "marked.";
49
48
 
50
49
  initialValue(_ctx: ExecutionContext): Accumulator {
51
- return {declared: new Set()};
50
+ return {declared: new Set(), majors: new Map()};
52
51
  }
53
52
 
54
53
  async scanner(acc: Accumulator): Promise<TreeVisitor<any, ExecutionContext>> {
55
- return new class extends PlainTextVisitor<ExecutionContext> {
54
+ const majors = materialMajorScanner((directory, major) => acc.majors.set(directory, major));
55
+ const declarations = new class extends PlainTextVisitor<ExecutionContext> {
56
56
  override async visitText(text: PlainText, p: ExecutionContext): Promise<PlainText | undefined> {
57
57
  if (text.sourcePath.endsWith('.scss')) {
58
58
  const masked = maskComments(text.text);
@@ -61,13 +61,22 @@ export class MigrateMaterialThemingApi extends ScanningRecipe<Accumulator> {
61
61
  return text;
62
62
  }
63
63
  }();
64
+ return new class extends TreeVisitor<any, ExecutionContext> {
65
+ async visit<R extends Tree>(tree: Tree, p: ExecutionContext, parent?: Cursor): Promise<R | undefined> {
66
+ await majors.visit(tree, p, parent);
67
+ await declarations.visit(tree, p, parent);
68
+ return tree as R;
69
+ }
70
+ }();
64
71
  }
65
72
 
66
73
  async editorWithData(acc: Accumulator): Promise<TreeVisitor<any, ExecutionContext>> {
67
74
  return new class extends PlainTextVisitor<ExecutionContext> {
68
75
  override async visitText(text: PlainText, p: ExecutionContext): Promise<PlainText | undefined> {
69
76
  const t = await super.visitText(text, p) as PlainText;
70
- if (!t || !t.sourcePath.endsWith('.scss') || hasSearchResult(t, "which the `@angular/material/theming` import let")) return t;
77
+ // Projects on Material 12 to 16 may still import `@angular/material/theming`, which 17 deleted.
78
+ if (!t || !t.sourcePath.endsWith('.scss') || !beforeMaterialVersion(acc.majors, t.sourcePath, 17) ||
79
+ hasSearchResult(t, "which the `@angular/material/theming` import let")) return t;
71
80
  const updated = withoutComments(t.text, content => migrateThemingApi(content, acc.declared));
72
81
  if (updated === t.text) return t;
73
82
  const masked = maskComments(t.text);
@@ -85,16 +94,15 @@ export class MigrateMaterialThemingApi extends ScanningRecipe<Accumulator> {
85
94
 
86
95
  /** Material theming variables that a stylesheet with the legacy theming import declares itself. */
87
96
  function overriddenMaterialVariables(content: string): string[] {
88
- if ((content.match(legacyImports('material')) ?? []).length === 0) return [];
97
+ if ((content.match(LEGACY_IMPORT) ?? []).length === 0) return [];
89
98
  const known = new Set([...Object.keys(MATERIAL_VARIABLES), ...Object.keys(REMOVED_MATERIAL_VARIABLES), ...Object.keys(UNPREFIXED_REMOVED_VARIABLES)]);
90
99
  return [...new Set([...content.matchAll(/^\s*\$([\w-]+)\s*:/gm)].map(m => m[1]))].filter(name => known.has(name));
91
100
  }
92
101
 
93
102
  /** Migrates the content of one stylesheet whose comments are masked. */
94
103
  export function migrateThemingApi(original: string, declared: Set<string>): string {
95
- const materialImports = original.match(legacyImports('material')) ?? [];
96
- const cdkImports = original.match(legacyImports('cdk')) ?? [];
97
- const content = withoutLegacyNamespaces(original, [...materialImports, ...cdkImports]);
104
+ const materialImports = original.match(LEGACY_IMPORT) ?? [];
105
+ const content = withoutLegacyNamespaces(original, materialImports);
98
106
  const materialUse = content.match(MATERIAL_USE);
99
107
  const cdkUse = content.match(CDK_USE);
100
108
  const mat = materialUse?.[2] ?? 'mat';
@@ -112,13 +120,13 @@ export function migrateThemingApi(original: string, declared: Set<string>): stri
112
120
  migrated = replaceVariables(migrated, REMOVED_MATERIAL_VARIABLES, declared);
113
121
  // A partial without the import that calls theming members reads its variables from the stylesheet importing it.
114
122
  if (imported || usesMaterial) migrated = replaceVariables(migrated, UNPREFIXED_REMOVED_VARIABLES, declared);
115
- if (migrated === original && materialImports.length + cdkImports.length === 0) return original;
123
+ if (migrated === original && materialImports.length === 0) return original;
116
124
 
117
125
  const uses = [
118
126
  ...(usesMaterial && !materialUse ? [`@use '@angular/material' as mat;`] : []),
119
127
  ...(usesCdk && !cdkUse ? [`@use '@angular/cdk' as cdk;`] : []),
120
128
  ];
121
- return replaceImports(migrated, [...materialImports, ...cdkImports], uses);
129
+ return replaceImports(migrated, materialImports, uses);
122
130
  }
123
131
 
124
132
  const HEADER = /^(?:\s*(?:__ngComment\d+__|@charset[^;]*;|@use[^;]*;))*\s*/;
@@ -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, ScanningRecipe, Tree, TreeVisitor} from "@openrewrite/rewrite";
7
+ import {ExecutionContext, 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,6 +12,7 @@ import {migrateInlineStyle} from "../components/style-sources";
12
12
  import {escapeRegExp, includedInBlock, includePattern, isStylesheet, withoutComments, withSemicolon} from "../components/stylesheets";
13
13
  import {beforeMaterialVersion, materialNamespaces, MaterialProjects, materialProjects, materialProjectScanner} from "./material-version";
14
14
  import {MDC_CLASS_RENAMES, RENAMED_TYPOGRAPHY_CLASSES} from "./material-15-classes";
15
+ import {inSequence} from "../components/lst";
15
16
 
16
17
  /** Mixins whose MDC components rely on the themes of other components, from the `mdc-migration` schematic. */
17
18
  export const COMPANION_MIXINS: Record<string, string[]> = {
@@ -63,11 +64,9 @@ export function migrateMdcStyles(content: string): string {
63
64
  export class MigrateMdcStyles extends ScanningRecipe<MaterialProjects> {
64
65
  readonly name: string = "org.openrewrite.angular.material.MigrateMdcStyles";
65
66
  readonly displayName: string = "Move styles to the Angular Material 15 MDC components";
66
- readonly description: string = "Rewrites stylesheets and inline `styles` metadata for the MDC-based components of " +
67
- "Angular Material 15, as the `mdc-migration` schematic does, in projects that are not on Material 15 yet: " +
68
- "renames selectors of classes the MDC components renamed, such as `.mat-form-field` to `.mat-mdc-form-field`, " +
69
- "renames the typography classes to the 2018 type scale, and includes the themes that the MDC components rely " +
70
- "on, such as `mat.fab-theme` and `mat.icon-button-theme` next to `mat.button-theme`.";
67
+ readonly description: string = "Moves stylesheets and inline `styles` to the MDC-based components of Angular " +
68
+ "Material 15, as the `mdc-migration` schematic does, such as renaming `.mat-form-field` to " +
69
+ "`.mat-mdc-form-field` and including `mat.fab-theme` next to `mat.button-theme`.";
71
70
 
72
71
  /** Whether the recipe applies to a source file, which by default means its project is not on Material 15 yet. */
73
72
  protected appliesTo(projects: MaterialProjects, sourcePath: string): boolean {
@@ -106,12 +105,6 @@ export class MigrateMdcStyles extends ScanningRecipe<MaterialProjects> {
106
105
  return migrateInlineStyle(await super.visitLiteral(literal, p) as J.Literal, this.cursor, migrate);
107
106
  }
108
107
  }();
109
- // Each visitor returns a source file it does not accept unchanged.
110
- return new class extends TreeVisitor<any, ExecutionContext> {
111
- async visit<R extends Tree>(tree: Tree, p: ExecutionContext, parent?: Cursor): Promise<R | undefined> {
112
- const visited = await files.visit<Tree>(tree, p, parent);
113
- return visited && await literals.visit(visited, p, parent) as R | undefined;
114
- }
115
- }();
108
+ return inSequence(files, literals);
116
109
  }
117
110
  }
@@ -4,24 +4,24 @@
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, ScanningRecipe, Tree, TreeVisitor} from "@openrewrite/rewrite";
7
+ import {Cursor, ExecutionContext, ScanningRecipe, TreeVisitor} from "@openrewrite/rewrite";
8
8
  import {PlainText, PlainTextVisitor} from "@openrewrite/rewrite/text";
9
- import {JavaScriptVisitor, JS} from "@openrewrite/rewrite/javascript";
10
- import {isLiteral, J} from "@openrewrite/rewrite/java";
9
+ import {capture, JavaScriptVisitor, JS, Pattern, pattern, raw, template} from "@openrewrite/rewrite/javascript";
10
+ import {isLiteral, isNewClass, J} from "@openrewrite/rewrite/java";
11
11
  import {create} from "mutative";
12
12
  import {
13
13
  applyEdits,
14
14
  attributeNamed,
15
15
  bareName,
16
16
  descendants,
17
+ literalValue,
17
18
  parseElements,
18
19
  removeAttribute,
19
20
  TemplateAttribute,
20
21
  TemplateEdit,
21
22
  TemplateElement
22
23
  } from "../components/template-elements";
23
- import {propertyName} from "../components/lst";
24
- import {moduleOf} from "../components/symbols";
24
+ import {inSequence, propertyName} from "../components/lst";
25
25
  import {requote} from "../components/templates";
26
26
  import {beforeMaterialVersion, MaterialProjects, materialProjects, materialProjectScanner} from "./material-version";
27
27
  import {RENAMED_TYPOGRAPHY_CLASSES} from "./material-15-classes";
@@ -62,7 +62,7 @@ export function migrateMdcTemplate(template: string, multiline = true): string {
62
62
  function migrateFormFields(template: string, elements: TemplateElement[]): TemplateEdit[] {
63
63
  return elements.filter(e => e.name === 'mat-form-field').flatMap(field => {
64
64
  const appearance = attributeNamed(field, 'appearance');
65
- const value = appearance?.name.startsWith('[') ? appearance.value?.trim().match(/^'(\w+)'$/)?.[1] : appearance?.value?.trim();
65
+ const value = appearance && literalValue(appearance);
66
66
  return appearance && (value === 'legacy' || value === 'standard') ? [removeAttribute(template, appearance)] : [];
67
67
  });
68
68
  }
@@ -195,16 +195,25 @@ function migrateTypographyClasses(template: string, elements: TemplateElement[])
195
195
  return edits;
196
196
  }
197
197
 
198
+ const FORM_FIELD_TYPES = {
199
+ context: ["import {MAT_FORM_FIELD_DEFAULT_OPTIONS, MatFormFieldDefaultOptions} from '@angular/material/form-field';"],
200
+ dependencies: {'@angular/material': '^14.0.0'},
201
+ };
202
+
203
+ const formFieldOptions = capture<J>('options');
204
+
205
+ /** The default options of the form field, in their provider or in a variable of their type. */
206
+ const FORM_FIELD_OPTIONS: Pattern[] = [
207
+ pattern`{provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, useValue: ${formFieldOptions}}`.configure(FORM_FIELD_TYPES),
208
+ pattern`const ${capture()}: MatFormFieldDefaultOptions = ${formFieldOptions}`.configure(FORM_FIELD_TYPES),
209
+ ];
210
+
198
211
  export class MigrateMdcTemplates extends ScanningRecipe<MaterialProjects> {
199
212
  readonly name: string = "org.openrewrite.angular.material.MigrateMdcTemplates";
200
213
  readonly displayName: string = "Move templates to the Angular Material 15 MDC components";
201
- readonly description: string = "Rewrites `.html` templates and inline `template` metadata for the MDC-based components " +
202
- "of Angular Material 15, as the `mdc-migration` schematic does, in projects that are not on Material 15 yet: " +
203
- "removes the `legacy` and `standard` form field appearances, which `MAT_FORM_FIELD_DEFAULT_OPTIONS` values set to `fill`, renames `<mat-chip-list>` to `<mat-chip-grid>` " +
204
- "with `<mat-chip-row>` when a `matChipInputFor` input refers to it and to `<mat-chip-listbox>` with " +
205
- "`<mat-chip-option>` otherwise, adds an `<input matSliderThumb>` to `<mat-slider>` and moves the value, its " +
206
- "events, form bindings and labels to it, renames `thumbLabel` to `discrete`, and renames the typography " +
207
- "classes to the 2018 type scale, such as `mat-title` to `mat-headline-6`.";
214
+ readonly description: string = "Moves templates to the MDC-based components of Angular Material 15, as the " +
215
+ "`mdc-migration` schematic does, such as `<mat-chip-list>` to `<mat-chip-grid>` or `<mat-chip-listbox>`. " +
216
+ "Also moves the default form field appearance in `MAT_FORM_FIELD_DEFAULT_OPTIONS` to `fill`.";
208
217
 
209
218
  /** Whether the recipe applies to a source file, which by default means its project is not on Material 15 yet. */
210
219
  protected appliesTo(projects: MaterialProjects, sourcePath: string): boolean {
@@ -230,24 +239,44 @@ export class MigrateMdcTemplates extends ScanningRecipe<MaterialProjects> {
230
239
  }
231
240
  }();
232
241
  const inline = new class extends JavaScriptVisitor<ExecutionContext> {
233
- private usesFormField = false;
242
+ /** The ids of the object literals that hold default options of the form field. */
243
+ private readonly formFieldOptions = new Set<string>();
234
244
 
235
245
  protected async visitJsCompilationUnit(cu: JS.CompilationUnit, p: ExecutionContext): Promise<J | undefined> {
236
- this.usesFormField = cu.statements.some(s => s.element.kind === JS.Kind.Import
237
- && /^@angular\/material\/(?:legacy-)?form-field$/.test(moduleOf(s.element as JS.Import) ?? ''));
238
246
  return applies(cu.sourcePath) ? super.visitJsCompilationUnit(cu, p) : cu;
239
247
  }
240
248
 
249
+ protected async visitNewClass(newClass: J.NewClass, p: ExecutionContext): Promise<J | undefined> {
250
+ await this.recordFormFieldOptions(newClass);
251
+ return super.visitNewClass(newClass, p);
252
+ }
253
+
254
+ protected async visitVariableDeclarations(declarations: J.VariableDeclarations, p: ExecutionContext): Promise<J | undefined> {
255
+ await this.recordFormFieldOptions(declarations);
256
+ return super.visitVariableDeclarations(declarations, p);
257
+ }
258
+
259
+ private async recordFormFieldOptions(tree: J): Promise<void> {
260
+ for (const options of FORM_FIELD_OPTIONS) {
261
+ const match = await options.match(tree, this.cursor);
262
+ const object = match?.get(formFieldOptions);
263
+ if (object) this.formFieldOptions.add(object.id);
264
+ }
265
+ }
266
+
241
267
  protected async visitPropertyAssignment(property: JS.PropertyAssignment, p: ExecutionContext): Promise<J | undefined> {
242
268
  const prop = await super.visitPropertyAssignment(property, p) as JS.PropertyAssignment;
243
269
  const name = propertyName(prop.name.element);
244
270
  const initializer = prop.initializer;
245
271
  if (!initializer || !isLiteral(initializer) || typeof initializer.value !== 'string' || !initializer.valueSource) return prop;
246
- if (name === 'appearance' && this.usesFormField && ['legacy', 'standard'].includes(initializer.value)) {
247
- return create(prop, (draft: any) => {
248
- draft.initializer.value = 'fill';
249
- draft.initializer.valueSource = requote(initializer.valueSource!, 'fill');
250
- });
272
+ const object: J.NewClass | undefined = this.cursor.firstEnclosing(isNewClass);
273
+ if (name === 'appearance' && ['legacy', 'standard'].includes(initializer.value) && object &&
274
+ this.formFieldOptions.has(object.id)) {
275
+ const fill = await template`${raw(requote(initializer.valueSource, 'fill'))}`
276
+ .apply(initializer, new Cursor(initializer, this.cursor));
277
+ if (!fill || !isLiteral(fill)) return prop;
278
+ const updated: JS.PropertyAssignment = {...prop, initializer: fill};
279
+ return updated;
251
280
  }
252
281
  if (name !== 'template') return prop;
253
282
  const value = migrateMdcTemplate(initializer.value, initializer.valueSource.startsWith('`'));
@@ -258,12 +287,6 @@ export class MigrateMdcTemplates extends ScanningRecipe<MaterialProjects> {
258
287
  });
259
288
  }
260
289
  }();
261
- // Each visitor returns a source file it does not accept unchanged.
262
- return new class extends TreeVisitor<any, ExecutionContext> {
263
- async visit<R extends Tree>(tree: Tree, p: ExecutionContext, parent?: Cursor): Promise<R | undefined> {
264
- const visited = await html.visit<Tree>(tree, p, parent);
265
- return visited && await inline.visit(visited, p, parent) as R | undefined;
266
- }
267
- }();
290
+ return inSequence(html, inline);
268
291
  }
269
292
  }
@@ -8,8 +8,7 @@ import {ExecutionContext, Recipe, TreeVisitor} from "@openrewrite/rewrite";
8
8
  import {JavaScriptVisitor, JS} from "@openrewrite/rewrite/javascript";
9
9
  import {J} from "@openrewrite/rewrite/java";
10
10
  import {importedNames} from "../components/symbols";
11
- import {extendedClassName, isSuperCall} from "../components/lst";
12
- import {argumentCount} from "../cdk/find-cdk-signature-changes";
11
+ import {argumentCount, extendedClassName, isSuperCall} from "../components/lst";
13
12
 
14
13
  /** The stepper classes whose constructor took a `_document` argument before Material 14. */
15
14
  const STEPPERS = ['MatStepper', 'MatVerticalStepper', 'MatHorizontalStepper'];
@@ -7,8 +7,7 @@
7
7
  import {ExecutionContext, Recipe, TreeVisitor} from "@openrewrite/rewrite";
8
8
  import {JavaScriptVisitor} from "@openrewrite/rewrite/javascript";
9
9
  import {J} from "@openrewrite/rewrite/java";
10
- import {emptyArguments} from "../components/lst";
11
- import {argumentCount} from "../cdk/find-cdk-signature-changes";
10
+ import {argumentCount, emptyArguments} from "../components/lst";
12
11
  import {isMaterialClass} from "./rename-material-members";
13
12
 
14
13
  /** `MatTabNav` and the base class that declares `updateActiveLink` as of Material 10. */