diff --git a/grammars/javascript.cson b/grammars/javascript.cson index 7c321d56..b6505767 100644 --- a/grammars/javascript.cson +++ b/grammars/javascript.cson @@ -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': diff --git a/spec/javascript-spec.coffee b/spec/javascript-spec.coffee index ac698bc6..e49c9050 100644 --- a/spec/javascript-spec.coffee +++ b/spec/javascript-spec.coffee @@ -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('/**/')