Skip to content

Commit c9e1d4a

Browse files
authored
fix(material/schematics): theming API migration not working with CRLF line endings (#29171)
Fixes that the migration didn't account for CRLF line endings when figuring out the Sass namespace. Fixes #29147.
1 parent 7b48b54 commit c9e1d4a

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/material/schematics/ng-update/migrations/m2-theming-v18/migration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ function extractNamespaceFromUseStatement(fullImport: string): string {
271271
function getNamespaces(moduleName: string, content: string): string[] {
272272
const namespaces = new Set<string>();
273273
const escapedName = moduleName.replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
274-
const pattern = new RegExp(`@use +['"]${escapedName}['"].*;?\n`, 'g');
274+
const pattern = new RegExp(`@use +['"]${escapedName}['"].*;?\\r?\\n`, 'g');
275275
let match: RegExpExecArray | null = null;
276276

277277
while ((match = pattern.exec(content))) {

src/material/schematics/ng-update/test-cases/m2-theming.spec.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,4 +309,46 @@ describe('M2 theming migration', () => {
309309
`@include matx.something-not-theming-related();`,
310310
]);
311311
});
312+
313+
it('should migrate usages of the M2 theming APIs in a file with CRLF endings', async () => {
314+
const result = await setup(
315+
[
316+
`@use '@angular/material' as mat;`,
317+
318+
`$my-primary: mat.define-palette(mat.$indigo-palette, 500);`,
319+
`$my-accent: mat.define-palette(mat.$pink-palette, A200, A100, A400);`,
320+
`$my-warn: mat.define-palette(mat.$red-palette);`,
321+
322+
`$my-theme: mat.define-light-theme((`,
323+
` color: (`,
324+
` primary: $my-primary,`,
325+
` accent: $my-accent,`,
326+
` warn: $my-warn,`,
327+
` ),`,
328+
` typography: mat.define-typography-config(),`,
329+
` density: 0,`,
330+
`));`,
331+
`@include mat.all-component-themes($my-theme);`,
332+
].join('\r\n'),
333+
);
334+
335+
expect(result.split('\r\n')).toEqual([
336+
`@use '@angular/material' as mat;`,
337+
338+
`$my-primary: mat.m2-define-palette(mat.$m2-indigo-palette, 500);`,
339+
`$my-accent: mat.m2-define-palette(mat.$m2-pink-palette, A200, A100, A400);`,
340+
`$my-warn: mat.m2-define-palette(mat.$m2-red-palette);`,
341+
342+
`$my-theme: mat.m2-define-light-theme((`,
343+
` color: (`,
344+
` primary: $my-primary,`,
345+
` accent: $my-accent,`,
346+
` warn: $my-warn,`,
347+
` ),`,
348+
` typography: mat.m2-define-typography-config(),`,
349+
` density: 0,`,
350+
`));`,
351+
`@include mat.all-component-themes($my-theme);`,
352+
]);
353+
});
312354
});

0 commit comments

Comments
 (0)