Skip to content

Commit a007b99

Browse files
authored
Merge pull request #739 from japgolly/topic/elidableVdom
Add VdomAttr.elidable
2 parents 38cb838 + 226a757 commit a007b99

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

bin/test-elision

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ case $# in
88
COMP_NAMES_ARE_ELIDABLE
99
DEVONLY
1010
ELIDABLE_AUTO_COMPONENT_NAME
11+
ELIDABLE_VDOM_ATTR
1112
REUSABILITY_OVERRIDE_TEST
1213
)
1314
for t in "${terms[@]}"; do

core/src/main/scala/japgolly/scalajs/react/vdom/Attr.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package japgolly.scalajs.react.vdom
22

33
import org.scalajs.dom
4-
import scala.annotation.{implicitNotFound, nowarn}
4+
import scala.annotation.{elidable, implicitNotFound, nowarn}
55
import scala.scalajs.LinkingInfo.developmentMode
66
import scala.scalajs.js
77
import japgolly.scalajs.react.internal.OptionLike
@@ -52,6 +52,16 @@ object Attr {
5252
else
5353
Dud
5454

55+
def elidable[A](name: => String): Attr[A] = {
56+
@elidable(scala.annotation.elidable.FINEST)
57+
def attempt: Attr[A] = new Generic(name)
58+
val x = attempt
59+
if (x eq null)
60+
Dud
61+
else
62+
x
63+
}
64+
5565
class Generic[-U](attrName: String) extends Attr[U](attrName) {
5666
override def :=[A](a: A)(implicit t: ValueType[A, U]): TagMod =
5767
t(attrName, a)

doc/changelog/1.7.2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# 1.7.2
22

33
* Fix: no longer generate warnings when `-Wunused:nowarn` is enabled
4+
* Add `VdomAttr.elidable` which allows you to elide VDOM attributes with `scalacOptions`

test/src/test/scala/japgolly/scalajs/react/ElisionTest.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@ object ElisionTest extends TestSuite {
2929
.build
3030
}
3131

32+
private val attr =
33+
VdomAttr.elidable("data-ELIDABLE_VDOM_ATTR")
34+
3235
override def tests = Tests {
3336
"normal" - s"[${Normal.raw.displayName}]"
3437
"static" - s"[${Static.raw.displayName}]"
38+
"attr" - ReactDOMServer.renderToStaticMarkup(<.div(attr := 1))
3539

3640
"reusabilityOverride" - {
3741
ScalaJsReactConfig.DevOnly.overrideReusability(reusabilityOverride)

0 commit comments

Comments
 (0)