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:
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user