@@ -27,15 +27,15 @@ function addConfig (source) {
27
27
}
28
28
29
29
walk . simple ( ast , {
30
- FunctionExpression ( node : any ) {
30
+ FunctionExpression ( node : any ) {
31
31
if ( ! node . id || ! node . id . name ) return
32
32
check ( node . id . name )
33
33
} ,
34
- FunctionDeclaration ( node : any ) {
34
+ FunctionDeclaration ( node : any ) {
35
35
if ( ! node . id || ! node . id . name ) return
36
36
check ( node . id . name )
37
37
} ,
38
- CallExpression ( node : any ) {
38
+ CallExpression ( node : any ) {
39
39
const { callee } = node
40
40
if ( callee . type === 'Identifier' ) {
41
41
check ( callee . name )
@@ -46,12 +46,43 @@ function addConfig (source) {
46
46
check ( callee . property . value )
47
47
}
48
48
}
49
- node . arguments . forEach ( item => {
49
+ node . arguments . forEach ( ( item : any ) => {
50
50
if ( item . type === 'Literal' && item . value ) {
51
51
check ( item . value )
52
52
}
53
53
} )
54
- }
54
+ } ,
55
+ ClassDeclaration ( node : any ) {
56
+ // 类声明: class Foo {}
57
+ if ( node . id && node . id . name ) {
58
+ check ( node . id . name )
59
+ }
60
+ // 类体方法: class Foo { bar() {} }
61
+ node . body . body . forEach ( ( method : any ) => {
62
+ if ( method . type === 'MethodDefinition' ) {
63
+ if ( method . key . type === 'Identifier' ) {
64
+ check ( method . key . name )
65
+ } else if ( method . key . type === 'Literal' ) {
66
+ check ( method . key . value as string )
67
+ }
68
+ }
69
+ } )
70
+ } ,
71
+ ClassExpression ( node : any ) {
72
+ // 类表达式: const A = class B {}
73
+ if ( node . id && node . id . name ) {
74
+ check ( node . id . name )
75
+ }
76
+ node . body . body . forEach ( ( method : any ) => {
77
+ if ( method . type === 'MethodDefinition' ) {
78
+ if ( method . key . type === 'Identifier' ) {
79
+ check ( method . key . name )
80
+ } else if ( method . key . type === 'Literal' ) {
81
+ check ( method . key . value as string )
82
+ }
83
+ }
84
+ } )
85
+ } ,
55
86
} )
56
87
57
88
return additionConfig
0 commit comments