Skip to content

Commit 3b1b758

Browse files
committed
Factor per method body scopedVars into withPerMethodBodyState
The following commit will introduce another call-site. Separating it to reduce noise. Forward port of scala-js/scala-js@587e194
1 parent 1716ff6 commit 3b1b758

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ class JSCodeGen()(using genCtx: Context) {
104104
}
105105
}
106106

107+
private def withPerMethodBodyState[A](methodSym: Symbol)(body: => A): A = {
108+
withScopedVars(
109+
currentMethodSym := methodSym,
110+
thisLocalVarIdent := None,
111+
isModuleInitialized := new ScopedVar.VarBox(false),
112+
undefinedDefaultParams := mutable.Set.empty,
113+
) {
114+
body
115+
}
116+
}
117+
107118
private def acquireContextualJSClassValue[A](f: Option[js.Tree] => A): A = {
108119
val jsClassValue = contextualJSClassValue.get
109120
withScopedVars(
@@ -1039,12 +1050,7 @@ class JSCodeGen()(using genCtx: Context) {
10391050
val vparamss = dd.termParamss
10401051
val rhs = dd.rhs
10411052

1042-
withScopedVars(
1043-
currentMethodSym := sym,
1044-
undefinedDefaultParams := mutable.Set.empty,
1045-
thisLocalVarIdent := None,
1046-
isModuleInitialized := new ScopedVar.VarBox(false)
1047-
) {
1053+
withPerMethodBodyState(sym) {
10481054
assert(vparamss.isEmpty || vparamss.tail.isEmpty,
10491055
"Malformed parameter list: " + vparamss)
10501056
val params = if (vparamss.isEmpty) Nil else vparamss.head.map(_.symbol)

0 commit comments

Comments
 (0)