diff --git a/grammars/javascript.cson b/grammars/javascript.cson index ef6aed65..99820fe6 100644 --- a/grammars/javascript.cson +++ b/grammars/javascript.cson @@ -827,15 +827,6 @@ { 'include': '#comments' } - { - 'match': '()' - 'captures': - '0': - 'name': 'punctuation.definition.comment.html.js' - '2': - 'name': 'punctuation.definition.comment.html.js' - 'name': 'comment.block.html.js' - } { 'match': '(?)' # Unfortunately, we don't know when we're embedded, so this is as good as it gets + 'name': 'comment.block.documentation.js' } { 'begin': '/\\*' 'beginCaptures': '0': 'name': 'punctuation.definition.comment.js' + 'end': '\\*/|(?=)' # Unfortunately, we don't know when we're embedded, so this is as good as it gets 'end': '\\*/' 'endCaptures': '0': @@ -1995,11 +1989,45 @@ 'beginCaptures': '0': 'name': 'punctuation.definition.comment.js' - 'end': '\\n' + 'end': '$|(?=)' # Unfortunately, we don't know when we're embedded, so this is as good as it gets 'name': 'comment.line.double-slash.js' } ] } + { + 'begin': '(^[ \\t]+)?(?=)' + 'beginCaptures': + '1': + 'name': 'punctuation.whitespace.comment.leading.js' + 'end': '(?!\\G)' + 'patterns': [ + { + 'begin': '-->' + 'beginCaptures': + '0': + 'name': 'punctuation.definition.comment.html.js' + 'end': '$|(?=)' # Unfortunately, we don't know when we're embedded, so this is as good as it gets + 'name': 'comment.line.html.js' + } + ] + } ] 'switch_statement': 'patterns': [ diff --git a/spec/javascript-spec.coffee b/spec/javascript-spec.coffee index b5b1ab50..49245d64 100644 --- a/spec/javascript-spec.coffee +++ b/spec/javascript-spec.coffee @@ -1821,6 +1821,39 @@ describe "Javascript grammar", -> expect(tokens[7]).toEqual value: ', p2 ', scopes: ['source.js', 'meta.function.js', 'meta.parameters.js', 'comment.block.js'] expect(tokens[8]).toEqual value: '*/', scopes: ['source.js', 'meta.function.js', 'meta.parameters.js', 'comment.block.js', 'punctuation.definition.comment.js'] + it "tokenizes HTML-style comments correctly", -> + {tokens} = grammar.tokenizeLine ' comment' + expect(tokens[0]).toEqual value: '-->', scopes: ['source.js', 'comment.line.html.js', 'punctuation.definition.comment.html.js'] + expect(tokens[1]).toEqual value: ' comment', scopes: ['source.js', 'comment.line.html.js'] + + it "stops comments when a tag is encountered", -> + # HTML doesn't count comments if they're followed by a tag. Unfortunately we have + # no idea if we're embedded or not, so we err on the side of caution and always assume that we are :/ + + {tokens} = grammar.tokenizeLine '/* ' + expect(tokens[0]).toEqual value: '/*', scopes: ['source.js', 'comment.block.js', 'punctuation.definition.comment.js'] + expect(tokens[1]).not.toEqual value: ' ', scopes: ['source.js', 'comment.block.js'] + + {tokens} = grammar.tokenizeLine '/** ' + expect(tokens[0]).toEqual value: '/**', scopes: ['source.js', 'comment.block.documentation.js', 'punctuation.definition.comment.js'] + expect(tokens[1]).not.toEqual value: ' ', scopes: ['source.js', 'comment.block.documentation.js'] + + {tokens} = grammar.tokenizeLine '// ' + expect(tokens[0]).toEqual value: '//', scopes: ['source.js', 'comment.line.double-slash.js', 'punctuation.definition.comment.js'] + expect(tokens[1]).not.toEqual value: ' ', scopes: ['source.js', 'comment.line.double-slash.js'] + + {tokens} = grammar.tokenizeLine ' ' + expect(tokens[0]).toEqual value: '-->', scopes: ['source.js', 'comment.line.html.js', 'punctuation.definition.comment.html.js'] + expect(tokens[1]).not.toEqual value: ' ', scopes: ['source.js', 'comment.line.html.js'] + describe "console", -> it "tokenizes the console keyword", -> {tokens} = grammar.tokenizeLine('console;')