Skip to content

Commit 85a8eb5

Browse files
committed
Insert StoreModules for JS module classes in the compiler.
And only enable the deserialization when reading IR < 1.18.
1 parent 68bfc6f commit 85a8eb5

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

compiler/src/main/scala/org/scalajs/nscplugin/GenJSCode.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1610,7 +1610,7 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
16101610

16111611
var preSuperStats = List.newBuilder[js.Tree]
16121612
var jsSuperCall: Option[js.JSSuperConstructorCall] = None
1613-
val postSuperStats = List.newBuilder[js.Tree]
1613+
val postSuperStats = mutable.ListBuffer.empty[js.Tree]
16141614

16151615
/* Move param accessor initializers and early initializers after the
16161616
* super constructor call since JS cannot access `this` before the super
@@ -1714,6 +1714,13 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
17141714
assert(jsSuperCall.isDefined, "Did not find Super call in primary JS " +
17151715
s"construtor at ${dd.pos}")
17161716

1717+
/* Insert a StoreModule if required.
1718+
* Do this now so we have the pos of the super ctor call.
1719+
* +=: prepends to the ListBuffer in O(1) -- yes, it's a cryptic name.
1720+
*/
1721+
if (isStaticModule(currentClassSym))
1722+
js.StoreModule()(jsSuperCall.get.pos) +=: postSuperStats
1723+
17171724
new PrimaryJSCtor(sym, genParamsAndInfo(sym, vparamss),
17181725
js.JSConstructorBody(preSuperStats.result(), jsSuperCall.get, postSuperStats.result())(dd.pos))
17191726
}

ir/shared/src/main/scala/org/scalajs/ir/Serializers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2005,7 +2005,7 @@ object Serializers {
20052005
val superCall = readTree().asInstanceOf[JSSuperConstructorCall]
20062006
val afterSuper0 = readTrees()
20072007

2008-
val afterSuper = if (true /*hacks.use17*/ && ownerKind == ClassKind.JSModuleClass) {
2008+
val afterSuper = if (hacks.use17 && ownerKind == ClassKind.JSModuleClass) {
20092009
afterSuper0 match {
20102010
case StoreModule() :: _ => afterSuper0
20112011
case _ => StoreModule()(superCall.pos) :: afterSuper0

0 commit comments

Comments
 (0)