coffee-react-transform icon indicating copy to clipboard operation
coffee-react-transform copied to clipboard

Spread operator doesn't evaluate internals

Open ElliotChong opened this issue 9 years ago • 1 comments

As per CoffeeScript's default behavior of evaluating statements, I was surprised to find that the following statements within a spread operator result in the CJSX error: SyntaxError: Unexpected end of input: unclosed CJSX_EL

render: ->
  <SomeComponent {...{foo: "bar"}}/>
render: ->
  foo = "bar"
  <SomeComponent {...{foo}}/>
render: ->
  foo = "bar"
  <SomeComponent {...({foo})}/>
render: ->
  foo = "bar"
  <SomeComponent {...(do -> {foo})}/>

Expected output is for a structured assignment of { foo: foo } and passing that result to the spread method.

ElliotChong avatar Apr 22 '16 06:04 ElliotChong

I've started work on a fix for #73, #62, and #39 @ https://github.com/ElliotChong/coffee-react-transform/commits/patch-1

It passes all existing tests and it should fix #62 and #39; however, I'm having some trouble with the assignment requirement outlined in this issue (#73).

It seems like the closing curly brace in structured assignment / Object creation isn't being output... I'm wondering if there's some code that might be de-duplicating curly braces that are back to back?

Test Case:

##desc
self closing tag with spread attribute with object creation
##input
<Component a={b} {... { d: "e" } } b="c" />
##expected
React.createElement(Component, React.__spread({"a": (b)},  {"d": "e"} , {"b": "c"}))
##end

Output:

Error: compile error in testcase: self closing tag with spread attribute with object creation

React.createElement(Component, React.__spread({"a": (b)},  { d: "e" , {"b": "c"}))

Test Case:

##desc
self closing spread attribute on next line with object creation
##input
<Component
  a="b"
  c="d"
  {...{ e: "f"}}

/>
##expected
React.createElement(Component, React.__spread({ \
  "a": "b",  \
  "c": "d"
  }, { e: "f"}

))
##end

Output:

Error: compile error in testcase: self closing spread attribute on next line with object creation

React.createElement(Component, React.__spread({ \
  "a": "b",  \
  "c": "d"
  }, ({ e: "f"



))

@jsdf Any thoughts on why that closing curly brace isn't appearing?

ElliotChong avatar Apr 22 '16 06:04 ElliotChong