Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix(angular): fix to check if source and destination are equivalent in angular.copy #695

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ var OPERATORS = {
'true':function(self){return true;},
'false':function(self){return false;},
$undefined:noop,
'+':function(self, a,b){return (isDefined(a)?a:0)+(isDefined(b)?b:0);},
'-':function(self, a,b){return (isDefined(a)?a:0)-(isDefined(b)?b:0);},
'*':function(self, a,b){return a*b;},
'/':function(self, a,b){return a/b;},
'%':function(self, a,b){return a%b;},
'^':function(self, a,b){return a^b;},
'+':function(self, a,b){a=a(self); b=b(self); return (isDefined(a)?a:0)+(isDefined(b)?b:0);},
'-':function(self, a,b){a=a(self); b=b(self); return (isDefined(a)?a:0)-(isDefined(b)?b:0);},
'*':function(self, a,b){return a(self)*b(self);},
'/':function(self, a,b){return a(self)/b(self);},
'%':function(self, a,b){return a(self)%b(self);},
'^':function(self, a,b){return a(self)^b(self);},
'=':noop,
'==':function(self, a,b){return a==b;},
'!=':function(self, a,b){return a!=b;},
'<':function(self, a,b){return a<b;},
'>':function(self, a,b){return a>b;},
'<=':function(self, a,b){return a<=b;},
'>=':function(self, a,b){return a>=b;},
'&&':function(self, a,b){return a&&b;},
'||':function(self, a,b){return a||b;},
'&':function(self, a,b){return a&b;},
'==':function(self, a,b){return a(self)==b(self);},
'!=':function(self, a,b){return a(self)!=b(self);},
'<':function(self, a,b){return a(self)<b(self);},
'>':function(self, a,b){return a(self)>b(self);},
'<=':function(self, a,b){return a(self)<=b(self);},
'>=':function(self, a,b){return a(self)>=b(self);},
'&&':function(self, a,b){return a(self)&&b(self);},
'||':function(self, a,b){return a(self)||b(self);},
'&':function(self, a,b){return a(self)&b(self);},
// '|':function(self, a,b){return a|b;},
'|':function(self, a,b){return b(self, a);},
'!':function(self, a){return !a;}
'|':function(self, a,b){return b(self)(self, a(self));},
'!':function(self, a){return !a(self);}
};
var ESCAPE = {"n":"\n", "f":"\f", "r":"\r", "t":"\t", "v":"\v", "'":"'", '"':'"'};

Expand Down Expand Up @@ -308,13 +308,13 @@ function parser(text, json){

function unaryFn(fn, right) {
return function(self) {
return fn(self, right(self));
return fn(self, right);
};
}

function binaryFn(left, fn, right) {
return function(self) {
return fn(self, left(self), right(self));
return fn(self, left, right);
};
}

Expand Down
16 changes: 16 additions & 0 deletions test/ParserSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,22 @@ describe('parser', function() {
expect(scope.obj[0].name).toEqual(1);
});

it('should short circuit AND operator', function(){
var scope = angular.scope();
scope.run = function(){
throw "IT SHOULD NOT HAVE RUN";
};
expect(scope.$eval('false && run()')).toBe(false);
});

it('should short circuit OR operator', function(){
var scope = angular.scope();
scope.run = function(){
throw "IT SHOULD NOT HAVE RUN";
};
expect(scope.$eval('true || run()')).toBe(true);
});

describe('formatter', function(){
it('should return no argument function', function() {
var noop = parser('noop').formatter()();
Expand Down