Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Logical Assignment Operators #212

Merged
merged 3 commits into from May 1, 2020

Conversation

mysticatea
Copy link
Contributor

Recently, Logical Assignment Operators arrived at Stage 3.

Considering AST before Stage 4 is nice.

### LogicalAssignmentExpression

```js
interface LogicalAssignmentExpression <: Expression {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a new node type for this rather than extending AssignmentOperator in AssignmentExpression?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry, I see it's explained below.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make sure I understand this: a new node type is necessary because logical assignment expressions are short-circuited?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understood, it's for symmetry with BinaryExpression vs LogicalExpression (which were initially separate due to short-circuiting, I suppose).

Personally, I'd rather have former to be a single node type as well, but that ship has sailed.

As for new node types, I don't have a strong opinion and fine with either a new node type or reusing AssignmentExpression. Would like to hear opinions of others.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's for symmetry with BinaryExpression vs LogicalExpression, and I thought that's because of short-circuit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bradzacher Yeah, as I said above

Personally, I'd rather have former to be a single node type as well, but that ship has sailed.

This has been there from the beginning of SpiderMonkey AST and I can only assume that it was for encoding of short-circuiting behaviour, but personally I'd also just use a single node type and encourage consumers to check the operator.

Not sure whether to follow the precedent or do something simpler for the new node types here. Side-note: this is why I said I'm very cautious of accidentally setting new precedents in #204 - they can affect design of nodes far away from the original addition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have any strong opinion about the choice of following the precedent or using AssignmentExpression simply.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is why I asked, as I’m not sure if we want to encode short-circuiting operations separately. My preference would be to reuse AssignmentExpression. If the intent is to execute based on the AST, you’ll always need to look at the operator anyway, and that seems like the logical time to apply any short circuiting behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK with either, but I hope consistent with #204. If we decide to not make new nodes for short-circuiting, I think it's better if #204 is consistent with that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated this PR to extending AssignmentOperator because the separation of nodes by short-circuiting looks not important to ESTree.

@mysticatea mysticatea mentioned this pull request Apr 21, 2020
Copy link
Contributor

@nzakas nzakas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@RReverser RReverser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@nzakas
Copy link
Contributor

nzakas commented May 1, 2020

We have approvals from all ESC members on this pull request, so it is approved and so I’m merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants