-
-
Notifications
You must be signed in to change notification settings - Fork 258
Add more tests for the nullish coalescing operator #762
Conversation
Oh yeah that may be better actually |
Has been changed from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs tests for ||
especially:
a || b ?? c;
a ?? b || c;
a && b ?? c;
a ?? b && c;
So: a || b ?? c === (a || b) ?? c
a ?? b || c === (a ?? b) || c But: a && b ?? c === (a && b) ?? c
a ?? b && c === a ?? (b && c) Do we have any data for why this was chosen? |
@jridgewell Is that what this code does? In the spec I wrote for |
Yes.
That appears to be what's happening? I was just curious why it's not tighter than |
@jridgewell I thought it would make sense to be exactly the same because people are likely to be upgrading their |
My intuition is it should be completely hot-swappable with |
Opened tc39/proposal-nullish-coalescing#15 to discuss this question; for now, the spec is hot-swappable like that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. We can discuss the precedence in tc39/proposal-nullish-coalescing#15.
Added some more tests for associativity, multiline parsing, and precedence.
Due to this operator being similar to
||
, and it being in theLogicalORExpression
non-terminal in the grammar, should it move fromBinaryExpression
to theLogicalExpression
AST node?Update:
??
has been moved toLogicalExpression