diff --git a/src/material/schematics/ng-update/migrations/theming-api-v12/migration.ts b/src/material/schematics/ng-update/migrations/theming-api-v12/migration.ts index a227fceffcb0..a168f93f920c 100644 --- a/src/material/schematics/ng-update/migrations/theming-api-v12/migration.ts +++ b/src/material/schematics/ng-update/migrations/theming-api-v12/migration.ts @@ -397,7 +397,7 @@ function replaceRemovedVariables(content: string, variables: Record { // 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'); + const regex = new RegExp(`\\$${escapeRegExp(variableName)}(?!\\s+:|[-_a-zA-Z0-9:])`, 'g'); content = content.replace(regex, variables[variableName]); }); diff --git a/src/material/schematics/ng-update/test-cases/v12/misc/theming-api-v12.spec.ts b/src/material/schematics/ng-update/test-cases/v12/misc/theming-api-v12.spec.ts index 547450404437..33bc8656bf5c 100644 --- a/src/material/schematics/ng-update/test-cases/v12/misc/theming-api-v12.spec.ts +++ b/src/material/schematics/ng-update/test-cases/v12/misc/theming-api-v12.spec.ts @@ -591,6 +591,17 @@ describe('v12 theming API migration', () => { ]); }); + it('should not replace removed variables whose name overlaps with other variables', async () => { + writeLines(THEME_PATH, [ + `@import '@angular/material/theming';`, + `$swift-ease-in-duration: 300ms !default`, + ]); + + await runMigration(); + + expect(splitFile(THEME_PATH)).toEqual([`$swift-ease-in-duration: 300ms !default`]); + }); + it('should not replace assignments to removed variables', async () => { writeLines(THEME_PATH, [ `@import '@angular/material/theming';`,