Omit spaces after https in jsdoc comments (#43800)

* Omit spaces after https in jsdoc comments

for tags with names.

Fxes #42581

* fix semicolon lint
This commit is contained in:
Nathan Shively-Sanders 2021-04-23 16:23:34 -07:00 committed by GitHub
parent dee4903f45
commit d171eee044
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 398 additions and 4 deletions

View File

@ -159,7 +159,9 @@ namespace ts.JsDoc {
case SyntaxKind.JSDocParameterTag:
case SyntaxKind.JSDocSeeTag:
const { name } = tag as JSDocTypedefTag | JSDocCallbackTag | JSDocPropertyTag | JSDocParameterTag | JSDocSeeTag;
return name ? withNode(name) : comment === undefined ? undefined : getDisplayPartsFromComment(comment, checker);
return name ? withNode(name)
: comment === undefined ? undefined
: getDisplayPartsFromComment(comment, checker);
default:
return comment === undefined ? undefined : getDisplayPartsFromComment(comment, checker);
}
@ -169,9 +171,17 @@ namespace ts.JsDoc {
}
function addComment(s: string) {
return comment
? [namePart(s), spacePart(), ...getDisplayPartsFromComment(comment, checker)]
: [textPart(s)];
if (comment) {
if (s.match(/^https?$/)) {
return [textPart(s), ...getDisplayPartsFromComment(comment, checker)];
}
else {
return [namePart(s), spacePart(), ...getDisplayPartsFromComment(comment, checker)];
}
}
else {
return [textPart(s)];
}
}
}

View File

@ -0,0 +1,360 @@
[
{
"marker": {
"fileName": "/tests/cases/fourslash/quickInfoForJSDocWithHttpLinks.js",
"position": 22,
"name": "1"
},
"quickInfo": {
"kind": "type",
"kindModifiers": "",
"textSpan": {
"start": 22,
"length": 5
},
"displayParts": [
{
"text": "type",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "https",
"kind": "aliasName"
},
{
"text": " ",
"kind": "space"
},
{
"text": "=",
"kind": "operator"
},
{
"text": " ",
"kind": "space"
},
{
"text": "number",
"kind": "keyword"
}
],
"documentation": [
{
"text": "://wat",
"kind": "text"
}
]
}
},
{
"marker": {
"fileName": "/tests/cases/fourslash/quickInfoForJSDocWithHttpLinks.js",
"position": 88,
"name": "2"
},
"quickInfo": {
"kind": "property",
"kindModifiers": "",
"textSpan": {
"start": 88,
"length": 5
},
"displayParts": [
{
"text": "(",
"kind": "punctuation"
},
{
"text": "property",
"kind": "text"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "https",
"kind": "propertyName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "number",
"kind": "keyword"
}
],
"documentation": [
{
"text": "://wass",
"kind": "text"
}
]
}
},
{
"marker": {
"fileName": "/tests/cases/fourslash/quickInfoForJSDocWithHttpLinks.js",
"position": 120,
"name": "3"
},
"quickInfo": {
"kind": "type",
"kindModifiers": "",
"textSpan": {
"start": 120,
"length": 4
},
"displayParts": [
{
"text": "type",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "http",
"kind": "aliasName"
},
{
"text": " ",
"kind": "space"
},
{
"text": "=",
"kind": "operator"
},
{
"text": " ",
"kind": "space"
},
{
"text": "(",
"kind": "punctuation"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "=>",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "any",
"kind": "keyword"
}
],
"documentation": [
{
"text": "://vad",
"kind": "text"
}
]
}
},
{
"marker": {
"fileName": "/tests/cases/fourslash/quickInfoForJSDocWithHttpLinks.js",
"position": 164,
"name": "4"
},
"quickInfo": {
"kind": "var",
"kindModifiers": "",
"textSpan": {
"start": 164,
"length": 4
},
"displayParts": [
{
"text": "var",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "see1",
"kind": "localName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "boolean",
"kind": "keyword"
}
],
"documentation": [],
"tags": [
{
"name": "see",
"text": [
{
"text": "https",
"kind": "text"
},
{
"text": "://hvad",
"kind": "text"
}
]
}
]
}
},
{
"marker": {
"fileName": "/tests/cases/fourslash/quickInfoForJSDocWithHttpLinks.js",
"position": 213,
"name": "5"
},
"quickInfo": {
"kind": "var",
"kindModifiers": "",
"textSpan": {
"start": 213,
"length": 4
},
"displayParts": [
{
"text": "var",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "see2",
"kind": "localName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "boolean",
"kind": "keyword"
}
],
"documentation": [],
"tags": [
{
"name": "see",
"text": [
{
"text": "",
"kind": "text"
},
{
"text": "{@link ",
"kind": "link"
},
{
"text": "https://hva",
"kind": "linkText"
},
{
"text": "}",
"kind": "link"
}
]
}
]
}
},
{
"marker": {
"fileName": "/tests/cases/fourslash/quickInfoForJSDocWithHttpLinks.js",
"position": 258,
"name": "6"
},
"quickInfo": {
"kind": "var",
"kindModifiers": "",
"textSpan": {
"start": 258,
"length": 4
},
"displayParts": [
{
"text": "var",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "see3",
"kind": "localName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "boolean",
"kind": "keyword"
}
],
"documentation": [
{
"text": "",
"kind": "text"
},
{
"text": "{@link ",
"kind": "link"
},
{
"text": "https://hvaD",
"kind": "linkText"
},
{
"text": "}",
"kind": "link"
}
]
}
}
]

View File

@ -0,0 +1,24 @@
/// <reference path='fourslash.ts' />
// @checkJs: true
// @filename: quickInfoForJSDocWithHttpLinks.js
//// /** @typedef {number} /*1*/https://wat */
////
//// /**
//// * @typedef {Object} Oops
//// * @property {number} /*2*/https://wass
//// */
////
////
//// /** @callback /*3*/http://vad */
////
//// /** @see https://hvad */
//// var /*4*/see1 = true
////
//// /** @see {@link https://hva} */
//// var /*5*/see2 = true
////
//// /** {@link https://hvaD} */
//// var /*6*/see3 = true
verify.baselineQuickInfo();