From d779789b6f7f937e476b7af8515dfd6ce2073075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sun, 20 Nov 2016 21:12:02 -0500 Subject: [PATCH] PaperScript: Prevent invalid JavaScript in assignment operators. Closes #1151 --- src/core/PaperScript.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/core/PaperScript.js b/src/core/PaperScript.js index 560094d0..e316f6c3 100644 --- a/src/core/PaperScript.js +++ b/src/core/PaperScript.js @@ -251,9 +251,13 @@ Base.exports.PaperScript = function() { if (/^.=$/.test(node.operator) && node.left.type !== 'Literal') { var left = getCode(node.left), - right = getCode(node.right); - replaceCode(node, left + ' = __$__(' + left + ', "' - + node.operator[0] + '", ' + right + ')'); + right = getCode(node.right), + exp = left + ' = __$__(' + left + ', "' + + node.operator[0] + '", ' + right + ')'; + // If the original expression is wrapped in + // parenthesis, do the same with the replacement: + replaceCode(node, /^\(.*\)$/.test(getCode(node)) + ? '(' + exp + ')' : exp); } } }