Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit cd6d3c2

Browse files
committed
Tokenize console, Math methods after comments
1 parent 7bddd57 commit cd6d3c2

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

grammars/javascript.cson

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -708,13 +708,16 @@
708708
'name': 'entity.name.type.object.console.js'
709709
'end': '''(?x)
710710
(?<=\\)) | (?=
711-
(?! \\s*(\\.)\\s*
711+
(?! (\\s*//)|(\\s*/\\*)|(\\s*(\\.)\\s*
712712
(assert|clear|debug|error|info|log|profile|profileEnd|time|timeEnd|warn)
713713
\\s*\\(
714-
) \\s*\\S
714+
)) \\s*\\S
715715
)
716716
'''
717717
'patterns': [
718+
{
719+
'include': '#comments'
720+
}
718721
{
719722
'begin': '\\s*(\\.)\\s*(\\w+)\\s*(?=\\()'
720723
'beginCaptures':
@@ -741,15 +744,18 @@
741744
'end': '''(?x)
742745
(?<=E|LN10|LN2|LOG10E|LOG2E|PI|SQRT1_2|SQRT2|\\)
743746
) | (?=
744-
(?! \\s*\\.\\s* (
747+
(?! (\\s*//)|(\\s*/\\*)|(\\s*\\.\\s* (
745748
((abs|acos|acosh|asin|asinh|atan|atan2|atanh|cbrt|ceil|clz32|cos|cosh|exp|
746749
expm1|floor|fround|hypot|imul|log|log10|log1p|log2|max|min|pow|random|
747750
round|sign|sin|sinh|sqrt|tan|tanh|trunc)\\s*\\(
748751
) | (E|LN10|LN2|LOG10E|LOG2E|PI|SQRT1_2|SQRT2)(?!\\s*[\\w$(]))
749-
) \\s*\\S
752+
)) \\s*\\S
750753
)
751754
'''
752755
'patterns': [
756+
{
757+
'include': '#comments'
758+
}
753759
{
754760
# Math.random()
755761
'begin': '\\s*(\\.)\\s*(\\w+)\\s*(?=\\()'

spec/javascript-spec.coffee

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,6 +1564,15 @@ describe "Javascript grammar", ->
15641564
expect(tokens[4]).toEqual value: ')', scopes: ['source.js', 'meta.method-call.js', 'meta.arguments.js', 'punctuation.definition.arguments.end.bracket.round.js']
15651565
expect(tokens[6]).not.toEqual value: 'log', scopes: ['source.js', 'meta.method-call.js', 'support.function.console.js']
15661566

1567+
{tokens} = grammar.tokenizeLine('console/**/.log()')
1568+
expect(tokens[0]).toEqual value: 'console', scopes: ['source.js', 'entity.name.type.object.console.js']
1569+
expect(tokens[1]).toEqual value: '/*', scopes: ['source.js', 'comment.block.js', 'punctuation.definition.comment.js']
1570+
expect(tokens[2]).toEqual value: '*/', scopes: ['source.js', 'comment.block.js', 'punctuation.definition.comment.js']
1571+
expect(tokens[3]).toEqual value: '.', scopes: ['source.js', 'meta.method-call.js', 'meta.delimiter.method.period.js']
1572+
expect(tokens[4]).toEqual value: 'log', scopes: ['source.js', 'meta.method-call.js', 'support.function.console.js']
1573+
expect(tokens[5]).toEqual value: '(', scopes: ['source.js', 'meta.method-call.js', 'meta.arguments.js', 'punctuation.definition.arguments.begin.bracket.round.js']
1574+
expect(tokens[6]).toEqual value: ')', scopes: ['source.js', 'meta.method-call.js', 'meta.arguments.js', 'punctuation.definition.arguments.end.bracket.round.js']
1575+
15671576
lines = grammar.tokenizeLines '''
15681577
console
15691578
.log();

0 commit comments

Comments
 (0)