question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[babel.generate]: generate convert ast to code

See original GitHub issue

Bug 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:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
AjayPoshakcommented, Oct 22, 2020

@nicolo-ribaudo I would like to raise a PR to document the above option.

0reactions
babel-botcommented, Oct 22, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

babel/generator - Babel.js
Turns an AST into code.
Read more >
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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found