From f87c82cc4e804dcae8b71a6187ad5f2768c0f3b3 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Sun, 30 Sep 2018 00:25:45 +0200 Subject: [PATCH] Improve glimmer parse errors (#5161) Instead of showing 80 carets, point out just which line the error was on, and rely on the original message to point out the "column". I thought about matching the `----^` in the original message with a regex and use the length of it as the column number, but unfortunately the original message does not show the original code (in this example some whitespace is missing), so it wouldn't work. Before: ``` $ ./bin/prettier.js test.hbs --parser glimmer [error] test.hbs: SyntaxError: Parse error on line 2: [error] {{one}}{{ [error] ---------^ [error] Expecting 'ID', 'STRING', 'NUMBER', 'BOOLEAN', 'UNDEFINED', 'NULL', 'DATA', got 'EOF' (2:0) [error] 1 | {{one}} [error] > 2 | {{ [error] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [error] 3 | ``` After: ``` $ ./bin/prettier.js test.hbs --parser glimmer [error] test.hbs: SyntaxError: Parse error on line 2: [error] {{one}}{{ [error] ---------^ [error] Expecting 'ID', 'STRING', 'NUMBER', 'BOOLEAN', 'UNDEFINED', 'NULL', 'DATA', got 'EOF' (2:0) [error] 1 | {{one}} [error] > 2 | {{ [error] 3 | ``` --- src/language-handlebars/parser-glimmer.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/language-handlebars/parser-glimmer.js b/src/language-handlebars/parser-glimmer.js index bf5fd7342..163dbf322 100644 --- a/src/language-handlebars/parser-glimmer.js +++ b/src/language-handlebars/parser-glimmer.js @@ -34,8 +34,7 @@ function parse(text) { const matches = error.message.match(/on line (\d+)/); if (matches) { throw createError(error.message, { - start: { line: +matches[1], column: 0 }, - end: { line: +matches[1], column: 80 } + start: { line: Number(matches[1]), column: 0 } }); } else { throw error;