@@ -27,15 +27,15 @@ function addConfig (source) {
2727 }
2828
2929 walk . simple ( ast , {
30- FunctionExpression ( node : any ) {
30+ FunctionExpression ( node : any ) {
3131 if ( ! node . id || ! node . id . name ) return
3232 check ( node . id . name )
3333 } ,
34- FunctionDeclaration ( node : any ) {
34+ FunctionDeclaration ( node : any ) {
3535 if ( ! node . id || ! node . id . name ) return
3636 check ( node . id . name )
3737 } ,
38- CallExpression ( node : any ) {
38+ CallExpression ( node : any ) {
3939 const { callee } = node
4040 if ( callee . type === 'Identifier' ) {
4141 check ( callee . name )
@@ -46,12 +46,43 @@ function addConfig (source) {
4646 check ( callee . property . value )
4747 }
4848 }
49- node . arguments . forEach ( item => {
49+ node . arguments . forEach ( ( item : any ) => {
5050 if ( item . type === 'Literal' && item . value ) {
5151 check ( item . value )
5252 }
5353 } )
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+ } ,
5586 } )
5687
5788 return additionConfig
0 commit comments