Skip to content

Commit

Permalink
Builders: initialize literals without user input
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindberg committed Mar 5, 2021
1 parent 710eff0 commit 8c5b59e
Show file tree
Hide file tree
Showing 20 changed files with 65 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package scalajs
package flavours

import org.scalablytyped.converter.internal.scalajs.ExprTree._
import org.scalablytyped.converter.internal.scalajs.transforms.FakeLiterals

sealed trait ObjectUpdater
case class Initializer(value: ExprTree.Arg.Named) extends ObjectUpdater
Expand All @@ -25,6 +26,24 @@ object defaultInterpretation {

(updater, Right(param))

case prop @ Prop.Normal(Prop.Variant(tpe, asExpr, _, _), _, Optionality.No, _, _)
if tpe.comments.has[FakeLiterals.WasLiteral] =>
def updateObj(value: ExprTree): Mutator =
Mutator(ref =>
Call(
Select(ref, Name("updateDynamic")),
IArray(IArray(StringLit(prop.originalName.unescaped)), IArray(value)),
),
)

val lit = tpe.comments.extract { case FakeLiterals.WasLiteral(lit) => lit }.get._1

val updater =
if (prop.canBeInitializer) Initializer(Arg.Named(prop.name, asExpr(Ref(prop.name))))
else updateObj(asExpr(Ref(prop.name)))

(updater, Left(Val(prop.name, lit)))

case prop @ Prop.Normal(Prop.Variant(tpe, asExpr, _, _), _, optionality, _, _) =>
def updateObj(value: ExprTree): Mutator =
Mutator(ref =>
Expand Down
4 changes: 2 additions & 2 deletions tests/material-ui/check-japgolly/m/material-ui/build.sbt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
organization := "org.scalablytyped"
name := "material-ui"
version := "0.0-unknown-f78bcc"
version := "0.0-unknown-a70916"
scalaVersion := "2.13.3"
enablePlugins(ScalaJSPlugin)
libraryDependencies ++= Seq(
"com.github.japgolly.scalajs-react" %%% "core" % "1.7.5",
"com.olvind" %%% "scalablytyped-runtime" % "2.4.0",
"org.scalablytyped" %%% "react" % "0.0-unknown-bcfda0",
"org.scalablytyped" %%% "react" % "0.0-unknown-f53ff8",
"org.scalablytyped" %%% "std" % "0.0-unknown-310cd4")
publishArtifact in packageDoc := false
scalacOptions ++= List("-encoding", "utf-8", "-feature", "-g:notailcalls", "-language:implicitConversions", "-language:higherKinds", "-language:existentials")
Expand Down
2 changes: 1 addition & 1 deletion tests/material-ui/check-japgolly/r/react/build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
organization := "org.scalablytyped"
name := "react"
version := "0.0-unknown-bcfda0"
version := "0.0-unknown-f53ff8"
scalaVersion := "2.13.3"
enablePlugins(ScalaJSPlugin)
libraryDependencies ++= Seq(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ object mod {
object HTMLProps {

@scala.inline
def apply[T](defaultValue: foo, onChange: foo, `type`: foo, value: foo): HTMLProps[T] = {
def apply[T](): HTMLProps[T] = {
val defaultValue = "foo"
val onChange = "foo"
val `type` = "foo"
val value = "foo"
val __obj = js.Dynamic.literal(defaultValue = defaultValue.asInstanceOf[js.Any], onChange = onChange.asInstanceOf[js.Any], value = value.asInstanceOf[js.Any])
__obj.updateDynamic("type")(`type`.asInstanceOf[js.Any])
__obj.asInstanceOf[HTMLProps[T]]
Expand Down
4 changes: 2 additions & 2 deletions tests/material-ui/check-slinky/m/material-ui/build.sbt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
organization := "org.scalablytyped"
name := "material-ui"
version := "0.0-unknown-4475ac"
version := "0.0-unknown-1ee9f3"
scalaVersion := "2.13.3"
enablePlugins(ScalaJSPlugin)
libraryDependencies ++= Seq(
"com.olvind" %%% "scalablytyped-runtime" % "2.4.0",
"me.shadaj" %%% "slinky-web" % "0.6.6",
"org.scalablytyped" %%% "react" % "0.0-unknown-eed1bf",
"org.scalablytyped" %%% "react" % "0.0-unknown-c65052",
"org.scalablytyped" %%% "std" % "0.0-unknown-da7a30")
publishArtifact in packageDoc := false
scalacOptions ++= List("-encoding", "utf-8", "-feature", "-g:notailcalls", "-language:implicitConversions", "-language:higherKinds", "-language:existentials")
Expand Down
2 changes: 1 addition & 1 deletion tests/material-ui/check-slinky/r/react/build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
organization := "org.scalablytyped"
name := "react"
version := "0.0-unknown-eed1bf"
version := "0.0-unknown-c65052"
scalaVersion := "2.13.3"
enablePlugins(ScalaJSPlugin)
libraryDependencies ++= Seq(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ object mod {
object HTMLProps {

@scala.inline
def apply[T](defaultValue: foo, onChange: foo, `type`: foo, value: foo): HTMLProps[T] = {
def apply[T](): HTMLProps[T] = {
val defaultValue = "foo"
val onChange = "foo"
val `type` = "foo"
val value = "foo"
val __obj = js.Dynamic.literal(defaultValue = defaultValue.asInstanceOf[js.Any], onChange = onChange.asInstanceOf[js.Any], value = value.asInstanceOf[js.Any])
__obj.updateDynamic("type")(`type`.asInstanceOf[js.Any])
__obj.asInstanceOf[HTMLProps[T]]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
organization := "org.scalablytyped"
name := "react-bootstrap"
version := "0.32-9c84e7"
version := "0.32-dfce69"
scalaVersion := "2.13.3"
enablePlugins(ScalaJSPlugin)
libraryDependencies ++= Seq(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ object toggleButtonGroupMod {
object CheckboxProps {

@scala.inline
def apply(`type`: checkbox): CheckboxProps = {
def apply(): CheckboxProps = {
val `type` = "checkbox"
val __obj = js.Dynamic.literal()
__obj.updateDynamic("type")(`type`.asInstanceOf[js.Any])
__obj.asInstanceOf[CheckboxProps]
Expand Down Expand Up @@ -114,7 +115,8 @@ object toggleButtonGroupMod {
object RadioProps {

@scala.inline
def apply(name: String, `type`: radio): RadioProps = {
def apply(name: String): RadioProps = {
val `type` = "radio"
val __obj = js.Dynamic.literal(name = name.asInstanceOf[js.Any])
__obj.updateDynamic("type")(`type`.asInstanceOf[js.Any])
__obj.asInstanceOf[RadioProps]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
organization := "org.scalablytyped"
name := "react-bootstrap"
version := "0.32-76e0eb"
version := "0.32-e57327"
scalaVersion := "2.13.3"
enablePlugins(ScalaJSPlugin)
libraryDependencies ++= Seq(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ object toggleButtonGroupMod {
object CheckboxProps {

@scala.inline
def apply(`type`: checkbox): CheckboxProps = {
def apply(): CheckboxProps = {
val `type` = "checkbox"
val __obj = js.Dynamic.literal()
__obj.updateDynamic("type")(`type`.asInstanceOf[js.Any])
__obj.asInstanceOf[CheckboxProps]
Expand Down Expand Up @@ -113,7 +114,8 @@ object toggleButtonGroupMod {
object RadioProps {

@scala.inline
def apply(name: String, `type`: radio): RadioProps = {
def apply(name: String): RadioProps = {
val `type` = "radio"
val __obj = js.Dynamic.literal(name = name.asInstanceOf[js.Any])
__obj.updateDynamic("type")(`type`.asInstanceOf[js.Any])
__obj.asInstanceOf[RadioProps]
Expand Down
2 changes: 1 addition & 1 deletion tests/type-mappings/check/t/type-mappings/build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
organization := "org.scalablytyped"
name := "type-mappings"
version := "0.0-unknown-4c9a52"
version := "0.0-unknown-dc551a"
scalaVersion := "2.13.3"
enablePlugins(ScalaJSPlugin)
libraryDependencies ++= Seq(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package typings.typeMappings

import typings.typeMappings.typeMappingsStrings.text
import typings.typeMappings.typeMappingsStrings.trail
import org.scalablytyped.runtime.StObject
import scala.scalajs.js
import scala.scalajs.js.`|`
Expand All @@ -15,14 +13,16 @@ trait Mark extends StObject
object Mark {

@scala.inline
def TextMark(`type`: text): typings.typeMappings.TextMark = {
def TextMark(): typings.typeMappings.TextMark = {
val `type` = "text"
val __obj = js.Dynamic.literal()
__obj.updateDynamic("type")(`type`.asInstanceOf[js.Any])
__obj.asInstanceOf[typings.typeMappings.TextMark]
}

@scala.inline
def TrailMark(`type`: trail): typings.typeMappings.TrailMark = {
def TrailMark(): typings.typeMappings.TrailMark = {
val `type` = "trail"
val __obj = js.Dynamic.literal()
__obj.updateDynamic("type")(`type`.asInstanceOf[js.Any])
__obj.asInstanceOf[typings.typeMappings.TrailMark]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ trait TextMark extends Mark {
object TextMark {

@scala.inline
def apply(`type`: text): TextMark = {
def apply(): TextMark = {
val `type` = "text"
val __obj = js.Dynamic.literal()
__obj.updateDynamic("type")(`type`.asInstanceOf[js.Any])
__obj.asInstanceOf[TextMark]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ trait TrailMark extends Mark {
object TrailMark {

@scala.inline
def apply(`type`: trail): TrailMark = {
def apply(): TrailMark = {
val `type` = "trail"
val __obj = js.Dynamic.literal()
__obj.updateDynamic("type")(`type`.asInstanceOf[js.Any])
__obj.asInstanceOf[TrailMark]
Expand Down
2 changes: 1 addition & 1 deletion tests/winston/check/w/winston/build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
organization := "org.scalablytyped"
name := "winston"
version := "3.0.0-b0ea11"
version := "3.0.0-eeac34"
scalaVersion := "2.13.3"
enablePlugins(ScalaJSPlugin)
libraryDependencies ++= Seq(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ object configMod extends Shortcut {
object Config {

@scala.inline
def apply(foo: bar): Config = {
def apply(): Config = {
val foo = "bar"
val __obj = js.Dynamic.literal(foo = foo.asInstanceOf[js.Any])
__obj.asInstanceOf[Config]
}
Expand Down
2 changes: 1 addition & 1 deletion tests/with-theme/check/r/react/build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
organization := "org.scalablytyped"
name := "react"
version := "0.0-unknown-b14678"
version := "0.0-unknown-637f43"
scalaVersion := "2.13.3"
enablePlugins(ScalaJSPlugin)
libraryDependencies ++= Seq(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ object mod {
object HTMLProps {

@scala.inline
def apply[T](defaultValue: foo, onChange: foo, `type`: foo, value: foo): HTMLProps[T] = {
def apply[T](): HTMLProps[T] = {
val defaultValue = "foo"
val onChange = "foo"
val `type` = "foo"
val value = "foo"
val __obj = js.Dynamic.literal(defaultValue = defaultValue.asInstanceOf[js.Any], onChange = onChange.asInstanceOf[js.Any], value = value.asInstanceOf[js.Any])
__obj.updateDynamic("type")(`type`.asInstanceOf[js.Any])
__obj.asInstanceOf[HTMLProps[T]]
Expand Down
4 changes: 2 additions & 2 deletions tests/with-theme/check/w/with-theme/build.sbt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
organization := "org.scalablytyped"
name := "with-theme"
version := "0.0-unknown-ffecee"
version := "0.0-unknown-206c7e"
scalaVersion := "2.13.3"
enablePlugins(ScalaJSPlugin)
libraryDependencies ++= Seq(
"com.olvind" %%% "scalablytyped-runtime" % "2.4.0",
"org.scalablytyped" %%% "react" % "0.0-unknown-b14678",
"org.scalablytyped" %%% "react" % "0.0-unknown-637f43",
"org.scalablytyped" %%% "std" % "0.0-unknown-952689")
publishArtifact in packageDoc := false
scalacOptions ++= List("-encoding", "utf-8", "-feature", "-g:notailcalls", "-language:implicitConversions", "-language:higherKinds", "-language:existentials")
Expand Down

0 comments on commit 8c5b59e

Please sign in to comment.