@@ -234,13 +234,33 @@ describe('AsyncWriter', function () {
234
234
) ;
235
235
} ) ;
236
236
237
+ it ( 'can handle semicolon-less input inside functions' , function ( ) {
238
+ expect (
239
+ runTranspiledCode ( `
240
+ (function() {
241
+ let foo = {}
242
+ foo.bar = {}
243
+ foo.fn = function() {}
244
+ return foo;
245
+ })()
246
+ ` ) . bar
247
+ ) . to . deep . equal ( { } ) ;
248
+ } ) ;
249
+
237
250
it ( 'moves top-level classes into the top-level scope' , function ( ) {
238
251
const A = runTranspiledCode ( 'class A {}' ) ;
239
252
expect ( A . constructor . name ) . to . equal ( 'Function' ) ;
240
253
expect ( A . name ) . to . equal ( 'A' ) ;
241
254
expect ( ctx . A ) . to . equal ( A ) ;
242
255
} ) ;
243
256
257
+ it ( 'can initialize immediately after a class definition' , function ( ) {
258
+ const A = runTranspiledCode (
259
+ 'class A { prop = 42; }\nconst foo = new A(); foo'
260
+ ) ;
261
+ expect ( A . prop ) . to . equal ( 42 ) ;
262
+ } ) ;
263
+
244
264
it ( 'does not move classes from block scopes to the top-level scope' , function ( ) {
245
265
const A = runTranspiledCode ( '{ class A {} }' ) ;
246
266
expect ( A ) . to . equal ( undefined ) ;
@@ -262,6 +282,32 @@ describe('AsyncWriter', function () {
262
282
runTranspiledCode ( 'switch (1) { case 1: 1; break; case 2: 2; break;}' )
263
283
) . to . equal ( 1 ) ;
264
284
} ) ;
285
+
286
+ it ( 'supports labeled break/switch' , function ( ) {
287
+ expect (
288
+ runTranspiledCode ( `
289
+ let i,j;
290
+ label1: for (i = 0;; i++) {
291
+ label2: for (j = 0; j < 2; j++) {
292
+ if (i++ === 0) continue label2;
293
+ };
294
+ if (i++ > 20) break label1;
295
+ }; i` )
296
+ ) . to . equal ( 23 ) ;
297
+ } ) ;
298
+
299
+ it ( 'keeps `this` intact for function calls' , function ( ) {
300
+ expect (
301
+ runTranspiledCode (
302
+ '({ foo: 42, method() { return this } }).method().foo'
303
+ )
304
+ ) . to . equal ( 42 ) ;
305
+ expect (
306
+ runTranspiledCode (
307
+ '({ foo: 42, method() { return this } })["method"]().foo'
308
+ )
309
+ ) . to . equal ( 42 ) ;
310
+ } ) ;
265
311
} ) ;
266
312
267
313
context ( 'implicit awaiting' , function ( ) {
@@ -482,6 +528,13 @@ describe('AsyncWriter', function () {
482
528
) ;
483
529
} ) ;
484
530
531
+ it ( 'handles sync callbacks for builtin functions' , async function ( ) {
532
+ const ret = runTranspiledCode (
533
+ '["abc", "def"].filter(x => x.endsWith("f"))'
534
+ ) ;
535
+ expect ( await ret ) . to . deep . equal ( [ 'def' ] ) ;
536
+ } ) ;
537
+
485
538
it ( 'supports typeof for un-defined variables' , function ( ) {
486
539
expect ( runTranspiledCode ( 'typeof nonexistent' ) ) . to . equal ( 'undefined' ) ;
487
540
} ) ;
0 commit comments