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

transform-react-constant-elements does not transform all hoisted `_react` references #10878

Open
GoodForOneFare opened this issue Dec 17, 2019 · 1 comment

Comments

@GoodForOneFare
Copy link

@GoodForOneFare GoodForOneFare commented Dec 17, 2019

Bug Report

Current Behavior
transform-react-constant-elements can generate unrunnable code if two functional components are defined, and the first component renders the second component.

Note: this only affects preset-env + transform-react-jsx + transform-react-constant-elements configs.

The last line of this simplified output shows the bug:

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

function Foo() {
  return _ref;
}

var _ref2 =
/*#__PURE__*/
_react["default"].createElement("div", null);

function Bar() {
  return _ref2;
}

var _ref =
/*#__PURE__*/
React.createElement(Bar, null); // <---- BUG!  This should be _react.createElement

Input Code

Expected behavior/code
When preset-env has renamed React to _react, all references should be updated to _react.

Babel Configuration

{
  "presets": ["@babel/preset-env"],
  "plugins": ["transform-react-jsx", "transform-react-constant-elements"]
}

Environment

  System:
    OS: macOS 10.15.2
  Binaries:
    Node: 12.10.0 - /usr/local/bin/node
    Yarn: 1.12.3 - ~/.dev/yarn/1.12.3/bin/yarn
    npm: 6.11.3 - /usr/local/bin/npm
  Monorepos:
    Lerna: 3.19.0
  npmPackages:
    @babel/cli: ^7.7.0 => 7.7.5
    @babel/core: ^7.7.2 => 7.7.5
    @babel/eslint-plugin-development: ^1.0.1 => 1.0.1
    @babel/plugin-proposal-class-properties: ^7.7.0 => 7.7.4
    @babel/plugin-proposal-export-namespace-from: ^7.5.2 => 7.7.4
    @babel/plugin-proposal-nullish-coalescing-operator: ^7.4.4 => 7.7.4
    @babel/plugin-proposal-numeric-separator: ^7.2.0 => 7.7.4
    @babel/plugin-proposal-object-rest-spread: ^7.7.4 => 7.7.4
    @babel/plugin-proposal-optional-chaining: ^7.6.0 => 7.7.5
    @babel/plugin-transform-flow-strip-types: ^7.7.4 => 7.7.4
    @babel/plugin-transform-for-of: ^7.7.4 => 7.7.4
    @babel/plugin-transform-modules-commonjs: ^7.7.0 => 7.7.5
    @babel/plugin-transform-runtime: ^7.6.2 => 7.7.6
    @babel/preset-env: ^7.7.1 => 7.7.6
    @babel/preset-flow: ^7.0.0 => 7.7.4
    @babel/register: ^7.7.0 => 7.7.4
    @babel/runtime: ^7.7.2 => 7.7.6
    babel-eslint: ^11.0.0-beta.2 => 11.0.0-beta.2
    babel-jest: ^24.9.0 => 24.9.0
    babel-plugin-transform-charcodes: ^0.2.0 => 0.2.0
    eslint: ^6.0.1 => 6.7.2
    eslint-config-babel: ^9.0.0 => 9.0.0
    gulp-babel: ^8.0.0 => 8.0.0
    jest: ^24.9.0 => 24.9.0
    lerna: ^3.19.0 => 3.19.0
    rollup-plugin-babel: ^4.0.0 => 4.3.3
  • Monorepo: Lerna
  • How you are using Babel: webpack loader
@babel-bot

This comment has been minimized.

Copy link
Collaborator

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

Hey @GoodForOneFare! 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."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.