@@ -73,7 +73,6 @@ pub(super) fn optimizer<'a>(
7373 in_strict : options. module ,
7474 remaining_depth : 6 ,
7575 } ,
76- var_kind : None ,
7776 scope : SyntaxContext :: default ( ) ,
7877 bit_ctx : BitCtx :: default ( ) ,
7978 } ;
@@ -101,8 +100,6 @@ pub(super) fn optimizer<'a>(
101100struct Ctx {
102101 expr_ctx : ExprCtx ,
103102
104- var_kind : Option < VarDeclKind > ,
105-
106103 /// Current scope.
107104 scope : SyntaxContext ,
108105
@@ -120,68 +117,75 @@ bitflags! {
120117 #[ derive( Debug , Clone , Copy , Default ) ]
121118 pub ( crate ) struct BitCtx : u32 {
122119 /// `true` if the [VarDecl] has const annotation.
123- const HasConstAnn = 1 << 0 ;
120+ const IsConst = 1 << 0 ;
121+ const IsVar = 1 << 1 ;
122+ const IsLet = 1 << 2 ;
124123
125- const DontUsePrependNorAppend = 1 << 1 ;
124+ const DontUsePrependNorAppend = 1 << 3 ;
126125
127- const InBoolCtx = 1 << 2 ;
126+ const InBoolCtx = 1 << 4 ;
128127
129- const InAsm = 1 << 3 ;
128+ const InAsm = 1 << 5 ;
130129
131130 /// `true` only for [Callee::Expr].
132- const IsCallee = 1 << 4 ;
131+ const IsCallee = 1 << 6 ;
133132
134133 /// `true` if we are try block. `true` means we cannot be sure about control
135134 /// flow.
136- const InTryBlock = 1 << 5 ;
135+ const InTryBlock = 1 << 7 ;
136+
137137 /// `true` while handling `test` of if / while / for.
138- const InCond = 1 << 6 ;
138+ const InCond = 1 << 8 ;
139139
140140 /// `true` if we are in `arg` of `delete arg`.
141- const IsDeleteArg = 1 << 7 ;
141+ const IsDeleteArg = 1 << 9 ;
142+
142143 /// `true` if we are in `arg` of `++arg` or `--arg`.
143- const IsUpdateArg = 1 << 8 ;
144- const IsLhsOfAssign = 1 << 9 ;
144+ const IsUpdateArg = 1 << 10 ;
145+
146+ const IsLhsOfAssign = 1 << 11 ;
147+
145148 /// `false` for `d` in `d[0] = foo`.
146- const IsExactLhsOfAssign = 1 << 10 ;
149+ const IsExactLhsOfAssign = 1 << 12 ;
147150
148151 /// `true` for loop bodies and conditions of loops.
149- const ExecutedMultipleTime = 1 << 11 ;
152+ const ExecutedMultipleTime = 1 << 13 ;
150153
151154 /// `true` while handling `expr` of `!expr`
152- const InBangArg = 1 << 12 ;
153- const InVarDeclOfForInOrOfLoop = 1 << 13 ;
155+ const InBangArg = 1 << 14 ;
156+
157+ const InVarDeclOfForInOrOfLoop = 1 << 15 ;
154158
155- const DontUseNegatedIife = 1 << 14 ;
159+ const DontUseNegatedIife = 1 << 16 ;
156160
157161 /// `true` while handling top-level export decls.
158- const IsExported = 1 << 15 ;
162+ const IsExported = 1 << 17 ;
159163
160164 /// `true` while handling top level items.
161- const TopLevel = 1 << 16 ;
165+ const TopLevel = 1 << 18 ;
162166
163167 /// `true` while we are in a function or something similar.
164- const InFnLike = 1 << 17 ;
168+ const InFnLike = 1 << 19 ;
165169
166- const InBlock = 1 << 18 ;
170+ const InBlock = 1 << 20 ;
167171
168- const InObjOfNonComputedMember = 1 << 19 ;
172+ const InObjOfNonComputedMember = 1 << 21 ;
169173
170- const InTplExpr = 1 << 20 ;
174+ const InTplExpr = 1 << 22 ;
171175
172176 /// True while handling callee, except an arrow expression in callee.
173- const IsThisAwareCallee = 1 << 21 ;
177+ const IsThisAwareCallee = 1 << 23 ;
174178
175- const IsNestedIfReturnMerging = 1 << 22 ;
179+ const IsNestedIfReturnMerging = 1 << 24 ;
176180
177- const DontInvokeIife = 1 << 23 ;
181+ const DontInvokeIife = 1 << 25 ;
178182
179- const InWithStmt = 1 << 24 ;
183+ const InWithStmt = 1 << 26 ;
180184
181- const InParam = 1 << 25 ;
185+ const InParam = 1 << 27 ;
182186
183187 /// `true` while we are inside a class body.
184- const InClass = 1 << 26 ;
188+ const InClass = 1 << 28 ;
185189 }
186190}
187191
@@ -2336,7 +2340,6 @@ impl VisitMut for Optimizer<'_> {
23362340 fn visit_mut_param ( & mut self , n : & mut Param ) {
23372341 let ctx = Ctx {
23382342 bit_ctx : self . ctx . bit_ctx . with ( BitCtx :: InParam , true ) ,
2339- var_kind : None ,
23402343 ..self . ctx . clone ( )
23412344 } ;
23422345 let mut o = self . with_ctx ( ctx) ;
@@ -2769,8 +2772,9 @@ impl VisitMut for Optimizer<'_> {
27692772 . ctx
27702773 . bit_ctx
27712774 . with ( BitCtx :: IsUpdateArg , false )
2772- . with ( BitCtx :: HasConstAnn , false ) ,
2773- var_kind : None ,
2775+ . with ( BitCtx :: IsConst , false )
2776+ . with ( BitCtx :: IsLet , false )
2777+ . with ( BitCtx :: IsVar , false ) ,
27742778 ..self . ctx . clone ( )
27752779 } ;
27762780
@@ -2787,8 +2791,12 @@ impl VisitMut for Optimizer<'_> {
27872791 . ctx
27882792 . bit_ctx
27892793 . with ( BitCtx :: IsUpdateArg , false )
2790- . with ( BitCtx :: HasConstAnn , self . has_const_ann ( n. ctxt ) ) ,
2791- var_kind : Some ( n. kind ) ,
2794+ . with (
2795+ BitCtx :: IsConst ,
2796+ n. kind == VarDeclKind :: Const || self . has_const_ann ( n. ctxt ) ,
2797+ )
2798+ . with ( BitCtx :: IsVar , n. kind == VarDeclKind :: Var )
2799+ . with ( BitCtx :: IsLet , n. kind == VarDeclKind :: Let ) ,
27922800 ..self . ctx . clone ( )
27932801 } ;
27942802
0 commit comments