Skip to content

Commit 2805ae3

Browse files
authoredJul 18, 2020
JSDoc: Improvements (#2466)
1 parent 398e294 commit 2805ae3

8 files changed

+220
-26
lines changed
 

‎components.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎components.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@
535535
},
536536
"jsdoc": {
537537
"title": "JSDoc",
538-
"require": ["javascript", "javadoclike"],
538+
"require": ["javascript", "javadoclike", "typescript"],
539539
"modify": "javascript",
540540
"optional": [
541541
"actionscript",

‎components/prism-jsdoc.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,22 @@
4040
},
4141
'class-name': [
4242
{
43-
pattern: RegExp('(@[a-z]+\\s+)' + type),
43+
pattern: RegExp(/(@(?:augments|extends|class|interface|memberof!?|template|this|typedef)\s+(?:<TYPE>\s+)?)[A-Z]\w*(?:\.[A-Z]\w*)*/.source.replace(/<TYPE>/g, function () { return type; })),
4444
lookbehind: true,
4545
inside: {
46-
'punctuation': /[.,:?=<>|{}()[\]]/
46+
'punctuation': /\./
4747
}
4848
},
4949
{
50-
pattern: /(@(?:augments|extends|class|interface|memberof!?|this)\s+)[A-Z]\w*(?:\.[A-Z]\w*)*/,
50+
pattern: RegExp('(@[a-z]+\\s+)' + type),
5151
lookbehind: true,
5252
inside: {
53-
'punctuation': /\./
53+
'string': javascript.string,
54+
'number': javascript.number,
55+
'boolean': javascript.boolean,
56+
'keyword': Prism.languages.typescript.keyword,
57+
'operator': /=>|\.\.\.|[&|?:*]/,
58+
'punctuation': /[.,;=<>{}()[\]]/
5459
}
5560
}
5661
],

‎components/prism-jsdoc.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎plugins/autoloader/prism-autoloader.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
"jolie": "clike",
6060
"jsdoc": [
6161
"javascript",
62-
"javadoclike"
62+
"javadoclike",
63+
"typescript"
6364
],
6465
"js-extras": "javascript",
6566
"json5": "json",

‎plugins/autoloader/prism-autoloader.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tests/languages/jsdoc/class-name_feature.test

+185-7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,26 @@
33
* @param {number | string}
44
* @param {Array.<number> | Object.<string, number>}
55
* @param {{[x: string]: {start: number, end?: number}}}
6+
* @param {readonly { min?: number; max: number | null | undefined }[]}
7+
* @param {null | 1 | 2}
8+
* @param {true | string}
9+
* @param {Type1 & Type2}
10+
* @param {typeof import("./foo").Bar}
11+
* @param {...any[]}
12+
* @param {*}
13+
* @param {() => void}
14+
*
15+
* @typedef Foo
16+
* @typedef {Bar} Foo
17+
* @template Foo
18+
* @template {Bar} Foo
19+
* @augments Foo
20+
* @extends Foo
21+
* @class Foo
22+
* @interface Foo
23+
* @memberof Foo
24+
* @memberof! Foo
25+
* @this Foo
626
*/
727

828
----------------------------------------------------
@@ -20,7 +40,7 @@
2040
["class-name", [
2141
["punctuation", "{"],
2242
"number ",
23-
["punctuation", "|"],
43+
["operator", "|"],
2444
" string",
2545
["punctuation", "}"]
2646
]],
@@ -33,7 +53,7 @@
3353
["punctuation", "<"],
3454
"number",
3555
["punctuation", ">"],
36-
["punctuation", "|"],
56+
["operator", "|"],
3757
" Object",
3858
["punctuation", "."],
3959
["punctuation", "<"],
@@ -50,23 +70,181 @@
5070
["punctuation", "{"],
5171
["punctuation", "["],
5272
"x",
53-
["punctuation", ":"],
73+
["operator", ":"],
5474
" string",
5575
["punctuation", "]"],
56-
["punctuation", ":"],
76+
["operator", ":"],
5777
["punctuation", "{"],
5878
"start",
59-
["punctuation", ":"],
79+
["operator", ":"],
6080
" number",
6181
["punctuation", ","],
6282
" end",
63-
["punctuation", "?"],
64-
["punctuation", ":"],
83+
["operator", "?"],
84+
["operator", ":"],
6585
" number",
6686
["punctuation", "}"],
6787
["punctuation", "}"],
6888
["punctuation", "}"]
6989
]],
90+
"\n * ",
91+
["keyword", "@param"],
92+
["class-name", [
93+
["punctuation", "{"],
94+
["keyword", "readonly"],
95+
["punctuation", "{"],
96+
" min",
97+
["operator", "?"],
98+
["operator", ":"],
99+
" number",
100+
["punctuation", ";"],
101+
" max",
102+
["operator", ":"],
103+
" number ",
104+
["operator", "|"],
105+
["keyword", "null"],
106+
["operator", "|"],
107+
["keyword", "undefined"],
108+
["punctuation", "}"],
109+
["punctuation", "["],
110+
["punctuation", "]"],
111+
["punctuation", "}"]
112+
]],
113+
"\n * ",
114+
["keyword", "@param"],
115+
["class-name", [
116+
["punctuation", "{"],
117+
["keyword", "null"],
118+
["operator", "|"],
119+
["number", "1"],
120+
["operator", "|"],
121+
["number", "2"],
122+
["punctuation", "}"]
123+
]],
124+
"\n * ",
125+
["keyword", "@param"],
126+
["class-name", [
127+
["punctuation", "{"],
128+
["boolean", "true"],
129+
["operator", "|"],
130+
" string",
131+
["punctuation", "}"]
132+
]],
133+
"\n * ",
134+
["keyword", "@param"],
135+
["class-name", [
136+
["punctuation", "{"],
137+
"Type1 ",
138+
["operator", "&"],
139+
" Type2",
140+
["punctuation", "}"]
141+
]],
142+
"\n * ",
143+
["keyword", "@param"],
144+
["class-name", [
145+
["punctuation", "{"],
146+
["keyword", "typeof"],
147+
["keyword", "import"],
148+
["punctuation", "("],
149+
["string", "\"./foo\""],
150+
["punctuation", ")"],
151+
["punctuation", "."],
152+
"Bar",
153+
["punctuation", "}"]
154+
]],
155+
"\n * ",
156+
["keyword", "@param"],
157+
["class-name", [
158+
["punctuation", "{"],
159+
["operator", "..."],
160+
"any",
161+
["punctuation", "["],
162+
["punctuation", "]"],
163+
["punctuation", "}"]
164+
]],
165+
"\n * ",
166+
["keyword", "@param"],
167+
["class-name", [
168+
["punctuation", "{"],
169+
["operator", "*"],
170+
["punctuation", "}"]
171+
]],
172+
"\n * ",
173+
["keyword", "@param"],
174+
["class-name", [
175+
["punctuation", "{"],
176+
["punctuation", "("],
177+
["punctuation", ")"],
178+
["operator", "=>"],
179+
["keyword", "void"],
180+
["punctuation", "}"]
181+
]],
182+
"\n *\n * ",
183+
["keyword", "@typedef"],
184+
["class-name", [
185+
"Foo"
186+
]],
187+
"\n * ",
188+
["keyword", "@typedef"],
189+
["class-name", [
190+
["punctuation", "{"],
191+
"Bar",
192+
["punctuation", "}"]
193+
]],
194+
["class-name", [
195+
"Foo"
196+
]],
197+
"\n * ",
198+
["keyword", "@template"],
199+
["class-name", [
200+
"Foo"
201+
]],
202+
"\n * ",
203+
["keyword", "@template"],
204+
["class-name", [
205+
["punctuation", "{"],
206+
"Bar",
207+
["punctuation", "}"]
208+
]],
209+
["class-name", [
210+
"Foo"
211+
]],
212+
"\n * ",
213+
["keyword", "@augments"],
214+
["class-name", [
215+
"Foo"
216+
]],
217+
"\n * ",
218+
["keyword", "@extends"],
219+
["class-name", [
220+
"Foo"
221+
]],
222+
"\n * ",
223+
["keyword", "@class"],
224+
["class-name", [
225+
"Foo"
226+
]],
227+
"\n * ",
228+
["keyword", "@interface"],
229+
["class-name", [
230+
"Foo"
231+
]],
232+
"\n * ",
233+
["keyword", "@memberof"],
234+
["class-name", [
235+
"Foo"
236+
]],
237+
"\n * ",
238+
["keyword", "@memberof"],
239+
"! ",
240+
["class-name", [
241+
"Foo"
242+
]],
243+
"\n * ",
244+
["keyword", "@this"],
245+
["class-name", [
246+
"Foo"
247+
]],
70248
"\n */"
71249
]
72250

‎tests/languages/jsdoc/parameter_feature.test

+20-10
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,25 @@
1212
[
1313
"/**\n * ",
1414
["keyword", "@param"],
15-
["parameter", ["n"]],
15+
["parameter", [
16+
"n"
17+
]],
1618
" - A number.\n * ",
1719
["keyword", "@param"],
1820
["optional-parameter", [
1921
["punctuation", "["],
20-
["parameter", ["n"]],
22+
["parameter", [
23+
"n"
24+
]],
2125
["punctuation", "]"]
2226
]],
2327
" - A number.\n * ",
2428
["keyword", "@param"],
2529
["optional-parameter", [
2630
["punctuation", "["],
27-
["parameter", ["n"]],
31+
["parameter", [
32+
"n"
33+
]],
2834
["punctuation", "="],
2935
["code", [
3036
["number", "1"],
@@ -40,32 +46,36 @@
4046
"number",
4147
["punctuation", "}"]
4248
]],
43-
["parameter", ["n"]],
49+
["parameter", [
50+
"n"
51+
]],
4452
" - A number.\n * ",
4553
["keyword", "@param"],
4654
["class-name", [
4755
["punctuation", "{"],
4856
["punctuation", "{"],
4957
["punctuation", "["],
5058
"x",
51-
["punctuation", ":"],
59+
["operator", ":"],
5260
" string",
5361
["punctuation", "]"],
54-
["punctuation", ":"],
62+
["operator", ":"],
5563
["punctuation", "{"],
5664
"start",
57-
["punctuation", ":"],
65+
["operator", ":"],
5866
" number",
5967
["punctuation", ","],
6068
" end",
61-
["punctuation", "?"],
62-
["punctuation", ":"],
69+
["operator", "?"],
70+
["operator", ":"],
6371
" number",
6472
["punctuation", "}"],
6573
["punctuation", "}"],
6674
["punctuation", "}"]
6775
]],
68-
["parameter", ["map"]],
76+
["parameter", [
77+
"map"
78+
]],
6979
"\n * ",
7080
["keyword", "@param"],
7181
["class-name", [

0 commit comments

Comments
 (0)
Please sign in to comment.