Fix macroExpandAndConvert with -D kissCache

This commit is contained in:
2023-03-02 05:50:52 -07:00
parent 99f7d7dde9
commit c5ebdb3293

View File

@@ -471,6 +471,7 @@ class Kiss {
// Core functionality of Kiss: returns ReaderExp when macroExpandOnly is true, and haxe.macro.Expr otherwise
public static function macroExpandAndConvert(exp:ReaderExp, k:KissState, macroExpandOnly:Bool):Either<ReaderExp,Expr> {
#if kissCache
var str = Reader.toString(exp.def);
if (!macroExpandOnly) {
if (expCache == null) {
expCache = if (sys.FileSystem.exists(cacheFile)) {
@@ -479,9 +480,9 @@ class Kiss {
{};
}
}
var str = Reader.toString(exp.def);
if (expCache.exists(str)) {
return Context.parse(expCache[str], Helpers.macroPos(exp));
return Right(Context.parse(expCache[str], Helpers.macroPos(exp)));
}
}
#end
@@ -641,7 +642,10 @@ class Kiss {
#if kissCache
if (!macroExpandOnly) {
if (conversionTime > cacheThreshold && !k.stateChanged) {
expCache[str] = expr.toString();
expCache[str] = switch (expr) {
case Right(expr): expr.toString();
default: throw "macroExpandAndConvert is broken";
}
File.saveContent(cacheFile, haxe.Json.stringify(expCache));
}
}