@@ -386,6 +386,14 @@ describe('AsyncWriter', () => {
386
386
for (const value of gen) return value;
387
387
})()` ) ) . to . throw ( '[ASYNC-10012] Result of expression "implicitlyAsyncFn()" cannot be used in this context' ) ;
388
388
} ) ;
389
+
390
+ it ( 'cannot implicitly await inside of array.sort() callback' , ( ) => {
391
+ implicitlyAsyncFn . callsFake ( ( x , y ) => x . a - y . a ) ;
392
+ expect ( ( ) => runTranspiledCode ( `
393
+ const arr = [{ a: 2 }, { a : 1 }];
394
+ arr.sort((x, y) => implicitlyAsyncFn(x, y));
395
+ ` ) ) . to . throw ( '[ASYNC-10012] Result of expression "compareFn(...args)" cannot be used in this context' ) ;
396
+ } ) ;
389
397
} ) ;
390
398
} ) ;
391
399
@@ -523,6 +531,15 @@ describe('AsyncWriter', () => {
523
531
expect ( implicitlyAsyncFn ) . to . have . been . calledWith ( 4 , 4 , set ) ;
524
532
expect ( implicitlyAsyncFn ) . to . have . been . calledWith ( 6 , 6 , set ) ;
525
533
} ) ;
534
+
535
+ it ( 'supports Array.prototype.flatMap' , async ( ) => {
536
+ implicitlyAsyncFn . callsFake ( x => [ x - 1 , x ] ) ;
537
+ const arr = await runTranspiledCode ( `
538
+ const arr = [ 2, 4, 6, 8 ];
539
+ arr.flatMap(implicitlyAsyncFn)
540
+ ` ) ;
541
+ expect ( arr ) . to . deep . equal ( [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] ) ;
542
+ } ) ;
526
543
} ) ;
527
544
528
545
context ( 'synchronous' , ( ) => {
@@ -630,6 +647,33 @@ describe('AsyncWriter', () => {
630
647
expect ( plainFn ) . to . have . been . calledWith ( 4 , 4 , set ) ;
631
648
expect ( plainFn ) . to . have . been . calledWith ( 6 , 6 , set ) ;
632
649
} ) ;
650
+
651
+ it ( 'supports Array.prototype.flatMap' , ( ) => {
652
+ plainFn . callsFake ( x => [ x - 1 , x ] ) ;
653
+ const arr = runTranspiledCode ( `
654
+ const arr = [ 2, 4, 6, 8 ];
655
+ arr.flatMap(plainFn)
656
+ ` ) ;
657
+ expect ( arr ) . to . deep . equal ( [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] ) ;
658
+ } ) ;
659
+
660
+ it ( 'supports Array.prototype.sort' , ( ) => {
661
+ plainFn . callsFake ( ( x , y ) => x . a - y . a ) ;
662
+ const arr = runTranspiledCode ( `
663
+ const arr = [ { a: 1 }, { a: 9 }, { a: 4 }, { a: 16 } ];
664
+ arr.sort(plainFn)
665
+ ` ) ;
666
+ expect ( arr ) . to . deep . equal ( [ { a : 1 } , { a : 4 } , { a : 9 } , { a : 16 } ] ) ;
667
+ } ) ;
668
+
669
+ it ( 'supports TypedArray.prototype.sort' , ( ) => {
670
+ plainFn . callsFake ( ( x , y ) => x - y ) ;
671
+ const arr = runTranspiledCode ( `
672
+ const arr = new Uint8Array([1, 9, 4, 16]);
673
+ arr.sort(plainFn)
674
+ ` ) ;
675
+ expect ( arr ) . to . deep . equal ( new Uint8Array ( [ 1 , 4 , 9 , 16 ] ) ) ;
676
+ } ) ;
633
677
} ) ;
634
678
635
679
context ( 'Function.prototype.toString' , ( ) => {
0 commit comments