Failing test case for compileToScript()
This commit is contained in:
47
src/kiss/CompilerTools.hx
Normal file
47
src/kiss/CompilerTools.hx
Normal file
@@ -0,0 +1,47 @@
|
||||
package kiss;
|
||||
|
||||
#if macro
|
||||
import kiss.Kiss;
|
||||
|
||||
enum CompileLang {
|
||||
JavaScript;
|
||||
Python;
|
||||
}
|
||||
|
||||
typedef CompilationArgs = {
|
||||
lang:CompileLang,
|
||||
outputFolder:String,
|
||||
// path to a folder where the script will be compiled
|
||||
?importHxFile:String,
|
||||
// path to a file with haxe import statements in it
|
||||
?hxmlFile:String,
|
||||
// path to a file with hxml args in it (SHOULD NOT specify target or main class)
|
||||
?langProjectFile:String,
|
||||
// path to a package.json or requirements.txt file
|
||||
?mainHxFile:String,
|
||||
// path to a haxe file defining the Main class
|
||||
}
|
||||
|
||||
/**
|
||||
* Multi-purpose tools for compiling Kiss projects.
|
||||
*/
|
||||
class CompilerTools {
|
||||
/**
|
||||
* Compile a kiss file into a standalone script.
|
||||
* @return A function that, when called, executes the script and returns the script output as a string.
|
||||
*/
|
||||
public static function compileFileToScript(kissFile:String, args:CompilationArgs):() -> String {
|
||||
var k = Kiss.defaultKissState();
|
||||
var beginExpsInFile = Kiss.load(kissFile, k, "", true);
|
||||
return compileToScript([beginExpsInFile], args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile kiss expressions into a standalone script
|
||||
* @return A function that, when called, executes the script and returns the script output as a string.
|
||||
*/
|
||||
public static function compileToScript(exps:Array<ReaderExp>, args:CompilationArgs):() -> String {
|
||||
return () -> "";
|
||||
}
|
||||
}
|
||||
#end
|
@@ -185,7 +185,7 @@ class Kiss {
|
||||
});
|
||||
}
|
||||
|
||||
public static function load(kissFile:String, k:KissState, ?loadingDirectory:String):Null<ReaderExp> {
|
||||
public static function load(kissFile:String, k:KissState, ?loadingDirectory:String, loadAllExps = false):Null<ReaderExp> {
|
||||
if (loadingDirectory == null)
|
||||
loadingDirectory = k.loadingDirectory;
|
||||
|
||||
@@ -221,7 +221,9 @@ class Kiss {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (!isEmpty(expr)) {
|
||||
// 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 || !isEmpty(expr)) {
|
||||
loadedExps.push(nextExp);
|
||||
}
|
||||
});
|
||||
|
28
src/test/cases/CompilerToolsTestCase.hx
Normal file
28
src/test/cases/CompilerToolsTestCase.hx
Normal file
@@ -0,0 +1,28 @@
|
||||
package test.cases;
|
||||
|
||||
import utest.Assert;
|
||||
import utest.Test;
|
||||
import kiss.CompilerTools;
|
||||
#if macro
|
||||
import haxe.macro.Expr;
|
||||
import haxe.macro.Context;
|
||||
#end
|
||||
|
||||
class CompilerToolsTestCase extends Test {
|
||||
function testCompileHelloWorld() {
|
||||
Assert.equals("Hello, world!", _testCompileHelloWorld());
|
||||
}
|
||||
|
||||
static macro function _testCompileHelloWorld() {
|
||||
var runHelloWorld = CompilerTools.compileFileToScript(
|
||||
"kiss/template/src/template/Main.kiss", {
|
||||
lang: JavaScript,
|
||||
outputFolder: "bin/js",
|
||||
});
|
||||
|
||||
return {
|
||||
pos: Context.currentPos(),
|
||||
expr: EConst(CString(runHelloWorld(), DoubleQuotes))
|
||||
};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user