File tree Expand file tree Collapse file tree 4 files changed +141
-3
lines changed Expand file tree Collapse file tree 4 files changed +141
-3
lines changed Original file line number Diff line number Diff line change 1+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+ exports [` resolveGenericTypeAnnotation resolves type 1` ] = `
4+ Node {
5+ " callProperties" : Array [],
6+ " end" : 57 ,
7+ " exact" : false ,
8+ " indexers" : Array [],
9+ " inexact" : false ,
10+ " internalSlots" : Array [],
11+ " loc" : SourceLocation {
12+ " end" : Position {
13+ " column" : 34 ,
14+ " line" : 3 ,
15+ },
16+ " filename" : undefined ,
17+ " identifierName" : undefined ,
18+ " start" : Position {
19+ " column" : 21 ,
20+ " line" : 3 ,
21+ },
22+ },
23+ " properties" : Array [
24+ Node {
25+ " end" : 55 ,
26+ " key" : Node {
27+ " end" : 47 ,
28+ " loc" : SourceLocation {
29+ " end" : Position {
30+ " column" : 24 ,
31+ " line" : 3 ,
32+ },
33+ " filename" : undefined ,
34+ " identifierName" : " x" ,
35+ " start" : Position {
36+ " column" : 23 ,
37+ " line" : 3 ,
38+ },
39+ },
40+ " name" : " x" ,
41+ " start" : 46 ,
42+ " type" : " Identifier" ,
43+ },
44+ " kind" : " init" ,
45+ " loc" : SourceLocation {
46+ " end" : Position {
47+ " column" : 32 ,
48+ " line" : 3 ,
49+ },
50+ " filename" : undefined ,
51+ " identifierName" : undefined ,
52+ " start" : Position {
53+ " column" : 23 ,
54+ " line" : 3 ,
55+ },
56+ },
57+ " method" : false ,
58+ " optional" : false ,
59+ " proto" : false ,
60+ " start" : 46 ,
61+ " static" : false ,
62+ " type" : " ObjectTypeProperty" ,
63+ " value" : Node {
64+ " end" : 55 ,
65+ " loc" : SourceLocation {
66+ " end" : Position {
67+ " column" : 32 ,
68+ " line" : 3 ,
69+ },
70+ " filename" : undefined ,
71+ " identifierName" : undefined ,
72+ " start" : Position {
73+ " column" : 26 ,
74+ " line" : 3 ,
75+ },
76+ },
77+ " start" : 49 ,
78+ " type" : " StringTypeAnnotation" ,
79+ },
80+ " variance" : null ,
81+ },
82+ ],
83+ " start" : 44 ,
84+ " type" : " ObjectTypeAnnotation" ,
85+ }
86+ ` ;
Original file line number Diff line number Diff line change 1+ import { expression , statement } from '../../../tests/utils' ;
2+ import isUnreachableFlowType from '../isUnreachableFlowType' ;
3+
4+ describe ( 'isUnreachableFlowType' , ( ) => {
5+ it ( 'considers Identifier as unreachable' , ( ) => {
6+ expect ( isUnreachableFlowType ( expression ( 'foo' ) ) ) . toBe ( true ) ;
7+ } ) ;
8+
9+ it ( 'considers ImportDeclaration as unreachable' , ( ) => {
10+ expect ( isUnreachableFlowType ( statement ( 'import x from "";' ) ) ) . toBe ( true ) ;
11+ } ) ;
12+
13+ it ( 'considers CallExpression as unreachable' , ( ) => {
14+ expect ( isUnreachableFlowType ( expression ( 'foo()' ) ) ) . toBe ( true ) ;
15+ } ) ;
16+
17+ it ( 'considers VariableDeclaration not as unreachable' , ( ) => {
18+ expect ( isUnreachableFlowType ( statement ( 'const x = 1;' ) ) ) . toBe ( false ) ;
19+ } ) ;
20+ } ) ;
Original file line number Diff line number Diff line change 1+ import { statement , noopImporter } from '../../../tests/utils' ;
2+ import resolveGenericTypeAnnotation from '../resolveGenericTypeAnnotation' ;
3+
4+ describe ( 'resolveGenericTypeAnnotation' , ( ) => {
5+ it ( 'resolves type' , ( ) => {
6+ const code = `
7+ var x: Props;
8+ type Props = { x: string };
9+ ` ;
10+ expect (
11+ resolveGenericTypeAnnotation (
12+ statement ( code ) . get (
13+ 'declarations' ,
14+ 0 ,
15+ 'id' ,
16+ 'typeAnnotation' ,
17+ 'typeAnnotation' ,
18+ ) ,
19+ noopImporter ,
20+ ) ,
21+ ) . toMatchSnapshot ( ) ;
22+ } ) ;
23+ } ) ;
Original file line number Diff line number Diff line change @@ -50,14 +50,23 @@ function toArray(path: NodePath): Array<string> {
5050 } else if ( t . Literal . check ( node ) ) {
5151 result . push ( node . raw ) ;
5252 continue ;
53+ } else if ( t . FunctionExpression . check ( node ) ) {
54+ result . push ( '<function>' ) ;
55+ continue ;
5356 } else if ( t . ThisExpression . check ( node ) ) {
5457 result . push ( 'this' ) ;
5558 continue ;
5659 } else if ( t . ObjectExpression . check ( node ) ) {
5760 const properties = path . get ( 'properties' ) . map ( function ( property ) {
58- return (
59- toString ( property . get ( 'key' ) ) + ': ' + toString ( property . get ( 'value' ) )
60- ) ;
61+ if ( t . SpreadElement . check ( property . node ) ) {
62+ return `...${ toString ( property . get ( 'argument' ) ) } ` ;
63+ } else {
64+ return (
65+ toString ( property . get ( 'key' ) ) +
66+ ': ' +
67+ toString ( property . get ( 'value' ) )
68+ ) ;
69+ }
6170 } ) ;
6271 result . push ( '{' + properties . join ( ', ' ) + '}' ) ;
6372 continue ;
You can’t perform that action at this time.
0 commit comments