@@ -52,8 +52,7 @@ describe('ES6 class', function() {
52
52
expect ( scope . type ) . to . be . equal ( 'class' ) ;
53
53
expect ( scope . block . type ) . to . be . equal ( 'ClassDeclaration' ) ;
54
54
expect ( scope . isStrict ) . to . be . true ;
55
- expect ( scope . variables ) . to . have . length ( 1 ) ;
56
- expect ( scope . variables [ 0 ] . name ) . to . be . equal ( 'Derived' ) ;
55
+ expect ( scope . variables ) . to . have . length ( 0 ) ;
57
56
expect ( scope . references ) . to . have . length ( 0 ) ;
58
57
59
58
scope = scopeManager . scopes [ 2 ] ;
@@ -191,6 +190,45 @@ describe('ES6 class', function() {
191
190
expect ( scope . references [ 0 ] . identifier . name ) . to . be . equal ( 'shoe' ) ;
192
191
expect ( scope . references [ 1 ] . identifier . name ) . to . be . equal ( 'Shoe' ) ;
193
192
} ) ;
193
+
194
+ it ( 'reference in class' , function ( ) {
195
+ const ast = parse ( `
196
+ class Foo {
197
+ constructor() {
198
+ Foo;
199
+ }
200
+ }
201
+ ` ) ;
202
+
203
+
204
+ const scopeManager = analyze ( ast , { ecmaVersion : 6 } ) ;
205
+ expect ( scopeManager . scopes ) . to . have . length ( 3 ) ;
206
+
207
+ let scope = scopeManager . scopes [ 0 ] ;
208
+ expect ( scope . type ) . to . be . equal ( 'global' ) ;
209
+ expect ( scope . block . type ) . to . be . equal ( 'Program' ) ;
210
+ expect ( scope . isStrict ) . to . be . false ;
211
+ expect ( scope . variables ) . to . have . length ( 1 ) ;
212
+ expect ( scope . variables [ 0 ] . name ) . to . be . equal ( 'Foo' ) ;
213
+ expect ( scope . variables [ 0 ] . references ) . to . have . length ( 1 ) ;
214
+ expect ( scope . variables [ 0 ] . references [ 0 ] . identifier . name ) . to . be . equal ( 'Foo' ) ;
215
+
216
+ scope = scopeManager . scopes [ 1 ] ;
217
+ expect ( scope . type ) . to . be . equal ( 'class' ) ;
218
+ expect ( scope . block . type ) . to . be . equal ( 'ClassDeclaration' ) ;
219
+ expect ( scope . isStrict ) . to . be . true ;
220
+ expect ( scope . variables ) . to . have . length ( 0 ) ;
221
+ expect ( scope . references ) . to . have . length ( 0 ) ;
222
+
223
+ scope = scopeManager . scopes [ 2 ] ;
224
+ expect ( scope . type ) . to . be . equal ( 'function' ) ;
225
+ expect ( scope . block . type ) . to . be . equal ( 'FunctionExpression' ) ;
226
+ expect ( scope . isStrict ) . to . be . true ;
227
+ expect ( scope . variables ) . to . have . length ( 1 ) ;
228
+ expect ( scope . variables [ 0 ] . name ) . to . be . equal ( 'arguments' ) ;
229
+ expect ( scope . references ) . to . have . length ( 1 ) ;
230
+ expect ( scope . references [ 0 ] . identifier . name ) . to . be . equal ( 'Foo' ) ;
231
+ } ) ;
194
232
} ) ;
195
233
196
234
// vim: set sw=4 ts=4 et tw=80 :
0 commit comments