@@ -12,26 +12,43 @@ import * as ts from 'typescript';
12
12
import { isMaterialImportDeclaration } from '../material/typescript-specifiers' ;
13
13
14
14
/**
15
- * Rule that walks through every identifier that is part of Angular Material and replaces the
16
- * outdated name with the new one .
15
+ * Rule that detects import declarations that refer to outdated identifiers from Angular Material
16
+ * or the CDK which cannot be updated automatically .
17
17
*/
18
18
export class Rule extends Rules . TypedRule {
19
19
applyWithProgram ( sourceFile : ts . SourceFile , program : ts . Program ) : RuleFailure [ ] {
20
- return this . applyWithWalker ( new CheckImportMiscWalker ( sourceFile , this . getOptions ( ) , program ) ) ;
20
+ return this . applyWithWalker ( new Walker ( sourceFile , this . getOptions ( ) , program ) ) ;
21
21
}
22
22
}
23
23
24
- export class CheckImportMiscWalker extends ProgramAwareRuleWalker {
25
- visitImportDeclaration ( declaration : ts . ImportDeclaration ) {
26
- if ( isMaterialImportDeclaration ( declaration ) ) {
27
- declaration . importClause . namedBindings . forEachChild ( n => {
28
- let importName = n . getFirstToken ( ) && n . getFirstToken ( ) . getText ( ) ;
29
- if ( importName === 'SHOW_ANIMATION' || importName === 'HIDE_ANIMATION' ) {
30
- this . addFailureAtNode (
31
- n ,
32
- `Found deprecated symbol "${ red ( importName ) } " which has been removed` ) ;
33
- }
34
- } ) ;
24
+ export class Walker extends ProgramAwareRuleWalker {
25
+
26
+ visitImportDeclaration ( node : ts . ImportDeclaration ) {
27
+ if ( ! isMaterialImportDeclaration ( node ) ||
28
+ ! node . importClause ||
29
+ ! node . importClause . namedBindings ) {
30
+ return ;
31
+ }
32
+
33
+ const namedBindings = node . importClause . namedBindings ;
34
+
35
+ if ( ts . isNamedImports ( namedBindings ) ) {
36
+ this . _checkAnimationConstants ( namedBindings ) ;
35
37
}
36
38
}
39
+
40
+ /**
41
+ * Checks for named imports that refer to the deleted animation constants.
42
+ * https://github.com/angular/material2/commit/9f3bf274c4f15f0b0fbd8ab7dbf1a453076e66d9
43
+ */
44
+ private _checkAnimationConstants ( namedImports : ts . NamedImports ) {
45
+ namedImports . elements . filter ( element => ts . isIdentifier ( element . name ) ) . forEach ( element => {
46
+ const importName = element . name . text ;
47
+
48
+ if ( importName === 'SHOW_ANIMATION' || importName === 'HIDE_ANIMATION' ) {
49
+ this . addFailureAtNode ( element ,
50
+ `Found deprecated symbol "${ red ( importName ) } " which has been removed` ) ;
51
+ }
52
+ } ) ;
53
+ }
37
54
}
0 commit comments