@@ -22,6 +22,12 @@ interface DetectImportResult {
22
22
namespaces : string [ ] ;
23
23
}
24
24
25
+ /** Addition mixin and function names that can be updated when invoking migration directly. */
26
+ interface ExtraSymbols {
27
+ mixins ?: Record < string , string > ;
28
+ functions ?: Record < string , string > ;
29
+ }
30
+
25
31
/**
26
32
* Migrates the content of a file to the new theming API. Note that this migration is using plain
27
33
* string manipulation, rather than the AST from PostCSS and the schematics string manipulation
@@ -40,13 +46,15 @@ export function migrateFileContent(content: string,
40
46
oldMaterialPrefix : string ,
41
47
oldCdkPrefix : string ,
42
48
newMaterialImportPath : string ,
43
- newCdkImportPath : string ) : string {
49
+ newCdkImportPath : string ,
50
+ extraMaterialSymbols : ExtraSymbols = { } ) : string {
44
51
const materialResults = detectImports ( content , oldMaterialPrefix ) ;
45
52
const cdkResults = detectImports ( content , oldCdkPrefix ) ;
46
53
47
54
// Try to migrate the symbols even if there are no imports. This is used
48
55
// to cover the case where the Components symbols were used transitively.
49
- content = migrateMaterialSymbols ( content , newMaterialImportPath , materialResults ) ;
56
+ content = migrateMaterialSymbols (
57
+ content , newMaterialImportPath , materialResults , extraMaterialSymbols ) ;
50
58
content = migrateCdkSymbols ( content , newCdkImportPath , cdkResults ) ;
51
59
content = replaceRemovedVariables ( content , removedMaterialVariables ) ;
52
60
@@ -103,16 +111,19 @@ function detectImports(content: string, prefix: string): DetectImportResult {
103
111
104
112
/** Migrates the Material symbols in a file. */
105
113
function migrateMaterialSymbols ( content : string , importPath : string ,
106
- detectedImports : DetectImportResult ) : string {
114
+ detectedImports : DetectImportResult ,
115
+ extraMaterialSymbols : ExtraSymbols = { } ) : string {
107
116
const initialContent = content ;
108
117
const namespace = 'mat' ;
118
+ const mixinsToUpdate = { ...materialMixins , ...extraMaterialSymbols . mixins } ;
119
+ const functionsToUpdate = { ...materialFunctions , ...extraMaterialSymbols . functions } ;
109
120
110
121
// Migrate the mixins.
111
- content = renameSymbols ( content , materialMixins , detectedImports . namespaces , mixinKeyFormatter ,
122
+ content = renameSymbols ( content , mixinsToUpdate , detectedImports . namespaces , mixinKeyFormatter ,
112
123
getMixinValueFormatter ( namespace ) ) ;
113
124
114
125
// Migrate the functions.
115
- content = renameSymbols ( content , materialFunctions , detectedImports . namespaces ,
126
+ content = renameSymbols ( content , functionsToUpdate , detectedImports . namespaces ,
116
127
functionKeyFormatter , getFunctionValueFormatter ( namespace ) ) ;
117
128
118
129
// Migrate the variables.
0 commit comments