STRd6 / jadelet

Pure and simple clientside templates
https://jadelet.com
MIT License
378 stars 11 forks source link

Normalize indent #37

Open zdenko opened 3 years ago

zdenko commented 3 years ago

This PR fixes a bug with firstIndent in the reduceLines function. The Indent token consists of two space character groups or one tab. In my previous, quick solution, I forgot to test cases with an odd number of spaces. In such cases, the parser can't detect the TagName token because of the "orphaned" space character in front. For example, in this case (symbol represents a space) :

var templateFoo = `div
⊔⊔⊔⊔⊔⊔⊔⊔⊔⊔⊔⊔⊔⊔⊔⊔⊔⊔⊔⊔span @name

there are 21 spaces. The parser will detect ten indents but will not detect LineBody token because of preceding space character (e.g., ⊔span).

To solve this, I added a rule for the TagName token, which now allows a single space character preceding an Indetifier token.