handlebars-error-parser
The purpose of this module is to parse the Handlebars compile exceptions messages into a more useable format which can be used in handlebars linter(s). Handlebars throws different exceptions depending the template error.
Handlebars exception types:
- Parser Error: handlebars can't compile the template.
- Block Error: the open and close block helpers do not match.
This module parses the exception message into:
minLine: 1 minColumn: 3 maxLine: 1 maxColumn: 4 message: 'foo doesn\'t match bar'
Install
npm install handlebars-error-parser --save
In Node.js:
var parser = parser;var html = '{{#foo}}{{/bar}}';var parsed;try hbs; catch e parsed = ;
In browser:
var html = '{{#foo}}{{/bar}}';var parsed;try hbs; catch e parsed = window;
Block Error: Mismatched: block helpers
{{#foo}}{{/bar}}
foo doesn't match bar - 1:3
Block Error: Mismatached: closing helpler
{{foo}}{{/foo}}
Parse error on line 1:{{foo}}{{/foo}}-------^Expecting 'EOF', got 'OPEN_ENDBLOCK'
Parse Error: Missing helper or variable closing
{{foo
Parse error on line 1:{{foo--^Expecting 'ID', 'STRING', 'NUMBER', 'BOOLEAN', 'UNDEFINED', 'NULL', 'DATA', got 'INVALID'
Parse Error: Missing block helper closing
{{#foo
Parse error on line 1:{{#foo---^Expecting 'ID', 'STRING', 'NUMBER', 'BOOLEAN', 'UNDEFINED', 'NULL', 'DATA', got 'INVALID'