-
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
Suggestion: 6to5 instead of built-in transforms #1641
Comments
Sounds like an idea for a _great_ community TypeScript project! |
There's so much duplication of effort in transpiling ES6. It's tough to actually get a solid ES6 implementation and it's much harder than most people think. 6to5 has built-in support for parsing flow types so if complete ES6 and types is something that tickles your fancy then you can just switch to flow. |
wouldn't it be able to just parse TypeScript as well? |
@basarat Probably, I'm not familiar with TypeScript types or any of the other features. |
I'm not 100% confortable with this idea for few reasons :
|
@fdecampredon To be clear, because the comments have strayed away a little bit:
|
from 6to5 repl: class Test {
test() {
}
}
// === compiled ==
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var Test = (function () {
function Test() {}
_prototypeProperties(Test, null, {
test: {
value: function () {},
writable: true,
enumerable: true,
configurable: true
}
});
return Test;
})();
Basicly it's already something you can do with the recent ES6 target minus the features that are not implemented (yet).
With all the effort the ts team has put in providing an efficient compiler with incremental parsing etc I doubt they would agree that the perf hit is acceptable but why not. |
The 6to5 emit looks like someone's eaten a pretty cake and spat it all out. |
This isn't a road we're going down. I think fdecampredon touched on all the relevant points here. In an alternate universe where we hadn't even written a compiler yet and ES3 were actually 100% dead, it might be a different conversation, but we can't recover that sunk cost or force IE8 to disappear any more quickly. The performance aspect is also very critical and I'm skeptical about whether we could ever make this arrangement fast enough. |
@fdecampredon
The wrapper function and so on? TS does exactly the same. So we're left with the little verbose
I listed why in my original suggestion. To repeat myself: transpiling is a complicated problem that has no lasting value and is already solved -- in a more correct way -- elsewhere. Like others (see #1644) I would like to see the TS team make faster progress in their implementation and the transpiling is just a waste of their time that we could do without.
I think you take a very quick shortcut here that is not an honest argument:
|
@RyanCavanaugh fair enough. Sunk costs are not recoverable indeed but you know that you have a lot of work ahead of you. "Throwing good money after bad" comes to mind. Anyway, whatever you do I hope you'll be able to speed up the implementation of ES6. Looking at the issues here, it's easy to see that many people are eager to get those features. With fully compliant browsers coming this year, good transpilers already available, the Flow project, more and more projects going this way (Angular 2 and Durandal nextgen)... the pressure raises. |
@jods4 if you're truly missing any specific features, you're more than welcome to send us a pull request at any time. |
Agreed, and it's been solved multiple times in different ways. There's a lot of ES6->5 transpilers out there, varying in the readability of their output and the features they support with what compatibility. Rather than fix on one, it's better for TS to remain independent. You can always tell TS to emit ES6 and use your preferred transpiler on its output as part of your build process. |
This is a radical suggestion but I think it makes sense.
Today, Typescript does two different things: it provides an awesome strongly-typed experience for coding javascript applications and it transpiles your code into equivalent javascript for various targets (es3, es5, es6).
These things are not strongly related and could easily be split into two distinct parts. In fact, lots of projects already try to do the second part. Notably 6to5, which is certainly the best es6 transpiler that exists today.
My suggestion is to drop any transpiling at all, drop the target options and always emit ES6 code. Because TS tries to align with ES, the emit code would mostly just remove the type annotations. This ES6 result can then be piped into 6to5 and we'll get our final js code, compatible with the browsers that we intend to support.
Why would you do that?
let
and transpileclass
or=>
.The text was updated successfully, but these errors were encountered: