@@ -10,7 +10,7 @@ import * as ts from 'typescript';
10
10
import * as postcss from 'postcss' ;
11
11
import * as scss from 'postcss-scss' ;
12
12
13
- import { MAT_IMPORT_CHANGE , MAT_MDC_IMPORT_CHANGE , MIXINS } from './constants' ;
13
+ import { MAT_IMPORT_CHANGES , MDC_IMPORT_CHANGES , MIXINS } from './constants' ;
14
14
15
15
import { Migration , ResolvedResource , TargetVersion , WorkspacePath } from '@angular/cdk/schematics' ;
16
16
@@ -109,16 +109,19 @@ export class LegacyComponentsMigration extends Migration<null> {
109
109
*/
110
110
private _handleImportDeclaration ( node : ts . ImportDeclaration ) : void {
111
111
const moduleSpecifier = node . moduleSpecifier as ts . StringLiteral ;
112
- if ( moduleSpecifier . text . startsWith ( MAT_IMPORT_CHANGE . old ) ) {
113
- this . _tsReplaceAt ( node , MAT_IMPORT_CHANGE ) ;
112
+
113
+ const matImportChange = this . _findMatImportChange ( moduleSpecifier ) ;
114
+ if ( matImportChange ) {
115
+ this . _tsReplaceAt ( node , matImportChange ) ;
114
116
115
117
if ( node . importClause ?. namedBindings && ts . isNamedImports ( node . importClause . namedBindings ) ) {
116
118
this . _handleNamedImportBindings ( node . importClause . namedBindings ) ;
117
119
}
118
120
}
119
121
120
- if ( moduleSpecifier . text . startsWith ( MAT_MDC_IMPORT_CHANGE . old ) ) {
121
- this . _tsReplaceAt ( node , MAT_MDC_IMPORT_CHANGE ) ;
122
+ const mdcImportChange = this . _findMdcImportChange ( moduleSpecifier ) ;
123
+ if ( mdcImportChange ) {
124
+ this . _tsReplaceAt ( node , mdcImportChange ) ;
122
125
}
123
126
}
124
127
@@ -128,12 +131,16 @@ export class LegacyComponentsMigration extends Migration<null> {
128
131
*/
129
132
private _handleImportExpression ( node : ts . CallExpression ) : void {
130
133
const moduleSpecifier = node . arguments [ 0 ] as ts . StringLiteral ;
131
- if ( moduleSpecifier . text . startsWith ( MAT_IMPORT_CHANGE . old ) ) {
132
- this . _tsReplaceAt ( node , MAT_IMPORT_CHANGE ) ;
134
+
135
+ const matImportChange = this . _findMatImportChange ( moduleSpecifier ) ;
136
+ if ( matImportChange ) {
137
+ this . _tsReplaceAt ( node , matImportChange ) ;
138
+ return ;
133
139
}
134
140
135
- if ( moduleSpecifier . text . startsWith ( MAT_MDC_IMPORT_CHANGE . old ) ) {
136
- this . _tsReplaceAt ( node , MAT_MDC_IMPORT_CHANGE ) ;
141
+ const mdcImportChange = this . _findMdcImportChange ( moduleSpecifier ) ;
142
+ if ( mdcImportChange ) {
143
+ this . _tsReplaceAt ( node , mdcImportChange ) ;
137
144
}
138
145
}
139
146
@@ -167,7 +174,8 @@ export class LegacyComponentsMigration extends Migration<null> {
167
174
! ! node . initializer &&
168
175
ts . isAwaitExpression ( node . initializer ) &&
169
176
this . _isImportCallExpression ( node . initializer . expression ) &&
170
- node . initializer . expression . arguments [ 0 ] . text . startsWith ( MAT_IMPORT_CHANGE . old ) &&
177
+ ts . isStringLiteral ( node . initializer . expression . arguments [ 0 ] ) &&
178
+ ! ! this . _findMatImportChange ( node . initializer . expression . arguments [ 0 ] ) &&
171
179
ts . isObjectBindingPattern ( node . name )
172
180
) ;
173
181
}
@@ -184,6 +192,18 @@ export class LegacyComponentsMigration extends Migration<null> {
184
192
) ;
185
193
}
186
194
195
+ private _findMatImportChange (
196
+ moduleSpecifier : ts . StringLiteral ,
197
+ ) : { old : string ; new : string } | undefined {
198
+ return MAT_IMPORT_CHANGES . find ( change => change . old === moduleSpecifier . text ) ;
199
+ }
200
+
201
+ private _findMdcImportChange (
202
+ moduleSpecifier : ts . StringLiteral ,
203
+ ) : { old : string ; new : string } | undefined {
204
+ return MDC_IMPORT_CHANGES . find ( change => change . old === moduleSpecifier . text ) ;
205
+ }
206
+
187
207
/** Updates the source file of the given ts node with the given replacements. */
188
208
private _tsReplaceAt ( node : ts . Node , str : { old : string ; new : string } ) : void {
189
209
const filePath = this . fileSystem . resolve ( node . getSourceFile ( ) . fileName ) ;
0 commit comments