diff --git a/packages/@glimmer/compiler/test/compiler-test.ts b/packages/@glimmer/compiler/test/compiler-test.ts index a73874f1e5..014176b945 100644 --- a/packages/@glimmer/compiler/test/compiler-test.ts +++ b/packages/@glimmer/compiler/test/compiler-test.ts @@ -317,6 +317,8 @@ test('top-level comments', ``, c` {{foo}} `); test('handlebars comments', `
{{! Better not break! }}content
`, ['
', [s`content`]]); +test('handlebars comments with whitespace removal', '
{{~! some comment ~}} content
', ['
', [s`content`]]); + test('namespaced attribute', `content`, [ '', { 'xlink:title': s`svg-title` }, diff --git a/packages/@glimmer/syntax/lib/v2/normalize.ts b/packages/@glimmer/syntax/lib/v2/normalize.ts index cd83f66fc6..44b6c7ab35 100644 --- a/packages/@glimmer/syntax/lib/v2/normalize.ts +++ b/packages/@glimmer/syntax/lib/v2/normalize.ts @@ -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), diff --git a/packages/@glimmer/syntax/test/parser-node-test.ts b/packages/@glimmer/syntax/test/parser-node-test.ts index 403666278d..f09b7286fc 100644 --- a/packages/@glimmer/syntax/test/parser-node-test.ts +++ b/packages/@glimmer/syntax/test/parser-node-test.ts @@ -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
after'; astEqual(