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

Remove old optional chain features #6345

Merged
merged 1 commit into from
Jan 22, 2018

Conversation

jridgewell
Copy link
Member

  • Optional New is removed
  • Put operations on an optional chain are removed
  • Deletes on optional chain are removed

@hzoo hzoo added area: tc39 proposal PR: Spec Compliance 👓 A type of pull request used for our changelog categories labels Sep 29, 2017
@babel-bot
Copy link
Collaborator

babel-bot commented Sep 29, 2017

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/6679/

@jridgewell
Copy link
Member Author

/cc @claudepache

@littledan
Copy link

For the deleted paths, what is the behaviour? Is there a syntax error triggered at some point?

Another recent change was to change the scope of short circuiting. For example, (null?.x).y used to return undefined and now it throws a TypeError. Do you have any tests that distinguish these cases?

@jridgewell
Copy link
Member Author

These removals have to be updated in Babylon so tbey’re no longer valid.

@claudepache
Copy link

Deletes on optional chain are removed

They are not removed in the official proposal, and I don’t expect them to be removed.

@jridgewell
Copy link
Member Author

I didn’t see it in the spec, where is it handled at?

@claudepache
Copy link

I didn’t see it in the spec, where is it handled at?

There is no change needed in the current spec around delete in order to make it work.

@claudepache
Copy link

Also, some invalid constructs that should be checked:

The new operator and tagged template literals can no longer be used after optional chaining, e.g.: new a?.b() or a?.b`${x}` : they are not supported by the grammar.

Attempt to assign to an optional chain (e.g. a?.b = 2 or (a?.b)++) is an early Reference Error, in line with what happens with other statically detectable invalid assignment targets. (In the spec text, this is handled by the IsValidSimpleAssignmentTarget static semantics rule returning false.)

Copy link

@littledan littledan left a comment

Choose a reason for hiding this comment

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

A few issues with this patch and the existing optional chaining transform:

  • Seems like this expands to == null, but the specified semantics are === undefined || === null. The difference is in the semantics of the document.all object, which passes the test you wrote but not the test in the spec. (== null is fine for loose mode though).
  • Should line 13 be deleted as part of getting rid of optional chaining new? Ditto the isNewExpression on line 33.
  • I see a bunch of tests deleted; I'd prefer to see them test for the newly intended behavior (and the previous version would fail against the new tests)
  • Rather than using the .call method, maybe better to use Function.prototype.call.call (or maybe that doesn't help, I dunno)
  • When finding ?. used in places which are disallowed, such as x?.y = z, this should be a SyntaxError because IsValidSimpleAssignmentTarget is false on x?.y. Is this implemented? Ditto for new x?.(y) (though this becomes allowed again, without any chaining semantics, if you add parens like new (x?.(y)).
  • I disagree with @claudepache about optional chain delete being good to keep in; we're discussing it at Ban optional chaining delete (and anything else that may be missing?) tc39/proposal-optional-chaining#40 . As long as the spec has optional chaining delete in it, IMO Babel should continue to support it. As things are now, I'd guess that delete x?.y might just consistently evaluate to true without deleting anything; if it is removed, this should become a syntax error.

@claudepache
Copy link

As things are now, I'd guess that delete x?.y might just consistently evaluate to true without deleting anything

delete x?.y evaluates to true if x evaluates to null/undefined; otherwise, it evaluates to the same value as delete x.y (with the same side-effect).

@littledan
Copy link

that delete x?.y might just

Thanks for clarifying what the specified behavior is. My comment was referring to the Babel source.

@jridgewell
Copy link
Member Author

This has been rebased. To answer a few of @littledan's points:

Seems like this expands to == null, but the specified semantics are === undefined || === null.

This was fixed on master, and is in the rebase.

I see a bunch of tests deleted; I'd prefer to see them test for the newly intended behavior
When finding ?. used in places which are disallowed, such as x?.y = z, this should be a SyntaxError

This would require a large redo of the babylon code to accomplish. I've added checks for AssignmentExpression and UpdateExpression to throw, but they still parse.

As long as the spec has optional chaining delete in it, IMO Babel should continue to support it.

Can someone walk me through how this is handled by the spec? Without it being explicitly called out, I don't see how the current text allows it.

@hzoo
Copy link
Member

hzoo commented Jan 22, 2018

I think we should land with what's here and make a new PR for new fixes then?

@jridgewell jridgewell merged commit 180eda3 into babel:master Jan 22, 2018
@jridgewell jridgewell deleted the optional-chaining-updates branch January 22, 2018 22:03
@littledan
Copy link

This would require a large redo of the babylon code to accomplish. I've added checks for AssignmentExpression and UpdateExpression to throw, but they still parse.

Sounds like some good follow-on work.

Can someone walk me through how this is handled by the spec? Without it being explicitly called out, I don't see how the current text allows it.

See tc39/proposal-optional-chaining#40 (comment)

aminmarashi pushed a commit to aminmarashi/babel that referenced this pull request Mar 17, 2018
@nicolo-ribaudo nicolo-ribaudo moved this from In Progress to Done in Core Apr 18, 2018
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 2, 2018
@lock lock bot locked as resolved and limited conversation to collaborators May 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Spec Compliance 👓 A type of pull request used for our changelog categories Priority: High Spec: Optional Chaining
Projects
No open projects
Core
Done
Development

Successfully merging this pull request may close these issues.

None yet

6 participants