-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Collect all marker comments in one place, seal trait, fix API, prepare to enable writing a codec - Use prefixes for more ADTs - Rename utils to core, move ASTs to core - Uniform style for deriving json codecs - Rewrite circe auto derivation to semiauto and be explicit about instances for all types - The circe codec for the scala AST costs a lot of compile time unfortunately, so let's offset it by turning off optimizations locally. They will only be turned on in CI and for releases
- Loading branch information
1 parent
fcfbc91
commit ba921f8
Showing
122 changed files
with
949 additions
and
852 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
core/src/main/scala/org/scalablytyped/converter/internal/Comment.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions
5
.../converter/internal/ProtectionLevel.scala → .../converter/internal/ProtectionLevel.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
25 changes: 25 additions & 0 deletions
25
core/src/main/scala/org/scalablytyped/converter/internal/orphanCodecs.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.