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

@babel/plugin-transform-react-constant-elements is not create _ref for component in case of using object destructuring syntax #10879

Open
Mrdev1ce opened this issue Dec 17, 2019 · 2 comments
Labels

Comments

@Mrdev1ce
Copy link

@Mrdev1ce Mrdev1ce commented Dec 17, 2019

Bug Report

Current Behavior
@babel/plugin-transform-react-constant-elements is not create _ref for component in case of using object destructuring syntax.
As you can see in example - _ref variable was used, but it was not defined.

Input Code

Input:

import React from 'react';

const namespace = {
  MyComponent: (props) => props.name
};
const buildTest = (name) => {
  const {MyComponent} = namespace;
  return () => (
    <MyComponent name={name} />
  );
}

Output:

"use strict";

var _react = _interopRequireDefault(require("react"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var namespace = {
  MyComponent: function MyComponent(props) {
    return props.name;
  }
};

var buildTest = function buildTest(name) {
  var MyComponent = namespace.MyComponent;
  return function () {
    return _ref;
  };
};

Expected behavior/code
_ref variable should be created.

Expected output:

"use strict";

var _react = _interopRequireDefault(require("react"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var namespace = {
  MyComponent: function MyComponent(props) {
    return props.name;
  }
};

var buildTest = function buildTest(name) {
  var MyComponent = namespace.MyComponent,
      _ref =
  /*#__PURE__*/
  _react.default.createElement(MyComponent, {
    name: name
  });

  return function () {
    return _ref;
  };
};

But it's still possible to achieve expected behavior if don't use destructuring syntax.

Edits by @JLHwung : simplified the REPL setup.

@babel-bot

This comment has been minimized.

Copy link
Collaborator

@babel-bot babel-bot commented Dec 17, 2019

Hey @Mrdev1ce! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."

@JLHwung JLHwung added area: jsx and removed i: needs triage labels Dec 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.