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

fix($parse): make equality and relational operators left-associative #6971

Closed
wants to merge 1 commit into from

Conversation

teropa
Copy link
Contributor

@teropa teropa commented Apr 3, 2014

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:

@mary-poppins
Copy link

Thanks for the PR! Please check the items below to help us merge this faster. See the contributing docs for more information.

  • Uses the issue template (#6971)

If you need to make changes to your pull request, you can update the commit with git commit --amend.
Then, update the pull request with git push -f.

Thanks again for your help!

@lgalfaso
Copy link
Contributor

lgalfaso commented Apr 3, 2014

Hi @teropa, this is a breaking change, can you please state so in the commit log?

Thinking out loud: should the behavior of = also change? This is so a = b = null is also possible

@caitp
Copy link
Contributor

caitp commented Apr 3, 2014

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.
@teropa
Copy link
Contributor Author

teropa commented Apr 4, 2014

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.

@lgalfaso
Copy link
Contributor

lgalfaso commented Apr 4, 2014

I know assignment is right-associative, but running

scope.$eval('a=b=123');

throws

Error: [$parse:syntax] Syntax Error: Token '=' is an unexpected token at column 4 of the expression [a=b=123] starting at [=123].

One way or another I do see this other issue as out of the scope of this PR

@lgalfaso
Copy link
Contributor

closing this in favor of #10592

@lgalfaso lgalfaso closed this Jan 30, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants