Templates render as Handlebars.js 4.7.10 renders them, and parse as @handlebars/parser 2.2.4 parses them. This page lists where they differ, and how that is tested.
Where rendering differs
- Decorators other than
{{#*inline}}are errors. A value called with arguments, like{{name "x"}}, isname is not a function, where Handlebars.js reports a JavaScriptTypeErrorfrom its generated code. Functions in data aren't called as helpers. - In strict mode, a missing value's error names the object it was looked up in
data, where Handlebars.js writes it as[object Object]:"first_name" not defined in data. Other values are written as Handlebars.js writes them, as in"first" not defined in undefined. - A missing value is
nilto a helper, where Handlebars.js tellsundefinedfromnull. #eachover a map can't follow the order keys were added in, since Elixir maps don't keep it. It walks keys that are array indexes in numeric order, then the others sorted. Decode JSON withBraces.Handlebars.decode_json/1to keep its order.#withand blocks only step into a new context, for../, when the value isn't equal to the current one. Handlebars.js compares objects by identity, and we compare them by value, so a block over an equal copy of the context doesn't add a level: in{{#with a}}{{#with ../b}}{{../k}}{{/with}}{{/with}}with equalaandb,../kisa.kin Handlebars.js and the root'skhere.- Output is joined as text. Handlebars.js joins a block's outputs with JavaScript's
+, which adds numbers:{{{a}}}{{{b}}}with 1 and 2 gives3there, and12here. - Templates are parsed by our port of @handlebars/parser 2.2.4, not by the parser Handlebars.js
4.7.10 bundles. That parser rejects a few templates 2.2.4 accepts (
{{a.0}},{{(helper)}}), and strips the whitespace around a few{{else if}}chains differently.
How it's tested
Rendering
The tests compare it with Handlebars.js 4.7.10 rendering @handlebars/parser 2.2.4's AST: the
spec's renders, those with custom helpers through Elixir equivalents of its JavaScript helpers
(test/support/corpus_helpers.ex), cases for each feature in strict mode and not, and a
StreamData property of random templates and data.
Compiled templates
The tests compile every template of the Handlebars.js corpus with a recorded render, with its
helpers and partials, and the random templates of the StreamData property, and check that each
renders as Braces.Handlebars.render/3 does. A module with helpers and partial files is checked
against Handlebars.js too.
Parser
test/handlebars/handlebars_js_corpus_test.exstakes every template in handlebars.js 4.7.10's spec files and its Mustache spec, 731 of them. Our AST, locations included, and its printed form must equal what @handlebars/parser 2.2.4 gives, and templates it rejects we reject.Braces.Handlebars.to_string/1of each AST must parse back to the same AST. 209 of them are rendered by Handlebars.js in the spec without custom helpers or partials, and 139 with them; all must render the same withBraces.Handlebars.render/3, the second with Elixir equivalents of the spec's JavaScript helpers, except the 3 renders whose helperstest/support/corpus_helpers.exlists as having none, with why.test/fixtures/handlebars_js_corpus.jsonholds upstream's results;test/js/extract_handlebars_corpus.jsrebuilds it from a handlebars.js checkout.test/handlebars/parser_spec_test.exsruns handlebars-parser'sspec/parser.js, whose 105 cases are copied intotest/fixtures/handlebars_parser_spec.json, andtest/handlebars/ast_spec_test.exsportsspec/ast.js.