diff --git a/src/material/schematics/ng-generate/mdc-migration/index.ts b/src/material/schematics/ng-generate/mdc-migration/index.ts index 80145ae74fd7..3651e0f9ce7a 100644 --- a/src/material/schematics/ng-generate/mdc-migration/index.ts +++ b/src/material/schematics/ng-generate/mdc-migration/index.ts @@ -62,9 +62,8 @@ export default function (options: Schema): Rule { console.log('Directory:', migrationDir); const migrators: StyleMigrator[] = []; - const components = [...componentsToMigrate]; for (let i = 0; i < MIGRATORS.length; i++) { - if (components.includes(MIGRATORS[i].component)) { + if (componentsToMigrate.has(MIGRATORS[i].component)) { migrators.push(MIGRATORS[i]); } } diff --git a/src/material/schematics/ng-generate/mdc-migration/rules/style-migrator.ts b/src/material/schematics/ng-generate/mdc-migration/rules/style-migrator.ts index 93ceb07f8e23..4f0fcb9090ab 100644 --- a/src/material/schematics/ng-generate/mdc-migration/rules/style-migrator.ts +++ b/src/material/schematics/ng-generate/mdc-migration/rules/style-migrator.ts @@ -12,6 +12,7 @@ import * as postcss from 'postcss'; export interface ClassNameChange { /** The legacy class name. */ old: string; + /** The new class name. */ new: string; } @@ -24,6 +25,8 @@ export interface MixinChange { /** The name(s) of the new scss mixin(s). */ new: string[]; } + +/** StyleMigrator implements the basic case for migrating old component styles to new ones. */ export abstract class StyleMigrator { /** The name of the component that this migration handles. */ abstract component: string; @@ -54,7 +57,11 @@ export abstract class StyleMigrator { replaceMixin(namespace: string, atRule: postcss.AtRule): void { const change = this.mixinChanges.find(c => { return atRule.params.includes(`${namespace}.${c.old}`); - })!; + }); + + if (!change) { + return; + } // Cloning & inserting the first node before changing the // indentation preserves the indentation of the first node (e.g. 3 newlines).