2

so I was working with an iterator inside a service with Ember. The code worked using the old style scripts I cannot use the ES2015 style

ReferenceError: regeneratorRuntime is not defined

    stuff[Symbol.iterator] = function *(){
        debugger;
        let properties = Object.keys(this);
        for(let p of properties){
            yield this[p];
        }
    };

I know this is because of the new '*' operator on the function. I have seen answers https://stackoverflow.com/a/28978619/24862 that describe having to load a browser-polyfill npm but I'm a little unclear how to get this to work inside the ember framework. Has anyone done this successfully? or should I just abandon until Ember supports it.

Community
  • 1
  • 1
hal9000
  • 823
  • 10
  • 23
  • Are you talking about ember-cli? Ember itself wouldn't have any issue with a language level syntax. – Kingpin2k Jan 02 '16 at 02:50
  • yes, sorry. I am using Ember-Cli and the code is inside a Controller or Conponent... to be honest I was copying some code in from another ES2015 test project. I can understand certain functionality not being available but since I never saw a listing I just assumed if the browser does, Ember-Cli would. – hal9000 Jan 06 '16 at 15:37

2 Answers2

4

Polyfill

Babel comes with a polyfill that includes a custom regenerator runtime and core-js. Many transformations will work without it, but for full support you may need to include the polyfill in your app.

You should now include as ember-cli-babel and not as babel. Like this:

var app = new EmberApp(defaults, {
    'ember-cli-babel': {
        includePolyfill: true
    }
}

Regenerator:

This package implements a fully-functional source transformation that takes the syntax for generators/yield from ECMAScript 2015 or ES2015 and Asynchronous Iteration proposal and spits out efficient JS-of-today (ES5) that behaves the same way.

Sources: https://github.com/babel/ember-cli-babel and https://github.com/facebook/regenerator

Community
  • 1
  • 1
renno
  • 2,659
  • 2
  • 27
  • 58
2

Perhaps your use of Babel.js needs to include the polyfill, in your ember-cli-build.js file use:

  var app = new EmberApp(defaults, {
    // Add options here
    babel: {
      includePolyfill: true
    }
  });
pixelhandler
  • 615
  • 4
  • 11
  • I'm not totally sure this will work, as I am 6 months further down the pipeline for this project... however since you took the time to answer it. Might as well get it off the un-answered list. – hal9000 Jun 12 '16 at 02:53