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
Transformer API #607
Comments
I'm working on a project where we need to instrument some parts of our code. Since we are using 6to5 and it generates an AST, we though it would be great to be able to add a custom transformer without having to re-parse the JS. Is there any way to do it? to5.transform(file, {
custom: [
require('my-transformer')
]
}) |
@ooflorent Not currently, hence this issue. |
Well, I hope this feature will land soon! Second parsing is total pain with our codebase... |
@ooflorent Hopefully. You can already get the transformed ast if that's useful to you: var result = require("6to5").transform("code here", {
code: false // disable generating code from the ast, performance etc
});
result.ast; |
@sebmck Thanks for the trick but it does not fit to our needs since we use 6to5ify 😞 |
@ooflorent This is sort of already possible now, it's just a bit hackish, and you have to update it when the structure of the code changes: var lib6to5 = "6to5-core/lib/6to5";
var util = require(lib6to5 + "/util");
var types = require(lib6to5 + "/types");
var transform = require(lib6to5 + "/transformation");
var Transformer = require(lib6to5 + "/transformation/transformer");
var templateName = "myTemplate";
util.templates[templateName] = util.parseTemplate(templateName, "... js code ...");
var transformerName = "myTransformer";
transform.transformers[transformerName] = new Transformer(transformerName, {
// ... transformer code here
}); Just make sure to require that file before you require 6to5ify, gulp-6to5, etc. I'm sure that sebmck is still working out how he wants to expose an API for this. What ever that looks like it would be nice to be able to reference a node module or file. I have some custom transformers that I use in a couple projects that I'd like to put in a separate repo. For now I'm using a local file. |
Not at the time, no. I don't want to support this prematurely. |
Prerequisites are #780 and a stable ESTree spec. |
Superseded by #883. |
Details/discussion to come.
The text was updated successfully, but these errors were encountered: