From b26c6221f1b0e2b1a9afbc9aa3745477a81fd97b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 15 Jun 2015 23:43:03 +0200 Subject: [PATCH] Fix PaperScript increment operator in rare special case. Closes #691. --- src/core/PaperScript.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/core/PaperScript.js b/src/core/PaperScript.js index 09843b9a..693616b7 100644 --- a/src/core/PaperScript.js +++ b/src/core/PaperScript.js @@ -225,15 +225,22 @@ Base.exports.PaperScript = (function() { || parentType === 'MemberExpression' && parent.computed )) { if (node.type === 'UpdateExpression') { - var arg = getCode(node.argument); - var str = arg + ' = __$__(' + arg - + ', "' + node.operator[0] + '", 1)'; + var arg = getCode(node.argument), + exp = '__$__(' + arg + ', "' + node.operator[0] + + '", 1)', + str = arg + ' = ' + exp; // If this is not a prefixed update expression // (++a, --a), assign the old value before updating it. if (!node.prefix && (parentType === 'AssignmentExpression' - || parentType === 'VariableDeclarator')) + || parentType === 'VariableDeclarator')) { + // Handle special issue #691 where the old value is + // assigned to itself, and the expression is just + // executed after, e.g.: `var x = ***; x = x++;` + if (getCode(parent.left || parent.id) === arg) + str = exp; str = arg + '; ' + str; + } replaceCode(node, str); } else { // AssignmentExpression if (/^.=$/.test(node.operator)