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

Can I use this with ES6 modules?

Open sferoze opened this issue 8 years ago • 3 comments

I really want to use coffeescript again but I am using the modules beta dev of Meteor.

This means I can import pacakges and such.

But I am not sure if it will work with coffeescript.

Any idea?

sferoze avatar Feb 27 '16 00:02 sferoze

coffee-react-transform won't be any different to normal coffeescript. I'm not sure how the Meteor modules support works, but basically you need to figure out what ES5 javascript code Meteor converts the ES6 import statement into and just write that in coffeescript. Eg. if it's like babel, it will basically convert an import statement into a require() statement.

jsdf avatar Apr 16 '16 23:04 jsdf

I am in a similar situation and was wondering if there is a feasible way out... I am backticking my ES6 import and export statements in my CoffeeScript, which SystemJS later picks up and does its magic with. I am running into an issue of: Got an unexpected exception from the coffee-script compiler. The original exception was: Error: Parse Error: Line 1: Illegal import declaration, supposedly because the React transformer doesn't know how to deal with ES6 Module syntax. Is there some option I can pass that allows the ES6 import and export statements? I did some digging and didn't come up with anything :/ Example code:

`import BaseComponent from 'base_component.js'`

class Header extends BaseComponent
  @propTypes:
    username : React.PropTypes.string
    ...

  constructor: (props) ->
    super
    ...

`export default Header`

Hate to make it seem like I am asking you to do my work for me, I just feel that you are the most qualified person to answer such questions! Thanks!

jeffmicklos avatar Apr 22 '16 20:04 jeffmicklos

coffee-react-transform will leave these statements untouched. coffee-script will also just pass them straight through. What will process the es6 import syntax? No browser supports it natively yet. Have you configured SystemJS to know that it needs to apply ES6 transpilation (eg. babel or traceur) to the output of the coffee-script compiler? SystemJS itself doesn't understand ES6 import/export syntax directly, it first runs a transpiler and then whatever that outputs in place of import/export is what it understands at runtime. You could configure SystemJS to apply babel processing to the output of coffeescript. Regardless, coffee-react-transform will have no impact on this.

jsdf avatar Apr 22 '16 22:04 jsdf