mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-08-10 21:19:10 -04:00
Clean up and improve PaperScript code a bit.
This commit is contained in:
parent
c227d589ca
commit
ee65ee1026
1 changed files with 8 additions and 8 deletions
|
@ -37,7 +37,7 @@ var PaperScript = this.PaperScript = new function() {
|
||||||
var handler = operators[operator];
|
var handler = operators[operator];
|
||||||
if (left && left[handler]) {
|
if (left && left[handler]) {
|
||||||
var res = left[handler](right);
|
var res = left[handler](right);
|
||||||
return operator == '!=' ? !res : res;
|
return operator === '!=' ? !res : res;
|
||||||
}
|
}
|
||||||
switch (operator) {
|
switch (operator) {
|
||||||
case '+': return left + right;
|
case '+': return left + right;
|
||||||
|
@ -50,7 +50,7 @@ var PaperScript = this.PaperScript = new function() {
|
||||||
default:
|
default:
|
||||||
throw new Error('Implement Operator: ' + operator);
|
throw new Error('Implement Operator: ' + operator);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
// Sign Operators
|
// Sign Operators
|
||||||
|
|
||||||
|
@ -109,8 +109,8 @@ var PaperScript = this.PaperScript = new function() {
|
||||||
// Handle simple mathematical operators here:
|
// Handle simple mathematical operators here:
|
||||||
return handleOperator(operator, left = walk(left),
|
return handleOperator(operator, left = walk(left),
|
||||||
right = walk(right))
|
right = walk(right))
|
||||||
// Always return something since we're walking left and
|
// Always return a new AST for this node, since we have
|
||||||
// right for the handleOperator() call already.
|
// processed left and right int he call above!
|
||||||
|| [this[0], operator, left, right];
|
|| [this[0], operator, left, right];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -121,10 +121,10 @@ var PaperScript = this.PaperScript = new function() {
|
||||||
// of handleOperator on the right hand side.
|
// of handleOperator on the right hand side.
|
||||||
var res = handleOperator(operator, left = walk(left),
|
var res = handleOperator(operator, left = walk(left),
|
||||||
right = walk(right));
|
right = walk(right));
|
||||||
if (res)
|
return res
|
||||||
return [this[0], true, left, res];
|
? [this[0], true, left, res]
|
||||||
// Always return something for the same reason as in binary
|
// Always return a new AST for the same reason as in binary
|
||||||
return [this[0], operator, left, right];
|
: [this[0], operator, left, right];
|
||||||
},
|
},
|
||||||
|
|
||||||
'unary-prefix': function(operator, exp) {
|
'unary-prefix': function(operator, exp) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue