2

I learnt that packages like Babel can do the job converting ES6 code to JavaScript in ES5, but can I just start from the ES6 AST I got somewhere?

4
  • So, you have an ES6 AST and you want to create an ES5 AST from it? Mar 30, 2015 at 13:26
  • @bali182 Yes. That ES6 AST is generated from other tools. It's also fine if it outputs JavaScript directly. Mar 30, 2015 at 13:28
  • But why don't you just don't parse the ES6 code at all, and let for example Babel do the converting it right into ES5 code? Also, If you would find a tool that converts an AST to something else, it would require the AST to be in a specific format, and you would have to do some nasty transforming (most likely) Mar 30, 2015 at 13:35
  • @bali182 Yes. It was actually an AltJS language, I suppose it might interesting if I generates ES6 AST and let babel or whatever that transforms AST into ES5 JavaScript . Mar 30, 2015 at 13:55

1 Answer 1

2

I posted a similar question in babel's Issues and got an anwser from the maintainer:

https://github.com/babel/babel/issues/1122

require("babel").transform.fromAST(ast, originalCode, options);

variable originalCode could be null and that will finish this task.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.