- Rollup Version: rollup v2.50.3
- Operating System (or Browser): n/a
- Node Version (if applicable): v16.1.0
This is an obscure corner of the ECMAScript specification - thenables are similar to Promises:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve#resolving_thenables_and_throwing_errors
Repro
2.50.3 REPL
$ cat then.js
const effects = [], effect = x => effects.push(x);
Promise.resolve({
then() {
effect(1);
}
});
(async function() {
return {
then() {
effect(2);
}
};
})();
(async function() {
await ({
then: function() {
effect(3);
}
});
})();
(async function() {
await ({
get then() {
effect(4);
return () => effect(5);
}
});
})();
(async function() {
await ({
then() {
effect(6);
}
});
})();
(async function() {
await await ({
then(resolve) {
resolve({
then() {
effect(7);
}
});
}
});
})();
async function action(x) {
return x;
}
action({}); // no side effects - may be dropped
var promise = action(8);
action({
then(success, fail) {
success(effect(9));
}
});
promise.then(x => effect(x));
action({
then(resolve) {
resolve({
then() {
console.log(effects.join(" "));
}
});
}
});
Expected Behavior
$ cat then.js | node
4 1 2 3 5 6 9 8 7
Actual Behavior
$ cat then.js | rollup --silent | node
$
$ cat then.js | rollup --silent
const effects = [], effect = x => effects.push(x);
async function action(x) {
return x;
}
var promise = action(8);
promise.then(x => effect(x));
Edit 2: test case was further refined.
This is an obscure corner of the ECMAScript specification - thenables are similar to Promises:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve#resolving_thenables_and_throwing_errors
Repro
2.50.3 REPL
Expected Behavior
Actual Behavior
Edit 2: test case was further refined.