-
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: Allow customizing the code emitter. #2727
Comments
We have got this request a lot lately. We need a design for extensiblity for the emitter. |
If we could also get parser extensibility, or at least ast transformation at the same time it could be cool :) ( see: https://github.com/benjamn/recast) |
I think at the very least the API needs to provide the following:
|
Note that this sort of extensibility is quite difficult to provide. The Roslyn team looked into this and found it to be too difficult to provide in any form. The problems include (and must be addressed by any proposal), but are not limited to:
Looking at the JSX work, for example, we can see how difficult this would be. There would need to be some way for an extension to add new AST types and kinds. But that means that so much additonal code in the system would now need to become aware of these kinds. It needs to fix up the scanner, but that involves invasive work of specific scanner functions. It needs to go into very specific places in the parser to change how they work. It needs to go into the incremental parser to address the issues there. And we haven't even gotten to all the LS features that would likely need to be updated to handle JSX features properly. Ideally, instead of asking for extensibility, one would come with a use case where they wanted to extend the compiler. They should then show how they'd like to do that in the form of an extension, rather than by manipulating the compiler/LS source directly. Then we could see about the viability of such an extensibility API and ensure that we had satisfactory answers to the above questions (and more). |
This is a good example of where this gets difficult:
Right now there is no JS code model (though i'd personally like one). So we'd need to provide some way to get a JS code model. Then we have the following design problem:
@Aleksey-Bykov I'm with Mohamed on this. We need a proposal for this feature. Ideally something that addresses all your bullet points, and all the points i listed in the previous post. If such a proposal can be made, and we can do things like measure the perf impact, then we can decide how to go forward. Thanks! |
As a least painful start all that needs to be done is to:
In addition to what's above it would also be nice to:
|
I wish I could pass these guys as parameters rather than having them hardcoded: /** Emit a node */
let emit = emitNodeWithoutSourceMap;
/** Called just before starting emit of a node */
let emitStart = function (node: Node) { };
/** Called once the emit of the node is done */
let emitEnd = function (node: Node) { }; Is there any chance you would allow customizing them? |
@Aleksey-Bykov we are looking into changing how we emit to a more transformation based approach. no ETA at the moment. but when it happens it should allow for more flexibility in extending the emitter functionality. |
@mhegazy any news? |
Since doing even simple inlining is out of scope of TypeScript, please allow extensions to the code emitter, so that there is a way to get JavaScript other than what is officially endorsed..
The text was updated successfully, but these errors were encountered: