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

Commit

Permalink
Add support for decorators
Browse files Browse the repository at this point in the history
Closes #163
  • Loading branch information
winstliu committed Aug 2, 2015
1 parent 3c8e493 commit b032a4b
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
57 changes: 57 additions & 0 deletions grammars/javascript.cson
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,63 @@
}
]
}
{
'begin': '^\\s*(?=@\\s*[A-Za-z_][A-Za-z0-9_]*(?:\\.[a-zA-Z_][a-zA-Z_0-9]*)*\\s*\\()'
'end': '(\\))'
'endCaptures':
'1':
'name': 'punctuation.definition.arguments.end.js'
'name': 'meta.function.decorator.js'
'patterns': [
{
'begin': '(?=(@)\\s*[A-Za-z_][A-Za-z0-9_]*(?:\\.[A-Za-z_][A-Za-z0-9_]*)*\\s*\\()'
'beginCaptures':
'1':
'name': 'punctuation.definition.decorator.js'
'contentName': 'entity.name.function.decorator.js'
'end': '(?=\\s*\\()'
}
{
'begin': '(\\()'
'beginCaptures':
'1':
'name': 'punctuation.definition.arguments.begin.js'
'contentName': 'meta.function.decorator.arguments.js'
'end': '(?=\\))'
'patterns': [
{
'include': '#function-params'
}
{
'include': '#comments'
}
{
'include': '$self'
}
]
}
]
}
{
'begin': '^\\s*(?=@\\s*[A-Za-z_][A-Za-z0-9_]*(?:\\.[a-zA-Z_][a-zA-Z_0-9]*)*)'
'contentName': 'entity.name.function.annotation.js'
'end': '(?=\\s|$\\n?|//)'
'name': 'meta.function.annotation.js'
'patterns': [
{
'begin': '(?=(@)\\s*[A-Za-z_][A-Za-z0-9_]*(\\.[A-Za-z_][A-Za-z0-9_]*)*)'
'beginCaptures':
'1':
'name': 'punctuation.definition.annotation.js'
'end': '(?=\\s|$\\n?|//)'
'patterns': [
{
'include': '#comments'
}
]
}
]
}
{
'begin': '\\b(constructor)\\s*(\\()'
'beginCaptures':
Expand Down
12 changes: 12 additions & 0 deletions spec/javascript-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,18 @@ describe "Javascript grammar", ->
expect(tokens[4]).toEqual value: ')', scopes: ['source.js', 'meta.function.arrow.js', 'punctuation.definition.parameters.end.js']
expect(tokens[5]).toEqual value: '=>', scopes: ['source.js', 'meta.function.arrow.js', 'storage.type.arrow.js']

describe "decorators and annotations", ->
it "tokenizes decorators", ->
{tokens} = grammar.tokenizeLine('@thisIsADecorator(true)')
expect(tokens[0]).toEqual value: '@thisIsADecorator', scopes: ['source.js', 'meta.function.decorator.js', 'entity.name.function.decorator.js']
expect(tokens[1]).toEqual value: '(', scopes: ['source.js', 'meta.function.decorator.js', 'punctuation.definition.arguments.begin.js']
expect(tokens[2]).toEqual value: 'true', scopes: ['source.js', 'meta.function.decorator.js', 'meta.function.decorator.arguments.js', 'variable.parameter.function.js']
expect(tokens[3]).toEqual value: ')', scopes: ['source.js', 'meta.function.decorator.js', 'punctuation.definition.arguments.end.js']

it "tokenizes annotations", ->
{tokens} = grammar.tokenizeLine('@thisIsAnAnnotation')
expect(tokens[0]).toEqual value: '@thisIsAnAnnotation', scopes: ['source.js', 'meta.function.annotation.js', 'entity.name.function.annotation.js']

describe "comments", ->
it "tokenizes /* */ comments", ->
{tokens} = grammar.tokenizeLine('/**/')
Expand Down

0 comments on commit b032a4b

Please sign in to comment.