Skip to content

Commit

Permalink
Correct bug in componentOf[] macro
Browse files Browse the repository at this point in the history
  • Loading branch information
jokade committed Mar 31, 2016
1 parent d36fb4d commit bda6e21
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions src/main/scala/biz/enef/angulate/Component.scala
Expand Up @@ -41,10 +41,10 @@ object Component {
def componentOf[T: c.WeakTypeTag] = {
val ct = weakTypeOf[T]
val module = Select(c.prefix.tree, TermName("self"))

val comp = TermName(ct.typeSymbol.fullName)
val comp = ct.typeSymbol.companion

val tree = q"""$module.component($comp.selector,$comp.options)"""

tree
}

Expand All @@ -70,16 +70,16 @@ object Component {
val args = paramNames(params)
val diNames = args map ( _.toString )

// @scalajs.js.annotation.JSExport($fullName)
// @scalajs.js.annotation.JSExport($objName)
val tree =
q"""{
@scalajs.js.annotation.JSExport($fullName)
@scalajs.js.annotation.ScalaJSDefined
class $name ( ..$params ) extends ..$base { ..$body }
@scalajs.js.annotation.JSExport($objName)
@scalajs.js.annotation.ScalaJSDefined
object ${name.toTermName} extends scalajs.js.Object {
def selector = "test"
def controller = js.Array(..$diNames,((..$params) => new $name(..$args)):js.Function)
def controller = scalajs.js.Array(..$diNames,((..$params) => new $name(..$args)):scalajs.js.Function)
def options = scalajs.js.Dictionary( "controller" -> controller, ..$annots )
}
}
Expand All @@ -89,19 +89,5 @@ object Component {
c.Expr[Any](tree)
}

// TODO: simpler, use generic function instead of local copy :)
def getDINames(params: Iterable[Tree]): Iterable[String] =
if(params.isEmpty) None
else
params map {
case q"$mods val $name: $tpe = $e" =>
val t = c.typecheck(tpe,c.TYPEmode).tpe
t.typeSymbol.annotations.map(_.tree).collectFirst{
case q"new $name( ..$params )" if name.toString == "scala.scalajs.js.annotation.JSName" => params.head match {
case Literal(Constant(x)) => x.toString
}
}.getOrElse(t.toString)
}

}
}

0 comments on commit bda6e21

Please sign in to comment.