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