8000 cr feedback · uberreact/TypeScript@18ee4b0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 18ee4b0

Browse files
committed
cr feedback
1 parent e69976c commit 18ee4b0

File tree

6 files changed

+42
-38
lines changed

6 files changed

+42
-38
lines changed

src/compiler/binder.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,18 @@ namespace ts {
267267
let functionType = <JSDocFunctionType>node.parent;
268268
let index = indexOf(functionType.parameters, node);
269269
return "p" + index;
270+
case SyntaxKind.JSDocTypedefTag:
271+
const parentNode = node.parent && node.parent.parent;
272+
let nameFromParentNode: string;
273+
if (parentNode && parentNode.kind === SyntaxKind.VariableStatement) {
274+
if ((<VariableStatement>parentNode).declarationList.declarations.length > 0) {
275+
const nameIdentifier = (<VariableStatement>parentNode).declarationList.declarations[0].name;
276+
if (nameIdentifier.kind === SyntaxKind.Identifier) {
277+
nameFromParentNode = (<Identifier>nameIdentifier).text;
278+
}
279+
}
280+
}
281+
return nameFromParentNode;
270282
}
271283
}
272284

src/compiler/checker.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3586,11 +3586,21 @@ namespace ts {
35863586
return unknownType;
35873587
}
35883588

3589+
let type: Type;
35893590
let declaration: JSDocTypedefTag | TypeAliasDeclaration = <JSDocTypedefTag>getDeclarationOfKind(symbol, SyntaxKind.JSDocTypedefTag);
3590-
if (!declaration) {
3591+
if (declaration) {
3592+
if (declaration.jsDocTypeLiteral) {
3593+
type = getTypeFromTypeNode(declaration.jsDocTypeLiteral);
3594+
}
3595+
else {
3596+
type = getTypeFromTypeNode(declaration.typeExpression.type);
3597+
}
3598+
}
3599+
else {
35913600
declaration = <TypeAliasDeclaration>getDeclarationOfKind(symbol, SyntaxKind.TypeAliasDeclaration);
3601+
type = getTypeFromTypeNode(declaration.type);
35923602
}
3593-
let type = getTypeFromTypeNode(declaration.type);
3603+
35943604
if (popTypeResolution()) {
35953605
links.typeParameters = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol);
35963606
if (links.typeParameters) {

src/compiler/parser.ts

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ namespace ts {
404404
case SyntaxKind.JSDocTypedefTag:
405405
return visitNode(cbNode, (<JSDocTypedefTag>node).typeExpression) ||
406406
visitNode(cbNode, (<JSDocTypedefTag>node).name) ||
407-
visitNode(cbNode, (<JSDocTypedefTag>node).type);
407+
visitNode(cbNode, (<JSDocTypedefTag>node).jsDocTypeLiteral);
408408
case SyntaxKind.JSDocTypeLiteral:
409409
return visitNodes(cbNodes, (<JSDocTypeLiteral>node).jsDocPropertyTags);
410410
case SyntaxKind.JSDocPropertyTag:
@@ -6301,28 +6301,11 @@ namespace ts {
63016301
function handleTypedefTag(atToken: Node, tagName: Identifier): JSDocTypedefTag {
63026302
const typeExpression = tryParseTypeExpression();
63036303
skipWhitespace();
6304-
let name = parseJSDocIdentifierName();
6305-
if (!name) {
6306-
let foundNameFromParentNode = false;
6307-
if (parentNode && parentNode.kind === SyntaxKind.VariableStatement) {
6308-
if ((<VariableStatement>parentNode).declarationList.declarations.length > 0) {
6309-
const nameFromParentNode = (<VariableStatement>parentNode).declarationList.declarations[0].name;
6310-
if (nameFromParentNode.kind === SyntaxKind.Identifier) {
6311-
foundNameFromParentNode = true;
6312-
name = <Identifier>nameFromParentNode;
6313-
}
6314-
}
6315-
}
6316-
if (!foundNameFromParentNode) {
6317-
parseErrorAtPosition(scanner.getStartPos(), 0, Diagnostics.Identifier_expected);
6318-
return undefined;
6319-
}
6320-
}
63216304

63226305
const typedefTag = <JSDocTypedefTag>createNode(SyntaxKind.JSDocTypedefTag, atToken.pos);
63236306
typedefTag.atToken = atToken;
63246307
typedefTag.tagName = tagName;
6325-
typedefTag.name = name;
6308+
typedefTag.name = parseJSDocIdentifierName();
63266309
typedefTag.typeExpression = typeExpression;
63276310

63286311
if (typeExpression) {
@@ -6331,16 +6314,16 @@ namespace ts {
63316314
if (jsDocTypeReference.name.kind === SyntaxKind.Identifier) {
63326315
const name = <Identifier>jsDocTypeReference.name;
63336316
if (name.text === "Object") {
6334-
typedefTag.type = scanChildTags();
6317+
typedefTag.jsDocTypeLiteral = scanChildTags();
63356318
}
63366319
}
63376320
}
6338-
if (!typedefTag.type) {
6339-
typedefTag.type = typeExpression.type;
6321+
if (!typedefTag.jsDocTypeLiteral) {
6322+
typedefTag.jsDocTypeLiteral = typeExpression.type;
63406323
}
63416324
}
63426325
else {
6343-
typedefTag.type = scanChildTags();
6326+
typedefTag.jsDocTypeLiteral = scanChildTags();
63446327
}
63456328

63466329
return finishNode(typedefTag);

src/compiler/types.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,9 @@ namespace ts {
376376
LastBinaryOperator = CaretEqualsToken,
377377
FirstNode = QualifiedName,
378378
FirstJSDocNode = JSDocTypeExpression,
379-
LastJSDocNode = JSDocTypeLiteral
379+
LastJSDocNode = JSDocTypeLiteral,
380+
FirstJSDocTagNode = JSDocComment,
381+
LastJSDocTagNode = JSDocTypeLiteral
380382
}
381383

382384
export const enum NodeFlags {
@@ -1518,9 +1520,9 @@ namespace ts {
15181520

15191521
// @kind(SyntaxKind.JSDocTypedefTag)
15201522
export interface JSDocTypedefTag extends JSDocTag, Declaration {
1521-
name: Identifier;
1523+
name?: Identifier;
15221524
typeExpression?: JSDocTypeExpression;
1523-
type: JSDocType;
1525+
jsDocTypeLiteral?: JSDocTypeLiteral;
15241526
}
15251527

15261528
// @kind(SyntaxKind.JSDocPropertyTag)

src/services/navigationBar.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,12 @@ namespace ts.NavigationBar {
653653
topItem.childItems.push(newItem);
654654
}
655655

656+
if (node.jsDocComments && node.jsDocComments.length > 0) {
657+
for (const jsDocComment of node.jsDocComments) {
658+
visitNode(jsDocComment);
659+
}
660+
}
661+
656662
// Add a level if traversing into a container
657663
if (newItem && (isFunctionLike(node) || isClassLike(node))) {
658664
const lastTop = topItem;

src/services/services.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -276,16 +276,7 @@ namespace ts {
276276
scanner.setText((sourceFile || this.getSourceFile()).text);
277277
children = [];
278278
let pos = this.pos;
279-
const useJSDocScanner =
280-
this.kind === SyntaxKind.JSDocComment ||
281-
this.kind === SyntaxKind.JSDocParameterTag ||
282-
this.kind === SyntaxKind.JSDocTag ||
283-
this.kind === SyntaxKind.JSDocParameterTag ||
284-
this.kind === SyntaxKind.JSDocReturnTag ||
285-
this.kind === SyntaxKind.JSDocTypeTag ||
286-
this.kind === SyntaxKind.JSDocTemplateTag ||
287-
this.kind === SyntaxKind.JSDocTypedefTag ||
288-
this.kind === SyntaxKind.JSDocPropertyTag;
279+
const useJSDocScanner = this.kind >= SyntaxKind.FirstJSDocTagNode && this.kind <= SyntaxKind.LastJSDocTagNode;
289280
const processNode = (node: Node) => {
290281
if (pos < node.pos) {
291282
pos = this.addSyntheticNodes(children, pos, node.pos, useJSDocScanner);

0 commit comments

Comments
 (0)
0