move isEmpty() into Kiss class
This commit is contained in:
@@ -10,6 +10,7 @@ using kiss.Helpers;
|
||||
#end
|
||||
|
||||
import kiss.Kiss;
|
||||
import kiss.ReaderExp;
|
||||
import kiss.Prelude;
|
||||
import kiss.cloner.Cloner;
|
||||
|
||||
@@ -178,7 +179,8 @@ class AsyncEmbeddedScript {
|
||||
Reader.readAndProcess(Stream.fromFile(scriptFile), k, (nextExp) -> {
|
||||
var exprString = Reader.toString(nextExp.def);
|
||||
var expr = Kiss.readerExpToHaxeExpr(nextExp, k);
|
||||
|
||||
if (Kiss.isEmpty(expr))
|
||||
return;
|
||||
#if debug
|
||||
expr = macro { Prelude.print($v{exprString}); $expr; };
|
||||
expr = expr.expr.withMacroPosOf(nextExp);
|
||||
|
@@ -404,19 +404,7 @@ class Kiss {
|
||||
// file that loaded them at the position (load) was called.
|
||||
// conditional compiler macros like (#when) tend to return empty blocks, or blocks containing empty blocks
|
||||
// when they contain field forms, so this should also be ignored
|
||||
function isEmpty(expr) {
|
||||
switch (expr.expr) {
|
||||
case EBlock([]):
|
||||
case EBlock(blockExps):
|
||||
for (exp in blockExps) {
|
||||
if (!isEmpty(exp))
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// When calling from build(), we can't add all expressions to the (begin) returned by (load), because that will
|
||||
// cause double-evaluation of field forms
|
||||
if (loadAllExps) {
|
||||
@@ -786,5 +774,19 @@ class Kiss {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static function isEmpty(expr:Expr) {
|
||||
switch (expr.expr) {
|
||||
case EBlock([]):
|
||||
case EBlock(blockExps):
|
||||
for (exp in blockExps) {
|
||||
if (!isEmpty(exp))
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#end
|
||||
}
|
||||
|
Reference in New Issue
Block a user