chocolateboy/parcel-plugin-nunjucks

Build Nunjucks AST instead of passing to HTMLAsset

devmattrick opened this issue · 4 comments

The current functionality is to simple compile the Nunjucks template and then pass it to the HTMLAsset where it is turned into an AST using JSDOM. It may be beneficial performance-wise to use Nunjucks to generate an AST and resolve dependencies from there.

Ideally, the Nunjucks compiler should be used so there are no compatibility issues.

When will you start implementing this issue?

@Seminioni I'm not too sure. I have a bit of work to do before this and I'm not too sure if Nunjucks builds a proper AST at all, so I don't know how long this will take.

Dependencies can't be determined statically from the AST. Dependencies are expressions (i.e. nonterminals) in nunjucks e.g. the following is valid:

{% set filename = banner.random() %}
{% include filename %}

Dependencies can also be loaded conditionally e.g.:

{% if foo > bar %}
    {% include "footer.html" %}
{% endif %}

Even dependencies that are represented as string literals can't be resolved statically, in general, since the interpretation of the string depends on the loader (i.e. they're identifiers rather than locators) e.g. foo.html could resolve to src/html/foo.html in the filesystem loader or to http://example.com/foo.html in a web loader.

Thanks for the insight, @chocolateboy. Turns out Nunjucks is a much more complicated engine that I expected. I'm having trouble finding time to maintain this project, but anyone is welcome to submit PRs if they are able to fix any of these issues.