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

React inline elements transform error for namespaced JSX components using named import (T7021) #4027

Closed
babel-bot opened this issue Jan 22, 2016 · 1 comment
Labels
area: react i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@babel-bot
Copy link
Collaborator

Issue originally made by @mavisd

Bug information

  • Babel version: 6.4.5
  • Node version: 5.5.0
  • npm version: 3.3.12

Options

.babelrc

{
    "presets": ["es2015", "react"],
    "plugins": ["transform-react-inline-elements"]
}

Input code

//export.js file
function TestComponent() {
    return null;
}

export const form = {
    TestComponent
};
//index.js file
import { form } from './export';

function ParentComponent() {
    return <form.TestComponent />;
}
//babel output for index.js file with transform-react-inline-elements plugin
'use strict';

var _jsx = function () { var REACT_ELEMENT_TYPE = typeof Symbol === "function" && Symbol.for && Symbol.for("react.element") || 0xeac7; return function createRawReactElement(type, props, key, children) { var defaultProps = type && type.defaultProps; var childrenLength = arguments.length - 3; if (!props && childrenLength !== 0) { props = {}; } if (props && defaultProps) { for (var propName in defaultProps) { if (props[propName] === void 0) { props[propName] = defaultProps[propName]; } } } else if (!props) { props = defaultProps || {}; } if (childrenLength === 1) { props.children = children; } else if (childrenLength > 1) { var childArray = Array(childrenLength); for (var i = 0; i < childrenLength; i++) { childArray[i] = arguments[i + 3]; } props.children = childArray; } return { $$typeof: REACT_ELEMENT_TYPE, type: type, key: key === undefined ? null : '' + key, ref: null, props: props, _owner: null }; }; }();

var _export = require('./export');

function ParentComponent() {
    return _jsx(form.TestComponent, {});
}
//babel output for index.js file **without** transform-react-inline-elements
'use strict';

var _export = require('./export');

function ParentComponent() {
    return React.createElement(_export.form.TestComponent, null);
}

Description

When using the React inline elements transform, a namespaced JSX component from a named import is transformed incorrectly. It drops the root import alias name (_export in this case) and leaves only the named import part (form in this case) without reference to the actual import alias, causing a ReferenceError.

@DrewML
Copy link
Member

DrewML commented Oct 23, 2016

@mavisd thanks for the report!

I'm a bit on the fence about how this should work.

For context, the reason this is not working for you is because the form identifier is lowercase. If you were to change the import in index.js to import { form as Form } from './export';, your code would work as expected.

The bug fix here from June of last year is what leads to this behavior. The issue for this change makes mention of this gist that specifies that all lowercase identifiers in JSX should be treated as an HTML tag, and not a custom component. However, it does not specify the proper handling for that in the case of a JSXMemberExpression.

Edit: Thinking about this more, it doesn't make sense to ever treat a JSXMemberExpression as an HTML tag. Will have a PR with a fix in shortly.

@hzoo hzoo closed this as completed in 555ee0c Oct 24, 2016
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 6, 2018
@lock lock bot locked as resolved and limited conversation to collaborators May 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: react i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

3 participants