File tree Expand file tree Collapse file tree 2 files changed +15
-9
lines changed Expand file tree Collapse file tree 2 files changed +15
-9
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ import * as utils from '../../../tests/utils';
18
18
19
19
describe ( 'resolveToValue' , ( ) => {
20
20
function parse ( src ) {
21
- const root = utils . parse ( src ) ;
21
+ const root = utils . parse ( src . trim ( ) ) ;
22
22
return root . get ( 'body' , root . node . body . length - 1 , 'expression' ) ;
23
23
}
24
24
@@ -61,23 +61,27 @@ describe('resolveToValue', () => {
61
61
} ) ;
62
62
63
63
it ( 'resolves to class declarations' , ( ) => {
64
- const program = utils . parse ( `
64
+ const path = parse ( `
65
65
class Foo {}
66
66
Foo;
67
67
` ) ;
68
- expect ( resolveToValue ( program . get ( 'body' , 1 , 'expression' ) ) . node . type ) . toBe (
69
- 'ClassDeclaration' ,
70
- ) ;
68
+ expect ( resolveToValue ( path ) . node . type ) . toBe ( 'ClassDeclaration' ) ;
71
69
} ) ;
72
70
73
71
it ( 'resolves to class function declaration' , ( ) => {
74
- const program = utils . parse ( `
72
+ const path = parse ( `
75
73
function foo() {}
76
74
foo;
77
75
` ) ;
78
- expect ( resolveToValue ( program . get ( 'body' , 1 , 'expression' ) ) . node . type ) . toBe (
79
- 'FunctionDeclaration' ,
80
- ) ;
76
+ expect ( resolveToValue ( path ) . node . type ) . toBe ( 'FunctionDeclaration' ) ;
77
+ } ) ;
78
+
79
+ it ( 'resolves type cast expressions' , ( ) => {
80
+ const path = parse ( `
81
+ function foo() {}
82
+ (foo: any);
83
+ ` ) ;
84
+ expect ( resolveToValue ( path ) . node . type ) . toBe ( 'FunctionDeclaration' ) ;
81
85
} ) ;
82
86
83
87
describe ( 'assignments' , ( ) => {
Original file line number Diff line number Diff line change @@ -141,6 +141,8 @@ export default function resolveToValue(path: NodePath): NodePath {
141
141
if ( node . operator === '=' ) {
142
142
return resolveToValue ( path . get ( 'right' ) ) ;
143
143
}
144
+ } else if ( types . TypeCastExpression . check ( node ) ) {
145
+ return resolveToValue ( path . get ( 'expression' ) ) ;
144
146
} else if ( types . Identifier . check ( node ) ) {
145
147
if (
146
148
( types . ClassDeclaration . check ( path . parentPath . node ) ||
You can’t perform that action at this time.
0 commit comments