diff --git a/src/handlebars/handlebars.test.ts b/src/handlebars/handlebars.test.ts index 4e5aa2bd..71738d77 100644 --- a/src/handlebars/handlebars.test.ts +++ b/src/handlebars/handlebars.test.ts @@ -281,5 +281,35 @@ testTokenization(['handlebars', 'css'], [ { startIndex: 30, type: 'delimiter.handlebars' }, { startIndex: 32, type: '' } ] - }] + }], + + // Block comment + [{ + line: '{{!-- block comment --}}', + tokens: [ + { startIndex: 0, type: 'comment.block.start.handlebars' }, + { startIndex: 5, type: 'comment.content.handlebars' }, + { startIndex: 20, type: 'comment.block.end.handlebars' } + ] + }], + + // Block comment with mustache + [{ + line: '{{!-- block comment }} with mustache --}}', + tokens: [ + { startIndex: 0, type: 'comment.block.start.handlebars' }, + { startIndex: 5, type: 'comment.content.handlebars' }, + { startIndex: 37, type: 'comment.block.end.handlebars' } + ] + }], + + // Handlebars comment + [{ + line: '{{! comment }}', + tokens: [ + { startIndex: 0, type: 'comment.start.handlebars' }, + { startIndex: 3, type: 'comment.content.handlebars' }, + { startIndex: 12, type: 'comment.end.handlebars' } + ] + }], ]); diff --git a/src/handlebars/handlebars.ts b/src/handlebars/handlebars.ts index dc1eee51..17db3fc3 100644 --- a/src/handlebars/handlebars.ts +++ b/src/handlebars/handlebars.ts @@ -63,9 +63,11 @@ export const language = { // The main tokenizer for our languages tokenizer: { root: [ + [/\{\{!--/, 'comment.block.start.handlebars', '@commentBlock'], + [/\{\{!/, 'comment.start.handlebars', '@comment'], [/\{\{/, { token: '@rematch', switchTo: '@handlebarsInSimpleState.root' }], [/)/, ['delimiter.html', 'tag.html', 'delimiter.html']], [/(<)(script)/, ['delimiter.html', { token: 'tag.html', next: '@script' }]], [/(<)(style)/, ['delimiter.html', { token: 'tag.html', next: '@style' }]], @@ -83,6 +85,16 @@ export const language = { ], comment: [ + [/\}\}/, 'comment.end.handlebars', '@pop'], + [/./, 'comment.content.handlebars'] + ], + + commentBlock: [ + [/--\}\}/, 'comment.block.end.handlebars', '@pop'], + [/./, 'comment.content.handlebars'] + ], + + commentHtml: [ [/\{\{/, { token: '@rematch', switchTo: '@handlebarsInSimpleState.comment' }], [/-->/, 'comment.html', '@pop'], [/[^-]+/, 'comment.content.html'],