diff --git a/build.sbt b/build.sbt index d0642fe..4be24ee 100644 --- a/build.sbt +++ b/build.sbt @@ -1,19 +1,16 @@ -val sjsxVersion = "0.3.0-SNAPSHOT" +val smacrotoolsVersion = "0.0.1" +val sjsxVersion = "0.3.0" +val rxjsVersion = "0.0.1" lazy val commonSettings = Seq( organization := "de.surfice", - version := "0.0.1-SNAPSHOT", + version := "0.0.1", scalaVersion := "2.11.8", scalacOptions ++= Seq("-deprecation","-unchecked","-feature","-language:implicitConversions","-Xlint"), autoCompilerPlugins := true, //addCompilerPlugin("com.lihaoyi" %% "acyclic" % "0.1.2"), resolvers += Resolver.sonatypeRepo("releases"), - resolvers += Resolver.sonatypeRepo("snapshots"), - scalacOptions ++= (if (isSnapshot.value) Seq.empty else Seq({ - val a = baseDirectory.value.toURI.toString.replaceFirst("[^/]+/?$", "") - val g = "https://raw.githubusercontent.com/jokade/angulate2" - s"-P:scalajs:mapSourceURI:$a->$g/v${version.value}/" - })) + resolvers += Resolver.sonatypeRepo("snapshots") ) @@ -28,11 +25,17 @@ lazy val angulate2 = project.in(file(".")). libraryDependencies ++= Seq( "org.scala-lang" % "scala-reflect" % scalaVersion.value, "org.scala-js" %%% "scalajs-dom" % "0.8.0", - "de.surfice" %%% "smacrotools-sjs" % "0.1-SNAPSHOT", + "de.surfice" %%% "smacrotools-sjs" % smacrotoolsVersion, "de.surfice" %%% "sjsx" % sjsxVersion, - "de.surfice" %%% "scalajs-rxjs" % "0.0.1-SNAPSHOT" + "de.surfice" %%% "scalajs-rxjs_cjsm" % rxjsVersion //"be.doeraene" %%% "scalajs-jquery" % "0.8.0" % "provided", - ) + ), + crossScalaVersions := Seq("2.11.8","2.12.0"), + scalacOptions ++= (if (isSnapshot.value) Seq.empty else Seq({ + val a = baseDirectory.value.toURI.toString.replaceFirst("[^/]+/?$", "") + val g = "https://raw.githubusercontent.com/jokade/angulate2" + s"-P:scalajs:mapSourceURI:$a->$g/v${version.value}/" + })) ) @@ -59,7 +62,8 @@ lazy val stubs = project .settings(commonSettings:_*) .settings(publishingSettings:_*) .settings( - name := "angulate2-stubs" + name := "angulate2-stubs", + crossScalaVersions := Seq("2.11.8","2.12.0") ) //lazy val tests = project. @@ -118,8 +122,4 @@ lazy val publishingSettings = Seq( ) ) -lazy val angulateDebugFlags = Seq( - "Directive" -).map( f => s"-Xmacro-settings:angulate2.debug.$f" ) - diff --git a/project/plugins.sbt b/project/plugins.sbt index bfdab78..d737ac9 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1 +1,5 @@ addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.13") + +addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "1.1") + +addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0") diff --git a/src/main/scala/angulate2/Component.scala b/src/main/scala/angulate2/Component.scala deleted file mode 100644 index 070516e..0000000 --- a/src/main/scala/angulate2/Component.scala +++ /dev/null @@ -1,192 +0,0 @@ -// Project: angulate2 (https://github.com/jokade/angulate2) -// Description: Angular2 @Component macro annotation - -// Copyright (c) 2015, 2016 Johannes.Kastner -// Distributed under the MIT License (see included LICENSE file) -package angulate2 - -import angulate2.internal.DecoratedClass - -import scala.annotation.{StaticAnnotation, compileTimeOnly} -import scala.collection.immutable.Iterable -import scala.language.experimental.macros -import scala.reflect.macros.whitebox -import scala.scalajs.js - -// NOTE: keep the constructor parameter list and Component.Macro.annotationParamNames in sync! -@compileTimeOnly("enable macro paradise to expand macro annotations") -class Component(selector: String = null, - inputs: js.Array[String] = null, - outputs: js.Array[String] = null, - host: js.Any = null, - exportAs: String = null, - moduleId: js.Any = null, - providers: js.Array[js.Any] = null, - viewProviders: js.Array[js.Any] = null, - changeDetection: js.Any = null, - queries: js.Any = null, - templateUrl: String = null, - template: String = null, - styles: js.Array[String] = null, - styleUrls: js.Array[String] = null, - animations: js.Array[js.Any] = null, - encapsulation: js.Any = null, - interpolation: js.Any = null, - entryComponents: js.Array[js.Any] = null) extends StaticAnnotation { - def macroTransform(annottees: Any*): Any = macro Component.Macro.impl -} - -object Component { - private[angulate2] class Macro(val c: whitebox.Context) extends DecoratedClass { - import c.universe._ - - override def mainAnnotation: String = "Component" - - // IMPORTANT: this list must contain all annotation arguments in the SAME order they are - // defined in the annotations constructor! - override def annotationParamNames: Seq[String] = Seq( - "selector", - "inputs", - "outputs", - "host", - "exportAs", - "moduleId", - "providers", - "viewProviders", - "changeDetection", - "queries", - "templateUrl", - "template", - "styles", - "styleUrls", - "animations", - "encapsulation", - "interpolation", - "entryComponents" - ) - - override def mainAnnotationObject: c.universe.Tree = q"angulate2.core.Component" - - object InputAnnot { - def unapply(annotations: Seq[Tree]): Option[Option[Tree]] = findAnnotation(annotations,"Input") - .map( t => extractAnnotationParameters(t,Seq("externalName")).apply("externalName") ) - def unapply(modifiers: Modifiers): Option[Option[Tree]] = unapply(modifiers.annotations) - } - - override def decoratorParameters(parts: ClassParts, annotationParamNames: Seq[String]) = { - import parts._ - - val inputStrLiterals = body collect { - case ValDef(InputAnnot(externalName),term,_,_) => externalName.flatMap(extractStringConstant).getOrElse(term.toString) - } - val (nonInputAnnotationParams, inputAnnotationParams) = super.decoratorParameters(parts,annotationParamNames).partition { - case q"inputs = $v" => false - case _ => true - } - val inputs = inputAnnotationParams match { - case q"inputs = $call(..$ins)" :: Nil => - q"inputs = scalajs.js.Array(..${ins ++ inputStrLiterals.map(s => Literal(Constant(s)))})" - case _ => - q"inputs = scalajs.js.Array(..$inputStrLiterals)" - } - - Iterable(inputs) ++ nonInputAnnotationParams - } - - } -// -// private[angulate2] class Macro(val c: whitebox.Context) extends JsWhiteboxMacroTools { -// import c.universe._ -// -// val annotationParamNames = Seq( -// "selector", -// "inputs", -// "outputs", -// "providers", -// "template", -// "templateUrl", -// "directives", -// "styles", -// "styleUrls") -// -// object InputAnnot { -// def unapply(annotations: Seq[Tree]): Option[Option[Tree]] = findAnnotation(annotations,"Input") -// .map( t => extractAnnotationParameters(t,Seq("externalName")).apply("externalName") ) -// def unapply(modifiers: Modifiers): Option[Option[Tree]] = unapply(modifiers.annotations) -// } -// -// def impl(annottees: c.Expr[Any]*) : c.Expr[Any] = annottees.map(_.tree).toList match { -// case (classDecl: ClassDef) :: Nil => modifiedDeclaration(classDecl) -// case _ => c.abort(c.enclosingPosition, "Invalid annottee for @Component") -// } -// -// def modifiedDeclaration(classDecl: ClassDef) = { -// val parts = extractClassParts(classDecl) -// -// import parts._ -// -// // load debug annotation values (returns default config, if there is no @debug on this component) -// val debug = getDebugConfig(modifiers) -// -// val inputStrLiterals = body collect { -// case ValDef(InputAnnot(externalName),term,_,_) => externalName.flatMap(extractStringConstant).getOrElse(term.toString) -// } -// -// val objName = fullName + "_" -// val allComponentAnnotationParams = extractAnnotationParameters(c.prefix.tree, annotationParamNames).collect { -// case (name,Some(value)) => q"${Ident(TermName(name))} = $value" -// } -// -// val (nonInputAnnotationParams, inputAnnotationParams) = allComponentAnnotationParams.partition { -// case q"inputs = $v" => false -// case _ => true -// } -// -// val inputs = inputAnnotationParams match { -// case q"inputs = $call(..$ins)" :: Nil => -// q"inputs = scalajs.js.Array(..${ins ++ inputStrLiterals.map(s => Literal(Constant(s)))})" -// case _ => -// q"inputs = scalajs.js.Array(..$inputStrLiterals)" -// } -// -// val componentAnnotationParams = Iterable(inputs) ++ nonInputAnnotationParams -// -//// val parameterAnnot = parameterAnnotation(fullName,params) -// val diTypes = getDINames(params) map ("$s."+_) -// val metadata = s"""__metadata('design:paramtypes',[${diTypes.mkString(",")}])""" -// -// // string to be written to the annotations.js file -// val decoration = s"$$s.$fullName = __annotate($$s.$objName().decorators,$metadata,$$s.$fullName);" -// -// // list of trees to be included in the component's annotation array -// val annotations = -// q"angulate2.core.Component( scalajs.js.Dynamic.literal( ..$componentAnnotationParams ))" // +: translateAngulateAnnotations(modifiers) -// -// val base = getJSBaseClass(parents) -// val log = -// if(debug.logInstances) { -// val msg = s"created Component $fullName:" -// q"""scalajs.js.Dynamic.global.console.debug($msg,this)""" -// } -// else q"" -// -// val tree = -// q"""{@scalajs.js.annotation.JSExport($fullName) -// @scalajs.js.annotation.ScalaJSDefined -// @sjsx.SJSXStatic(1000, $decoration ) -// class $name ( ..$params ) extends ..$base { ..$body; $log } -// @scalajs.js.annotation.JSExport($objName) -// @scalajs.js.annotation.ScalaJSDefined -// object ${name.toTermName} extends scalajs.js.Object { -// val decorators = scalajs.js.Array( ..$annotations ) -// } -// } -// """ -// -// if(debug.showExpansion) printTree(tree) -// -// c.Expr[Any](tree) -// } -// -// } -} diff --git a/src/main/scala/angulate2/Directive.scala b/src/main/scala/angulate2/Directive.scala deleted file mode 100644 index 96f0951..0000000 --- a/src/main/scala/angulate2/Directive.scala +++ /dev/null @@ -1,109 +0,0 @@ -// Project: angulate2 (https://github.com/jokade/angulate2) -// Description: Angular2 @Directive macro annotation - -// Copyright (c) 2015 Johannes.Kastner -// Distributed under the MIT License (see included LICENSE file) -package angulate2 - -import angulate2.internal.JsWhiteboxMacroTools - -import scala.annotation.{StaticAnnotation, compileTimeOnly} -import scala.language.experimental.macros -import scala.reflect.macros.whitebox -import scala.scalajs.js - -// NOTE: keep the constructor parameter list and Directive.Macro.annotationParamNames in sync! -@compileTimeOnly("enable macro paradise to expand macro annotations") -class Directive(selector: String, - template: String = null, - directives: js.Array[js.Any] = null, - appInjector: js.Array[js.Any] = null) extends StaticAnnotation { - def macroTransform(annottees: Any*): Any = macro Directive.Macro.impl -} - - -object Directive { - - private[angulate2] class Macro(val c: whitebox.Context) extends JsWhiteboxMacroTools { - - import c.universe._ - - lazy val debug = isSet("angulate2.debug.Directive") - - val annotationParamNames = - Seq("selector") - - def impl(annottees: c.Expr[Any]*): c.Expr[Any] = annottees.map(_.tree).toList match { - case (classDecl: ClassDef) :: Nil => modifiedDeclaration(classDecl) - case _ => c.abort(c.enclosingPosition, "Invalid annottee for @Directive") - } - - - def modifiedDeclaration(classDecl: ClassDef) = { - val parts = extractClassParts(classDecl) - import parts._ - - val annots = annotations( extractAnnotationParameters(c.prefix.tree,annotationParamNames) ) - - // we use this dummy class only for type checking, so that we can access the types of the constructor parameters - val cl = (q"""class $name ( ..$params )""").duplicate - val diTypes = constructorDI(cl) - - val objName = fullName+"_" - - val jsAnnot = s"$fullName.annotations = $objName().annotations(); $fullName.parameters = $objName().parameters();" - //val jsAnnot = s"$fullName.annotations = $objName().annotations();" - - val tree = - q"""{@scalajs.js.annotation.JSExport($fullName) - @scalajs.js.annotation.JSExportAll - @de.surfice.sjsannots.SJSAnnotation(1000,$jsAnnot) - class $name ( ..$params ) extends ..$parents { ..$body } - @scalajs.js.annotation.JSExport($objName) - object ${name.toTermName} { - import angulate2.annotations._ - @scalajs.js.annotation.JSExport - def annotations() = $annots - @scalajs.js.annotation.JSExport - def parameters() = $diTypes - } - }""" - - if(debug) printTree(tree) - - c.Expr[Any](tree) - } - - - def annotations(params: Map[String,Option[Tree]]) = { - val groups = params.collect { - case ("appInjector",Some(rhs)) => ("injectables",c.typecheck(rhs)) - case (name, Some(rhs)) => (name, rhs) - }.groupBy { - case ("selector", _) => "DirectiveAnnotation" - case ("template"|"directives", _) => "ViewAnnotation" - case _ => ??? - }.map{ - case (atype,m) => - val annot = TermName(atype) - val params = m.toList.map( p => q"${TermName(p._1)} = ${p._2}") - q"$annot( ..$params )" - } - - q"scalajs.js.Array( ..$groups )" - } - - - def constructorDI(classDecl: Tree) = { - val paramTypes = c.typecheck(classDecl) match { - case q"class $_ ( ..$params )" => params.map { - case q"$_ val $_: $tpe" => q"scalajs.js.Array(${selectGlobalDynamic(tpe.toString)})" - } - } - q"scalajs.js.Array( ..$paramTypes )" - } - - } - -} - diff --git a/src/main/scala/angulate2/Input.scala b/src/main/scala/angulate2/Input.scala deleted file mode 100644 index 2d83331..0000000 --- a/src/main/scala/angulate2/Input.scala +++ /dev/null @@ -1,7 +0,0 @@ -package angulate2 - -import scala.annotation.StaticAnnotation - -class Input() extends StaticAnnotation { - def this(externalName: String) = this() -} diff --git a/src/main/scala/angulate2/common/Location.scala b/src/main/scala/angulate2/common/Location.scala index 6b712ce..605051e 100644 --- a/src/main/scala/angulate2/common/Location.scala +++ b/src/main/scala/angulate2/common/Location.scala @@ -11,6 +11,15 @@ import scala.scalajs.js.annotation.JSImport @js.native @JSImport("@angular/common","Location") class Location extends js.Object { + def path(includeHash: js.UndefOr[Boolean] = js.undefined): String = js.native + def isCurrentPathEqualTo(path: String, query: js.UndefOr[String] = js.undefined): Boolean = js.native + def normalize(url: String): String = js.native + def prepareExternalUrl(url: String): String = js.native def back(): Unit = js.native def forward(): Unit = js.native + def go(path: String, query: String = ""): Unit = js.native + def replaceState(path: String, query: String = ""): Unit = js.native + def subscribe(onNext: js.Function1[js.Any,_], + onThrow: js.UndefOr[js.Function1[js.Any,_]] = js.undefined, + onReturn: js.UndefOr[js.Function0[_]] = js.undefined): js.Dynamic = js.native } diff --git a/src/main/scala/angulate2/core/Component.scala b/src/main/scala/angulate2/core/Component.scala new file mode 100644 index 0000000..0175868 --- /dev/null +++ b/src/main/scala/angulate2/core/Component.scala @@ -0,0 +1,105 @@ +// Project: angulate2 (https://github.com/jokade/angulate2) +// Description: Angular2 @Component macro annotation + +// Copyright (c) 2016 Johannes.Kastner +// Distributed under the MIT License (see included LICENSE file) +package angulate2.core + +import angulate2.internal.ClassDecorator + +import scala.annotation.{StaticAnnotation, compileTimeOnly} +import scala.collection.immutable.Iterable +import scala.language.experimental.macros +import scala.reflect.macros.whitebox +import scala.scalajs.js +import scala.scalajs.js.annotation.JSImport + +@js.native +@JSImport("@angular/core","Component") +object ComponentFacade extends js.Object { + def apply(options: js.Object) : js.Object = js.native +} + +// NOTE: keep the constructor parameter list and Component.Macro.annotationParamNames in sync! +@compileTimeOnly("enable macro paradise to expand macro annotations") +class Component(selector: String = null, + inputs: js.Array[String] = null, + outputs: js.Array[String] = null, + host: js.Any = null, + exportAs: String = null, + moduleId: js.Any = null, + providers: js.Array[js.Any] = null, + viewProviders: js.Array[js.Any] = null, + changeDetection: js.Any = null, + queries: js.Any = null, + templateUrl: String = null, + template: String = null, + styles: js.Array[String] = null, + styleUrls: js.Array[String] = null, + animations: js.Array[js.Any] = null, + encapsulation: js.Any = null, + interpolation: js.Any = null, + entryComponents: js.Array[js.Any] = null) extends StaticAnnotation { + def macroTransform(annottees: Any*): Any = macro Component.Macro.impl +} + +object Component { + private[angulate2] class Macro(val c: whitebox.Context) extends ClassDecorator { + import c.universe._ + + override def mainAnnotation: String = "Component" + + // IMPORTANT: this list must contain all annotation arguments in the SAME order they are + // defined in the annotations constructor! + override def annotationParamNames: Seq[String] = Seq( + "selector", + "inputs", + "outputs", + "host", + "exportAs", + "moduleId", + "providers", + "viewProviders", + "changeDetection", + "queries", + "templateUrl", + "template", + "styles", + "styleUrls", + "animations", + "encapsulation", + "interpolation", + "entryComponents" + ) + + override def mainAnnotationObject: c.universe.Tree = q"angulate2.core.ComponentFacade" + + object InputAnnot { + def unapply(annotations: Seq[Tree]): Option[Option[Tree]] = findAnnotation(annotations,"Input") + .map( t => extractAnnotationParameters(t,Seq("externalName")).apply("externalName") ) + def unapply(modifiers: Modifiers): Option[Option[Tree]] = unapply(modifiers.annotations) + } + + override def decoratorParameters(parts: ClassParts, annotationParamNames: Seq[String]) = { + import parts._ + + val inputStrLiterals = body collect { + case ValDef(InputAnnot(externalName),term,_,_) => externalName.flatMap(extractStringConstant).getOrElse(term.toString) + } + val (nonInputAnnotationParams, inputAnnotationParams) = super.decoratorParameters(parts,annotationParamNames).partition { + case q"inputs = $v" => false + case _ => true + } + val inputs = inputAnnotationParams match { + case q"inputs = $call(..$ins)" :: Nil => + q"inputs = scalajs.js.Array(..${ins ++ inputStrLiterals.map(s => Literal(Constant(s)))})" + case _ => + q"inputs = scalajs.js.Array(..$inputStrLiterals)" + } + + Iterable(inputs) ++ nonInputAnnotationParams + } + + } + +} diff --git a/src/main/scala/angulate2/core/Directive.scala b/src/main/scala/angulate2/core/Directive.scala new file mode 100644 index 0000000..83125d0 --- /dev/null +++ b/src/main/scala/angulate2/core/Directive.scala @@ -0,0 +1,57 @@ +// Project: angulate2 (https://github.com/jokade/angulate2) +// Description: Angular2 @Directive macro annotation + +// Copyright (c) 2016 Johannes.Kastner +// Distributed under the MIT License (see included LICENSE file) +package angulate2.core + +import angulate2.internal.{ClassDecorator, JsWhiteboxMacroTools} + +import scala.annotation.{StaticAnnotation, compileTimeOnly} +import scala.language.experimental.macros +import scala.reflect.macros.whitebox +import scala.scalajs.js +import scala.scalajs.js.annotation.JSImport + +@js.native +@JSImport("@angular/core","Directive") +object DirectiveFacade extends js.Object { + def apply(options: js.Object) : js.Object = js.native +} + +// NOTE: keep the constructor parameter list and Directive.Macro.annotationParamNames in sync! +@compileTimeOnly("enable macro paradise to expand macro annotations") +class Directive(selector: String = null, + inputs: js.Array[String] = null, + outputs: js.Array[String] = null, + host: js.Dictionary[String] = null, + template: String = null, + providers: js.Array[js.Any] = null, + exportAs: String = null, + queries: js.Any = null) extends StaticAnnotation { + def macroTransform(annottees: Any*): Any = macro Directive.Macro.impl +} + + +object Directive { + + private[angulate2] class Macro(val c: whitebox.Context) extends ClassDecorator { + import c.universe._ + + override def mainAnnotation: String = "Directive" + + override def mainAnnotationObject: c.universe.Tree = q"angulate2.core.DirectiveFacade" + + override def annotationParamNames: Seq[String] = Seq( + "selector", + "inputs", + "outputs", + "host", + "template", + "providers", + "exportAs", + "queries" + ) + } +} + diff --git a/src/main/scala/angulate2/Injectable.scala b/src/main/scala/angulate2/core/Injectable.scala similarity index 53% rename from src/main/scala/angulate2/Injectable.scala rename to src/main/scala/angulate2/core/Injectable.scala index 7a47278..ed2b8ee 100644 --- a/src/main/scala/angulate2/Injectable.scala +++ b/src/main/scala/angulate2/core/Injectable.scala @@ -1,16 +1,26 @@ // Project: angulate2 (https://github.com/jokade/angulate2) // Description: Angular2 @Injectable annotation. -// Copyright (c) 2015, 2016 Johannes.Kastner -// Distributed under the MIT License (see included file LICENSE) -package angulate2 +// Copyright (c) 2016 Johannes.Kastner +// Distributed under the MIT License (see included LICENSE file) +package angulate2.core -import angulate2.internal.{DecoratedClass, JsWhiteboxMacroTools} +import angulate2.internal.ClassDecorator -import scala.annotation.StaticAnnotation +import scala.annotation.{StaticAnnotation, compileTimeOnly} import scala.language.experimental.macros import scala.reflect.macros.whitebox +import scala.scalajs.js +import scala.scalajs.js.annotation.JSImport +@js.native +@JSImport("@angular/core","Injectable") +object InjectableFacade extends js.Object { + def apply() : js.Object = js.native +} + +// NOTE: keep the constructor parameter list and Injectable.Macro.annotationParamNames in sync! +@compileTimeOnly("enable macro paradise to expand macro annotations") class Injectable extends StaticAnnotation { def macroTransform(annottees: Any*): Any = macro Injectable.Macro.impl } @@ -18,12 +28,12 @@ class Injectable extends StaticAnnotation { object Injectable { - private[angulate2] class Macro(val c: whitebox.Context) extends DecoratedClass { + private[angulate2] class Macro(val c: whitebox.Context) extends ClassDecorator { import c.universe._ override val mainAnnotation: String = "Injectable" override val annotationParamNames: Seq[String] = Seq() - override def mainAnnotationObject = q"angulate2.core.Injectable" + override def mainAnnotationObject = q"angulate2.core.InjectableFacade" } } diff --git a/src/main/scala/angulate2/core/Input.scala b/src/main/scala/angulate2/core/Input.scala new file mode 100644 index 0000000..943a766 --- /dev/null +++ b/src/main/scala/angulate2/core/Input.scala @@ -0,0 +1,9 @@ +// Copyright (c) 2016 Johannes.Kastner +// Distributed under the MIT License (see included LICENSE file) +package angulate2.core + +import scala.annotation.StaticAnnotation + +class Input() extends StaticAnnotation { + def this(externalName: String) = this() +} diff --git a/src/main/scala/angulate2/NgModule.scala b/src/main/scala/angulate2/core/NgModule.scala similarity index 83% rename from src/main/scala/angulate2/NgModule.scala rename to src/main/scala/angulate2/core/NgModule.scala index 3597810..edb79cb 100644 --- a/src/main/scala/angulate2/NgModule.scala +++ b/src/main/scala/angulate2/core/NgModule.scala @@ -3,14 +3,21 @@ // Copyright (c) 2016 Johannes.Kastner // Distributed under the MIT License (see included LICENSE file) -package angulate2 +package angulate2.core -import angulate2.internal.{JSType, DecoratedClass, JsWhiteboxMacroTools} +import angulate2.internal.ClassDecorator import scala.annotation.{StaticAnnotation, compileTimeOnly} import scala.language.experimental.macros import scala.reflect.macros.whitebox import scala.scalajs.js +import scala.scalajs.js.annotation.JSImport + +@js.native +@JSImport("@angular/core","NgModule") +object NgModuleFacade extends js.Object { + def apply(options: js.Object) : js.Object = js.native +} // NOTE: keep the constructor parameter list and Component.Macro.annotationParamNames in sync! @compileTimeOnly("enable macro paradise to expand macro annotations") @@ -26,7 +33,7 @@ class NgModule(providers: js.Array[js.Any] = null, } object NgModule { - private[angulate2] class Macro(val c: whitebox.Context) extends DecoratedClass { + private[angulate2] class Macro(val c: whitebox.Context) extends ClassDecorator { import c.universe._ val annotationParamNames = Seq( @@ -42,7 +49,7 @@ object NgModule { override val mainAnnotation: String = "NgModule" - override def mainAnnotationObject = q"angulate2.core.NgModule" + override def mainAnnotationObject = q"angulate2.core.NgModuleFacade" } } diff --git a/src/main/scala/angulate2/core/annotations.scala b/src/main/scala/angulate2/core/annotations.scala deleted file mode 100644 index 2182682..0000000 --- a/src/main/scala/angulate2/core/annotations.scala +++ /dev/null @@ -1,31 +0,0 @@ -// Project: angulate2 (https://github.com/jokade/angulate2) -// Description: Façade traits for the Angular2 runtime core annotations - -// Copyright (c) 2016 Johannes.Kastner -// Distributed under the MIT License (see included LICENSE file) -package angulate2.core - -import scala.scalajs.js -import scala.scalajs.js.annotation.JSImport - -@js.native -@JSImport("@angular/core","NgModule") -object NgModule extends js.Object { - def apply(options: js.Object) : js.Object = js.native -} - -@js.native -@JSImport("@angular/core","Component") -object Component extends js.Object { - def apply(options: js.Object) : js.Object = js.native -} - -@js.native -@JSImport("@angular/core","Injectable") -object Injectable extends js.Object { - def apply() : js.Object = js.native -} - -@js.native -@JSImport("@angular/core","Directive") -class Directive(options: js.Object) extends js.Object \ No newline at end of file diff --git a/src/main/scala/angulate2/core/hooks.scala b/src/main/scala/angulate2/core/hooks.scala index 31d4ab5..61571c7 100644 --- a/src/main/scala/angulate2/core/hooks.scala +++ b/src/main/scala/angulate2/core/hooks.scala @@ -6,19 +6,20 @@ package angulate2.core import scala.scalajs.js +import scala.scalajs.js.annotation.ScalaJSDefined /** * Lifecycle hook that is called after data-bound properties of a directive are initialized. */ -@js.native +@ScalaJSDefined trait OnInit extends js.Object { - def ngOnInit(): Unit = js.native + def ngOnInit(): Unit } /** * Lifecycle hook that is called when a directive or pipe is destroyed. */ -@js.native +@ScalaJSDefined trait OnDestroy extends js.Object { def ngOnDestroy() : Unit } \ No newline at end of file diff --git a/src/main/scala/angulate2/Data.scala b/src/main/scala/angulate2/ext/Data.scala similarity index 99% rename from src/main/scala/angulate2/Data.scala rename to src/main/scala/angulate2/ext/Data.scala index 8fdb461..ffdcb1c 100644 --- a/src/main/scala/angulate2/Data.scala +++ b/src/main/scala/angulate2/ext/Data.scala @@ -3,7 +3,7 @@ // Copyright (c) 2016 Johannes.Kastner // Distributed under the MIT License (see included LICENSE file) -package angulate2 +package angulate2.ext import angulate2.internal.JsWhiteboxMacroTools diff --git a/src/main/scala/angulate2/debug.scala b/src/main/scala/angulate2/ext/debug.scala similarity index 97% rename from src/main/scala/angulate2/debug.scala rename to src/main/scala/angulate2/ext/debug.scala index 30ade6a..6037bac 100644 --- a/src/main/scala/angulate2/debug.scala +++ b/src/main/scala/angulate2/ext/debug.scala @@ -3,7 +3,7 @@ // Copyright (c) 2016 Johannes.Kastner // Distributed under the MIT License (see included LICENSE file) -package angulate2 +package angulate2.ext import scala.annotation.StaticAnnotation diff --git a/src/main/scala/angulate2/extra/inMemoryWebApi/InMemoryBackendConfigArgs.scala b/src/main/scala/angulate2/ext/inMemoryWebApi/InMemoryBackendConfigArgs.scala similarity index 95% rename from src/main/scala/angulate2/extra/inMemoryWebApi/InMemoryBackendConfigArgs.scala rename to src/main/scala/angulate2/ext/inMemoryWebApi/InMemoryBackendConfigArgs.scala index 3ae79b3..7080fb0 100644 --- a/src/main/scala/angulate2/extra/inMemoryWebApi/InMemoryBackendConfigArgs.scala +++ b/src/main/scala/angulate2/ext/inMemoryWebApi/InMemoryBackendConfigArgs.scala @@ -3,7 +3,7 @@ // Copyright (c) 2016 Johannes.Kastner // Distributed under the MIT License (see included LICENSE file) -package angulate2.extra.inMemoryWebApi +package angulate2.ext.inMemoryWebApi import de.surfice.smacrotools.JSOptionsObject diff --git a/src/main/scala/angulate2/extra/inMemoryWebApi/InMemoryDbService.scala b/src/main/scala/angulate2/ext/inMemoryWebApi/InMemoryDbService.scala similarity index 90% rename from src/main/scala/angulate2/extra/inMemoryWebApi/InMemoryDbService.scala rename to src/main/scala/angulate2/ext/inMemoryWebApi/InMemoryDbService.scala index 5bc7f89..41fe527 100644 --- a/src/main/scala/angulate2/extra/inMemoryWebApi/InMemoryDbService.scala +++ b/src/main/scala/angulate2/ext/inMemoryWebApi/InMemoryDbService.scala @@ -3,7 +3,7 @@ // Copyright (c) 2016 Johannes.Kastner // Distributed under the MIT License (see included LICENSE file) -package angulate2.extra.inMemoryWebApi +package angulate2.ext.inMemoryWebApi import scala.scalajs.js import scala.scalajs.js.annotation.ScalaJSDefined diff --git a/src/main/scala/angulate2/extra/inMemoryWebApi/InMemoryWebApiModule.scala b/src/main/scala/angulate2/ext/inMemoryWebApi/InMemoryWebApiModule.scala similarity index 94% rename from src/main/scala/angulate2/extra/inMemoryWebApi/InMemoryWebApiModule.scala rename to src/main/scala/angulate2/ext/inMemoryWebApi/InMemoryWebApiModule.scala index 605817e..3e91f92 100644 --- a/src/main/scala/angulate2/extra/inMemoryWebApi/InMemoryWebApiModule.scala +++ b/src/main/scala/angulate2/ext/inMemoryWebApi/InMemoryWebApiModule.scala @@ -3,7 +3,7 @@ // Copyright (c) 2016 Johannes.Kastner // Distributed under the MIT License (see included LICENSE file) -package angulate2.extra.inMemoryWebApi +package angulate2.ext.inMemoryWebApi import angulate2.core.ModuleWithProviders import angulate2.internal.JSType diff --git a/src/main/scala/angulate2/internal/DecoratedClass.scala b/src/main/scala/angulate2/internal/ClassDecorator.scala similarity index 98% rename from src/main/scala/angulate2/internal/DecoratedClass.scala rename to src/main/scala/angulate2/internal/ClassDecorator.scala index 5b61292..e47bdb7 100644 --- a/src/main/scala/angulate2/internal/DecoratedClass.scala +++ b/src/main/scala/angulate2/internal/ClassDecorator.scala @@ -7,7 +7,7 @@ package angulate2.internal import scala.language.reflectiveCalls -abstract class DecoratedClass extends JsWhiteboxMacroTools { +abstract class ClassDecorator extends JsWhiteboxMacroTools { import c.universe._ // Prefix for accessing the Scala module's exports object from within the sjsx module diff --git a/src/main/scala/angulate2/listeners.scala b/src/main/scala/angulate2/listeners.scala deleted file mode 100644 index 15d7116..0000000 --- a/src/main/scala/angulate2/listeners.scala +++ /dev/null @@ -1,29 +0,0 @@ -// Project: angulate2 -// Description: Traits for Angular2 core lifecycle hooks. - -// Copyright (c) 2016 Johannes.Kastner -// Distributed under the MIT License (see included LICENSE file) -package angulate2 - -import scala.scalajs.js -import scala.scalajs.js.annotation.{JSExport, ScalaJSDefined} - -/** - * Implement this interface to execute custom initialization logic after your directive's data-bound properties have been initialized. - * - * @see [[https://angular.io/docs/ts/latest/api/core/OnInit-interface.html]] - */ -@ScalaJSDefined -trait OnInit extends js.Object { - def ngOnInit(): Unit -} - -/** - * Implement this interface to get notified when your directive is destroyed. - * - * @see [[https://angular.io/docs/ts/latest/api/core/OnDestroy-interface.html]] - */ -@ScalaJSDefined -trait OnDestroy extends js.Object { - def ngOnDestroy(): Unit -} diff --git a/src/main/scala/angulate2/ops.scala b/src/main/scala/angulate2/ops.scala new file mode 100644 index 0000000..655c501 --- /dev/null +++ b/src/main/scala/angulate2/ops.scala @@ -0,0 +1,110 @@ +// Project: angulate2 (https://github.com/jokade/angulate2) +// Description: + +// Copyright (c) 2016 Johannes.Kastner +// Distributed under the MIT License (see included LICENSE file) +package angulate2 + +import angulate2.internal.{JSType, JsBlackboxMacroTools} + +import scala.language.experimental.macros +import scala.reflect.macros.blackbox +import scala.scalajs.js + +object ops extends OpsTrait + +private[angulate2] trait OpsTrait { + + import js.JSConverters._ + + def %%[T]: JSType = macro OpsMacros.jsType[T] + + def @@[T1]: js.Array[js.Any] = macro OpsMacros.jsRefArray1[T1] + + def @@[T1, T2]: js.Array[js.Any] = macro OpsMacros.jsRefArray2[T1, T2] + + def @@[T1, T2, T3]: js.Array[js.Any] = macro OpsMacros.jsRefArray3[T1, T2, T3] + + def @@[T1, T2, T3, T4]: js.Array[js.Any] = macro OpsMacros.jsRefArray4[T1, T2, T3, T4] + + def @@[T1, T2, T3, T4, T5]: js.Array[js.Any] = macro OpsMacros.jsRefArray5[T1, T2, T3, T4, T5] + + def @@[T1, T2, T3, T4, T5, T6]: js.Array[js.Any] = macro OpsMacros.jsRefArray6[T1, T2, T3, T4, T5, T6] + + def @@[T1, T2, T3, T4, T5, T6, T7]: js.Array[js.Any] = macro OpsMacros.jsRefArray7[T1, T2, T3, T4, T5, T6, T7] + + def @@[T1, T2, T3, T4, T5, T6, T7, T8]: js.Array[js.Any] = macro OpsMacros.jsRefArray8[T1, T2, T3, T4, T5, T6, T7, T8] + + def @@[T1, T2, T3, T4, T5, T6, T7, T8, T9]: js.Array[js.Any] = macro OpsMacros.jsRefArray9[T1, T2, T3, T4, T5, T6, T7, T8, T9] + + def @@[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]: js.Array[js.Any] = macro OpsMacros.jsRefArray10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10] + + def @@[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]: js.Array[js.Any] = macro OpsMacros.jsRefArray11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11] + + def @@[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]: js.Array[js.Any] = macro OpsMacros.jsRefArray12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12] + + def @@@[T](items: T*): js.Array[T] = items.toJSArray +} + +private[angulate2] class OpsMacros(val c: blackbox.Context) extends JsBlackboxMacroTools { + import c.universe._ + + + private def findJSRef(symbol: Symbol) = findAnnotations(symbol).collectFirst{ + case ("scala.scalajs.js.annotation.JSExport",_) => selectExported(symbol.fullName) + case ("scala.scalajs.js.annotation.JSImport",a) => q"scalajs.runtime.constructorOf(classOf[$symbol])" + } + + def jsType[T: c.WeakTypeTag]: Tree = findJSRef(weakTypeOf[T].typeSymbol) match { + case Some(t) => q"$t.asInstanceOf[angulate2.internal.JSType]" + case None => + error(s"Cannot get JS reference for type ${weakTypeOf[T].typeSymbol.fullName}; maybe you forgot @JSExport?") + q"" + } + + def jsRef[T: c.WeakTypeTag]: Tree = findJSRef(weakTypeOf[T].typeSymbol) + .getOrElse{error(s"Cannot get JS reference for type ${weakTypeOf[T].typeSymbol.fullName}");q""} + + def jsRefArray1[T: c.WeakTypeTag] = q"scalajs.js.Array(${jsRef[T]})" + + def jsRefArray2[T1: c.WeakTypeTag, T2: c.WeakTypeTag] = q"scalajs.js.Array(${jsRef[T1]},${jsRef[T2]})" + + def jsRefArray3[T1: c.WeakTypeTag, T2: c.WeakTypeTag, T3: c.WeakTypeTag] = + q"scalajs.js.Array(${jsRef[T1]},${jsRef[T2]},${jsRef[T3]})" + + def jsRefArray4[T1: c.WeakTypeTag, T2: c.WeakTypeTag, T3: c.WeakTypeTag, T4: c.WeakTypeTag] = + q"scalajs.js.Array(${jsRef[T1]},${jsRef[T2]},${jsRef[T3]},${jsRef[T4]})" + + def jsRefArray5[T1: c.WeakTypeTag, T2: c.WeakTypeTag, T3: c.WeakTypeTag, T4: c.WeakTypeTag, T5: c.WeakTypeTag] = + q"scalajs.js.Array(${jsRef[T1]},${jsRef[T2]},${jsRef[T3]},${jsRef[T4]},${jsRef[T5]})" + + def jsRefArray6[T1: c.WeakTypeTag, T2: c.WeakTypeTag, T3: c.WeakTypeTag, T4: c.WeakTypeTag, T5: c.WeakTypeTag, + T6: c.WeakTypeTag] = + q"scalajs.js.Array(${jsRef[T1]},${jsRef[T2]},${jsRef[T3]},${jsRef[T4]},${jsRef[T5]},${jsRef[T6]})" + + def jsRefArray7[T1: c.WeakTypeTag, T2: c.WeakTypeTag, T3: c.WeakTypeTag, T4: c.WeakTypeTag, T5: c.WeakTypeTag, + T6: c.WeakTypeTag, T7: c.WeakTypeTag] = + q"scalajs.js.Array(${jsRef[T1]},${jsRef[T2]},${jsRef[T3]},${jsRef[T4]},${jsRef[T5]},${jsRef[T6]},${jsRef[T7]})" + + def jsRefArray8[T1: c.WeakTypeTag, T2: c.WeakTypeTag, T3: c.WeakTypeTag, T4: c.WeakTypeTag, T5: c.WeakTypeTag, + T6: c.WeakTypeTag, T7: c.WeakTypeTag, T8: c.WeakTypeTag] = + q"scalajs.js.Array(${jsRef[T1]},${jsRef[T2]},${jsRef[T3]},${jsRef[T4]},${jsRef[T5]},${jsRef[T6]},${jsRef[T7]},${jsRef[T8]})" + + def jsRefArray9[T1: c.WeakTypeTag, T2: c.WeakTypeTag, T3: c.WeakTypeTag, T4: c.WeakTypeTag, T5: c.WeakTypeTag, + T6: c.WeakTypeTag, T7: c.WeakTypeTag, T8: c.WeakTypeTag, T9: c.WeakTypeTag] = + q"scalajs.js.Array(${jsRef[T1]},${jsRef[T2]},${jsRef[T3]},${jsRef[T4]},${jsRef[T5]},${jsRef[T6]},${jsRef[T7]},${jsRef[T8]},${jsRef[T9]})" + + def jsRefArray10[T1: c.WeakTypeTag, T2: c.WeakTypeTag, T3: c.WeakTypeTag, T4: c.WeakTypeTag, T5: c.WeakTypeTag, + T6: c.WeakTypeTag, T7: c.WeakTypeTag, T8: c.WeakTypeTag, T9: c.WeakTypeTag, T10: c.WeakTypeTag] = + q"scalajs.js.Array(${jsRef[T1]},${jsRef[T2]},${jsRef[T3]},${jsRef[T4]},${jsRef[T5]},${jsRef[T6]},${jsRef[T7]},${jsRef[T8]},${jsRef[T9]},${jsRef[T10]})" + + def jsRefArray11[T1: c.WeakTypeTag, T2: c.WeakTypeTag, T3: c.WeakTypeTag, T4: c.WeakTypeTag, T5: c.WeakTypeTag, + T6: c.WeakTypeTag, T7: c.WeakTypeTag, T8: c.WeakTypeTag, T9: c.WeakTypeTag, T10: c.WeakTypeTag, T11: c.WeakTypeTag] = + q"scalajs.js.Array(${jsRef[T1]},${jsRef[T2]},${jsRef[T3]},${jsRef[T4]},${jsRef[T5]},${jsRef[T6]},${jsRef[T7]},${jsRef[T8]},${jsRef[T9]},${jsRef[T10]},${jsRef[T11]})" + + def jsRefArray12[T1: c.WeakTypeTag, T2: c.WeakTypeTag, T3: c.WeakTypeTag, T4: c.WeakTypeTag, T5: c.WeakTypeTag, + T6: c.WeakTypeTag, T7: c.WeakTypeTag, T8: c.WeakTypeTag, T9: c.WeakTypeTag, T10: c.WeakTypeTag, T11: c.WeakTypeTag, + T12: c.WeakTypeTag] = + q"scalajs.js.Array(${jsRef[T1]},${jsRef[T2]},${jsRef[T3]},${jsRef[T4]},${jsRef[T5]},${jsRef[T6]},${jsRef[T7]},${jsRef[T8]},${jsRef[T9]},${jsRef[T10]},${jsRef[T11]},${jsRef[T12]})" +} + diff --git a/src/main/scala/angulate2/package.scala b/src/main/scala/angulate2/package.scala deleted file mode 100644 index 6fcf4db..0000000 --- a/src/main/scala/angulate2/package.scala +++ /dev/null @@ -1,101 +0,0 @@ -// Project: angulate2 (https://github.com/jokade/angulate2) -// Description: - -// Copyright (c) 2015 Johannes.Kastner -// Distributed under the MIT License (see included file LICENSE) -import angulate2.internal.{JSType, JsBlackboxMacroTools} - -import scala.language.experimental.macros -import scala.reflect.macros.blackbox -import scala.scalajs.js - -package object angulate2 { - import js.JSConverters._ - - def %%[T]: JSType = macro Macros.jsType[T] - def @@[T1] : js.Array[js.Any] = macro Macros.jsRefArray1[T1] - def @@[T1,T2] : js.Array[js.Any] = macro Macros.jsRefArray2[T1,T2] - def @@[T1,T2,T3] : js.Array[js.Any] = macro Macros.jsRefArray3[T1,T2,T3] - def @@[T1,T2,T3,T4] : js.Array[js.Any] = macro Macros.jsRefArray4[T1,T2,T3,T4] - def @@[T1,T2,T3,T4,T5] : js.Array[js.Any] = macro Macros.jsRefArray5[T1,T2,T3,T4,T5] - def @@[T1,T2,T3,T4,T5,T6] : js.Array[js.Any] = macro Macros.jsRefArray6[T1,T2,T3,T4,T5,T6] - def @@[T1,T2,T3,T4,T5,T6,T7] : js.Array[js.Any] = macro Macros.jsRefArray7[T1,T2,T3,T4,T5,T6,T7] - def @@[T1,T2,T3,T4,T5,T6,T7,T8] : js.Array[js.Any] = macro Macros.jsRefArray8[T1,T2,T3,T4,T5,T6,T7,T8] - def @@[T1,T2,T3,T4,T5,T6,T7,T8,T9] : js.Array[js.Any] = macro Macros.jsRefArray9[T1,T2,T3,T4,T5,T6,T7,T8,T9] - - def @@(items: String*) : js.Array[String] = items.toJSArray - def @@@[T<:js.Any](items: T*): js.Array[T] = items.toJSArray -} - -package angulate2 { - private[angulate2] class Macros(val c: blackbox.Context) extends JsBlackboxMacroTools { - import c.universe._ - -// def bootstrapWith[T: c.WeakTypeTag] = { -// val t = selectGlobalDynamic[T] -// val r = -// q"""angulate2.es5.ng.platform.browser.bootstrap($t)""" -// r -// } - -// def register[T: c.WeakTypeTag] = { -// val name = weakTypeOf[T].typeSymbol.fullName -// val t = selectGlobalDynamic(name) -// val obj = selectGlobalDynamic(name+"_") -// val res = q"""{$t.annotations = $obj().annotations() -// () -// }""" -// res -// } - -// private def registerAll(annottees: Map[String,Any]) = -// annottees.toSeq.map{ -// case (_,tree:Tree) => tree -// } - - - private def findJSRef(symbol: Symbol) = findAnnotations(symbol).collectFirst{ - case ("scala.scalajs.js.annotation.JSExport",_) => selectExported(symbol.fullName) - case ("scala.scalajs.js.annotation.JSImport",a) => q"scalajs.runtime.constructorOf(classOf[$symbol])" - } - - def jsType[T: c.WeakTypeTag]: Tree = findJSRef(weakTypeOf[T].typeSymbol) match { - case Some(t) => q"$t.asInstanceOf[angulate2.internal.JSType]" - case None => - error(s"Cannot get JS reference for type ${weakTypeOf[T].typeSymbol.fullName}; maybe you forgot @JSExport?") - q"" - } - - def jsRef[T: c.WeakTypeTag]: Tree = findJSRef(weakTypeOf[T].typeSymbol) - .getOrElse{error(s"Cannot get JS reference for type ${weakTypeOf[T].typeSymbol.fullName}");q""} - - def jsRefArray1[T: c.WeakTypeTag] = q"scalajs.js.Array(${jsRef[T]})" - - def jsRefArray2[T1: c.WeakTypeTag, T2: c.WeakTypeTag] = q"scalajs.js.Array(${jsRef[T1]},${jsRef[T2]})" - - def jsRefArray3[T1: c.WeakTypeTag, T2: c.WeakTypeTag, T3: c.WeakTypeTag] = - q"scalajs.js.Array(${jsRef[T1]},${jsRef[T2]},${jsRef[T3]})" - - def jsRefArray4[T1: c.WeakTypeTag, T2: c.WeakTypeTag, T3: c.WeakTypeTag, T4: c.WeakTypeTag] = - q"scalajs.js.Array(${jsRef[T1]},${jsRef[T2]},${jsRef[T3]},${jsRef[T4]})" - - def jsRefArray5[T1: c.WeakTypeTag, T2: c.WeakTypeTag, T3: c.WeakTypeTag, T4: c.WeakTypeTag, T5: c.WeakTypeTag] = - q"scalajs.js.Array(${jsRef[T1]},${jsRef[T2]},${jsRef[T3]},${jsRef[T4]},${jsRef[T5]})" - - def jsRefArray6[T1: c.WeakTypeTag, T2: c.WeakTypeTag, T3: c.WeakTypeTag, T4: c.WeakTypeTag, T5: c.WeakTypeTag, - T6: c.WeakTypeTag] = - q"scalajs.js.Array(${jsRef[T1]},${jsRef[T2]},${jsRef[T3]},${jsRef[T4]},${jsRef[T5]},${jsRef[T6]})" - - def jsRefArray7[T1: c.WeakTypeTag, T2: c.WeakTypeTag, T3: c.WeakTypeTag, T4: c.WeakTypeTag, T5: c.WeakTypeTag, - T6: c.WeakTypeTag, T7: c.WeakTypeTag] = - q"scalajs.js.Array(${jsRef[T1]},${jsRef[T2]},${jsRef[T3]},${jsRef[T4]},${jsRef[T5]},${jsRef[T6]},${jsRef[T7]})" - - def jsRefArray8[T1: c.WeakTypeTag, T2: c.WeakTypeTag, T3: c.WeakTypeTag, T4: c.WeakTypeTag, T5: c.WeakTypeTag, - T6: c.WeakTypeTag, T7: c.WeakTypeTag, T8: c.WeakTypeTag] = - q"scalajs.js.Array(${jsRef[T1]},${jsRef[T2]},${jsRef[T3]},${jsRef[T4]},${jsRef[T5]},${jsRef[T6]},${jsRef[T7]},${jsRef[T8]})" - - def jsRefArray9[T1: c.WeakTypeTag, T2: c.WeakTypeTag, T3: c.WeakTypeTag, T4: c.WeakTypeTag, T5: c.WeakTypeTag, - T6: c.WeakTypeTag, T7: c.WeakTypeTag, T8: c.WeakTypeTag, T9: c.WeakTypeTag] = - q"scalajs.js.Array(${jsRef[T1]},${jsRef[T2]},${jsRef[T3]},${jsRef[T4]},${jsRef[T5]},${jsRef[T6]},${jsRef[T7]},${jsRef[T8]},${jsRef[T9]})" - } -} diff --git a/src/main/scala/angulate2/std.scala b/src/main/scala/angulate2/std.scala new file mode 100644 index 0000000..40b8b40 --- /dev/null +++ b/src/main/scala/angulate2/std.scala @@ -0,0 +1,90 @@ +// Project: angulate2 (https://github.com/jokade/angulate2) +// Description: Object to allow simple import of the most commonly used annotations and operations + +// Copyright (c) 2016 Johannes.Kastner +// Distributed under the MIT License (see included LICENSE file) +package angulate2 + +import scala.annotation.{StaticAnnotation, compileTimeOnly} +import scala.language.experimental.macros +import scala.scalajs.js + +/** + * Import this object to get the most commonly used angulate2 annotations and operators. + * + * @example ```import angulate2.std._``` + */ +object std extends OpsTrait { + + // duplicate definition of core.Component since `type = core.Component` won't compile + // NOTE: keep in sync with core.Component()!! + @compileTimeOnly("enable macro paradise to expand macro annotations") + class Component(selector: String = null, + inputs: js.Array[String] = null, + outputs: js.Array[String] = null, + host: js.Any = null, + exportAs: String = null, + moduleId: js.Any = null, + providers: js.Array[js.Any] = null, + viewProviders: js.Array[js.Any] = null, + changeDetection: js.Any = null, + queries: js.Any = null, + templateUrl: String = null, + template: String = null, + styles: js.Array[String] = null, + styleUrls: js.Array[String] = null, + animations: js.Array[js.Any] = null, + encapsulation: js.Any = null, + interpolation: js.Any = null, + entryComponents: js.Array[js.Any] = null) extends StaticAnnotation { + def macroTransform(annottees: Any*): Any = macro core.Component.Macro.impl + } + + // duplicate definition of core.Injectable since `type = core.Injectable` won't compile + // NOTE: keep in sync with core.Injectable()!! + @compileTimeOnly("enable macro paradise to expand macro annotations") + class Injectable extends StaticAnnotation { + def macroTransform(annottees: Any*): Any = macro core.Injectable.Macro.impl + } + + // duplicate definition of core.NgModule since `type = core.NgModule` won't compile + // NOTE: keep in sync with core.NgModule()!! + @compileTimeOnly("enable macro paradise to expand macro annotations") + class NgModule(providers: js.Array[js.Any] = null, + declarations: js.Array[js.Any] = null, + imports: js.Array[js.Any] = null, + exports: js.Array[js.Any] = null, + entryComponents: js.Array[js.Any] = null, + bootstrap: js.Array[js.Any] = null, + schemas: js.Array[js.Any] = null, + id: String = null) extends StaticAnnotation { + def macroTransform(annottees: Any*): Any = macro core.NgModule.Macro.impl + } + + // duplicate definition of core.Directive since `type = core.Directive` won't compile + // NOTE: keep in sync with core.Directive()!! + @compileTimeOnly("enable macro paradise to expand macro annotations") + class Directive(selector: String = null, + inputs: js.Array[String] = null, + outputs: js.Array[String] = null, + host: js.Dictionary[String] = null, + template: String = null, + providers: js.Array[js.Any] = null, + exportAs: String = null, + queries: js.Any = null) extends StaticAnnotation { + def macroTransform(annottees: Any*): Any = macro core.Directive.Macro.impl + } + + type Input = core.Input + type OnInit = core.OnInit + type OnDestroy = core.OnDestroy + + + // duplicate definition of ext.Data since `type = ext.Data` won't compile + // NOTE: keep in sync with ext.Data()!! + @compileTimeOnly("enable macro paradise to expand macro annotations") + class Data extends StaticAnnotation { + def macroTransform(annottees: Any*): Any = macro ext.Data.Macro.impl + } +} + diff --git a/tests/src/test/scala/angulate2/test/component/ComponentTests.scala b/tests/src/test/scala/angulate2/test/component/ComponentTests.scala index d1b355f..ee54cf5 100644 --- a/tests/src/test/scala/angulate2/test/component/ComponentTests.scala +++ b/tests/src/test/scala/angulate2/test/component/ComponentTests.scala @@ -6,8 +6,8 @@ package angulate2.test.component import angulate2._ +import angulate2.core.Component import angulate2.test.TestBase -import utest._ import scala.scalajs.js diff --git a/tests/src/test/scala/angulate2/test/directive/DirectiveTests.scala b/tests/src/test/scala/angulate2/test/directive/DirectiveTests.scala index 85b72f4..a1baf04 100644 --- a/tests/src/test/scala/angulate2/test/directive/DirectiveTests.scala +++ b/tests/src/test/scala/angulate2/test/directive/DirectiveTests.scala @@ -6,7 +6,7 @@ package angulate2.test.directive import angulate2._ -import utest._ +import angulate2.core.Component import angulate2.test.TestBase import scala.scalajs.js