jsdf / coffee-react-transform

DEPRECATED – Provides React JSX support for Coffeescript
MIT License
433 stars 58 forks source link

Comments in multiline JSX tags are parsed wrongly #38

Closed NotBobTheBuilder closed 9 years ago

NotBobTheBuilder commented 9 years ago

In the code

<foo>
  <bar />
  # <baz /> leaving baz unimplemented
</foo>

I’d expect the comment to be ignored - instead, it seems to be parsed and placed into the function call, as follows:

React.createElement(foo, null,
  React.createElement(bar, null), """
  # """, React.createElement(baz, null), """ leaving baz unimplemented
""")

I’m assuming this is a bug, and I attached a failing test case.

jsdf commented 9 years ago

Not a bug. Anything within a JSX expression which is not a JSX tag becomes a text node. Thus the # becomes literal text, and is not interpreted as a comment.

Consider this JS equivalent compiled with the official JSX transformer:

<Foo>
  <Bar />
  // <Baz /> leaving baz unimplemented
</Foo>

becomes

React.createElement(Foo, null, 
  React.createElement(Bar, null), 
  "// ", React.createElement(Baz, null), " leaving baz unimplemented"
)
NotBobTheBuilder commented 9 years ago

Ah ok - if that’s upstream behaviour (which I find a bit weird, but hey ho) then following it seems like the right thing to do.

Thanks :)