From b9bea76ff0072215bde2477a75f4d64d51b85e82 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Mon, 7 Mar 2022 15:27:44 +0100 Subject: [PATCH] Revert "Upgrade to Scala.js 1.9.0." --- .../dotty/tools/backend/sjs/JSCodeGen.scala | 9 +--- .../dotc/transform/sjs/PrepJSInterop.scala | 33 +++----------- project/Build.scala | 2 +- project/plugins.sbt | 2 +- .../native-load-spec-need-explicit-name.check | 44 +------------------ .../native-load-spec-need-explicit-name.scala | 44 ++----------------- 6 files changed, 15 insertions(+), 119 deletions(-) diff --git a/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala b/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala index 4d8c8a63c444..0a7fc0e0ad10 100644 --- a/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala +++ b/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala @@ -4563,14 +4563,7 @@ class JSCodeGen()(using genCtx: Context) { val module = annot.argumentConstantString(0).getOrElse { unexpected("could not read the module argument as a string literal") } - val path = annot.argumentConstantString(1).fold { - if (annot.arguments.sizeIs < 2) - parsePath(sym.defaultJSName) - else - Nil - } { pathName => - parsePath(pathName) - } + val path = annot.argumentConstantString(1).fold[List[String]](Nil)(parsePath) val importSpec = Import(module, path) annot.argumentConstantString(2).fold[js.JSNativeLoadSpec] { importSpec diff --git a/compiler/src/dotty/tools/dotc/transform/sjs/PrepJSInterop.scala b/compiler/src/dotty/tools/dotc/transform/sjs/PrepJSInterop.scala index 97bdc138f571..2d9934d5526c 100644 --- a/compiler/src/dotty/tools/dotc/transform/sjs/PrepJSInterop.scala +++ b/compiler/src/dotty/tools/dotc/transform/sjs/PrepJSInterop.scala @@ -14,8 +14,7 @@ import Contexts._ import Decorators._ import DenotTransformers._ import Flags._ -import NameKinds.{DefaultGetterName, ModuleClassName} -import NameOps._ +import NameKinds.DefaultGetterName import StdNames._ import Symbols._ import SymUtils._ @@ -560,14 +559,9 @@ class PrepJSInterop extends MacroTransform with IdentityDenotTransformer { thisP case Some(annot) if annot.symbol == jsdefn.JSGlobalAnnot => checkJSGlobalLiteral(annot) val pathName = annot.argumentConstantString(0).getOrElse { - val symTermName = sym.name.exclude(NameKinds.ModuleClassName).toTermName - if (symTermName == nme.apply) { + if ((enclosingOwner is OwnerKind.ScalaMod) && !sym.owner.isPackageObject) { report.error( - "Native JS definitions named 'apply' must have an explicit name in @JSGlobal", - annot.tree) - } else if (symTermName.isSetterName) { - report.error( - "Native JS definitions with a name ending in '_=' must have an explicit name in @JSGlobal", + "Native JS members inside non-native objects must have an explicit name in @JSGlobal", annot.tree) } sym.defaultJSName @@ -576,18 +570,6 @@ class PrepJSInterop extends MacroTransform with IdentityDenotTransformer { thisP case Some(annot) if annot.symbol == jsdefn.JSImportAnnot => checkJSImportLiteral(annot) - if (annot.arguments.sizeIs < 2) { - val symTermName = sym.name.exclude(NameKinds.ModuleClassName).toTermName - if (symTermName == nme.apply) { - report.error( - "Native JS definitions named 'apply' must have an explicit name in @JSImport", - annot.tree) - } else if (symTermName.isSetterName) { - report.error( - "Native JS definitions with a name ending in '_=' must have an explicit name in @JSImport", - annot.tree) - } - } annot.argumentConstantString(2).foreach { globalPathName => checkGlobalRefPath(globalPathName) } @@ -1125,19 +1107,18 @@ object PrepJSInterop { */ private def checkJSImportLiteral(annot: Annotation)(using Context): Unit = { val args = annot.arguments - val argCount = args.size - assert(argCount >= 1 && argCount <= 3, - i"@JSImport annotation $annot does not have between 1 and 3 arguments") + assert(args.size == 2 || args.size == 3, + i"@JSImport annotation $annot does not have exactly 2 or 3 arguments") val firstArgIsValid = annot.argumentConstantString(0).isDefined if (!firstArgIsValid) report.error("The first argument to @JSImport must be a literal string.", args.head) - val secondArgIsValid = argCount < 2 || annot.argumentConstantString(1).isDefined || args(1).symbol == jsdefn.JSImportNamespaceModule + val secondArgIsValid = annot.argumentConstantString(1).isDefined || args(1).symbol == jsdefn.JSImportNamespaceModule if (!secondArgIsValid) report.error("The second argument to @JSImport must be literal string or the JSImport.Namespace object.", args(1)) - val thirdArgIsValid = argCount < 3 || annot.argumentConstantString(2).isDefined + val thirdArgIsValid = args.size < 3 || annot.argumentConstantString(2).isDefined if (!thirdArgIsValid) report.error("The third argument to @JSImport, when present, must be a literal string.", args(2)) } diff --git a/project/Build.scala b/project/Build.scala index f699d0232658..928aa5e1b67d 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -59,7 +59,7 @@ object Build { val referenceVersion = "3.1.2-RC1" - val baseVersion = "3.2.0-RC1" + val baseVersion = "3.1.3-RC1" // Versions used by the vscode extension to create a new project // This should be the latest published releases. diff --git a/project/plugins.sbt b/project/plugins.sbt index 9d743cec8252..1716bb51b7f1 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -2,7 +2,7 @@ // // e.g. addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.1.0") -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.9.0") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.7.1") addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.10") diff --git a/tests/neg-scalajs/native-load-spec-need-explicit-name.check b/tests/neg-scalajs/native-load-spec-need-explicit-name.check index 263acca9a2ca..9d91d4897d10 100644 --- a/tests/neg-scalajs/native-load-spec-need-explicit-name.check +++ b/tests/neg-scalajs/native-load-spec-need-explicit-name.check @@ -1,48 +1,8 @@ -- Error: tests/neg-scalajs/native-load-spec-need-explicit-name.scala:6:2 ---------------------------------------------- 6 | @JSGlobal // error | ^^^^^^^^^ - | Native JS definitions named 'apply' must have an explicit name in @JSGlobal + | Native JS members inside non-native objects must have an explicit name in @JSGlobal -- Error: tests/neg-scalajs/native-load-spec-need-explicit-name.scala:10:2 --------------------------------------------- 10 | @JSGlobal // error | ^^^^^^^^^ - | Native JS definitions named 'apply' must have an explicit name in @JSGlobal --- Error: tests/neg-scalajs/native-load-spec-need-explicit-name.scala:14:2 --------------------------------------------- -14 | @JSGlobal // error - | ^^^^^^^^^ - | Native JS definitions with a name ending in '_=' must have an explicit name in @JSGlobal --- Error: tests/neg-scalajs/native-load-spec-need-explicit-name.scala:20:2 --------------------------------------------- -20 | @JSGlobal // error - | ^^^^^^^^^ - | Native JS definitions with a name ending in '_=' must have an explicit name in @JSGlobal --- Error: tests/neg-scalajs/native-load-spec-need-explicit-name.scala:19:2 --------------------------------------------- -19 | @js.native // error - | ^^^^^^^^^^ - | @js.native is not allowed on vars, lazy vals and setter defs --- Error: tests/neg-scalajs/native-load-spec-need-explicit-name.scala:24:2 --------------------------------------------- -24 | @JSGlobal // error - | ^^^^^^^^^ - | Native JS definitions named 'apply' must have an explicit name in @JSGlobal --- Error: tests/neg-scalajs/native-load-spec-need-explicit-name.scala:30:3 --------------------------------------------- -30 | @JSImport("bar.js") // error - | ^^^^^^^^^^^^^^^^^^^ - | Native JS definitions named 'apply' must have an explicit name in @JSImport --- Error: tests/neg-scalajs/native-load-spec-need-explicit-name.scala:34:3 --------------------------------------------- -34 | @JSImport("bar.js") // error - | ^^^^^^^^^^^^^^^^^^^ - | Native JS definitions named 'apply' must have an explicit name in @JSImport --- Error: tests/neg-scalajs/native-load-spec-need-explicit-name.scala:38:3 --------------------------------------------- -38 | @JSImport("bar.js") // error - | ^^^^^^^^^^^^^^^^^^^ - | Native JS definitions with a name ending in '_=' must have an explicit name in @JSImport --- Error: tests/neg-scalajs/native-load-spec-need-explicit-name.scala:44:3 --------------------------------------------- -44 | @JSImport("bar.js") // error - | ^^^^^^^^^^^^^^^^^^^ - | Native JS definitions with a name ending in '_=' must have an explicit name in @JSImport --- Error: tests/neg-scalajs/native-load-spec-need-explicit-name.scala:43:2 --------------------------------------------- -43 | @js.native // error - | ^^^^^^^^^^ - | @js.native is not allowed on vars, lazy vals and setter defs --- Error: tests/neg-scalajs/native-load-spec-need-explicit-name.scala:48:3 --------------------------------------------- -48 | @JSImport("bar.js") // error - | ^^^^^^^^^^^^^^^^^^^ - | Native JS definitions named 'apply' must have an explicit name in @JSImport + | Native JS members inside non-native objects must have an explicit name in @JSGlobal diff --git a/tests/neg-scalajs/native-load-spec-need-explicit-name.scala b/tests/neg-scalajs/native-load-spec-need-explicit-name.scala index 7235fa4e7a36..fc08d414dd63 100644 --- a/tests/neg-scalajs/native-load-spec-need-explicit-name.scala +++ b/tests/neg-scalajs/native-load-spec-need-explicit-name.scala @@ -1,52 +1,14 @@ import scala.scalajs.js import scala.scalajs.js.annotation.* -object A1 { +object A { @js.native @JSGlobal // error - class apply extends js.Object + class B extends js.Object @js.native @JSGlobal // error - object apply extends js.Object - - @js.native - @JSGlobal // error - class foo_= extends js.Object -} - -object A2 { - @js.native // error - @JSGlobal // error - def foo_=(x: Int): Unit = js.native - - @js.native - @JSGlobal // error - def apply(x: Int): Int = js.native -} - -object B1 { - @js.native - @JSImport("bar.js") // error - class apply extends js.Object - - @js.native - @JSImport("bar.js") // error - object apply extends js.Object - - @js.native - @JSImport("bar.js") // error - class foo_= extends js.Object -} - -object B2 { - @js.native // error - @JSImport("bar.js") // error - def foo_=(x: Int): Unit = js.native - - @js.native - @JSImport("bar.js") // error - def apply(x: Int): Int = js.native + object C extends js.Object } // scala-js#2401