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

Commit 87bb934

Browse files
author
Wliu
authored
Merge pull request #472 from Alhadis/jsdoc-fixes
Fix various highlighting bugs
2 parents bd1d81a + 2bd0949 commit 87bb934

File tree

2 files changed

+96
-5
lines changed

2 files changed

+96
-5
lines changed

grammars/javascript.cson

+18-5
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@
286286
]
287287
}
288288
{
289-
'match': '(?<!\\.)\\b(?<!\\$)(super|this|arguments)(?!\\s*:|\\$)\\b'
289+
'match': '(?:(?<=\\.{3})|(?<!\\.)\\b)(?<!\\$)(super|this|arguments)(?!\\s*:|\\$)\\b'
290290
'name': 'variable.language.js'
291291
}
292292
{
@@ -1926,6 +1926,7 @@
19261926
\\? | # {?string} nullable type
19271927
! | # {!string} non-nullable type
19281928
\\.{3} # {...string} variable number of parameters
1929+
[*?]? # {...*} Variable number of mixed types
19291930
)?
19301931
19311932
(?:
@@ -2052,7 +2053,9 @@
20522053
(?:
20532054
[\\w$\\s]* | # [foo=bar] Unquoted
20542055
"[^"]*" | # [foo="bar"] Double-quoted
2055-
'[^']*' # [foo='bar'] Single-quoted
2056+
'[^']*' | # [foo='bar'] Single-quoted
2057+
{[^{}]*} | # [foo={a:1}] Object literal
2058+
\\[ [^\\[\\]]* \\] # [foo=[1,2]] Array literal
20562059
)
20572060
)?
20582061
)
@@ -2097,6 +2100,7 @@
20972100
\\? | # {?string} nullable type
20982101
! | # {!string} non-nullable type
20992102
\\.{3} # {...string} variable number of parameters
2103+
[*?]? # {...*} Variable number of mixed types
21002104
)?
21012105
21022106
(?:
@@ -2164,21 +2168,30 @@
21642168
\\( # Opening bracket of multiple types with parenthesis {(string|number)}
21652169
[a-zA-Z_$]+
21662170
(?:
2167-
[\\w$]* |
2171+
(?:
2172+
[\\w$]*
2173+
(?:\\[\\])? # {(string[]|number)} type application, an array of strings or a number
2174+
) |
21682175
\\.?<[\\w$]+(?:,\\s+[\\w$]+)*> # {Array<string>} or {Object<string, number>} type application (optional .)
21692176
)
21702177
(?:
21712178
[\\.|~] # {Foo.bar} namespaced, {string|number} multiple, {Foo~bar} class-specific callback
21722179
[a-zA-Z_$]+
21732180
(?:
2174-
[\\w$]* |
2181+
(?:
2182+
[\\w$]*
2183+
(?:\\[\\])? # {(string|number[])} type application, a string or an array of numbers
2184+
) |
21752185
\\.?<[\\w$]+(?:,\\s+[\\w$]+)*> # {Array<string>} or {Object<string, number>} type application (optional .)
21762186
)
21772187
)*
21782188
\\) |
21792189
[a-zA-Z_$]+
21802190
(?:
2181-
[\\w$]* |
2191+
(?:
2192+
[\\w$]*
2193+
(?:\\[\\])? # {(string|number[])} type application, a string or an array of numbers
2194+
) |
21822195
\\.?<[\\w$]+(?:,\\s+[\\w$]+)*> # {Array<string>} or {Object<string, number>} type application (optional .)
21832196
)
21842197
(?:

spec/javascript-spec.coffee

+78
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,18 @@ describe "JavaScript grammar", ->
305305
expect(tokens[1]).toEqual value: '...', scopes: ['source.js', 'keyword.operator.spread.js']
306306
expect(tokens[2]).toEqual value: 'iterableObj', scopes: ['source.js']
307307

308+
{tokens} = grammar.tokenizeLine('...arguments')
309+
expect(tokens[0]).toEqual value: '...', scopes: ['source.js', 'keyword.operator.spread.js']
310+
expect(tokens[1]).toEqual value: 'arguments', scopes: ['source.js', 'variable.language.js']
311+
312+
{tokens} = grammar.tokenizeLine('...super')
313+
expect(tokens[0]).toEqual value: '...', scopes: ['source.js', 'keyword.operator.spread.js']
314+
expect(tokens[1]).toEqual value: 'super', scopes: ['source.js', 'variable.language.js']
315+
316+
{tokens} = grammar.tokenizeLine('...this')
317+
expect(tokens[0]).toEqual value: '...', scopes: ['source.js', 'keyword.operator.spread.js']
318+
expect(tokens[1]).toEqual value: 'this', scopes: ['source.js', 'variable.language.js']
319+
308320
describe "increment, decrement", ->
309321
it "tokenizes increment", ->
310322
{tokens} = grammar.tokenizeLine('i++')
@@ -2063,6 +2075,54 @@ describe "JavaScript grammar", ->
20632075
expect(tokens[6]).toEqual value: "[ variable = ' default value ' ]", scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'variable.other.jsdoc']
20642076
expect(tokens[8]).toEqual value: 'this is the description ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc']
20652077
2078+
{tokens} = grammar.tokenizeLine('/** @param {Object} [variable={a: "b"}] - An object */')
2079+
expect(tokens[4]).toEqual value: '{Object}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc']
2080+
expect(tokens[6]).toEqual value: '[variable={a: "b"}]', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'variable.other.jsdoc']
2081+
expect(tokens[7]).toEqual value: ' - ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc']
2082+
expect(tokens[8]).toEqual value: 'An object ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc']
2083+
2084+
{tokens} = grammar.tokenizeLine('/** @param {Object} [ variable = { a : "b" } ] - An object */')
2085+
expect(tokens[4]).toEqual value: '{Object}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc']
2086+
expect(tokens[6]).toEqual value: '[ variable = { a : "b" } ]', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'variable.other.jsdoc']
2087+
expect(tokens[7]).toEqual value: ' - ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc']
2088+
expect(tokens[8]).toEqual value: 'An object ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc']
2089+
2090+
{tokens} = grammar.tokenizeLine('/** @param {Array} [variable=[1,2,3]] - An array */')
2091+
expect(tokens[4]).toEqual value: '{Array}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc']
2092+
expect(tokens[6]).toEqual value: '[variable=[1,2,3]]', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'variable.other.jsdoc']
2093+
expect(tokens[7]).toEqual value: ' - ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc']
2094+
expect(tokens[8]).toEqual value: 'An array ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc']
2095+
2096+
{tokens} = grammar.tokenizeLine('/** @param {Array} [ variable = [ 1 , 2 , 3 ] ] - An array */')
2097+
expect(tokens[4]).toEqual value: '{Array}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc']
2098+
expect(tokens[6]).toEqual value: '[ variable = [ 1 , 2 , 3 ] ]', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'variable.other.jsdoc']
2099+
expect(tokens[7]).toEqual value: ' - ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc']
2100+
expect(tokens[8]).toEqual value: 'An array ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc']
2101+
2102+
{tokens} = grammar.tokenizeLine('/** @param {Object} [variable={}] - Empty object */')
2103+
expect(tokens[4]).toEqual value: '{Object}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc']
2104+
expect(tokens[6]).toEqual value: '[variable={}]', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'variable.other.jsdoc']
2105+
expect(tokens[7]).toEqual value: ' - ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc']
2106+
expect(tokens[8]).toEqual value: 'Empty object ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc']
2107+
2108+
{tokens} = grammar.tokenizeLine('/** @param {Object} [ variable = { } ] - Empty object */')
2109+
expect(tokens[4]).toEqual value: '{Object}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc']
2110+
expect(tokens[6]).toEqual value: '[ variable = { } ]', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'variable.other.jsdoc']
2111+
expect(tokens[7]).toEqual value: ' - ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc']
2112+
expect(tokens[8]).toEqual value: 'Empty object ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc']
2113+
2114+
{tokens} = grammar.tokenizeLine('/** @param {Array} [variable=[]] - Empty array */')
2115+
expect(tokens[4]).toEqual value: '{Array}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc']
2116+
expect(tokens[6]).toEqual value: '[variable=[]]', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'variable.other.jsdoc']
2117+
expect(tokens[7]).toEqual value: ' - ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc']
2118+
expect(tokens[8]).toEqual value: 'Empty array ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc']
2119+
2120+
{tokens} = grammar.tokenizeLine('/** @param {Array} [ variable = [ ] ] - Empty array */')
2121+
expect(tokens[4]).toEqual value: '{Array}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc']
2122+
expect(tokens[6]).toEqual value: '[ variable = [ ] ]', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'variable.other.jsdoc']
2123+
expect(tokens[7]).toEqual value: ' - ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc']
2124+
expect(tokens[8]).toEqual value: 'Empty array ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc']
2125+
20662126
{tokens} = grammar.tokenizeLine('/** @param {object} variable - this is a {@link linked} description */')
20672127
expect(tokens[6]).toEqual value: 'variable', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'variable.other.jsdoc']
20682128
expect(tokens[8]).toEqual value: 'this is a ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc']
@@ -2182,6 +2242,16 @@ describe "JavaScript grammar", ->
21822242
expect(tokens[6]).toEqual value: 'variable', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'variable.other.jsdoc']
21832243
expect(tokens[8]).toEqual value: 'this is the description ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc']
21842244
2245+
{tokens} = grammar.tokenizeLine('/** @param {...*} remainder */')
2246+
expect(tokens[2]).toEqual value: '@param', scopes: ['source.js', 'comment.block.documentation.js', 'storage.type.class.jsdoc']
2247+
expect(tokens[4]).toEqual value: '{...*}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc']
2248+
expect(tokens[6]).toEqual value: 'remainder', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'variable.other.jsdoc']
2249+
2250+
{tokens} = grammar.tokenizeLine('/** @param {...?} remainder */')
2251+
expect(tokens[2]).toEqual value: '@param', scopes: ['source.js', 'comment.block.documentation.js', 'storage.type.class.jsdoc']
2252+
expect(tokens[4]).toEqual value: '{...?}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc']
2253+
expect(tokens[6]).toEqual value: 'remainder', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'variable.other.jsdoc']
2254+
21852255
{tokens} = grammar.tokenizeLine('/** @param {number=} variable this is the description */')
21862256
expect(tokens[4]).toEqual value: '{number=}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc']
21872257
expect(tokens[6]).toEqual value: 'variable', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'variable.other.jsdoc']
@@ -2339,6 +2409,14 @@ describe "JavaScript grammar", ->
23392409
{tokens} = grammar.tokenizeLine('/** @return {Some|Thing} Something to return */')
23402410
expect(tokens[4]).toEqual value: '{Some|Thing}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc']
23412411
2412+
{tokens} = grammar.tokenizeLine('/** @return {(String[]|Number[])} Description */')
2413+
expect(tokens[4]).toEqual value: '{(String[]|Number[])}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc']
2414+
expect(tokens[6]).toEqual value: 'Description ', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'other.description.jsdoc']
2415+
2416+
{tokens} = grammar.tokenizeLine('/** @param {(Number|Number[])} Numbers */')
2417+
expect(tokens[4]).toEqual value: '{(Number|Number[])}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc']
2418+
expect(tokens[6]).toEqual value: 'Numbers', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'variable.other.jsdoc']
2419+
23422420
{tokens} = grammar.tokenizeLine('/** @return {object} */')
23432421
expect(tokens[4]).toEqual value: '{object}', scopes: ['source.js', 'comment.block.documentation.js', 'other.meta.jsdoc', 'entity.name.type.instance.jsdoc']
23442422

0 commit comments

Comments
 (0)