-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix($parse): make equality and relational operators left-associative #6971
Conversation
Thanks for the PR! Please check the items below to help us merge this faster. See the contributing docs for more information.
If you need to make changes to your pull request, you can update the commit with Thanks again for your help! |
Hi @teropa, this is a breaking change, can you please state so in the commit log? Thinking out loud: should the behavior of |
people shouldn't even be doing expressions like this in angular expressions, but @lgalfaso is right, this is a breaking change, and that might make it difficult to backport into 1.2. @lgalfaso I don't think assignment needs to be left-associative, you'd expect the right-most assignment operation to occur first, before the left-hand ones. But really, that kind of stuff shouldn't even be happening in angular expressions :( |
This fixes an associativity issue in expressions that use multiple equality or relational operators back to back without grouping. Previously, these expressions were right-associative, which may cause confusion for users who expect them to behave identically to JavaScript expressions. An expression like "a === b === c" was evaluated as "a === (b === c)". Now it is evaluated as it is in JavaScript: "(a === b) === c". Breaks expressions that have relied on right-associativity.
Added a mention of the breakage to the commit message. Agree with @caitp that people shouldn't be doing this in Angular expressions, nor in JavaScript. In any case, this looks to me like a deviation from JavaScript's behavior for no apparent reason. Assignment is right-associative in both JavaScript and ng expressions. |
I know assignment is right-associative, but running scope.$eval('a=b=123'); throws
One way or another I do see this other issue as out of the scope of this PR |
02dc2aa
to
fd2d6c0
Compare
cad9560
to
f294244
Compare
e8dc429
to
e83fab9
Compare
4dd5a20
to
998c61c
Compare
closing this in favor of #10592 |
Request Type: bug
How to reproduce: Evaluate
"1 === 1 === true"
. Expected:true
. Actual:false
.Component(s): $parse
Impact: small
Complexity: small
This issue is related to:
Detailed Description:
This fixes an associativity issue in expressions that use multiple
equality or relational operators back to back without grouping.
Previously, these expressions were right-associative, which may
cause confusion for users who expect them to behave identically
to JavaScript expressions.
An expression like "a === b === c" was evaluated as "a === (b === c)".
Now it is evaluated as it is in JavaScript: "(a === b) === c".
Breaks expressions that have relied on right-associativity.
Other Comments: