Skip to content

Commit

Permalink
fixup! feat(material/schematics): set up a system for migrating scss …
Browse files Browse the repository at this point in the history
…* also implements the migrator for the button
  • Loading branch information
wagnermaciel committed Feb 2, 2022
1 parent 30cd65f commit 33596f4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/material/schematics/ng-generate/mdc-migration/index.ts
Expand Up @@ -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]);
}
}
Expand Down
Expand Up @@ -12,6 +12,7 @@ import * as postcss from 'postcss';
export interface ClassNameChange {
/** The legacy class name. */
old: string;

/** The new class name. */
new: string;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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).
Expand Down

0 comments on commit 33596f4

Please sign in to comment.