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

Commit c53a055

Browse files
committed
Merge pull request #134 from AMalininHere/master
Added methods support
2 parents 75687f0 + 373e3a6 commit c53a055

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

grammars/javascript.cson

+28
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@
241241
}
242242
]
243243
}
244+
{
245+
'include': '#methods'
246+
}
244247
{
245248
'match': '\\b(class)(?:(?:\\s+(extends)\\s+(\\w+(?:\\.\\w*)?))|(?:(?:\\s+(\\w+(?:\\.\\w*)?))(?:\\s+(extends)\\s+(\\w+(?:\\.\\w*)?))?))'
246249
'captures':
@@ -521,6 +524,31 @@
521524
]
522525
}
523526
]
527+
'methods':
528+
'patterns': [
529+
{
530+
'name': 'meta.method.js'
531+
'comment': 'match regular function like: function myFunc(arg) { … }'
532+
533+
'begin': '\\b((?!(?:break|case|catch|continue|do|else|finally|for|function|if|export|import|package|return|switch|throw|try|while|with)[\\s\\(])(?:[a-zA-Z_$][a-zA-Z_$0-9]*))\\s*(\\()(?=(?:[^\\(\\)]*)?\\)\\s*\\{)'
534+
'beginCaptures':
535+
'1':
536+
'name': 'entity.name.function.js'
537+
'2':
538+
'name': 'punctuation.definition.parameters.begin.js'
539+
540+
'patterns': [
541+
{
542+
'include': '#function-params'
543+
}
544+
]
545+
546+
'end': '(\\))'
547+
'endCaptures':
548+
'1':
549+
'name': 'punctuation.definition.parameters.end.js'
550+
}
551+
]
524552
'function-params':
525553
'patterns': [
526554
{

spec/javascript-spec.coffee

+8
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,14 @@ describe "Javascript grammar", ->
235235
expect(tokens[8]).toEqual value: 'nonAnonymous', scopes: ['source.js', 'meta.function.js', 'entity.name.function.js']
236236
expect(tokens[9]).toEqual value: '(', scopes: ['source.js', 'meta.function.js', 'punctuation.definition.parameters.begin.js']
237237

238+
it "tokenizes methods", ->
239+
{tokens} = grammar.tokenizeLine('f(a, b) {}')
240+
expect(tokens[0]).toEqual value: 'f', scopes: ['source.js', 'meta.method.js', 'entity.name.function.js']
241+
expect(tokens[1]).toEqual value: '(', scopes: ['source.js', 'meta.method.js', 'punctuation.definition.parameters.begin.js']
242+
expect(tokens[2]).toEqual value: 'a', scopes: ['source.js', 'meta.method.js', 'variable.parameter.function.js']
243+
expect(tokens[4]).toEqual value: 'b', scopes: ['source.js', 'meta.method.js', 'variable.parameter.function.js']
244+
expect(tokens[5]).toEqual value: ')', scopes: ['source.js', 'meta.method.js', 'punctuation.definition.parameters.end.js']
245+
238246
it "tokenizes functions", ->
239247
{tokens} = grammar.tokenizeLine('var func = function nonAnonymous(')
240248

0 commit comments

Comments
 (0)