export let n = 0;
function add(a, b) {
return a + b;
}
setTimeout(() => console.log(add(++n, 99)));
This program should output "100", but actually outputs "2". This is the transpiled result:
(function () {
'use strict';
let n = 0;
function add(a, b) {
return a + b;
}
setTimeout(() => console.log(add(++n, exports.n = n, 99)));
exports.n = n;
}).call(global);
Esperanto is trying to replace the UpdateExpression with a SequenceExpression, but instead it's adding an argument to the parent CallExpression. In this case the SequenceExpression should be wrapped in parentheses. We could always wrap it in parentheses, but it'd be nice to only add them if required.
This program should output "100", but actually outputs "2". This is the transpiled result:
Esperanto is trying to replace the
UpdateExpression
with aSequenceExpression
, but instead it's adding an argument to the parentCallExpression
. In this case theSequenceExpression
should be wrapped in parentheses. We could always wrap it in parentheses, but it'd be nice to only add them if required.For reference, here's babel's output:
It seems that it does not need parentheses for this case, but for
n++
it would.