Skip to content

Fix forEachChild jsdoc @typedef tag #18333

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

Merged
merged 4 commits into from
Sep 8, 2017
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
17 changes: 10 additions & 7 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,10 @@ namespace ts {
visitNode(cbNode, (<JSDocTypedefTag>node).typeExpression);
}
case SyntaxKind.JSDocTypeLiteral:
for (const tag of (node as JSDocTypeLiteral).jsDocPropertyTags) {
visitNode(cbNode, tag);
if ((node as JSDocTypeLiteral).jsDocPropertyTags) {
for (const tag of (node as JSDocTypeLiteral).jsDocPropertyTags) {
visitNode(cbNode, tag);
}
}
return;
case SyntaxKind.PartiallyEmittedExpression:
Expand Down Expand Up @@ -6672,19 +6674,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 {
Expand All @@ -6698,7 +6699,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);
}
}

Expand Down
1 change: 0 additions & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 10 additions & 0 deletions tests/baselines/reference/jsdocTwoLineTypedef.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//// [jsdocTwoLineTypedef.ts]
// Regression from #18301
/**
* @typedef LoadCallback
* @type {function}
*/
type LoadCallback = void;


//// [jsdocTwoLineTypedef.js]
9 changes: 9 additions & 0 deletions tests/baselines/reference/jsdocTwoLineTypedef.symbols
Original file line number Diff line number Diff line change
@@ -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 changes: 9 additions & 0 deletions tests/baselines/reference/jsdocTwoLineTypedef.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
=== tests/cases/conformance/jsdoc/jsdocTwoLineTypedef.ts ===
// Regression from #18301
/**
* @typedef LoadCallback
* @type {function}
*/
type LoadCallback = void;
>LoadCallback : void

6 changes: 6 additions & 0 deletions tests/cases/conformance/jsdoc/jsdocTwoLineTypedef.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Regression from #18301
/**
* @typedef LoadCallback
* @type {function}
*/
type LoadCallback = void;