Skip to content
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: 4 additions & 13 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,17 +282,8 @@ namespace ts {
const index = indexOf(functionType.parameters, node);
return "arg" + index as __String;
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 (isIdentifier(nameIdentifier)) {
nameFromParentNode = nameIdentifier.escapedText;
}
}
}
return nameFromParentNode;
const name = getNameOfJSDocTypedef(node as JSDocTypedefTag);
return typeof name !== "undefined" ? name.escapedText : undefined;
}
}

Expand Down Expand Up @@ -598,7 +589,7 @@ namespace ts {
// Binding of JsDocComment should be done before the current block scope container changes.
// because the scope of JsDocComment should not be affected by whether the current node is a
// container or not.
if (node.jsDoc) {
if (hasJSDocNodes(node)) {
if (isInJavaScriptFile(node)) {
for (const j of node.jsDoc) {
bind(j);
Expand Down Expand Up @@ -1931,7 +1922,7 @@ namespace ts {
}

function bindJSDocTypedefTagIfAny(node: Node) {
if (!node.jsDoc) {
if (!hasJSDocNodes(node)) {
return;
}

Expand Down
9 changes: 6 additions & 3 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19158,6 +19158,8 @@ namespace ts {
switch (d.kind) {
case SyntaxKind.InterfaceDeclaration:
case SyntaxKind.TypeAliasDeclaration:
// A jsdoc typedef is, by definition, a type alias
case SyntaxKind.JSDocTypedefTag:
return DeclarationSpaces.ExportType;
case SyntaxKind.ModuleDeclaration:
return isAmbientModule(d) || getModuleInstanceState(d) !== ModuleInstanceState.NonInstantiated
Expand Down Expand Up @@ -19827,7 +19829,7 @@ namespace ts {
}
}
else if (compilerOptions.noUnusedLocals) {
forEach(local.declarations, d => errorUnusedLocal(getNameOfDeclaration(d) || d, unescapeLeadingUnderscores(local.escapedName)));
forEach(local.declarations, d => errorUnusedLocal(d, unescapeLeadingUnderscores(local.escapedName)));
}
}
});
Expand All @@ -19842,7 +19844,8 @@ namespace ts {
return false;
}

function errorUnusedLocal(node: Node, name: string) {
function errorUnusedLocal(declaration: Declaration, name: string) {
const node = getNameOfDeclaration(declaration) || declaration;
if (isIdentifierThatStartsWithUnderScore(node)) {
const declaration = getRootDeclaration(node.parent);
if (declaration.kind === SyntaxKind.VariableDeclaration && isForInOrOfStatement(declaration.parent.parent)) {
Expand Down Expand Up @@ -19909,7 +19912,7 @@ namespace ts {
if (!local.isReferenced && !local.exportSymbol) {
for (const declaration of local.declarations) {
if (!isAmbientModule(declaration)) {
errorUnusedLocal(getNameOfDeclaration(declaration), unescapeLeadingUnderscores(local.escapedName));
errorUnusedLocal(declaration, unescapeLeadingUnderscores(local.escapedName));
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2441,7 +2441,7 @@ namespace ts {
}
}

export function fail(message?: string, stackCrawlMark?: Function): void {
export function fail(message?: string, stackCrawlMark?: Function): never {
debugger;
const e = new Error(message ? `Debug Failure. ${message}` : "Debug Failure.");
if ((<any>Error).captureStackTrace) {
Expand All @@ -2450,6 +2450,10 @@ namespace ts {
throw e;
}

export function assertNever(member: never, message?: string, stackCrawlMark?: Function): never {
return fail(message || `Illegal value: ${member}`, stackCrawlMark || assertNever);
}

export function getFunctionName(func: Function) {
if (typeof func !== "function") {
return "";
Expand Down
16 changes: 8 additions & 8 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ namespace ts {
}


function addJSDocComment<T extends Node>(node: T): T {
function addJSDocComment<T extends HasJSDoc>(node: T): T {
const comments = getJSDocCommentRanges(node, sourceFile.text);
if (comments) {
for (const comment of comments) {
Expand Down Expand Up @@ -768,7 +768,7 @@ namespace ts {
const saveParent = parent;
parent = n;
forEachChild(n, visitNode);
if (n.jsDoc) {
if (hasJSDocNodes(n)) {
for (const jsDoc of n.jsDoc) {
jsDoc.parent = n;
parent = jsDoc;
Expand Down Expand Up @@ -2158,7 +2158,7 @@ namespace ts {
const result = <JSDocFunctionType>createNode(SyntaxKind.JSDocFunctionType);
nextToken();
fillSignature(SyntaxKind.ColonToken, SignatureFlags.Type | SignatureFlags.JSDoc, result);
return finishNode(result);
return addJSDocComment(finishNode(result));
}
const node = <TypeReferenceNode>createNode(SyntaxKind.TypeReference);
node.typeName = parseIdentifierName();
Expand Down Expand Up @@ -2365,7 +2365,7 @@ namespace ts {
parseSemicolon();
}

function parseSignatureMember(kind: SyntaxKind): CallSignatureDeclaration | ConstructSignatureDeclaration {
function parseSignatureMember(kind: SyntaxKind.CallSignature | SyntaxKind.ConstructSignature): CallSignatureDeclaration | ConstructSignatureDeclaration {
const node = <CallSignatureDeclaration | ConstructSignatureDeclaration>createNode(kind);
if (kind === SyntaxKind.ConstructSignature) {
parseExpected(SyntaxKind.NewKeyword);
Expand Down Expand Up @@ -2445,7 +2445,7 @@ namespace ts {
node.parameters = parseBracketedList(ParsingContext.Parameters, parseParameter, SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken);
node.type = parseTypeAnnotation();
parseTypeMemberSemicolon();
return finishNode(node);
return addJSDocComment(finishNode(node));
}

function parsePropertyOrMethodSignature(fullStart: number, modifiers: NodeArray<Modifier>): PropertySignature | MethodSignature {
Expand Down Expand Up @@ -2605,7 +2605,7 @@ namespace ts {
parseExpected(SyntaxKind.NewKeyword);
}
fillSignature(SyntaxKind.EqualsGreaterThanToken, SignatureFlags.Type, node);
return finishNode(node);
return addJSDocComment(finishNode(node));
}

function parseKeywordAndNoDot(): TypeNode | undefined {
Expand Down Expand Up @@ -6182,7 +6182,7 @@ namespace ts {
return jsDoc ? { jsDoc, diagnostics } : undefined;
}

export function parseJSDocComment(parent: Node, start: number, length: number): JSDoc {
export function parseJSDocComment(parent: HasJSDoc, start: number, length: number): JSDoc {
const saveToken = currentToken;
const saveParseDiagnosticsLength = parseDiagnostics.length;
const saveParseErrorBeforeNextFinishedNode = parseErrorBeforeNextFinishedNode;
Expand Down Expand Up @@ -6997,7 +6997,7 @@ namespace ts {
}

forEachChild(node, visitNode, visitArray);
if (node.jsDoc) {
if (hasJSDocNodes(node)) {
for (const jsDocComment of node.jsDoc) {
forEachChild(jsDocComment, visitNode, visitArray);
}
Expand Down
Loading