Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
16 changes: 9 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,8 @@ namespace ts {
if (typeExpression && typeExpression.type.kind === SyntaxKind.ArrayType) {
jsdocTypeLiteral.isArrayType = true;
}
typedefTag.typeExpression = finishNode(jsdocTypeLiteral);
const useChildTypeTagAsType = childTypeTag && !isObjectOrObjectArrayTypeReference(childTypeTag.typeExpression.type);
typedefTag.typeExpression = useChildTypeTagAsType ? childTypeTag.typeExpression : finishNode(jsdocTypeLiteral);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably better to make these one expression so that if we have strictNullChecks TS can infer that we just checked for childTypeTag being defined.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Done.

}
}

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;