coffee-react-transform
coffee-react-transform copied to clipboard
Unexpected indentation with newline delimited attributes
If I have JSX that looks like:
<Foo
className="Foo">
<Bar
className="Bar">
{expr}
</Bar>
</Foo>
This gets compiled to:
React.createElement(Foo, { \
"className": "Foo"},
React.createElement(Bar, { \
"className": "Bar"},
(expr)
)
)
CoffeeScript chokes on this input, claiming unexpected indentation
. Strangely, if I remove either of the backslashes (or put the attributes on the same line, which makes the transform produce equivalent code), it works without a problem.
Try to keep your closing brackets in line with your opening ones. I want to remove this limitation in future but it's a big piece of work
Ah I see. Forgive my ignorance but is there a specific reason why the newlines aren't simply stripped? This was the implicit behaviour I was expecting before I actually looked into what the output looked like.
For example:
<Foo
className="Foo">
<Bar
className="Bar">
{expr}
</Bar>
</Foo>
would be converted to
React.createElement(Foo, {"className": "Foo"},
React.createElement(Bar, {"className": "Bar"},
(expr)
)
)
As I haven't implemented source maps yet, the temporary (but long standing) solution was to make sure the input lines had 1 to 1 parity with output lines.
Fair enough. I don't really use source maps since the transformation is pretty trivial to work backwards to the offending line, but I can see the reasoning.
Perhaps in the short term a --ugly
could be introduced to explicitly opt into a more permissive parsing mode provided that the output doesn't need to match 1 to 1?