handlebars-lang / handlebars-lang/handlebars.js
Enhance `showPosition()` to Accurately Display Error Position by Line Number
- Dominant language
- JavaScript
- Stars
- 18.7k
- Forks
- 2.1k
- PR merge metrics
- No merged PRs in 30d
Description
### Description
Preserve new-lines in templates when showing the position of parsing-errors.
### Current behavior
#### Input
```hbs
{{#if}
HELLO
{{/if}}
```
#### Error
```
Parse error on line 1:
{{#if} HELLO{{/if}}
-----^
```
https://handlebarsjs.com/playground.html#format=1¤tExample=%7B%22template%22%3A%22%7B%7B%23if%7D%5Cn%20%20HELLO%5Cn%7B%7B%2Fif%7D%7D%22%2C%22partials%22%3A%5B%5D%2C%22input%22%3A%22%7B%7D%5Cn%22%2C%22output%22%3A%22Yehuda%20KATZ%5Cn%22%2C%22preparationScript%22%3A%22%22%2C%22handlebarsVersion%22%3A%224.7.8%22%7D
### Expected behavior
```hbs
{{#if}
HELLO
{{/if}}
```
#### Error
```
Parse error on line 1:
{{#if}
----^
HELLO
{{/if}}
```
### Original issues
@jaylinski can we enhance `showPosition()` ??
**to Ensures that the ----^ indicator accurately reflects the error position on the relevant line, rather than defaulting to the last line:**
For more visit: https://github.com/zaach/jison/issues/406
Contributor guide
Research direction
Start by locating showPosition() in the JavaScript parser and reproduce the template example from the issue. Compare the current and expected parse-error output, then verify that newlines are preserved and the caret points to the error position on the relevant line.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- handlebars, javascript
- Domain
- web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100