Skip to content

Commit df50b07

Browse files
authored
fix(material/schematics): add explicit typography @include in v15 update (#25724)
1 parent b5f15f4 commit df50b07

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

src/material/schematics/ng-update/migrations/legacy-components-v15/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ export const CUSTOM_SASS_MIXIN_RENAMINGS: {[key: string]: string} = {
103103
'all-component-colors': 'all-legacy-component-colors',
104104
'all-component-typographies': 'all-legacy-component-typographies',
105105
'private-all-component-densities': 'private-all-legacy-component-densities',
106-
'core': 'legacy-core',
107106
};
108107

109108
export const CUSTOM_SASS_FUNCTION_RENAMINGS: {[key: string]: string} = {

src/material/schematics/ng-update/migrations/legacy-components-v15/index.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,31 @@ export class LegacyComponentsMigration extends Migration<null> {
5757
if (!namespace || !node.source?.start) {
5858
return;
5959
}
60-
const mixinName = node.params.split(/[.(;]/)[1];
61-
if (CUSTOM_SASS_MIXIN_RENAMINGS[mixinName]) {
60+
const original = node.toString();
61+
const [atInclude, delim, mixinName, ...rest] = original.split(/([.(;])/);
62+
if (mixinName === 'core') {
63+
// The parameters may include function calls that need to be renamed.
64+
const updatedFunctionsRest = Object.keys(CUSTOM_SASS_FUNCTION_RENAMINGS).reduce(
65+
(s, r) => s.replace(new RegExp(r, 'g'), CUSTOM_SASS_FUNCTION_RENAMINGS[r]),
66+
rest.join(''),
67+
);
68+
// The parameters are moved from the core include to the typography include.
69+
const includeTypography = [atInclude, delim, mixinName, updatedFunctionsRest]
70+
.join('')
71+
.replace(`${namespace}.core`, `${namespace}.all-legacy-component-typographies`);
72+
const indent = original.match(/^\s*/)?.[0] || '';
73+
// Replace the whole original with a comment, typography include, and legacy-core include.
74+
this._replaceAt(filePath, node.source.start.offset, {
75+
old: original,
76+
new: [
77+
`${indent}// TODO(v15): As of v15 ${namespace}.legacy-core no longer includes default typography styles.`,
78+
`${indent}// Instead an explicit typography include has been automatically added here.`,
79+
`${indent}// If you add typography styles elsewhere, you may want to remove this.`,
80+
`${includeTypography};`,
81+
`${indent}@include ${namespace}.legacy-core()`,
82+
].join('\n'),
83+
});
84+
} else if (CUSTOM_SASS_MIXIN_RENAMINGS[mixinName]) {
6285
this._replaceAt(filePath, node.source.start.offset, {
6386
old: `${namespace}.${mixinName}`,
6487
new: `${namespace}.${CUSTOM_SASS_MIXIN_RENAMINGS[mixinName]}`,

src/material/schematics/ng-update/test-cases/v15/legacy-components-v15.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,5 +279,28 @@ describe('v15 legacy components migration', () => {
279279
],
280280
});
281281
});
282+
283+
it('updates mat.core mixin', async () => {
284+
await runSassMigrationTest('mat.core mixin', {
285+
old: [
286+
`@use '@angular/material' as mat;`,
287+
`@include mat.core();`,
288+
`@include mat.core(mat.define-typography-config());`,
289+
],
290+
new: [
291+
`@use '@angular/material' as mat;`,
292+
`// TODO(v15): As of v15 mat.legacy-core no longer includes default typography styles.`,
293+
`// Instead an explicit typography include has been automatically added here.`,
294+
`// If you add typography styles elsewhere, you may want to remove this.`,
295+
`@include mat.all-legacy-component-typographies();`,
296+
`@include mat.legacy-core();`,
297+
`// TODO(v15): As of v15 mat.legacy-core no longer includes default typography styles.`,
298+
`// Instead an explicit typography include has been automatically added here.`,
299+
`// If you add typography styles elsewhere, you may want to remove this.`,
300+
`@include mat.all-legacy-component-typographies(mat.define-legacy-typography-config());`,
301+
`@include mat.legacy-core();`,
302+
],
303+
});
304+
});
282305
});
283306
});

0 commit comments

Comments
 (0)