Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async/await #105

Closed
jaydson opened this issue Jan 21, 2015 · 14 comments
Closed

async/await #105

jaydson opened this issue Jan 21, 2015 · 14 comments

Comments

@jaydson
Copy link
Contributor

jaydson commented Jan 21, 2015

I'm trying to use async/await(es7) (experimental feature in 6to5) but i'm not sure gulp-6to5 is working.
I've changed build.js file:

    config: {
        jscs: { configPath: '.jscsrc', esnext: true },
        '6to5': { blacklist: ['generators'], experimental: true },
        mocha: { bail: true, timeout: 5000 }
    }

My sample code:

async function test() {
    let x = await Promise.resolve();
}

And i get the following error:
events.js:85 throw er; // Unhandled 'error' event ^ /home/jaydson/Workspace/harmonic/dist/bin/parser.js:19 async function test() { ^^^^^^^^ SyntaxError: Unexpected token function
The async function is not being transpiled.

Any thoughts @UltCombo ?

@jaydson
Copy link
Contributor Author

jaydson commented Jan 21, 2015

I found the issue.
It seems like the config property 6to5 in build.js is being ignored.
I changed the gulpfile to this:

.pipe(plugins['6to5'], { experimental: true })

instead of this:

.pipe(plugins['6to5'], build.config['6to5'])

and it works.

Probably the blacklisted generators never were blacklisted until now.

@UltCombo
Copy link
Member

Probably the blacklisted generators never were blacklisted until now.

Weird. I'm pretty sure co-prompt was throwing errors when we transpiled generators.

It looks like the async functions transform converts them to generators, so the async functions transform doesn't work/is ignored when we blacklist generators. I believe this makes sense, anyway, @sebmck can you confirm?

@jaydson change the build.js to remove generators from the blacklist and enable the experimental option:

'6to5': { experimental: true },

Does this work?

@UltCombo
Copy link
Member

If that's the issue, then we can replace co-prompt with Inquirer (#68) then remove generators from the blacklist and use async functions. 😄

@sebmck
Copy link

sebmck commented Jan 21, 2015

Async functions and generators are transformed in the same transformer (it's delegated to regenerator). It's confusing I know but since 3.0.0 is going to include a regenerator fork it'll allow it to be split up into multiple transformers.

@UltCombo
Copy link
Member

@sebmck oh nice! Thanks for the clarification. 😄

@jaydson
Copy link
Contributor Author

jaydson commented Jan 21, 2015

@UltCombo both '6to5': { experimental: true } and '6to5': { blacklist: ['generators'], experimental: true } works in the same way.

@UltCombo
Copy link
Member

@jaydson I believe blacklist: ['generators'] disables the async transform as @sebmck explained.

Doesn't '6to5': { experimental: true } work? It fails to transpile async functions or throws some specific error?

@jaydson
Copy link
Contributor Author

jaydson commented Jan 21, 2015

Oh, now i got it.
'6to5': { experimental: true } works (transpile async functions).
We can remove generators from the blacklist :)

@UltCombo
Copy link
Member

Oh nice. :)

Btw, the whole idea behind the build.js file is to have project-specific settings outside of the gulpfile, so that whenever we update the gulpfile we can seamlessly copy it to the slush-es6 repository forth and back. This way we can pull updates from slush-es6 by simply copying the files over.

Of course, in the future Harmonic may need a more complex gulpfile than slush-es6's, but for the time being this workflow has been working nicely. 😃

@UltCombo
Copy link
Member

@jaydson also, please test harmonic init� before committing the changes.

IIRC, co-prompt was throwing an error when we passed a transpiled generator to it.

As we've discussed earlier, we can't transpile generators with regenerator as co and co-* libs are not transpiled (they work with native generators only). So I guess we have to drop the co dependency(ies) before un-blacklisting generators.

@UltCombo
Copy link
Member

There's probably regenerator'ed versions of co out there, but if we're using it only for the CLI input we can easily replace it with Inquirer and drop co. What do you think?

@jaydson
Copy link
Contributor Author

jaydson commented Jan 23, 2015

I think we can replace co and focus on async/await.

Weird thing is i've tested harmonic init and it worked well. I'm probably missing something.

@UltCombo
Copy link
Member

@jaydson perhaps it was an issue with one of our dependencies that got fixed. Never mind it if it is working as expected for you. :D

focus on async/await

👍

@jaydson
Copy link
Contributor Author

jaydson commented May 3, 2015

We're already using async functions yay!
c4bb69d

@jaydson jaydson closed this as completed May 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants