ensure consistent expression value for post-assignment unary expressions (#3650)
This commit is contained in:
@@ -43,10 +43,26 @@ export default function ({ types: t }) {
|
||||
|
||||
let node = path.node;
|
||||
|
||||
// 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;
|
||||
if (isPostUpdateExpression) {
|
||||
if (node.operator === "++")
|
||||
node = t.binaryExpression("+", node.argument, t.numericLiteral(1));
|
||||
else if (node.operator === "--")
|
||||
node = t.binaryExpression("-", node.argument, t.numericLiteral(1));
|
||||
else
|
||||
isPostUpdateExpression = false;
|
||||
}
|
||||
|
||||
for (let exportedName of exportedNames) {
|
||||
node = this.buildCall(exportedName, node).expression;
|
||||
}
|
||||
|
||||
if (isPostUpdateExpression)
|
||||
node = t.sequenceExpression([node, path.node]);
|
||||
|
||||
path.replaceWith(node);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"plugins": ["external-helpers", "transform-es2015-modules-systemjs"]
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
export function a() {
|
||||
alert("a");
|
||||
c++;
|
||||
}
|
||||
|
||||
export var c = 5;
|
||||
|
||||
function b() {
|
||||
a();
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
System.register([], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var c;
|
||||
function a() {
|
||||
alert("a");
|
||||
_export("c", c + 1), c++;
|
||||
}
|
||||
|
||||
_export("a", a);
|
||||
@@ -14,6 +16,10 @@ System.register([], function (_export, _context) {
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
_export("c", c = 5);
|
||||
|
||||
_export("c", c);
|
||||
|
||||
b();
|
||||
}
|
||||
};
|
||||
@@ -10,7 +10,7 @@ System.register([], function (_export, _context) {
|
||||
_export("test", test);
|
||||
|
||||
_export("test", test = 5);
|
||||
_export("test", test++);
|
||||
_export("test", test + 1), test++;
|
||||
|
||||
(function () {
|
||||
var test = 2;
|
||||
|
||||
Reference in New Issue
Block a user