Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSDoc: Improvements #2466

Merged
merged 3 commits into from
Jul 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion components.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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