From 226696d1d2d4812d483ab81287e4211123349478 Mon Sep 17 00:00:00 2001 From: Wagner Maciel Date: Thu, 25 Aug 2022 15:10:02 +0000 Subject: [PATCH] feat(material/schematics): add handling for all-component-themes (#25528) --- .../migrations/legacy-components-v15/index.ts | 10 +++++++++- .../test-cases/v15/legacy-components-v15.spec.ts | 16 ++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/material/schematics/ng-update/migrations/legacy-components-v15/index.ts b/src/material/schematics/ng-update/migrations/legacy-components-v15/index.ts index bf4e6ae40c55..63149dd0097e 100644 --- a/src/material/schematics/ng-update/migrations/legacy-components-v15/index.ts +++ b/src/material/schematics/ng-update/migrations/legacy-components-v15/index.ts @@ -55,7 +55,12 @@ export class LegacyComponentsMigration extends Migration { if (!namespace || !node.source?.start) { return; } - if (this._isLegacyMixin(node, namespace)) { + if (node.params.startsWith(`${namespace}.all-component-`)) { + this._replaceAt(filePath, node.source.start.offset, { + old: `${namespace}.all-`, + new: `${namespace}.all-legacy-`, + }); + } else if (this._isLegacyMixin(node, namespace)) { this._replaceAt(filePath, node.source.start.offset, { old: `${namespace}.`, new: `${namespace}.legacy-`, @@ -65,6 +70,9 @@ export class LegacyComponentsMigration extends Migration { /** Returns true if the given at-include rule is a use of a legacy component mixin. */ private _isLegacyMixin(node: postcss.AtRule, namespace: string): boolean { + if (!node.params.startsWith(`${namespace}.`)) { + return false; + } for (let i = 0; i < MIXINS.length; i++) { if (node.params.startsWith(`${namespace}.${MIXINS[i]}`)) { return true; diff --git a/src/material/schematics/ng-update/test-cases/v15/legacy-components-v15.spec.ts b/src/material/schematics/ng-update/test-cases/v15/legacy-components-v15.spec.ts index 848346718a7d..416315435918 100644 --- a/src/material/schematics/ng-update/test-cases/v15/legacy-components-v15.spec.ts +++ b/src/material/schematics/ng-update/test-cases/v15/legacy-components-v15.spec.ts @@ -170,8 +170,20 @@ describe('v15 legacy components migration', () => { } it('updates all mixins', async () => { - const oldFile: string[] = [`@use '@angular/material' as mat;`]; - const newFile: string[] = [`@use '@angular/material' as mat;`]; + const oldFile: string[] = [ + `@use '@angular/material' as mat;`, + `@include mat.all-component-themes($theme);`, + `@include mat.all-component-colors($theme);`, + `@include mat.all-component-densities($theme);`, + `@include mat.all-component-typographies($theme);`, + ]; + const newFile: string[] = [ + `@use '@angular/material' as mat;`, + `@include mat.all-legacy-component-themes($theme);`, + `@include mat.all-legacy-component-colors($theme);`, + `@include mat.all-legacy-component-densities($theme);`, + `@include mat.all-legacy-component-typographies($theme);`, + ]; for (let i = 0; i < COMPONENTS.length; i++) { oldFile.push( ...[