mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
Use the same filtering for UpdateExpression and AssignmentExpression.
This commit is contained in:
parent
cd7604952c
commit
dd37704f2c
1 changed files with 20 additions and 21 deletions
|
@ -168,8 +168,7 @@ var PaperScript = Base.exports.PaperScript = (function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch (node && node.type) {
|
switch (node && node.type) {
|
||||||
case 'UnaryExpression':
|
case 'UnaryExpression': // -a
|
||||||
// -a
|
|
||||||
if (node.operator in unaryOperators
|
if (node.operator in unaryOperators
|
||||||
&& node.argument.type !== 'Literal') {
|
&& node.argument.type !== 'Literal') {
|
||||||
var arg = getCode(node.argument);
|
var arg = getCode(node.argument);
|
||||||
|
@ -177,8 +176,7 @@ var PaperScript = Base.exports.PaperScript = (function() {
|
||||||
+ arg + ')');
|
+ arg + ')');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'BinaryExpression':
|
case 'BinaryExpression': // a + b, a - b, a / b, a * b, a == b, ...
|
||||||
// a + b, a - b, a / b, a * b, a == b, a % b, ...
|
|
||||||
if (node.operator in binaryOperators
|
if (node.operator in binaryOperators
|
||||||
&& node.left.type !== 'Literal') {
|
&& node.left.type !== 'Literal') {
|
||||||
var left = getCode(node.left),
|
var left = getCode(node.left),
|
||||||
|
@ -187,9 +185,9 @@ var PaperScript = Base.exports.PaperScript = (function() {
|
||||||
+ '", ' + right + ')');
|
+ '", ' + right + ')');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'UpdateExpression':
|
case 'UpdateExpression': // a++, a--
|
||||||
// a++, a--
|
case 'AssignmentExpression': /// a += b, a -= b
|
||||||
if (!node.prefix && !(parent && (
|
if (!(parent && (
|
||||||
// Filter out for statements to allow loop increments
|
// Filter out for statements to allow loop increments
|
||||||
// to perform well
|
// to perform well
|
||||||
parent.type === 'ForStatement'
|
parent.type === 'ForStatement'
|
||||||
|
@ -203,20 +201,21 @@ var PaperScript = Base.exports.PaperScript = (function() {
|
||||||
// We can't replace that with array[_$_(i, "+", 1)].
|
// We can't replace that with array[_$_(i, "+", 1)].
|
||||||
|| parent.type === 'MemberExpression'
|
|| parent.type === 'MemberExpression'
|
||||||
&& parent.computed))) {
|
&& parent.computed))) {
|
||||||
var arg = getCode(node.argument);
|
if (node.type === 'UpdateExpression') {
|
||||||
replaceCode(node, arg + ' = _$_(' + arg + ', "'
|
if (!node.prefix) {
|
||||||
+ node.operator[0] + '", 1)');
|
var arg = getCode(node.argument);
|
||||||
}
|
replaceCode(node, arg + ' = _$_(' + arg + ', "'
|
||||||
break;
|
+ node.operator[0] + '", 1)');
|
||||||
case 'AssignmentExpression':
|
}
|
||||||
/// a += b, a -= b
|
} else {
|
||||||
if (/^.=$/.test(node.operator)
|
if (/^.=$/.test(node.operator)
|
||||||
&& node.left.type !== 'Literal'
|
&& node.left.type !== 'Literal') {
|
||||||
&& !(parent && parent.type === 'ForStatement')) {
|
var left = getCode(node.left),
|
||||||
var left = getCode(node.left),
|
right = getCode(node.right);
|
||||||
right = getCode(node.right);
|
replaceCode(node, left + ' = _$_(' + left + ', "'
|
||||||
replaceCode(node, left + ' = _$_(' + left + ', "'
|
+ node.operator[0] + '", ' + right + ')');
|
||||||
+ node.operator[0] + '", ' + right + ')');
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue