Correct update expression Number coercion (#7766)

* Correct update expression Number coercion

You have to `ToNumber` whatever the `UpdateExpression` argument is.

* Fix systemjs update expression
This commit is contained in:
Justin Ridgewell
2018-04-22 13:50:11 -04:00
committed by GitHub
parent 890a45216f
commit 34d73ebef0
7 changed files with 40 additions and 28 deletions

View File

@@ -50,23 +50,13 @@ export default declare((api, options) => {
// if it is a non-prefix update expression (x++ etc)
// then we must replace with the expression (_export('x', x + 1), x++)
// in order to ensure the same update expression value
let isPostUpdateExpression = path.isUpdateExpression() && !node.prefix;
const isPostUpdateExpression = path.isUpdateExpression({ prefix: false });
if (isPostUpdateExpression) {
if (node.operator === "++") {
node = t.binaryExpression(
"+",
t.cloneNode(node.argument),
t.numericLiteral(1),
);
} else if (node.operator === "--") {
node = t.binaryExpression(
"-",
t.cloneNode(node.argument),
t.numericLiteral(1),
);
} else {
isPostUpdateExpression = false;
}
node = t.binaryExpression(
node.operator[0],
t.unaryExpression("+", t.cloneNode(node.argument)),
t.numericLiteral(1),
);
}
for (const exportedName of exportedNames) {

View File

@@ -5,7 +5,7 @@ System.register([], function (_export, _context) {
function a() {
alert("a");
_export("c", c + 1), c++;
_export("c", +c + 1), c++;
}
_export("a", a);

View File

@@ -11,7 +11,7 @@ System.register([], function (_export, _context) {
_export("test", test = 5);
_export("test", test + 1), test++;
_export("test", +test + 1), test++;
(function () {
var test = 2;