diff --git a/.circleci/config.yml b/.circleci/config.yml index feb1973eb4..45f9578c5f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -19,7 +19,7 @@ jobs: # Customize the JVM maximum heap limit JVM_OPTS: -Xmx3200m TERM: dumb - + CI: 'true' steps: - checkout diff --git a/build.sbt b/build.sbt index ab662aef40..67aa3457f7 100644 --- a/build.sbt +++ b/build.sbt @@ -8,7 +8,7 @@ Global / bspEnabled := false autoStartServer := false Global / excludeLintKeys += autoStartServer -lazy val utils = project +lazy val core = project .configure(baseSettings) .settings(libraryDependencies ++= Seq(Deps.ammoniteOps, Deps.osLib, Deps.sourcecode) ++ Deps.circe) @@ -18,7 +18,7 @@ lazy val logging = project lazy val ts = project .configure(baseSettings, optimize) - .dependsOn(utils, logging) + .dependsOn(core, logging) .settings(libraryDependencies += Deps.parserCombinators) lazy val docs = project @@ -31,12 +31,12 @@ lazy val docs = project .enablePlugins(MdocPlugin, DocusaurusPlugin) lazy val scalajs = project - .dependsOn(utils, logging) + .dependsOn(core, logging) .configure(baseSettings, optimize) .settings(libraryDependencies ++= Seq(Deps.scalaXml)) lazy val phases = project - .dependsOn(utils, logging) + .dependsOn(core, logging) .configure(baseSettings, optimize) lazy val `importer-portable` = project @@ -101,17 +101,7 @@ lazy val root = project skip in publish := true, ) .configure(baseSettings) - .aggregate( - logging, - utils, - phases, - ts, - scalajs, - `importer-portable`, - `sbt-converter`, - importer, - cli, - ) + .aggregate(logging, core, phases, ts, scalajs, `importer-portable`, `sbt-converter`, importer, cli) lazy val baseSettings: Project => Project = _.settings( @@ -136,17 +126,20 @@ lazy val baseSettings: Project => Project = lazy val optimize: Project => Project = _.settings( - scalacOptions ++= Seq( - "-opt:l:inline", - "-opt:l:method", - "-opt:simplify-jumps", - "-opt:compact-locals", - "-opt:copy-propagation", - "-opt:redundant-casts", - "-opt:box-unbox", - "-opt:nullness-tracking", - // "-opt:closure-invocations", - "-opt-inline-from:org.scalablytyped.converter.internal.**", - "-opt-warnings", - ), + scalacOptions ++= { + if (insideCI.value || !isSnapshot.value) + Seq( + "-opt:l:inline", + "-opt:l:method", + "-opt:simplify-jumps", + "-opt:compact-locals", + "-opt:copy-propagation", + "-opt:redundant-casts", + "-opt:box-unbox", + "-opt:nullness-tracking", + "-opt-inline-from:org.scalablytyped.converter.internal.**", + "-opt-warnings", + ) + else Nil + }, ) diff --git a/cli/src/main/scala/org/scalablytyped/converter/cli/Main.scala b/cli/src/main/scala/org/scalablytyped/converter/cli/Main.scala index 8765cc27d5..4d171dacd5 100644 --- a/cli/src/main/scala/org/scalablytyped/converter/cli/Main.scala +++ b/cli/src/main/scala/org/scalablytyped/converter/cli/Main.scala @@ -1,20 +1,17 @@ package org.scalablytyped.converter.cli -import java.net.URI - import com.olvind.logging.{stdout, storing, LogLevel, Logger} import fansi.{Attr, Color, Str} import org.scalablytyped.converter.internal.importer._ import org.scalablytyped.converter.internal.importer.build.{BloopCompiler, PublishedSbtProject, SbtProject} import org.scalablytyped.converter.internal.importer.documentation.Npmjs -import org.scalablytyped.converter.internal.importer.jsonCodecs._ import org.scalablytyped.converter.internal.phases.PhaseListener.NoListener import org.scalablytyped.converter.internal.phases.{PhaseRes, PhaseRunner, RecPhase} import org.scalablytyped.converter.internal.scalajs.{Name, Versions} import org.scalablytyped.converter.internal.sets.SetOps import org.scalablytyped.converter.internal.ts.CalculateLibraryVersion.PackageJsonOnly import org.scalablytyped.converter.internal.ts.{PackageJsonDeps, TsIdentLibrary} -import org.scalablytyped.converter.internal.{constants, files, sets, BuildInfo, IArray, InFolder, Json} +import org.scalablytyped.converter.internal.{constants, files, sets, BuildInfo, InFolder, Json} import org.scalablytyped.converter.{Flavour, Selection} import scopt.{OParser, OParserBuilder, Read} @@ -74,13 +71,13 @@ object Main { storing().zipWith(stdout.filter(LogLevel.warn)) implicit val ReadsFlavour: Read[Flavour] = - Read.reads(s => Flavour.all.getOrElse(s, sys.error(s"'$s' is not among ${Flavour.all.keys}"))) + Read.reads(s => Flavour.byName.getOrElse(s, sys.error(s"'$s' is not among ${Flavour.byName.keys}"))) implicit val ReadsVersionsScalaJs: Read[Versions.ScalaJs] = - Read.stringRead.map(Versions.ScalaJs) + Read.stringRead.map(Versions.ScalaJs.apply) implicit val ReadsVersionsScala: Read[Versions.Scala] = - Read.stringRead.map(Versions.Scala) + Read.stringRead.map(Versions.Scala.apply) implicit val ReadsTsIdentLibrary: Read[TsIdentLibrary] = Read.stringRead.map(TsIdentLibrary.apply) @@ -133,7 +130,7 @@ object Main { opt[Flavour]('f', "flavour") .action((x, c) => c.mapConversion(_.copy(flavour = x))) .text( - s"One of ${Flavour.all.keys.mkString(", ")}. See https://scalablytyped.org/docs/flavour", + s"One of ${Flavour.byName.keys.mkString(", ")}. See https://scalablytyped.org/docs/flavour", ), opt[Versions.ScalaJs]("scalajs") .action((x, c) => c.mapConversion(cc => cc.copy(versions = cc.versions.copy(scalaJs = x)))) diff --git a/utils/src/main/scala/org/scalablytyped/converter/Selection.scala b/core/src/main/scala/org/scalablytyped/converter/Selection.scala similarity index 86% rename from utils/src/main/scala/org/scalablytyped/converter/Selection.scala rename to core/src/main/scala/org/scalablytyped/converter/Selection.scala index ad71c37492..002bc0e0be 100644 --- a/utils/src/main/scala/org/scalablytyped/converter/Selection.scala +++ b/core/src/main/scala/org/scalablytyped/converter/Selection.scala @@ -1,5 +1,7 @@ package org.scalablytyped.converter +import io.circe013.{Decoder, Encoder} + import scala.collection.immutable.{SortedSet, TreeSet} sealed trait Selection[T] { @@ -47,4 +49,6 @@ object Selection { final case class Or[T](_1: Selection[T], _2: Selection[T]) extends Selection[T] + implicit def encodes[T: Encoder: Ordering]: Encoder[Selection[T]] = io.circe013.generic.semiauto.deriveEncoder + implicit def decodes[T: Decoder: Ordering]: Decoder[Selection[T]] = io.circe013.generic.semiauto.deriveDecoder } diff --git a/core/src/main/scala/org/scalablytyped/converter/internal/Comment.scala b/core/src/main/scala/org/scalablytyped/converter/internal/Comment.scala new file mode 100644 index 0000000000..f15e7b9a9a --- /dev/null +++ b/core/src/main/scala/org/scalablytyped/converter/internal/Comment.scala @@ -0,0 +1,48 @@ +package org.scalablytyped.converter.internal + +import io.circe013.{Decoder, Encoder} +import org.scalablytyped.converter.internal.scalajs.{ExprTree, QualifiedName, TypeRef} +import org.scalablytyped.converter.internal.ts.TsIdentModule + +sealed trait Comment + +/* We need a few pieces of out of band information bundled within the tree, + to be used like annotations. Instead of actually inventing annotations on + the typescript side we rather just work with special comments. + */ +sealed trait Marker extends Comment + +object Marker { + case object CouldBeScalaJsDefined extends Marker + case object IsTrivial extends Marker + case object ExpandedCallables extends Marker + case object ExpandedClass extends Marker + case object EnumObject extends Marker + case class NameHint(value: String) extends Marker + case class ModuleAliases(aliases: IArray[TsIdentModule]) extends Marker + case class WasLiteral(lit: ExprTree.Lit) extends Marker + case class WasUnion(related: IArray[TypeRef]) extends Marker + + /* Disable the minimizer for object with this marker */ + final case class MinimizationKeep(related: IArray[TypeRef]) extends Marker + + /* Similar to above, but it's conditional. If the object with this marker is included, only then include the related objects as well */ + final case class MinimizationRelated(related: IArray[TypeRef]) extends Marker + + case class WasDefaulted(among: Set[QualifiedName]) extends Marker + + case object ManglerLeaveAlone extends Marker + case object ManglerWasJsNative extends Marker +} + +object Comment { + final case class Raw(raw: String) extends Comment + + def apply(raw: String): Comment = Comment.Raw(raw) + + def warning(s: String)(implicit e: sourcecode.Enclosing): Comment = + Comment(s"/* import warning: ${e.value.split("\\.").takeRight(2).mkString(".")} $s */") + + implicit lazy val encodes: Encoder[Comment] = io.circe013.generic.semiauto.deriveEncoder + implicit lazy val decodes: Decoder[Comment] = io.circe013.generic.semiauto.deriveDecoder +} diff --git a/utils/src/main/scala/org/scalablytyped/converter/internal/comments.scala b/core/src/main/scala/org/scalablytyped/converter/internal/Comments.scala similarity index 77% rename from utils/src/main/scala/org/scalablytyped/converter/internal/comments.scala rename to core/src/main/scala/org/scalablytyped/converter/internal/Comments.scala index bbdddb74ef..6d73683bba 100644 --- a/utils/src/main/scala/org/scalablytyped/converter/internal/comments.scala +++ b/core/src/main/scala/org/scalablytyped/converter/internal/Comments.scala @@ -1,38 +1,26 @@ package org.scalablytyped.converter.internal -import scala.collection.mutable -import seqs._ +import io.circe013.{Decoder, Encoder} +import org.scalablytyped.converter.internal.seqs._ +import scala.collection.mutable import scala.reflect.ClassTag -sealed trait Comment -final case class CommentRaw(raw: String) extends Comment -final case class CommentData(data: Comment.Data) extends Comment - -object Comment { - trait Data - - def apply(raw: String): Comment = CommentRaw(raw) - - def warning(s: String)(implicit e: sourcecode.Enclosing): Comment = - Comment(s"/* import warning: ${e.value.split("\\.").takeRight(2).mkString(".")} $s */") -} - @SerialVersionUID(8167323919307012581L) // something about this class seems brittle sealed class Comments(val cs: List[Comment]) extends Serializable { - def rawCs = cs.collect { case CommentRaw(raw) => raw } + def rawCs = cs.collect { case Comment.Raw(raw) => raw } - def extract[T](pf: PartialFunction[Comment.Data, T]): Option[(T, Comments)] = + def extract[T](pf: PartialFunction[Marker, T]): Option[(T, Comments)] = cs.partitionCollect { - case CommentData(data) if pf.isDefinedAt(data) => pf(data) + case marker: Marker if pf.isDefinedAt(marker) => pf(marker) } match { case (Nil, _) => None case (some, rest) => Some((some.head, Comments(rest))) } - def has[T <: Comment.Data: ClassTag]: Boolean = + def has[T <: Marker: ClassTag]: Boolean = cs.exists { - case CommentData(_: T) => true + case _: T => true case _ => false } @@ -80,6 +68,9 @@ case object NoComments extends Comments(Nil) { } object Comments { + implicit val encodes: Encoder[Comments] = Encoder[List[Comment]].contramap(_.cs) + implicit val decodes: Decoder[Comments] = Decoder[List[Comment]].map(Comments.apply) + def apply(h: String, tail: String*): Comments = new Comments(Comment(h) +: tail.map(Comment.apply).toList) @@ -119,4 +110,5 @@ object Comments { def format(comments: Comments, keepComments: Boolean): String = if (keepComments) format(comments) else "" + } diff --git a/utils/src/main/scala/org/scalablytyped/converter/internal/Digest.scala b/core/src/main/scala/org/scalablytyped/converter/internal/Digest.scala similarity index 100% rename from utils/src/main/scala/org/scalablytyped/converter/internal/Digest.scala rename to core/src/main/scala/org/scalablytyped/converter/internal/Digest.scala diff --git a/utils/src/main/scala/org/scalablytyped/converter/internal/EscapeStrings.scala b/core/src/main/scala/org/scalablytyped/converter/internal/EscapeStrings.scala similarity index 100% rename from utils/src/main/scala/org/scalablytyped/converter/internal/EscapeStrings.scala rename to core/src/main/scala/org/scalablytyped/converter/internal/EscapeStrings.scala diff --git a/utils/src/main/scala/org/scalablytyped/converter/internal/IArray.scala b/core/src/main/scala/org/scalablytyped/converter/internal/IArray.scala similarity index 98% rename from utils/src/main/scala/org/scalablytyped/converter/internal/IArray.scala rename to core/src/main/scala/org/scalablytyped/converter/internal/IArray.scala index 03cc232581..5003671985 100644 --- a/utils/src/main/scala/org/scalablytyped/converter/internal/IArray.scala +++ b/core/src/main/scala/org/scalablytyped/converter/internal/IArray.scala @@ -2,6 +2,7 @@ package org.scalablytyped.converter.internal import java.util +import io.circe013.{Decoder, Encoder} import org.scalablytyped.converter.internal.IArray.fromArrayAndSize import scala.collection.immutable.{Range, SortedSet} @@ -9,6 +10,12 @@ import scala.collection.mutable.WrappedArray.ofRef import scala.collection.{immutable, mutable, GenTraversableOnce, Iterator} object IArray { + implicit def IArrayEncoder[T <: AnyRef: Encoder]: Encoder[IArray[T]] = + Encoder[List[T]].contramap[IArray[T]](_.toList) + + implicit def IArrayDecoder[T <: AnyRef: Decoder]: Decoder[IArray[T]] = + Decoder[List[T]].map[IArray[T]](IArray.fromTraversable) + def apply[A <: AnyRef](as: A*): IArray[A] = as match { case x: ofRef[A] => fromArray(x.array) diff --git a/utils/src/main/scala/org/scalablytyped/converter/internal/Json.scala b/core/src/main/scala/org/scalablytyped/converter/internal/Json.scala similarity index 100% rename from utils/src/main/scala/org/scalablytyped/converter/internal/Json.scala rename to core/src/main/scala/org/scalablytyped/converter/internal/Json.scala diff --git a/utils/src/main/scala/org/scalablytyped/converter/internal/Key.scala b/core/src/main/scala/org/scalablytyped/converter/internal/Key.scala similarity index 100% rename from utils/src/main/scala/org/scalablytyped/converter/internal/Key.scala rename to core/src/main/scala/org/scalablytyped/converter/internal/Key.scala diff --git a/utils/src/main/scala/org/scalablytyped/converter/internal/LibraryVersion.scala b/core/src/main/scala/org/scalablytyped/converter/internal/LibraryVersion.scala similarity index 100% rename from utils/src/main/scala/org/scalablytyped/converter/internal/LibraryVersion.scala rename to core/src/main/scala/org/scalablytyped/converter/internal/LibraryVersion.scala diff --git a/utils/src/main/scala/org/scalablytyped/converter/internal/ProtectionLevel.scala b/core/src/main/scala/org/scalablytyped/converter/internal/ProtectionLevel.scala similarity index 51% rename from utils/src/main/scala/org/scalablytyped/converter/internal/ProtectionLevel.scala rename to core/src/main/scala/org/scalablytyped/converter/internal/ProtectionLevel.scala index 379aacec7a..c9d9c67c2f 100644 --- a/utils/src/main/scala/org/scalablytyped/converter/internal/ProtectionLevel.scala +++ b/core/src/main/scala/org/scalablytyped/converter/internal/ProtectionLevel.scala @@ -1,9 +1,14 @@ package org.scalablytyped.converter.internal +import io.circe013.{Decoder, Encoder} + sealed trait ProtectionLevel object ProtectionLevel { case object Default extends ProtectionLevel case object Private extends ProtectionLevel case object Protected extends ProtectionLevel + + implicit val encodes: Encoder[ProtectionLevel] = io.circe013.generic.semiauto.deriveEncoder + implicit val decodes: Decoder[ProtectionLevel] = io.circe013.generic.semiauto.deriveDecoder } diff --git a/utils/src/main/scala/org/scalablytyped/converter/internal/Suffix.scala b/core/src/main/scala/org/scalablytyped/converter/internal/Suffix.scala similarity index 100% rename from utils/src/main/scala/org/scalablytyped/converter/internal/Suffix.scala rename to core/src/main/scala/org/scalablytyped/converter/internal/Suffix.scala diff --git a/utils/src/main/scala/org/scalablytyped/converter/internal/constants.scala b/core/src/main/scala/org/scalablytyped/converter/internal/constants.scala similarity index 100% rename from utils/src/main/scala/org/scalablytyped/converter/internal/constants.scala rename to core/src/main/scala/org/scalablytyped/converter/internal/constants.scala diff --git a/utils/src/main/scala/org/scalablytyped/converter/internal/environment.scala b/core/src/main/scala/org/scalablytyped/converter/internal/environment.scala similarity index 100% rename from utils/src/main/scala/org/scalablytyped/converter/internal/environment.scala rename to core/src/main/scala/org/scalablytyped/converter/internal/environment.scala diff --git a/utils/src/main/scala/org/scalablytyped/converter/internal/files.scala b/core/src/main/scala/org/scalablytyped/converter/internal/files.scala similarity index 93% rename from utils/src/main/scala/org/scalablytyped/converter/internal/files.scala rename to core/src/main/scala/org/scalablytyped/converter/internal/files.scala index fdd310c0c8..a8c39c0c59 100644 --- a/utils/src/main/scala/org/scalablytyped/converter/internal/files.scala +++ b/core/src/main/scala/org/scalablytyped/converter/internal/files.scala @@ -6,6 +6,7 @@ import java.nio.file.{Files, Path} import java.util import ammonite.ops.% +import io.circe013.{Decoder, Encoder} import org.scalablytyped.converter.internal.environment.OpSystem import scala.util.Try @@ -30,6 +31,10 @@ object InFile { final case class InFolder(path: os.Path) { def name: String = path.last } +object InFolder { + implicit val encodes: Encoder[InFolder] = orphanCodecs.PathEncoder.contramap(_.path) + implicit val decodes: Decoder[InFolder] = orphanCodecs.PathDecoder.map(InFolder.apply) +} trait Layout[F, V] { def all: Map[F, V] diff --git a/utils/src/main/scala/org/scalablytyped/converter/internal/maps.scala b/core/src/main/scala/org/scalablytyped/converter/internal/maps.scala similarity index 100% rename from utils/src/main/scala/org/scalablytyped/converter/internal/maps.scala rename to core/src/main/scala/org/scalablytyped/converter/internal/maps.scala diff --git a/utils/src/main/scala/org/scalablytyped/converter/internal/nameVariants.scala b/core/src/main/scala/org/scalablytyped/converter/internal/nameVariants.scala similarity index 100% rename from utils/src/main/scala/org/scalablytyped/converter/internal/nameVariants.scala rename to core/src/main/scala/org/scalablytyped/converter/internal/nameVariants.scala diff --git a/core/src/main/scala/org/scalablytyped/converter/internal/orphanCodecs.scala b/core/src/main/scala/org/scalablytyped/converter/internal/orphanCodecs.scala new file mode 100644 index 0000000000..8dcd9e116a --- /dev/null +++ b/core/src/main/scala/org/scalablytyped/converter/internal/orphanCodecs.scala @@ -0,0 +1,25 @@ +package org.scalablytyped.converter.internal + +import java.io.File +import java.net.URI + +import io.circe013.{Decoder, Encoder} + +import scala.collection.immutable.{SortedSet, TreeSet} + +object orphanCodecs { + implicit def SortedSetEncoder[T: Encoder: Ordering]: Encoder[SortedSet[T]] = + Encoder[Vector[T]].contramap[SortedSet[T]](x => x.toVector) + + implicit def SortedSetDecoder[T: Decoder: Ordering]: Decoder[SortedSet[T]] = + Decoder[Vector[T]].map[SortedSet[T]](ts => TreeSet.empty[T] ++ ts) + + implicit val FileEncoder: Encoder[File] = Encoder[String].contramap[File](_.toString) + implicit val FileDecoder: Decoder[File] = Decoder[String].map[File](new File(_)) + implicit val RelPathDecoder: Decoder[os.RelPath] = Decoder[String].map(str => os.RelPath(str.dropWhile(_ === '/'))) + implicit val RelPathEncoder: Encoder[os.RelPath] = Encoder[String].contramap[os.RelPath](_.toString) + implicit val PathDecoder: Decoder[os.Path] = Decoder[String].map(str => os.Path(str)) + implicit val PathEncoder: Encoder[os.Path] = Encoder[String].contramap[os.Path](_.toString) + implicit val URIDecoder: Decoder[URI] = Decoder[String].map(new URI(_)) + implicit val URIEncoder: Encoder[URI] = Encoder[String].contramap[URI](_.toString) +} diff --git a/utils/src/main/scala/org/scalablytyped/converter/internal/package.scala b/core/src/main/scala/org/scalablytyped/converter/internal/package.scala similarity index 100% rename from utils/src/main/scala/org/scalablytyped/converter/internal/package.scala rename to core/src/main/scala/org/scalablytyped/converter/internal/package.scala diff --git a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/Annotation.scala b/core/src/main/scala/org/scalablytyped/converter/internal/scalajs/Annotation.scala similarity index 72% rename from scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/Annotation.scala rename to core/src/main/scala/org/scalablytyped/converter/internal/scalajs/Annotation.scala index 91e6c84651..d40d004c24 100644 --- a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/Annotation.scala +++ b/core/src/main/scala/org/scalablytyped/converter/internal/scalajs/Annotation.scala @@ -1,6 +1,8 @@ package org.scalablytyped.converter.internal package scalajs +import io.circe013.{Decoder, Encoder} + sealed trait Annotation extends Product with Serializable sealed trait LocationAnnotation extends Annotation @@ -9,6 +11,9 @@ object Imported { case object Namespace extends Imported case object Default extends Imported case class Named(name: IArray[Name]) extends Imported + + implicit val encodes: Encoder[Imported] = io.circe013.generic.semiauto.deriveEncoder + implicit val decodes: Decoder[Imported] = io.circe013.generic.semiauto.deriveDecoder } object Annotation { @@ -24,6 +29,11 @@ object Annotation { case class JsImport(module: String, imported: Imported, global: Option[JsGlobal]) extends LocationAnnotation case class JsGlobal(name: QualifiedName) extends LocationAnnotation + object JsGlobal { + implicit val encodes: Encoder[JsGlobal] = io.circe013.generic.semiauto.deriveEncoder + implicit val decodes: Decoder[JsGlobal] = io.circe013.generic.semiauto.deriveDecoder + } + def renamedFrom(newName: Name)(oldAnnotations: IArray[Annotation]): IArray[Annotation] = { val (names, others) = oldAnnotations.partition { @@ -40,4 +50,7 @@ object Annotation { others ++ updatedNames } + + implicit lazy val encodes: Encoder[Annotation] = io.circe013.generic.semiauto.deriveEncoder + implicit lazy val decodes: Decoder[Annotation] = io.circe013.generic.semiauto.deriveDecoder } diff --git a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/ClassType.scala b/core/src/main/scala/org/scalablytyped/converter/internal/scalajs/ClassType.scala similarity index 76% rename from scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/ClassType.scala rename to core/src/main/scala/org/scalablytyped/converter/internal/scalajs/ClassType.scala index 88dd5209a9..a8959b8d10 100644 --- a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/ClassType.scala +++ b/core/src/main/scala/org/scalablytyped/converter/internal/scalajs/ClassType.scala @@ -1,6 +1,8 @@ package org.scalablytyped.converter.internal package scalajs +import io.circe013.{Decoder, Encoder} + sealed trait ClassType { import ClassType._ @@ -25,4 +27,7 @@ object ClassType { case object Class extends ClassType case object AbstractClass extends ClassType case object Trait extends ClassType + + implicit val encodes: Encoder[ClassType] = io.circe013.generic.semiauto.deriveEncoder + implicit val decodes: Decoder[ClassType] = io.circe013.generic.semiauto.deriveDecoder } diff --git a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/Name.scala b/core/src/main/scala/org/scalablytyped/converter/internal/scalajs/Name.scala similarity index 97% rename from scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/Name.scala rename to core/src/main/scala/org/scalablytyped/converter/internal/scalajs/Name.scala index 5830cb0dcb..7d85c23968 100644 --- a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/Name.scala +++ b/core/src/main/scala/org/scalablytyped/converter/internal/scalajs/Name.scala @@ -1,6 +1,8 @@ package org.scalablytyped.converter.internal package scalajs +import io.circe013.{Decoder, Encoder} + final case class Name(unescaped: String) { def withSuffix[T: ToSuffix](t: T): Name = new Name(unescaped + "_" + ToSuffix(t).unescaped) @@ -13,6 +15,9 @@ final case class Name(unescaped: String) { } object Name { + implicit val encodes: Encoder[Name] = Encoder[String].contramap(_.unescaped) + implicit val decodes: Decoder[Name] = Decoder[String].map(Name.apply) + val mod: Name = Name("mod") val std: Name = Name("std") val typings: Name = Name("typings") diff --git a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/QualifiedName.scala b/core/src/main/scala/org/scalablytyped/converter/internal/scalajs/QualifiedName.scala similarity index 95% rename from scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/QualifiedName.scala rename to core/src/main/scala/org/scalablytyped/converter/internal/scalajs/QualifiedName.scala index 7c978c1291..990a085acd 100644 --- a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/QualifiedName.scala +++ b/core/src/main/scala/org/scalablytyped/converter/internal/scalajs/QualifiedName.scala @@ -1,6 +1,9 @@ package org.scalablytyped.converter.internal package scalajs +import io.circe013.{Decoder, Encoder} +import io.circe013.generic.semiauto.{deriveDecoder, deriveEncoder} + final case class QualifiedName(parts: IArray[Name]) { def +(name: Name) = QualifiedName(parts :+ name) @@ -113,5 +116,7 @@ object QualifiedName { case n => scala_js + Name("Tuple" + n.toString) } - implicit val QualifiedNameSuffix: ToSuffix[QualifiedName] = t => ToSuffix(t.parts.last) + implicit val suffix: ToSuffix[QualifiedName] = t => ToSuffix(t.parts.last) + implicit val encodes: Encoder[QualifiedName] = deriveEncoder + implicit val decodes: Decoder[QualifiedName] = deriveDecoder } diff --git a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/ScalaNameEscape.scala b/core/src/main/scala/org/scalablytyped/converter/internal/scalajs/ScalaNameEscape.scala similarity index 100% rename from scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/ScalaNameEscape.scala rename to core/src/main/scala/org/scalablytyped/converter/internal/scalajs/ScalaNameEscape.scala diff --git a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/tree.scala b/core/src/main/scala/org/scalablytyped/converter/internal/scalajs/tree.scala similarity index 91% rename from scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/tree.scala rename to core/src/main/scala/org/scalablytyped/converter/internal/scalajs/tree.scala index e40f9d4b15..b6519182d3 100644 --- a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/tree.scala +++ b/core/src/main/scala/org/scalablytyped/converter/internal/scalajs/tree.scala @@ -1,6 +1,8 @@ package org.scalablytyped.converter.internal package scalajs +import io.circe013.{Decoder, Encoder} + import scala.util.hashing.MurmurHash3.productHash sealed trait Tree extends Product with Serializable { @@ -10,6 +12,11 @@ sealed trait Tree extends Product with Serializable { override lazy val hashCode: Int = productHash(this) } +object Tree { + implicit val encodes: Encoder[Tree] = io.circe013.generic.semiauto.deriveEncoder + implicit val decodes: Decoder[Tree] = io.circe013.generic.semiauto.deriveDecoder +} + sealed trait HasCodePath { val codePath: QualifiedName } @@ -49,7 +56,7 @@ sealed trait ContainerTree extends Tree with HasCodePath with HasAnnotations wit sealed trait InheritanceTree extends Tree with HasCodePath with HasAnnotations with HasMembers { def isScalaJsDefined: Boolean = annotations contains Annotation.ScalaJSDefined - def receivesCompanion: Boolean = isScalaJsDefined || comments.has[Markers.CouldBeScalaJsDefined.type] + def receivesCompanion: Boolean = isScalaJsDefined || comments.has[Marker.CouldBeScalaJsDefined.type] def isNative: Boolean = annotations.exists { @@ -179,6 +186,9 @@ final case class CtorTree(level: ProtectionLevel, params: IArray[ParamTree], com } object CtorTree { + implicit val encodes: Encoder[CtorTree] = io.circe013.generic.semiauto.deriveEncoder + implicit val decodes: Decoder[CtorTree] = io.circe013.generic.semiauto.deriveDecoder + val defaultPublic = CtorTree(ProtectionLevel.Default, IArray(), NoComments) val defaultProtected = CtorTree(ProtectionLevel.Protected, IArray(), NoComments) } @@ -195,7 +205,9 @@ object TypeParamTree { def asTypeArgs(tps: IArray[TypeParamTree]): IArray[TypeRef] = tps.map(x => TypeRef(x.name)) - implicit val TypeParamToSuffix: ToSuffix[TypeParamTree] = tp => ToSuffix(tp.name) +? tp.upperBound + implicit val suffix: ToSuffix[TypeParamTree] = tp => ToSuffix(tp.name) +? tp.upperBound + implicit val encodes: Encoder[TypeParamTree] = io.circe013.generic.semiauto.deriveEncoder + implicit val decodes: Decoder[TypeParamTree] = io.circe013.generic.semiauto.deriveDecoder } final case class ParamTree( @@ -207,6 +219,11 @@ final case class ParamTree( comments: Comments, ) extends Tree +object ParamTree { + implicit val encodes: Encoder[ParamTree] = io.circe013.generic.semiauto.deriveEncoder + implicit val decodes: Decoder[ParamTree] = io.circe013.generic.semiauto.deriveDecoder +} + final case class TypeRef(typeName: QualifiedName, targs: IArray[TypeRef], comments: Comments) extends Tree { override val name: Name = typeName.parts.last @@ -218,6 +235,10 @@ final case class TypeRef(typeName: QualifiedName, targs: IArray[TypeRef], commen } object TypeRef { + implicit val suffix: ToSuffix[TypeRef] = t => ToSuffix(t.typeName) ++ t.targs + implicit lazy val encodes: Encoder[TypeRef] = io.circe013.generic.semiauto.deriveEncoder + implicit lazy val decodes: Decoder[TypeRef] = io.circe013.generic.semiauto.deriveDecoder + def apply(n: Name): TypeRef = TypeRef(QualifiedName(IArray(n)), Empty, NoComments) def apply(qn: QualifiedName): TypeRef = @@ -494,23 +515,23 @@ object TypeRef { case _ => None } } - - implicit val TypeRefSuffix: ToSuffix[TypeRef] = - t => ToSuffix(t.typeName) ++ t.targs - - implicit val TypeRefOrdering: Ordering[TypeRef] = - Ordering.by[TypeRef, String](Printer.formatTypeRef(0)) } sealed trait ImplTree extends Tree { override val name: Name = Name("ImplTree") override val comments: Comments = NoComments } +object ImplTree { + implicit val encodes: Encoder[ImplTree] = io.circe013.generic.semiauto.deriveEncoder + implicit val decodes: Decoder[ImplTree] = io.circe013.generic.semiauto.deriveDecoder +} case object NotImplemented extends ImplTree sealed trait ExprTree extends ImplTree object ExprTree { + implicit val encodes: Encoder[ExprTree] = io.circe013.generic.semiauto.deriveEncoder + implicit val decodes: Decoder[ExprTree] = io.circe013.generic.semiauto.deriveDecoder val undefined = Ref(QualifiedName.scala_js + Name("undefined")) val native = Ref(QualifiedName.scala_js + Name("native")) @@ -544,6 +565,11 @@ object ExprTree { } } sealed trait Lit extends ExprTree + object Lit { + implicit val encodes: Encoder[Lit] = io.circe013.generic.semiauto.deriveEncoder + implicit val decodes: Decoder[Lit] = io.circe013.generic.semiauto.deriveDecoder + } + case class BooleanLit(value: Boolean) extends Lit case class NumberLit(value: String) extends Lit case class StringLit(value: String) extends Lit @@ -555,6 +581,8 @@ object ExprTree { case class Variable(expr: ExprTree) extends Arg implicit def fromExpr(expr: ExprTree): Arg = Pos(expr) implicit def fromTuple(t: (Name, ExprTree)): Arg = Named(t._1, t._2) + implicit val encodes: Encoder[Arg] = io.circe013.generic.semiauto.deriveEncoder + implicit val decodes: Decoder[Arg] = io.circe013.generic.semiauto.deriveDecoder } object Block { diff --git a/utils/src/main/scala/org/scalablytyped/converter/internal/seqs.scala b/core/src/main/scala/org/scalablytyped/converter/internal/seqs.scala similarity index 100% rename from utils/src/main/scala/org/scalablytyped/converter/internal/seqs.scala rename to core/src/main/scala/org/scalablytyped/converter/internal/seqs.scala diff --git a/utils/src/main/scala/org/scalablytyped/converter/internal/sets.scala b/core/src/main/scala/org/scalablytyped/converter/internal/sets.scala similarity index 100% rename from utils/src/main/scala/org/scalablytyped/converter/internal/sets.scala rename to core/src/main/scala/org/scalablytyped/converter/internal/sets.scala diff --git a/utils/src/main/scala/org/scalablytyped/converter/internal/stringUtils.scala b/core/src/main/scala/org/scalablytyped/converter/internal/stringUtils.scala similarity index 100% rename from utils/src/main/scala/org/scalablytyped/converter/internal/stringUtils.scala rename to core/src/main/scala/org/scalablytyped/converter/internal/stringUtils.scala diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/CodePath.scala b/core/src/main/scala/org/scalablytyped/converter/internal/ts/CodePath.scala similarity index 85% rename from ts/src/main/scala/org/scalablytyped/converter/internal/ts/CodePath.scala rename to core/src/main/scala/org/scalablytyped/converter/internal/ts/CodePath.scala index 8a5afe769e..0f118fb7df 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/CodePath.scala +++ b/core/src/main/scala/org/scalablytyped/converter/internal/ts/CodePath.scala @@ -1,11 +1,6 @@ package org.scalablytyped.converter.internal package ts -trait HasCodePath { - def codePath: CodePath - def withCodePath(newCodePath: CodePath): HasCodePath -} - sealed trait CodePath { def forceHasPath: CodePath.HasPath = get.getOrElse(sys.error("Expected code path")) @@ -27,11 +22,16 @@ sealed trait CodePath { } object CodePath { + trait Has { + def codePath: CodePath + def withCodePath(newCodePath: CodePath): CodePath.Has + } + case object NoPath extends CodePath { def +(ident: TsIdent): NoPath.type = NoPath } - case class HasPath private (inLibrary: TsIdent, codePathPart: TsQIdent) extends CodePath { + case class HasPath(inLibrary: TsIdent, codePathPart: TsQIdent) extends CodePath { lazy val codePath: TsQIdent = TsQIdent(inLibrary +: codePathPart.parts) diff --git a/core/src/main/scala/org/scalablytyped/converter/internal/ts/Directive.scala b/core/src/main/scala/org/scalablytyped/converter/internal/ts/Directive.scala new file mode 100644 index 0000000000..f4f8af048e --- /dev/null +++ b/core/src/main/scala/org/scalablytyped/converter/internal/ts/Directive.scala @@ -0,0 +1,37 @@ +package org.scalablytyped.converter.internal +package ts + +sealed trait Directive + +object Directive { + case object NoStdLib extends Directive + + sealed trait Ref extends Directive { + def stringPath: String + } + + /** + * The path in + * /// + */ + final case class PathRef(stringPath: String) extends Ref + + /** + * The types ref in + * /// + */ + final case class TypesRef(stringPath: String) extends Ref + + /** + * The ref in + * /// + */ + final case class LibRef(stringPath: String) extends Ref + + /** + * The ref in + * /// + */ + final case class AmdModule(stringPath: String) extends Ref + +} diff --git a/core/src/main/scala/org/scalablytyped/converter/internal/ts/ExportType.scala b/core/src/main/scala/org/scalablytyped/converter/internal/ts/ExportType.scala new file mode 100644 index 0000000000..d8775bc5e3 --- /dev/null +++ b/core/src/main/scala/org/scalablytyped/converter/internal/ts/ExportType.scala @@ -0,0 +1,11 @@ +package org.scalablytyped.converter.internal.ts + +sealed trait ExportType + +object ExportType { + val NotNamed: Set[ExportType] = Set(ExportType.Namespaced, ExportType.Defaulted) + + case object Named extends ExportType + case object Defaulted extends ExportType + case object Namespaced extends ExportType +} diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/JsLocation.scala b/core/src/main/scala/org/scalablytyped/converter/internal/ts/JsLocation.scala similarity index 73% rename from ts/src/main/scala/org/scalablytyped/converter/internal/ts/JsLocation.scala rename to core/src/main/scala/org/scalablytyped/converter/internal/ts/JsLocation.scala index a712d15218..4e480567f9 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/JsLocation.scala +++ b/core/src/main/scala/org/scalablytyped/converter/internal/ts/JsLocation.scala @@ -24,31 +24,12 @@ sealed trait JsLocation { } } -sealed trait ModuleSpec { - def +(tsIdent: TsIdent): ModuleSpec = - if (tsIdent === TsIdent.namespaced) this - else - this match { - case ModuleSpec.Defaulted => ModuleSpec.Specified(IArray(TsIdent.default, tsIdent)) - case ModuleSpec.Namespaced => ModuleSpec.Specified(IArray(tsIdent)) - case ModuleSpec.Specified(is) => ModuleSpec.Specified(is :+ tsIdent) - } -} - -object ModuleSpec { - def apply(ident: TsIdent): ModuleSpec = - ident match { - case TsIdent.default => Defaulted - case TsIdent.namespaced => Namespaced - case other => Specified(IArray(other)) - } - - case object Defaulted extends ModuleSpec - case object Namespaced extends ModuleSpec - final case class Specified(tsIdents: IArray[TsIdent]) extends ModuleSpec -} - object JsLocation { + trait Has { + def jsLocation: JsLocation + def withJsLocation(newLocation: JsLocation): JsLocation.Has + } + case object Zero extends JsLocation { override def /(tree: TsTree): JsLocation = tree match { @@ -81,7 +62,7 @@ object JsLocation { } } - case class Both private (module: Module, global: Global) extends JsLocation { + case class Both(module: Module, global: Global) extends JsLocation { override def /(tree: TsTree): JsLocation = global / tree match { case g: Global => Both(module / tree, g) diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/MemberCache.scala b/core/src/main/scala/org/scalablytyped/converter/internal/ts/MemberCache.scala similarity index 95% rename from ts/src/main/scala/org/scalablytyped/converter/internal/ts/MemberCache.scala rename to core/src/main/scala/org/scalablytyped/converter/internal/ts/MemberCache.scala index 0a83a95347..6ec5965af2 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/MemberCache.scala +++ b/core/src/main/scala/org/scalablytyped/converter/internal/ts/MemberCache.scala @@ -21,7 +21,7 @@ trait MemberCache { lazy val isModule: Boolean = exports.nonEmpty || imports.exists { - case TsImport(_, _, _: TsImporteeLocal) => false + case TsImport(_, _, _: TsImportee.Local) => false case _ => true } @@ -45,7 +45,7 @@ trait MemberCache { } case x: TsNamedDecl => ret(x.name) = x :: ret.getOrElseUpdate(x.name, Nil) - case TsExport(_, _, _, TsExporteeTree(x: TsNamedDecl)) => + case TsExport(_, _, _, TsExportee.Tree(x: TsNamedDecl)) => ret(x.name) = x :: ret.getOrElseUpdate(x.name, Nil) case _ => () } diff --git a/core/src/main/scala/org/scalablytyped/converter/internal/ts/MethodType.scala b/core/src/main/scala/org/scalablytyped/converter/internal/ts/MethodType.scala new file mode 100644 index 0000000000..407b017634 --- /dev/null +++ b/core/src/main/scala/org/scalablytyped/converter/internal/ts/MethodType.scala @@ -0,0 +1,8 @@ +package org.scalablytyped.converter.internal.ts + +sealed trait MethodType +object MethodType { + case object Normal extends MethodType + case object Getter extends MethodType + case object Setter extends MethodType +} diff --git a/core/src/main/scala/org/scalablytyped/converter/internal/ts/ModuleSpec.scala b/core/src/main/scala/org/scalablytyped/converter/internal/ts/ModuleSpec.scala new file mode 100644 index 0000000000..ace7f1beb6 --- /dev/null +++ b/core/src/main/scala/org/scalablytyped/converter/internal/ts/ModuleSpec.scala @@ -0,0 +1,26 @@ +package org.scalablytyped.converter.internal +package ts + +sealed trait ModuleSpec { + def +(tsIdent: TsIdent): ModuleSpec = + if (tsIdent === TsIdent.namespaced) this + else + this match { + case ModuleSpec.Defaulted => ModuleSpec.Specified(IArray(TsIdent.default, tsIdent)) + case ModuleSpec.Namespaced => ModuleSpec.Specified(IArray(tsIdent)) + case ModuleSpec.Specified(is) => ModuleSpec.Specified(is :+ tsIdent) + } +} + +object ModuleSpec { + def apply(ident: TsIdent): ModuleSpec = + ident match { + case TsIdent.default => Defaulted + case TsIdent.namespaced => Namespaced + case other => Specified(IArray(other)) + } + + case object Defaulted extends ModuleSpec + case object Namespaced extends ModuleSpec + final case class Specified(tsIdents: IArray[TsIdent]) extends ModuleSpec +} diff --git a/core/src/main/scala/org/scalablytyped/converter/internal/ts/OptionalModifier.scala b/core/src/main/scala/org/scalablytyped/converter/internal/ts/OptionalModifier.scala new file mode 100644 index 0000000000..231a3184bd --- /dev/null +++ b/core/src/main/scala/org/scalablytyped/converter/internal/ts/OptionalModifier.scala @@ -0,0 +1,20 @@ +package org.scalablytyped.converter.internal.ts + +sealed trait OptionalModifier { + def apply(tpe: TsType): TsType = + this match { + case OptionalModifier.Noop => tpe + case OptionalModifier.Optionalize => OptionalType(tpe) + case OptionalModifier.Deoptionalize => + tpe match { + case OptionalType(rest) => rest + case other => other + } + } +} + +object OptionalModifier { + case object Noop extends OptionalModifier + case object Optionalize extends OptionalModifier + case object Deoptionalize extends OptionalModifier +} diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/OptionalType.scala b/core/src/main/scala/org/scalablytyped/converter/internal/ts/OptionalType.scala similarity index 100% rename from ts/src/main/scala/org/scalablytyped/converter/internal/ts/OptionalType.scala rename to core/src/main/scala/org/scalablytyped/converter/internal/ts/OptionalType.scala diff --git a/core/src/main/scala/org/scalablytyped/converter/internal/ts/ReadonlyModifier.scala b/core/src/main/scala/org/scalablytyped/converter/internal/ts/ReadonlyModifier.scala new file mode 100644 index 0000000000..45e6909d31 --- /dev/null +++ b/core/src/main/scala/org/scalablytyped/converter/internal/ts/ReadonlyModifier.scala @@ -0,0 +1,16 @@ +package org.scalablytyped.converter.internal.ts + +sealed trait ReadonlyModifier { + def apply(wasReadonly: Boolean): Boolean = + this match { + case ReadonlyModifier.Noop => wasReadonly + case ReadonlyModifier.Yes => true + case ReadonlyModifier.No => false + } +} + +object ReadonlyModifier { + case object Noop extends ReadonlyModifier + case object Yes extends ReadonlyModifier + case object No extends ReadonlyModifier +} diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/TsExpr.scala b/core/src/main/scala/org/scalablytyped/converter/internal/ts/TsExpr.scala similarity index 64% rename from ts/src/main/scala/org/scalablytyped/converter/internal/ts/TsExpr.scala rename to core/src/main/scala/org/scalablytyped/converter/internal/ts/TsExpr.scala index c35073a0ac..963419dffe 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/TsExpr.scala +++ b/core/src/main/scala/org/scalablytyped/converter/internal/ts/TsExpr.scala @@ -15,17 +15,17 @@ object TsExpr { def format(expr: TsExpr): String = expr match { - case Ref(value) => TsTypeFormatter.qident(value) - case Literal(TsLiteralString(value)) => stringUtils.quote(value) + case Ref(value) => TsTypeFormatter.qident(value) + case Literal(TsLiteral.Str(value)) => stringUtils.quote(value) case Literal(Num.Long(long)) => if (long > Int.MaxValue) long + ".0" // long's wont work in scala.js, so we'll just YOLO this else long.toString - case Literal(TsLiteralNumber(value)) => value - case Literal(TsLiteralBoolean(value)) => value.toString - case Call(function, params) => s"${format(function)}(${params.map(format).mkString(", ")})" - case Unary(op, expr) => s"$op${format(expr)}" - case BinaryOp(one, op, two) => s"${format(one)} $op ${format(two)}" - case Cast(expr, tpe) => s"${format(expr)} as ${TsTypeFormatter(tpe)}" + case Literal(TsLiteral.Num(value)) => value + case Literal(TsLiteral.Bool(value)) => value.toString + case Call(function, params) => s"${format(function)}(${params.map(format).mkString(", ")})" + case Unary(op, expr) => s"$op${format(expr)}" + case BinaryOp(one, op, two) => s"${format(one)} $op ${format(two)}" + case Cast(expr, tpe) => s"${format(expr)} as ${TsTypeFormatter(tpe)}" } object Num { @@ -37,7 +37,7 @@ object TsExpr { def unapply(x: TsLiteral): Option[BigDecimal] = x match { - case TsLiteralNumber(value) if value.forall(c => c.isDigit || c === '.') => Some(BigDecimal(value)) + case TsLiteral.Num(value) if value.forall(c => c.isDigit || c === '.') => Some(BigDecimal(value)) case _ => None } @@ -49,7 +49,7 @@ object TsExpr { } def unapply(x: TsLiteral): Option[Long] = x match { - case TsLiteralNumber(value) if value.forall(c => c.isDigit) => Some(value.toLong) + case TsLiteral.Num(value) if value.forall(c => c.isDigit) => Some(value.toLong) case _ => None } } @@ -65,13 +65,13 @@ object TsExpr { case BinaryOp(e1, op, e2) => (typeOf(e1), op, typeOf(e2)) match { case (Num(n1), "+", Num(n2)) => - TsTypeLiteral(TsLiteralNumber((n1 + n2).toString)) + TsTypeLiteral(TsLiteral.Num((n1 + n2).toString)) case (Num(n1), "*", Num(n2)) => - TsTypeLiteral(TsLiteralNumber((n1 * n2).toString)) + TsTypeLiteral(TsLiteral.Num((n1 * n2).toString)) case (Num.Long(n1), "<<", Num.Long(n2)) => - TsTypeLiteral(TsLiteralNumber((n1 << n2).toString)) + TsTypeLiteral(TsLiteral.Num((n1 << n2).toString)) case (Num.Long(n1), ">>", Num.Long(n2)) => - TsTypeLiteral(TsLiteralNumber((n1 >> n2).toString)) + TsTypeLiteral(TsLiteral.Num((n1 >> n2).toString)) case (t, _, _) => widen(t) } } @@ -84,12 +84,12 @@ object TsExpr { def widen(tpe: TsType): TsType = tpe match { - case TsTypeLiteral(TsLiteralString(_)) => TsTypeRef.string - case TsTypeLiteral(TsLiteralNumber(_)) => TsTypeRef.number - case TsTypeLiteral(TsLiteralBoolean(_)) => TsTypeRef.boolean - case TsTypeRef.string => TsTypeRef.string - case TsTypeRef.number => TsTypeRef.number - case _ => Default + case TsTypeLiteral(TsLiteral.Str(_)) => TsTypeRef.string + case TsTypeLiteral(TsLiteral.Num(_)) => TsTypeRef.number + case TsTypeLiteral(TsLiteral.Bool(_)) => TsTypeRef.boolean + case TsTypeRef.string => TsTypeRef.string + case TsTypeRef.number => TsTypeRef.number + case _ => Default } def visit(e: TsExpr)(f: TsExpr => TsExpr): TsExpr = diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/TsTypeFormatter.scala b/core/src/main/scala/org/scalablytyped/converter/internal/ts/TsTypeFormatter.scala similarity index 95% rename from ts/src/main/scala/org/scalablytyped/converter/internal/ts/TsTypeFormatter.scala rename to core/src/main/scala/org/scalablytyped/converter/internal/ts/TsTypeFormatter.scala index 271a814be2..6ab8fe9ad5 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/TsTypeFormatter.scala +++ b/core/src/main/scala/org/scalablytyped/converter/internal/ts/TsTypeFormatter.scala @@ -77,8 +77,8 @@ class TsTypeFormatter(val keepComments: Boolean) { if (isReadOnly) Some("readonly") else None, level(l), Some(indexing match { - case IndexingDict(name, tpe) => s"[${name.value}: ${apply(tpe)}]" - case IndexingSingle(name) => s"[${qident(name)}]" + case Indexing.Dict(name, tpe) => s"[${name.value}: ${apply(tpe)}]" + case Indexing.Single(name) => s"[${qident(name)}]" }), valueType.map(tpe => s": ${apply(tpe)}"), ).flatten.mkString(" ").replaceAllLiterally(" ?", "?") @@ -108,9 +108,9 @@ class TsTypeFormatter(val keepComments: Boolean) { } def lit(lit: TsLiteral): String = lit match { - case TsLiteralString(str) => s"'$str'" - case TsLiteralBoolean(bool) => bool.toString - case TsLiteralNumber(num) => num + case TsLiteral.Str(str) => s"'$str'" + case TsLiteral.Bool(bool) => bool.toString + case TsLiteral.Num(num) => num } def tupleElement(elem: TsTupleElement): String = { diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/trees.scala b/core/src/main/scala/org/scalablytyped/converter/internal/ts/trees.scala similarity index 84% rename from ts/src/main/scala/org/scalablytyped/converter/internal/ts/trees.scala rename to core/src/main/scala/org/scalablytyped/converter/internal/ts/trees.scala index 07d3a86d48..1928dab1a2 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/trees.scala +++ b/core/src/main/scala/org/scalablytyped/converter/internal/ts/trees.scala @@ -1,8 +1,7 @@ package org.scalablytyped.converter.internal package ts -import com.olvind.logging.Formatter -import org.scalablytyped.converter.internal.ts.transforms.ExtractInterfaces +import io.circe013.{Decoder, Encoder, KeyDecoder, KeyEncoder} import scala.util.hashing.MurmurHash3.productHash @@ -27,13 +26,13 @@ sealed trait TsContainerOrDecl extends TsTree sealed trait TsDecl extends TsContainerOrDecl -sealed trait TsContainer extends TsContainerOrDecl with MemberCache with HasCodePath { +sealed trait TsContainer extends TsContainerOrDecl with MemberCache with CodePath.Has { def members: IArray[TsContainerOrDecl] def withMembers(newMembers: IArray[TsContainerOrDecl]): TsContainer } -sealed trait TsNamedDecl extends TsDecl with HasCodePath { +sealed trait TsNamedDecl extends TsDecl with CodePath.Has { val comments: Comments def withComments(cs: Comments): TsNamedDecl final def addComment(c: Comment) = withComments(comments + c) @@ -53,17 +52,18 @@ final case class TsParsedFile( lazy val isStdLib: Boolean = directives.exists { - case DirectiveNoStdLib => true - case _ => false + case Directive.NoStdLib => true + case _ => false } override def withMembers(newMembers: IArray[TsContainerOrDecl]): TsParsedFile = copy(members = newMembers) - override def withCodePath(newCodePath: CodePath): HasCodePath = copy(codePath = newCodePath) + override def withCodePath(newCodePath: CodePath): CodePath.Has = copy(codePath = newCodePath) } -sealed trait TsDeclNamespaceOrModule extends TsContainer with TsNamedValueDecl with HasJsLocation +sealed trait TsDeclNamespaceOrModule extends TsContainer with TsNamedValueDecl with JsLocation.Has + sealed trait TsDeclModuleLike extends TsDeclNamespaceOrModule final case class TsDeclNamespace( @@ -146,11 +146,11 @@ final case class TsGlobal( members: IArray[TsContainerOrDecl], codePath: CodePath, ) extends TsContainer - with HasCodePath { + with CodePath.Has { override def withMembers(newMembers: IArray[TsContainerOrDecl]): TsGlobal = copy(members = newMembers) - override def withCodePath(newCodePath: CodePath): HasCodePath = copy(codePath = newCodePath) + override def withCodePath(newCodePath: CodePath): CodePath.Has = copy(codePath = newCodePath) } final case class TsDeclClass( @@ -165,7 +165,7 @@ final case class TsDeclClass( jsLocation: JsLocation, codePath: CodePath, ) extends TsNamedValueDecl - with HasJsLocation + with JsLocation.Has with HasClassMembers with TsNamedDecl { @@ -216,7 +216,7 @@ final case class TsDeclEnum( jsLocation: JsLocation, codePath: CodePath, ) extends TsNamedValueDecl - with HasJsLocation + with JsLocation.Has with TsNamedDecl { override def withCodePath(newCodePath: CodePath): TsDeclEnum = @@ -245,7 +245,7 @@ final case class TsDeclVar( jsLocation: JsLocation, codePath: CodePath, ) extends TsNamedValueDecl - with HasJsLocation + with JsLocation.Has with TsNamedDecl { override def withCodePath(newCodePath: CodePath): TsDeclVar = @@ -269,7 +269,7 @@ final case class TsDeclFunction( jsLocation: JsLocation, codePath: CodePath, ) extends TsNamedValueDecl - with HasJsLocation + with JsLocation.Has with TsNamedDecl { override def withCodePath(newCodePath: CodePath): TsDeclFunction = @@ -334,21 +334,18 @@ object TsTypeParam { def asTypeArgs(tps: IArray[TsTypeParam]): IArray[TsTypeRef] = tps.map(tp => TsTypeRef(tp.name)) } -// terms - -sealed trait TsTerm extends TsTree -sealed abstract class TsLiteral(repr: String) extends TsTerm { +sealed abstract class TsLiteral(repr: String) extends TsTree { val literal = repr } -final case class TsLiteralNumber(value: String) extends TsLiteral(value) - -final case class TsLiteralString(value: String) extends TsLiteral(value) - -final case class TsLiteralBoolean(value: Boolean) extends TsLiteral(value.toString) +object TsLiteral { + final case class Num(value: String) extends TsLiteral(value) + final case class Str(value: String) extends TsLiteral(value) + final case class Bool(value: Boolean) extends TsLiteral(value.toString) +} -sealed trait TsIdent extends TsTerm { +sealed trait TsIdent extends TsTree { val value: String } @@ -358,8 +355,6 @@ final case class TsIdentImport(from: TsIdentModule) extends TsIdent { override val value: String = from.value } -final case class ModuleAliases(aliases: IArray[TsIdentModule]) extends Comment.Data - final case class TsIdentModule(scopeOpt: Option[String], fragments: List[String]) extends TsIdent { @deprecated("this doesnt really work for node", "") def inLibrary: TsIdentLibrary = @@ -386,6 +381,9 @@ final case class TsIdentModule(scopeOpt: Option[String], fragments: List[String] object TsIdentModule { def simple(s: String): TsIdentModule = TsIdentModule(None, s :: Nil) + + implicit val encodes: Encoder[TsIdentModule] = io.circe013.generic.semiauto.deriveEncoder + implicit val decodes: Decoder[TsIdentModule] = io.circe013.generic.semiauto.deriveDecoder } sealed trait TsIdentLibrary extends TsIdent { @@ -398,9 +396,14 @@ sealed trait TsIdentLibrary extends TsIdent { object TsIdentLibrary { implicit val ordering: Ordering[TsIdentLibrary] = Ordering[String].on[TsIdentLibrary](_.value) - - implicit val FormatterTsIdentLibrary: Formatter[TsIdentLibrary] = - i => i.value + implicit val TsIdentLibraryDecoder: Decoder[TsIdentLibrary] = + Decoder[String].map(TsIdentLibrary.apply) + implicit val TsIdentLibraryEncoder: Encoder[TsIdentLibrary] = + Encoder[String].contramap[TsIdentLibrary](_.value) + implicit val TsIdentLibraryKeyDec: KeyDecoder[TsIdentLibrary] = + KeyDecoder[String].map(TsIdentLibrary.apply) + implicit val TsIdentLibraryKeyEnc: KeyEncoder[TsIdentLibrary] = + KeyEncoder[String].contramap[TsIdentLibrary](_.value) val Scoped = "@([^/]+)/(.+)".r val Scoped__ = "(.+)__(.+)".r @@ -422,6 +425,11 @@ final case class TsIdentLibraryScoped(scope: String, name: String) extends TsIde } object TsIdent { + implicit val encodes: Encoder[TsIdent] = io.circe013.generic.semiauto.deriveEncoder + implicit val decodes: Decoder[TsIdent] = io.circe013.generic.semiauto.deriveDecoder + + implicit object TsIdentKey extends IsKey[TsIdent] + def apply(str: String): TsIdentSimple = TsIdentSimple(str) @@ -444,8 +452,6 @@ object TsIdent { val dummyLibrary: TsIdentLibrary = TsIdentLibrarySimple("dummyLibrary") val std: TsIdentLibrary = TsIdentLibrarySimple("std") val node: TsIdentLibrary = TsIdentLibrarySimple("node") - - implicit object TsIdentKey extends IsKey[TsIdent] } final case class TsQIdent(parts: IArray[TsIdent]) extends TsTree { @@ -457,6 +463,8 @@ final case class TsQIdent(parts: IArray[TsIdent]) extends TsTree { } object TsQIdent { + implicit val encodes: Encoder[TsQIdent] = io.circe013.generic.semiauto.deriveEncoder + implicit val decodes: Decoder[TsQIdent] = io.circe013.generic.semiauto.deriveDecoder def of(ss: String*) = TsQIdent(IArray.fromTraversable(ss.map(TsIdent.apply))) def of(tsIdent: TsIdent) = TsQIdent(IArray(tsIdent)) @@ -506,6 +514,14 @@ object TsQIdent { sealed abstract class TsType extends TsTree +object TsType { + def isTypeMapping(members: IArray[TsMember]): Boolean = + members match { + case IArray.exactlyOne(_: TsMemberTypeMapped) => true + case _ => false + } +} + final case class TsTypeRef(comments: Comments, name: TsQIdent, tparams: IArray[TsType]) extends TsType object TsTypeRef { @@ -559,7 +575,7 @@ final case class TsTypeLookup(from: TsType, key: TsType) extends TsType final case class TsTypeThis() extends TsType -final case class TsTypeIntersect private (types: IArray[TsType]) extends TsType +final case class TsTypeIntersect(types: IArray[TsType]) extends TsType object TsTypeIntersect { private def flatten(types: IArray[TsType]): IArray[TsType] = @@ -570,7 +586,7 @@ object TsTypeIntersect { def simplified(types: IArray[TsType]): TsType = { val withCombinedObjects = types.partitionCollect { - case x: TsTypeObject if !ExtractInterfaces.isTypeMapping(x.members) => x + case x: TsTypeObject if !TsType.isTypeMapping(x.members) => x } match { case (Empty, all) => all case (IArray.exactlyOne(_), _) => types // just keep order @@ -584,7 +600,7 @@ object TsTypeIntersect { } } -final case class TsTypeUnion private (types: IArray[TsType]) extends TsType +final case class TsTypeUnion(types: IArray[TsType]) extends TsType object TsTypeUnion { private def flatten(types: IArray[TsType]): IArray[TsType] = @@ -631,8 +647,10 @@ final case class TsMemberFunction( ) extends TsMember sealed trait Indexing extends TsTree -case class IndexingDict(name: TsIdent, tpe: TsType) extends Indexing -case class IndexingSingle(name: TsQIdent) extends Indexing +object Indexing { + case class Dict(name: TsIdent, tpe: TsType) extends Indexing + case class Single(name: TsQIdent) extends Indexing +} final case class TsMemberIndex( comments: Comments, @@ -642,40 +660,6 @@ final case class TsMemberIndex( valueType: Option[TsType], ) extends TsMember -sealed trait OptionalModifier { - def apply(tpe: TsType): TsType = - this match { - case OptionalModifier.Noop => tpe - case OptionalModifier.Optionalize => OptionalType(tpe) - case OptionalModifier.Deoptionalize => - tpe match { - case OptionalType(rest) => rest - case other => other - } - } -} - -object OptionalModifier { - case object Noop extends OptionalModifier - case object Optionalize extends OptionalModifier - case object Deoptionalize extends OptionalModifier -} - -sealed trait ReadonlyModifier { - def apply(wasReadonly: Boolean): Boolean = - this match { - case ReadonlyModifier.Noop => wasReadonly - case ReadonlyModifier.Yes => true - case ReadonlyModifier.No => false - } -} - -object ReadonlyModifier { - case object Noop extends ReadonlyModifier - case object Yes extends ReadonlyModifier - case object No extends ReadonlyModifier -} - final case class TsMemberTypeMapped( comments: Comments, level: ProtectionLevel, @@ -699,53 +683,30 @@ final case class TsMemberProperty( //imports sealed trait TsImported extends TsTree - -final case class TsImportedIdent(ident: TsIdentSimple) extends TsImported - -final case class TsImportedDestructured(idents: IArray[(TsIdent, Option[TsIdentSimple])]) extends TsImported - -final case class TsImportedStar(asOpt: Option[TsIdentSimple]) extends TsImported +object TsImported { + final case class Ident(ident: TsIdentSimple) extends TsImported + final case class Destructured(idents: IArray[(TsIdent, Option[TsIdentSimple])]) extends TsImported + final case class Star(asOpt: Option[TsIdentSimple]) extends TsImported +} sealed trait TsImportee extends TsTree - -final case class TsImporteeRequired(from: TsIdentModule) extends TsImportee - -final case class TsImporteeFrom(from: TsIdentModule) extends TsImportee - -final case class TsImporteeLocal(qident: TsQIdent) extends TsImportee +object TsImportee { + final case class Required(from: TsIdentModule) extends TsImportee + final case class From(from: TsIdentModule) extends TsImportee + final case class Local(qident: TsQIdent) extends TsImportee +} final case class TsImport(typeOnly: Boolean, imported: IArray[TsImported], from: TsImportee) extends TsDecl with TsTree //exports sealed trait TsExportee extends TsTree - -final case class TsExporteeNames(idents: IArray[(TsQIdent, Option[TsIdentSimple])], fromOpt: Option[TsIdentModule]) - extends TsExportee - -final case class TsExporteeTree(decl: TsDecl) extends TsExportee - -final case class TsExporteeStar(as: Option[TsIdentSimple], from: TsIdentModule) extends TsExportee - -sealed trait ExportType - -object ExportType { - val NotNamed: Set[ExportType] = Set(ExportType.Namespaced, ExportType.Defaulted) - - case object Named extends ExportType - - case object Defaulted extends ExportType - - case object Namespaced extends ExportType +object TsExportee { + case class Names(idents: IArray[(TsQIdent, Option[TsIdentSimple])], fromOpt: Option[TsIdentModule]) extends TsExportee + case class Tree(decl: TsDecl) extends TsExportee + case class Star(as: Option[TsIdentSimple], from: TsIdentModule) extends TsExportee } final case class TsExport(comments: Comments, typeOnly: Boolean, tpe: ExportType, exported: TsExportee) extends TsDecl final case class TsExportAsNamespace(ident: TsIdent) extends TsDecl - -sealed trait MethodType -object MethodType { - case object Normal extends MethodType - case object Getter extends MethodType - case object Setter extends MethodType -} diff --git a/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/AdaptiveNamingImport.scala b/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/AdaptiveNamingImport.scala index bdc1045b92..c4216c990e 100644 --- a/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/AdaptiveNamingImport.scala +++ b/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/AdaptiveNamingImport.scala @@ -37,8 +37,8 @@ object AdaptiveNamingImport { TsTreeTraverse .collect(library) { /* we won't output these, so ignore the name collision */ - case x: TsDeclTypeAlias if x.comments.has[Markers.IsTrivial.type] => IArray.Empty - case x: HasCodePath => x.codePath.forceHasPath.codePath.parts + case x: TsDeclTypeAlias if x.comments.has[Marker.IsTrivial.type] => IArray.Empty + case x: CodePath.Has => x.codePath.forceHasPath.codePath.parts } .distinct .sorted(ShortestAndLowercaseFirst) diff --git a/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ConversionOptions.scala b/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ConversionOptions.scala index 05a3a2014f..0b2de4766a 100644 --- a/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ConversionOptions.scala +++ b/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ConversionOptions.scala @@ -3,7 +3,8 @@ package internal package importer import io.circe013.{Decoder, Encoder} -import org.scalablytyped.converter.internal.scalajs.{flavours, Name, Versions} +import org.scalablytyped.converter.internal.scalajs.flavours._ +import org.scalablytyped.converter.internal.scalajs.{Name, Versions} import org.scalablytyped.converter.internal.ts.TsIdentLibrary import scala.collection.immutable.SortedSet @@ -27,24 +28,21 @@ case class ConversionOptions( val ignoredModulePrefixes: Set[List[String]] = ignored.map(_.split("/").toList) - val flavourImpl: flavours.FlavourImpl = + val flavourImpl: FlavourImpl = flavour match { case Flavour.Normal => - flavours.NormalFlavour(useScalaJsDomTypes, enableLongApplyMethod, outputPackage) + NormalFlavour(useScalaJsDomTypes, enableLongApplyMethod, outputPackage) case Flavour.Slinky => - flavours.SlinkyFlavour(outputPackage, enableLongApplyMethod, versions.scala, enableReactTreeShaking) + SlinkyFlavour(outputPackage, enableLongApplyMethod, versions.scala, enableReactTreeShaking) case Flavour.SlinkyNative => - flavours.SlinkyNativeFlavour(outputPackage, enableLongApplyMethod, versions.scala, enableReactTreeShaking) + SlinkyNativeFlavour(outputPackage, enableLongApplyMethod, versions.scala, enableReactTreeShaking) case Flavour.Japgolly => - flavours.JapgollyFlavour(outputPackage, enableLongApplyMethod, versions.scala, enableReactTreeShaking) + JapgollyFlavour(outputPackage, enableLongApplyMethod, versions.scala, enableReactTreeShaking) } } object ConversionOptions { - import io.circe013.generic.auto._ - import jsonCodecs._ - - implicit val encodes: Encoder[ConversionOptions] = exportEncoder[ConversionOptions].instance - implicit val decodes: Decoder[ConversionOptions] = exportDecoder[ConversionOptions].instance + implicit val encodes: Encoder[ConversionOptions] = io.circe013.generic.semiauto.deriveEncoder + implicit val decodes: Decoder[ConversionOptions] = io.circe013.generic.semiauto.deriveDecoder } diff --git a/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ImportEnum.scala b/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ImportEnum.scala index b06d8abcac..1dff803d36 100644 --- a/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ImportEnum.scala +++ b/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ImportEnum.scala @@ -10,9 +10,9 @@ object ImportEnum { val found = e.members.collect { case TsEnumMember(_, _, Some(TsExpr.Literal(lit))) => lit match { - case _: TsLiteralString => TypeRef.String - case _: TsLiteralNumber => TypeRef.Double - case _: TsLiteralBoolean => TypeRef.Boolean + case _: TsLiteral.Str => TypeRef.String + case _: TsLiteral.Num => TypeRef.Double + case _: TsLiteral.Bool => TypeRef.Boolean } } TypeRef.Union(found, NoComments, sort = true) @@ -32,7 +32,7 @@ object ImportEnum { case TsDeclEnum(cs, _, true, _, _, _, Some(exportedFrom), _, codePath) => val tpe = importType(Wildcards.No, scope, importName)(exportedFrom) val importedCp = importName(codePath) - IArray(TypeAliasTree(importedCp.parts.last, Empty, tpe, cs + CommentData(Markers.IsTrivial), importedCp)) + IArray(TypeAliasTree(importedCp.parts.last, Empty, tpe, cs + Marker.IsTrivial, importedCp)) /* normal const enum? type alias. And output a scala object with values if possible, otherwise a comment */ case TsDeclEnum(cs, _, true, _, members, _, None, _, codePath) => @@ -69,7 +69,7 @@ object ImportEnum { .distinctBy(_.name.unescaped) /* keep module members when minimizing */ - val related = Comments(CommentData(Minimization.Related(newMembers.map(m => TypeRef(m.codePath))))) + val related = Comments(Marker.MinimizationRelated(newMembers.map(m => TypeRef(m.codePath)))) ModuleTree( Empty, importedCodePath.parts.last, @@ -102,7 +102,7 @@ object ImportEnum { name = enumName, tparams = Empty, alias = importType(Wildcards.No, scope, importName)(TsTypeRef(NoComments, ef.name, Empty)), - comments = Comments(CommentData(Markers.IsTrivial)), + comments = Comments(Marker.IsTrivial), codePath = importedCodePath, ) case None => @@ -199,7 +199,7 @@ object ImportEnum { enumName, parents = Empty, members = membersSyms ++ IArray.fromOption(applyMethod), - comments = cs + CommentData(Markers.EnumObject), + comments = cs + Marker.EnumObject, codePath = importedCodePath, isOverride = false, ) diff --git a/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ImportExpr.scala b/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ImportExpr.scala index 268111fcdc..3682fd7642 100644 --- a/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ImportExpr.scala +++ b/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ImportExpr.scala @@ -13,13 +13,13 @@ class ImportExpr(importType: ImportType, importName: AdaptiveNamingImport) { case TsExpr.Literal(value) => value match { - case TsLiteralNumber(value) => + case TsLiteral.Num(value) => FakeLiterals.isTooBigForInt(value) match { case Some(long) => ExprTree.NumberLit(long.toString + ".0") case None => ExprTree.NumberLit(value) } - case TsLiteralString(value) => ExprTree.StringLit(value) - case TsLiteralBoolean(value) => ExprTree.BooleanLit(value) + case TsLiteral.Str(value) => ExprTree.StringLit(value) + case TsLiteral.Bool(value) => ExprTree.BooleanLit(value) } case TsExpr.Cast(expr, tpe) => ExprTree.Cast(apply(expr, scope), importType(Wildcards.No, scope, importName)(tpe)) diff --git a/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ImportTree.scala b/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ImportTree.scala index 5c5ddd2a74..2df648d80e 100644 --- a/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ImportTree.scala +++ b/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ImportTree.scala @@ -5,7 +5,7 @@ import com.olvind.logging.Logger import org.scalablytyped.converter.internal.importer.Phase1Res.{LibTs, UnpackLibs} import org.scalablytyped.converter.internal.maps._ import org.scalablytyped.converter.internal.scalajs._ -import org.scalablytyped.converter.internal.scalajs.transforms.{CleanIllegalNames, Mangler} +import org.scalablytyped.converter.internal.scalajs.transforms.CleanIllegalNames import org.scalablytyped.converter.internal.ts.{ParentsResolver, _} class ImportTree( @@ -45,7 +45,7 @@ class ImportTree( Comment("""/* This can be used to `require` the library as a side effect. If it is a global library this will make scalajs-bundler include it */ """), - CommentData(Mangler.LeaveAlone), + Marker.ManglerLeaveAlone, ), ), codePath = QualifiedName(IArray(outputPkg, libName, name)), @@ -64,6 +64,9 @@ class ImportTree( ) } + implicit val TypeRefOrdering: Ordering[TypeRef] = + Ordering.by[TypeRef, String](Printer.formatTypeRef(0)) + def decl(_scope: TsTreeScope)(t1: TsContainerOrDecl): IArray[Tree] = { val scope: TsTreeScope = _scope / t1 @@ -208,7 +211,7 @@ class ImportTree( val (anns, newComments, isScalaJsDefined) = (IsUserImplementable(withParents), enableScalaJsDefined) match { case (true, true) => (IArray(Annotation.ScalaJSDefined), cs, true) - case (true, false) => (IArray(Annotation.JsNative), cs + CommentData(Markers.CouldBeScalaJsDefined), false) + case (true, false) => (IArray(Annotation.JsNative), cs + Marker.CouldBeScalaJsDefined, false) case (false, _) => (IArray(Annotation.JsNative), cs, false) } @@ -358,7 +361,7 @@ class ImportTree( case m: TsMemberIndex => m.indexing match { - case IndexingDict(indexName, indexType) => + case Indexing.Dict(indexName, indexType) => val indexTpe = importType(Wildcards.No, scope, importName)(indexType) val valueTpe = importType.orAny(Wildcards.No, scope, importName)(m.valueType) @@ -370,7 +373,7 @@ class ImportTree( else scope.logger.fatal(s"Unsupported index type $indexTpe") IArray(MemberRet.Inheritance(rewritten)) - case IndexingSingle(name) => + case Indexing.Single(name) => val KnownSymbols = Set( "hasInstance", "isConcatSpreadable", @@ -484,7 +487,7 @@ class ImportTree( } def hack(f: FieldTree): Option[FieldTree] = - f.comments.extract { case Markers.ExpandedCallables => () } match { + f.comments.extract { case Marker.ExpandedCallables => () } match { case None => Some(f) case Some((_, _)) => if (f.name === Name.namespaced) None diff --git a/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ImportType.scala b/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ImportType.scala index ab1d19a9f7..98beb9c1db 100644 --- a/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ImportType.scala +++ b/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ImportType.scala @@ -120,12 +120,12 @@ class ImportType(stdNames: QualifiedName.StdNames) { case TsTypeObject(_, ms) if ExtractInterfaces.isDictionary(ms) => val (numbers, strings, Empty) = ms.partitionCollect2( - { case x @ TsMemberIndex(_, _, _, IndexingDict(_, TsTypeRef.number), _) => x }, - { case x @ TsMemberIndex(_, _, _, IndexingDict(_, _), _) => x }, + { case x @ TsMemberIndex(_, _, _, Indexing.Dict(_, TsTypeRef.number), _) => x }, + { case x @ TsMemberIndex(_, _, _, Indexing.Dict(_, _), _) => x }, ) val translatedStrings = strings.collect { - case TsMemberIndex(cs, _, _, IndexingDict(_, _), valueType) => + case TsMemberIndex(cs, _, _, Indexing.Dict(_, _), valueType) => (cs, orAny(wildcards, scope, importName)(valueType)) } val stringDict = translatedStrings match { @@ -140,7 +140,7 @@ class ImportType(stdNames: QualifiedName.StdNames) { ) } val translatedNumbers = numbers.collect { - case TsMemberIndex(cs, _, _, IndexingDict(_, TsTypeRef.number), valueType) => + case TsMemberIndex(cs, _, _, Indexing.Dict(_, TsTypeRef.number), valueType) => (cs, orAny(wildcards, scope, importName)(valueType)) } val numberDict = translatedNumbers match { @@ -181,8 +181,8 @@ class ImportType(stdNames: QualifiedName.StdNames) { if (!types.contains(TsTypeRef.boolean)) types else { types.partitionCollect { - case TsTypeLiteral(TsLiteralString("true" | "false")) => null - case TsTypeLiteral(TsLiteralBoolean(true | false)) => null + case TsTypeLiteral(TsLiteral.Str("true" | "false")) => null + case TsTypeLiteral(TsLiteral.Bool(true | false)) => null } match { case (_, rest) => rest } @@ -258,9 +258,9 @@ class ImportType(stdNames: QualifiedName.StdNames) { case TsTypeLiteral(lit) => lit match { - case TsLiteralNumber(value) => TypeRef.NumberLiteral(value) - case TsLiteralString(value) => TypeRef.StringLiteral(value) - case TsLiteralBoolean(value) => TypeRef.BooleanLiteral(value.toString) + case TsLiteral.Num(value) => TypeRef.NumberLiteral(value) + case TsLiteral.Str(value) => TypeRef.StringLiteral(value) + case TsLiteral.Bool(value) => TypeRef.BooleanLiteral(value.toString) } case TsTypeThis() => diff --git a/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/IsUserImplementable.scala b/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/IsUserImplementable.scala index f10ab428f6..5624813078 100644 --- a/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/IsUserImplementable.scala +++ b/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/IsUserImplementable.scala @@ -29,8 +29,8 @@ object IsUserImplementable { case int: TsDeclInterface => val fromUnnamed = int.unnamed.forall { case _: TsMemberTypeMapped => false - case TsMemberIndex(_, _, _, IndexingSingle(_), _) => false - case _ => true + case TsMemberIndex(_, _, _, Indexing.Single(_), _) => false + case _ => true } val fromNamed = int.membersByName.forall { @@ -43,7 +43,7 @@ object IsUserImplementable { val toConsider: IArray[TsMember] = sameName .collectFirst { - case x: TsMemberProperty if x.comments.has[Markers.ExpandedCallables.type] => IArray(x) + case x: TsMemberProperty if x.comments.has[Marker.ExpandedCallables.type] => IArray(x) } .getOrElse(sameName) diff --git a/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/Phase1ReadTypescript.scala b/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/Phase1ReadTypescript.scala index dd6cf09663..f20d1515bf 100644 --- a/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/Phase1ReadTypescript.scala +++ b/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/Phase1ReadTypescript.scala @@ -81,13 +81,13 @@ class Phase1ReadTypescript( parsed.directives.toSet .partitionCollect3( { - case r @ DirectivePathRef(value) => + case r @ Directive.PathRef(value) => val maybeSource: Option[Source] = LibraryResolver.file(file.folder, value).map(Source.helperFile(inLib)) PhaseRes.fromOption(source, maybeSource, Right(s"Couldn't resolve $r")) }, - { case DirectiveTypesRef(value) => resolveDep(value) }, { - case r @ DirectiveLibRef(value) if inLib.libName === TsIdent.std => + { case Directive.TypesRef(value) => resolveDep(value) }, { + case r @ Directive.LibRef(value) if inLib.libName === TsIdent.std => val maybeSource: Option[Source] = LibraryResolver.file(resolve.stdLib.folder, s"lib.$value.d.ts").map(Source.helperFile(inLib)) PhaseRes.fromOption(source, maybeSource, Right(s"Couldn't resolve $r")) @@ -173,7 +173,7 @@ class Phase1ReadTypescript( case more => _2.copy(members = _2.members.map { case m: TsDeclModule if more.contains(m.name) => - m.copy(comments = m.comments + CommentData(ModuleAliases(more.filterNot(_ === m.name)))) + m.copy(comments = m.comments + Marker.ModuleAliases(more.filterNot(_ === m.name))) case other => other }) } diff --git a/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ResolveExternalReferences.scala b/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ResolveExternalReferences.scala index 7ca94e9fb4..1032c94cf4 100644 --- a/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ResolveExternalReferences.scala +++ b/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ResolveExternalReferences.scala @@ -19,11 +19,11 @@ object ResolveExternalReferences { def apply(resolve: LibraryResolver, source: TsSource, tsParsedFile: TsParsedFile, logger: Logger[Unit]): Result = { val imported: Set[TsIdentModule] = { val fromImports = tsParsedFile.imports.collect { - case TsImport(_, _, TsImporteeFrom(from)) => from - case TsImport(_, _, TsImporteeRequired(from)) => from + case TsImport(_, _, TsImportee.From(from)) => from + case TsImport(_, _, TsImportee.Required(from)) => from } val fromExports = tsParsedFile.exports.collect { - case TsExport(_, _, _, TsExporteeNames(_, Some(from))) => from + case TsExport(_, _, _, TsExportee.Names(_, Some(from))) => from } fromImports.toSet ++ fromExports.toSet } @@ -48,7 +48,7 @@ object ResolveExternalReferences { val newImports: IArray[TsImport] = v.importTypes.mapToIArray { case (TsIdentImport(from), name) => - TsImport(typeOnly = false, IArray(TsImportedStar(Some(name))), TsImporteeFrom(from)) + TsImport(typeOnly = false, IArray(TsImported.Star(Some(name))), TsImportee.From(from)) } Result(after.withMembers(after.members ++ newImports), v.foundSources.to[Set], v.notFound.to[Set]) @@ -93,16 +93,16 @@ object ResolveExternalReferences { case other => other } - override def enterTsExporteeStar(t: TsTreeScope)(x: TsExporteeStar): TsExporteeStar = + override def enterTsExporteeStar(t: TsTreeScope)(x: TsExportee.Star): TsExportee.Star = x.copy(from = resolveAndStore(x.from)) - override def enterTsImporteeRequired(t: TsTreeScope)(x: TsImporteeRequired): TsImporteeRequired = + override def enterTsImporteeRequired(t: TsTreeScope)(x: TsImportee.Required): TsImportee.Required = x.copy(from = resolveAndStore(x.from)) - override def enterTsImporteeFrom(t: TsTreeScope)(x: TsImporteeFrom): TsImporteeFrom = + override def enterTsImporteeFrom(t: TsTreeScope)(x: TsImportee.From): TsImportee.From = x.copy(from = resolveAndStore(x.from)) - override def enterTsExporteeNames(t: TsTreeScope)(x: TsExporteeNames): TsExporteeNames = + override def enterTsExporteeNames(t: TsTreeScope)(x: TsExportee.Names): TsExportee.Names = x.fromOpt.fold(x)(from => x.copy(fromOpt = Some(resolveAndStore(from)))) override def enterTsQIdent(t: TsTreeScope)(x: TsQIdent): TsQIdent = diff --git a/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ScalaJsBundlerDepFile.scala b/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ScalaJsBundlerDepFile.scala index 56d9e81793..6da14549d1 100644 --- a/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ScalaJsBundlerDepFile.scala +++ b/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/ScalaJsBundlerDepFile.scala @@ -2,7 +2,6 @@ package org.scalablytyped.converter.internal package importer import org.scalablytyped.converter.internal.ts.TsIdentLibrary -import io.circe013.generic.semiauto.{deriveDecoder, deriveEncoder} import io.circe013.{Decoder, Encoder} import io.circe013.syntax._ @@ -21,8 +20,8 @@ object ScalaJsBundlerDepFile { ) object NpmDependencies { - implicit val Encoder: Encoder[NpmDependencies] = deriveEncoder[NpmDependencies] - implicit val Decoder: Decoder[NpmDependencies] = deriveDecoder[NpmDependencies] + implicit val Encoder: Encoder[NpmDependencies] = io.circe013.generic.semiauto.deriveEncoder + implicit val Decoder: Decoder[NpmDependencies] = io.circe013.generic.semiauto.deriveDecoder } def apply(libName: TsIdentLibrary, v: LibraryVersion): Map[os.RelPath, Array[Byte]] = diff --git a/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/Source.scala b/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/Source.scala index 828d21c670..c109d0fac9 100644 --- a/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/Source.scala +++ b/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/Source.scala @@ -34,8 +34,6 @@ object Source { } sealed trait TsLibSource extends TsSource with TsTreeScope.TsLib { - import jsonCodecs._ - override lazy val packageJsonOpt: Option[PackageJsonDeps] = Json.opt[PackageJsonDeps](folder.path / "package.json").orElse /* discover stdlib package.json as well */ ( Json.opt[PackageJsonDeps](folder.path / os.up / "package.json"), @@ -68,8 +66,6 @@ object Source { def fromTypingsJson(fromFolder: Source.FromFolder, fileOpt: Option[String]): IArray[InFile] = fileOpt match { case Some(path) if path.endsWith("typings.json") => - import jsonCodecs._ - val typingsJsonPath = fromFolder.folder.path / os.RelPath(path) val typingsJson = Json.force[TypingsJson](typingsJsonPath) IArray(InFile(typingsJsonPath / os.up / typingsJson.main)) diff --git a/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/documentation/Npmjs.scala b/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/documentation/Npmjs.scala index 6130ff7df5..29ed0aa9d9 100644 --- a/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/documentation/Npmjs.scala +++ b/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/documentation/Npmjs.scala @@ -2,7 +2,6 @@ package org.scalablytyped.converter.internal package importer.documentation import com.olvind.logging.Logger -import io.circe013.generic.semiauto.{deriveDecoder, deriveEncoder} import io.circe013.{Decoder, Encoder} import org.scalablytyped.converter.internal.importer.Source @@ -44,24 +43,24 @@ object Npmjs { case class Data(analyzedAt: DateString, collected: Collected, score: Score) object Data { - implicit val DecoderDatedNumbers: Decoder[DatedNumbers] = deriveDecoder[DatedNumbers] - implicit val EncoderDatedNumbers: Encoder[DatedNumbers] = deriveEncoder[DatedNumbers] - implicit val DecoderLinks: Decoder[Links] = deriveDecoder[Links] - implicit val EncoderLinks: Encoder[Links] = deriveEncoder[Links] - implicit val DecoderRepository: Decoder[Repository] = deriveDecoder[Repository] - implicit val EncoderRepository: Encoder[Repository] = deriveEncoder[Repository] - implicit val DecoderMetadata: Decoder[Metadata] = deriveDecoder[Metadata] - implicit val EncoderMetadata: Encoder[Metadata] = deriveEncoder[Metadata] - implicit val DecoderNpm: Decoder[Npm] = deriveDecoder[Npm] - implicit val EncoderNpm: Encoder[Npm] = deriveEncoder[Npm] - implicit val DecoderCollected: Decoder[Collected] = deriveDecoder[Collected] - implicit val EncoderCollected: Encoder[Collected] = deriveEncoder[Collected] - implicit val DecoderScoreDetail: Decoder[ScoreDetail] = deriveDecoder[ScoreDetail] - implicit val EncoderScoreDetail: Encoder[ScoreDetail] = deriveEncoder[ScoreDetail] - implicit val DecoderScore: Decoder[Score] = deriveDecoder[Score] - implicit val EncoderScore: Encoder[Score] = deriveEncoder[Score] - implicit val DecoderData: Decoder[Data] = deriveDecoder[Data] - implicit val EncoderData: Encoder[Data] = deriveEncoder[Data] + implicit val DecoderDatedNumbers: Decoder[DatedNumbers] = io.circe013.generic.semiauto.deriveDecoder + implicit val EncoderDatedNumbers: Encoder[DatedNumbers] = io.circe013.generic.semiauto.deriveEncoder + implicit val DecoderLinks: Decoder[Links] = io.circe013.generic.semiauto.deriveDecoder + implicit val EncoderLinks: Encoder[Links] = io.circe013.generic.semiauto.deriveEncoder + implicit val DecoderRepository: Decoder[Repository] = io.circe013.generic.semiauto.deriveDecoder + implicit val EncoderRepository: Encoder[Repository] = io.circe013.generic.semiauto.deriveEncoder + implicit val DecoderMetadata: Decoder[Metadata] = io.circe013.generic.semiauto.deriveDecoder + implicit val EncoderMetadata: Encoder[Metadata] = io.circe013.generic.semiauto.deriveEncoder + implicit val DecoderNpm: Decoder[Npm] = io.circe013.generic.semiauto.deriveDecoder + implicit val EncoderNpm: Encoder[Npm] = io.circe013.generic.semiauto.deriveEncoder + implicit val DecoderCollected: Decoder[Collected] = io.circe013.generic.semiauto.deriveDecoder + implicit val EncoderCollected: Encoder[Collected] = io.circe013.generic.semiauto.deriveEncoder + implicit val DecoderScoreDetail: Decoder[ScoreDetail] = io.circe013.generic.semiauto.deriveDecoder + implicit val EncoderScoreDetail: Encoder[ScoreDetail] = io.circe013.generic.semiauto.deriveEncoder + implicit val DecoderScore: Decoder[Score] = io.circe013.generic.semiauto.deriveDecoder + implicit val EncoderScore: Encoder[Score] = io.circe013.generic.semiauto.deriveEncoder + implicit val DecoderData: Decoder[Data] = io.circe013.generic.semiauto.deriveDecoder + implicit val EncoderData: Encoder[Data] = io.circe013.generic.semiauto.deriveEncoder } object No extends Npmjs { diff --git a/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/jsonCodecs.scala b/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/jsonCodecs.scala deleted file mode 100644 index c93f261f38..0000000000 --- a/importer-portable/src/main/scala/org/scalablytyped/converter/internal/importer/jsonCodecs.scala +++ /dev/null @@ -1,52 +0,0 @@ -package org.scalablytyped.converter.internal -package importer - -import io.circe013._ -import org.scalablytyped.converter.internal.ts._ - -import java.io.File -import java.net.URI -import scala.collection.immutable.{SortedSet, TreeSet} - -object jsonCodecs { - implicit def IArrayEncoder[T <: AnyRef: Encoder]: Encoder[IArray[T]] = - Encoder[List[T]].contramap[IArray[T]](_.toList) - - implicit def IArrayDecoder[T <: AnyRef: Decoder]: Decoder[IArray[T]] = - Decoder[List[T]].map[IArray[T]](IArray.fromTraversable) - - implicit def SortedSetEncoder[T: Encoder: Ordering]: Encoder[SortedSet[T]] = - Encoder[Vector[T]].contramap[SortedSet[T]](x => x.toVector) - - implicit def SortedSetDecoder[T: Decoder: Ordering]: Decoder[SortedSet[T]] = - Decoder[Vector[T]].map[SortedSet[T]](ts => TreeSet.empty[T] ++ ts) - - implicit val FileEncoder: Encoder[File] = Encoder[String].contramap[File](_.toString) - implicit val FileDecoder: Decoder[File] = Decoder[String].map[File](new File(_)) - implicit val RelPathDecoder: Decoder[os.RelPath] = Decoder[String].map(str => os.RelPath(str.dropWhile(_ === '/'))) - implicit val RelPathEncoder: Encoder[os.RelPath] = Encoder[String].contramap[os.RelPath](_.toString) - implicit val PathDecoder: Decoder[os.Path] = Decoder[String].map(str => os.Path(str)) - implicit val PathEncoder: Encoder[os.Path] = Encoder[String].contramap[os.Path](_.toString) - implicit val URIDecoder: Decoder[URI] = Decoder[String].map(new URI(_)) - implicit val URIEncoder: Encoder[URI] = Encoder[String].contramap[URI](_.toString) - implicit val TsIdentLibraryDecoder: Decoder[TsIdentLibrary] = Decoder[String].map(TsIdentLibrary.apply) - implicit val TsIdentLibraryEncoder: Encoder[TsIdentLibrary] = Encoder[String].contramap[TsIdentLibrary](_.value) - implicit val TsIdentLibraryKeyDec: KeyDecoder[TsIdentLibrary] = KeyDecoder[String].map(TsIdentLibrary.apply) - implicit val TsIdentLibraryKeyEnc: KeyEncoder[TsIdentLibrary] = KeyEncoder[String].contramap[TsIdentLibrary](_.value) - - import io.circe013.generic.semiauto._ - - implicit val CompilerOptionsEncoder: Encoder[CompilerOptions] = deriveEncoder[CompilerOptions] - implicit val CompilerOptionsDecoder: Decoder[CompilerOptions] = deriveDecoder[CompilerOptions] - implicit val TsConfigEncoder: Encoder[TsConfig] = deriveEncoder[TsConfig] - implicit val TsConfigDecoder: Decoder[TsConfig] = deriveDecoder[TsConfig] - implicit val PackageJsonDepsEncoder: Encoder[PackageJsonDeps] = deriveEncoder[PackageJsonDeps] - implicit val PackageJsonDepsDecoder: Decoder[PackageJsonDeps] = deriveDecoder[PackageJsonDeps] - implicit val NotNeededPackageEncoder: Encoder[NotNeededPackage] = deriveEncoder[NotNeededPackage] - implicit val NotNeededPackageDecoder: Decoder[NotNeededPackage] = deriveDecoder[NotNeededPackage] - implicit val NotNeededPackagesEncoder: Encoder[NotNeededPackages] = deriveEncoder[NotNeededPackages] - implicit val NotNeededPackagesDecoder: Decoder[NotNeededPackages] = deriveDecoder[NotNeededPackages] - implicit val TypingsJsonEncoder: Encoder[TypingsJson] = deriveEncoder[TypingsJson] - implicit val TypingsJsonDecoder: Decoder[TypingsJson] = deriveDecoder[TypingsJson] - -} diff --git a/importer/src/main/scala/org/scalablytyped/converter/internal/importer/Ci.scala b/importer/src/main/scala/org/scalablytyped/converter/internal/importer/Ci.scala index 7ab6db27f4..309ea8cb85 100644 --- a/importer/src/main/scala/org/scalablytyped/converter/internal/importer/Ci.scala +++ b/importer/src/main/scala/org/scalablytyped/converter/internal/importer/Ci.scala @@ -13,7 +13,6 @@ import com.olvind.logging.Logger.Stored import com.olvind.logging.{LogLevel, LogRegistry} import org.scalablytyped.converter.internal.importer.build._ import org.scalablytyped.converter.internal.importer.documentation.{NpmjsFetcher, Readme, TopLists} -import org.scalablytyped.converter.internal.importer.jsonCodecs._ import org.scalablytyped.converter.internal.phases.{PhaseRes, PhaseRunner, RecPhase} import org.scalablytyped.converter.internal.scalajs.{Name, Versions} import org.scalablytyped.converter.internal.ts._ diff --git a/importer/src/main/scala/org/scalablytyped/converter/internal/importer/Summary.scala b/importer/src/main/scala/org/scalablytyped/converter/internal/importer/Summary.scala index 856930e086..0790116117 100644 --- a/importer/src/main/scala/org/scalablytyped/converter/internal/importer/Summary.scala +++ b/importer/src/main/scala/org/scalablytyped/converter/internal/importer/Summary.scala @@ -1,10 +1,9 @@ package org.scalablytyped.converter.internal package importer -import org.scalablytyped.converter.internal.ts.TsIdentLibrary import io.circe013.Decoder.Result -import io.circe013.generic.semiauto.{deriveDecoder, deriveEncoder} import io.circe013.{Decoder, Encoder, HCursor} +import org.scalablytyped.converter.internal.ts.TsIdentLibrary case class Summary( successes: Set[TsIdentLibrary], @@ -32,12 +31,13 @@ object Summary { } } - implicit val EncoderTsIdentLibrary: Encoder[TsIdentLibrary] = deriveEncoder[TsIdentLibrary] - implicit val DecoderTsIdentLibrary: Decoder[TsIdentLibrary] = deriveDecoder[TsIdentLibrary].or(legacyLibDecoder) - implicit val EncoderSummary: Encoder[Summary] = deriveEncoder[Summary] - implicit val EncoderSummaryDiff: Encoder[SummaryDiff] = deriveEncoder[SummaryDiff] - implicit val DecoderSummary: Decoder[Summary] = deriveDecoder[Summary] - implicit val DecoderSummaryDiff: Decoder[SummaryDiff] = deriveDecoder[SummaryDiff] + implicit val EncoderTsIdentLibrary: Encoder[TsIdentLibrary] = io.circe013.generic.semiauto.deriveEncoder + implicit val DecoderTsIdentLibrary: Decoder[TsIdentLibrary] = + io.circe013.generic.semiauto.deriveDecoder[TsIdentLibrary].or(legacyLibDecoder) + implicit val EncoderSummary: Encoder[Summary] = io.circe013.generic.semiauto.deriveEncoder + implicit val DecoderSummary: Decoder[Summary] = io.circe013.generic.semiauto.deriveDecoder + implicit val EncoderSummaryDiff: Encoder[SummaryDiff] = io.circe013.generic.semiauto.deriveEncoder + implicit val DecoderSummaryDiff: Decoder[SummaryDiff] = io.circe013.generic.semiauto.deriveDecoder val path = os.RelPath("summary.json") diff --git a/importer/src/main/scala/org/scalablytyped/converter/internal/importer/UpToDateExternals.scala b/importer/src/main/scala/org/scalablytyped/converter/internal/importer/UpToDateExternals.scala index 5f421989b8..375f1ad66a 100644 --- a/importer/src/main/scala/org/scalablytyped/converter/internal/importer/UpToDateExternals.scala +++ b/importer/src/main/scala/org/scalablytyped/converter/internal/importer/UpToDateExternals.scala @@ -2,7 +2,6 @@ package org.scalablytyped.converter.internal package importer import com.olvind.logging.Logger -import org.scalablytyped.converter.internal.importer.jsonCodecs._ import org.scalablytyped.converter.internal.ts.{PackageJsonDeps, TsIdentLibrary} object UpToDateExternals { diff --git a/importer/src/test/scala/org/scalablytyped/converter/internal/importer/JsonTests.scala b/importer/src/test/scala/org/scalablytyped/converter/internal/importer/JsonTests.scala index fc46c74bcc..4a18aa58f6 100644 --- a/importer/src/test/scala/org/scalablytyped/converter/internal/importer/JsonTests.scala +++ b/importer/src/test/scala/org/scalablytyped/converter/internal/importer/JsonTests.scala @@ -1,7 +1,6 @@ package org.scalablytyped.converter.internal.importer import org.scalablytyped.converter.internal.{IArray, Json} -import org.scalablytyped.converter.internal.importer.jsonCodecs._ import org.scalablytyped.converter.internal.ts._ import org.scalatest.funsuite.AnyFunSuite diff --git a/importer/src/test/scala/org/scalablytyped/converter/internal/ts/TypeExpansionTest.scala b/importer/src/test/scala/org/scalablytyped/converter/internal/ts/TypeExpansionTest.scala index 34fe7c2fad..5147f50d3e 100644 --- a/importer/src/test/scala/org/scalablytyped/converter/internal/ts/TypeExpansionTest.scala +++ b/importer/src/test/scala/org/scalablytyped/converter/internal/ts/TypeExpansionTest.scala @@ -45,7 +45,7 @@ type AA = Partial type Ta = OptionalKey """).extract[TsDeclTypeAlias]("Ta") - out.alias.shouldBe(TsTypeUnion(IArray("c", "d", "e", "f").map(str => TsTypeLiteral(TsLiteralString(str))))) + out.alias.shouldBe(TsTypeUnion(IArray("c", "d", "e", "f").map(str => TsTypeLiteral(TsLiteral.Str(str))))) } test("Except from union type") { diff --git a/importer/src/test/scala/org/scalablytyped/converter/internal/ts/parser/CommentTests.scala b/importer/src/test/scala/org/scalablytyped/converter/internal/ts/parser/CommentTests.scala index 800a10fc1c..2137154318 100644 --- a/importer/src/test/scala/org/scalablytyped/converter/internal/ts/parser/CommentTests.scala +++ b/importer/src/test/scala/org/scalablytyped/converter/internal/ts/parser/CommentTests.scala @@ -178,7 +178,7 @@ final class CommentTests extends AnyFunSuite with Matchers { NoComments, typeOnly = false, ExportType.Named, - TsExporteeTree( + TsExportee.Tree( TsDeclFunction( NoComments, declared = false, diff --git a/importer/src/test/scala/org/scalablytyped/converter/internal/ts/parser/ImportExportParseTests.scala b/importer/src/test/scala/org/scalablytyped/converter/internal/ts/parser/ImportExportParseTests.scala index ee4137903a..d4829b547f 100644 --- a/importer/src/test/scala/org/scalablytyped/converter/internal/ts/parser/ImportExportParseTests.scala +++ b/importer/src/test/scala/org/scalablytyped/converter/internal/ts/parser/ImportExportParseTests.scala @@ -36,7 +36,7 @@ final class ImportExportParseTests extends AnyFunSuite with Matchers { NoComments, typeOnly = false, ExportType.Namespaced, - TsExporteeNames( + TsExportee.Names( IArray( (TsQIdent(IArray(TsIdent("AuthenticationContext"))), None), (TsQIdent(IArray(TsIdent("Logging"))), None), @@ -53,7 +53,7 @@ final class ImportExportParseTests extends AnyFunSuite with Matchers { NoComments, typeOnly = false, ExportType.Defaulted, - TsExporteeNames(IArray((TsQIdent(IArray(TsIdent("Abs"))), None)), None), + TsExportee.Names(IArray((TsQIdent(IArray(TsIdent("Abs"))), None)), None), ), ) } @@ -64,7 +64,7 @@ final class ImportExportParseTests extends AnyFunSuite with Matchers { NoComments, typeOnly = false, ExportType.Named, - TsExporteeNames( + TsExportee.Names( IArray( (TsQIdent(IArray(TsIdent("Pool"))), None), (TsQIdent(IArray(TsIdent("PoolConfig"))), None), @@ -77,7 +77,7 @@ final class ImportExportParseTests extends AnyFunSuite with Matchers { test("export alias") { shouldParseAs("""export * from "aphrodite"""", TsParser.tsExport)( - TsExport(NoComments, typeOnly = false, ExportType.Named, TsExporteeStar(None, TsIdentModule.simple("aphrodite"))), + TsExport(NoComments, typeOnly = false, ExportType.Named, TsExportee.Star(None, TsIdentModule.simple("aphrodite"))), ) } @@ -87,7 +87,7 @@ final class ImportExportParseTests extends AnyFunSuite with Matchers { NoComments, typeOnly = false, ExportType.Named, - TsExporteeTree( + TsExportee.Tree( TsDeclEnum( NoComments, declared = false, @@ -108,8 +108,8 @@ final class ImportExportParseTests extends AnyFunSuite with Matchers { shouldParseAs("import http = require('http')", TsParser.tsImport)( TsImport( typeOnly = false, - IArray(TsImportedIdent(TsIdent("http"))), - TsImporteeRequired(TsIdentModule.simple("http")), + IArray(TsImported.Ident(TsIdent("http"))), + TsImportee.Required(TsIdentModule.simple("http")), ), ) } @@ -118,8 +118,8 @@ final class ImportExportParseTests extends AnyFunSuite with Matchers { shouldParseAs("""import {EventEmitter} from "events"""", TsParser.tsImport)( TsImport( typeOnly = false, - IArray(TsImportedDestructured(IArray((TsIdent("EventEmitter"), None)))), - TsImporteeFrom(TsIdentModule.simple("events")), + IArray(TsImported.Destructured(IArray((TsIdent("EventEmitter"), None)))), + TsImportee.From(TsIdentModule.simple("events")), ), ) } @@ -128,8 +128,8 @@ final class ImportExportParseTests extends AnyFunSuite with Matchers { shouldParseAs("""import * as e from 'express'""", TsParser.tsImport)( TsImport( typeOnly = false, - IArray(TsImportedStar(Some(TsIdent("e")))), - TsImporteeFrom(TsIdentModule.simple("express")), + IArray(TsImported.Star(Some(TsIdent("e")))), + TsImportee.From(TsIdentModule.simple("express")), ), ) } @@ -138,8 +138,8 @@ final class ImportExportParseTests extends AnyFunSuite with Matchers { shouldParseAs("""import ng = angular.dynamicLocale""", TsParser.tsImport)( TsImport( typeOnly = false, - IArray(TsImportedIdent(TsIdent("ng"))), - TsImporteeLocal(TsQIdent(IArray(TsIdent("angular"), TsIdent("dynamicLocale")))), + IArray(TsImported.Ident(TsIdent("ng"))), + TsImportee.Local(TsQIdent(IArray(TsIdent("angular"), TsIdent("dynamicLocale")))), ), ) } @@ -148,8 +148,8 @@ final class ImportExportParseTests extends AnyFunSuite with Matchers { shouldParseAs("""import ng = angular""", TsParser.tsImport)( TsImport( typeOnly = false, - IArray(TsImportedIdent(TsIdent("ng"))), - TsImporteeLocal(TsQIdent(IArray(TsIdent("angular")))), + IArray(TsImported.Ident(TsIdent("ng"))), + TsImportee.Local(TsQIdent(IArray(TsIdent("angular")))), ), ) } @@ -158,8 +158,8 @@ final class ImportExportParseTests extends AnyFunSuite with Matchers { shouldParseAs("""import traverse, {Visitor} from "babel-traverse"""", TsParser.tsImport)( TsImport( typeOnly = false, - IArray(TsImportedIdent(TsIdent("traverse")), TsImportedDestructured(IArray((TsIdent("Visitor"), None)))), - TsImporteeFrom(TsIdentModule.simple("babel-traverse")), + IArray(TsImported.Ident(TsIdent("traverse")), TsImported.Destructured(IArray((TsIdent("Visitor"), None)))), + TsImportee.From(TsIdentModule.simple("babel-traverse")), ), ) } @@ -170,11 +170,11 @@ final class ImportExportParseTests extends AnyFunSuite with Matchers { NoComments, typeOnly = false, ExportType.Named, - TsExporteeTree( + TsExportee.Tree( TsImport( typeOnly = false, - IArray(TsImportedIdent(TsIdent("AppBar"))), - TsImporteeLocal(TsQIdent(IArray(TsIdent("__MaterialUI"), TsIdent("AppBar")))), + IArray(TsImported.Ident(TsIdent("AppBar"))), + TsImportee.Local(TsQIdent(IArray(TsIdent("__MaterialUI"), TsIdent("AppBar")))), ), ), ), @@ -191,8 +191,8 @@ final class ImportExportParseTests extends AnyFunSuite with Matchers { shouldParseAs("""import { default as SidebarPushable } from './SidebarPushable'""", TsParser.tsImport)( TsImport( typeOnly = false, - IArray(TsImportedDestructured(IArray((TsIdent("default"), Some(TsIdent("SidebarPushable")))))), - TsImporteeFrom(TsIdentModule(None, "." :: "SidebarPushable" :: Nil)), + IArray(TsImported.Destructured(IArray((TsIdent("default"), Some(TsIdent("SidebarPushable")))))), + TsImportee.From(TsIdentModule(None, "." :: "SidebarPushable" :: Nil)), ), ) } @@ -208,7 +208,7 @@ final class ImportExportParseTests extends AnyFunSuite with Matchers { TsImport( typeOnly = false, IArray( - TsImportedDestructured( + TsImported.Destructured( IArray( (TsIdent("ValidationOptions"), Some(TsIdent("JoiValidationOptions"))), (TsIdent("SchemaMap"), Some(TsIdent("JoiSchemaMap"))), @@ -216,7 +216,7 @@ final class ImportExportParseTests extends AnyFunSuite with Matchers { ), ), ), - TsImporteeFrom(TsIdentModule.simple("joi")), + TsImportee.From(TsIdentModule.simple("joi")), ), ) } @@ -229,7 +229,7 @@ final class ImportExportParseTests extends AnyFunSuite with Matchers { NoComments, typeOnly = false, ExportType.Defaulted, - TsExporteeTree( + TsExportee.Tree( TsDeclFunction( NoComments, declared = false, @@ -272,13 +272,13 @@ final class ImportExportParseTests extends AnyFunSuite with Matchers { test("import 'foo'") { shouldParseAs("""import 'jquery'""", TsParser.tsImport)( - TsImport(typeOnly = false, IArray(TsImportedStar(None)), TsImporteeFrom(TsIdentModule.simple("jquery"))), + TsImport(typeOnly = false, IArray(TsImported.Star(None)), TsImportee.From(TsIdentModule.simple("jquery"))), ) shouldParseAs("""import "../index"""", TsParser.tsImport)( TsImport( typeOnly = false, - IArray(TsImportedStar(None)), - TsImporteeFrom(TsIdentModule(None, ".." :: "index" :: Nil)), + IArray(TsImported.Star(None)), + TsImportee.From(TsIdentModule(None, ".." :: "index" :: Nil)), ), ) } @@ -289,7 +289,7 @@ final class ImportExportParseTests extends AnyFunSuite with Matchers { NoComments, typeOnly = false, ExportType.Defaulted, - TsExporteeTree( + TsExportee.Tree( TsDeclClass( NoComments, declared = false, @@ -335,7 +335,7 @@ final class ImportExportParseTests extends AnyFunSuite with Matchers { NoComments, typeOnly = false, ExportType.Defaulted, - TsExporteeTree( + TsExportee.Tree( TsDeclClass( NoComments, declared = false, @@ -358,11 +358,11 @@ final class ImportExportParseTests extends AnyFunSuite with Matchers { TsImport( typeOnly = true, IArray( - TsImportedDestructured( + TsImported.Destructured( IArray((TsIdentSimple("DiffOptions"), None), (TsIdentSimple("DiffOptionsNormalized"), None)), ), ), - TsImporteeFrom(TsIdentModule(None, List(".", "types"))), + TsImportee.From(TsIdentModule(None, List(".", "types"))), ), ) } @@ -372,7 +372,7 @@ final class ImportExportParseTests extends AnyFunSuite with Matchers { NoComments, typeOnly = true, tpe = ExportType.Named, - exported = TsExporteeNames( + exported = TsExportee.Names( IArray( (TsQIdent(IArray(TsIdentSimple("DiffOptions"))), None), (TsQIdent(IArray(TsIdentSimple("DiffOptionsColor"))), None), @@ -398,13 +398,13 @@ final class ImportExportParseTests extends AnyFunSuite with Matchers { TsImport( typeOnly = true, IArray(), - TsImporteeLocal(TsQIdent(IArray(TsIdentSimple("__esri"), TsIdentSimple("type")))), + TsImportee.Local(TsQIdent(IArray(TsIdentSimple("__esri"), TsIdentSimple("type")))), ), TsExport( NoComments, typeOnly = false, ExportType.Namespaced, - TsExporteeNames(IArray((TsQIdent(IArray(TsIdentSimple("type"))), None)), None), + TsExportee.Names(IArray((TsQIdent(IArray(TsIdentSimple("type"))), None)), None), ), ), CodePath.NoPath, @@ -420,7 +420,7 @@ final class ImportExportParseTests extends AnyFunSuite with Matchers { NoComments, false, ExportType.Named, - TsExporteeStar(Some(TsIdentSimple("specialChars")), TsIdentModule(None, List(".", "specialChars"))), + TsExportee.Star(Some(TsIdentSimple("specialChars")), TsIdentModule(None, List(".", "specialChars"))), ), ) } diff --git a/importer/src/test/scala/org/scalablytyped/converter/internal/ts/parser/ParserTests.scala b/importer/src/test/scala/org/scalablytyped/converter/internal/ts/parser/ParserTests.scala index 8b4654f0c2..d9949ff3a0 100644 --- a/importer/src/test/scala/org/scalablytyped/converter/internal/ts/parser/ParserTests.scala +++ b/importer/src/test/scala/org/scalablytyped/converter/internal/ts/parser/ParserTests.scala @@ -17,7 +17,7 @@ final class ParserTests extends AnyFunSuite { val expected = TsParsedFile( NoComments, - IArray(DirectivePathRef("./path-case.d.ts")), + IArray(Directive.PathRef("./path-case.d.ts")), IArray( TsDeclModule( NoComments, @@ -52,7 +52,7 @@ final class ParserTests extends AnyFunSuite { NoComments, typeOnly = false, ExportType.Namespaced, - TsExporteeNames(IArray((TsQIdent(IArray(TsIdent("pathCase"))), None)), None), + TsExportee.Names(IArray((TsQIdent(IArray(TsIdent("pathCase"))), None)), None), ), ), CodePath.NoPath, @@ -191,7 +191,7 @@ final class ParserTests extends AnyFunSuite { NoComments, isReadOnly = false, level = ProtectionLevel.Default, - indexing = IndexingDict(TsIdent("key"), TsTypeRef.string), + indexing = Indexing.Dict(TsIdent("key"), TsTypeRef.string), valueType = Some(TsTypeRef.any), ), ), @@ -250,8 +250,8 @@ final class ParserTests extends AnyFunSuite { isConst = false, TsIdent("LoggingLevel"), IArray( - TsEnumMember(NoComments, TsIdent("ERROR"), Some(TsExpr.Literal(TsLiteralNumber("0")))), - TsEnumMember(NoComments, TsIdent("WARNING"), Some(TsExpr.Literal(TsLiteralNumber("1")))), + TsEnumMember(NoComments, TsIdent("ERROR"), Some(TsExpr.Literal(TsLiteral.Num("0")))), + TsEnumMember(NoComments, TsIdent("WARNING"), Some(TsExpr.Literal(TsLiteral.Num("1")))), ), isValue = true, exportedFrom = None, @@ -270,8 +270,8 @@ final class ParserTests extends AnyFunSuite { isConst = true, TsIdent("ErrorCode"), IArray( - TsEnumMember(NoComments, TsIdent("OTHER_CAUSE"), Some(TsExpr.Literal(TsLiteralNumber("-1")))), - TsEnumMember(NoComments, TsIdent("INTERNAL_SERVER_ERROR"), Some(TsExpr.Literal(TsLiteralNumber("1")))), + TsEnumMember(NoComments, TsIdent("OTHER_CAUSE"), Some(TsExpr.Literal(TsLiteral.Num("-1")))), + TsEnumMember(NoComments, TsIdent("INTERNAL_SERVER_ERROR"), Some(TsExpr.Literal(TsLiteral.Num("1")))), ), isValue = true, exportedFrom = None, @@ -442,7 +442,7 @@ final class ParserTests extends AnyFunSuite { NoComments, typeOnly = false, ExportType.Named, - TsExporteeTree( + TsExportee.Tree( TsDeclFunction( NoComments, declared = false, @@ -505,7 +505,7 @@ final class ParserTests extends AnyFunSuite { NoComments, typeOnly = false, ExportType.Named, - TsExporteeTree( + TsExportee.Tree( TsDeclTypeAlias( NoComments, declared = false, @@ -572,9 +572,9 @@ final class ParserTests extends AnyFunSuite { OptionalType( TsTypeUnion( IArray( - TsTypeLiteral(TsLiteralString("ProtectionLevel.Default")), - TsTypeLiteral(TsLiteralString("top")), - TsTypeLiteral(TsLiteralString("bottom")), + TsTypeLiteral(TsLiteral.Str("ProtectionLevel.Default")), + TsTypeLiteral(TsLiteral.Str("top")), + TsTypeLiteral(TsLiteral.Str("bottom")), ), ), ), @@ -596,8 +596,8 @@ final class ParserTests extends AnyFunSuite { OptionalType( TsTypeUnion( IArray( - TsTypeLiteral(TsLiteralNumber("0")), - TsTypeLiteral(TsLiteralNumber("1")), + TsTypeLiteral(TsLiteral.Num("0")), + TsTypeLiteral(TsLiteral.Num("1")), TsTypeRef(NoComments, TsQIdent.boolean, Empty), ), ), @@ -612,12 +612,12 @@ final class ParserTests extends AnyFunSuite { test("negative numbers") { shouldParseAs("OTHER_CAUSE = -1", TsParser.tsEnumMembers.map(_.head))( - TsEnumMember(NoComments, TsIdent("OTHER_CAUSE"), Some(TsExpr.Literal(TsLiteralNumber("-1")))), + TsEnumMember(NoComments, TsIdent("OTHER_CAUSE"), Some(TsExpr.Literal(TsLiteral.Num("-1")))), ) } test("bigint literals") { - shouldParseAs("-1n", TsParser.tsLiteral)(TsLiteralNumber("-1")) + shouldParseAs("-1n", TsParser.tsLiteral)(TsLiteral.Num("-1")) } test("this type") { @@ -1089,7 +1089,7 @@ final class ParserTests extends AnyFunSuite { comments = NoComments, isReadOnly = true, level = ProtectionLevel.Default, - indexing = IndexingDict(TsIdent("index"), TsTypeRef(NoComments, TsQIdent.number, Empty)), + indexing = Indexing.Dict(TsIdent("index"), TsTypeRef(NoComments, TsQIdent.number, Empty)), valueType = Some(TsTypeRef.string), ), ), @@ -1350,8 +1350,8 @@ type Readonly = { comments = NoComments, isReadOnly = true, level = ProtectionLevel.Default, - indexing = IndexingSingle(TsQIdent(IArray(TsIdent("Symbol"), TsIdent("toStringTag")))), - valueType = Some(TsTypeLiteral(TsLiteralString("Symbol"))), + indexing = Indexing.Single(TsQIdent(IArray(TsIdent("Symbol"), TsIdent("toStringTag")))), + valueType = Some(TsTypeLiteral(TsLiteral.Str("Symbol"))), ), ), CodePath.NoPath, @@ -1445,8 +1445,8 @@ type Readonly = { } test("boolean expr") { - shouldParseAs("true", TsParser.tsLiteral)(TsLiteralBoolean(true)) - shouldParseAs("false", TsParser.tsLiteral)(TsLiteralBoolean(false)) + shouldParseAs("true", TsParser.tsLiteral)(TsLiteral.Bool(true)) + shouldParseAs("false", TsParser.tsLiteral)(TsLiteral.Bool(false)) shouldParseAs("boolean", TsParser.tsType)( TsTypeRef(NoComments, TsQIdent(IArray(TsIdent("boolean"))), Empty), ) @@ -1635,7 +1635,7 @@ type Readonly = { shouldParseAs("KeywordTypeNode[\"kind\"]", TsParser.tsType)( TsTypeLookup( TsTypeRef(NoComments, TsQIdent(IArray(TsIdent("KeywordTypeNode"))), Empty), - TsTypeLiteral(TsLiteralString("kind")), + TsTypeLiteral(TsLiteral.Str("kind")), ), ) } @@ -1646,7 +1646,7 @@ type Readonly = { NoComments, ProtectionLevel.Default, TsIdentSimple("swipeVelocityThreshold"), - Some(TsTypeLiteral(TsLiteralNumber("0.25"))), + Some(TsTypeLiteral(TsLiteral.Num("0.25"))), expr = None, isStatic = false, isReadOnly = false, @@ -1863,7 +1863,7 @@ type Readonly = { ), ), ), - TsTypeLiteral(TsLiteralString("bivarianceHack")), + TsTypeLiteral(TsLiteral.Str("bivarianceHack")), ), CodePath.NoPath, ), @@ -1878,8 +1878,8 @@ type Readonly = { TsQIdent(IArray(TsIdentSimple("UnionType"))), IArray( RTS, - TsTypeLookup(TsTypeLookup(RTS, TsTypeLiteral(TsLiteralString("_A"))), TsTypeLiteral(TsLiteralString("_A"))), - TsTypeLookup(TsTypeLookup(RTS, TsTypeLiteral(TsLiteralString("_A"))), TsTypeLiteral(TsLiteralString("_O"))), + TsTypeLookup(TsTypeLookup(RTS, TsTypeLiteral(TsLiteral.Str("_A"))), TsTypeLiteral(TsLiteral.Str("_A"))), + TsTypeLookup(TsTypeLookup(RTS, TsTypeLiteral(TsLiteral.Str("_A"))), TsTypeLiteral(TsLiteral.Str("_O"))), TsTypeRef(NoComments, TsQIdent(IArray(TsIdentSimple("mixed"))), Empty), ), ), @@ -1898,7 +1898,7 @@ type Readonly = { isConst = true, TsIdentSimple("Button"), IArray( - TsEnumMember(NoComments, TsIdentSimple("MINUS"), Some(TsExpr.Literal(TsLiteralNumber("0x00000004")))), + TsEnumMember(NoComments, TsIdentSimple("MINUS"), Some(TsExpr.Literal(TsLiteral.Num("0x00000004")))), TsEnumMember(NoComments, TsIdentSimple("SELECT"), Some(TsExpr.Ref(TsQIdent(IArray(TsIdentSimple("MINUS")))))), ), isValue = true, @@ -2172,8 +2172,8 @@ type Readonly = { test("conditional types part 2") { val TT = T - val True = TsTypeLiteral(TsLiteralBoolean(true)) - val False = TsTypeLiteral(TsLiteralBoolean(false)) + val True = TsTypeLiteral(TsLiteral.Bool(true)) + val False = TsTypeLiteral(TsLiteral.Bool(false)) shouldParseAs( "type IsOptional = undefined | null extends T ? true : undefined extends T ? true : null extends T ? true : false", TsParser.tsDeclTypeAlias, @@ -2213,7 +2213,7 @@ type Readonly = { comments = NoComments, isReadOnly = false, level = ProtectionLevel.Default, - indexing = IndexingSingle(TsQIdent(IArray(TsIdentSimple("nominalTypeHack")))), + indexing = Indexing.Single(TsQIdent(IArray(TsIdentSimple("nominalTypeHack")))), valueType = Some(OptionalType(T)), ), ), @@ -2352,7 +2352,7 @@ type Readonly = { TsQIdent.Array, IArray(TsTypeRef(NoComments, TsQIdent(IArray(TsIdentSimple("T"))), Empty)), ), - TsTypeLiteral(TsLiteralString("forEach")), + TsTypeLiteral(TsLiteral.Str("forEach")), ), ) @@ -2366,7 +2366,7 @@ type Readonly = { IArray( TsTypeLookup( TsTypeRef(NoComments, TsQIdent(IArray(TsIdentSimple("T"))), Empty), - TsTypeLiteral(TsLiteralString("forEach")), + TsTypeLiteral(TsLiteral.Str("forEach")), ), ), ), @@ -2402,7 +2402,7 @@ export {}; TsParsedFile( NoComments, Empty, - IArray(TsExport(NoComments, typeOnly = false, ExportType.Named, TsExporteeNames(Empty, None))), + IArray(TsExport(NoComments, typeOnly = false, ExportType.Named, TsExportee.Names(Empty, None))), CodePath.NoPath, ), ) @@ -2417,7 +2417,7 @@ export {}; NoComments, isReadOnly = false, ProtectionLevel.Private, - IndexingSingle(TsQIdent(IArray(TsIdentSimple("kChannel")))), + Indexing.Single(TsQIdent(IArray(TsIdentSimple("kChannel")))), None, ), ) @@ -2432,7 +2432,7 @@ export {}; NoComments, isReadOnly = false, ProtectionLevel.Default, - IndexingDict(TsIdentSimple("attributeName"), TsTypeRef.string), + Indexing.Dict(TsIdentSimple("attributeName"), TsTypeRef.string), Some( TsTypeUnion( IArray( @@ -2597,7 +2597,7 @@ export {}; test("expr with parents") { shouldParseAs("""(1 << 2)""", TsParser.expr)( - TsExpr.BinaryOp(TsExpr.Literal(TsLiteralNumber("1")), "<<", TsExpr.Literal(TsLiteralNumber("2"))), + TsExpr.BinaryOp(TsExpr.Literal(TsLiteral.Num("1")), "<<", TsExpr.Literal(TsLiteral.Num("2"))), ) } @@ -2642,7 +2642,7 @@ export {}; NoComments, typeOnly = false, ExportType.Named, - TsExporteeTree( + TsExportee.Tree( TsDeclVar( NoComments, declared = true, @@ -2673,7 +2673,7 @@ export {}; shouldParseAs("""LoggingLevel.ERROR(6 + 7)""", TsParser.expr)( TsExpr.Call( TsExpr.Ref(TsQIdent(IArray(TsIdentSimple("LoggingLevel"), TsIdentSimple("ERROR")))), - IArray(TsExpr.BinaryOp(TsExpr.Literal(TsLiteralNumber("6")), "+", TsExpr.Literal(TsLiteralNumber("7")))), + IArray(TsExpr.BinaryOp(TsExpr.Literal(TsLiteral.Num("6")), "+", TsExpr.Literal(TsLiteral.Num("7")))), ), ) @@ -2698,25 +2698,25 @@ export {}; ) shouldParseAs("""1e-7""", TsParser.expr)( - TsExpr.Literal(TsLiteralNumber("1e-7")), + TsExpr.Literal(TsLiteral.Num("1e-7")), ) shouldParseAs("""(0x000FFFF2 + 2)""", TsParser.expr)( - TsExpr.BinaryOp(TsExpr.Literal(TsLiteralNumber("0x000FFFF2")), "+", TsExpr.Literal(TsLiteralNumber("2"))), + TsExpr.BinaryOp(TsExpr.Literal(TsLiteral.Num("0x000FFFF2")), "+", TsExpr.Literal(TsLiteral.Num("2"))), ) shouldParseAs("""(4)""", TsParser.expr)( - TsExpr.Literal(TsLiteralNumber("4")), + TsExpr.Literal(TsLiteral.Num("4")), ) shouldParseAs("""(4) >> 2""", TsParser.expr)( - TsExpr.BinaryOp(TsExpr.Literal(TsLiteralNumber("4")), ">>", TsExpr.Literal(TsLiteralNumber("2"))), + TsExpr.BinaryOp(TsExpr.Literal(TsLiteral.Num("4")), ">>", TsExpr.Literal(TsLiteral.Num("2"))), ) shouldParseAs("""(0x000FFFFF + 1) >> 2""", TsParser.expr)( TsExpr.BinaryOp( - TsExpr.BinaryOp(TsExpr.Literal(TsLiteralNumber("0x000FFFFF")), "+", TsExpr.Literal(TsLiteralNumber("1"))), + TsExpr.BinaryOp(TsExpr.Literal(TsLiteral.Num("0x000FFFFF")), "+", TsExpr.Literal(TsLiteral.Num("1"))), ">>", - TsExpr.Literal(TsLiteralNumber("2")), + TsExpr.Literal(TsLiteral.Num("2")), ), ) } diff --git a/sbt-converter/src/main/scala/org/scalablytyped/converter/internal/ImportTypings.scala b/sbt-converter/src/main/scala/org/scalablytyped/converter/internal/ImportTypings.scala index 0fd149e807..636205b682 100644 --- a/sbt-converter/src/main/scala/org/scalablytyped/converter/internal/ImportTypings.scala +++ b/sbt-converter/src/main/scala/org/scalablytyped/converter/internal/ImportTypings.scala @@ -29,11 +29,8 @@ object ImportTypings { } object Input { - import io.circe013.generic.auto._ - import jsonCodecs._ - - implicit val InputEncoder: Encoder[Input] = exportEncoder[Input].instance - implicit val InputDecoder: Decoder[Input] = exportDecoder[Input].instance + implicit val encodes: Encoder[Input] = io.circe013.generic.semiauto.deriveEncoder + implicit val decodes: Decoder[Input] = io.circe013.generic.semiauto.deriveDecoder } case class Output(externalDeps: Set[Dep.Concrete], allProjects: Seq[Dep.Concrete]) { @@ -48,10 +45,8 @@ object ImportTypings { } object Output { - import io.circe013.generic.auto._ - import jsonCodecs._ - implicit val OutputEncoder: Encoder[Output] = exportEncoder[Output].instance - implicit val OutputDecoder: Decoder[Output] = exportDecoder[Output].instance + implicit val encodes: Encoder[Output] = io.circe013.generic.semiauto.deriveEncoder + implicit val decodes: Decoder[Output] = io.circe013.generic.semiauto.deriveDecoder } def apply( diff --git a/sbt-converter/src/main/scala/org/scalablytyped/converter/internal/ImportTypingsGenSources.scala b/sbt-converter/src/main/scala/org/scalablytyped/converter/internal/ImportTypingsGenSources.scala index 96d6ef36b1..3fb31afcda 100644 --- a/sbt-converter/src/main/scala/org/scalablytyped/converter/internal/ImportTypingsGenSources.scala +++ b/sbt-converter/src/main/scala/org/scalablytyped/converter/internal/ImportTypingsGenSources.scala @@ -30,11 +30,9 @@ object ImportTypingsGenSources { ) object Input { - import io.circe013.generic.auto._ - import jsonCodecs._ - - implicit val ConfigEncoder: Encoder[Input] = exportEncoder[Input].instance - implicit val ConfigDecoder: Decoder[Input] = exportDecoder[Input].instance + import orphanCodecs._ + implicit val encodes: Encoder[Input] = io.circe013.generic.semiauto.deriveEncoder + implicit val decodes: Decoder[Input] = io.circe013.generic.semiauto.deriveDecoder } def apply( diff --git a/sbt-converter/src/main/scala/org/scalablytyped/converter/plugin/ScalablyTypedConverterExternalNpmPlugin.scala b/sbt-converter/src/main/scala/org/scalablytyped/converter/plugin/ScalablyTypedConverterExternalNpmPlugin.scala index 609892c48c..ba36cdc3da 100644 --- a/sbt-converter/src/main/scala/org/scalablytyped/converter/plugin/ScalablyTypedConverterExternalNpmPlugin.scala +++ b/sbt-converter/src/main/scala/org/scalablytyped/converter/plugin/ScalablyTypedConverterExternalNpmPlugin.scala @@ -2,7 +2,6 @@ package org.scalablytyped.converter.plugin import com.olvind.logging.Formatter import org.scalablytyped.converter.internal._ -import org.scalablytyped.converter.internal.importer.jsonCodecs.PackageJsonDepsDecoder import org.scalablytyped.converter.internal.maps._ import org.scalablytyped.converter.internal.ts.{PackageJsonDeps, TsIdentLibrary} import org.scalajs.sbtplugin.ScalaJSPlugin diff --git a/sbt-converter/src/main/scala/org/scalablytyped/converter/plugin/ScalablyTypedConverterGenSourcePlugin.scala b/sbt-converter/src/main/scala/org/scalablytyped/converter/plugin/ScalablyTypedConverterGenSourcePlugin.scala index bd8e894c68..592854d7ad 100644 --- a/sbt-converter/src/main/scala/org/scalablytyped/converter/plugin/ScalablyTypedConverterGenSourcePlugin.scala +++ b/sbt-converter/src/main/scala/org/scalablytyped/converter/plugin/ScalablyTypedConverterGenSourcePlugin.scala @@ -2,7 +2,7 @@ package org.scalablytyped.converter package plugin import org.scalablytyped.converter.internal._ -import org.scalablytyped.converter.internal.importer.jsonCodecs.{FileDecoder, FileEncoder} +import org.scalablytyped.converter.internal.orphanCodecs.{FileDecoder, FileEncoder} import org.scalablytyped.converter.internal.maps._ import org.scalablytyped.converter.internal.scalajs.{Name, QualifiedName} import org.scalablytyped.converter.internal.ts.TsIdentLibrary diff --git a/scalajs/src/main/scala/org/scalablytyped/converter/Flavour.scala b/scalajs/src/main/scala/org/scalablytyped/converter/Flavour.scala index 72be5e0f46..858adeaede 100644 --- a/scalajs/src/main/scala/org/scalablytyped/converter/Flavour.scala +++ b/scalajs/src/main/scala/org/scalablytyped/converter/Flavour.scala @@ -1,17 +1,22 @@ package org.scalablytyped.converter -sealed trait Flavour +import io.circe013.{Decoder, Encoder} + +sealed abstract class Flavour(val id: String) object Flavour { - case object Normal extends Flavour - case object Slinky extends Flavour - case object SlinkyNative extends Flavour - case object Japgolly extends Flavour + case object Normal extends Flavour("normal") + case object Slinky extends Flavour("slinky") + case object SlinkyNative extends Flavour("slinky-native") + case object Japgolly extends Flavour("japgolly") + + val All: List[Flavour] = + List(Normal, Slinky, SlinkyNative, Japgolly) + + val byName: Map[String, Flavour] = + All.map(f => f.id -> f).toMap - val all = Map( - "normal" -> Flavour.Normal, - "japgolly" -> Flavour.Japgolly, - "slinky" -> Flavour.Slinky, - "slinky-native" -> Flavour.SlinkyNative, - ) + implicit val encodes: Encoder[Flavour] = Encoder[String].contramap(_.id) + implicit val decodes: Decoder[Flavour] = + Decoder[String].emap(str => byName.get(str).toRight(s"flavour '$str' not among ${byName.keys}")) } diff --git a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/Dep.scala b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/Dep.scala index 99953a3f5c..24b64655bd 100644 --- a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/Dep.scala +++ b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/Dep.scala @@ -62,6 +62,10 @@ object Dep { // format: on } + object Concrete { + implicit val encodes: Encoder[Concrete] = io.circe013.generic.semiauto.deriveEncoder + implicit val decodes: Decoder[Concrete] = io.circe013.generic.semiauto.deriveDecoder + } case class Java(org: String, name: String, version: String) extends Concrete { override def mangledArtifact: String = name @@ -75,6 +79,6 @@ object Dep { override def version: String = dep.version } - implicit val DepDecoder: Decoder[Dep] = io.circe013.generic.semiauto.deriveDecoder[Dep] - implicit val DepEncoder: Encoder[Dep] = io.circe013.generic.semiauto.deriveEncoder[Dep] + implicit val decodes: Decoder[Dep] = io.circe013.generic.semiauto.deriveDecoder + implicit val encodes: Encoder[Dep] = io.circe013.generic.semiauto.deriveEncoder } diff --git a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/Erasure.scala b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/Erasure.scala index bce07fe99e..4ceb18db7b 100644 --- a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/Erasure.scala +++ b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/Erasure.scala @@ -62,7 +62,7 @@ object Erasure { case QualifiedName(IArray.exactlyOne(head)) if scope.tparams.contains(head) => QualifiedName.ScalaAny // if run after FakeSingletons - case name @ QualifiedName(parts) if parts.length > 2 && (tpe.comments.has[FakeLiterals.WasLiteral]) => name + case name @ QualifiedName(parts) if parts.length > 2 && (tpe.comments.has[Marker.WasLiteral]) => name case other => scope diff --git a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/FillInTParams.scala b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/FillInTParams.scala index 4b0de7f3fc..1a293314a3 100644 --- a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/FillInTParams.scala +++ b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/FillInTParams.scala @@ -1,8 +1,6 @@ package org.scalablytyped.converter.internal package scalajs -import org.scalablytyped.converter.internal.scalajs.transforms.UnionToInheritance - object FillInTParams { def apply( cls: ClassTree, @@ -15,11 +13,11 @@ object FillInTParams { val rewriter = TypeRewriter(rewrites(cls.tparams, providedTParams)) val newCls = rewriter.visitClassTree(scope)(cls) - newCls.comments.extract { case UnionToInheritance.WasUnion(related) => related } match { + newCls.comments.extract { case Marker.WasUnion(related) => related } match { case None => newCls case Some((related, rest)) => // https://en.wikipedia.org/wiki/Leaky_abstraction - val newRelated = CommentData(UnionToInheritance.WasUnion(related.map(rewriter.visitTypeRef(scope)))) + val newRelated = Marker.WasUnion(related.map(rewriter.visitTypeRef(scope))) newCls.copy(comments = rest + newRelated) } }.copy(tparams = newTParams) diff --git a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/FollowAliases.scala b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/FollowAliases.scala index 4e8f42ef32..7f8b3c7e17 100644 --- a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/FollowAliases.scala +++ b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/FollowAliases.scala @@ -1,8 +1,6 @@ package org.scalablytyped.converter.internal package scalajs -import org.scalablytyped.converter.internal.scalajs.transforms.UnionToInheritance - object FollowAliases { def apply(scope: TreeScope)(tpe: TypeRef): TypeRef = tpe match { @@ -20,9 +18,9 @@ object FollowAliases { .collectFirst { case (ta: TypeAliasTree, newScope) => apply(newScope)(FillInTParams(ta, scope, ref.targs, Empty).alias) - case (_cls: ClassTree, newScope) if _cls.comments.has[UnionToInheritance.WasUnion] => + case (_cls: ClassTree, newScope) if _cls.comments.has[Marker.WasUnion] => val cls = FillInTParams(_cls, newScope, ref.targs, Empty) - cls.comments.extract { case UnionToInheritance.WasUnion(types) => types } match { + cls.comments.extract { case Marker.WasUnion(types) => types } match { case Some((types, _)) => TypeRef.Union(types, NoComments, sort = true) case None => ref } diff --git a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/Minimization.scala b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/Minimization.scala index 8cf92e6c7c..45446a7fb7 100644 --- a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/Minimization.scala +++ b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/Minimization.scala @@ -6,13 +6,7 @@ import com.olvind.logging.Logger import scala.collection.mutable object Minimization { - val KeepMarker = Comments(CommentData(Minimization.Keep(Empty))) - - /* Disable the minimizer for object with this marker */ - final case class Keep(related: IArray[TypeRef]) extends Comment.Data - - /* Similar to above, but it's conditional. If the object with this marker is included, only then include the related objects as well */ - final case class Related(related: IArray[TypeRef]) extends Comment.Data + val KeepMarker = Comments(Marker.MinimizationKeep(Empty)) /* some refs we only keep when they refer to objects/packages */ type OnlyStatic = Boolean @@ -43,13 +37,14 @@ object Minimization { globalScope.lookup(parent).foreach { case (tree, _) => tree.comments.extract { - case Related(related) => + case Marker.MinimizationRelated(related) => TreeTraverse.foreach(related) { case TypeRef(typeName, _, _) if typeName =/= parent => expand(typeName) case _ => () } } + () } } @@ -70,7 +65,7 @@ object Minimization { val relatedRefs: IArray[TypeRef] = trees.flatMap { t => - t.comments.extract { case Related(x) => x } match { + t.comments.extract { case Marker.MinimizationRelated(x) => x } match { case Some(value) => value._1 case None => Empty } @@ -91,13 +86,14 @@ object Minimization { TreeTraverse.foreach(pkg) { case tree: Tree with HasCodePath => tree.comments.extract { - case Keep(related) => + case Marker.MinimizationKeep(related) => expand(tree.codePath) TreeTraverse.foreach(related) { case TypeRef(typeName, _, _) => expand(typeName) case _ => () } } + () case TypeRef(typeName, _, _) if !shouldMinimize => expand(typeName) case _ => () @@ -112,7 +108,7 @@ object Minimization { private final class FilteringTransformation(keep: KeepIndex) extends TreeTransformation { override def leaveModuleTree(scope: TreeScope)(s: ModuleTree): ModuleTree = - if (s.comments.has[Keep]) s + if (s.comments.has[Marker.MinimizationKeep]) s else { val newParents = s.parents.filter(tr => keep.contains(tr.typeName)) val newMembers = s.members.filter { diff --git a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/Versions.scala b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/Versions.scala index 0570356743..b9692aef90 100644 --- a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/Versions.scala +++ b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/Versions.scala @@ -1,5 +1,7 @@ package org.scalablytyped.converter.internal.scalajs +import io.circe013.{Decoder, Encoder} + object Versions { val sbtVersion = "1.4.2" @@ -21,6 +23,10 @@ object Versions { case other => other } } + object Scala { + implicit val encodes: Encoder[Scala] = Encoder[String].contramap(_.scalaVersion) + implicit val decodes: Decoder[Scala] = Decoder[String].map(Scala.apply) + } val Scala212 = Scala("2.12.13") @@ -52,9 +58,16 @@ object Versions { val compiler = Dep.ScalaFullVersion(scalaJsOrganization, "scalajs-compiler", scalaJsVersion) val sbtPlugin = Dep.Scala(scalaJsOrganization, "sbt-scalajs", scalaJsVersion) } + object ScalaJs { + implicit val encodes: Encoder[ScalaJs] = Encoder[String].contramap(_.scalaJsVersion) + implicit val decodes: Decoder[ScalaJs] = Decoder[String].map(ScalaJs.apply) + } val ScalaJs1 = ScalaJs("1.3.0") val ScalaJs06 = ScalaJs("0.6.33") + + implicit val encodes: Encoder[Versions] = io.circe013.generic.semiauto.deriveEncoder + implicit val decodes: Decoder[Versions] = io.circe013.generic.semiauto.deriveDecoder } case class Versions(scala: Versions.Scala, scalaJs: Versions.ScalaJs) { diff --git a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/CastConversion.scala b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/CastConversion.scala index ecbc71c2a4..300a5851eb 100644 --- a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/CastConversion.scala +++ b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/CastConversion.scala @@ -117,14 +117,13 @@ object CastConversion { * then replacing the type parameter with something that actually conforms. */ object UndoDamage { - case class WasDefaulted(among: Set[QualifiedName]) extends Comment.Data def comment(among: Set[QualifiedName]) = - Comments(CommentData(WasDefaulted(among))) + Comments(Marker.WasDefaulted(among)) def apply(x: TypeRef): TypeRef = x match { case TypeRef.Intersection(IArray.exactlyTwo(original, _), comments: Comments) => - comments.extract { case WasDefaulted(among) => among } match { + comments.extract { case Marker.WasDefaulted(among) => among } match { case Some((among, _)) if among.contains(original.typeName) => original case _ => x } diff --git a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/CreatorMethod.scala b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/CreatorMethod.scala index 854c984118..891dc923b7 100644 --- a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/CreatorMethod.scala +++ b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/CreatorMethod.scala @@ -70,8 +70,8 @@ object CreatorMethod { // required literals case prop @ Prop.Normal(Prop.Variant(tpe, _, _, _), _, Optionality.No, _, _) - if tpe.comments.has[FakeLiterals.WasLiteral] => - val literal = tpe.comments.extract { case FakeLiterals.WasLiteral(lit) => lit }.get._1 + if tpe.comments.has[Marker.WasLiteral] => + val literal = tpe.comments.extract { case Marker.WasLiteral(lit) => lit }.get._1 Const(requiredProp(prop, literal)) @@ -103,8 +103,8 @@ object CreatorMethod { ) case prop @ Prop.Normal(Prop.Variant(tpe, _, _, _), _, Optionality.No, _, _) - if tpe.comments.has[FakeLiterals.WasLiteral] => - val lit = tpe.comments.extract { case FakeLiterals.WasLiteral(lit) => lit }.get._1 + if tpe.comments.has[Marker.WasLiteral] => + val lit = tpe.comments.extract { case Marker.WasLiteral(lit) => lit }.get._1 Const(requiredProp(prop, lit)) diff --git a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/FindProps.scala b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/FindProps.scala index 7a23ef3198..ea1a315b18 100644 --- a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/FindProps.scala +++ b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/FindProps.scala @@ -144,7 +144,7 @@ final class FindProps( acceptNativeTraits: Boolean, selfRef: TypeRef, ): Res[IArray[String], IArray[Prop]] = - cls.comments.extract { case UnionToInheritance.WasUnion(subclassRefs) => subclassRefs } match { + cls.comments.extract { case Marker.WasUnion(subclassRefs) => subclassRefs } match { case Some((subclassRefs, _)) => Res.combine(subclassRefs.map { subClsRef => scope @@ -255,7 +255,7 @@ final class FindProps( private def combine(ms: IArray[MemberTree]): MemberTree = ms.partitionCollect2({ case x: FieldTree => x }, { case x: MethodTree => x }) match { - case (IArray.exactlyOne(field), _, _) if field.comments.has[Markers.ExpandedCallables.type] => + case (IArray.exactlyOne(field), _, _) if field.comments.has[Marker.ExpandedCallables.type] => field case (_, IArray.exactlyOne(method), Empty) => method diff --git a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/GenCompanions.scala b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/GenCompanions.scala index dbbb8c9959..4bcaa028a5 100644 --- a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/GenCompanions.scala +++ b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/GenCompanions.scala @@ -42,7 +42,7 @@ final class GenCompanions(findProps: FindProps, enableLongApplyMethod: Boolean) /** When we rewrite type unions to inheritance we might produce two companions in the same scope, see `echarts` test. * This test catches a bit too much (meaning we might not generate some companions), but it should be fairly safe */ - if (cls.comments.has[UnionToInheritance.WasUnion]) + if (cls.comments.has[Marker.WasUnion]) container.index(cls.name).length > 1 else container.index(cls.name).exists { @@ -92,8 +92,8 @@ final class GenCompanions(findProps: FindProps, enableLongApplyMethod: Boolean) generatedCreators ++ IArray.fromOption(generatedBuilder) match { case Empty => None case some => - val related = Minimization.Related(some.collect { case m: HasCodePath => TypeRef(m.codePath) }) - val dontMinimize = Comments(CommentData(related)) + val related = Marker.MinimizationRelated(some.collect { case m: HasCodePath => TypeRef(m.codePath) }) + val dontMinimize = Comments(related) val mod = ModuleTree(Empty, cls.name, Empty, some, dontMinimize, cls.codePath, isOverride = false) Some(mod) } diff --git a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/JapgollyGenComponents.scala b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/JapgollyGenComponents.scala index cb959a9379..532d9778a6 100644 --- a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/JapgollyGenComponents.scala +++ b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/JapgollyGenComponents.scala @@ -272,7 +272,7 @@ class JapgollyGenComponents( case nonEmpty => val newPackage = setCodePath( pkgCp, - PackageTree(Empty, names.components, nonEmpty, Comments(CommentData(Mangler.LeaveAlone)), pkgCp), + PackageTree(Empty, names.components, nonEmpty, Comments(Marker.ManglerLeaveAlone), pkgCp), ) tree.withMembers(tree.members :+ newPackage) } diff --git a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/JapgollyGenStBuildingComponent.scala b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/JapgollyGenStBuildingComponent.scala index 0fb36f9f85..2a8b1c5947 100644 --- a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/JapgollyGenStBuildingComponent.scala +++ b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/JapgollyGenStBuildingComponent.scala @@ -437,7 +437,7 @@ class JapgollyGenStBuildingComponent(val outputPkg: Name, val scalaVersion: Vers name, IArray(TypeRef.Object), IArray(createElementField), - Minimization.KeepMarker + CommentData(Mangler.LeaveAlone), + Minimization.KeepMarker + Marker.ManglerLeaveAlone, ReactRawCp, isOverride = false, ) @@ -513,7 +513,7 @@ class JapgollyGenStBuildingComponent(val outputPkg: Name, val scalaVersion: Vers StBuildingComponent, Empty, IArray(ReactRaw, make, Default), - Minimization.KeepMarker + CommentData(Mangler.LeaveAlone), + Minimization.KeepMarker + Marker.ManglerLeaveAlone, builderCp, isOverride = false, ) diff --git a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/SlinkyGenComponents.scala b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/SlinkyGenComponents.scala index 8417696034..fc0c15a8e8 100644 --- a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/SlinkyGenComponents.scala +++ b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/SlinkyGenComponents.scala @@ -303,7 +303,7 @@ class SlinkyGenComponents( case nonEmpty => val newPackage = setCodePath( pkgCp, - PackageTree(Empty, names.components, nonEmpty, Comments(CommentData(Mangler.LeaveAlone)), pkgCp), + PackageTree(Empty, names.components, nonEmpty, Comments(Marker.ManglerLeaveAlone), pkgCp), ) tree.withMembers(tree.members :+ newPackage) } diff --git a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/SlinkyGenStBuildingComponent.scala b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/SlinkyGenStBuildingComponent.scala index 0deac9e79b..3894c14f31 100644 --- a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/SlinkyGenStBuildingComponent.scala +++ b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/SlinkyGenStBuildingComponent.scala @@ -388,7 +388,7 @@ class SlinkyGenStBuildingComponent(val outputPkg: Name, val scalaVersion: Versio name, IArray(TypeRef.Object), IArray(createElementField), - Minimization.KeepMarker + CommentData(Mangler.LeaveAlone), + Minimization.KeepMarker + Marker.ManglerLeaveAlone, ReactRawCp, isOverride = false, ) @@ -465,7 +465,7 @@ class SlinkyGenStBuildingComponent(val outputPkg: Name, val scalaVersion: Versio StBuildingComponent, Empty, IArray(ReactRaw, make, Default), - Minimization.KeepMarker + CommentData(Mangler.LeaveAlone), + Minimization.KeepMarker + Marker.ManglerLeaveAlone, builderCp, isOverride = false, ) diff --git a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/transforms/CleanupTypeAliases.scala b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/transforms/CleanupTypeAliases.scala index 3e11875f05..b76e54132b 100644 --- a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/transforms/CleanupTypeAliases.scala +++ b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/transforms/CleanupTypeAliases.scala @@ -29,7 +29,7 @@ object CleanupTypeAliases extends TreeTransformation { def removeTrivialTypeAlias(members: IArray[Tree]): IArray[Tree] = members.mapNotNone { case ta: TypeAliasTree => - ta.comments.extract { case Markers.IsTrivial => () } match { + ta.comments.extract { case Marker.IsTrivial => () } match { case None => Some(ta) case Some((_, restCs)) => if (restCs.cs.nonEmpty) @@ -37,7 +37,7 @@ object CleanupTypeAliases extends TreeTransformation { None } - case x: FieldTree if x.comments.has[Markers.IsTrivial.type] => None + case x: FieldTree if x.comments.has[Marker.IsTrivial.type] => None case other => Some(other) } } diff --git a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/transforms/FakeLiterals.scala b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/transforms/FakeLiterals.scala index dc4b4660d0..a49fa96f85 100644 --- a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/transforms/FakeLiterals.scala +++ b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/transforms/FakeLiterals.scala @@ -6,9 +6,6 @@ import scala.collection.mutable import scala.util.{Success, Try} object FakeLiterals { - /* hack: I needed some out of band communication that a TypeRef is actually to a fake literal type. We use reference equality */ - case class WasLiteral(lit: ExprTree.Lit) extends Comment.Data - def apply(outputPkg: Name, scope: TreeScope, illegalNames: CleanIllegalNames)(tree: ContainerTree): ContainerTree = LiteralRewriter(outputPkg, illegalNames, tree, scope).output @@ -111,7 +108,7 @@ object FakeLiterals { TypeRef( QualifiedName(IArray(outputPkg, tree.name, StringModuleName, name)), Empty, - Comments(CommentData(WasLiteral(lit))), + Comments(Marker.WasLiteral(lit)), ) case TypeRef.BooleanLiteral(underlying) => @@ -121,7 +118,7 @@ object FakeLiterals { TypeRef( QualifiedName(IArray(outputPkg, tree.name, BooleansModuleName, name)), Empty, - Comments(CommentData(WasLiteral(lit))), + Comments(Marker.WasLiteral(lit)), ) case TypeRef.NumberLiteral(underlying) => @@ -137,7 +134,7 @@ object FakeLiterals { TypeRef( QualifiedName(IArray(outputPkg, tree.name, NumbersModuleName, name)), Empty, - Comments(CommentData(WasLiteral(lit))), + Comments(Marker.WasLiteral(lit)), ) case other => diff --git a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/transforms/Mangler.scala b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/transforms/Mangler.scala index b6e08434b3..3e616f8e6d 100644 --- a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/transforms/Mangler.scala +++ b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/transforms/Mangler.scala @@ -5,15 +5,13 @@ package transforms import org.scalablytyped.converter.internal.scalajs.ExprTree._ object Mangler extends TreeTransformation { - case object LeaveAlone extends Comment.Data - case object WasJsNative extends Comment.Data - val WasJsNativeComment = Comments(List(CommentData(WasJsNative))) + val WasJsNativeComment = Comments(List(Marker.ManglerWasJsNative)) override def leaveContainerTree(scope: TreeScope)(container: ContainerTree): ContainerTree = { val rewrittenMembers = container.members.map { - case pkg: PackageTree if pkg.comments.has[LeaveAlone.type] => pkg + case pkg: PackageTree if pkg.comments.has[Marker.ManglerLeaveAlone.type] => pkg case pkg: PackageTree => genPkgForwarders(pkg, Empty) - case mod: ModuleTree if mod.comments.has[Markers.EnumObject.type] => + case mod: ModuleTree if mod.comments.has[Marker.EnumObject.type] => def stripLocationAnns(tree: Tree): Tree = { def filterAnns(anns: IArray[Annotation]): IArray[Annotation] = anns.filter { @@ -33,7 +31,7 @@ object Mangler extends TreeTransformation { } mod.copy(members = mod.members.map(stripLocationAnns)) - case mod: ModuleTree if mod.comments.has[LeaveAlone.type] || !mod.isNative => mod + case mod: ModuleTree if mod.comments.has[Marker.ManglerLeaveAlone.type] || !mod.isNative => mod case mod: ModuleTree => Action(scope / mod, mod) match { case Action.RemainModule => @@ -49,7 +47,7 @@ object Mangler extends TreeTransformation { } val isTopLevel = scope.stack.length < 3 // typings, libName - if (isTopLevel && !container.comments.has[LeaveAlone.type]) + if (isTopLevel && !container.comments.has[Marker.ManglerLeaveAlone.type]) genPkgForwarders( PackageTree(container.annotations, container.name, rewrittenMembers, container.comments, container.codePath), Empty, @@ -113,7 +111,7 @@ object Mangler extends TreeTransformation { case (n, _) => n } - if (mod.comments.has[Markers.EnumObject.type]) false + if (mod.comments.has[Marker.EnumObject.type]) false else countClasses(mod) > 40 } @@ -248,10 +246,10 @@ object Mangler extends TreeTransformation { hatModuleOpt.map(hat => TypeRef(hat.codePath)), ) - pkg.comments.extract { case Minimization.Related(related) => related } match { + pkg.comments.extract { case Marker.MinimizationRelated(related) => related } match { case Some((existingRelated, restComments)) => - restComments + CommentData(Minimization.Related(existingRelated ++ addedRelated)) - case None => pkg.comments + CommentData(Minimization.Related(addedRelated)) + restComments + Marker.MinimizationRelated(existingRelated ++ addedRelated) + case None => pkg.comments + Marker.MinimizationRelated(addedRelated) } } @@ -433,10 +431,10 @@ object Mangler extends TreeTransformation { hatOpt.map(hat => TypeRef(hat.codePath)), ) - mod.comments.extract { case Minimization.Related(related) => related } match { + mod.comments.extract { case Marker.MinimizationRelated(related) => related } match { case Some((existingRelated, restComments)) => - restComments + CommentData(Minimization.Related(existingRelated ++ addedRelated)) - case None => mod.comments + CommentData(Minimization.Related(addedRelated)) + restComments + Marker.MinimizationRelated(existingRelated ++ addedRelated) + case None => mod.comments + Marker.MinimizationRelated(addedRelated) } } diff --git a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/transforms/Sorter.scala b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/transforms/Sorter.scala index 5603821096..82e5036499 100644 --- a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/transforms/Sorter.scala +++ b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/transforms/Sorter.scala @@ -23,7 +23,7 @@ object Sorter extends TreeTransformation { } def had(comments: Comments): Boolean = - comments.has[Mangler.WasJsNative.type] + comments.has[Marker.ManglerWasJsNative.type] t match { case tree: ContainerTree => has(tree.annotations) || tree.members.exists(hasNativeLocation) || had(tree.comments) diff --git a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/transforms/UnionToInheritance.scala b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/transforms/UnionToInheritance.scala index ccfc2a3bde..8bb3ee3a18 100644 --- a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/transforms/UnionToInheritance.scala +++ b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/transforms/UnionToInheritance.scala @@ -67,8 +67,6 @@ package transforms * ``` */ object UnionToInheritance { - final case class WasUnion(related: IArray[TypeRef]) extends Comment.Data - def apply( scope: TreeScope, tree: ContainerTree, @@ -121,8 +119,7 @@ object UnionToInheritance { Empty, ClassType.Trait, isSealed = false, - ta.comments ++? commentsOpt + CommentData(Minimization.Related(asInheritance)) + - CommentData(WasUnion(asInheritance)), + ta.comments ++? commentsOpt + Marker.MinimizationRelated(asInheritance) + Marker.WasUnion(asInheritance), ta.codePath, ) @@ -139,9 +136,7 @@ object UnionToInheritance { Empty, ClassType.Trait, isSealed = false, - Comments( - List(CommentData(Minimization.Related(asInheritance)), CommentData(WasUnion(asInheritance))), - ), + Comments(List(Marker.MinimizationRelated(asInheritance), Marker.WasUnion(asInheritance))), patchedTa.codePath, ) val newTa = ta.copy( diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/DeriveNonConflictingName.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/DeriveNonConflictingName.scala index 609b0e5d2c..d838ccbe9b 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/DeriveNonConflictingName.scala +++ b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/DeriveNonConflictingName.scala @@ -38,7 +38,7 @@ object DeriveNonConflictingName { case x: TsMemberProperty => val short = Detail.pretty(x.name.value) Detail(short, IArray.fromOptions(Some(short), Detail.prettyType(x.tpe)).mkString) - case TsMemberIndex(_, _, _, IndexingSingle(qname), tpe) => + case TsMemberIndex(_, _, _, Indexing.Single(qname), tpe) => val short = Detail.pretty(qname.parts.last.value) Detail(short, IArray.fromOptions(Some(short), Detail.prettyType(tpe)).mkString) case x: TsMemberFunction => Detail(Detail.pretty(x.name.value)) @@ -57,7 +57,7 @@ object DeriveNonConflictingName { val fromDict: Option[Detail] = members .collectFirst { - case TsMemberIndex(_, _, _, IndexingDict(name, inType), outType) => + case TsMemberIndex(_, _, _, Indexing.Dict(name, inType), outType) => val short = Detail.pretty("Dict" + name.value) val long = IArray .fromOptions(Some(short), Some(Detail.prettyType(inType)), Detail.prettyType(outType)) diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/FlattenTrees.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/FlattenTrees.scala index 2b33ab5279..d30982d27b 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/FlattenTrees.scala +++ b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/FlattenTrees.scala @@ -123,7 +123,7 @@ object FlattenTrees { case that: TsDeclTypeAlias => rets.addOrUpdateMatching(that)(x => x) { case existing: TsDeclTypeAlias if that.name === existing.name => - IArray(existing, that).find(ta => !ta.comments.has[Markers.IsTrivial.type]).getOrElse { + IArray(existing, that).find(ta => !ta.comments.has[Marker.IsTrivial.type]).getOrElse { TsDeclTypeAlias( comments = mergeComments(existing.comments, that.comments), declared = existing.declared || that.declared, diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/ModuleNameParser.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/ModuleNameParser.scala index d179b178e7..0718a49b7c 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/ModuleNameParser.scala +++ b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/ModuleNameParser.scala @@ -2,7 +2,7 @@ package org.scalablytyped.converter.internal package ts object ModuleNameParser { - def apply(lit: TsLiteralString): TsIdentModule = apply(lit.value.split("/").toList, keepIndexFragment = true) + def apply(lit: TsLiteral.Str): TsIdentModule = apply(lit.value.split("/").toList, keepIndexFragment = true) def apply(fragments: List[String], keepIndexFragment: Boolean): TsIdentModule = { val rewritten: List[String] = diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/TreeTransformation.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/TreeTransformation.scala index 6fb989a537..488c71735f 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/TreeTransformation.scala +++ b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/TreeTransformation.scala @@ -5,70 +5,69 @@ package ts trait TreeTransformation[T] { self => def withTree(t: T, tree: TsTree): T - def enterTsDeclClass(t: T)(x: TsDeclClass): TsDeclClass = x - def enterTsDeclEnum(t: T)(x: TsDeclEnum): TsDeclEnum = x - def enterTsDeclFunction(t: T)(x: TsDeclFunction): TsDeclFunction = x - def enterTsGlobal(t: T)(x: TsGlobal): TsGlobal = x - def enterTsDeclInterface(t: T)(x: TsDeclInterface): TsDeclInterface = x - def enterTsDeclModule(t: T)(x: TsDeclModule): TsDeclModule = x - def enterTsAugmentedModule(t: T)(x: TsAugmentedModule): TsAugmentedModule = x - def enterTsDeclNamespace(t: T)(x: TsDeclNamespace): TsDeclNamespace = x - def enterTsDeclTypeAlias(t: T)(x: TsDeclTypeAlias): TsDeclTypeAlias = x - def enterTsDeclVar(t: T)(x: TsDeclVar): TsDeclVar = x - def enterTsEnumMember(t: T)(x: TsEnumMember): TsEnumMember = x - def enterTsExportAsNamespace(t: T)(x: TsExportAsNamespace): TsExportAsNamespace = x - def enterTsExporteeNames(t: T)(x: TsExporteeNames): TsExporteeNames = x - def enterTsExporteeStar(t: T)(x: TsExporteeStar): TsExporteeStar = x - def enterTsExporteeTree(t: T)(x: TsExporteeTree): TsExporteeTree = x - def enterTsExport(t: T)(x: TsExport): TsExport = x - def enterTsFunParam(t: T)(x: TsFunParam): TsFunParam = x - def enterTsFunSig(t: T)(x: TsFunSig): TsFunSig = x - def enterTsImportedDestructured(t: T)(x: TsImportedDestructured): TsImportedDestructured = x - def enterTsImportedIdent(t: T)(x: TsImportedIdent): TsImportedIdent = x - def enterTsImportedStar(t: T)(x: TsImportedStar): TsImportedStar = x - def enterTsImporteeFrom(t: T)(x: TsImporteeFrom): TsImporteeFrom = x - def enterTsImporteeLocal(t: T)(x: TsImporteeLocal): TsImporteeLocal = x - def enterTsImporteeRequired(t: T)(x: TsImporteeRequired): TsImporteeRequired = x - def enterTsImport(t: T)(x: TsImport): TsImport = x - def enterTsLiteralBoolean(t: T)(x: TsLiteralBoolean): TsLiteralBoolean = x - def enterTsLiteralNumber(t: T)(x: TsLiteralNumber): TsLiteralNumber = x - def enterTsLiteralString(t: T)(x: TsLiteralString): TsLiteralString = x - def enterTsMemberCall(t: T)(x: TsMemberCall): TsMemberCall = x - def enterTsMemberCtor(t: T)(x: TsMemberCtor): TsMemberCtor = x - def enterTsMemberFunction(t: T)(x: TsMemberFunction): TsMemberFunction = x - def enterTsMemberIndex(t: T)(x: TsMemberIndex): TsMemberIndex = x - def enterTsMemberProperty(t: T)(x: TsMemberProperty): TsMemberProperty = x - def enterTsMemberTypeMapped(t: T)(x: TsMemberTypeMapped): TsMemberTypeMapped = x - def enterTsParsedFile(t: T)(x: TsParsedFile): TsParsedFile = x - def enterTsQIdent(t: T)(x: TsQIdent): TsQIdent = x - def enterTsTypeAsserts(t: T)(x: TsTypeAsserts): TsTypeAsserts = x - def enterTsTypeConstructor(t: T)(x: TsTypeConstructor): TsTypeConstructor = x - def enterTsTypeConditional(t: T)(x: TsTypeConditional): TsTypeConditional = x - def enterTsTypeExtends(t: T)(x: TsTypeExtends): TsTypeExtends = x - def enterTsTypeFunction(t: T)(x: TsTypeFunction): TsTypeFunction = x - def enterTsTypeKeyOf(t: T)(x: TsTypeKeyOf): TsTypeKeyOf = x - def enterTsTypeIntersect(t: T)(x: TsTypeIntersect): TsTypeIntersect = x - def enterTsTypeIs(t: T)(x: TsTypeIs): TsTypeIs = x - def enterTsTypeInfer(t: T)(x: TsTypeInfer): TsTypeInfer = x - def enterTsTypeLiteral(t: T)(x: TsTypeLiteral): TsTypeLiteral = x - def enterTsTypeLookup(t: T)(x: TsTypeLookup): TsTypeLookup = x - def enterTsTypeObject(t: T)(x: TsTypeObject): TsTypeObject = x - def enterTsTypeParam(t: T)(x: TsTypeParam): TsTypeParam = x - def enterTsTypeQuery(t: T)(x: TsTypeQuery): TsTypeQuery = x - def enterTsTypeRef(t: T)(x: TsTypeRef): TsTypeRef = x - def enterTsTypeRepeated(t: T)(x: TsTypeRepeated): TsTypeRepeated = x - def enterTsTypeThis(t: T)(x: TsTypeThis): TsTypeThis = x - def enterTsTypeTuple(t: T)(x: TsTypeTuple): TsTypeTuple = x - def enterTsTypeUnion(t: T)(x: TsTypeUnion): TsTypeUnion = x - def enterIndexingDict(t: T)(x: IndexingDict): IndexingDict = x - def enterIndexingSingle(t: T)(x: IndexingSingle): IndexingSingle = x + def enterTsDeclClass(t: T)(x: TsDeclClass): TsDeclClass = x + def enterTsDeclEnum(t: T)(x: TsDeclEnum): TsDeclEnum = x + def enterTsDeclFunction(t: T)(x: TsDeclFunction): TsDeclFunction = x + def enterTsGlobal(t: T)(x: TsGlobal): TsGlobal = x + def enterTsDeclInterface(t: T)(x: TsDeclInterface): TsDeclInterface = x + def enterTsDeclModule(t: T)(x: TsDeclModule): TsDeclModule = x + def enterTsAugmentedModule(t: T)(x: TsAugmentedModule): TsAugmentedModule = x + def enterTsDeclNamespace(t: T)(x: TsDeclNamespace): TsDeclNamespace = x + def enterTsDeclTypeAlias(t: T)(x: TsDeclTypeAlias): TsDeclTypeAlias = x + def enterTsDeclVar(t: T)(x: TsDeclVar): TsDeclVar = x + def enterTsEnumMember(t: T)(x: TsEnumMember): TsEnumMember = x + def enterTsExportAsNamespace(t: T)(x: TsExportAsNamespace): TsExportAsNamespace = x + def enterTsExporteeNames(t: T)(x: TsExportee.Names): TsExportee.Names = x + def enterTsExporteeStar(t: T)(x: TsExportee.Star): TsExportee.Star = x + def enterTsExporteeTree(t: T)(x: TsExportee.Tree): TsExportee.Tree = x + def enterTsExport(t: T)(x: TsExport): TsExport = x + def enterTsFunParam(t: T)(x: TsFunParam): TsFunParam = x + def enterTsFunSig(t: T)(x: TsFunSig): TsFunSig = x + def enterTsImportedDestructured(t: T)(x: TsImported.Destructured): TsImported.Destructured = x + def enterTsImportedIdent(t: T)(x: TsImported.Ident): TsImported.Ident = x + def enterTsImportedStar(t: T)(x: TsImported.Star): TsImported.Star = x + def enterTsImporteeFrom(t: T)(x: TsImportee.From): TsImportee.From = x + def enterTsImporteeLocal(t: T)(x: TsImportee.Local): TsImportee.Local = x + def enterTsImporteeRequired(t: T)(x: TsImportee.Required): TsImportee.Required = x + def enterTsImport(t: T)(x: TsImport): TsImport = x + def enterTsLiteralBoolean(t: T)(x: TsLiteral.Bool): TsLiteral.Bool = x + def enterTsLiteralNumber(t: T)(x: TsLiteral.Num): TsLiteral.Num = x + def enterTsLiteralString(t: T)(x: TsLiteral.Str): TsLiteral.Str = x + def enterTsMemberCall(t: T)(x: TsMemberCall): TsMemberCall = x + def enterTsMemberCtor(t: T)(x: TsMemberCtor): TsMemberCtor = x + def enterTsMemberFunction(t: T)(x: TsMemberFunction): TsMemberFunction = x + def enterTsMemberIndex(t: T)(x: TsMemberIndex): TsMemberIndex = x + def enterTsMemberProperty(t: T)(x: TsMemberProperty): TsMemberProperty = x + def enterTsMemberTypeMapped(t: T)(x: TsMemberTypeMapped): TsMemberTypeMapped = x + def enterTsParsedFile(t: T)(x: TsParsedFile): TsParsedFile = x + def enterTsQIdent(t: T)(x: TsQIdent): TsQIdent = x + def enterTsTypeAsserts(t: T)(x: TsTypeAsserts): TsTypeAsserts = x + def enterTsTypeConstructor(t: T)(x: TsTypeConstructor): TsTypeConstructor = x + def enterTsTypeConditional(t: T)(x: TsTypeConditional): TsTypeConditional = x + def enterTsTypeExtends(t: T)(x: TsTypeExtends): TsTypeExtends = x + def enterTsTypeFunction(t: T)(x: TsTypeFunction): TsTypeFunction = x + def enterTsTypeKeyOf(t: T)(x: TsTypeKeyOf): TsTypeKeyOf = x + def enterTsTypeIntersect(t: T)(x: TsTypeIntersect): TsTypeIntersect = x + def enterTsTypeIs(t: T)(x: TsTypeIs): TsTypeIs = x + def enterTsTypeInfer(t: T)(x: TsTypeInfer): TsTypeInfer = x + def enterTsTypeLiteral(t: T)(x: TsTypeLiteral): TsTypeLiteral = x + def enterTsTypeLookup(t: T)(x: TsTypeLookup): TsTypeLookup = x + def enterTsTypeObject(t: T)(x: TsTypeObject): TsTypeObject = x + def enterTsTypeParam(t: T)(x: TsTypeParam): TsTypeParam = x + def enterTsTypeQuery(t: T)(x: TsTypeQuery): TsTypeQuery = x + def enterTsTypeRef(t: T)(x: TsTypeRef): TsTypeRef = x + def enterTsTypeRepeated(t: T)(x: TsTypeRepeated): TsTypeRepeated = x + def enterTsTypeThis(t: T)(x: TsTypeThis): TsTypeThis = x + def enterTsTypeTuple(t: T)(x: TsTypeTuple): TsTypeTuple = x + def enterTsTypeUnion(t: T)(x: TsTypeUnion): TsTypeUnion = x + def enterIndexingDict(t: T)(x: Indexing.Dict): Indexing.Dict = x + def enterIndexingSingle(t: T)(x: Indexing.Single): Indexing.Single = x def enterTsTree(t: T)(x: TsTree): TsTree = x def enterTsDecl(t: T)(x: TsDecl): TsDecl = x def enterTsNamedDecl(t: T)(x: TsNamedDecl): TsNamedDecl = x def enterTsContainer(t: T)(x: TsContainer): TsContainer = x def enterTsContainerOrDecl(t: T)(x: TsContainerOrDecl): TsContainerOrDecl = x - def enterTsTerm(t: T)(x: TsTerm): TsTerm = x def enterTsLiteral(t: T)(x: TsLiteral): TsLiteral = x def enterTsType(t: T)(x: TsType): TsType = x def enterTsMember(t: T)(x: TsMember): TsMember = x @@ -206,24 +205,24 @@ trait TreeTransformation[T] { self => final def visitTsExportAsNamespace(t: T)(x: TsExportAsNamespace): TsExportAsNamespace = enterTsExportAsNamespace(withTree(t, x))(x) - final def visitTsExporteeNames(t: T)(x: TsExporteeNames): TsExporteeNames = { + final def visitTsExporteeNames(t: T)(x: TsExportee.Names): TsExportee.Names = { val xx = enterTsExporteeNames(withTree(t, x))(x) val tt = withTree(t, xx) xx match { - case TsExporteeNames(_1, _2) => - TsExporteeNames(_1.map(a => (visitTsQIdent(tt)(a._1), a._2)), _2) + case TsExportee.Names(_1, _2) => + TsExportee.Names(_1.map(a => (visitTsQIdent(tt)(a._1), a._2)), _2) } } - final def visitTsExporteeStar(t: T)(x: TsExporteeStar): TsExporteeStar = + final def visitTsExporteeStar(t: T)(x: TsExportee.Star): TsExportee.Star = enterTsExporteeStar(withTree(t, x))(x) - final def visitTsExporteeTree(t: T)(x: TsExporteeTree): TsExporteeTree = { + final def visitTsExporteeTree(t: T)(x: TsExportee.Tree): TsExportee.Tree = { val xx = enterTsExporteeTree(withTree(t, x))(x) val tt = withTree(t, xx) xx match { - case TsExporteeTree(_1) => - TsExporteeTree(visitTsDecl(tt)(_1)) + case TsExportee.Tree(_1) => + TsExportee.Tree(visitTsDecl(tt)(_1)) } } final def visitTsExport(t: T)(x: TsExport): TsExport = { @@ -250,24 +249,22 @@ trait TreeTransformation[T] { self => } } - final def visitTsImportedDestructured( - t: T, - )(x: TsImportedDestructured): TsImportedDestructured = + final def visitTsImportedDestructured(t: T)(x: TsImported.Destructured): TsImported.Destructured = enterTsImportedDestructured(withTree(t, x))(x) - final def visitTsImportedIdent(t: T)(x: TsImportedIdent): TsImportedIdent = + final def visitTsImportedIdent(t: T)(x: TsImported.Ident): TsImported.Ident = enterTsImportedIdent(withTree(t, x))(x) - final def visitTsImportedStar(t: T)(x: TsImportedStar): TsImportedStar = + final def visitTsImportedStar(t: T)(x: TsImported.Star): TsImported.Star = enterTsImportedStar(withTree(t, x))(x) - final def visitTsImporteeFrom(t: T)(x: TsImporteeFrom): TsImporteeFrom = + final def visitTsImporteeFrom(t: T)(x: TsImportee.From): TsImportee.From = enterTsImporteeFrom(withTree(t, x))(x) - final def visitTsImporteeLocal(t: T)(x: TsImporteeLocal): TsImporteeLocal = { + final def visitTsImporteeLocal(t: T)(x: TsImportee.Local): TsImportee.Local = { val xx = enterTsImporteeLocal(withTree(t, x))(x) val tt = withTree(t, xx) xx match { - case TsImporteeLocal(_1) => TsImporteeLocal(visitTsQIdent(tt)(_1)) + case TsImportee.Local(_1) => TsImportee.Local(visitTsQIdent(tt)(_1)) } } - final def visitTsImporteeRequired(t: T)(x: TsImporteeRequired): TsImporteeRequired = + final def visitTsImporteeRequired(t: T)(x: TsImportee.Required): TsImportee.Required = enterTsImporteeRequired(withTree(t, x))(x) final def visitTsImport(t: T)(x: TsImport): TsImport = { val xx = enterTsImport(withTree(t, x))(x) @@ -276,11 +273,11 @@ trait TreeTransformation[T] { self => case TsImport(_1, _2, _3) => TsImport(_1, _2.map(visitTsImported(tt)), visitTsImportee(tt)(_3)) } } - final def visitTsLiteralBoolean(t: T)(x: TsLiteralBoolean): TsLiteralBoolean = + final def visitTsLiteralBoolean(t: T)(x: TsLiteral.Bool): TsLiteral.Bool = enterTsLiteralBoolean(withTree(t, x))(x) - final def visitTsLiteralNumber(t: T)(x: TsLiteralNumber): TsLiteralNumber = + final def visitTsLiteralNumber(t: T)(x: TsLiteral.Num): TsLiteral.Num = enterTsLiteralNumber(withTree(t, x))(x) - final def visitTsLiteralString(t: T)(x: TsLiteralString): TsLiteralString = + final def visitTsLiteralString(t: T)(x: TsLiteral.Str): TsLiteral.Str = enterTsLiteralString(withTree(t, x))(x) final def visitTsMemberCall(t: T)(x: TsMemberCall): TsMemberCall = { val xx = enterTsMemberCall(withTree(t, x))(x) @@ -478,18 +475,18 @@ trait TreeTransformation[T] { self => } } - final def visitIndexingDict(t: T)(x: IndexingDict): IndexingDict = { + final def visitIndexingDict(t: T)(x: Indexing.Dict): Indexing.Dict = { val xx = enterIndexingDict(withTree(t, x))(x) val tt = withTree(t, xx) xx match { - case IndexingDict(_1, _2) => IndexingDict(_1, visitTsType(tt)(_2)) + case Indexing.Dict(_1, _2) => Indexing.Dict(_1, visitTsType(tt)(_2)) } } - final def visitIndexingSingle(t: T)(x: IndexingSingle): IndexingSingle = { + final def visitIndexingSingle(t: T)(x: Indexing.Single): Indexing.Single = { val xx = enterIndexingSingle(withTree(t, x))(x) val tt = withTree(t, xx) xx match { - case IndexingSingle(_1) => IndexingSingle(visitTsQIdent(tt)(_1)) + case Indexing.Single(_1) => Indexing.Single(visitTsQIdent(tt)(_1)) } } @@ -498,7 +495,6 @@ trait TreeTransformation[T] { self => case x: TsContainerOrDecl => visitTsContainerOrDecl(t)(x) case x: TsType => visitTsType(t)(x) case x: TsMember => visitTsMember(t)(x) - case x: TsTerm => visitTsTerm(t)(x) case x: TsEnumMember => visitTsEnumMember(t)(x) case x: TsFunSig => visitTsFunSig(t)(x) case x: TsFunParam => visitTsFunParam(t)(x) @@ -548,22 +544,16 @@ trait TreeTransformation[T] { self => final def visitTsExportee(t: T)(x: TsExportee): TsExportee = enterTsExportee(withTree(t, x))(x) match { - case x: TsExporteeNames => visitTsExporteeNames(t)(x) - case x: TsExporteeTree => visitTsExporteeTree(t)(x) - case x: TsExporteeStar => visitTsExporteeStar(t)(x) - } - - final def visitTsTerm(t: T)(x: TsTerm): TsTerm = - enterTsTerm(withTree(t, x))(x) match { - case x: TsLiteral => visitTsLiteral(t)(x) - case x: TsIdent => x + case x: TsExportee.Names => visitTsExporteeNames(t)(x) + case x: TsExportee.Tree => visitTsExporteeTree(t)(x) + case x: TsExportee.Star => visitTsExporteeStar(t)(x) } final def visitTsLiteral(t: T)(x: TsLiteral): TsLiteral = enterTsLiteral(withTree(t, x))(x) match { - case x: TsLiteralBoolean => visitTsLiteralBoolean(t)(x) - case x: TsLiteralString => visitTsLiteralString(t)(x) - case x: TsLiteralNumber => visitTsLiteralNumber(t)(x) + case x: TsLiteral.Bool => visitTsLiteralBoolean(t)(x) + case x: TsLiteral.Str => visitTsLiteralString(t)(x) + case x: TsLiteral.Num => visitTsLiteralNumber(t)(x) } final def visitTsType(t: T)(x: TsType): TsType = @@ -603,22 +593,22 @@ trait TreeTransformation[T] { self => final def visitTsImported(t: T)(x: TsImported): TsImported = enterTsImported(withTree(t, x))(x) match { - case x: TsImportedIdent => visitTsImportedIdent(t)(x) - case x: TsImportedDestructured => visitTsImportedDestructured(t)(x) - case x: TsImportedStar => visitTsImportedStar(t)(x) + case x: TsImported.Ident => visitTsImportedIdent(t)(x) + case x: TsImported.Destructured => visitTsImportedDestructured(t)(x) + case x: TsImported.Star => visitTsImportedStar(t)(x) } final def visitTsImportee(t: T)(x: TsImportee): TsImportee = enterTsImportee(withTree(t, x))(x) match { - case x: TsImporteeRequired => visitTsImporteeRequired(t)(x) - case x: TsImporteeFrom => visitTsImporteeFrom(t)(x) - case x: TsImporteeLocal => visitTsImporteeLocal(t)(x) + case x: TsImportee.Required => visitTsImporteeRequired(t)(x) + case x: TsImportee.From => visitTsImporteeFrom(t)(x) + case x: TsImportee.Local => visitTsImporteeLocal(t)(x) } final def visitIndexing(t: T)(x: Indexing): Indexing = enterIndexing(withTree(t, x))(x) match { - case x: IndexingDict => visitIndexingDict(t)(x) - case x: IndexingSingle => visitIndexingSingle(t)(x) + case x: Indexing.Dict => visitIndexingDict(t)(x) + case x: Indexing.Single => visitIndexingSingle(t)(x) } final def >>(that: TreeTransformation[T]): TreeTransformation[T] = @@ -650,11 +640,11 @@ trait TreeTransformation[T] { self => self.enterTsEnumMember(t)(that.enterTsEnumMember(t)(x)) override def enterTsExportAsNamespace(t: T)(x: TsExportAsNamespace): TsExportAsNamespace = self.enterTsExportAsNamespace(t)(that.enterTsExportAsNamespace(t)(x)) - override def enterTsExporteeNames(t: T)(x: TsExporteeNames): TsExporteeNames = + override def enterTsExporteeNames(t: T)(x: TsExportee.Names): TsExportee.Names = self.enterTsExporteeNames(t)(that.enterTsExporteeNames(t)(x)) - override def enterTsExporteeStar(t: T)(x: TsExporteeStar): TsExporteeStar = + override def enterTsExporteeStar(t: T)(x: TsExportee.Star): TsExportee.Star = self.enterTsExporteeStar(t)(that.enterTsExporteeStar(t)(x)) - override def enterTsExporteeTree(t: T)(x: TsExporteeTree): TsExporteeTree = + override def enterTsExporteeTree(t: T)(x: TsExportee.Tree): TsExportee.Tree = self.enterTsExporteeTree(t)(that.enterTsExporteeTree(t)(x)) override def enterTsExport(t: T)(x: TsExport): TsExport = self.enterTsExport(t)(that.enterTsExport(t)(x)) @@ -662,25 +652,25 @@ trait TreeTransformation[T] { self => self.enterTsFunParam(t)(that.enterTsFunParam(t)(x)) override def enterTsFunSig(t: T)(x: TsFunSig): TsFunSig = self.enterTsFunSig(t)(that.enterTsFunSig(t)(x)) - override def enterTsImportedDestructured(t: T)(x: TsImportedDestructured): TsImportedDestructured = + override def enterTsImportedDestructured(t: T)(x: TsImported.Destructured): TsImported.Destructured = self.enterTsImportedDestructured(t)(that.enterTsImportedDestructured(t)(x)) - override def enterTsImportedIdent(t: T)(x: TsImportedIdent): TsImportedIdent = + override def enterTsImportedIdent(t: T)(x: TsImported.Ident): TsImported.Ident = self.enterTsImportedIdent(t)(that.enterTsImportedIdent(t)(x)) - override def enterTsImportedStar(t: T)(x: TsImportedStar): TsImportedStar = + override def enterTsImportedStar(t: T)(x: TsImported.Star): TsImported.Star = self.enterTsImportedStar(t)(that.enterTsImportedStar(t)(x)) - override def enterTsImporteeFrom(t: T)(x: TsImporteeFrom): TsImporteeFrom = + override def enterTsImporteeFrom(t: T)(x: TsImportee.From): TsImportee.From = self.enterTsImporteeFrom(t)(that.enterTsImporteeFrom(t)(x)) - override def enterTsImporteeLocal(t: T)(x: TsImporteeLocal): TsImporteeLocal = + override def enterTsImporteeLocal(t: T)(x: TsImportee.Local): TsImportee.Local = self.enterTsImporteeLocal(t)(that.enterTsImporteeLocal(t)(x)) - override def enterTsImporteeRequired(t: T)(x: TsImporteeRequired): TsImporteeRequired = + override def enterTsImporteeRequired(t: T)(x: TsImportee.Required): TsImportee.Required = self.enterTsImporteeRequired(t)(that.enterTsImporteeRequired(t)(x)) override def enterTsImport(t: T)(x: TsImport): TsImport = self.enterTsImport(t)(that.enterTsImport(t)(x)) - override def enterTsLiteralBoolean(t: T)(x: TsLiteralBoolean): TsLiteralBoolean = + override def enterTsLiteralBoolean(t: T)(x: TsLiteral.Bool): TsLiteral.Bool = self.enterTsLiteralBoolean(t)(that.enterTsLiteralBoolean(t)(x)) - override def enterTsLiteralNumber(t: T)(x: TsLiteralNumber): TsLiteralNumber = + override def enterTsLiteralNumber(t: T)(x: TsLiteral.Num): TsLiteral.Num = self.enterTsLiteralNumber(t)(that.enterTsLiteralNumber(t)(x)) - override def enterTsLiteralString(t: T)(x: TsLiteralString): TsLiteralString = + override def enterTsLiteralString(t: T)(x: TsLiteral.Str): TsLiteral.Str = self.enterTsLiteralString(t)(that.enterTsLiteralString(t)(x)) override def enterTsMemberCall(t: T)(x: TsMemberCall): TsMemberCall = self.enterTsMemberCall(t)(that.enterTsMemberCall(t)(x)) @@ -742,8 +732,6 @@ trait TreeTransformation[T] { self => self.enterTsDecl(t)(that.enterTsDecl(t)(x)) override def enterTsContainer(t: T)(x: TsContainer): TsContainer = self.enterTsContainer(t)(that.enterTsContainer(t)(x)) - override def enterTsTerm(t: T)(x: TsTerm): TsTerm = - self.enterTsTerm(t)(that.enterTsTerm(t)(x)) override def enterTsLiteral(t: T)(x: TsLiteral): TsLiteral = self.enterTsLiteral(t)(that.enterTsLiteral(t)(x)) override def enterTsType(t: T)(x: TsType): TsType = diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/TsTreeScope.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/TsTreeScope.scala index 5cde46c714..17e5219be4 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/TsTreeScope.scala +++ b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/TsTreeScope.scala @@ -540,7 +540,7 @@ object TsTreeScope { addAlternative(mod.name, modScope) ret += (mod.name -> modScope) mod.comments.cs.foreach { - case CommentData(ModuleAliases(aliases)) => + case Marker.ModuleAliases(aliases) => aliases.foreach { alias => ret += ((alias, modScope)) addAlternative(alias, modScope) diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/directives.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/directives.scala deleted file mode 100644 index ff3ec529e2..0000000000 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/directives.scala +++ /dev/null @@ -1,34 +0,0 @@ -package org.scalablytyped.converter.internal -package ts - -sealed trait Directive - -case object DirectiveNoStdLib extends Directive - -sealed trait DirectiveRef extends Directive { - def stringPath: String -} - -/** - * The path in - * /// - */ -final case class DirectivePathRef(stringPath: String) extends DirectiveRef - -/** - * The types ref in - * /// - */ -final case class DirectiveTypesRef(stringPath: String) extends DirectiveRef - -/** - * The ref in - * /// - */ -final case class DirectiveLibRef(stringPath: String) extends DirectiveRef - -/** - * The ref in - * /// - */ -final case class AmdModule(stringPath: String) extends DirectiveRef diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/metadata.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/metadata.scala index 1bc342f829..e6c2fa3639 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/metadata.scala +++ b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/metadata.scala @@ -1,7 +1,9 @@ package org.scalablytyped.converter.internal package ts +import io.circe013.{Decoder, Encoder} import org.scalablytyped.converter.internal.sets.SetOps +import org.scalablytyped.converter.internal.orphanCodecs._ import scala.collection.immutable.SortedSet @@ -18,11 +20,21 @@ case class CompilerOptions( forceConsistentCasingInFileNames: Option[Boolean], ) +object CompilerOptions { + implicit val encodes: Encoder[CompilerOptions] = io.circe013.generic.semiauto.deriveEncoder + implicit val decodes: Decoder[CompilerOptions] = io.circe013.generic.semiauto.deriveDecoder +} + case class TsConfig( compilerOptions: Option[CompilerOptions], files: Option[IArray[String]], ) +object TsConfig { + implicit val encodes: Encoder[TsConfig] = io.circe013.generic.semiauto.deriveEncoder + implicit val decodes: Decoder[TsConfig] = io.circe013.generic.semiauto.deriveDecoder +} + case class PackageJsonDeps( version: Option[String], dependencies: Option[Map[String, String]], @@ -39,12 +51,23 @@ case class PackageJsonDeps( .sorted } +object PackageJsonDeps { + implicit val encodes: Encoder[PackageJsonDeps] = io.circe013.generic.semiauto.deriveEncoder + implicit val decodes: Decoder[PackageJsonDeps] = io.circe013.generic.semiauto.deriveDecoder +} + case class NotNeededPackage( libraryName: String, typingsPackageName: TsIdentLibrary, sourceRepoURL: Option[String], asOfVersion: String, ) + +object NotNeededPackage { + implicit val encodes: Encoder[NotNeededPackage] = io.circe013.generic.semiauto.deriveEncoder + implicit val decodes: Decoder[NotNeededPackage] = io.circe013.generic.semiauto.deriveDecoder +} + case class TypingsJson( name: String, main: String, @@ -52,4 +75,14 @@ case class TypingsJson( global: Boolean, ) +object TypingsJson { + implicit val encodes: Encoder[TypingsJson] = io.circe013.generic.semiauto.deriveEncoder + implicit val decodes: Decoder[TypingsJson] = io.circe013.generic.semiauto.deriveDecoder +} + case class NotNeededPackages(packages: IArray[NotNeededPackage]) + +object NotNeededPackages { + implicit val encodes: Encoder[NotNeededPackages] = io.circe013.generic.semiauto.deriveEncoder + implicit val decodes: Decoder[NotNeededPackages] = io.circe013.generic.semiauto.deriveDecoder +} diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/AugmentModules.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/AugmentModules.scala index 976fb960c4..c45611c51f 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/AugmentModules.scala +++ b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/AugmentModules.scala @@ -19,7 +19,7 @@ object AugmentModules { def target(mod: TsDeclModule, scope: TsTreeScope): CodePath.HasPath = { val exportedNamespaceOpt: Option[CodePath] = mod.exports.firstDefined { - case TsExport(_, _, exportType, TsExporteeNames(IArray.exactlyOne((qIdent, None)), None)) + case TsExport(_, _, exportType, TsExportee.Names(IArray.exactlyOne((qIdent, None)), None)) if ExportType.NotNamed(exportType) => (scope / mod) .lookupBase(Picker.Namespaces, qIdent, skipValidation = true) diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/DeriveCopy.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/DeriveCopy.scala index 884b323e61..74c1e555f6 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/DeriveCopy.scala +++ b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/DeriveCopy.scala @@ -58,7 +58,7 @@ object DeriveCopy { case x: TsDeclInterface => IArray( TsDeclTypeAlias( - comments = Comments(CommentData(Markers.IsTrivial)), + comments = Comments(Marker.IsTrivial), declared = true, name = name, tparams = x.tparams, @@ -89,7 +89,7 @@ object DeriveCopy { case x: TsDeclTypeAlias => IArray( TsDeclTypeAlias( - Comments(CommentData(Markers.IsTrivial)), + Comments(Marker.IsTrivial), declared = false, name, x.tparams, diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/Exports.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/Exports.scala index b28dabaad3..984a212e2e 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/Exports.scala +++ b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/Exports.scala @@ -23,12 +23,12 @@ object Exports { val codePath = owner.codePath.forceHasPath val ret: IArray[TsNamedDecl] = e match { - case TsExport(_, _, exportType, TsExporteeTree(exported)) => + case TsExport(_, _, exportType, TsExportee.Tree(exported)) => exported match { case decl: TsNamedDecl => export(codePath, jsLocation, scope, exportType, decl, None, loopDetector) - case i @ TsImport(_, IArray.exactlyOne(TsImportedIdent(ident)), _) => + case i @ TsImport(_, IArray.exactlyOne(TsImported.Ident(ident)), _) => Imports.expandImportee(i.from, scope, loopDetector) match { case founds if founds.nonEmpty => founds match { @@ -60,7 +60,7 @@ object Exports { } } - case TsExport(_, _, exportType, TsExporteeNames(idents, fromOpt)) => + case TsExport(_, _, exportType, TsExportee.Names(idents, fromOpt)) => val newScope = fromOpt match { case Some(from) => scope.moduleScopes.get(from) match { @@ -86,7 +86,7 @@ object Exports { } } - case TsExport(_, _, exportType, TsExporteeStar(_, from)) => + case TsExport(_, _, exportType, TsExportee.Star(_, from)) => scope.moduleScopes.get(from) match { case Some(TsTreeScope.Scoped(newScope, mod: TsDeclModule)) => val resolvedModule: TsDeclModule = @@ -174,22 +174,22 @@ object Exports { case e @ TsExport(_, _, ExportType.Named, exported) => exported match { - case exported @ TsExporteeNames(idents, _) => // + case exported @ TsExportee.Names(idents, _) => // idents.collectFirst { case tuple @ (TsQIdent(parts), None) if wanted.startsWith(parts) => PickedExport(e.copy(exported = exported.copy(idents = IArray(tuple))), wanted.drop(parts.length)) } - case TsExporteeTree(i: TsImport) => - Imports.validImport(wanted)(i).map(ii => PickedExport(e.copy(exported = TsExporteeTree(ii)), wanted)) + case TsExportee.Tree(i: TsImport) => + Imports.validImport(wanted)(i).map(ii => PickedExport(e.copy(exported = TsExportee.Tree(ii)), wanted)) - case TsExporteeTree(x: TsNamedDecl) => + case TsExportee.Tree(x: TsNamedDecl) => if (wanted.headOption.contains(x.name)) Some(PickedExport(e, wanted)) else None - case TsExporteeTree(other) => + case TsExportee.Tree(other) => sys.error(s"Unexpected $other") - case TsExporteeStar(_, _) => + case TsExportee.Star(_, _) => Some(PickedExport(e, wanted)) } } diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/HandleCommonJsModules.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/HandleCommonJsModules.scala index f4d0ed9547..684931fc3a 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/HandleCommonJsModules.scala +++ b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/HandleCommonJsModules.scala @@ -52,7 +52,7 @@ object HandleCommonJsModules extends TreeTransformationScopedChanges { _, _, ExportType.Namespaced, - TsExporteeNames(IArray.exactlyOne((TsQIdent(qident), None)), _), + TsExportee.Names(IArray.exactlyOne((TsQIdent(qident), None)), _), ) => e -> qident } @@ -98,7 +98,7 @@ object HandleCommonJsModules extends TreeTransformationScopedChanges { val flattened = namespaces .flatMap(_.members) .map { - case x: TsNamedDecl => TsExport(NoComments, typeOnly = false, ExportType.Named, TsExporteeTree(x)) + case x: TsNamedDecl => TsExport(NoComments, typeOnly = false, ExportType.Named, TsExportee.Tree(x)) case other => other } .map(x => SetCodePath.visitTsContainerOrDecl(mod.codePath.forceHasPath)(x)) @@ -127,11 +127,11 @@ object HandleCommonJsModules extends TreeTransformationScopedChanges { _, _, ExportType.Named, - TsExporteeTree( + TsExportee.Tree( TsImport( _, - IArray.exactlyOne(TsImportedIdent(newName)), - TsImporteeLocal(TsQIdent(IArray.exactlyOne(name))), + IArray.exactlyOne(TsImported.Ident(newName)), + TsImportee.Local(TsQIdent(IArray.exactlyOne(name))), ), ), ) if name.value === target.value => @@ -139,9 +139,9 @@ object HandleCommonJsModules extends TreeTransformationScopedChanges { NoComments, typeOnly = false, ExportType.Named, - TsExporteeTree( + TsExportee.Tree( TsDeclVar( - Comments(CommentData(Markers.IsTrivial)), + Comments(Marker.IsTrivial), declared = true, readOnly = true, newName, diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/Imports.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/Imports.scala index 3d75fd2c52..7dfacf2ce4 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/Imports.scala +++ b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/Imports.scala @@ -23,7 +23,7 @@ object Imports { val expanded: ExpandedMod = expandImportee(chosenImport.from, scope, loopDetector) chosenImport.imported.flatMap { - case TsImportedStar(Some(renamed)) => + case TsImported.Star(Some(renamed)) => val all: IArray[TsNamedDecl] = expanded match { case ExpandedMod.Picked(things) => @@ -43,7 +43,7 @@ object Imports { } Utils.searchAmong(scope, Pick, wanted, all, loopDetector) - case TsImportedStar(None) => + case TsImported.Star(None) => val all: IArray[TsNamedDecl] = expanded match { case ExpandedMod.Picked(things) => @@ -54,7 +54,7 @@ object Imports { Utils.searchAmong(scope, Pick, wanted, all, loopDetector) - case TsImportedIdent(ident) => + case TsImported.Ident(ident) => val all: IArray[TsNamedDecl] = expanded match { case ExpandedMod.Picked(things) => @@ -75,7 +75,7 @@ object Imports { Utils.searchAmong(scope, Pick, wanted, all, loopDetector) - case TsImportedDestructured(idents: IArray[(TsIdent, Option[TsIdentSimple])]) => + case TsImported.Destructured(idents: IArray[(TsIdent, Option[TsIdentSimple])]) => val all: IArray[TsNamedDecl] = expanded match { case ExpandedMod.Picked(things) => @@ -117,7 +117,7 @@ object Imports { } val ret: ExpandedMod = from match { - case TsImporteeRequired(fromModule) => + case TsImportee.Required(fromModule) => scope.moduleScopes.get(fromModule) match { case Some(modScope @ TsTreeScope.Scoped(_, mod: TsDeclModule)) => val newMod: TsDeclModule = CachedReplaceExports(modScope.`..`, loopDetector, mod) @@ -144,7 +144,7 @@ object Imports { ExpandedMod.Picked(Empty) } - case TsImporteeFrom(fromModule) => + case TsImportee.From(fromModule) => scope.moduleScopes.get(fromModule) match { case Some(modScope @ TsTreeScope.Scoped(_, mod: TsDeclModule)) => val newMod = CachedReplaceExports(modScope.`..`, loopDetector, mod) @@ -172,7 +172,7 @@ object Imports { ExpandedMod.Picked(Empty) } - case TsImporteeLocal(qident) => + case TsImportee.Local(qident) => ExpandedMod.Picked(scope.lookupInternal(Picker.NotModules, qident.parts, loopDetector)) } @@ -192,20 +192,20 @@ object Imports { case IArray.Empty => None case IArray.first(first) => val newImported: IArray[TsImported] = i.imported.mapNotNone { - case im @ TsImportedIdent(`first`) => + case im @ TsImported.Ident(`first`) => Some(im) - case TsImportedIdent(_) => None + case TsImported.Ident(_) => None - case TsImportedDestructured(idents) => + case TsImported.Destructured(idents) => idents.collectFirst { - case t @ (`first`, None) => TsImportedDestructured(IArray(t)) - case t @ (_, Some(`first`)) => TsImportedDestructured(IArray(t)) + case t @ (`first`, None) => TsImported.Destructured(IArray(t)) + case t @ (_, Some(`first`)) => TsImported.Destructured(IArray(t)) } - case im @ TsImportedStar(Some(`first`)) => + case im @ TsImported.Star(Some(`first`)) => Some(im) - case TsImportedStar(_) => None + case TsImported.Star(_) => None } if (newImported.nonEmpty) Some(i.copy(imported = newImported)) else None diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/KeepTypesOnly.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/KeepTypesOnly.scala index 91818ff9ed..0d1471f2d1 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/KeepTypesOnly.scala +++ b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/KeepTypesOnly.scala @@ -5,9 +5,9 @@ package modules object KeepTypesOnly { def apply(x: TsContainerOrDecl): Option[TsContainerOrDecl] = x match { - case e @ TsExport(_, _, _, TsExporteeTree(decl)) => + case e @ TsExport(_, _, _, TsExportee.Tree(decl)) => apply(decl).flatMap { - case d: TsNamedDecl => Some(e.copy(exported = TsExporteeTree(d))) + case d: TsNamedDecl => Some(e.copy(exported = TsExportee.Tree(d))) case _ => Some(e) } case x: TsNamedDecl => named(x) diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/ReplaceExports.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/ReplaceExports.scala index 82dea99a56..d3e79f9981 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/ReplaceExports.scala +++ b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/ReplaceExports.scala @@ -27,7 +27,7 @@ class ReplaceExports(loopDetector: LoopDetector) extends TreeTransformationScope if (x.exports.isEmpty && x.imports.isEmpty) x else { val newMembers: IArray[TsContainerOrDecl] = x.members.flatMap { - case TsExport(_, _, ExportType.Named, TsExporteeTree(tree)) => + case TsExport(_, _, ExportType.Named, TsExportee.Tree(tree)) => tree match { case namedExport: TsNamedDecl => export( @@ -40,7 +40,7 @@ class ReplaceExports(loopDetector: LoopDetector) extends TreeTransformationScope loopDetector, ) - case TsImport(_, IArray.exactlyOne(TsImportedIdent(to)), TsImporteeLocal(from)) => + case TsImport(_, IArray.exactlyOne(TsImported.Ident(to)), TsImportee.Local(from)) => scope .lookupInternal(Picker.ButNot(Picker.All, x), from.parts, loopDetector) .map { case (d, _) => d.withName(to) } @@ -49,7 +49,7 @@ class ReplaceExports(loopDetector: LoopDetector) extends TreeTransformationScope case other => scope.logger.fatal(s"Unexpected $other") } - case TsExport(NoComments, _, ExportType.Named, TsExporteeNames(Empty, None)) => + case TsExport(NoComments, _, ExportType.Named, TsExportee.Names(Empty, None)) => Empty case e: TsExport => scope.fatalMaybe(s"Dropping unexpected export in namespace $e") @@ -86,8 +86,8 @@ class ReplaceExports(loopDetector: LoopDetector) extends TreeTransformationScope override def leaveTsParsedFile(t: TsTreeScope)(x: TsParsedFile): TsParsedFile = x.copy(members = x.members.mapNotNone { case _: TsImport => None - case TsExport(_, _, _, TsExporteeTree(x)) => Some(x) - case other => Some(other) + case TsExport(_, _, _, TsExportee.Tree(x)) => Some(x) + case other => Some(other) }) def ensureTypesPresent[T <: TsContainer](old: T, `new`: T): T = { @@ -97,7 +97,7 @@ class ReplaceExports(loopDetector: LoopDetector) extends TreeTransformationScope val missingTypes: IArray[TsContainerOrDecl] = old.members .collect { - case TsExport(_, _, _, TsExporteeTree(Picker.Types(tpe))) if !newTypes.contains(tpe.name) => + case TsExport(_, _, _, TsExportee.Tree(Picker.Types(tpe))) if !newTypes.contains(tpe.name) => KeepTypesOnly(tpe) case Picker.Types(tpe) if !newTypes.contains(tpe.name) => KeepTypesOnly(tpe) } @@ -131,22 +131,22 @@ class ReplaceExports(loopDetector: LoopDetector) extends TreeTransformationScope ): CanBeShadowed = { lazy val hasExportedValues: Boolean = owner.exports.exists { - case TsExport(_, _, _, TsExporteeTree(_: TsDeclInterface | _: TsDeclTypeAlias)) => false + case TsExport(_, _, _, TsExportee.Tree(_: TsDeclInterface | _: TsDeclTypeAlias)) => false case _: TsExport => true case _ => false } decl match { /* fix for @angular/core */ - case TsExport(NoComments, _, _, TsExporteeStar(_, name)) if owner.name === name => + case TsExport(NoComments, _, _, TsExportee.Star(_, name)) if owner.name === name => CanBeShadowed(maybe = false, Empty) case e: TsExport => val ret = Exports.expandExport(scope, jsLocation, e, loopDetector, owner) if (ret.isEmpty && scope.root.pedantic) { e match { /* OF COURSE somebody had to export an empty object */ - case TsExport(_, _, ExportType.Named, TsExporteeNames(names, None)) if names.isEmpty => () - case other => + case TsExport(_, _, ExportType.Named, TsExportee.Names(names, None)) if names.isEmpty => () + case other => // for debugging Exports.expandExport(scope, jsLocation, other, loopDetector, owner: TsDeclNamespaceOrModule) @@ -154,8 +154,8 @@ class ReplaceExports(loopDetector: LoopDetector) extends TreeTransformationScope } } val canBeShadowed = e match { - case TsExport(_, _, ExportType.Named, TsExporteeStar(_, _)) => true - case _ => false + case TsExport(_, _, ExportType.Named, TsExportee.Star(_, _)) => true + case _ => false } CanBeShadowed(canBeShadowed, ret) @@ -163,7 +163,7 @@ class ReplaceExports(loopDetector: LoopDetector) extends TreeTransformationScope val ret: IArray[TsNamedDecl] = ms.collect { case x: TsNamedDecl => x - case TsExport(_, _, _, TsExporteeTree(x: TsNamedDecl)) => x + case TsExport(_, _, _, TsExportee.Tree(x: TsNamedDecl)) => x } .map(x => Utils.withJsLocation(x, JsLocation.Global(TsQIdent.of(x.name)))) diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/RewriteExportStarAs.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/RewriteExportStarAs.scala index dee6da446e..e631ff5f72 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/RewriteExportStarAs.scala +++ b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/RewriteExportStarAs.scala @@ -5,9 +5,9 @@ package modules object RewriteExportStarAs extends TransformMembers { override def newMembers(scope: TsTreeScope, x: TsContainer): IArray[TsContainerOrDecl] = x.members.flatMap { - case TsExport(comments, typeOnly, tpe, TsExporteeStar(Some(as), from)) => - val newImport = TsImport(typeOnly, IArray(TsImportedStar(Some(as))), TsImporteeFrom(from)) - val newExport = TsExport(comments, typeOnly, tpe, TsExporteeNames(IArray(TsQIdent(IArray(as)) -> None), None)) + case TsExport(comments, typeOnly, tpe, TsExportee.Star(Some(as), from)) => + val newImport = TsImport(typeOnly, IArray(TsImported.Star(Some(as))), TsImportee.From(from)) + val newExport = TsExport(comments, typeOnly, tpe, TsExportee.Names(IArray(TsQIdent(IArray(as)) -> None), None)) IArray(newImport, newExport) case other => IArray(other) diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/Utils.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/Utils.scala index 3980b173e5..f388846fd8 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/Utils.scala +++ b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/modules/Utils.scala @@ -8,7 +8,7 @@ import org.scalablytyped.converter.internal.ts.transforms.SetJsLocation object Utils { def withJsLocation[T <: TsTree](tree: T, jsLocation: JsLocation): T = tree match { - case x: HasJsLocation => + case x: JsLocation.Has => x.withJsLocation(jsLocation) match { case xx: TsContainer => xx.withMembers(xx.members.map(SetJsLocation.visitTsContainerOrDecl(jsLocation))).asInstanceOf[T] diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/parser/TsParser.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/parser/TsParser.scala index 6ed8efc357..52d6ddbe9a 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/parser/TsParser.scala +++ b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/parser/TsParser.scala @@ -95,13 +95,13 @@ class TsParser(path: Option[(os.Path, Int)]) extends StdTokenParsers with Parser lazy val directive: Parser[Directive] = accept( "Directive", { - case lexical.DirectiveToken("reference", "lib", value) => DirectiveLibRef(value) - case lexical.DirectiveToken("reference", "types", value) => DirectiveTypesRef(value) + case lexical.DirectiveToken("reference", "lib", value) => Directive.LibRef(value) + case lexical.DirectiveToken("reference", "types", value) => Directive.TypesRef(value) case lexical.DirectiveToken("references", "types", value) => - DirectiveTypesRef(value) // not sure if it's a typo, but we'll retain the hint - case lexical.DirectiveToken("reference", "path", value) => DirectivePathRef(value) - case lexical.DirectiveToken("reference", "no-default-lib", "true") => DirectiveNoStdLib - case lexical.DirectiveToken("amd-module", "name", value) => AmdModule(value) + Directive.TypesRef(value) // not sure if it's a typo, but we'll retain the hint + case lexical.DirectiveToken("reference", "path", value) => Directive.PathRef(value) + case lexical.DirectiveToken("reference", "no-default-lib", "true") => Directive.NoStdLib + case lexical.DirectiveToken("amd-module", "name", value) => Directive.AmdModule(value) }, ).named("directive") @@ -113,7 +113,7 @@ class TsParser(path: Option[(os.Path, Int)]) extends StdTokenParsers with Parser }) lazy val parsedTsFile: Parser[TsParsedFile] = - shebang.? ~> comments ~ directives ~ tsContainerOrDecls ~ success(CodePath.NoPath) ^^ TsParsedFile + shebang.? ~> comments ~ directives ~ tsContainerOrDecls ~ success(CodePath.NoPath) ^^ TsParsedFile.apply lazy val tsNamedDecl: Parser[TsNamedDecl] = tsDeclInterface | @@ -195,22 +195,22 @@ class TsParser(path: Option[(os.Path, Int)]) extends StdTokenParsers with Parser val rename = "as" ~> tsIdent repsep_( - "*" ~> rename ^^ (r => TsImportedStar(Some(r))) | - "{" ~> (tsIdent ~ rename.? <~ ",".? ^^ { case x1 ~ x2 => (x1, x2) }).** <~ "}" ^^ TsImportedDestructured | - tsIdent ^^ TsImportedIdent, + "*" ~> rename ^^ (r => TsImported.Star(Some(r))) | + "{" ~> (tsIdent ~ rename.? <~ ",".? ^^ { case x1 ~ x2 => (x1, x2) }).** <~ "}" ^^ TsImported.Destructured | + tsIdent ^^ TsImported.Ident, ",", ) } val importee: Parser[TsImportee] = { - val required: Parser[TsImporteeRequired] = - "=" ~> "require" ~> "(" ~> tsIdentModule <~ ")" ^^ TsImporteeRequired + val required: Parser[TsImportee.Required] = + "=" ~> "require" ~> "(" ~> tsIdentModule <~ ")" ^^ TsImportee.Required - val from: Parser[TsImporteeFrom] = - "from" ~> tsIdentModule ^^ TsImporteeFrom.apply + val from: Parser[TsImportee.From] = + "from" ~> tsIdentModule ^^ TsImportee.From.apply - val local: Parser[TsImporteeLocal] = - "=" ~> qualifiedIdent ^^ TsImporteeLocal + val local: Parser[TsImportee.Local] = + "=" ~> qualifiedIdent ^^ TsImportee.Local required | from | local } @@ -219,7 +219,10 @@ class TsParser(path: Option[(os.Path, Int)]) extends StdTokenParsers with Parser "import" ~> "type".isDefined ~ imported ~ importee ^^ TsImport val raw: Parser[TsImport] = - "import" ~> tsIdentModule ^^ (id => TsImport(typeOnly = false, IArray(TsImportedStar(None)), TsImporteeFrom(id))) + "import" ~> tsIdentModule ^^ ( + id => + TsImport(typeOnly = false, IArray(TsImported.Star(None)), TsImportee.From(id)), + ) normalImport | raw } @@ -239,22 +242,22 @@ class TsParser(path: Option[(os.Path, Int)]) extends StdTokenParsers with Parser val asNameOpt: Parser[Option[TsIdentSimple]] = ("as" ~> tsIdent).? - val exportedNames: Parser[Boolean ~ TsExporteeNames] = { + val exportedNames: Parser[Boolean ~ TsExportee.Names] = { val maybeRenamedName: Parser[(TsQIdent, Option[TsIdentSimple])] = qualifiedIdent ~ asNameOpt ^^ tuple2 val one = maybeRenamedName.map(IArray(_)) val many = "{" ~>! (maybeRenamedName <~! (";" | ",").?).** <~ comments.? <~ "}" - val base = (one | many) ~ from.? ^^ TsExporteeNames + val base = (one | many) ~ from.? ^^ TsExportee.Names ("type".isDefined ~ base) | (success(false) ~ base) } - val exporteeStar: Parser[Boolean ~ TsExporteeStar] = - success(false) ~ ("*" ~> ("as" ~> tsIdent).? ~ from ^^ TsExporteeStar.apply) + val exporteeStar: Parser[Boolean ~ TsExportee.Star] = + success(false) ~ ("*" ~> ("as" ~> tsIdent).? ~ from ^^ TsExportee.Star.apply) - val exporteeTree: Parser[Boolean ~ TsExporteeTree] = - success(false) ~ (tsDecl ^^ TsExporteeTree) + val exporteeTree: Parser[Boolean ~ TsExportee.Tree] = + success(false) ~ (tsDecl ^^ TsExportee.Tree) exporteeTree | exportedNames | exporteeStar } @@ -380,7 +383,7 @@ class TsParser(path: Option[(os.Path, Int)]) extends StdTokenParsers with Parser } lazy val functionSignature: Parser[TsFunSig] = - comments ~ tsTypeParams ~ ("(" ~>! tsFunctionParams <~ ")") ~ typeAnnotationOpt ^^ TsFunSig + comments ~ tsTypeParams ~ ("(" ~>! tsFunctionParams <~ ")") ~ typeAnnotationOpt ^^ TsFunSig.apply lazy val functionParam: Parser[TsFunParam] = { @@ -593,12 +596,12 @@ class TsParser(path: Option[(os.Path, Int)]) extends StdTokenParsers with Parser comments ~ ("new" ~>! protectionLevel) ~ functionSignature ^^ TsMemberCtor val indexing: Parser[Indexing] = ( - ("[" ~> qualifiedIdent <~ "]") ^^ IndexingSingle - | ("[" ~> tsIdent ~ typeAnnotation <~ "]") ^^ IndexingDict + ("[" ~> qualifiedIdent <~ "]") ^^ Indexing.Single + | ("[" ~> tsIdent ~ typeAnnotation <~ "]") ^^ Indexing.Dict ) val indexedType: Parser[TsType] = - typeAnnotation | (functionSignature ^^ TsTypeFunction) + typeAnnotation | (functionSignature ^^ TsTypeFunction.apply) val tsMemberIndex: Parser[TsMemberIndex] = comments ~ "readonly".isDefined ~ (protectionLevel <~ "readonly".isDefined) ~ indexing ~ "?".isDefined ~ indexedType.? ^^ { @@ -636,19 +639,19 @@ class TsParser(path: Option[(os.Path, Int)]) extends StdTokenParsers with Parser withImport | normal } - lazy val tsLiteralString: Parser[TsLiteralString] = - stringLit ^^ TsLiteralString.apply + lazy val tsLiteralString: Parser[TsLiteral.Str] = + stringLit ^^ TsLiteral.Str.apply lazy val tsIdentModule: Parser[TsIdentModule] = tsLiteralString ^^ ModuleNameParser.apply - lazy val tsLiteralNumber: Parser[TsLiteralNumber] = - numericLit ^^ TsLiteralNumber + lazy val tsLiteralNumber: Parser[TsLiteral.Num] = + numericLit ^^ TsLiteral.Num - lazy val tsLiteralBoolean: Parser[TsLiteralBoolean] = + lazy val tsLiteralBoolean: Parser[TsLiteral.Bool] = accept("boolean literal", { - case lexical.Keyword("true") => TsLiteralBoolean(true) - case lexical.Keyword("false") => TsLiteralBoolean(false) + case lexical.Keyword("true") => TsLiteral.Bool(true) + case lexical.Keyword("false") => TsLiteral.Bool(false) }) lazy val tsLiteral: Parser[TsLiteral] = diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/ExpandCallables.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/ExpandCallables.scala index f1d8e2c7d0..4a2b0e24b0 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/ExpandCallables.scala +++ b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/ExpandCallables.scala @@ -34,7 +34,7 @@ object ExpandCallables extends TransformClassMembers { case Expand(callables, keepOriginalMember) if callables.nonEmpty => val keptOpt: Option[TsMemberProperty] = if (keepOriginalMember || !isReadonly) - Some(m.copy(comments = m.comments + CommentData(Markers.ExpandedCallables))) + Some(m.copy(comments = m.comments + Marker.ExpandedCallables)) else None val fs: IArray[TsMemberFunction] = diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/ExpandTypeMappings.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/ExpandTypeMappings.scala index 7b44254eba..a86c875088 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/ExpandTypeMappings.scala +++ b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/ExpandTypeMappings.scala @@ -20,8 +20,8 @@ object ExpandTypeMappings extends TreeTransformationScopedChanges { scope.stack.exists { case TsTypeObject(Comments(cs), _) => cs.exists { - case CommentData(Markers.NameHint(`nameHint`)) => true - case _ => false + case Marker.NameHint(`nameHint`) => true + case _ => false } case _ => false } @@ -53,7 +53,7 @@ object ExpandTypeMappings extends TreeTransformationScopedChanges { val notices = Comments( List( Comment("/* Inlined " + TsTypeFormatter(x) + " */\n"), - CommentData(Markers.NameHint(nameHint)), + Marker.NameHint(nameHint), ), ) TsTypeObject(notices, newMembers) @@ -81,7 +81,7 @@ object ExpandTypeMappings extends TreeTransformationScopedChanges { } case ta @ TsDeclTypeAlias(comments, declared, name, tparams, alias, codePath) - if !comments.has[Markers.IsTrivial.type] && !pointsToConcreteType(scope, alias) => + if !comments.has[Marker.IsTrivial.type] && !pointsToConcreteType(scope, alias) => AllMembersFor.forType(scope, LoopDetector.initial)(alias) match { case Problems(_) => evaluateKeys(scope, LoopDetector.initial)(alias) match { @@ -226,9 +226,9 @@ object ExpandTypeMappings extends TreeTransformationScopedChanges { def keysFor(members: IArray[TsMember]): IArray[TaggedLiteral] = members.collect { case TsMemberProperty(_, _, name, Some(OptionalType(_)), _, _, _) => - TaggedLiteral(TsLiteralString(name.value))(isOptional = true) - case x: TsMemberProperty => TaggedLiteral(TsLiteralString(x.name.value))(isOptional = false) - case x: TsMemberFunction => TaggedLiteral(TsLiteralString(x.name.value))(isOptional = false) + TaggedLiteral(TsLiteral.Str(name.value))(isOptional = true) + case x: TsMemberProperty => TaggedLiteral(TsLiteral.Str(x.name.value))(isOptional = false) + case x: TsMemberFunction => TaggedLiteral(TsLiteral.Str(x.name.value))(isOptional = false) } val res: Res[Set[TaggedLiteral]] = FollowAliases(scope)(keys) match { diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/ExpandTypeParams.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/ExpandTypeParams.scala index 34e4611689..6a45b61410 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/ExpandTypeParams.scala +++ b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/ExpandTypeParams.scala @@ -157,8 +157,8 @@ object ExpandTypeParams extends TransformMembers with TransformClassMembers { members.collect { case TsMemberProperty(_, _, TsIdentSimple(n), Some(tpe), _, false, _) => val rewrites = Map[TsType, TsType]( - TsTypeRef(exp.typeParam) -> TsTypeLiteral(TsLiteralString(n)), - TsTypeLookup(ref, TsTypeLiteral(TsLiteralString(n))) -> tpe, + TsTypeRef(exp.typeParam) -> TsTypeLiteral(TsLiteral.Str(n)), + TsTypeLookup(ref, TsTypeLiteral(TsLiteral.Str(n))) -> tpe, ) new TypeRewriter(sigCleaned).visitTsFunSig(rewrites)(sigCleaned) diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/ExtractClasses.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/ExtractClasses.scala index d24413cb1d..0d2b4cd011 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/ExtractClasses.scala +++ b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/ExtractClasses.scala @@ -100,7 +100,7 @@ object ExtractClasses extends TransformLeaveMembers { case (base, false) => s"/* $base. In rare cases (like HTMLElement in the DOM) it might not work as you expect. */\n" } - Comments(List(CommentData(Markers.ExpandedClass), Comment(msg))) + Comments(List(Marker.ExpandedClass, Comment(msg))) } def extractClassFromMember( diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/ExtractInterfaces.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/ExtractInterfaces.scala index be8a78141a..2e916c6aa7 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/ExtractInterfaces.scala +++ b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/ExtractInterfaces.scala @@ -56,18 +56,12 @@ object ExtractInterfaces { } def partOfTypeMapping(stack: List[TsTree], obj: TsTypeObject): Boolean = - stack.exists(_.isInstanceOf[TsMemberTypeMapped]) || isTypeMapping(obj.members) - - def isTypeMapping(members: IArray[TsMember]): Boolean = - members match { - case IArray.exactlyOne(_: TsMemberTypeMapped) => true - case _ => false - } + stack.exists(_.isInstanceOf[TsMemberTypeMapped]) || TsType.isTypeMapping(obj.members) def isDictionary(members: IArray[TsMember]): Boolean = members.nonEmpty && members.forall { - case TsMemberIndex(_, _, _, IndexingDict(_, _), _) => true - case _ => false + case TsMemberIndex(_, _, _, Indexing.Dict(_, _), _) => true + case _ => false } private class LiftTypeObjects(store: ConflictHandlingStore) extends TreeTransformationScopedChanges { @@ -88,7 +82,7 @@ object ExtractInterfaces { case _ => false } - obj.comments.extract { case Markers.NameHint(hint) => hint } match { + obj.comments.extract { case Marker.NameHint(hint) => hint } match { case Some((nameHint, _)) => nameHint.take(25) case None if isFunction => DeriveNonConflictingName.Fn case None => DeriveNonConflictingName.Anon @@ -97,7 +91,7 @@ object ExtractInterfaces { val codePath = store.addInterface(scope, prefix, obj.members, referencedTparams) { name => TsDeclInterface( - obj.comments.extract { case Markers.NameHint(hint) => hint }.fold(obj.comments)(_._2), + obj.comments.extract { case Marker.NameHint(hint) => hint }.fold(obj.comments)(_._2), declared = true, name, referencedTparams, diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/InferEnumTypes.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/InferEnumTypes.scala index 16c8d2eda6..5c3038dfe9 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/InferEnumTypes.scala +++ b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/InferEnumTypes.scala @@ -10,7 +10,7 @@ object InferEnumTypes extends TreeTransformationScopedChanges { var lastUnspecifiedIndex = 0 members.map { case em @ TsEnumMember(_, _, None) => - val ret = em.copy(expr = Some(TsExpr.Literal(TsLiteralNumber(lastUnspecifiedIndex.toString)))) + val ret = em.copy(expr = Some(TsExpr.Literal(TsLiteral.Num(lastUnspecifiedIndex.toString)))) lastUnspecifiedIndex += 1 ret case other => other diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/InlineTrivialTypeAlias.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/InlineTrivialTypeAlias.scala index be2b7feb76..ffda2c0429 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/InlineTrivialTypeAlias.scala +++ b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/InlineTrivialTypeAlias.scala @@ -44,7 +44,7 @@ object InlineTrivialTypeAlias extends TreeTransformationScopedChanges { def followTrivialAliases(scope: TsTreeScope)(cur: TsDeclTypeAlias): Option[TsQIdent] = cur match { case TsDeclTypeAlias(cs, _, _, _, EffectiveTypeRef(TsTypeRef(_, nextName, _)), codePath) - if cs.has[Markers.IsTrivial.type] => + if cs.has[Marker.IsTrivial.type] => scope .lookupTypeIncludeScope(nextName) .firstDefined { diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/NormalizeFunctions.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/NormalizeFunctions.scala index 3378e906ff..7bac5fcebd 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/NormalizeFunctions.scala +++ b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/NormalizeFunctions.scala @@ -43,7 +43,7 @@ object NormalizeFunctions extends TransformMembers with TransformClassMembers { case other => IArray(other) } - override def enterTsExporteeTree(t: TsTreeScope)(x: TsExporteeTree): TsExporteeTree = + override def enterTsExporteeTree(t: TsTreeScope)(x: TsExportee.Tree): TsExportee.Tree = rewriteDecl(x.decl) match { case IArray.exactlyOne(one) => x.copy(decl = one) case _ => x diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/PreferTypeAlias.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/PreferTypeAlias.scala index 6bd3b35681..6c287f7edd 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/PreferTypeAlias.scala +++ b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/PreferTypeAlias.scala @@ -20,7 +20,7 @@ object PreferTypeAlias extends TreeTransformationScopedChanges { * There is little value in keep these two types distinct */ case i @ TsDeclInterface(comments, declared, name, tparams, Empty, members, codePath) - if ExtractInterfaces.isTypeMapping(members) || ExtractInterfaces.isDictionary(members) => + if TsType.isTypeMapping(members) || ExtractInterfaces.isDictionary(members) => if (hasCircularReference(codePath.forceHasPath.codePath, mutable.Set(), scope, members.head)) i else TsDeclTypeAlias(comments, declared, name, tparams, TsTypeObject(NoComments, members), codePath) @@ -97,7 +97,7 @@ object PreferTypeAlias extends TreeTransformationScopedChanges { */ case TsDeclTypeAlias(cs, dec, name, tparams, AllTypeObjects(members), cp) if members.nonEmpty && - !ExtractInterfaces.isTypeMapping(members) && + !TsType.isTypeMapping(members) && !ExtractInterfaces.isDictionary(members) => TsDeclInterface(cs, dec, name, tparams, Empty, members, cp) diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/RemoveDifficultInheritance.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/RemoveDifficultInheritance.scala index febe3bca55..66db2465a5 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/RemoveDifficultInheritance.scala +++ b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/RemoveDifficultInheritance.scala @@ -74,7 +74,7 @@ object RemoveDifficultInheritance extends TreeTransformationScopedChanges { case TsTypeIntersect(types) => Res.combine(types.map { case next: TsTypeRef => cleanParentRef(newScope)(next) - case TsTypeObject(_, members) if !ExtractInterfaces.isTypeMapping(members) => + case TsTypeObject(_, members) if !TsType.isTypeMapping(members) => Res(Empty, Empty, Map(tr -> members)) case other => Res(Empty, other +: Empty, Map.empty) }) @@ -82,7 +82,7 @@ object RemoveDifficultInheritance extends TreeTransformationScopedChanges { case _: TsTypeFunction => Res(tr +: Empty, Empty, Map.empty) case TsTypeObject(_, members) if ExtractInterfaces.isDictionary(members) => Res(IArray(tr), Empty, Map.empty) - case TsTypeObject(_, members) if !ExtractInterfaces.isTypeMapping(members) => + case TsTypeObject(_, members) if !TsType.isTypeMapping(members) => Res(Empty, Empty, Map(tr -> members)) case dropUnknown => Res(Empty, dropUnknown +: Empty, Map.empty) } diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/ResolveTypeQueries.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/ResolveTypeQueries.scala index 7f2ebfa6d5..c81f3e79e1 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/ResolveTypeQueries.scala +++ b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/ResolveTypeQueries.scala @@ -53,7 +53,7 @@ object ResolveTypeQueries extends TransformMembers with TransformLeaveClassMembe override def newMembers(scope: TsTreeScope, tree: TsContainer): IArray[TsContainerOrDecl] = { lazy val avoidCircular: Set[CodePath] = - scope.stack.collect { case x: HasCodePath => x.codePath }.toSet + scope.stack.collect { case x: CodePath.Has => x.codePath }.toSet val addedClasses = mutable.Set.empty[TsIdentSimple] @@ -62,7 +62,7 @@ object ResolveTypeQueries extends TransformMembers with TransformLeaveClassMembe val note = Comment(s"/* was `${TsTypeFormatter(tpe)}` */\n") lazy val ownerLoc = tree match { - case x: HasJsLocation => x.jsLocation + case x: JsLocation.Has => x.jsLocation case _ => JsLocation.Zero } @@ -141,7 +141,7 @@ object ResolveTypeQueries extends TransformMembers with TransformLeaveClassMembe def unapply(decl: TsContainerOrDecl): Option[(TsDeclClass, TsType)] = decl match { - case _cls: TsDeclClass if !_cls.comments.has[Markers.ExpandedClass.type] => + case _cls: TsDeclClass if !_cls.comments.has[Marker.ExpandedClass.type] => val cls = new TypeRewriter(_cls).visitTsDeclClass( _cls.tparams .map(tp => @@ -169,7 +169,7 @@ object ResolveTypeQueries extends TransformMembers with TransformLeaveClassMembe statics match { case Empty => Some((cls, ctor)) case some => - val nameHint = Comments(CommentData(Markers.NameHint(s"Typeof${cls.name.value}"))) + val nameHint = Comments(Marker.NameHint(s"Typeof${cls.name.value}")) Some( ( cls, @@ -300,7 +300,7 @@ object ResolveTypeQueries extends TransformMembers with TransformLeaveClassMembe case TsDeclModule(_, _, name, _, _, _) => s"Typeof${name.value}" case TsAugmentedModule(_, name, _, _, _) => s"Typeof${name.value}" } - Some(TsTypeObject(Comments(CommentData(Markers.NameHint(namehint))), rewritten)) + Some(TsTypeObject(Comments(Marker.NameHint(namehint)), rewritten)) } } diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/RewriteTypeThis.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/RewriteTypeThis.scala index 4fc8e882b3..a485cbb434 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/RewriteTypeThis.scala +++ b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/RewriteTypeThis.scala @@ -56,7 +56,7 @@ object RewriteTypeThis extends TreeTransformationScopedChanges { def isReferencedInIndexType(stack: List[TsTree]): Boolean = stack.exists { - case TsMemberIndex(_, _, _, IndexingDict(_, _), _) => true - case _ => false + case TsMemberIndex(_, _, _, Indexing.Dict(_, _), _) => true + case _ => false } } diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/SetCodePath.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/SetCodePath.scala index d0d69b465e..82b0d80df3 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/SetCodePath.scala +++ b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/SetCodePath.scala @@ -5,19 +5,19 @@ import org.scalablytyped.converter.internal.ts._ object SetCodePath extends TreeTransformation[CodePath.HasPath] { override def enterTsDecl(cp: CodePath.HasPath)(x: TsDecl): TsDecl = x match { - case xx: HasCodePath => xx.withCodePath(cp).asInstanceOf[TsDecl] + case xx: CodePath.Has => xx.withCodePath(cp).asInstanceOf[TsDecl] case other => other } override def enterTsContainer(cp: CodePath.HasPath)(x: TsContainer): TsContainer = x match { - case xx: HasCodePath => xx.withCodePath(cp).asInstanceOf[TsContainer] + case xx: CodePath.Has => xx.withCodePath(cp).asInstanceOf[TsContainer] case other => other } override def enterTsNamedDecl(cp: CodePath.HasPath)(x: TsNamedDecl): TsNamedDecl = x match { - case xx: HasCodePath => xx.withCodePath(cp).asInstanceOf[TsNamedDecl] + case xx: CodePath.Has => xx.withCodePath(cp).asInstanceOf[TsNamedDecl] case other => other } diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/SetJsLocation.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/SetJsLocation.scala index 22f830c7af..e4bf375515 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/SetJsLocation.scala +++ b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/SetJsLocation.scala @@ -5,19 +5,19 @@ import org.scalablytyped.converter.internal.ts._ object SetJsLocation extends TreeTransformation[JsLocation] { override def enterTsDecl(loc: JsLocation)(x: TsDecl): TsDecl = x match { - case xx: HasJsLocation => xx.withJsLocation(loc).asInstanceOf[TsDecl] + case xx: JsLocation.Has => xx.withJsLocation(loc).asInstanceOf[TsDecl] case other => other } override def enterTsNamedDecl(loc: JsLocation)(x: TsNamedDecl): TsNamedDecl = x match { - case xx: HasJsLocation => xx.withJsLocation(loc).asInstanceOf[TsNamedDecl] + case xx: JsLocation.Has => xx.withJsLocation(loc).asInstanceOf[TsNamedDecl] case other => other } override def enterTsContainer(loc: JsLocation)(x: TsContainer): TsContainer = x match { - case xx: HasJsLocation => xx.withJsLocation(loc).asInstanceOf[TsContainer] + case xx: JsLocation.Has => xx.withJsLocation(loc).asInstanceOf[TsContainer] case other => other } diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/TypeAliasIntersection.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/TypeAliasIntersection.scala index 68ff65bbf2..f0923bb23a 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/TypeAliasIntersection.scala +++ b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/TypeAliasIntersection.scala @@ -22,7 +22,7 @@ object TypeAliasIntersection extends TreeTransformationScopedChanges { def legalInheritance(x: TsType): Boolean = x match { case TsTypeRef(_, _, _) => true - case TsTypeObject(_, members) => !ExtractInterfaces.isTypeMapping(members) + case TsTypeObject(_, members) => !TsType.isTypeMapping(members) case TsTypeFunction(_) => true case _ => false } diff --git a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/UnionTypesFromKeyOf.scala b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/UnionTypesFromKeyOf.scala index 319ce245a5..a691d8de13 100644 --- a/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/UnionTypesFromKeyOf.scala +++ b/ts/src/main/scala/org/scalablytyped/converter/internal/ts/transforms/UnionTypesFromKeyOf.scala @@ -10,7 +10,7 @@ object UnionTypesFromKeyOf extends TreeTransformationScopedChanges { case Some(TsDeclInterface(_, _, _, _, _, members, _)) => val literals = members.collect { case TsMemberProperty(_, _, TsIdent(name), _, _, _, _) => - TsTypeLiteral(TsLiteralString(name)) + TsTypeLiteral(TsLiteral.Str(name)) } literals.length match { diff --git a/utils/src/main/scala/org/scalablytyped/converter/internal/Markers.scala b/utils/src/main/scala/org/scalablytyped/converter/internal/Markers.scala deleted file mode 100644 index 855781df10..0000000000 --- a/utils/src/main/scala/org/scalablytyped/converter/internal/Markers.scala +++ /dev/null @@ -1,14 +0,0 @@ -package org.scalablytyped.converter.internal - -/* We need a few pieces of out of band information bundled within the tree, - to be used like annotations. Instead of actually inventing annotations on - the typescript side we rather just work with special comments. - */ -object Markers { - case object CouldBeScalaJsDefined extends Comment.Data - case object IsTrivial extends Comment.Data - case object ExpandedCallables extends Comment.Data - case object ExpandedClass extends Comment.Data - case object EnumObject extends Comment.Data - case class NameHint(value: String) extends Comment.Data -}