Skip to content

Commit

Permalink
Fix scala-js#2442: Deprecated @JSExportNamed.
Browse files Browse the repository at this point in the history
  • Loading branch information
sjrd committed Jul 6, 2016
1 parent b613a8a commit 1749acb
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import org.junit.Test

class JSExportTest extends DirectTest with TestHelpers {

override def extraArgs: List[String] =
super.extraArgs :+ "-deprecation"

override def preamble: String =
"""import scala.scalajs.js, js.annotation._
"""
Expand Down Expand Up @@ -783,6 +786,26 @@ class JSExportTest extends DirectTest with TestHelpers {

}

@Test
def namedExportIsDeprecated: Unit = {

"""
class A {
@JSExportNamed
def foo(x: Int, y: Int) = 1
}
""" hasWarns
"""
|newSource1.scala:5: warning: class JSExportNamed in package annotation is deprecated: Use @JSExport with an explicit option bag instead. See the Scaladoc for more details.
| def foo(x: Int, y: Int) = 1
| ^
|newSource1.scala:4: warning: class JSExportNamed in package annotation is deprecated: Use @JSExport with an explicit option bag instead. See the Scaladoc for more details.
| @JSExportNamed
| ^
"""

}

@Test
def noOverrideNamedExport: Unit = {

Expand All @@ -798,10 +821,19 @@ class JSExportTest extends DirectTest with TestHelpers {
}
""" hasErrors
"""
|newSource1.scala:5: warning: class JSExportNamed in package annotation is deprecated: Use @JSExport with an explicit option bag instead. See the Scaladoc for more details.
| def foo(x: Int, y: Int) = 1
| ^
|newSource1.scala:4: warning: class JSExportNamed in package annotation is deprecated: Use @JSExport with an explicit option bag instead. See the Scaladoc for more details.
| @JSExportNamed
| ^
|newSource1.scala:9: error: overriding method $js$exported$meth$foo in class A of type (namedArgs: Any)Any;
| method $js$exported$meth$foo cannot override final member
| @JSExportNamed
| ^
|newSource1.scala:10: warning: class JSExportNamed in package annotation is deprecated: Use @JSExport with an explicit option bag instead. See the Scaladoc for more details.
| override def foo(x: Int, y: Int) = 2
| ^
"""

}
Expand Down Expand Up @@ -882,6 +914,12 @@ class JSExportTest extends DirectTest with TestHelpers {
}
""" hasErrors
"""
|newSource1.scala:5: warning: class JSExportNamed in package annotation is deprecated: Use @JSExport with an explicit option bag instead. See the Scaladoc for more details.
| def foo(a: Int*) = 1
| ^
|newSource1.scala:4: warning: class JSExportNamed in package annotation is deprecated: Use @JSExport with an explicit option bag instead. See the Scaladoc for more details.
| @JSExportNamed
| ^
|newSource1.scala:4: error: You may not name-export a method with a *-parameter
| @JSExportNamed
| ^
Expand Down Expand Up @@ -1021,6 +1059,12 @@ class JSExportTest extends DirectTest with TestHelpers {
|newSource1.scala:7: warning: Member cannot be exported to function application. It is available under the name apply instead. Add @JSExport("apply") to silence this warning. This will be enforced in 1.0.
| def apply(): Int = 1
| ^
|newSource1.scala:7: warning: class JSExportNamed in package annotation is deprecated: Use @JSExport with an explicit option bag instead. See the Scaladoc for more details.
| def apply(): Int = 1
| ^
|newSource1.scala:5: warning: class JSExportNamed in package annotation is deprecated: Use @JSExport with an explicit option bag instead. See the Scaladoc for more details.
| @JSExportNamed("apply")
| ^
"""

"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,45 @@ package scala.scalajs.js.annotation
* def a(bar: String) = "Hello " + bar
* }
* }}}
*
* As of Scala.js 0.6.11, `@JSExportNamed` is deprecated without direct
* replacement (see [[https://github.com/scala-js/scala-js/issues/2442]]).
* You should take a single parameter of a JS type and decompose it yourself.
* For example, instead of
* {{{
* class A {
* @JSExportNamed
* def foo(a: Int, b: String, c: Boolean = false): Unit = {
* // do something with a, b, c
* }
* }
* }}}
* you should write:
* {{{
* @ScalaJSDefined
* trait FooOptions extends js.Object {
* val a: Int
* val b: String
* val c: js.UndefOr[Boolean]
* }
*
* class A {
* @JSExport
* def foo(options: FooOptions): Unit = {
* val a = options.a
* val b = options.b
* val c = options.c.getOrElse(false)
* // do something with a, b, c
* }
* }
* }}}
*
* @see [[http://www.scala-js.org/doc/export-to-javascript.html Export Scala.js APIs to JavaScript]]
*/
@deprecated(
"Use @JSExport with an explicit option bag instead. " +
"See the Scaladoc for more details.",
"0.6.11")
class JSExportNamed extends scala.annotation.StaticAnnotation {
def this(name: String) = this()
}

0 comments on commit 1749acb

Please sign in to comment.