-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Add ES2016 target #5361
Comments
I still think this is challenging and that a simple "es6/es2015" or "es7/es2016" target won't solve the challenges... It almost needs some sort of granular feature flag. I am not familiar with it, but how is Babel handling these sort of control of these emits? Also, is it a fair assumption at this point that an ES6+ feature ever be down emitted in ES6 as well as ES5/ES6? For something like exponation, the emit wouldn't change, but in theory if there was a down-emit for async to ES6, you could emit Promises but you couldn't do that to ES5. |
@kitsonk OK, I'm going on a tangent with respect to this ticket. The business of emiting JS for down-level browsers is a complex thing, which is mostly unrelated to the TypeScript language. On several aspects, Babel does a better job than TS at this. That's why some people pipe TS (for static typing) into Babel (for ES5 emit). Granularity is one example of this. Babel supports enabling/disabling any Transformer individually. That's why it is enough that TS passes through ES7 code, I can handle the granular transpiling with Babel. I don't mind TS supporting more emitting options (I think granularity is #4692), but letting the ES7 code passthrough is an easy step that supports such a workflow right now.
Not sure I got the point here. |
A real world use case for this would be the next major release of Koa.js which will natively support async/await in addition to the current generator syntax. While it works nicely with async functions transpiled by Babel it does not play well with the async functions transpiled by typescript (although I guess maybe that could be addressed separately). |
There are likely to be features introduce in ES7 and beyond that would be better to emit as ES6 when possible. For example you could use WeakMaps/Promises/Symbols to better polyfill functionality in ES6 which is likely more performant (and less likely to have unintended consequences). Even using Again, I don't see anyway of properly supporting it without some sort of micro-targeting. ES7/ES2016 will be a moving target for a long time. |
@kitsonk I may be misunderstanding you but I think Babel allows you to do exactly that. It gives you fairly granular control over what transforms and polyfills you use to emit code, so for example when targeting node >= 0.12 I can turn off the regenerator transform to take advantage of native generator support. |
@kitsonk exactly what @robotlovesyou said. Anyway, in the long run as browsers evolve we will not transpile code anymore so a ES2016 target is required, juste like an ES6 target was added back then. Another added benefit is that it enables TS team to add new features without downlevel support first (or ever... |
@robotlovesyou can you elaborate on the issue here? can we file another issue with more details? if it is not working we would love to know why and what can be done to fix it. |
We have discussed adding a |
@mhegazy I think TS is evolving along with ES specs. You support ES2016 proposals so I think it makes sense to have a ES2016 target. If a feature slips out of ES2016 -- e.g. Decorators -- I suggest you update the TS compiler to polyfill them in ES2016 and let them through in the ES2017 target. Indeed for people that want to always be on the bleeding edge, an |
I thought we were talking about TypeScript. The proposal was to add a new target to TypeScript. I am suggesting that @jods4 proposal over simplifies that problem and that something more is needed and that has additional considerations.
The challenge with that is one day you compile and you get passed through code, and the next day you get down emitted. 😦 |
I think the point is that there are different "problems" at hand, and this issue is not meant to solve your "problem". My problem is that I want to be able to get JS code without any transpiling at all. Today TS works with standards-based targets: ES3, ES5, ES6. Now that we start adding ES7 features we should add a matching target. It is the natural continuity of existing TS and makes perfect sense. I don't mind introducing more flexibility, but that's a different discussion.
Is it a challenge? If you say "I want to target ES7 compliant browsers" and decorators are not in the standard anymore, then it's as it should be. Given that ES7 is not finalized yet if you ask for such a target you should be ready for that. And "down emitted" code would actually still works. If you want stability target something stable, like ES5 or ES6. If you want the bleeding edge, I think we need a new |
I think that is the root of the problem... We are likely to be in a constant evolving situation, where browsers will likely ever be in a static situation where you can specifically target that browser. Kangax's compatibility tables demonstrate this clearly. The agreed standards are already a moving target and then the standards that aren't even close to being finalised. There will never be something as an "ES7 compliant browser". Likely TC39 will cut ES7 as whatever is agreed at a particular point in time and everything else gets rolled forward. Like |
Actually, most likely there will. It is my understanding that Edge was planned to be ES6-compliant this year and that FF and Chrome are working hard to follow suite as soon as possible. That's great news and it means we won't need polyfills for all this stuff in 2016 (if you can target the latest browsers only, of course). Something similar will happen for ES7,you just need to wait a little longer. Given the new TC39 yearly schedule, ES7 is ES2016 and it will be frozen next year. Give it one (or two?) years and you'll see ES2016 compliant browsers. And then we'll need a ES2017 target next year. |
+1 I am definitely for this proposal. I already pipeline typescript and babel but would like the option of just letting typescript handle types, and do the es7 to es5 transpilation in one step. |
+1 I was about to open the same issue and found this. At present there is no combination of compiler switches that allows ES7 |
TS 1.8 breaks bluebird usage (#6631 (comment)). So, I don't want to let TS transform async/await anymore — I want to use babel (http://babeljs.io/docs/plugins/transform-async-to-module-method/). So, ES7 target (do not transform async/await) is wanted. |
Hi @mhegazy, Given the final feature set of ES2016 has been agreed I wonder if you might look again at an ES2016 target? In the end it's only these that made the cut: I think you've already go the Exponentiation supported? |
Adding the ES2016 target should be a simple task. but i wounder if it will be of any value. most comments on this thread really wanted |
Personally, I think the ES2016 feature set is so minimal it's barely worth the effort. TypeScript already supports the exponent operator, and ESNext would be a good target to have, but what would it allow? Assuming async + await would end up there? Decorators? Bind operator? |
that is what we need to define. possibly anything that has a standards proposal even a stage 0 one. |
@jamiewinder @mhegazy I think what people who ask for Writing that out loud makes me wonder: maybe someone (could be community) could write a Babel plugin that removes the TS syntax? EDIT just realized it's not as easy as it may seem. Syntax can't be cleaned up without performing some semantic analysis. For instance you need to remove the interfaces... including in other modules where they might be imported. So it's not trivial. |
I figured you were going to add es2016 at some point. I just wondered if now would be sensible given the state of things. Perhaps I should have raised this separately. I'm using Babel for transpilation, I thought switching to the es2016 preset would be the smoothest upgrade if TypeScript supported that target also. |
@jods4 take a look at this: https://github.com/Microsoft/TypeScriptSamples/tree/master/es6-babel-react-flux-karma The point is you write es2015 TypeScript and Babel transpires it down to esOld. As a workflow it rocks. |
Yes, TS doesn't support granular target control and so we have to use babel. @johnnyreilly To keep away from gulp and use simple workflow (use only tsconfig and npm scripts), I have written ts-babel. |
I should note that granular transformation support is already tracked in #4692 |
@johnnyreilly I do this and I'm happy 😄 But it has limitations that annoy some people. For instance, currently TS always emits ES6 code for I personnally don't care but now that TS adheres to the current specifications of not using custom |
I did not know granular targeting was on the roadmap. Awesome! |
+1 |
Is there any way for async/await not to be transpiled already today? |
no |
Because the original issue is for an ES2016 target, I'm going to say an ESNext target should be discussed separately. |
👍 , TypeScript is basically unusable in my current Ember.js stack (which uses Babel) if I can't turn off async/await transpilation. |
+1 for a target of "esnext" (or maybe just "edge"), which just remove the typescript specific things (types/enums/namespaces/etc..) |
For those of you who use Babel, I have written a Babel plugin native-async-for-typescript, which reverts the TypeScript async/await transpilation back to your original |
Another reason for adding ES7/ES8 transpile "support" in TypeScript is that it could enable es2016.d.ts and es2017.d.ts automatically. What's the best practice on including these definitions files at the moment? EDIT: Solved this by updating to TypeScript 2.x and adding the following to |
The original request should be handled by #11407. |
7b9a42f adds a new |
For various reasons that are discussed in other issues, some people like to pipe TS into Babel for the downlevel (e.g. ES5) code generation. I won't reiterate here why one might want to do so.
Now that TS is starting to get ES7+ features such as
async
, decorators, possibly::
& co. it would be very welcome to add a ES7 (ES2016) target.The use case today is to get raw, non transformed code from TS and process it with Babel.
The future use case is of course that JS runtimes are going to have some of those features natively supported and down-level emit won't be required anymore.
The text was updated successfully, but these errors were encountered: