Skip to content
This repository was archived by the owner on Jan 6, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/@glimmer/compiler/test/compiler-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ test('top-level comments', `<!-- {{foo}} -->`, c` {{foo}} `);

test('handlebars comments', `<div>{{! Better not break! }}content</div>`, ['<div>', [s`content`]]);

test('handlebars comments with whitespace removal', '<div> {{~! some comment ~}} content</div>', ['<div>', [s`content`]]);

test('namespaced attribute', `<svg xlink:title='svg-title'>content</svg>`, [
'<svg>',
{ 'xlink:title': s`svg-title` },
Expand Down
14 changes: 10 additions & 4 deletions packages/@glimmer/syntax/lib/v2/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,18 @@ class StatementNormalizer {
let loc = this.block.loc(node.loc);
let textLoc: SourceSpan;

if (loc.asString().slice(0, 5) === '{{!--') {
textLoc = loc.slice({ skipStart: 5, skipEnd: 4 });
} else {
textLoc = loc.slice({ skipStart: 3, skipEnd: 2 });
let locStr = loc.asString();

let skipStart = locStr.startsWith('{{~') ? 4 : 3;
let skipEnd = locStr.endsWith('~}}') ? 3 : 2;

if (locStr.slice(skipStart-1).startsWith('!--')) {
skipStart += 2;
skipEnd += 2;
}

textLoc = loc.slice({ skipStart, skipEnd });

return new ASTv2.GlimmerComment({
loc,
text: textLoc.toSlice(node.value),
Expand Down
8 changes: 8 additions & 0 deletions packages/@glimmer/syntax/test/parser-node-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,14 @@ test('a Handlebars comment', function () {
);
});

test('a Handlebars comment with whitespace removal', function () {
let t = 'before {{~! some comment ~}} after';
astEqual(
t,
b.program([b.text('before'), b.mustacheComment(' some comment '), b.text('after')])
);
});

test('a Handlebars comment in proper element space', function () {
let t = 'before <div {{! some comment }} data-foo="bar" {{! other comment }}></div> after';
astEqual(
Expand Down