thlorenz/es6ify

Omit a feature to use native instead

Closed this issue · 6 comments

I'm trying to use the generators built into Chrome instead of the Traceur version, so I used the es6ify.traceurOverrides = { generators: false }, but it's now failing to even compile my files with generators such as the below:

function* getPage() {
  return new Promise(function (resolve, reject) {
    resolve('My great content!');
 });
}

The error might be useful...

[Error: /Users/simovate/Documents/current/playground/client/main.js:25:9: 'identifier' expected]

stream.js:94
      throw er; // Unhandled stream error in pipe.
            ^
Error: /Users/simovate/Documents/current/playground/client/main.js:25:9: 'identifier' expected
    at compileFile (/Users/simovate/Documents/current/playground/node_modules/es6ify/index.js:32:29)
    at Stream.end (/Users/simovate/Documents/current/playground/node_modules/es6ify/index.js:85:37)
    at _end (/Users/simovate/Documents/current/playground/node_modules/es6ify/node_modules/through/index.js:61:9)
    at Stream.stream.end (/Users/simovate/Documents/current/playground/node_modules/es6ify/node_modules/through/index.js:70:5)
    at f (/Users/simovate/Documents/current/playground/node_modules/browserify/node_modules/module-deps/index.js:224:19)
    at makeTransform (/Users/simovate/Documents/current/playground/node_modules/browserify/node_modules/module-deps/index.js:290:20)
    at ap (/Users/simovate/Documents/current/playground/node_modules/browserify/node_modules/module-deps/index.js:209:13)
    at applyTransforms (/Users/simovate/Documents/current/playground/node_modules/browserify/node_modules/module-deps/index.js:226:11)
    at /Users/simovate/Documents/current/playground/node_modules/browserify/node_modules/module-deps/index.js:172:17
    at fs.js:258:14    

That's an interesting problem. I'm not sure how it could be solved.
The gist is this:

  • you turn off generator support -> traceur fails since it encounters something you told it to not support when you transpile the file
  • you turn it on -> they get transpiled instead of using native generators

Seems like traceur should provide an option to omit some features from being transpiled, but to support them in the sense that it understands what they are in order to skip them.

Therefore I'd suggest you'll take this issue to the traceur team, I think it is a very valid use case and most likely others will run into it soon.

As a temporary workaround you could put code that uses generators into separate modules and name them similarly, i.e. do-x-gen.js do-y-gen.js. Of course no other ES6 code can be in there, since you'll exclude them from transpiling (see below).

Then you could use es6ify.configure to exclude these files from being transpiled.
For the above example you'd do something similar to es6.configure(/^(?!.*-gen)\.js$/).

I know this is a hack, but could work for you until traceur adds the feature you need.

Also please lmk once traceur adds that feature, so I can expose it via es6ify.

Thanks.

Will do, thanks.

So it is supported, instead of generators: false, just use generators: 'parse' and you should be golden.

Wow that's good news, we need to document that.
If you don't mind, could you add a note about that to the traceur overrides example?

I'll update the jsdoc as well in order to make users aware of that.

Sure, I'll send a PR tonight.
On Apr 1, 2014 12:04 PM, "Thorsten Lorenz" notifications@github.com wrote:

Wow that's good news, we need to document that.
If you don't mind, could you add a note about that to the traceur
overrides example https://github.com/thlorenz/es6ify#examples?

I'll update the jsdoc as well in order to make users aware of that.

Reply to this email directly or view it on GitHubhttps://github.com//issues/22#issuecomment-39223783
.