From 193db5ef6b2cd627f009edabeb6cd7356206fa5d Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Wed, 8 Mar 2023 07:48:19 -0700 Subject: [PATCH] move isEmpty() into Kiss class --- src/kiss/AsyncEmbeddedScript.hx | 4 +++- src/kiss/Kiss.hx | 30 ++++++++++++++++-------------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/kiss/AsyncEmbeddedScript.hx b/src/kiss/AsyncEmbeddedScript.hx index 2ecf851..c371493 100644 --- a/src/kiss/AsyncEmbeddedScript.hx +++ b/src/kiss/AsyncEmbeddedScript.hx @@ -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); diff --git a/src/kiss/Kiss.hx b/src/kiss/Kiss.hx index 4e30ff0..066702f 100644 --- a/src/kiss/Kiss.hx +++ b/src/kiss/Kiss.hx @@ -399,24 +399,12 @@ class Kiss { // readerExpToHaxeExpr must be called to process readermacro, alias, and macro definitions macroUsed = false; var expr = readerExpToHaxeExpr(nextExp, k); - + // exps in the loaded file that actually become haxe expressions can be inserted into the // 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 }