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

Arrow syntax missing a closure in ES5 #9408

Closed
texastoland opened this issue Jun 29, 2016 · 6 comments
Closed

Arrow syntax missing a closure in ES5 #9408

texastoland opened this issue Jun 29, 2016 · 6 comments

Comments

@texastoland
Copy link
Contributor

texastoland commented Jun 29, 2016

TypeScript Version: 1.8.0 / nightly (2.0.0-dev.20160628)

I'm currently using async in ES5 from the compiler service (similar to #1564 (comment)) via Regenerator. Could #7706 be fixed since it's on the 2.0 roadmap?

Code

async () => aPromise

ES2015:

(() => __awaiter(this, void 0, void 0, function* () { return aPromise; }));

Actual ES5:

(function () __awaiter(this, void 0, void 0, function* () { return aPromise; }));
//           ^ syntax error

Expected ES5:

(function () { return __awaiter(this, void 0, void 0, function* () { return aPromise; }); });

CC @spicydonuts

@yortus
Copy link
Contributor

yortus commented Jun 30, 2016

Looks like #7334, which is fixed in typescript@next.

@texastoland
Copy link
Contributor Author

texastoland commented Jun 30, 2016

TypeScript Version: 1.8.0 / nightly (2.0.0-dev.20160628)

^ I've been using nightlies the entire time and verified it with the above build. The diagnostic message is working but I'm ignoring it because support is on the roadmap. Would it be fixed another way?

@yortus
Copy link
Contributor

yortus commented Jun 30, 2016

With the currently nightly, if your target is ES5, then the expression async () => aPromise should give you a compile-time error (Async functions are only available when tyargering ES2015 or higher). Are you getting this error?

The bug in v1.8 was not the invalid emitted code, it was the lack of error message. v1.8 didn't support async in ES5, but it didn't produce an error message if the async function was a function expression, as it is in your example here.

@texastoland
Copy link
Contributor Author

texastoland commented Jun 30, 2016

Yes the diagnostic message is working but the 2.0 roadmap indicates planned support in #1564. I assume there's a bigger architectural theme but I've been using Regenerator with async function () {} (non arrow) syntax. I thought the missing closure might be a legitimate bug?

@yortus
Copy link
Contributor

yortus commented Jun 30, 2016

Yeah, I'd say the current emit is not a bug since there are no guarantees about emitted code when there are compile errors.

The v2.0 milestone is currently at 96% completion, so if you wait a little longer you'll be able to target ES5 and get valid emitted code. However it won't look much like your Expected ES5 code above since that contains an ES6 generator function. I expect it will look something like the output you currently get from regenerator (ie a function implementing a state machine).

@texastoland
Copy link
Contributor Author

texastoland commented Jun 30, 2016

Okay I understood that's the probable resolution. When I set up our build a few months ago I was silencing several diagnostics and you've already made all the rest work. Thanks!

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants