@@ -11,8 +11,8 @@ import { parse } from '../../../tests/utils';
1111import resolveToValue from '../resolveToValue' ;
1212
1313describe ( 'resolveToValue' , ( ) => {
14- function parsePath ( src ) {
15- const root = parse ( src . trim ( ) ) ;
14+ function parsePath ( src , options = { } ) {
15+ const root = parse ( src . trim ( ) , options ) ;
1616 return root . get ( 'body' , root . node . body . length - 1 , 'expression' ) ;
1717 }
1818
@@ -72,12 +72,35 @@ describe('resolveToValue', () => {
7272 expect ( resolveToValue ( path ) . node . type ) . toBe ( 'FunctionDeclaration' ) ;
7373 } ) ;
7474
75- it ( 'resolves type cast expressions' , ( ) => {
76- const path = parsePath ( `
75+ describe ( 'flow' , ( ) => {
76+ it ( 'resolves type cast expressions' , ( ) => {
77+ const path = parsePath ( `
7778 function foo() {}
7879 (foo: any);
7980 ` ) ;
80- expect ( resolveToValue ( path ) . node . type ) . toBe ( 'FunctionDeclaration' ) ;
81+ expect ( resolveToValue ( path ) . node . type ) . toBe ( 'FunctionDeclaration' ) ;
82+ } ) ;
83+ } ) ;
84+
85+ describe ( 'typescript' , ( ) => {
86+ const parseTypescript = src =>
87+ parsePath ( src , { parserOptions : { plugins : [ 'typescript' ] } } ) ;
88+
89+ it ( 'resolves type as expressions' , ( ) => {
90+ const path = parseTypescript ( `
91+ function foo() {}
92+ (foo as any);
93+ ` ) ;
94+ expect ( resolveToValue ( path ) . node . type ) . toBe ( 'FunctionDeclaration' ) ;
95+ } ) ;
96+
97+ it ( 'resolves type assertions' , ( ) => {
98+ const path = parseTypescript ( `
99+ function foo() {}
100+ (<any> foo);
101+ ` ) ;
102+ expect ( resolveToValue ( path ) . node . type ) . toBe ( 'FunctionDeclaration' ) ;
103+ } ) ;
81104 } ) ;
82105
83106 describe ( 'assignments' , ( ) => {
0 commit comments