@@ -24,14 +24,14 @@ describe('resolveToValue', () => {
24
24
25
25
it ( 'resolves simple variable declarations' , ( ) => {
26
26
const path = parse ( [ 'var foo = 42;' , 'foo;' ] . join ( '\n' ) ) ;
27
- expect ( resolveToValue ( path ) . node ) . toEqualASTNode ( builders . literal ( 42 ) ) ;
27
+ expect ( resolveToValue ( path ) ) . toEqualASTNode ( builders . literal ( 42 ) ) ;
28
28
} ) ;
29
29
30
30
it ( 'resolves object destructuring' , ( ) => {
31
31
const path = parse ( [ 'var {foo: {bar: baz}} = bar;' , 'baz;' ] . join ( '\n' ) ) ;
32
32
33
33
// Node should be equal to bar.foo.bar
34
- expect ( resolveToValue ( path ) . node ) . toEqualASTNode (
34
+ expect ( resolveToValue ( path ) ) . toEqualASTNode (
35
35
builders . memberExpression (
36
36
builders . memberExpression (
37
37
builders . identifier ( 'bar' ) ,
@@ -45,19 +45,19 @@ describe('resolveToValue', () => {
45
45
it ( 'handles SpreadElements properly' , ( ) => {
46
46
const path = parse ( [ 'var {foo: {bar}, ...baz} = bar;' , 'baz;' ] . join ( '\n' ) ) ;
47
47
48
- expect ( resolveToValue ( path ) . node ) . toEqualASTNode ( path . node ) ;
48
+ expect ( resolveToValue ( path ) ) . toEqualASTNode ( path ) ;
49
49
} ) ;
50
50
51
51
it ( 'returns the original path if it cannot be resolved' , ( ) => {
52
52
const path = parse ( [ 'function foo() {}' , 'foo()' ] . join ( '\n' ) ) ;
53
53
54
- expect ( resolveToValue ( path ) . node ) . toEqualASTNode ( path . node ) ;
54
+ expect ( resolveToValue ( path ) ) . toEqualASTNode ( path ) ;
55
55
} ) ;
56
56
57
57
it ( 'resolves variable declarators to their init value' , ( ) => {
58
58
const path = utils . parse ( 'var foo = 42;' ) . get ( 'body' , 0 , 'declarations' , 0 ) ;
59
59
60
- expect ( resolveToValue ( path ) . node ) . toEqualASTNode ( builders . literal ( 42 ) ) ;
60
+ expect ( resolveToValue ( path ) ) . toEqualASTNode ( builders . literal ( 42 ) ) ;
61
61
} ) ;
62
62
63
63
it ( 'resolves to class declarations' , ( ) => {
@@ -84,49 +84,57 @@ describe('resolveToValue', () => {
84
84
it ( 'resolves to assigned values' , ( ) => {
85
85
const path = parse ( [ 'var foo;' , 'foo = 42;' , 'foo;' ] . join ( '\n' ) ) ;
86
86
87
- expect ( resolveToValue ( path ) . node ) . toEqualASTNode ( builders . literal ( 42 ) ) ;
87
+ expect ( resolveToValue ( path ) ) . toEqualASTNode ( builders . literal ( 42 ) ) ;
88
88
} ) ;
89
89
} ) ;
90
90
91
91
describe ( 'ImportDeclaration' , ( ) => {
92
92
it ( 'resolves default import references to the import declaration' , ( ) => {
93
93
const path = parse ( [ 'import foo from "Foo"' , 'foo;' ] . join ( '\n' ) ) ;
94
+ const value = resolveToValue ( path ) ;
94
95
95
- expect ( resolveToValue ( path ) . node . type ) . toBe ( 'ImportDeclaration' ) ;
96
+ expect ( Array . isArray ( value . value ) ) . toBe ( false ) ;
97
+ expect ( value . node . type ) . toBe ( 'ImportDeclaration' ) ;
96
98
} ) ;
97
99
98
100
it ( 'resolves named import references to the import declaration' , ( ) => {
99
101
const path = parse ( [ 'import {foo} from "Foo"' , 'foo;' ] . join ( '\n' ) ) ;
102
+ const value = resolveToValue ( path ) ;
100
103
101
- expect ( resolveToValue ( path ) . node . type ) . toBe ( 'ImportDeclaration' ) ;
104
+ expect ( Array . isArray ( value . value ) ) . toBe ( false ) ;
105
+ expect ( value . node . type ) . toBe ( 'ImportDeclaration' ) ;
102
106
} ) ;
103
107
104
108
it ( 'resolves aliased import references to the import declaration' , ( ) => {
105
109
const path = parse ( [ 'import {foo as bar} from "Foo"' , 'bar;' ] . join ( '\n' ) ) ;
110
+ const value = resolveToValue ( path ) ;
106
111
107
- expect ( resolveToValue ( path ) . node . type ) . toBe ( 'ImportDeclaration' ) ;
112
+ expect ( Array . isArray ( value . value ) ) . toBe ( false ) ;
113
+ expect ( value . node . type ) . toBe ( 'ImportDeclaration' ) ;
108
114
} ) ;
109
115
110
116
it ( 'resolves namespace import references to the import declaration' , ( ) => {
111
117
const path = parse ( [ 'import * as bar from "Foo"' , 'bar;' ] . join ( '\n' ) ) ;
118
+ const value = resolveToValue ( path ) ;
112
119
113
- expect ( resolveToValue ( path ) . node . type ) . toBe ( 'ImportDeclaration' ) ;
120
+ expect ( Array . isArray ( value . value ) ) . toBe ( false ) ;
121
+ expect ( value . node . type ) . toBe ( 'ImportDeclaration' ) ;
114
122
} ) ;
115
123
} ) ;
116
124
117
125
describe ( 'MemberExpression' , ( ) => {
118
126
it ( "resolves a MemberExpression to it's init value" , ( ) => {
119
127
const path = parse ( [ 'var foo = { bar: 1 };' , 'foo.bar;' ] . join ( '\n' ) ) ;
120
128
121
- expect ( resolveToValue ( path ) . node ) . toEqualASTNode ( builders . literal ( 1 ) ) ;
129
+ expect ( resolveToValue ( path ) ) . toEqualASTNode ( builders . literal ( 1 ) ) ;
122
130
} ) ;
123
131
124
132
it ( 'resolves a MemberExpression in the scope chain' , ( ) => {
125
133
const path = parse (
126
134
[ 'var foo = 1;' , 'var bar = { baz: foo };' , 'bar.baz;' ] . join ( '\n' ) ,
127
135
) ;
128
136
129
- expect ( resolveToValue ( path ) . node ) . toEqualASTNode ( builders . literal ( 1 ) ) ;
137
+ expect ( resolveToValue ( path ) ) . toEqualASTNode ( builders . literal ( 1 ) ) ;
130
138
} ) ;
131
139
132
140
it ( 'resolves a nested MemberExpression in the scope chain' , ( ) => {
@@ -138,7 +146,7 @@ describe('resolveToValue', () => {
138
146
] . join ( '\n' ) ,
139
147
) ;
140
148
141
- expect ( resolveToValue ( path ) . node ) . toEqualASTNode ( builders . literal ( 1 ) ) ;
149
+ expect ( resolveToValue ( path ) ) . toEqualASTNode ( builders . literal ( 1 ) ) ;
142
150
} ) ;
143
151
144
152
it ( 'returns the last resolvable MemberExpression' , ( ) => {
@@ -150,7 +158,7 @@ describe('resolveToValue', () => {
150
158
] . join ( '\n' ) ,
151
159
) ;
152
160
153
- expect ( resolveToValue ( path ) . node ) . toEqualASTNode (
161
+ expect ( resolveToValue ( path ) ) . toEqualASTNode (
154
162
builders . memberExpression (
155
163
builders . identifier ( 'foo' ) ,
156
164
builders . identifier ( 'bar' ) ,
@@ -163,7 +171,7 @@ describe('resolveToValue', () => {
163
171
[ 'var foo = {};' , 'foo.bar = 1;' , 'foo.bar;' ] . join ( '\n' ) ,
164
172
) ;
165
173
166
- expect ( resolveToValue ( path ) . node ) . toEqualASTNode ( path . node ) ;
174
+ expect ( resolveToValue ( path ) ) . toEqualASTNode ( path ) ;
167
175
} ) ;
168
176
} ) ;
169
177
} ) ;
0 commit comments