Merge pull request #18333 from Microsoft/fix-forEachChild-JSDocTypedefTag

Fix forEachChild jsdoc `@typedef` tag
This commit is contained in:
Nathan Shively-Sanders 2017-09-08 08:52:46 -07:00 committed by GitHub
commit d4e3e19763
7 changed files with 44 additions and 40 deletions

View file

@ -438,8 +438,10 @@ namespace ts {
visitNode(cbNode, (<JSDocTypedefTag>node).typeExpression); visitNode(cbNode, (<JSDocTypedefTag>node).typeExpression);
} }
case SyntaxKind.JSDocTypeLiteral: case SyntaxKind.JSDocTypeLiteral:
for (const tag of (node as JSDocTypeLiteral).jsDocPropertyTags) { if ((node as JSDocTypeLiteral).jsDocPropertyTags) {
visitNode(cbNode, tag); for (const tag of (node as JSDocTypeLiteral).jsDocPropertyTags) {
visitNode(cbNode, tag);
}
} }
return; return;
case SyntaxKind.PartiallyEmittedExpression: case SyntaxKind.PartiallyEmittedExpression:
@ -6652,19 +6654,18 @@ namespace ts {
if (!typeExpression || isObjectOrObjectArrayTypeReference(typeExpression.type)) { if (!typeExpression || isObjectOrObjectArrayTypeReference(typeExpression.type)) {
let child: JSDocTypeTag | JSDocPropertyTag | false; let child: JSDocTypeTag | JSDocPropertyTag | false;
let jsdocTypeLiteral: JSDocTypeLiteral; let jsdocTypeLiteral: JSDocTypeLiteral;
let alreadyHasTypeTag = false; let childTypeTag: JSDocTypeTag;
const start = scanner.getStartPos(); const start = scanner.getStartPos();
while (child = tryParse(() => parseChildParameterOrPropertyTag(PropertyLikeParse.Property))) { while (child = tryParse(() => parseChildParameterOrPropertyTag(PropertyLikeParse.Property))) {
if (!jsdocTypeLiteral) { if (!jsdocTypeLiteral) {
jsdocTypeLiteral = <JSDocTypeLiteral>createNode(SyntaxKind.JSDocTypeLiteral, start); jsdocTypeLiteral = <JSDocTypeLiteral>createNode(SyntaxKind.JSDocTypeLiteral, start);
} }
if (child.kind === SyntaxKind.JSDocTypeTag) { if (child.kind === SyntaxKind.JSDocTypeTag) {
if (alreadyHasTypeTag) { if (childTypeTag) {
break; break;
} }
else { else {
jsdocTypeLiteral.jsDocTypeTag = child; childTypeTag = child;
alreadyHasTypeTag = true;
} }
} }
else { else {
@ -6678,7 +6679,9 @@ namespace ts {
if (typeExpression && typeExpression.type.kind === SyntaxKind.ArrayType) { if (typeExpression && typeExpression.type.kind === SyntaxKind.ArrayType) {
jsdocTypeLiteral.isArrayType = true; jsdocTypeLiteral.isArrayType = true;
} }
typedefTag.typeExpression = finishNode(jsdocTypeLiteral); typedefTag.typeExpression = childTypeTag && !isObjectOrObjectArrayTypeReference(childTypeTag.typeExpression.type) ?
childTypeTag.typeExpression :
finishNode(jsdocTypeLiteral);
} }
} }

View file

@ -2211,7 +2211,6 @@ namespace ts {
export interface JSDocTypeLiteral extends JSDocType { export interface JSDocTypeLiteral extends JSDocType {
kind: SyntaxKind.JSDocTypeLiteral; kind: SyntaxKind.JSDocTypeLiteral;
jsDocPropertyTags?: ReadonlyArray<JSDocPropertyLikeTag>; jsDocPropertyTags?: ReadonlyArray<JSDocPropertyLikeTag>;
jsDocTypeTag?: JSDocTypeTag;
/** If true, then this type literal represents an *array* of its type. */ /** If true, then this type literal represents an *array* of its type. */
isArrayType?: boolean; isArrayType?: boolean;
} }

View file

@ -34,38 +34,6 @@
"kind": "JSDocTypeLiteral", "kind": "JSDocTypeLiteral",
"pos": 26, "pos": 26,
"end": 98, "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": [ "jsDocPropertyTags": [
{ {
"kind": "JSDocPropertyTag", "kind": "JSDocPropertyTag",

View file

@ -0,0 +1,10 @@
//// [jsdocTwoLineTypedef.ts]
// Regression from #18301
/**
* @typedef LoadCallback
* @type {function}
*/
type LoadCallback = void;
//// [jsdocTwoLineTypedef.js]

View 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))

View file

@ -0,0 +1,9 @@
=== tests/cases/conformance/jsdoc/jsdocTwoLineTypedef.ts ===
// Regression from #18301
/**
* @typedef LoadCallback
* @type {function}
*/
type LoadCallback = void;
>LoadCallback : void

View file

@ -0,0 +1,6 @@
// Regression from #18301
/**
* @typedef LoadCallback
* @type {function}
*/
type LoadCallback = void;