Skip to content
This repository has been archived by the owner on Apr 4, 2019. It is now read-only.

HTMLBars AST does not push CommentStatements? #417

Open
step2yeung opened this issue Sep 28, 2015 · 3 comments
Open

HTMLBars AST does not push CommentStatements? #417

step2yeung opened this issue Sep 28, 2015 · 3 comments

Comments

@step2yeung
Copy link

I noticed that HTMLBars AST does not push mustache statement styled comments into the AST, while HandleBars AST does. Is there a reason for this difference?

For example:

{{! comments }}
<div">
  foobar
</div>

Handlebars AST looks like (Notice the CommentStatement element):

{ loc: 
   { source: undefined,
     start: { line: 1, column: 0 },
     end: { line: 5, column: 0 } },
  type: 'Program',
  body: 
   [ { loc: [Object],
       type: 'CommentStatement',
       value: ' comments ',
       strip: [Object] },
     { loc: [Object],
       type: 'ContentStatement',
       value: '<div class="panel">\n  foobar\n</div>\n',
       original: '\n<div class="panel">\n  foobar\n</div>\n',
       rightStripped: true } ],
  blockParams: null,
  strip: {} }

While, HTMLBar AST does not push the comment statement into the AST elements.

{ type: 'Program',
  body: 
   [ { type: 'ElementNode',
       tag: 'div',
       attributes: [Object],
       modifiers: [],
       children: [Object],
       loc: [Object] },
     { type: 'TextNode', chars: '\n', loc: null } ],
  blockParams: [],
  loc: 
   { source: null,
     start: { line: 1, column: 0 },
     end: { line: 5, column: 0 } } }
@mmun
Copy link
Collaborator

mmun commented Sep 28, 2015

This is a bug. We need to preserve both HTML and HBS comments.

@zackthehuman
Copy link

The more I think about this it actually seems like not a bug. If the objective of HTMLBars' parsing is to produce an AST that ultimately maps to DOM, then preserving Handlebars comments has no meaningful impact on the DOM, unlike HTML comments.

@mmun
Copy link
Collaborator

mmun commented Dec 18, 2015

Yes, they are 100% inert but for practical reasons it would be useful to have them in the AST, e.g. for future linting tools. We may opt instead to have a separate Concrete Syntax Tree but my hunch is that there isn't enough differences between the AST and CST to merit the extra complexity.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants