benjamn / ast-types

Esprima-compatible implementation of the Mozilla JS Parser API
MIT License
1.13k stars 196 forks source link

Add `@babel/template`-like package #369

Open fengzilong opened 4 years ago

fengzilong commented 4 years ago

Write the builders syntax by hand is really tedious, can we provide some package like @babel/template or add an online playground to convert the code to builders syntax. It will save us tons of time

rajasegar-c commented 4 years ago

@fengzilong Actually I am working on one playground to build AST nodes through code for jscodeshift and Glimmer templates here. https://rajasegar.github.io/ast-builder/ Please let me know this is what you are looking for. Appreciate any PRs or issues. And thanks for the @babel/template pointer btw. For this project, let's hear from @benjamn

fengzilong commented 4 years ago

Yeah, good job, that's the playground I need, but there are some issues with yours

try this snippet

module.exports = {
  components: {
    'demo': demo
  }
}

the 'demo' becomes j.identifier('undefined')

and it seems not to be usable with es6 export syntax

some suggestion: it will be much better if we can format the code with prettier

thanks for reply @rajasegar-c

rajasegar commented 4 years ago

@fengzilong Thanks for trying it out and reporting the issues. It's a bug I need to fix and yes formatting needs some work.

rajasegar commented 4 years ago

Can you give me an example for the ES6 export you were trying, have you tried changing the parser to babel or babylon? Fixed the module.exports and formatting

fengzilong commented 4 years ago

@rajasegar sorry for my late reply, I just see the notification from github. I tried and ES6 export has been fixed, and formatting works perfectly👍