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

Commit b032a4b

Browse files
committed
Add support for decorators
Closes #163
1 parent 3c8e493 commit b032a4b

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

grammars/javascript.cson

+57
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,63 @@
258258
}
259259
]
260260
}
261+
{
262+
'begin': '^\\s*(?=@\\s*[A-Za-z_][A-Za-z0-9_]*(?:\\.[a-zA-Z_][a-zA-Z_0-9]*)*\\s*\\()'
263+
'end': '(\\))'
264+
'endCaptures':
265+
'1':
266+
'name': 'punctuation.definition.arguments.end.js'
267+
'name': 'meta.function.decorator.js'
268+
'patterns': [
269+
{
270+
'begin': '(?=(@)\\s*[A-Za-z_][A-Za-z0-9_]*(?:\\.[A-Za-z_][A-Za-z0-9_]*)*\\s*\\()'
271+
'beginCaptures':
272+
'1':
273+
'name': 'punctuation.definition.decorator.js'
274+
'contentName': 'entity.name.function.decorator.js'
275+
'end': '(?=\\s*\\()'
276+
}
277+
{
278+
'begin': '(\\()'
279+
'beginCaptures':
280+
'1':
281+
'name': 'punctuation.definition.arguments.begin.js'
282+
'contentName': 'meta.function.decorator.arguments.js'
283+
'end': '(?=\\))'
284+
'patterns': [
285+
{
286+
'include': '#function-params'
287+
}
288+
{
289+
'include': '#comments'
290+
}
291+
{
292+
'include': '$self'
293+
}
294+
]
295+
}
296+
]
297+
}
298+
{
299+
'begin': '^\\s*(?=@\\s*[A-Za-z_][A-Za-z0-9_]*(?:\\.[a-zA-Z_][a-zA-Z_0-9]*)*)'
300+
'contentName': 'entity.name.function.annotation.js'
301+
'end': '(?=\\s|$\\n?|//)'
302+
'name': 'meta.function.annotation.js'
303+
'patterns': [
304+
{
305+
'begin': '(?=(@)\\s*[A-Za-z_][A-Za-z0-9_]*(\\.[A-Za-z_][A-Za-z0-9_]*)*)'
306+
'beginCaptures':
307+
'1':
308+
'name': 'punctuation.definition.annotation.js'
309+
'end': '(?=\\s|$\\n?|//)'
310+
'patterns': [
311+
{
312+
'include': '#comments'
313+
}
314+
]
315+
}
316+
]
317+
}
261318
{
262319
'begin': '\\b(constructor)\\s*(\\()'
263320
'beginCaptures':

spec/javascript-spec.coffee

+12
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,18 @@ describe "Javascript grammar", ->
478478
expect(tokens[4]).toEqual value: ')', scopes: ['source.js', 'meta.function.arrow.js', 'punctuation.definition.parameters.end.js']
479479
expect(tokens[5]).toEqual value: '=>', scopes: ['source.js', 'meta.function.arrow.js', 'storage.type.arrow.js']
480480

481+
describe "decorators and annotations", ->
482+
it "tokenizes decorators", ->
483+
{tokens} = grammar.tokenizeLine('@thisIsADecorator(true)')
484+
expect(tokens[0]).toEqual value: '@thisIsADecorator', scopes: ['source.js', 'meta.function.decorator.js', 'entity.name.function.decorator.js']
485+
expect(tokens[1]).toEqual value: '(', scopes: ['source.js', 'meta.function.decorator.js', 'punctuation.definition.arguments.begin.js']
486+
expect(tokens[2]).toEqual value: 'true', scopes: ['source.js', 'meta.function.decorator.js', 'meta.function.decorator.arguments.js', 'variable.parameter.function.js']
487+
expect(tokens[3]).toEqual value: ')', scopes: ['source.js', 'meta.function.decorator.js', 'punctuation.definition.arguments.end.js']
488+
489+
it "tokenizes annotations", ->
490+
{tokens} = grammar.tokenizeLine('@thisIsAnAnnotation')
491+
expect(tokens[0]).toEqual value: '@thisIsAnAnnotation', scopes: ['source.js', 'meta.function.annotation.js', 'entity.name.function.annotation.js']
492+
481493
describe "comments", ->
482494
it "tokenizes /* */ comments", ->
483495
{tokens} = grammar.tokenizeLine('/**/')

0 commit comments

Comments
 (0)