Rishab Jain
Rishab Jain

Reputation: 299

Dart replacing the node in the abstract syntax tree

i want to replace print(a) with print(a+b) in the following code.

void main(){
   String a ="hey";
   String b ="there"; 
   print(\$a);
}

cn is the AstNode & cn contains print($a)

Is their any way i can do this? Please help me, i am new to dart.

Upvotes: 0

Views: 348

Answers (2)

Code on the Rocks
Code on the Rocks

Reputation: 17804

It is not recommended to edit the AST directly and the analyzer package is primarily for read-only analysis.

What you can do instead is use the analyzer package to find the index of code you want to edit in a file and then replace it using simple file operations.

Upvotes: 0

Related Questions