Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Conditional MemberAccess (Null propagation) #205

Closed
kristofdegrave opened this issue Oct 29, 2016 · 10 comments
Closed

Conditional MemberAccess (Null propagation) #205

kristofdegrave opened this issue Oct 29, 2016 · 10 comments

Comments

@kristofdegrave
Copy link

Hi,

I would like to add conditional member access to babel. This must allow developers to access the members of an object conditionally. This means they no longer need to check if the object is undefined before accessing the member of the object.

The syntax I use for this is "?." and "?[".

So before I can add a transformer for this in the babel project I need to adjust babylon so "?." and "?[" get recognized as member access but in a conditional form. I already created a fork on which I committed some code to do the parsing and handeling.

I guess before I can create a pull request you probably want some tests added for this. This is where it is getting unclear for me. I don't know where I should add the test for this functionality. Can anyone help me with this?

I have also added the transformer on a fork of babel so you can get an idea where I want to go. https://github.com/kristofdegrave/babel/tree/master/packages/babel-plugin-transform-conditional-member-access

@SerkanSipahi
Copy link

Hi,
nice suggestion. I would use it but i think the babylon(babel) team will not add "condition member access" to babel as long as it does not have any status in:

I have not found any discussion about it in TC39. Maybe you could make your suggestion as proposals in TC39.

Here is an discussion about "condition member access" in microsoft/TypeScript#16 - maybe interesting for you!

@DrewML
Copy link
Member

DrewML commented Oct 30, 2016

Hi @kristofdegrave,

Thanks for the interest in contributing to Babylon! @SerkanSipahi is correct that the project only accepts PRs right now for TC39 proposals that are at Stage 0 or higher. There has been some discussion around a proposal on ESDiscuss, but nothing official yet.

It might be worth taking a look at Sweet.js, which lets you write hygienic macros for JavaScript.

@DrewML DrewML closed this as completed Oct 30, 2016
@kristofdegrave
Copy link
Author

@SerkanSipahi @DrewML Thanks for the feedback. Too bad it is not possible at the time, but let's hope it will come to es6 :). I'll leave the forks maybe sometime in the future they will become useable.

@SerkanSipahi
Copy link

@kristofdegrave "condition member access" is not part of es6.

@kristofdegrave
Copy link
Author

It looks like what I was trying to add is already a stage 1 proposal:
https://github.com/tc39/proposals under the name Null propagation. (https://github.com/tc39/proposals at the bottom)
Proposal: https://docs.google.com/presentation/d/11O_wIBBbZgE1bMVRJI8kGnmC6dWCBOwutbN9SWOK0fU/view#slide=id.p

Does this mean you can take this under consideration? If so can you let me know what the next steps should be for getting the PR merged?

@kristofdegrave kristofdegrave changed the title Conditional MemberAccess Conditional MemberAccess (Null propagation) Feb 11, 2017
@SerkanSipahi
Copy link

SerkanSipahi commented Feb 11, 2017

@kristofdegrave see #328 ! i think they are looking for someone who can implement that :)

@kristofdegrave
Copy link
Author

Nice, working on It. ;)

@SerkanSipahi
Copy link

@kristofdegrave :)

kristofdegrave pushed a commit to kristofdegrave/babylon that referenced this issue Feb 11, 2017
…member access. (.? or ?.[) If the object is undefined this will return undefined. If the object on which you want to access the property is defined, the value of the propery will be given back.
@agudovitoria
Copy link

Hi.
¿Has been this changes released on some version, or proposed for some version?

Thank you.

@babel babel locked and limited conversation to collaborators Mar 2, 2017
@hzoo
Copy link
Member

hzoo commented Mar 2, 2017

Check #328

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

No branches or pull requests

5 participants