How to replace a Identifier node with a Literal node? #8065
Unanswered
rattlecattle
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm building a constant folding optimization pass. This is a contrived example of what I'm trying to achieve.
This is the orignal JS code.
I want to simplify it to the below.
Using Scope and Bindings can already find out the places the variable
PI
is referenced. My question is how to replace occurences of the IdentifierPI
with the Literal3.14
without implementingvisit_xxx
forVisitMut
for every type of parent node the Identifier may be in?For example,
In
getPI
, the parent ofPI
isReturnStatement
.In
area
the parent isBinaryExpression
.Is there a way to avoid implemeting
visit_xxx
for each ofReturnStatement
,BinaryExpression
and so on to check if the child is an identifier and replace it with a Literal?Beta Was this translation helpful? Give feedback.
All reactions