From f8bebe73fdd90580641764992702458720b31eb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Raddum=20Berg?= Date: Thu, 2 Jul 2020 12:54:24 +0200 Subject: [PATCH] recognize function components returning `any` --- .../src/sbt-test/react/external/build.sbt | 1 - .../flavours/IdentifyReactComponents.scala | 2 + .../build.sbt | 2 +- .../components/EventListener.scala | 47 +++++++++++++++++++ .../build.sbt | 2 +- .../components/EventListener.scala | 38 +++++++++++++++ 6 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 tests/react-integration-test/check-japgolly/s/stardust-ui__react-component-event-listener/src/main/scala/typingsJapgolly/stardustUiReactComponentEventListener/components/EventListener.scala create mode 100644 tests/react-integration-test/check-slinky/s/stardust-ui__react-component-event-listener/src/main/scala/typingsSlinky/stardustUiReactComponentEventListener/components/EventListener.scala diff --git a/sbt-converter/src/sbt-test/react/external/build.sbt b/sbt-converter/src/sbt-test/react/external/build.sbt index 4ba6bbf98f..81aa88422b 100644 --- a/sbt-converter/src/sbt-test/react/external/build.sbt +++ b/sbt-converter/src/sbt-test/react/external/build.sbt @@ -15,4 +15,3 @@ lazy val testProject = scalaVersion := "2.13.2", organization := "net.leibman", ) - diff --git a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/IdentifyReactComponents.scala b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/IdentifyReactComponents.scala index ecbc7334c8..cc1afbed7c 100644 --- a/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/IdentifyReactComponents.scala +++ b/scalajs/src/main/scala/org/scalablytyped/converter/internal/scalajs/flavours/IdentifyReactComponents.scala @@ -75,6 +75,8 @@ class IdentifyReactComponents(reactNames: ReactNames, parentsResolver: ParentsRe def maybeMethodComponent(method: MethodTree, owner: ContainerTree, scope: TreeScope): Option[Component] = { def returnsElement(scope: TreeScope, current: TypeRef): Option[TypeRef] = if (reactNames.isElement(current.typeName)) Some(current) + else if (current === TypeRef.Any) + Some(current) // unfortunately this conforms on the TS side, let's see how it works out else if (scope.isAbstract(current)) None else current match { diff --git a/tests/react-integration-test/check-japgolly/s/stardust-ui__react-component-event-listener/build.sbt b/tests/react-integration-test/check-japgolly/s/stardust-ui__react-component-event-listener/build.sbt index 3c18ca48d3..9431d28dad 100644 --- a/tests/react-integration-test/check-japgolly/s/stardust-ui__react-component-event-listener/build.sbt +++ b/tests/react-integration-test/check-japgolly/s/stardust-ui__react-component-event-listener/build.sbt @@ -1,6 +1,6 @@ organization := "org.scalablytyped" name := "stardust-ui__react-component-event-listener" -version := "0.38.0-ffa70f" +version := "0.38.0-ad5fb5" scalaVersion := "2.13.2" enablePlugins(ScalaJSPlugin) libraryDependencies ++= Seq( diff --git a/tests/react-integration-test/check-japgolly/s/stardust-ui__react-component-event-listener/src/main/scala/typingsJapgolly/stardustUiReactComponentEventListener/components/EventListener.scala b/tests/react-integration-test/check-japgolly/s/stardust-ui__react-component-event-listener/src/main/scala/typingsJapgolly/stardustUiReactComponentEventListener/components/EventListener.scala new file mode 100644 index 0000000000..1cd8102e61 --- /dev/null +++ b/tests/react-integration-test/check-japgolly/s/stardust-ui__react-component-event-listener/src/main/scala/typingsJapgolly/stardustUiReactComponentEventListener/components/EventListener.scala @@ -0,0 +1,47 @@ +package typingsJapgolly.stardustUiReactComponentEventListener.components + +import japgolly.scalajs.react.Callback +import japgolly.scalajs.react.Children.Varargs +import japgolly.scalajs.react.CtorType.ChildArg +import japgolly.scalajs.react.JsComponent +import japgolly.scalajs.react.Key +import japgolly.scalajs.react.component.Js.MountedWithRawType +import japgolly.scalajs.react.component.Js.RawMounted +import japgolly.scalajs.react.component.Js.UnmountedSimple +import japgolly.scalajs.react.raw.React.RefHandle +import org.scalablytyped.runtime.StringDictionary +import typingsJapgolly.stardustUiReactComponentEventListener.typesMod.EventListenerOptions +import scala.scalajs.js +import scala.scalajs.js.`|` +import scala.scalajs.js.annotation._ + +object EventListener { + def apply[/* <: typingsJapgolly.stardustUiReactComponentEventListener.typesMod.EventTypes */ T]( + listener: /* import warning: importer.ImportType#apply Failed type conversion: / * import warning: transforms.QualifyReferences#resolveTypeRef many Couldn't qualify DocumentEventMap * / any[T] */ /* e */ js.Any => Callback, + targetRef: RefHandle[ + /* import warning: transforms.QualifyReferences#resolveTypeRef many Couldn't qualify Node */ js.Any + ], + `type`: T, + capture: js.UndefOr[Boolean] = js.undefined, + key: Key = null, + _overrides: StringDictionary[js.Any] = null + )( + children: ChildArg* + ): UnmountedSimple[ + EventListenerOptions[T], + MountedWithRawType[EventListenerOptions[T], js.Object, RawMounted[EventListenerOptions[T], js.Object]] + ] = { + val __obj = js.Dynamic.literal(listener = js.Any.fromFunction1((t0: /* import warning: importer.ImportType#apply Failed type conversion: / * import warning: transforms.QualifyReferences#resolveTypeRef many Couldn't qualify DocumentEventMap * / any[T] */ /* e */ js.Any) => listener(t0).runNow()), targetRef = targetRef.asInstanceOf[js.Any]) + __obj.updateDynamic("type")(`type`.asInstanceOf[js.Any]) + if (!js.isUndefined(capture)) __obj.updateDynamic("capture")(capture.get.asInstanceOf[js.Any]) + if (key != null) __obj.updateDynamic("key")(key.asInstanceOf[js.Any]) + if (_overrides != null) js.Dynamic.global.Object.assign(__obj, _overrides) + val f = JsComponent[EventListenerOptions[T], Varargs, js.Object](this.componentImport) + f(__obj.asInstanceOf[EventListenerOptions[T]])(children :_*) + } + @JSImport("@stardust-ui/react-component-event-listener/dist/es/EventListener", JSImport.Default) + @js.native + object componentImport extends js.Object + +} + diff --git a/tests/react-integration-test/check-slinky/s/stardust-ui__react-component-event-listener/build.sbt b/tests/react-integration-test/check-slinky/s/stardust-ui__react-component-event-listener/build.sbt index 1a2fbff7e8..c1874b94d8 100644 --- a/tests/react-integration-test/check-slinky/s/stardust-ui__react-component-event-listener/build.sbt +++ b/tests/react-integration-test/check-slinky/s/stardust-ui__react-component-event-listener/build.sbt @@ -1,6 +1,6 @@ organization := "org.scalablytyped" name := "stardust-ui__react-component-event-listener" -version := "0.38.0-dc344e" +version := "0.38.0-8f5a38" scalaVersion := "2.13.2" enablePlugins(ScalaJSPlugin) libraryDependencies ++= Seq( diff --git a/tests/react-integration-test/check-slinky/s/stardust-ui__react-component-event-listener/src/main/scala/typingsSlinky/stardustUiReactComponentEventListener/components/EventListener.scala b/tests/react-integration-test/check-slinky/s/stardust-ui__react-component-event-listener/src/main/scala/typingsSlinky/stardustUiReactComponentEventListener/components/EventListener.scala new file mode 100644 index 0000000000..5cea079405 --- /dev/null +++ b/tests/react-integration-test/check-slinky/s/stardust-ui__react-component-event-listener/src/main/scala/typingsSlinky/stardustUiReactComponentEventListener/components/EventListener.scala @@ -0,0 +1,38 @@ +package typingsSlinky.stardustUiReactComponentEventListener.components + +import slinky.core.facade.ReactRef +import slinky.web.html.`*`.tag +import typingsSlinky.StBuildingComponent +import typingsSlinky.stardustUiReactComponentEventListener.typesMod.EventListenerOptions +import scala.scalajs.js +import scala.scalajs.js.`|` +import scala.scalajs.js.annotation._ + +object EventListener { + @JSImport("@stardust-ui/react-component-event-listener/dist/es/EventListener", JSImport.Default) + @js.native + object component extends js.Object + + @scala.inline + class Builder[/* <: typingsSlinky.stardustUiReactComponentEventListener.typesMod.EventTypes */ T] (val args: js.Array[js.Any]) + extends AnyVal + with StBuildingComponent[tag.type, js.Object] { + @scala.inline + def capture(value: Boolean): this.type = set("capture", value.asInstanceOf[js.Any]) + } + + def withProps[/* <: typingsSlinky.stardustUiReactComponentEventListener.typesMod.EventTypes */ T](p: EventListenerOptions[T]): Builder[T] = new Builder[T](js.Array(this.component, p.asInstanceOf[js.Any])) + @scala.inline + def apply[/* <: typingsSlinky.stardustUiReactComponentEventListener.typesMod.EventTypes */ T]( + listener: /* import warning: importer.ImportType#apply Failed type conversion: / * import warning: transforms.QualifyReferences#resolveTypeRef many Couldn't qualify DocumentEventMap * / any[T] */ /* e */ js.Any => Unit, + targetRef: ReactRef[ + /* import warning: transforms.QualifyReferences#resolveTypeRef many Couldn't qualify Node */ js.Any + ], + `type`: T + ): Builder[T] = { + val __props = js.Dynamic.literal(listener = js.Any.fromFunction1(listener), targetRef = targetRef.asInstanceOf[js.Any]) + __props.updateDynamic("type")(`type`.asInstanceOf[js.Any]) + new Builder[T](js.Array(this.component, __props.asInstanceOf[EventListenerOptions[T]])) + } +} +