Skip to content

Commit 0f2ebe9

Browse files
committed
fix(material/schematics): ng-update typography-hierarchy
1 parent 2ea0c97 commit 0f2ebe9

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ export class LegacyComponentsMigration extends Migration<null> {
7474
const includeTypography = [atInclude, delim, mixinName, updatedFunctionsRest]
7575
.join('')
7676
.replace(`${namespace}.core`, `${namespace}.all-legacy-component-typographies`);
77+
// If there are no params, pass the default typography config.
78+
const hierarchyParams =
79+
updatedFunctionsRest.replace(/[()\s]/g, '') === ''
80+
? `(${namespace}.define-legacy-typography-config())`
81+
: updatedFunctionsRest;
82+
const includeHierarchy = [atInclude, delim, mixinName, hierarchyParams]
83+
.join('')
84+
.replace(`${namespace}.core`, `${namespace}.legacy-typography-hierarchy`);
7785
const indent = original.match(/^\s*/)?.[0] || '';
7886
// Replace the whole original with a comment, typography include, and legacy-core include.
7987
this._replaceAt(filePath, node.source.start.offset, {
@@ -83,6 +91,10 @@ export class LegacyComponentsMigration extends Migration<null> {
8391
`${indent}// Instead an explicit typography include has been automatically added here.`,
8492
`${indent}// If you add typography styles elsewhere, you may want to remove this.`,
8593
`${includeTypography};`,
94+
`${indent}// TODO(v15): If you want to keep just the typography hierarchy styles,`,
95+
`${indent}// but not the component default typography styles, delete the line above and keep the following.`,
96+
`${indent}// If you keep the above line or do not want the hierarchy styles, you can delete this line.`,
97+
`${includeHierarchy};`,
8698
`${indent}@include ${namespace}.legacy-core()`,
8799
].join('\n'),
88100
});

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ describe('v15 legacy components migration', () => {
285285
old: [
286286
`@use '@angular/material' as mat;`,
287287
`@include mat.core();`,
288-
`@include mat.core(mat.define-typography-config());`,
288+
`@include mat.core(mat.define-typography-config(()));`,
289289
`@include mat.core-theme(())`,
290290
],
291291
new: [
@@ -294,11 +294,19 @@ describe('v15 legacy components migration', () => {
294294
`// Instead an explicit typography include has been automatically added here.`,
295295
`// If you add typography styles elsewhere, you may want to remove this.`,
296296
`@include mat.all-legacy-component-typographies();`,
297+
`// TODO(v15): If you want to keep just the typography hierarchy styles,`,
298+
`// but not the component default typography styles, delete the line above and keep the following.`,
299+
`// If you keep the above line or do not want the hierarchy styles, you can delete this line.`,
300+
`@include mat.legacy-typography-hierarchy(mat.define-legacy-typography-config());`,
297301
`@include mat.legacy-core();`,
298302
`// TODO(v15): As of v15 mat.legacy-core no longer includes default typography styles.`,
299303
`// Instead an explicit typography include has been automatically added here.`,
300304
`// If you add typography styles elsewhere, you may want to remove this.`,
301-
`@include mat.all-legacy-component-typographies(mat.define-legacy-typography-config());`,
305+
`@include mat.all-legacy-component-typographies(mat.define-legacy-typography-config(()));`,
306+
`// TODO(v15): If you want to keep just the typography hierarchy styles,`,
307+
`// but not the component default typography styles, delete the line above and keep the following.`,
308+
`// If you keep the above line or do not want the hierarchy styles, you can delete this line.`,
309+
`@include mat.legacy-typography-hierarchy(mat.define-legacy-typography-config(()));`,
302310
`@include mat.legacy-core();`,
303311
`@include mat.legacy-core-theme(())`,
304312
],

0 commit comments

Comments
 (0)