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

Add support for decorators #187

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions grammars/javascript.cson
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,21 @@
'name': 'entity.name.type.js'
'name': 'meta.class.js'
}
{
'begin': '^\\s*(@)\\s*([A-Za-z_$][\\w$]*)'
'beginCaptures':
'1':
'name': 'punctuation.definition.decorator.js'
'2':
'name': 'entity.name.function.decorator.js'
'end': '(?<=\\))|$'
'name': 'meta.function.decorator.js'
'patterns': [
{
'include': '#arguments'
}
]
}
{
'captures':
'1':
Expand Down
18 changes: 18 additions & 0 deletions spec/javascript-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,24 @@ describe "Javascript grammar", ->
expect(tokens[14]).toEqual value: delim, scopes: ['source.js', 'meta.method-call.js', 'meta.arguments.js', scope, 'punctuation.definition.string.end.js']
expect(tokens[15]).toEqual value: ')', scopes: ['source.js', 'meta.method-call.js', 'meta.arguments.js', 'punctuation.definition.arguments.end.bracket.round.js']

describe "decorators", ->
it "tokenizes decorators with arguments", ->
{tokens} = grammar.tokenizeLine('@deprecate("nope", true)')
expect(tokens[0]).toEqual value: '@', scopes: ['source.js', 'meta.function.decorator.js', 'punctuation.definition.decorator.js']
expect(tokens[1]).toEqual value: 'deprecate', scopes: ['source.js', 'meta.function.decorator.js', 'entity.name.function.decorator.js']
expect(tokens[2]).toEqual value: '(', scopes: ['source.js', 'meta.function.decorator.js', 'meta.arguments.js', 'punctuation.definition.arguments.begin.bracket.round.js']
expect(tokens[3]).toEqual value: '"', scopes: ['source.js', 'meta.function.decorator.js', 'meta.arguments.js', 'string.quoted.double.js', 'punctuation.definition.string.begin.js']
expect(tokens[4]).toEqual value: 'nope', scopes: ['source.js', 'meta.function.decorator.js', 'meta.arguments.js', 'string.quoted.double.js']
expect(tokens[5]).toEqual value: '"', scopes: ['source.js', 'meta.function.decorator.js', 'meta.arguments.js', 'string.quoted.double.js', 'punctuation.definition.string.end.js']
expect(tokens[6]).toEqual value: ',', scopes: ['source.js', 'meta.function.decorator.js', 'meta.arguments.js', 'meta.delimiter.object.comma.js']
expect(tokens[8]).toEqual value: 'true', scopes: ['source.js', 'meta.function.decorator.js', 'meta.arguments.js', 'constant.language.boolean.true.js']
expect(tokens[9]).toEqual value: ')', scopes: ['source.js', 'meta.function.decorator.js', 'meta.arguments.js', 'punctuation.definition.arguments.end.bracket.round.js']

it "tokenizes decorators with no arguments", ->
{tokens} = grammar.tokenizeLine('@deprecate')
expect(tokens[0]).toEqual value: '@', scopes: ['source.js', 'meta.function.decorator.js', 'punctuation.definition.decorator.js']
expect(tokens[1]).toEqual value: 'deprecate', scopes: ['source.js', 'meta.function.decorator.js', 'entity.name.function.decorator.js']

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