Skip to content

Conversation

sshailabh
Copy link

@sshailabh sshailabh commented Oct 4, 2025

  • 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
  • BaseTemplate stores tokenStream + token span (start/end indices)
  • TemplateBuilder.visitTemplate() and visitBody() set token spans during parsing
  • getSourceText() uses TokenStream.getText(Interval) for exact reconstruction
  • ForwardingTemplate delegates getSourceText() to wrapped template

Example:

handlebars.compileInline("{{ foo }}").text();          // "{{foo}}"   (normalized, Existing)
handlebars.compileInline("{{ foo }}").getSourceText(); // "{{ foo }}" (exact, New)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant