Skip to content

Commit

Permalink
PaperScript: Prevent invalid JavaScript in assignment operators.
Browse files Browse the repository at this point in the history
Closes #1151
  • Loading branch information
lehni committed Nov 21, 2016
1 parent 3c43a78 commit d779789
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/core/PaperScript.js
Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit d779789

Please sign in to comment.