Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/async-rewriter2/src/async-writer-babel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/async-rewriter2/src/runtime-support.nocov.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down