Skip to content

Commit 1080f1b

Browse files
Merge pull request #14610 from dotty-staging/scalajs-1.9.0
Upgrade to Scala.js 1.9.0.
2 parents dfdd31a + cd7f528 commit 1080f1b

File tree

6 files changed

+119
-15
lines changed

6 files changed

+119
-15
lines changed

compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4563,7 +4563,14 @@ class JSCodeGen()(using genCtx: Context) {
45634563
val module = annot.argumentConstantString(0).getOrElse {
45644564
unexpected("could not read the module argument as a string literal")
45654565
}
4566-
val path = annot.argumentConstantString(1).fold[List[String]](Nil)(parsePath)
4566+
val path = annot.argumentConstantString(1).fold {
4567+
if (annot.arguments.sizeIs < 2)
4568+
parsePath(sym.defaultJSName)
4569+
else
4570+
Nil
4571+
} { pathName =>
4572+
parsePath(pathName)
4573+
}
45674574
val importSpec = Import(module, path)
45684575
annot.argumentConstantString(2).fold[js.JSNativeLoadSpec] {
45694576
importSpec

compiler/src/dotty/tools/dotc/transform/sjs/PrepJSInterop.scala

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import Contexts._
1414
import Decorators._
1515
import DenotTransformers._
1616
import Flags._
17-
import NameKinds.DefaultGetterName
17+
import NameKinds.{DefaultGetterName, ModuleClassName}
18+
import NameOps._
1819
import StdNames._
1920
import Symbols._
2021
import SymUtils._
@@ -559,9 +560,14 @@ class PrepJSInterop extends MacroTransform with IdentityDenotTransformer { thisP
559560
case Some(annot) if annot.symbol == jsdefn.JSGlobalAnnot =>
560561
checkJSGlobalLiteral(annot)
561562
val pathName = annot.argumentConstantString(0).getOrElse {
562-
if ((enclosingOwner is OwnerKind.ScalaMod) && !sym.owner.isPackageObject) {
563+
val symTermName = sym.name.exclude(NameKinds.ModuleClassName).toTermName
564+
if (symTermName == nme.apply) {
563565
report.error(
564-
"Native JS members inside non-native objects must have an explicit name in @JSGlobal",
566+
"Native JS definitions named 'apply' must have an explicit name in @JSGlobal",
567+
annot.tree)
568+
} else if (symTermName.isSetterName) {
569+
report.error(
570+
"Native JS definitions with a name ending in '_=' must have an explicit name in @JSGlobal",
565571
annot.tree)
566572
}
567573
sym.defaultJSName
@@ -570,6 +576,18 @@ class PrepJSInterop extends MacroTransform with IdentityDenotTransformer { thisP
570576

571577
case Some(annot) if annot.symbol == jsdefn.JSImportAnnot =>
572578
checkJSImportLiteral(annot)
579+
if (annot.arguments.sizeIs < 2) {
580+
val symTermName = sym.name.exclude(NameKinds.ModuleClassName).toTermName
581+
if (symTermName == nme.apply) {
582+
report.error(
583+
"Native JS definitions named 'apply' must have an explicit name in @JSImport",
584+
annot.tree)
585+
} else if (symTermName.isSetterName) {
586+
report.error(
587+
"Native JS definitions with a name ending in '_=' must have an explicit name in @JSImport",
588+
annot.tree)
589+
}
590+
}
573591
annot.argumentConstantString(2).foreach { globalPathName =>
574592
checkGlobalRefPath(globalPathName)
575593
}
@@ -1107,18 +1125,19 @@ object PrepJSInterop {
11071125
*/
11081126
private def checkJSImportLiteral(annot: Annotation)(using Context): Unit = {
11091127
val args = annot.arguments
1110-
assert(args.size == 2 || args.size == 3,
1111-
i"@JSImport annotation $annot does not have exactly 2 or 3 arguments")
1128+
val argCount = args.size
1129+
assert(argCount >= 1 && argCount <= 3,
1130+
i"@JSImport annotation $annot does not have between 1 and 3 arguments")
11121131

11131132
val firstArgIsValid = annot.argumentConstantString(0).isDefined
11141133
if (!firstArgIsValid)
11151134
report.error("The first argument to @JSImport must be a literal string.", args.head)
11161135

1117-
val secondArgIsValid = annot.argumentConstantString(1).isDefined || args(1).symbol == jsdefn.JSImportNamespaceModule
1136+
val secondArgIsValid = argCount < 2 || annot.argumentConstantString(1).isDefined || args(1).symbol == jsdefn.JSImportNamespaceModule
11181137
if (!secondArgIsValid)
11191138
report.error("The second argument to @JSImport must be literal string or the JSImport.Namespace object.", args(1))
11201139

1121-
val thirdArgIsValid = args.size < 3 || annot.argumentConstantString(2).isDefined
1140+
val thirdArgIsValid = argCount < 3 || annot.argumentConstantString(2).isDefined
11221141
if (!thirdArgIsValid)
11231142
report.error("The third argument to @JSImport, when present, must be a literal string.", args(2))
11241143
}

project/Build.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ object Build {
5959

6060
val referenceVersion = "3.1.2-RC1"
6161

62-
val baseVersion = "3.1.3-RC1"
62+
val baseVersion = "3.2.0-RC1"
6363

6464
// Versions used by the vscode extension to create a new project
6565
// This should be the latest published releases.

project/plugins.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// e.g. addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.1.0")
44

5-
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.7.1")
5+
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.9.0")
66

77
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.10")
88

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,48 @@
11
-- Error: tests/neg-scalajs/native-load-spec-need-explicit-name.scala:6:2 ----------------------------------------------
22
6 | @JSGlobal // error
33
| ^^^^^^^^^
4-
| Native JS members inside non-native objects must have an explicit name in @JSGlobal
4+
| Native JS definitions named 'apply' must have an explicit name in @JSGlobal
55
-- Error: tests/neg-scalajs/native-load-spec-need-explicit-name.scala:10:2 ---------------------------------------------
66
10 | @JSGlobal // error
77
| ^^^^^^^^^
8-
| Native JS members inside non-native objects must have an explicit name in @JSGlobal
8+
| Native JS definitions named 'apply' must have an explicit name in @JSGlobal
9+
-- Error: tests/neg-scalajs/native-load-spec-need-explicit-name.scala:14:2 ---------------------------------------------
10+
14 | @JSGlobal // error
11+
| ^^^^^^^^^
12+
| Native JS definitions with a name ending in '_=' must have an explicit name in @JSGlobal
13+
-- Error: tests/neg-scalajs/native-load-spec-need-explicit-name.scala:20:2 ---------------------------------------------
14+
20 | @JSGlobal // error
15+
| ^^^^^^^^^
16+
| Native JS definitions with a name ending in '_=' must have an explicit name in @JSGlobal
17+
-- Error: tests/neg-scalajs/native-load-spec-need-explicit-name.scala:19:2 ---------------------------------------------
18+
19 | @js.native // error
19+
| ^^^^^^^^^^
20+
| @js.native is not allowed on vars, lazy vals and setter defs
21+
-- Error: tests/neg-scalajs/native-load-spec-need-explicit-name.scala:24:2 ---------------------------------------------
22+
24 | @JSGlobal // error
23+
| ^^^^^^^^^
24+
| Native JS definitions named 'apply' must have an explicit name in @JSGlobal
25+
-- Error: tests/neg-scalajs/native-load-spec-need-explicit-name.scala:30:3 ---------------------------------------------
26+
30 | @JSImport("bar.js") // error
27+
| ^^^^^^^^^^^^^^^^^^^
28+
| Native JS definitions named 'apply' must have an explicit name in @JSImport
29+
-- Error: tests/neg-scalajs/native-load-spec-need-explicit-name.scala:34:3 ---------------------------------------------
30+
34 | @JSImport("bar.js") // error
31+
| ^^^^^^^^^^^^^^^^^^^
32+
| Native JS definitions named 'apply' must have an explicit name in @JSImport
33+
-- Error: tests/neg-scalajs/native-load-spec-need-explicit-name.scala:38:3 ---------------------------------------------
34+
38 | @JSImport("bar.js") // error
35+
| ^^^^^^^^^^^^^^^^^^^
36+
| Native JS definitions with a name ending in '_=' must have an explicit name in @JSImport
37+
-- Error: tests/neg-scalajs/native-load-spec-need-explicit-name.scala:44:3 ---------------------------------------------
38+
44 | @JSImport("bar.js") // error
39+
| ^^^^^^^^^^^^^^^^^^^
40+
| Native JS definitions with a name ending in '_=' must have an explicit name in @JSImport
41+
-- Error: tests/neg-scalajs/native-load-spec-need-explicit-name.scala:43:2 ---------------------------------------------
42+
43 | @js.native // error
43+
| ^^^^^^^^^^
44+
| @js.native is not allowed on vars, lazy vals and setter defs
45+
-- Error: tests/neg-scalajs/native-load-spec-need-explicit-name.scala:48:3 ---------------------------------------------
46+
48 | @JSImport("bar.js") // error
47+
| ^^^^^^^^^^^^^^^^^^^
48+
| Native JS definitions named 'apply' must have an explicit name in @JSImport

tests/neg-scalajs/native-load-spec-need-explicit-name.scala

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,52 @@
11
import scala.scalajs.js
22
import scala.scalajs.js.annotation.*
33

4-
object A {
4+
object A1 {
55
@js.native
66
@JSGlobal // error
7-
class B extends js.Object
7+
class apply extends js.Object
88

99
@js.native
1010
@JSGlobal // error
11-
object C extends js.Object
11+
object apply extends js.Object
12+
13+
@js.native
14+
@JSGlobal // error
15+
class foo_= extends js.Object
16+
}
17+
18+
object A2 {
19+
@js.native // error
20+
@JSGlobal // error
21+
def foo_=(x: Int): Unit = js.native
22+
23+
@js.native
24+
@JSGlobal // error
25+
def apply(x: Int): Int = js.native
26+
}
27+
28+
object B1 {
29+
@js.native
30+
@JSImport("bar.js") // error
31+
class apply extends js.Object
32+
33+
@js.native
34+
@JSImport("bar.js") // error
35+
object apply extends js.Object
36+
37+
@js.native
38+
@JSImport("bar.js") // error
39+
class foo_= extends js.Object
40+
}
41+
42+
object B2 {
43+
@js.native // error
44+
@JSImport("bar.js") // error
45+
def foo_=(x: Int): Unit = js.native
46+
47+
@js.native
48+
@JSImport("bar.js") // error
49+
def apply(x: Int): Int = js.native
1250
}
1351

1452
// scala-js#2401

0 commit comments

Comments
 (0)