Skip to content

transform-react-constant-elements HOC params issue #5315

@GuillaumeCisco

Description

@GuillaumeCisco

Input Code

Declare a file where layout is created from elements

import LeftPart from './LeftPart';
import RightPart from './RightPart';
import CreateLayout from './createLayout';

export default CreateLayout([LeftPart, RightPart], 'tab title');

createLayout file

import React from 'react';
import OneComponent from './OneComponent';

const CreateLayoutHOC = (Components, title = '') =>
    props => <div>
        <OneComponent title={title}/>
        {Components.map((Component, i) =>
            <Component key={i} {...props} />,
        )}
    </div>;

export default CreateLayoutHOC;

Babel Configuration (.babelrc, package.json, cli command)

{
    "babel-cli": "6.23.0",
    "babel-core": "6.23.1",
    "babel-eslint": "7.1.1",
    "babel-loader": "6.3.1",
    "babel-plugin-add-module-exports": "0.2.1",
    "babel-plugin-date-fns": "0.1.0",
    "babel-plugin-lodash": "3.2.11",
    "babel-plugin-transform-react-constant-elements": "6.23.0",
    "babel-plugin-transform-react-inline-elements": "6.22.0",
    "babel-plugin-transform-react-remove-prop-types": "0.3.2",
    "babel-plugin-transform-runtime": "6.23.0",
    "babel-polyfill": "6.23.0",
    "babel-preset-es2015": "6.22.0",
    "babel-preset-react": "6.23.0",
    "babel-preset-stage-0": "6.22.0",
    "babel-register": "6.23.0",
    "babel-runtime": "6.23.0",
}

Current Behavior

Get an error: ReferenceError: _ref is not defined

Possible Solution

Replace <OneComponent title={title} /> by <OneComponent {...{title}} />
Looks like the param from the HOC component makes it bug.
If replacing <OneComponent title={title} /> by <OneComponent title={'a string'} /> works as expected, but I'd like to use params from closure context.

Context

Broke prod, was really hard to debug.

Your Environment

software version
Babel 6.23.0
node 7.4.0
npm 4.0.5
OS Linux

Metadata

Metadata

Assignees

Labels

Has PRarea: reactoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions