@@ -234,13 +234,33 @@ describe('AsyncWriter', function () {
234234 ) ;
235235 } ) ;
236236
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+
237250 it ( 'moves top-level classes into the top-level scope' , function ( ) {
238251 const A = runTranspiledCode ( 'class A {}' ) ;
239252 expect ( A . constructor . name ) . to . equal ( 'Function' ) ;
240253 expect ( A . name ) . to . equal ( 'A' ) ;
241254 expect ( ctx . A ) . to . equal ( A ) ;
242255 } ) ;
243256
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+
244264 it ( 'does not move classes from block scopes to the top-level scope' , function ( ) {
245265 const A = runTranspiledCode ( '{ class A {} }' ) ;
246266 expect ( A ) . to . equal ( undefined ) ;
@@ -262,6 +282,32 @@ describe('AsyncWriter', function () {
262282 runTranspiledCode ( 'switch (1) { case 1: 1; break; case 2: 2; break;}' )
263283 ) . to . equal ( 1 ) ;
264284 } ) ;
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+ } ) ;
265311 } ) ;
266312
267313 context ( 'implicit awaiting' , function ( ) {
@@ -482,6 +528,13 @@ describe('AsyncWriter', function () {
482528 ) ;
483529 } ) ;
484530
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+
485538 it ( 'supports typeof for un-defined variables' , function ( ) {
486539 expect ( runTranspiledCode ( 'typeof nonexistent' ) ) . to . equal ( 'undefined' ) ;
487540 } ) ;
0 commit comments