From 2039cd5a695c49d167859c3c4aa668f95f1199bf Mon Sep 17 00:00:00 2001 From: Jason McClellan Date: Mon, 5 Feb 2024 19:36:50 -0500 Subject: [PATCH] Added test case to show issue with export default Some pacakges such as pixi.js re-export 3rd party libraries under their own namespace, e.g. @pixi/util does the following: export { default as EventEmitter } from 'eventemitter3' in order to provide the EventEmitter module from eventemitter3 under the @pixi/util namespace. The converter appears to ignore exports of this form and no module is created. This breaks libraries that rely on this behavior such as Pixi. --- .../internal/importer/ImporterTest.scala | 1 + .../check-3/e/export-default/build.sbt | 11 +++++++++++ .../e/export-default/project/build.properties | 1 + .../check-3/e/export-default/project/plugins.sbt | 1 + .../check-3/e/export-default/readme.md | 15 +++++++++++++++ .../exportDefault/exportDefaultRequire.scala | 11 +++++++++++ .../main/scala/typings/exportDefault/mod.scala | 13 +++++++++++++ tests/export-default/check-3/f/foo/build.sbt | 10 ++++++++++ .../check-3/f/foo/project/build.properties | 1 + .../check-3/f/foo/project/plugins.sbt | 1 + tests/export-default/check-3/f/foo/readme.md | 15 +++++++++++++++ .../src/main/scala/typings/foo/fooRequire.scala | 11 +++++++++++ .../f/foo/src/main/scala/typings/foo/mod.scala | 16 ++++++++++++++++ .../export-default/in/export-default/index.d.ts | 1 + tests/export-default/in/foo/index.d.ts | 1 + .../check-3/e/eventemitter3/build.sbt | 10 ++++++++++ .../e/eventemitter3/project/build.properties | 1 + .../check-3/e/eventemitter3/project/plugins.sbt | 1 + .../check-3/e/eventemitter3/readme.md | 15 +++++++++++++++ .../eventemitter3/eventemitter3Require.scala | 11 +++++++++++ .../main/scala/typings/eventemitter3/mod.scala | 16 ++++++++++++++++ .../check-3/p/pixi__utils/build.sbt | 11 +++++++++++ .../p/pixi__utils/project/build.properties | 1 + .../check-3/p/pixi__utils/project/plugins.sbt | 1 + .../check-3/p/pixi__utils/readme.md | 15 +++++++++++++++ .../main/scala/typings/pixiUtils/libMod.scala | 13 +++++++++++++ .../typings/pixiUtils/pixiUtilsRequire.scala | 11 +++++++++++ 27 files changed, 215 insertions(+) create mode 100644 tests/export-default/check-3/e/export-default/build.sbt create mode 100644 tests/export-default/check-3/e/export-default/project/build.properties create mode 100644 tests/export-default/check-3/e/export-default/project/plugins.sbt create mode 100644 tests/export-default/check-3/e/export-default/readme.md create mode 100644 tests/export-default/check-3/e/export-default/src/main/scala/typings/exportDefault/exportDefaultRequire.scala create mode 100644 tests/export-default/check-3/e/export-default/src/main/scala/typings/exportDefault/mod.scala create mode 100644 tests/export-default/check-3/f/foo/build.sbt create mode 100644 tests/export-default/check-3/f/foo/project/build.properties create mode 100644 tests/export-default/check-3/f/foo/project/plugins.sbt create mode 100644 tests/export-default/check-3/f/foo/readme.md create mode 100644 tests/export-default/check-3/f/foo/src/main/scala/typings/foo/fooRequire.scala create mode 100644 tests/export-default/check-3/f/foo/src/main/scala/typings/foo/mod.scala create mode 100644 tests/export-default/in/export-default/index.d.ts create mode 100644 tests/export-default/in/foo/index.d.ts create mode 100644 tests/pixi-utils-7.4.0/check-3/e/eventemitter3/build.sbt create mode 100644 tests/pixi-utils-7.4.0/check-3/e/eventemitter3/project/build.properties create mode 100644 tests/pixi-utils-7.4.0/check-3/e/eventemitter3/project/plugins.sbt create mode 100644 tests/pixi-utils-7.4.0/check-3/e/eventemitter3/readme.md create mode 100644 tests/pixi-utils-7.4.0/check-3/e/eventemitter3/src/main/scala/typings/eventemitter3/eventemitter3Require.scala create mode 100644 tests/pixi-utils-7.4.0/check-3/e/eventemitter3/src/main/scala/typings/eventemitter3/mod.scala create mode 100644 tests/pixi-utils-7.4.0/check-3/p/pixi__utils/build.sbt create mode 100644 tests/pixi-utils-7.4.0/check-3/p/pixi__utils/project/build.properties create mode 100644 tests/pixi-utils-7.4.0/check-3/p/pixi__utils/project/plugins.sbt create mode 100644 tests/pixi-utils-7.4.0/check-3/p/pixi__utils/readme.md create mode 100644 tests/pixi-utils-7.4.0/check-3/p/pixi__utils/src/main/scala/typings/pixiUtils/libMod.scala create mode 100644 tests/pixi-utils-7.4.0/check-3/p/pixi__utils/src/main/scala/typings/pixiUtils/pixiUtilsRequire.scala diff --git a/importer/src/test/scala/org/scalablytyped/converter/internal/importer/ImporterTest.scala b/importer/src/test/scala/org/scalablytyped/converter/internal/importer/ImporterTest.scala index 41cc073fb5..321ec5c55f 100644 --- a/importer/src/test/scala/org/scalablytyped/converter/internal/importer/ImporterTest.scala +++ b/importer/src/test/scala/org/scalablytyped/converter/internal/importer/ImporterTest.scala @@ -26,6 +26,7 @@ trait ImporterTest extends AnyFunSuite with ImporterHarness with ParallelTestExe test("pixi.js")(assertImportsOk("pixi.js", pedantic = false)) test("augment-module")(assertImportsOk("augment-module", pedantic = false)) test("typings-json")(assertImportsOk("typings-json", pedantic = true)) + test("export-default")(assertImportsOk("export-default", pedantic = true)) test("export-as-namespace")(assertImportsOk("export-as-namespace", pedantic = true)) test("babylon")(assertImportsOk("babylon", pedantic = true)) test("bigint")(assertImportsOk("bigint", pedantic = true)) diff --git a/tests/export-default/check-3/e/export-default/build.sbt b/tests/export-default/check-3/e/export-default/build.sbt new file mode 100644 index 0000000000..7d238463e5 --- /dev/null +++ b/tests/export-default/check-3/e/export-default/build.sbt @@ -0,0 +1,11 @@ +organization := "org.scalablytyped" +name := "export-default" +version := "0.0-unknown-d7a32e" +scalaVersion := "3.3.1" +enablePlugins(ScalaJSPlugin) +libraryDependencies ++= Seq( + "com.olvind" %%% "scalablytyped-runtime" % "2.4.2", + "org.scalablytyped" %%% "foo" % "0.0-unknown-f52260") +publishArtifact in packageDoc := false +scalacOptions ++= List("-encoding", "utf-8", "-feature", "-language:implicitConversions", "-language:higherKinds", "-language:existentials", "-no-indent", "-source:future") +licenses += ("MIT", url("http://opensource.org/licenses/MIT")) diff --git a/tests/export-default/check-3/e/export-default/project/build.properties b/tests/export-default/check-3/e/export-default/project/build.properties new file mode 100644 index 0000000000..dde206f70d --- /dev/null +++ b/tests/export-default/check-3/e/export-default/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.9.6 \ No newline at end of file diff --git a/tests/export-default/check-3/e/export-default/project/plugins.sbt b/tests/export-default/check-3/e/export-default/project/plugins.sbt new file mode 100644 index 0000000000..e7caee80b5 --- /dev/null +++ b/tests/export-default/check-3/e/export-default/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("org.scala-js" %% "sbt-scalajs" % "1.11.0") diff --git a/tests/export-default/check-3/e/export-default/readme.md b/tests/export-default/check-3/e/export-default/readme.md new file mode 100644 index 0000000000..6ca6d02649 --- /dev/null +++ b/tests/export-default/check-3/e/export-default/readme.md @@ -0,0 +1,15 @@ + +# Scala.js typings for export-default + + + + +## Note +This library has been generated from typescript code from first party type definitions. + +Provided with :purple_heart: from [ScalablyTyped](https://github.com/oyvindberg/ScalablyTyped) + +## Usage +See [the main readme](../../readme.md) for instructions. + + diff --git a/tests/export-default/check-3/e/export-default/src/main/scala/typings/exportDefault/exportDefaultRequire.scala b/tests/export-default/check-3/e/export-default/src/main/scala/typings/exportDefault/exportDefaultRequire.scala new file mode 100644 index 0000000000..ee006fc5ee --- /dev/null +++ b/tests/export-default/check-3/e/export-default/src/main/scala/typings/exportDefault/exportDefaultRequire.scala @@ -0,0 +1,11 @@ +package typings.exportDefault + +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +/* 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 */ +@JSImport("export-default", JSImport.Namespace) +@js.native +object exportDefaultRequire extends StObject diff --git a/tests/export-default/check-3/e/export-default/src/main/scala/typings/exportDefault/mod.scala b/tests/export-default/check-3/e/export-default/src/main/scala/typings/exportDefault/mod.scala new file mode 100644 index 0000000000..b03023cc75 --- /dev/null +++ b/tests/export-default/check-3/e/export-default/src/main/scala/typings/exportDefault/mod.scala @@ -0,0 +1,13 @@ +package typings.exportDefault + +import typings.foo.mod.default +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +object mod { + + @JSImport("export-default", "Foo") + @js.native + open class Foo () extends default +} diff --git a/tests/export-default/check-3/f/foo/build.sbt b/tests/export-default/check-3/f/foo/build.sbt new file mode 100644 index 0000000000..6c8f1388a1 --- /dev/null +++ b/tests/export-default/check-3/f/foo/build.sbt @@ -0,0 +1,10 @@ +organization := "org.scalablytyped" +name := "foo" +version := "0.0-unknown-f52260" +scalaVersion := "3.3.1" +enablePlugins(ScalaJSPlugin) +libraryDependencies ++= Seq( + "com.olvind" %%% "scalablytyped-runtime" % "2.4.2") +publishArtifact in packageDoc := false +scalacOptions ++= List("-encoding", "utf-8", "-feature", "-language:implicitConversions", "-language:higherKinds", "-language:existentials", "-no-indent", "-source:future") +licenses += ("MIT", url("http://opensource.org/licenses/MIT")) diff --git a/tests/export-default/check-3/f/foo/project/build.properties b/tests/export-default/check-3/f/foo/project/build.properties new file mode 100644 index 0000000000..dde206f70d --- /dev/null +++ b/tests/export-default/check-3/f/foo/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.9.6 \ No newline at end of file diff --git a/tests/export-default/check-3/f/foo/project/plugins.sbt b/tests/export-default/check-3/f/foo/project/plugins.sbt new file mode 100644 index 0000000000..e7caee80b5 --- /dev/null +++ b/tests/export-default/check-3/f/foo/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("org.scala-js" %% "sbt-scalajs" % "1.11.0") diff --git a/tests/export-default/check-3/f/foo/readme.md b/tests/export-default/check-3/f/foo/readme.md new file mode 100644 index 0000000000..fa00438111 --- /dev/null +++ b/tests/export-default/check-3/f/foo/readme.md @@ -0,0 +1,15 @@ + +# Scala.js typings for foo + + + + +## Note +This library has been generated from typescript code from first party type definitions. + +Provided with :purple_heart: from [ScalablyTyped](https://github.com/oyvindberg/ScalablyTyped) + +## Usage +See [the main readme](../../readme.md) for instructions. + + diff --git a/tests/export-default/check-3/f/foo/src/main/scala/typings/foo/fooRequire.scala b/tests/export-default/check-3/f/foo/src/main/scala/typings/foo/fooRequire.scala new file mode 100644 index 0000000000..e239d2c4f2 --- /dev/null +++ b/tests/export-default/check-3/f/foo/src/main/scala/typings/foo/fooRequire.scala @@ -0,0 +1,11 @@ +package typings.foo + +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +/* 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 */ +@JSImport("foo", JSImport.Namespace) +@js.native +object fooRequire extends StObject diff --git a/tests/export-default/check-3/f/foo/src/main/scala/typings/foo/mod.scala b/tests/export-default/check-3/f/foo/src/main/scala/typings/foo/mod.scala new file mode 100644 index 0000000000..d4c897af87 --- /dev/null +++ b/tests/export-default/check-3/f/foo/src/main/scala/typings/foo/mod.scala @@ -0,0 +1,16 @@ +package typings.foo + +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +object mod { + + @JSImport("foo", JSImport.Default) + @js.native + open class default () + extends StObject + with Foo + + trait Foo extends StObject +} diff --git a/tests/export-default/in/export-default/index.d.ts b/tests/export-default/in/export-default/index.d.ts new file mode 100644 index 0000000000..b11ac9432d --- /dev/null +++ b/tests/export-default/in/export-default/index.d.ts @@ -0,0 +1 @@ +export { default as Foo } from "foo"; diff --git a/tests/export-default/in/foo/index.d.ts b/tests/export-default/in/foo/index.d.ts new file mode 100644 index 0000000000..7804111002 --- /dev/null +++ b/tests/export-default/in/foo/index.d.ts @@ -0,0 +1 @@ +export default class Foo {} diff --git a/tests/pixi-utils-7.4.0/check-3/e/eventemitter3/build.sbt b/tests/pixi-utils-7.4.0/check-3/e/eventemitter3/build.sbt new file mode 100644 index 0000000000..b04d32c5e6 --- /dev/null +++ b/tests/pixi-utils-7.4.0/check-3/e/eventemitter3/build.sbt @@ -0,0 +1,10 @@ +organization := "org.scalablytyped" +name := "eventemitter3" +version := "0.0-unknown-f8988b" +scalaVersion := "3.3.1" +enablePlugins(ScalaJSPlugin) +libraryDependencies ++= Seq( + "com.olvind" %%% "scalablytyped-runtime" % "2.4.2") +publishArtifact in packageDoc := false +scalacOptions ++= List("-encoding", "utf-8", "-feature", "-language:implicitConversions", "-language:higherKinds", "-language:existentials", "-no-indent", "-source:future") +licenses += ("MIT", url("http://opensource.org/licenses/MIT")) diff --git a/tests/pixi-utils-7.4.0/check-3/e/eventemitter3/project/build.properties b/tests/pixi-utils-7.4.0/check-3/e/eventemitter3/project/build.properties new file mode 100644 index 0000000000..dde206f70d --- /dev/null +++ b/tests/pixi-utils-7.4.0/check-3/e/eventemitter3/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.9.6 \ No newline at end of file diff --git a/tests/pixi-utils-7.4.0/check-3/e/eventemitter3/project/plugins.sbt b/tests/pixi-utils-7.4.0/check-3/e/eventemitter3/project/plugins.sbt new file mode 100644 index 0000000000..e7caee80b5 --- /dev/null +++ b/tests/pixi-utils-7.4.0/check-3/e/eventemitter3/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("org.scala-js" %% "sbt-scalajs" % "1.11.0") diff --git a/tests/pixi-utils-7.4.0/check-3/e/eventemitter3/readme.md b/tests/pixi-utils-7.4.0/check-3/e/eventemitter3/readme.md new file mode 100644 index 0000000000..3679c7eb1e --- /dev/null +++ b/tests/pixi-utils-7.4.0/check-3/e/eventemitter3/readme.md @@ -0,0 +1,15 @@ + +# Scala.js typings for eventemitter3 + + + + +## Note +This library has been generated from typescript code from first party type definitions. + +Provided with :purple_heart: from [ScalablyTyped](https://github.com/oyvindberg/ScalablyTyped) + +## Usage +See [the main readme](../../readme.md) for instructions. + + diff --git a/tests/pixi-utils-7.4.0/check-3/e/eventemitter3/src/main/scala/typings/eventemitter3/eventemitter3Require.scala b/tests/pixi-utils-7.4.0/check-3/e/eventemitter3/src/main/scala/typings/eventemitter3/eventemitter3Require.scala new file mode 100644 index 0000000000..3459e3015b --- /dev/null +++ b/tests/pixi-utils-7.4.0/check-3/e/eventemitter3/src/main/scala/typings/eventemitter3/eventemitter3Require.scala @@ -0,0 +1,11 @@ +package typings.eventemitter3 + +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +/* 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 */ +@JSImport("eventemitter3", JSImport.Namespace) +@js.native +object eventemitter3Require extends StObject diff --git a/tests/pixi-utils-7.4.0/check-3/e/eventemitter3/src/main/scala/typings/eventemitter3/mod.scala b/tests/pixi-utils-7.4.0/check-3/e/eventemitter3/src/main/scala/typings/eventemitter3/mod.scala new file mode 100644 index 0000000000..3c7777448c --- /dev/null +++ b/tests/pixi-utils-7.4.0/check-3/e/eventemitter3/src/main/scala/typings/eventemitter3/mod.scala @@ -0,0 +1,16 @@ +package typings.eventemitter3 + +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +object mod { + + @JSImport("eventemitter3", JSImport.Namespace) + @js.native + open class ^[EventTypes, Context /* <: Any */] () + extends StObject + with EventEmitter[EventTypes, Context] + + trait EventEmitter[EventTypes, Context /* <: Any */] extends StObject +} diff --git a/tests/pixi-utils-7.4.0/check-3/p/pixi__utils/build.sbt b/tests/pixi-utils-7.4.0/check-3/p/pixi__utils/build.sbt new file mode 100644 index 0000000000..9ca26802b1 --- /dev/null +++ b/tests/pixi-utils-7.4.0/check-3/p/pixi__utils/build.sbt @@ -0,0 +1,11 @@ +organization := "org.scalablytyped" +name := "pixi__utils" +version := "0.0-unknown-02740c" +scalaVersion := "3.3.1" +enablePlugins(ScalaJSPlugin) +libraryDependencies ++= Seq( + "com.olvind" %%% "scalablytyped-runtime" % "2.4.2", + "org.scalablytyped" %%% "eventemitter3" % "0.0-unknown-f8988b") +publishArtifact in packageDoc := false +scalacOptions ++= List("-encoding", "utf-8", "-feature", "-language:implicitConversions", "-language:higherKinds", "-language:existentials", "-no-indent", "-source:future") +licenses += ("MIT", url("http://opensource.org/licenses/MIT")) diff --git a/tests/pixi-utils-7.4.0/check-3/p/pixi__utils/project/build.properties b/tests/pixi-utils-7.4.0/check-3/p/pixi__utils/project/build.properties new file mode 100644 index 0000000000..dde206f70d --- /dev/null +++ b/tests/pixi-utils-7.4.0/check-3/p/pixi__utils/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.9.6 \ No newline at end of file diff --git a/tests/pixi-utils-7.4.0/check-3/p/pixi__utils/project/plugins.sbt b/tests/pixi-utils-7.4.0/check-3/p/pixi__utils/project/plugins.sbt new file mode 100644 index 0000000000..e7caee80b5 --- /dev/null +++ b/tests/pixi-utils-7.4.0/check-3/p/pixi__utils/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("org.scala-js" %% "sbt-scalajs" % "1.11.0") diff --git a/tests/pixi-utils-7.4.0/check-3/p/pixi__utils/readme.md b/tests/pixi-utils-7.4.0/check-3/p/pixi__utils/readme.md new file mode 100644 index 0000000000..bb4991090c --- /dev/null +++ b/tests/pixi-utils-7.4.0/check-3/p/pixi__utils/readme.md @@ -0,0 +1,15 @@ + +# Scala.js typings for pixi__utils + + + + +## Note +This library has been generated from typescript code from first party type definitions. + +Provided with :purple_heart: from [ScalablyTyped](https://github.com/oyvindberg/ScalablyTyped) + +## Usage +See [the main readme](../../readme.md) for instructions. + + diff --git a/tests/pixi-utils-7.4.0/check-3/p/pixi__utils/src/main/scala/typings/pixiUtils/libMod.scala b/tests/pixi-utils-7.4.0/check-3/p/pixi__utils/src/main/scala/typings/pixiUtils/libMod.scala new file mode 100644 index 0000000000..26d9ad52b8 --- /dev/null +++ b/tests/pixi-utils-7.4.0/check-3/p/pixi__utils/src/main/scala/typings/pixiUtils/libMod.scala @@ -0,0 +1,13 @@ +package typings.pixiUtils + +import typings.eventemitter3.mod.^ +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +object libMod { + + @JSImport("@pixi/utils/lib", "EventEmitter") + @js.native + open class EventEmitter[EventTypes, Context /* <: Any */] () extends ^[EventTypes, Context] +} diff --git a/tests/pixi-utils-7.4.0/check-3/p/pixi__utils/src/main/scala/typings/pixiUtils/pixiUtilsRequire.scala b/tests/pixi-utils-7.4.0/check-3/p/pixi__utils/src/main/scala/typings/pixiUtils/pixiUtilsRequire.scala new file mode 100644 index 0000000000..fd08cdd18a --- /dev/null +++ b/tests/pixi-utils-7.4.0/check-3/p/pixi__utils/src/main/scala/typings/pixiUtils/pixiUtilsRequire.scala @@ -0,0 +1,11 @@ +package typings.pixiUtils + +import org.scalablytyped.runtime.StObject +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess} + +/* 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 */ +@JSImport("@pixi/utils", JSImport.Namespace) +@js.native +object pixiUtilsRequire extends StObject