Skip to content

bug(material/schematics): v12 theming API migration should not rename variables appended with extra characters #24013

Closed
@Den-dp

Description

@Den-dp

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

after running ng update @angular/material I end up with invalid scss:

- $swift-ease-in-duration: 300ms !default;
- $swift-ease-in-timing-function: cubic-bezier(0.55, 0, 0.55, 0.2) !default;
+ all 300ms cubic-bezier(0.55, 0, 0.55, 0.2)-duration: 300ms !default;
+ all 300ms cubic-bezier(0.55, 0, 0.55, 0.2)-timing-function: cubic-bezier(0.55, 0, 0.55, 0.2) !default;

probably related to

'swift-ease-in': 'all 300ms cubic-bezier(0.55, 0, 0.55, 0.2)',

and
/**
* Replaces variables that have been removed with their values.
* @param content Content of the file to be migrated.
* @param variables Mapping between variable names and their values.
*/
function replaceRemovedVariables(content: string, variables: Record<string, string>): string {
Object.keys(variables).forEach(variableName => {
// Note that the pattern uses a negative lookahead to exclude
// variable assignments, because they can't be migrated.
const regex = new RegExp(`\\$${escapeRegExp(variableName)}(?!\\s+:|:)`, 'g');
content = content.replace(regex, variables[variableName]);
});
return content;
}

/** Escapes special regex characters in a string. */
function escapeRegExp(str: string): string {
return str.replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
}

Reproduction

I was able to reproduce it by running yarn test material/schematics in this repo since there is a test for it

it('should not rename variables appended with extra characters', async () => {
writeLines(THEME_PATH, [
`@import '@angular/material/theming';`,
`$mat-light-theme-background-override: 123;`,
`@include mat-core();`,
]);
await runMigration();
expect(splitFile(THEME_PATH)).toEqual([
`@use '@angular/material' as mat;`,
`$mat-light-theme-background-override: 123;`,
`@include mat.core();`,
]);
});

Expected Behavior

should not rename variables appended with extra characters

Actual Behavior

it renames it in an incorrect way

Environment

  • CDK/Material: 13 and I think 12

Metadata

Metadata

Assignees

Labels

P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: material/core

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions