diff options
author | Haoyi Li <haoyi@haoyi-mbp.corp.dropbox.com> | 2014-11-26 00:45:31 -0800 |
---|---|---|
committer | Haoyi Li <haoyi@haoyi-mbp.corp.dropbox.com> | 2014-11-26 00:45:31 -0800 |
commit | 24f31e120f9537faede7a174bb09ee35f64e1ce4 (patch) | |
tree | 06ffc3ecc7847789008352b7e2b7c040dad48907 /examples/scala-js/tools/shared/src/main/scala/scala/scalajs/tools/javascript/TreeDSL.scala | |
parent | b89ce9cbf79363f8cab09186a5d7ba94bc0af02a (diff) | |
parent | 2c4b142503bd2d871e6818b5cab8c38627d9e4a0 (diff) | |
download | hands-on-scala-js-24f31e120f9537faede7a174bb09ee35f64e1ce4.tar.gz hands-on-scala-js-24f31e120f9537faede7a174bb09ee35f64e1ce4.tar.bz2 hands-on-scala-js-24f31e120f9537faede7a174bb09ee35f64e1ce4.zip |
Merge commit '2c4b142503bd2d871e6818b5cab8c38627d9e4a0' as 'examples/scala-js'
Diffstat (limited to 'examples/scala-js/tools/shared/src/main/scala/scala/scalajs/tools/javascript/TreeDSL.scala')
-rw-r--r-- | examples/scala-js/tools/shared/src/main/scala/scala/scalajs/tools/javascript/TreeDSL.scala | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/examples/scala-js/tools/shared/src/main/scala/scala/scalajs/tools/javascript/TreeDSL.scala b/examples/scala-js/tools/shared/src/main/scala/scala/scalajs/tools/javascript/TreeDSL.scala new file mode 100644 index 0000000..3ac54d8 --- /dev/null +++ b/examples/scala-js/tools/shared/src/main/scala/scala/scalajs/tools/javascript/TreeDSL.scala @@ -0,0 +1,50 @@ +/* __ *\ +** ________ ___ / / ___ __ ____ Scala.js tools ** +** / __/ __// _ | / / / _ | __ / // __/ (c) 2014, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ |/_// /_\ \ http://scala-js.org/ ** +** /____/\___/_/ |_/____/_/ | |__/ /____/ ** +** |/____/ ** +\* */ + + +package scala.scalajs.tools.javascript + +import scala.language.implicitConversions + +import scala.scalajs.ir.Position + +import Trees._ + +private[javascript] object TreeDSL { + implicit class TreeOps(val self: Tree) extends AnyVal { + /** Select a member */ + def DOT(field: Ident)(implicit pos: Position): DotSelect = + DotSelect(self, field) + + /** Select a member */ + def DOT(field: String)(implicit pos: Position): DotSelect = + DotSelect(self, Ident(field)) + + // Some operators that we use + + def ===(that: Tree)(implicit pos: Position): Tree = + BinaryOp("===", self, that) + def ===(that: String)(implicit pos: Position): Tree = + BinaryOp("===", self, StringLiteral(that)) + + def unary_!()(implicit pos: Position): Tree = + UnaryOp("!", self) + def &&(that: Tree)(implicit pos: Position): Tree = + BinaryOp("&&", self, that) + def ||(that: Tree)(implicit pos: Position): Tree = + BinaryOp("||", self, that) + + // Other constructs + + def :=(that: Tree)(implicit pos: Position): Tree = + Assign(self, that) + } + + def typeof(expr: Tree)(implicit pos: Position): Tree = + UnaryOp("typeof", expr) +} |