acornjs / acorn-jsx

Alternative, faster React.js JSX parser
MIT License
648 stars 74 forks source link

`export default <Somejsx />` doesn't parse #25

Closed jmm closed 9 years ago

jmm commented 9 years ago

Sorry if I'm missing something obvious, but is there a reason this shouldn't parse?:

export default <Somejsx />;

This does:

export default (<Somejsx />);

Same result with acorn-jsx@2.0.0, with this of course:

{
  ecmaVersion: 6,
  sourceType: "module",
  plugins: {
    jsx: true
  }
}
RReverser commented 9 years ago

This is not related to acorn-jsx but an issue in Acorn itself, as it doesn't set exprAllowed = true after export default and thus cannot handle ambigous cases.

JSX tags are implemented in similar manner as regular expressions (both start with character that is usually tokenized as an operator), and thus it's the same bug - as you can try, export default /regex/ throws the same error in Acorn.

Please report to the upstream instead and I'll try to look into it when find some time (or you can try on your own).

jmm commented 9 years ago

Ah, ok, thanks. I didn't realize it was more general. Reported at https://github.com/marijnh/acorn/issues/283.

I'll try to look into it when find some time (or you can try on your own).

Thanks! And thanks for the pointers. I wanted to look into it, but my ability to debug is hampered right now by my node-inspector not working.