Merge pull request #18333 from Microsoft/fix-forEachChild-JSDocTypedefTag
Fix forEachChild jsdoc `@typedef` tag
This commit is contained in:
commit
d4e3e19763
7 changed files with 44 additions and 40 deletions
|
@ -438,9 +438,11 @@ namespace ts {
|
|||
visitNode(cbNode, (<JSDocTypedefTag>node).typeExpression);
|
||||
}
|
||||
case SyntaxKind.JSDocTypeLiteral:
|
||||
if ((node as JSDocTypeLiteral).jsDocPropertyTags) {
|
||||
for (const tag of (node as JSDocTypeLiteral).jsDocPropertyTags) {
|
||||
visitNode(cbNode, tag);
|
||||
}
|
||||
}
|
||||
return;
|
||||
case SyntaxKind.PartiallyEmittedExpression:
|
||||
return visitNode(cbNode, (<PartiallyEmittedExpression>node).expression);
|
||||
|
@ -6652,19 +6654,18 @@ namespace ts {
|
|||
if (!typeExpression || isObjectOrObjectArrayTypeReference(typeExpression.type)) {
|
||||
let child: JSDocTypeTag | JSDocPropertyTag | false;
|
||||
let jsdocTypeLiteral: JSDocTypeLiteral;
|
||||
let alreadyHasTypeTag = false;
|
||||
let childTypeTag: JSDocTypeTag;
|
||||
const start = scanner.getStartPos();
|
||||
while (child = tryParse(() => parseChildParameterOrPropertyTag(PropertyLikeParse.Property))) {
|
||||
if (!jsdocTypeLiteral) {
|
||||
jsdocTypeLiteral = <JSDocTypeLiteral>createNode(SyntaxKind.JSDocTypeLiteral, start);
|
||||
}
|
||||
if (child.kind === SyntaxKind.JSDocTypeTag) {
|
||||
if (alreadyHasTypeTag) {
|
||||
if (childTypeTag) {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
jsdocTypeLiteral.jsDocTypeTag = child;
|
||||
alreadyHasTypeTag = true;
|
||||
childTypeTag = child;
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -6678,7 +6679,9 @@ namespace ts {
|
|||
if (typeExpression && typeExpression.type.kind === SyntaxKind.ArrayType) {
|
||||
jsdocTypeLiteral.isArrayType = true;
|
||||
}
|
||||
typedefTag.typeExpression = finishNode(jsdocTypeLiteral);
|
||||
typedefTag.typeExpression = childTypeTag && !isObjectOrObjectArrayTypeReference(childTypeTag.typeExpression.type) ?
|
||||
childTypeTag.typeExpression :
|
||||
finishNode(jsdocTypeLiteral);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2211,7 +2211,6 @@ namespace ts {
|
|||
export interface JSDocTypeLiteral extends JSDocType {
|
||||
kind: SyntaxKind.JSDocTypeLiteral;
|
||||
jsDocPropertyTags?: ReadonlyArray<JSDocPropertyLikeTag>;
|
||||
jsDocTypeTag?: JSDocTypeTag;
|
||||
/** If true, then this type literal represents an *array* of its type. */
|
||||
isArrayType?: boolean;
|
||||
}
|
||||
|
|
|
@ -34,38 +34,6 @@
|
|||
"kind": "JSDocTypeLiteral",
|
||||
"pos": 26,
|
||||
"end": 98,
|
||||
"jsDocTypeTag": {
|
||||
"kind": "JSDocTypeTag",
|
||||
"pos": 28,
|
||||
"end": 42,
|
||||
"atToken": {
|
||||
"kind": "AtToken",
|
||||
"pos": 28,
|
||||
"end": 29
|
||||
},
|
||||
"tagName": {
|
||||
"kind": "Identifier",
|
||||
"pos": 29,
|
||||
"end": 33,
|
||||
"escapedText": "type"
|
||||
},
|
||||
"typeExpression": {
|
||||
"kind": "JSDocTypeExpression",
|
||||
"pos": 34,
|
||||
"end": 42,
|
||||
"type": {
|
||||
"kind": "TypeReference",
|
||||
"pos": 35,
|
||||
"end": 41,
|
||||
"typeName": {
|
||||
"kind": "Identifier",
|
||||
"pos": 35,
|
||||
"end": 41,
|
||||
"escapedText": "Object"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"jsDocPropertyTags": [
|
||||
{
|
||||
"kind": "JSDocPropertyTag",
|
||||
|
|
10
tests/baselines/reference/jsdocTwoLineTypedef.js
Normal file
10
tests/baselines/reference/jsdocTwoLineTypedef.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
//// [jsdocTwoLineTypedef.ts]
|
||||
// Regression from #18301
|
||||
/**
|
||||
* @typedef LoadCallback
|
||||
* @type {function}
|
||||
*/
|
||||
type LoadCallback = void;
|
||||
|
||||
|
||||
//// [jsdocTwoLineTypedef.js]
|
9
tests/baselines/reference/jsdocTwoLineTypedef.symbols
Normal file
9
tests/baselines/reference/jsdocTwoLineTypedef.symbols
Normal file
|
@ -0,0 +1,9 @@
|
|||
=== tests/cases/conformance/jsdoc/jsdocTwoLineTypedef.ts ===
|
||||
// Regression from #18301
|
||||
/**
|
||||
* @typedef LoadCallback
|
||||
* @type {function}
|
||||
*/
|
||||
type LoadCallback = void;
|
||||
>LoadCallback : Symbol(LoadCallback, Decl(jsdocTwoLineTypedef.ts, 0, 0))
|
||||
|
9
tests/baselines/reference/jsdocTwoLineTypedef.types
Normal file
9
tests/baselines/reference/jsdocTwoLineTypedef.types
Normal file
|
@ -0,0 +1,9 @@
|
|||
=== tests/cases/conformance/jsdoc/jsdocTwoLineTypedef.ts ===
|
||||
// Regression from #18301
|
||||
/**
|
||||
* @typedef LoadCallback
|
||||
* @type {function}
|
||||
*/
|
||||
type LoadCallback = void;
|
||||
>LoadCallback : void
|
||||
|
6
tests/cases/conformance/jsdoc/jsdocTwoLineTypedef.ts
Normal file
6
tests/cases/conformance/jsdoc/jsdocTwoLineTypedef.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
// Regression from #18301
|
||||
/**
|
||||
* @typedef LoadCallback
|
||||
* @type {function}
|
||||
*/
|
||||
type LoadCallback = void;
|
Loading…
Reference in a new issue