Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

JSX in function results in Unexpected JSXIdentifier #158

Closed
radekmie opened this issue Sep 12, 2016 · 4 comments
Closed

JSX in function results in Unexpected JSXIdentifier #158

radekmie opened this issue Sep 12, 2016 · 4 comments

Comments

@radekmie
Copy link

This code:

const X = x();
<X />

Is correctly minified to:

"use strict";var X=x();React.createElement(X,null);

This code:

const render = () => {
    const X = x();

    return (
        <X />
    );
}

Results with:

Unexpected JSXIdentifier. Expected an Identifier

This occurs in Babel REPL - when I used CLI, I've received minified version of something like this:

const a = () => {  // minified name - OK
    const b = x(); // minified name - OK

    return (
        <X /> // oops!
    );
}
@boopathi
Copy link
Member

boopathi commented Sep 12, 2016

The first one works because it is in the global scope and is not mangled.

I'm not sure why that errors in REPL.

For the last case, consider this workaround for now - use passPerPreset=true option when using with react preset. Have to debug why mangler skips that path after transforming to React.createElement.

@radekmie
Copy link
Author

radekmie commented Sep 13, 2016

The first one works because it is in the global scope and is not mangled.

Good to know.

For the last case, consider this workaround for now - use passPerPreset=true option when using with react preset. Have to debug why mangler skips that path after transforming to React.createElement.

I'm using babel-preset-babili ("presets": ["babili", ...]) - how can I pass this option?

EDIT: OK, found it. I'll try it later today and let you know.
EDIT 2: I've tried it - same error.

@boopathi
Copy link
Member

console.log(require('babel-core').transform(`
const render = () => {
  const Foo = x();
  return <Foo/>;
}`, {
  presets: ['react', 'babili'],
  passPerPreset: true
}).code);

And I get the output

const render = () => {
    const a = x();
    return React.createElement(a, null);
};

@radekmie
Copy link
Author

OK, maybe I mistyped passPerPreset or something.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants