Generating correct assignments for live bindings updated with UpdateExpressions (#7489)

Fixes #7488
This commit is contained in:
Marvin Hagemeister 2018-03-04 20:46:33 +01:00 committed by Mateusz Burzyński
parent ab1e295c74
commit c92e8be612
6 changed files with 49 additions and 1 deletions

View File

@ -29,8 +29,9 @@ const simpleAssignmentVisitor = {
(path.parentPath.isExpressionStatement() && !path.isCompletionRecord())
) {
// ++i => (i += 1);
const operator = path.node.operator == "++" ? "+=" : "-=";
path.replaceWith(
t.assignmentExpression("+=", arg.node, t.numericLiteral(1)),
t.assignmentExpression(operator, arg.node, t.numericLiteral(1)),
);
} else {
const varName = path.scope.generateDeclaredUidIdentifier("old").name;

View File

@ -0,0 +1,3 @@
{
"plugins": ["external-helpers", ["transform-modules-commonjs"]]
}

View File

@ -0,0 +1,7 @@
export let diffLevel = 0;
export function diff() {
if (!--diffLevel) {
console.log("hey");
}
}

View File

@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true,
});
exports.diff = diff;
exports.diffLevel = void 0;
let diffLevel = 0;
exports.diffLevel = diffLevel;
function diff() {
if (!(exports.diffLevel = diffLevel = diffLevel - 1)) {
console.log("hey");
}
}

View File

@ -0,0 +1,7 @@
export let diffLevel = 0;
export function diff() {
if (!++diffLevel) {
console.log("hey");
}
}

View File

@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true,
});
exports.diff = diff;
exports.diffLevel = void 0;
let diffLevel = 0;
exports.diffLevel = diffLevel;
function diff() {
if (!(exports.diffLevel = diffLevel = diffLevel + 1)) {
console.log("hey");
}
}