Generate ast-building code from given source
See original GitHub issueWhen I generated code in plugins I often have to look what the various elements are called like and what arguments they expect. Also the “reverse” chaining is not intuitive at times.
I’d be cool if I could input the source I want:
this.emit.bind(this, 'myArgument')
and get the code needed to generate it:
import * as t from "babel-types";
t.callExpression(
t.memberExpression(
t.memberExpression(
t.Identifier("this"),
t.Identifier("emit")
),
t.Identifier("bind")
),
[
t.thisExpression(),
t.StringLiteral("myArgument")
]
)
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Building AST nodes from source code - DEV Community
In this article, we are going to take a look at a tool called AST Builder which will significantly improve the developer experience...
Read more >How to create AST with ANTLR4? - Stack Overflow
I used parts of code found in the TestRig.java file. Let's suppose again that we have a string of C++ source code from...
Read more >CS75: Parser
Your final version of the parser will create an AST of the program as it parses. The AST will then be used by...
Read more >A deep dive into the Elixir AST: Building a static code analyzer
Analyzing the AST to build a static code analyzer. ... At a high level, when you run it, it scans you project, parses...
Read more >aggalex/Variables: A simple example of parsing and AST ... - GitHub
Variables. A simple example of parsing and AST building with Rust and LALRPOP. What can it do? It can successfuly parse and execute...
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
@RReverser Thanks for pointing me at
babel-template
(again). I must confess that when I first followed the link in @hzoo’s comment, I completely misunderstood what that library does.I’m going to replace my “long nested expression” with a short and readable
babel-template
expression and not look back! 😄There are so many great features to Babel if one knows where to look!
you can use babel-template: https://github.com/babel/babel/tree/master/packages/babel-template, also included in the plugin with
export default function ({types: t, template}) {