diff --git a/src/material/schematics/ng-update/migrations/mat-core-removal.ts b/src/material/schematics/ng-update/migrations/mat-core-removal.ts index dac48916476c..cf486a0a7430 100644 --- a/src/material/schematics/ng-update/migrations/mat-core-removal.ts +++ b/src/material/schematics/ng-update/migrations/mat-core-removal.ts @@ -25,16 +25,23 @@ export class MatCoreMigration extends Migration { } override visitStylesheet(stylesheet: ResolvedResource): void { - const processor = new postcss.Processor([ - { - postcssPlugin: 'mat-core-removal-v19-plugin', - AtRule: { - use: node => this._getNamespace(node), - include: node => this._handleAtInclude(node, stylesheet.filePath), + try { + const processor = new postcss.Processor([ + { + postcssPlugin: 'mat-core-removal-v19-plugin', + AtRule: { + use: node => this._getNamespace(node), + include: node => this._handleAtInclude(node, stylesheet.filePath), + }, }, - }, - ]); - processor.process(stylesheet.content, {syntax: scss}).sync(); + ]); + processor.process(stylesheet.content, {syntax: scss}).sync(); + } catch (e) { + this.logger.warn( + `Failed to migrate usages of mat.core in ${stylesheet.filePath} due to error:`, + ); + this.logger.warn(e + ''); + } } /** Handles updating the at-include rules of uses of the core mixin. */ diff --git a/src/material/schematics/ng-update/test-cases/v19-mat-core-removal.spec.ts b/src/material/schematics/ng-update/test-cases/v19-mat-core-removal.spec.ts index e249f8983b54..2a05fac5c73d 100644 --- a/src/material/schematics/ng-update/test-cases/v19-mat-core-removal.spec.ts +++ b/src/material/schematics/ng-update/test-cases/v19-mat-core-removal.spec.ts @@ -6,7 +6,7 @@ import {MIGRATION_PATH} from '../../paths'; const PROJECT_ROOT_DIR = '/projects/cdk-testing'; const THEME_FILE_PATH = join(PROJECT_ROOT_DIR, 'src/theme.scss'); -describe('v15 legacy components migration', () => { +describe('v19 mat.core migration', () => { let tree: UnitTestTree; /** Writes multiple lines to a file. */ @@ -73,5 +73,12 @@ describe('v15 legacy components migration', () => { ], }); }); + + it('should not break if there is an invalid syntax', async () => { + await runSassMigrationTest('', { + old: [`@use '@angular/material' as mat;`, `.foo { content: '; }`], + new: [`@use '@angular/material' as mat;`, `.foo { content: '; }`], + }); + }); }); });