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

Commit d59666c

Browse files
author
Wliu
authored
Merge pull request #455 from bgriffith/feature/jsdoc-func-return
Add JSDoc support for function return type
2 parents 3b12774 + 2e551b8 commit d59666c

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

grammars/javascript.cson

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,6 +1945,10 @@
19451945
)?
19461946
\\s*
19471947
\\)
1948+
(?: # {function(): string} function return type
1949+
\\s*:\\s*
1950+
[a-zA-Z_$][\\w$]*
1951+
)?
19481952
)?
19491953
|
19501954
(?:
@@ -2063,6 +2067,10 @@
20632067
)?
20642068
\\s*
20652069
\\)
2070+
(?: # {function(): string} function return type
2071+
\\s*:\\s*
2072+
[a-zA-Z_$][\\w$]*
2073+
)?
20662074
)?
20672075
|
20682076
(?:

spec/javascript-spec.coffee

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2037,6 +2037,21 @@ describe "JavaScript grammar", ->
20372037
expect(tokens[6]).toEqual value: 'variable', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'variable.other.jsdoc']
20382038
expect(tokens[8]).toEqual value: 'this is the description ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc']
20392039
2040+
{tokens} = grammar.tokenizeLine('/** @param {function():number} variable this is the description */')
2041+
expect(tokens[4]).toEqual value: '{function():number}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc']
2042+
expect(tokens[6]).toEqual value: 'variable', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'variable.other.jsdoc']
2043+
expect(tokens[8]).toEqual value: 'this is the description ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc']
2044+
2045+
{tokens} = grammar.tokenizeLine('/** @param {function(string): number} variable this is the description */')
2046+
expect(tokens[4]).toEqual value: '{function(string): number}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc']
2047+
expect(tokens[6]).toEqual value: 'variable', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'variable.other.jsdoc']
2048+
expect(tokens[8]).toEqual value: 'this is the description ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc']
2049+
2050+
{tokens} = grammar.tokenizeLine('/** @param {function(string) : number} variable this is the description */')
2051+
expect(tokens[4]).toEqual value: '{function(string) : number}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc']
2052+
expect(tokens[6]).toEqual value: 'variable', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'variable.other.jsdoc']
2053+
expect(tokens[8]).toEqual value: 'this is the description ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc']
2054+
20402055
{tokens} = grammar.tokenizeLine('/** @return {object} this is the description */')
20412056
expect(tokens[4]).toEqual value: '{object}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc']
20422057
expect(tokens[6]).toEqual value: 'this is the description ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc']
@@ -2077,6 +2092,18 @@ describe "JavaScript grammar", ->
20772092
expect(tokens[4]).toEqual value: '{function(string, number)}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc']
20782093
expect(tokens[6]).toEqual value: 'this is the description ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc']
20792094
2095+
{tokens} = grammar.tokenizeLine('/** @return {function():number} this is the description */')
2096+
expect(tokens[4]).toEqual value: '{function():number}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc']
2097+
expect(tokens[6]).toEqual value: 'this is the description ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc']
2098+
2099+
{tokens} = grammar.tokenizeLine('/** @return {function(string): number} this is the description */')
2100+
expect(tokens[4]).toEqual value: '{function(string): number}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc']
2101+
expect(tokens[6]).toEqual value: 'this is the description ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc']
2102+
2103+
{tokens} = grammar.tokenizeLine('/** @return {function(string) : number} this is the description */')
2104+
expect(tokens[4]).toEqual value: '{function(string) : number}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc']
2105+
expect(tokens[6]).toEqual value: 'this is the description ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc']
2106+
20802107
it "tokenizes // comments", ->
20812108
{tokens} = grammar.tokenizeLine('// comment')
20822109
expect(tokens[0]).toEqual value: '//', scopes: ['source.js', 'comment.line.double-slash.js', 'punctuation.definition.comment.js']

0 commit comments

Comments
 (0)