Skip to content

Commit

Permalink
Elm: Fix import for Dict (#685)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbryzek authored Oct 11, 2023
1 parent 4020ae9 commit ef4ab4c
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions elm-generator/src/main/scala/generator/elm/Imports.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ package generator.elm
import scala.collection.concurrent.TrieMap

case class Imports() {
private[this] sealed trait ExposingAllValue
private[this] object ExposingAllValue {
case object Wildcard extends ExposingAllValue
case class Types(types: Seq[String]) extends ExposingAllValue
}

private[this] val allAs: TrieMap[String, String] = TrieMap[String, String]()
private[this] val exposingAll: TrieMap[String, Unit] = TrieMap[String, Unit]()
private[this] val exposingAll: TrieMap[String, ExposingAllValue] = TrieMap[String, ExposingAllValue]()

def addAs(name: String, as: String): Unit = {
allAs.put(name, as).foreach { existing =>
Expand All @@ -14,7 +20,14 @@ case class Imports() {
}

def addExposingAll(name: String): Unit = {
exposingAll.put(name, ())
exposingAll.put(name, ExposingAllValue.Wildcard)
()
}

def addExposing(name: String, types: String): Unit = addExposing(name, Seq(types))

private[this] def addExposing(name: String, types: Seq[String]): Unit = {
exposingAll.put(name, ExposingAllValue.Types(types))
()
}

Expand All @@ -23,7 +36,10 @@ case class Imports() {
allAs.keysIterator.toSeq.sorted.map { name =>
s"import $name as ${allAs(name)}"
} ++ exposingAll.keysIterator.toSeq.sorted.map { name =>
s"import $name exposing (..)"
exposingAll(name) match {
case ExposingAllValue.Wildcard => s"import $name exposing (..)"
case ExposingAllValue.Types(types) => s"import $name exposing (${types.mkString(", ")})"
}
}
).mkString("\n")
}
Expand Down

0 comments on commit ef4ab4c

Please sign in to comment.