9
9
import * as ts from 'typescript' ;
10
10
import * as postcss from 'postcss' ;
11
11
import * as scss from 'postcss-scss' ;
12
-
13
12
import {
14
13
CUSTOM_TS_SYMBOL_RENAMINGS ,
15
14
MAT_IMPORT_CHANGES ,
16
15
MDC_IMPORT_CHANGES ,
17
16
COMPONENT_THEME_MIXINS ,
18
17
CUSTOM_SASS_MIXIN_RENAMINGS ,
18
+ CUSTOM_SASS_FUNCTION_RENAMINGS ,
19
19
} from './constants' ;
20
-
21
20
import { Migration , ResolvedResource , TargetVersion , WorkspacePath } from '@angular/cdk/schematics' ;
22
21
23
22
export class LegacyComponentsMigration extends Migration < null > {
@@ -34,6 +33,7 @@ export class LegacyComponentsMigration extends Migration<null> {
34
33
} ,
35
34
include : node => this . _handleAtInclude ( node , stylesheet . filePath , namespace ) ,
36
35
} ,
36
+ RootExit : root => this . _handleRootNode ( root , stylesheet . filePath , namespace ) ,
37
37
} ,
38
38
] ) ;
39
39
processor . process ( stylesheet . content , { syntax : scss } ) . sync ( ) ;
@@ -70,6 +70,28 @@ export class LegacyComponentsMigration extends Migration<null> {
70
70
}
71
71
}
72
72
73
+ /** Handles updating the root node. */
74
+ private _handleRootNode ( root : postcss . Root , file : any , namespace ?: string ) {
75
+ if ( ! namespace ) {
76
+ return ;
77
+ }
78
+ // @functions could be referenced anywhere, so we need to just walk everything from the root
79
+ // and replace all instances that are not in comments.
80
+ root . walk ( node => {
81
+ if ( node . source ?. start != null && node . type !== 'comment' ) {
82
+ const srcString = node . toString ( ) ;
83
+ for ( const old in CUSTOM_SASS_FUNCTION_RENAMINGS ) {
84
+ if ( srcString . includes ( `${ namespace } .${ old } ` ) ) {
85
+ this . _replaceAt ( file , node . source . start . offset , {
86
+ old : `${ namespace } .${ old } ` ,
87
+ new : `${ namespace } .${ CUSTOM_SASS_FUNCTION_RENAMINGS [ old ] } ` ,
88
+ } ) ;
89
+ }
90
+ }
91
+ }
92
+ } ) ;
93
+ }
94
+
73
95
/** Returns true if the given at-include rule is a use of a legacy component mixin. */
74
96
private _isLegacyMixin ( node : postcss . AtRule , namespace : string ) : boolean {
75
97
if ( ! node . params . startsWith ( `${ namespace } .` ) ) {
0 commit comments