I have a project that pre-packages some data at compile time via haxe.Serializer
. This works with --dce std
but --dce full
removes the classes if they aren’t directly referenced, and also any custom hxUnserialize
methods are lost which breaks the Unserializer
.
I understand why this happens, but I’m struggling to convince the compiler to hold on to what I need without having to modify code in all the libraries used.
I have tried things like --macro keep('', ['htmlparser'], true)
in the build, but it doesn’t appear to be working. Has anyone out there run into this already and is there a clean solution?
The bare-bones system looks like this:
import htmlparser.*;
import haxe.*;
class MainTest {
static function main() {
var s = $v{PreSerialize.serializeHtml("<p>serialized</p>")};
trace(s);
var n2:Array<HtmlNode> = Unserializer.run(s);
trace(n2);
}
}
class PreSerialize {
macro public static inline function serializeHtml(html:String):haxe.macro.Expr {
haxe.Serializer.USE_CACHE = true;
return macro $v{Serializer.run(HtmlParser.run(html))};
}
}