Skip to content
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

Closed
sebmck opened this issue Jan 28, 2015 · 9 comments
Closed

Transformer API #607

sebmck opened this issue Jan 28, 2015 · 9 comments
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@sebmck
Copy link
Contributor

sebmck commented Jan 28, 2015

Details/discussion to come.

@ooflorent
Copy link

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?
Doing this would help a lot:

to5.transform(file, {
  custom: [
    require('my-transformer')
  ]
})

@sebmck
Copy link
Contributor Author

sebmck commented Feb 13, 2015

@ooflorent Not currently, hence this issue.

@ooflorent
Copy link

Well, I hope this feature will land soon! Second parsing is total pain with our codebase...

@sebmck
Copy link
Contributor Author

sebmck commented Feb 13, 2015

@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;

@ooflorent
Copy link

@sebmck Thanks for the trick but it does not fit to our needs since we use 6to5ify 😞
If I implement custom transformers to 6to5, would the PR be merged?

@lukescott
Copy link
Contributor

@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.

@sebmck
Copy link
Contributor Author

sebmck commented Feb 13, 2015

@ooflorent

If I implement custom transformers to 6to5, would the PR be merged?

Not at the time, no. I don't want to support this prematurely.

@sebmck
Copy link
Contributor Author

sebmck commented Feb 15, 2015

Prerequisites are #780 and a stable ESTree spec.

@sebmck
Copy link
Contributor Author

sebmck commented Feb 25, 2015

Superseded by #883.

@sebmck sebmck closed this as completed Feb 25, 2015
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jul 29, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jul 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

3 participants