Skip to content

Commit 151be2d

Browse files
committed
fix(material/schematics): delete legacy mixin when migrating if new mixin is already present
1 parent 7ab41f6 commit 151be2d

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

integration/mdc-migration/golden/src/styles.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ $sample-project-theme: mat.define-light-theme((
4747
@include mat.progress-bar-theme($sample-project-theme);
4848
@include mat.progress-spinner-theme($sample-project-theme);
4949
@include mat.radio-theme($sample-project-theme);
50-
@include mat.legacy-select-theme($sample-project-theme);
5150
@include mat.slide-toggle-theme($sample-project-theme);
5251
@include mat.slider-theme($sample-project-theme);
5352
@include mat.snack-bar-theme($sample-project-theme);

src/material/schematics/ng-generate/mdc-migration/rules/components/multiple-components-styles.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,26 @@ describe('multiple component styles', () => {
6060
);
6161
});
6262

63+
it('should remove legacy mixin if all replacements are already accounted for', async () => {
64+
await runMigrationTest(
65+
['paginator', 'select'],
66+
`
67+
@use '@angular/material' as mat;
68+
$theme: ();
69+
@include mat.legacy-paginator-theme($theme);
70+
@include mat.legacy-select-theme($theme);
71+
`,
72+
`
73+
@use '@angular/material' as mat;
74+
$theme: ();
75+
@include mat.paginator-theme($theme);
76+
@include mat.icon-button-theme($theme);
77+
@include mat.form-field-theme($theme);
78+
@include mat.select-theme($theme);
79+
`,
80+
);
81+
});
82+
6383
it('should migrate all component mixins for a full migration', async () => {
6484
await runMigrationTest(
6585
['all'],

src/material/schematics/ng-generate/mdc-migration/rules/style-migrator.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export interface MixinChange {
2626
old: string;
2727

2828
/** The name(s) of the new scss mixin(s). */
29-
new: string[];
29+
new: string[] | null;
3030

3131
/** Optional check to see if new scss mixin(s) already exist in the styles */
3232
checkForDuplicates?: boolean;
@@ -75,7 +75,7 @@ export abstract class StyleMigrator {
7575
}
7676

7777
// Check if mixin replacements already exist in the stylesheet
78-
const replacements = [...change.new];
78+
const replacements = [...(change.new ?? [])];
7979
if (change.checkForDuplicates) {
8080
const mixinArgumentMatches = atRule.params?.match(MIXIN_ARGUMENTS_REGEX);
8181
atRule.root().walkAtRules(rule => {
@@ -94,12 +94,7 @@ export abstract class StyleMigrator {
9494
});
9595
}
9696

97-
// Don't do anything if all the new changes already exist in the stylesheet
98-
if (replacements.length < 1) {
99-
return null;
100-
}
101-
102-
return {old: change.old, new: replacements};
97+
return {old: change.old, new: replacements.length ? replacements : null};
10398
}
10499

105100
/**

src/material/schematics/ng-generate/mdc-migration/rules/theming-styles.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ export class ThemingStylesMigration extends Migration<ComponentMigrator[], Schem
6363
if (migrator) {
6464
const mixinChange = migrator.styles.getMixinChange(this.namespace, atRule);
6565
if (mixinChange) {
66-
replaceAtRuleWithMultiple(atRule, mixinChange.old, mixinChange.new);
66+
if (mixinChange.new) {
67+
replaceAtRuleWithMultiple(atRule, mixinChange.old, mixinChange.new);
68+
} else {
69+
atRule.remove();
70+
}
6771
}
6872
} else if (atRule.parent && this.isCrossCuttingMixin(atRule.params)) {
6973
if (this.isPartialMigration()) {

0 commit comments

Comments
 (0)