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

Adding defineEnumerableProperties to packager babelHelpers #12702

Closed
sonaye opened this issue Mar 4, 2017 · 2 comments
Closed

Adding defineEnumerableProperties to packager babelHelpers #12702

sonaye opened this issue Mar 4, 2017 · 2 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@sonaye
Copy link
Contributor

sonaye commented Mar 4, 2017

While working on a certain state management use case mobxjs/mobx#839, i had an issue getting it to work specifically with react native. After some digging, i now understand that the react native packager uses some custom babel helpers, which can be found here facebook/react-native/packager/src/Resolver/polyfills/babelHelpers.js.

It appears that the helper needed to run my code defineEnumerableProperties is currently missing from the list. The helper definition as provided from babel can be found here babel/babel/packages/babel-helpers/src/helpers.js, a small utility.

Adding it locally to the helpers indeed fixed the issue and all is working great now.

babelHelpers.defineEnumerableProperties = function(obj, descs) {
  for (var key in descs) {
    var desc = descs[key];
    desc.configurable = (desc.enumerable = true);
    if ('value' in desc) desc.writable = true;
    Object.defineProperty(obj, key, desc);
  }
  return obj;
};

I guess the question now, how can i add this custom helper and utilize it within react native, is it possible to achieve this with some sort of babel plugin? or would modifying the list of the helpers be the way to go? i will submit a pull request along with this issue detailing the modification needed.

I am using react native on top of exponent, which means that the support needs to come from here in order for it to actually get there in one of their future sdk releases.

@sonaye
Copy link
Contributor Author

sonaye commented Mar 5, 2017

any comments on this @skevy?

@ericvicenti
Copy link
Contributor

I'm landing the PR now, which will probably go smoothly

facebook-github-bot pushed a commit that referenced this issue Mar 7, 2017
Summary:
**Motivation**
detailed in #12702.

**Test plan**
1) running [a piece of code](mobxjs/mobx#839 (comment)) that utilizes the helper without any modifications on the react native package results an error being thrown.

![b589a71c-0041-11e7-9d47-cb79efff3ba5](https://cloud.githubusercontent.com/assets/23000873/23579517/3c8fe992-0100-11e7-9eb5-93c47f3df3e0.png)

2) updating the list of helpers available by adding the definition of `defineEnumerableProperties` as provided by babel [babel/babel/packages/babel-helpers/src/helpers.js](https://github.com/babel/babel/blob/master/packages/babel-helpers/src/helpers.js#L275-L285) results no errors.

![kapture 2017-03-04 at 16 48 35](https://cloud.githubusercontent.com/assets/23000873/23579520/457b8ca0-0100-11e7-8ca4-c704c6e9631f.gif)
Closes #12703

Differential Revision: D4658120

Pulled By: ericvicenti

fbshipit-source-id: 914aed4d313b3cc4f7ab99049d05d0aef269a3be
jaredru pushed a commit to Remitly/react-native that referenced this issue May 9, 2017
Summary:
**Motivation**
detailed in facebook#12702.

**Test plan**
1) running [a piece of code](mobxjs/mobx#839 (comment)) that utilizes the helper without any modifications on the react native package results an error being thrown.

![b589a71c-0041-11e7-9d47-cb79efff3ba5](https://cloud.githubusercontent.com/assets/23000873/23579517/3c8fe992-0100-11e7-9eb5-93c47f3df3e0.png)

2) updating the list of helpers available by adding the definition of `defineEnumerableProperties` as provided by babel [babel/babel/packages/babel-helpers/src/helpers.js](https://github.com/babel/babel/blob/master/packages/babel-helpers/src/helpers.js#L275-L285) results no errors.

![kapture 2017-03-04 at 16 48 35](https://cloud.githubusercontent.com/assets/23000873/23579520/457b8ca0-0100-11e7-8ca4-c704c6e9631f.gif)
Closes facebook#12703

Differential Revision: D4658120

Pulled By: ericvicenti

fbshipit-source-id: 914aed4d313b3cc4f7ab99049d05d0aef269a3be
@facebook facebook locked as resolved and limited conversation to collaborators May 24, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

3 participants