diff --git a/bin/test-elision b/bin/test-elision index 527f50b51..7364561b3 100755 --- a/bin/test-elision +++ b/bin/test-elision @@ -8,6 +8,7 @@ case $# in COMP_NAMES_ARE_ELIDABLE DEVONLY ELIDABLE_AUTO_COMPONENT_NAME + ELIDABLE_VDOM_ATTR REUSABILITY_OVERRIDE_TEST ) for t in "${terms[@]}"; do diff --git a/core/src/main/scala/japgolly/scalajs/react/vdom/Attr.scala b/core/src/main/scala/japgolly/scalajs/react/vdom/Attr.scala index 0901d5336..d05a46f99 100644 --- a/core/src/main/scala/japgolly/scalajs/react/vdom/Attr.scala +++ b/core/src/main/scala/japgolly/scalajs/react/vdom/Attr.scala @@ -1,7 +1,7 @@ package japgolly.scalajs.react.vdom import org.scalajs.dom -import scala.annotation.{implicitNotFound, nowarn} +import scala.annotation.{elidable, implicitNotFound, nowarn} import scala.scalajs.LinkingInfo.developmentMode import scala.scalajs.js import japgolly.scalajs.react.internal.OptionLike @@ -52,6 +52,16 @@ object Attr { else Dud + def elidable[A](name: => String): Attr[A] = { + @elidable(scala.annotation.elidable.FINEST) + def attempt: Attr[A] = new Generic(name) + val x = attempt + if (x eq null) + Dud + else + x + } + class Generic[-U](attrName: String) extends Attr[U](attrName) { override def :=[A](a: A)(implicit t: ValueType[A, U]): TagMod = t(attrName, a) diff --git a/doc/changelog/1.7.2.md b/doc/changelog/1.7.2.md index f04be589d..15faab2d6 100644 --- a/doc/changelog/1.7.2.md +++ b/doc/changelog/1.7.2.md @@ -1,3 +1,4 @@ # 1.7.2 * Fix: no longer generate warnings when `-Wunused:nowarn` is enabled +* Add `VdomAttr.elidable` which allows you to elide VDOM attributes with `scalacOptions` diff --git a/test/src/test/scala/japgolly/scalajs/react/ElisionTest.scala b/test/src/test/scala/japgolly/scalajs/react/ElisionTest.scala index 335ad81a4..ace9d75a3 100644 --- a/test/src/test/scala/japgolly/scalajs/react/ElisionTest.scala +++ b/test/src/test/scala/japgolly/scalajs/react/ElisionTest.scala @@ -29,9 +29,13 @@ object ElisionTest extends TestSuite { .build } + private val attr = + VdomAttr.elidable("data-ELIDABLE_VDOM_ATTR") + override def tests = Tests { "normal" - s"[${Normal.raw.displayName}]" "static" - s"[${Static.raw.displayName}]" + "attr" - ReactDOMServer.renderToStaticMarkup(<.div(attr := 1)) "reusabilityOverride" - { ScalaJsReactConfig.DevOnly.overrideReusability(reusabilityOverride)