Skip to content

Commit f975e17

Browse files
author
Wliu
authored
Merge pull request atom#486 from atom/wl-fix-line-comments
Simplify single-line comment handling
2 parents 245162f + a87481e commit f975e17

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

grammars/javascript.cson

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2269,21 +2269,12 @@
22692269
'name': 'comment.block.js'
22702270
}
22712271
{
2272-
'begin': '(^[ \\t]+)?(?=//)'
2272+
'begin': '//'
22732273
'beginCaptures':
2274-
'1':
2275-
'name': 'punctuation.whitespace.comment.leading.js'
2276-
'end': '(?!\\G)'
2277-
'patterns': [
2278-
{
2279-
'begin': '//'
2280-
'beginCaptures':
2281-
'0':
2282-
'name': 'punctuation.definition.comment.js'
2283-
'end': '\\n'
2284-
'name': 'comment.line.double-slash.js'
2285-
}
2286-
]
2274+
'0':
2275+
'name': 'punctuation.definition.comment.js'
2276+
'end': '$'
2277+
'name': 'comment.line.double-slash.js'
22872278
}
22882279
]
22892280
'switch_statement':

spec/javascript-spec.coffee

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,14 @@ describe "JavaScript grammar", ->
833833
expect(lines[2][2]).toEqual value: ' comment ', scopes: ['source.js', 'meta.import.js', 'comment.block.js']
834834
expect(lines[2][3]).toEqual value: '*/', scopes: ['source.js', 'meta.import.js', 'comment.block.js', 'punctuation.definition.comment.js']
835835
836+
# https://github.com/atom/language-javascript/issues/485
837+
lines = grammar.tokenizeLines '''
838+
import a from 'a' //
839+
import b from 'b'
840+
'''
841+
expect(lines[0][10]).toEqual value: '//', scopes: ['source.js', 'meta.import.js', 'comment.line.double-slash.js', 'punctuation.definition.comment.js']
842+
expect(lines[1][0]).toEqual value: 'import', scopes: ['source.js', 'meta.import.js', 'keyword.control.js']
843+
836844
describe "ES6 export", ->
837845
it "tokenizes named export", ->
838846
{tokens} = grammar.tokenizeLine('export var x = 0;')
@@ -1715,6 +1723,14 @@ describe "JavaScript grammar", ->
17151723
expect(tokens[15]).toEqual value: ')', scopes: ['source.js', 'meta.method-call.js', 'meta.arguments.js', 'punctuation.definition.arguments.end.bracket.round.js']
17161724
17171725
describe "comments", ->
1726+
it "tokenizes // comments", ->
1727+
{tokens} = grammar.tokenizeLine '//'
1728+
expect(tokens[0]).toEqual value: '//', scopes: ['source.js', 'comment.line.double-slash.js', 'punctuation.definition.comment.js']
1729+
1730+
{tokens} = grammar.tokenizeLine '// stuff'
1731+
expect(tokens[0]).toEqual value: '//', scopes: ['source.js', 'comment.line.double-slash.js', 'punctuation.definition.comment.js']
1732+
expect(tokens[1]).toEqual value: ' stuff', scopes: ['source.js', 'comment.line.double-slash.js']
1733+
17181734
it "tokenizes /* */ comments", ->
17191735
{tokens} = grammar.tokenizeLine('/**/')
17201736
expect(tokens[0]).toEqual value: '/*', scopes: ['source.js', 'comment.block.js', 'punctuation.definition.comment.js']

0 commit comments

Comments
 (0)