Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elm: Fix import for Dict #685

Merged
merged 4 commits into from
Oct 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading