-
Notifications
You must be signed in to change notification settings - Fork 27.4k
A problem with boolean expression evaluation in 1.4 #11959
Comments
Thanks for the report. This happens since 1.4.0-beta.3, so it looks like it's caused by the parse refactor. @lgalfaso can you take a look? |
When there is an expression of the form `a.b` and there is a recursion that specifies where the value should be placed, then when `a == null` then set the value of the returned identifier to `undefined` Closes angular#11959
@SamuraiPrinciple thanks for reporting this! The fix landed and should be part of the next release |
Indeed - just tried it on master and it works like a charm. Much appreciated |
@lgalfaso any idea on when this might land? |
This already landed and should be part of 1.4.1 once released |
Due to the changes in angular/angular.js@71fc3f4 angular/angular.js@d19504a xref angular/angular.js#11959
Due to the changes in angular/angular.js@71fc3f4 angular/angular.js@d19504a xref angular/angular.js#11959
When there is an expression of the form `true && a.b` and where `a == null`, then set the value of `true && a.b` to `undefined`. Closes angular#11959
Due to the changes in angular/angular.js@71fc3f4 angular/angular.js@d19504a xref angular/angular.js#11959
Due to the changes in angular/angular.js@71fc3f4 angular/angular.js@d19504a xref angular/angular.js#11959
Commenting on here as I can't seem to find anything related, I just ran into an issue similar to this. I had a line of code I had to rewrite the line to This is on Angular @ 7.1 |
@jziggas This is actually the github for angularJS 1.x, but what you're doing is essentially evaluating
Which does return undefined, so it seems to be working as expected. You can use !! and parens to convert that statement into a bool like this So essentially
When either of these is falsey, it will return false If you're wondering why does this happen, this is because logical and "&&" evaluates whether left of operator (this.item) can be evaluated to truthy. If so, it returns right of operator, otherwise returns left of operator. In your case this is undefined. You can see the same if you did something like the following two is returned because one is truthy. And I realize this is getting quite long, but for the sake of completeness and a full answer I will explain the !! With Parens you can evaluate the result of (this.item && this.item.id) which will be undefined. So now you have
The ! operator returns false if its operand "undefined" is truthy otherwise true. undefined is not truthy so now you have
and the final result is obviously
|
Greetings,
After upgrading to angular 1.4 we're having a problem with expressions like:
true && aMissingObject.aMissingProperty
They evaluate to true, instead of false (incidentally, true && !!aMissingObject.aMissingProperty evaluates to false).
Here is an example on plunkr:
http://plnkr.co/edit/4wVwHOO3lsc10JaSrIXI
Could you please comment if this is expected behaviour?
Many thanks
The text was updated successfully, but these errors were encountered: