ember-script icon indicating copy to clipboard operation
ember-script copied to clipboard

EmberCLI and ES6 Support

Open alem0lars opened this issue 10 years ago • 7 comments

If I try to use ember script with EmberCLI (which uses ES6 style import modules) it doesn't work anymore (e.g. with EmberCLI 0.37).

This problem is always reproducible when using ES6 because of the lack of global namespaces. Now Ember is not globally available so I have to import it (import Ember from "ember").

The problem is that the substitution of import Ember from "ember" is after the generated getters and setters generated lines, so I always get the TypeError: undefined Ember in any project using both EmberScript and ES6.

I think that the problem is more generic because somehow the EmberScript compiler is twisting the rows (which is generally bad). As a programmer if I write

`import Ember from "ember"`
class IndexRoute extends Ember.Route

I expect that the import thing happens before the class definition thing.

Instead, this is what has been generated:

var IndexRoute;
var get$ = Ember.get;
var set$ = Ember.set;
import Ember from "ember";
IndexRoute = Ember.Route.extend();
export default IndexRoute;

As you can see the fourth line should happen before to the first three lines, in order to have the same semantics has the EmberScript defined code.

alem0lars avatar Jun 28 '14 08:06 alem0lars

Yeah that's why there is #42

huafu avatar Jul 05 '14 06:07 huafu

honestly doing:

var get$ = Ember.get;
var set$ = Ember.set;

would break bindings in cycle situations anyways, so i would discourage the re-aliasing, once full es6 syntax is supported + ember finally finishes that migration we will have.

import { get, set } from 'ember/accessors';`

no need to re-alias, and cycle safe bindings are preserved.

stefanpenner avatar Jul 12 '14 21:07 stefanpenner

:+1:

kristianmandrup avatar Aug 30 '14 10:08 kristianmandrup

So, is this safe to use with ember-cli 0.40 or will it break?

NedgoIO avatar Sep 09 '14 23:09 NedgoIO

I think we should motivate/encourage @ghempton to make a new release that fixes this and other blocking issues. Until such fixes are made, I don't think it will work for the latest ember/cli releases.

kristianmandrup avatar Sep 10 '14 12:09 kristianmandrup

Fixed and tested here ;)

https://github.com/ghempton/ember-script/pull/49

With room for improvements...

kristianmandrup avatar Sep 20 '14 11:09 kristianmandrup

What's the status on this one? Should we use @kristianmandrup's PR? Or is there another way to fix this?

mszoernyi avatar Nov 25 '14 16:11 mszoernyi