Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reimplement whitespace handling for standalone tokens
Whitespace handling was previously done by a post-processor on the token stream produced by the lexer. We reimplement it as a post-processor on the *output* stream after rendering. This means that information from the fully-parsed AST can be used to make rendering decisions. For example, non-rendered sections (because their corresponding json data is empty) are now handled as standalone tokens. This gives nicer output, consider for example: {{#foo}}Foo is present.{{/foo}} {{^foo}}Foo is absent. {{/foo}} This used to produce two lines of output, one being empty. Now this only produces one line of input (if 'foo' is a scalar or object, not a list). (Interestingly, such examples are not tested in the Mustache specification testsuite. Both the previous implementation and the current implementation pass all the specification tests, which suggests that the tests are not comprehensive enough.) Note: The real motivation for this change is not inverted sections, but rather indentation and whitespace handling for partial parameters -- when implementing template inheritance.
- Loading branch information