Skip to content

Commit

Permalink
remove unused exceptions, better macro error message
Browse files Browse the repository at this point in the history
  • Loading branch information
greg2010 committed Feb 25, 2021
1 parent 241594d commit a5b73c9
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .idea/scala_compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

26 changes: 16 additions & 10 deletions macro/src/main/scala/org/kys/athena/util/assets/AssetLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,23 @@ object AssetLoader {

def requireImpl(c: blackbox.Context)(path: c.Expr[String]): c.Expr[String] = {
import c.universe._
path match {
case Expr(Literal(_)) => {
reify {
JSImporter.require[String](s"../../src/main/resources" + path.splice)
}
}
case _ => {
throw new IllegalArgumentException("Cannot call require with non-literal values.\n" +
"This will produce an invalid JS require that will likely break " +
"things.")
def eval[B](tree: Tree): B = c.eval[B](c.Expr[B](c.untypecheck(tree.duplicate)))
try {
val pathStr = eval[String](path.tree)
println("Evaled to " + pathStr)
val expr = c.Expr[String](Literal(Constant(pathStr)))
reify {
JSImporter.require[String](s"../../src/main/resources" + expr.splice)
}
} catch {
case e: Throwable =>
c.abort(c.enclosingPosition,
s"""
|Exception during require macro expansion.
|This method cannot be called with values not known at compile-time.
|This will produce an invalid JS require that will likely break things.
|Caused by: $e
|""".stripMargin)
}
/*
def eval[B](tree: Tree): B = c.eval[B](c.Expr[B](c.untypecheck(tree.duplicate)))
Expand Down

0 comments on commit a5b73c9

Please sign in to comment.