tildeio / htmlbars

A variant of Handlebars that emits DOM and allows you to write helpers that manipulate live DOM nodes
MIT License
1.61k stars 193 forks source link

Fix loc info for content statements with leading newlines. #450

Closed rwjblue closed 8 years ago

rwjblue commented 8 years ago

Given the following:

<div>
  {{#if isSingleError}}
    Single error here!
  {{else if errors}}
    Multiple errors here!
  {{else}}
    No errors found!
  {{/if}}
</div>

The ElementNode for the <div> was indicating that its loc.end.column was 12. This is ultimately due to how Handlebars handles trailing newlines after the {{/if}}. We were properly detecting that the node was rightStripped and adding the number of stripped newlines to the tokenizer.line number, but we did not reset the tokenizer.column also.

The fix is to ensure that the column is reset when incrementing the line count.


This is also being fixed in Glimmer in https://github.com/tildeio/glimmer/pull/91

stefanpenner commented 8 years ago

LGTM

rwjblue commented 8 years ago

After digging a bit more, I realized that almost all ElementNode locations on the same line as a mustache were incorrect. I have updated the approach to utilize the ContentStatement's location information to reset the tokenizer's current positioning which fixes the following additional issues that I identified while digging into the {{else if foo}} issue: