Skip to content

Commit

Permalink
Merge pull request #25 from VirtusLab/es-version
Browse files Browse the repository at this point in the history
Add support for parsing es version
  • Loading branch information
lwronski authored Aug 16, 2023
2 parents c91a2fb + f7ccde7 commit fc94cdf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cli/src/org/scalajs/cli/Scalajsld.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import java.io.File
import java.net.URI
import java.nio.file.Path
import java.lang.NoClassDefFoundError
import org.scalajs.cli.internal.ModuleSplitStyleParser
import org.scalajs.cli.internal.{EsVersionParser, ModuleSplitStyleParser}

object Scalajsld {

Expand Down Expand Up @@ -153,6 +153,9 @@ object Scalajsld {
opt[Unit]("es2015")
.action { (_, c) => c.copy(esFeatures = c.esFeatures.withESVersion(ESVersion.ES2015)) }
.text("Use ECMAScript 2015")
opt[String]("esVersion")
.action { (esV, c) => c.copy(esFeatures = c.esFeatures.withESVersion(EsVersionParser.parse(esV))) }
.text("EsVersion " + EsVersionParser.All.mkString("(", ", ", ")"))
opt[ModuleKind]('k', "moduleKind")
.action { (kind, c) => c.copy(moduleKind = kind) }
.text("Module kind " + ModuleKind.All.mkString("(", ", ", ")"))
Expand Down
23 changes: 23 additions & 0 deletions cli/src/org/scalajs/cli/internal/EsVersionParser.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.scalajs.cli.internal

import org.scalajs.linker.interface.ESVersion

import java.util.Locale

object EsVersionParser {
def parse(esVersion: String): ESVersion =
esVersion.trim.toLowerCase(Locale.ROOT) match {
case "es5_1" => ESVersion.ES5_1
case "es2015" => ESVersion.ES2015
case "es2016" => ESVersion.ES2016
case "es2017" => ESVersion.ES2017
case "es2018" => ESVersion.ES2018
case "es2019" => ESVersion.ES2019
case "es2020" => ESVersion.ES2020
case "es2021" => ESVersion.ES2021
case unknown => throw new IllegalArgumentException(s"Warning: unrecognized argument: $unknown for --esVersion parameter")
}

val All: List[ESVersion] =
List(ESVersion.ES5_1, ESVersion.ES2015, ESVersion.ES2016, ESVersion.ES2017, ESVersion.ES2018, ESVersion.ES2019, ESVersion.ES2020, ESVersion.ES2021)
}

0 comments on commit fc94cdf

Please sign in to comment.