Skip to content

Commit

Permalink
JSDoc: Improvements (#2466)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment committed Jul 18, 2020
1 parent 398e294 commit 2805ae3
Show file tree
Hide file tree
Showing 8 changed files with 220 additions and 26 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion components.json
Expand Up @@ -535,7 +535,7 @@
},
"jsdoc": {
"title": "JSDoc",
"require": ["javascript", "javadoclike"],
"require": ["javascript", "javadoclike", "typescript"],
"modify": "javascript",
"optional": [
"actionscript",
Expand Down
13 changes: 9 additions & 4 deletions components/prism-jsdoc.js
Expand Up @@ -40,17 +40,22 @@
},
'class-name': [
{
pattern: RegExp('(@[a-z]+\\s+)' + type),
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; })),
lookbehind: true,
inside: {
'punctuation': /[.,:?=<>|{}()[\]]/
'punctuation': /\./
}
},
{
pattern: /(@(?:augments|extends|class|interface|memberof!?|this)\s+)[A-Z]\w*(?:\.[A-Z]\w*)*/,
pattern: RegExp('(@[a-z]+\\s+)' + type),
lookbehind: true,
inside: {
'punctuation': /\./
'string': javascript.string,
'number': javascript.number,
'boolean': javascript.boolean,
'keyword': Prism.languages.typescript.keyword,
'operator': /=>|\.\.\.|[&|?:*]/,
'punctuation': /[.,;=<>{}()[\]]/
}
}
],
Expand Down
2 changes: 1 addition & 1 deletion components/prism-jsdoc.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion plugins/autoloader/prism-autoloader.js
Expand Up @@ -59,7 +59,8 @@
"jolie": "clike",
"jsdoc": [
"javascript",
"javadoclike"
"javadoclike",
"typescript"
],
"js-extras": "javascript",
"json5": "json",
Expand Down
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

192 changes: 185 additions & 7 deletions tests/languages/jsdoc/class-name_feature.test
Expand Up @@ -3,6 +3,26 @@
* @param {number | string}
* @param {Array.<number> | Object.<string, number>}
* @param {{[x: string]: {start: number, end?: number}}}
* @param {readonly { min?: number; max: number | null | undefined }[]}
* @param {null | 1 | 2}
* @param {true | string}
* @param {Type1 & Type2}
* @param {typeof import("./foo").Bar}
* @param {...any[]}
* @param {*}
* @param {() => void}
*
* @typedef Foo
* @typedef {Bar} Foo
* @template Foo
* @template {Bar} Foo
* @augments Foo
* @extends Foo
* @class Foo
* @interface Foo
* @memberof Foo
* @memberof! Foo
* @this Foo
*/

----------------------------------------------------
Expand All @@ -20,7 +40,7 @@
["class-name", [
["punctuation", "{"],
"number ",
["punctuation", "|"],
["operator", "|"],
" string",
["punctuation", "}"]
]],
Expand All @@ -33,7 +53,7 @@
["punctuation", "<"],
"number",
["punctuation", ">"],
["punctuation", "|"],
["operator", "|"],
" Object",
["punctuation", "."],
["punctuation", "<"],
Expand All @@ -50,23 +70,181 @@
["punctuation", "{"],
["punctuation", "["],
"x",
["punctuation", ":"],
["operator", ":"],
" string",
["punctuation", "]"],
["punctuation", ":"],
["operator", ":"],
["punctuation", "{"],
"start",
["punctuation", ":"],
["operator", ":"],
" number",
["punctuation", ","],
" end",
["punctuation", "?"],
["punctuation", ":"],
["operator", "?"],
["operator", ":"],
" number",
["punctuation", "}"],
["punctuation", "}"],
["punctuation", "}"]
]],
"\n * ",
["keyword", "@param"],
["class-name", [
["punctuation", "{"],
["keyword", "readonly"],
["punctuation", "{"],
" min",
["operator", "?"],
["operator", ":"],
" number",
["punctuation", ";"],
" max",
["operator", ":"],
" number ",
["operator", "|"],
["keyword", "null"],
["operator", "|"],
["keyword", "undefined"],
["punctuation", "}"],
["punctuation", "["],
["punctuation", "]"],
["punctuation", "}"]
]],
"\n * ",
["keyword", "@param"],
["class-name", [
["punctuation", "{"],
["keyword", "null"],
["operator", "|"],
["number", "1"],
["operator", "|"],
["number", "2"],
["punctuation", "}"]
]],
"\n * ",
["keyword", "@param"],
["class-name", [
["punctuation", "{"],
["boolean", "true"],
["operator", "|"],
" string",
["punctuation", "}"]
]],
"\n * ",
["keyword", "@param"],
["class-name", [
["punctuation", "{"],
"Type1 ",
["operator", "&"],
" Type2",
["punctuation", "}"]
]],
"\n * ",
["keyword", "@param"],
["class-name", [
["punctuation", "{"],
["keyword", "typeof"],
["keyword", "import"],
["punctuation", "("],
["string", "\"./foo\""],
["punctuation", ")"],
["punctuation", "."],
"Bar",
["punctuation", "}"]
]],
"\n * ",
["keyword", "@param"],
["class-name", [
["punctuation", "{"],
["operator", "..."],
"any",
["punctuation", "["],
["punctuation", "]"],
["punctuation", "}"]
]],
"\n * ",
["keyword", "@param"],
["class-name", [
["punctuation", "{"],
["operator", "*"],
["punctuation", "}"]
]],
"\n * ",
["keyword", "@param"],
["class-name", [
["punctuation", "{"],
["punctuation", "("],
["punctuation", ")"],
["operator", "=>"],
["keyword", "void"],
["punctuation", "}"]
]],
"\n *\n * ",
["keyword", "@typedef"],
["class-name", [
"Foo"
]],
"\n * ",
["keyword", "@typedef"],
["class-name", [
["punctuation", "{"],
"Bar",
["punctuation", "}"]
]],
["class-name", [
"Foo"
]],
"\n * ",
["keyword", "@template"],
["class-name", [
"Foo"
]],
"\n * ",
["keyword", "@template"],
["class-name", [
["punctuation", "{"],
"Bar",
["punctuation", "}"]
]],
["class-name", [
"Foo"
]],
"\n * ",
["keyword", "@augments"],
["class-name", [
"Foo"
]],
"\n * ",
["keyword", "@extends"],
["class-name", [
"Foo"
]],
"\n * ",
["keyword", "@class"],
["class-name", [
"Foo"
]],
"\n * ",
["keyword", "@interface"],
["class-name", [
"Foo"
]],
"\n * ",
["keyword", "@memberof"],
["class-name", [
"Foo"
]],
"\n * ",
["keyword", "@memberof"],
"! ",
["class-name", [
"Foo"
]],
"\n * ",
["keyword", "@this"],
["class-name", [
"Foo"
]],
"\n */"
]

Expand Down
30 changes: 20 additions & 10 deletions tests/languages/jsdoc/parameter_feature.test
Expand Up @@ -12,19 +12,25 @@
[
"/**\n * ",
["keyword", "@param"],
["parameter", ["n"]],
["parameter", [
"n"
]],
" - A number.\n * ",
["keyword", "@param"],
["optional-parameter", [
["punctuation", "["],
["parameter", ["n"]],
["parameter", [
"n"
]],
["punctuation", "]"]
]],
" - A number.\n * ",
["keyword", "@param"],
["optional-parameter", [
["punctuation", "["],
["parameter", ["n"]],
["parameter", [
"n"
]],
["punctuation", "="],
["code", [
["number", "1"],
Expand All @@ -40,32 +46,36 @@
"number",
["punctuation", "}"]
]],
["parameter", ["n"]],
["parameter", [
"n"
]],
" - A number.\n * ",
["keyword", "@param"],
["class-name", [
["punctuation", "{"],
["punctuation", "{"],
["punctuation", "["],
"x",
["punctuation", ":"],
["operator", ":"],
" string",
["punctuation", "]"],
["punctuation", ":"],
["operator", ":"],
["punctuation", "{"],
"start",
["punctuation", ":"],
["operator", ":"],
" number",
["punctuation", ","],
" end",
["punctuation", "?"],
["punctuation", ":"],
["operator", "?"],
["operator", ":"],
" number",
["punctuation", "}"],
["punctuation", "}"],
["punctuation", "}"]
]],
["parameter", ["map"]],
["parameter", [
"map"
]],
"\n * ",
["keyword", "@param"],
["class-name", [
Expand Down

0 comments on commit 2805ae3

Please sign in to comment.