Skip to content

Commit f231404

Browse files
amysortommalerba
authored andcommitted
fix(material/schematics): add support for replacing mixins that begin with all-legacy-component
1 parent 4a512cf commit f231404

File tree

3 files changed

+34
-20
lines changed

3 files changed

+34
-20
lines changed

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
@@ -125,5 +125,25 @@ describe('multiple component styles', () => {
125125
`,
126126
);
127127
});
128+
129+
it('should add migrate all component mixins', async () => {
130+
await runMigrationTest(
131+
['checkbox', 'radio'],
132+
`
133+
@use '@angular/material' as mat;
134+
$theme: ();
135+
@include mat.all-legacy-component-themes($sample-project-themes);
136+
@include mat.all-legacy-component-colors($sample-colors);
137+
@include mat.all-legacy-component-typographies($sample-typographies);
138+
`,
139+
`
140+
@use '@angular/material' as mat;
141+
$theme: ();
142+
@include mat.all-component-themes($sample-project-themes);
143+
@include mat.all-component-colors($sample-colors);
144+
@include mat.all-component-typographies($sample-typographies);
145+
`,
146+
);
147+
});
128148
});
129149
});

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -118,21 +118,6 @@ export abstract class StyleMigrator {
118118
atRule.remove();
119119
}
120120

121-
/**
122-
* Replaces the all-component-themes mixin with the MDC equivalent.
123-
*
124-
* @param allComponentThemesNode a all-components-theme mixin node
125-
*/
126-
replaceAllComponentThemeMixin(allComponentThemesNode: postcss.AtRule) {
127-
allComponentThemesNode.cloneBefore({
128-
params: allComponentThemesNode.params.replace(
129-
'all-legacy-component-themes',
130-
'all-component-themes',
131-
),
132-
});
133-
allComponentThemesNode.remove();
134-
}
135-
136121
/**
137122
* Returns whether the given postcss rule uses a legacy selector of this component.
138123
*

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,8 @@ export class ThemingStylesMigration extends Migration<ComponentMigrator[], Schem
5050
});
5151
if (migrator) {
5252
migrator.styles.replaceMixin(this.namespace, atRule);
53-
} else if (atRule.params.includes('all-legacy-component-themes') && atRule.parent) {
54-
// We use an arbitrary migrator because searching for the right one
55-
// doesn't matter since the all-component-theme mixin affects all
56-
// components and it only needs to be replaced once.
57-
this.upgradeData[0]?.styles.replaceAllComponentThemeMixin(atRule);
53+
} else if (atRule.params.includes('all-legacy-component-') && atRule.parent) {
54+
replaceAllComponentsMixin(atRule);
5855
}
5956
}
6057

@@ -97,3 +94,15 @@ function parseNamespace(atRule: postcss.AtRule): string {
9794
const params = postcss.list.space(atRule.params);
9895
return params[params.length - 1];
9996
}
97+
98+
/**
99+
* Replaces mixin prefixed with `all-legacy-component` to the MDC equivalent.
100+
*
101+
* @param allComponentThemesNode a all-components-theme mixin node
102+
*/
103+
function replaceAllComponentsMixin(allComponentNode: postcss.AtRule) {
104+
allComponentNode.cloneBefore({
105+
params: allComponentNode.params.replace('all-legacy-component', 'all-component'),
106+
});
107+
allComponentNode.remove();
108+
}

0 commit comments

Comments
 (0)