diff --git a/packages/async-rewriter2/src/async-writer-babel.spec.ts b/packages/async-rewriter2/src/async-writer-babel.spec.ts index 47ac0728c2..38d0491029 100644 --- a/packages/async-rewriter2/src/async-writer-babel.spec.ts +++ b/packages/async-rewriter2/src/async-writer-babel.spec.ts @@ -674,6 +674,14 @@ describe('AsyncWriter', () => { `); expect(arr).to.deep.equal(new Uint8Array([1, 4, 9, 16])); }); + + it('supports Array.prototype.sort without callback', () => { + const arr = runTranspiledCode(` + const arr = [ 1, 9, 4, 16 ]; + arr.sort() + `); + expect(arr).to.deep.equal([ 1, 16, 4, 9 ]); + }); }); context('Function.prototype.toString', () => { diff --git a/packages/async-rewriter2/src/runtime-support.nocov.js b/packages/async-rewriter2/src/runtime-support.nocov.js index 9fb33c60f6..728033a54f 100644 --- a/packages/async-rewriter2/src/runtime-support.nocov.js +++ b/packages/async-rewriter2/src/runtime-support.nocov.js @@ -453,23 +453,23 @@ module.exports = '(' + function() { const origArraySort = Array.prototype.sort; Array.prototype.sort = function(compareFn) { - return origArraySort.call(this, function(...args) { + return origArraySort.call(this, compareFn ? function(...args) { // (Ab-)use a generator function as one of the places where using // implicit async expression results in an error. return [...(function*() { yield compareFn(...args); })()][0]; - }); + } : undefined); }; const origTypedArraySort = TypedArray.prototype.sort; TypedArray.prototype.sort = function(compareFn) { - return origTypedArraySort.call(this, function(...args) { + return origTypedArraySort.call(this, compareFn ? function(...args) { // (Ab-)use a generator function as one of the places where using // implicit async expression results in an error. return [...(function*() { yield compareFn(...args); })()][0]; - }); + } : undefined); }; Array.prototype.flatMap = function(...args) {