Skip to content

Commit 3765ee1

Browse files
committed
Derive the .sjsir file names from the ClassDef's names.
Now that we have non-mangled names as `ClassDef`'s names, we can derive the corresponding file names from that, instead of having to carry around the original symbol and an optional suffix. This is a forward port of scala-js/scala-js@44996ce
1 parent 6d3fe1d commit 3765ee1

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

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

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class JSCodeGen()(implicit ctx: Context) {
137137
}
138138
val allTypeDefs = collectTypeDefs(cunit.tpdTree)
139139

140-
val generatedClasses = mutable.ListBuffer.empty[(Symbol, js.ClassDef)]
140+
val generatedClasses = mutable.ListBuffer.empty[js.ClassDef]
141141

142142
// TODO Record anonymous JS function classes
143143

@@ -167,20 +167,17 @@ class JSCodeGen()(implicit ctx: Context) {
167167
genScalaClass(td)
168168
}
169169

170-
generatedClasses += ((sym, tree))
170+
generatedClasses += tree
171171
}
172172
}
173173
}
174174

175-
val clDefs = generatedClasses.map(_._2).toList
176-
177-
for ((sym, tree) <- generatedClasses)
178-
genIRFile(cunit, sym, tree)
175+
for (tree <- generatedClasses)
176+
genIRFile(cunit, tree)
179177
}
180178

181-
private def genIRFile(cunit: CompilationUnit, sym: Symbol,
182-
tree: ir.Trees.ClassDef): Unit = {
183-
val outfile = getFileFor(cunit, sym, ".sjsir")
179+
private def genIRFile(cunit: CompilationUnit, tree: ir.Trees.ClassDef): Unit = {
180+
val outfile = getFileFor(cunit, tree.name.name, ".sjsir")
184181
val output = outfile.bufferedOutput
185182
try {
186183
ir.Serializers.serialize(output, tree)
@@ -189,21 +186,13 @@ class JSCodeGen()(implicit ctx: Context) {
189186
}
190187
}
191188

192-
private def getFileFor(cunit: CompilationUnit, sym: Symbol,
189+
private def getFileFor(cunit: CompilationUnit, className: ClassName,
193190
suffix: String): dotty.tools.io.AbstractFile = {
194-
import dotty.tools.io._
195-
196-
val outputDirectory: AbstractFile =
197-
ctx.settings.outputDir.value
198-
199-
val pathParts = sym.fullName.toString.split("[./]")
191+
val outputDirectory = ctx.settings.outputDir.value
192+
val pathParts = className.nameString.split('.')
200193
val dir = pathParts.init.foldLeft(outputDirectory)(_.subdirectoryNamed(_))
201-
202-
var filename = pathParts.last
203-
if (sym.is(ModuleClass))
204-
filename = filename + nme.MODULE_SUFFIX.toString
205-
206-
dir fileNamed (filename + suffix)
194+
val filename = pathParts.last
195+
dir.fileNamed(filename + suffix)
207196
}
208197

209198
// Generate a class --------------------------------------------------------

0 commit comments

Comments
 (0)