PaperScript: Prevent invalid JavaScript in assignment operators.

Closes #1151
This commit is contained in:
Jürg Lehni 2016-11-20 21:12:02 -05:00
parent 3c43a78c53
commit d779789b6f

View file

@ -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);
}
}
}