handlebars.java
handlebars.java copied to clipboard
[ISSUE-1168] Read whitespace in tokenstream and reconstruct source content
- Read whitespace to a separate channle in tokenstream.
- Added
Template.getSourceText()for exact source reconstruction with whitespace preservation. Enables formatters, linters, and IDE tooling.
Implementation:
- Whitespace tokens sent to channel 1 (not skipped) in
HbsLexer.g4 -
BaseTemplatestorestokenStream+ token span (start/end indices) -
TemplateBuilder.visitTemplate()andvisitBody()set token spans during parsing -
getSourceText()usesTokenStream.getText(Interval)for exact reconstruction -
ForwardingTemplatedelegatesgetSourceText()to wrapped template
Example:
handlebars.compileInline("{{ foo }}").text(); // "{{foo}}" (normalized, Existing)
handlebars.compileInline("{{ foo }}").getSourceText(); // "{{ foo }}" (exact, New)