-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Proposal: Replace emitter with syntax tree transformations and a simplified node emitter. #5595
Comments
+1 TypeScript should has more modularbility for testability and maintainability for implementations of new ECMA-262 specification. If possible, I want the plugable design and hook points for transforms like the babel. TypeScript team will be able to get feedbacks from user implemented plugins. |
+1 |
It would be very nice to allow extending the emitter to output JSDoc comments with types, so transpiled ES5 code could then be fed into Closure Compiler with advanced optimizations turned on. |
Will you be able to create the Syntax Tree from scratch? |
that is the plan :) |
It would be great if this would be compatible to the Babel-plugin style. Great way to open the door to implement typescript "native" runtime type checking |
https://github.com/Microsoft/TypeScript/wiki/Roadmap hasn't been updated to match. |
Hope to see it soon! another big step to make babel obsolete. |
Completed as of 4685646. |
@rbuckton where it is possible to read how to use committed changes? |
@whitecolor see #1564 (comment) (use |
Would it be possible to provide an example that creates a syntax tree from scratch and emits the TypeScript? I've been wanting to be able to do this for a couple of years now. See How do you do a straight TS emit? |
One thing I would like to do is to manipulate the emitted values for string literals. For example I would love to be able to specify strings to be translated with some kind of special syntax in string literals, like "@foo", and have the emitter translate all strings literals that match the given syntax to a specific function call. In the non-goal there is : "We will not support end-user extensibility of these transformations at this time, though we may consider this in a future proposal." So should I assume that doing something like that is not currently possible? |
yes. but we intend to expose all the transformation and factory APIs so it should be possible in the near future. |
Thanks for the answer, looking forward to that |
In my Typescript packaging compiler I create a single module bundle (via import dependency analysis) and then directly minify the bundle. To minify the ts bundle I must first perform identifier shortening, compile the bundle and then perform whitespace removal on the js output ( a multistep process as I currently don't have access to the emitter ). With the new transformation and factory APIs I am hoping to do this all in 1 step. My question is how to provide directives to a transform within the ts source file. Since I have total control of how I package my bundle I can essentially make the whole package internal and thus shorten the majority of identifiers. However, when using Angular 2 components, mangling identifiers which are used within component html templates is a problem!. If I had a mechanism to provide a directive to the minification transform I could then selectively bypass identifier shortening for those used within the template. As an alternative to transform directives would using Thanks for any help! |
How near is this future? |
I'm not entirely sure, but I don't think it is a goal of TypeScript to transform non-language features. Is there any plan to compile such things in TypeScript? |
No |
In an effort to better support down-level transformations for complex emit like generators and Async Functions, and to be able to add new down-level transformations for the evolving ECMA-262 specification, we propose to replace the current emitter logic for the TypeScript compiler with an implementation that relies on transformations of the source tree.
Our current emitter is not built to handle the requirements for some of the more complex rewriting needed to support features such as generators (ES6/ES2015) and Async Functions (ES2016). In addition, as time goes on we will need to add more and more branching logic to handle down-level emit of new language features due to the yearly cadence that TC39 is adopting for the ECMAScript specification.
Syntax tree transformations will give us the ability to transform our source tree in an iterative fashion, allowing us to inject new transformations at the head of a transformation chain so that few (if any) changes need to be made to existing transformations in later iterations. As a result, there would be minimal maintenance for the complex transformations needed for down-level generators, as long as new features are already transformed into a syntactically valid ES6 tree.
Generally this will also help to reduce the branching logic of our current emitter, and keep syntactic transformations isolated to an individual file for a language version or feature. As a result, the emitter itself can be simplified drastically and focus specifically on emitting the given syntax tree with almost no branching logic.
Requirements:
Goals:
Non-Goals:
Remaining Tasks:
The text was updated successfully, but these errors were encountered: