cr feedback

This commit is contained in:
zhengbli 2016-05-30 22:11:43 -07:00
parent e69976c4b7
commit 18ee4b0a1e
6 changed files with 43 additions and 39 deletions

View file

@ -267,6 +267,18 @@ namespace ts {
let functionType = <JSDocFunctionType>node.parent;
let index = indexOf(functionType.parameters, node);
return "p" + index;
case SyntaxKind.JSDocTypedefTag:
const parentNode = node.parent && node.parent.parent;
let nameFromParentNode: string;
if (parentNode && parentNode.kind === SyntaxKind.VariableStatement) {
if ((<VariableStatement>parentNode).declarationList.declarations.length > 0) {
const nameIdentifier = (<VariableStatement>parentNode).declarationList.declarations[0].name;
if (nameIdentifier.kind === SyntaxKind.Identifier) {
nameFromParentNode = (<Identifier>nameIdentifier).text;
}
}
}
return nameFromParentNode;
}
}

View file

@ -3586,11 +3586,21 @@ namespace ts {
return unknownType;
}
let type: Type;
let declaration: JSDocTypedefTag | TypeAliasDeclaration = <JSDocTypedefTag>getDeclarationOfKind(symbol, SyntaxKind.JSDocTypedefTag);
if (!declaration) {
declaration = <TypeAliasDeclaration>getDeclarationOfKind(symbol, SyntaxKind.TypeAliasDeclaration);
if (declaration) {
if (declaration.jsDocTypeLiteral) {
type = getTypeFromTypeNode(declaration.jsDocTypeLiteral);
}
else {
type = getTypeFromTypeNode(declaration.typeExpression.type);
}
}
let type = getTypeFromTypeNode(declaration.type);
else {
declaration = <TypeAliasDeclaration>getDeclarationOfKind(symbol, SyntaxKind.TypeAliasDeclaration);
type = getTypeFromTypeNode(declaration.type);
}
if (popTypeResolution()) {
links.typeParameters = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol);
if (links.typeParameters) {

View file

@ -404,7 +404,7 @@ namespace ts {
case SyntaxKind.JSDocTypedefTag:
return visitNode(cbNode, (<JSDocTypedefTag>node).typeExpression) ||
visitNode(cbNode, (<JSDocTypedefTag>node).name) ||
visitNode(cbNode, (<JSDocTypedefTag>node).type);
visitNode(cbNode, (<JSDocTypedefTag>node).jsDocTypeLiteral);
case SyntaxKind.JSDocTypeLiteral:
return visitNodes(cbNodes, (<JSDocTypeLiteral>node).jsDocPropertyTags);
case SyntaxKind.JSDocPropertyTag:
@ -6301,28 +6301,11 @@ namespace ts {
function handleTypedefTag(atToken: Node, tagName: Identifier): JSDocTypedefTag {
const typeExpression = tryParseTypeExpression();
skipWhitespace();
let name = parseJSDocIdentifierName();
if (!name) {
let foundNameFromParentNode = false;
if (parentNode && parentNode.kind === SyntaxKind.VariableStatement) {
if ((<VariableStatement>parentNode).declarationList.declarations.length > 0) {
const nameFromParentNode = (<VariableStatement>parentNode).declarationList.declarations[0].name;
if (nameFromParentNode.kind === SyntaxKind.Identifier) {
foundNameFromParentNode = true;
name = <Identifier>nameFromParentNode;
}
}
}
if (!foundNameFromParentNode) {
parseErrorAtPosition(scanner.getStartPos(), 0, Diagnostics.Identifier_expected);
return undefined;
}
}
const typedefTag = <JSDocTypedefTag>createNode(SyntaxKind.JSDocTypedefTag, atToken.pos);
typedefTag.atToken = atToken;
typedefTag.tagName = tagName;
typedefTag.name = name;
typedefTag.name = parseJSDocIdentifierName();
typedefTag.typeExpression = typeExpression;
if (typeExpression) {
@ -6331,16 +6314,16 @@ namespace ts {
if (jsDocTypeReference.name.kind === SyntaxKind.Identifier) {
const name = <Identifier>jsDocTypeReference.name;
if (name.text === "Object") {
typedefTag.type = scanChildTags();
typedefTag.jsDocTypeLiteral = scanChildTags();
}
}
}
if (!typedefTag.type) {
typedefTag.type = typeExpression.type;
if (!typedefTag.jsDocTypeLiteral) {
typedefTag.jsDocTypeLiteral = typeExpression.type;
}
}
else {
typedefTag.type = scanChildTags();
typedefTag.jsDocTypeLiteral = scanChildTags();
}
return finishNode(typedefTag);

View file

@ -376,7 +376,9 @@ namespace ts {
LastBinaryOperator = CaretEqualsToken,
FirstNode = QualifiedName,
FirstJSDocNode = JSDocTypeExpression,
LastJSDocNode = JSDocTypeLiteral
LastJSDocNode = JSDocTypeLiteral,
FirstJSDocTagNode = JSDocComment,
LastJSDocTagNode = JSDocTypeLiteral
}
export const enum NodeFlags {
@ -1518,9 +1520,9 @@ namespace ts {
// @kind(SyntaxKind.JSDocTypedefTag)
export interface JSDocTypedefTag extends JSDocTag, Declaration {
name: Identifier;
name?: Identifier;
typeExpression?: JSDocTypeExpression;
type: JSDocType;
jsDocTypeLiteral?: JSDocTypeLiteral;
}
// @kind(SyntaxKind.JSDocPropertyTag)

View file

@ -653,6 +653,12 @@ namespace ts.NavigationBar {
topItem.childItems.push(newItem);
}
if (node.jsDocComments && node.jsDocComments.length > 0) {
for (const jsDocComment of node.jsDocComments) {
visitNode(jsDocComment);
}
}
// Add a level if traversing into a container
if (newItem && (isFunctionLike(node) || isClassLike(node))) {
const lastTop = topItem;

View file

@ -276,16 +276,7 @@ namespace ts {
scanner.setText((sourceFile || this.getSourceFile()).text);
children = [];
let pos = this.pos;
const useJSDocScanner =
this.kind === SyntaxKind.JSDocComment ||
this.kind === SyntaxKind.JSDocParameterTag ||
this.kind === SyntaxKind.JSDocTag ||
this.kind === SyntaxKind.JSDocParameterTag ||
this.kind === SyntaxKind.JSDocReturnTag ||
this.kind === SyntaxKind.JSDocTypeTag ||
this.kind === SyntaxKind.JSDocTemplateTag ||
this.kind === SyntaxKind.JSDocTypedefTag ||
this.kind === SyntaxKind.JSDocPropertyTag;
const useJSDocScanner = this.kind >= SyntaxKind.FirstJSDocTagNode && this.kind <= SyntaxKind.LastJSDocTagNode;
const processNode = (node: Node) => {
if (pos < node.pos) {
pos = this.addSyntheticNodes(children, pos, node.pos, useJSDocScanner);