dustjs icon indicating copy to clipboard operation
dustjs copied to clipboard

debug friendly compiler output

Open carchrae opened this issue 12 years ago • 1 comments

I've been running compiled dust templates through beautify.js - and while it makes it much easier to trace, they are still not so easy to debug.

eg,

(a template that makes a button and gets the href from the context { nav : 'http://blarg.com', title : 'Blargh Site!' }

(function() {
    dust.register("bigbutton", body_0);
    function body_0(chk, ctx) {
        return chk
                .write(
                        " <a role=\"button\" class=\"btn btn-warning btn-large pull-right\" href=\"")
                .reference(ctx.get("nav"), ctx, "h").write("\">").reference(
                        ctx.get("title"), ctx, "h").write("</a>");
    }
    return body_0;
})();

I propose a compiler mode, perhaps dust.compiledebug - which would instead produce this kind of output:

(function() {
    dust.register("bigbutton", body_0);
    function body_0(chk, ctx) {
        var get = {};
        chk = chk.write(" <a role=\"button\" class=\"btn btn-warning btn-large pull-right\" href=\"");
        get["nav"] = ctx.get("nav");
        chk = chk.reference(get["nav"], ctx, "h")
        chk = chk.write("\">");
        get["title"] = ctx.get("title");
        chk = chk.reference(get["title"], ctx, "h");
        chk = chk.write("</a>");
        return chk;
    }
    return body_0;
})();
  • runs beautify.js
  • produces more local varaibles
  • does not chain calls (eg, chk.write('bla').reference(...).write('bla bla);
  • automatically inserts logger statements, perhaps using #137

carchrae avatar Jul 04 '13 17:07 carchrae

adding to my wishlist.

  • source ref to the original template (a line number would be ok - but sourcemaps would be oh so sexy! http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/ )

carchrae avatar Jul 04 '13 18:07 carchrae