[babel.generate]: generate convert ast to code
See original GitHub issueBug Report
- I would like to work on a fix!
Current behavior
first, I use babel parse a angular module which decorators before export
const preCode = `
@NgModule({})
export class AppModule {};
`;
const ast = parse(preCode, {
sourceType: "module",
plugins: [
"decorators-legacy" // decoratorsBeforeExport: true
]
});
then, I use generate to convert ast to code.
const code = generate(ast).code;
// export @NgModule({})
// class AppModule {}
but code by generate is export before decorators
Expected behavior
I expect generate could support a option like decoratorsBeforeExport
or decorators-legacy
Environment
- Babel version(s): [7+]
- Node/npm version: [ Node 10+/npm 6+]
- OS: [Mac OS]
Possible Solution
I hope someone can tell me how to do it。
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Step-by-step guide for writing a custom babel transformation
So the general idea is to parse your code to AST, transform the AST, and then generate code from the transformed AST.
Read more >How to get code as a string from Babel node during traverse
Each AST node returned by @babel/parser has a start and end properties pointing to it's location in the source code.
Read more >Revealing the magic of AST by writing babel plugins
They first convert our code to an AST tree, then apply some transformation on it(add, edit, update, delete), create a new tree out...
Read more >Understanding ASTs by Building Your Own Babel Plugin
Generate. Finally, the babel-generator module is used to turn the transformed AST back into regular code. Coding Assessments ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@nicolo-ribaudo I would like to raise a PR to document the above option.
Hey @ls365882248! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we’re a limited number of volunteers, so it’s possible this won’t be addressed swiftly.
If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.