diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 65cd8e7ae8f..5e89cd89b98 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -439,7 +439,8 @@ namespace ts { // during global merging in the checker. Why? The only case when ambient module is permitted inside another module is module augmentation // and this case is specially handled. Module augmentations should only be merged with original module definition // and should never be merged directly with other augmentation, and the latter case would be possible if automatic merge is allowed. - const isJSDocTypedefInJSDocNamespace = isInJavaScriptFile(node) && node.kind === SyntaxKind.JSDocTypedefTag && + if (node.kind === SyntaxKind.JSDocTypedefTag) Debug.assert(isInJavaScriptFile(node)); // We shouldn't add symbols for JSDoc nodes if not in a JS file. + const isJSDocTypedefInJSDocNamespace = node.kind === SyntaxKind.JSDocTypedefTag && (node as JSDocTypedefTag).name && (node as JSDocTypedefTag).name.kind === SyntaxKind.Identifier && ((node as JSDocTypedefTag).name as Identifier).isInJSDocNamespace; @@ -603,9 +604,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) { - forEach(node.jsDoc, bind); - } + forEach(node.jsDoc, bind); if (checkUnreachable(node)) { bindEachChild(node); return; @@ -2071,10 +2070,7 @@ namespace ts { return bindVariableDeclarationOrBindingElement(node); case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: - case SyntaxKind.JSDocRecordMember: - return bindPropertyOrMethodOrAccessor(node, SymbolFlags.Property | ((node).questionToken ? SymbolFlags.Optional : SymbolFlags.None), SymbolFlags.PropertyExcludes); - case SyntaxKind.JSDocPropertyTag: - return bindJSDocProperty(node); + return bindPropertyWorker(node as PropertyDeclaration | PropertySignature); case SyntaxKind.PropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: return bindPropertyOrMethodOrAccessor(node, SymbolFlags.Property, SymbolFlags.PropertyExcludes); @@ -2119,13 +2115,10 @@ namespace ts { return bindPropertyOrMethodOrAccessor(node, SymbolFlags.SetAccessor, SymbolFlags.SetAccessorExcludes); case SyntaxKind.FunctionType: case SyntaxKind.ConstructorType: - case SyntaxKind.JSDocFunctionType: return bindFunctionOrConstructorType(node); case SyntaxKind.TypeLiteral: case SyntaxKind.MappedType: - case SyntaxKind.JSDocTypeLiteral: - case SyntaxKind.JSDocRecordType: - return bindAnonymousDeclaration(node, SymbolFlags.TypeLiteral, "__type"); + return bindAnonymousTypeWorker(node as TypeLiteralNode | MappedTypeNode); case SyntaxKind.ObjectLiteralExpression: return bindObjectLiteralExpression(node); case SyntaxKind.FunctionExpression: @@ -2146,11 +2139,6 @@ namespace ts { return bindClassLikeDeclaration(node); case SyntaxKind.InterfaceDeclaration: return bindBlockScopedDeclaration(node, SymbolFlags.Interface, SymbolFlags.InterfaceExcludes); - case SyntaxKind.JSDocTypedefTag: - if (isInJavaScriptFile(node) && (!(node).fullName || (node).fullName.kind === SyntaxKind.Identifier)) { - return bindBlockScopedDeclaration(node, SymbolFlags.TypeAlias, SymbolFlags.TypeAliasExcludes); - } - break; case SyntaxKind.TypeAliasDeclaration: return bindBlockScopedDeclaration(node, SymbolFlags.TypeAlias, SymbolFlags.TypeAliasExcludes); case SyntaxKind.EnumDeclaration: @@ -2188,9 +2176,41 @@ namespace ts { // falls through case SyntaxKind.ModuleBlock: return updateStrictModeStatementList((node).statements); + + default: + if (isInJavaScriptFile(node)) return bindJSDocWorker(node); } } + function bindJSDocWorker(node: Node) { + switch (node.kind) { + case SyntaxKind.JSDocRecordMember: + return bindPropertyWorker(node as JSDocRecordMember); + case SyntaxKind.JSDocPropertyTag: + return declareSymbolAndAddToSymbolTable(node as JSDocPropertyTag, SymbolFlags.Property, SymbolFlags.PropertyExcludes); + case SyntaxKind.JSDocFunctionType: + return bindFunctionOrConstructorType(node); + case SyntaxKind.JSDocTypeLiteral: + case SyntaxKind.JSDocRecordType: + return bindAnonymousTypeWorker(node as JSDocTypeLiteral | JSDocRecordType); + case SyntaxKind.JSDocTypedefTag: { + const { fullName } = node as JSDocTypedefTag; + if (!fullName || fullName.kind === SyntaxKind.Identifier) { + return bindBlockScopedDeclaration(node, SymbolFlags.TypeAlias, SymbolFlags.TypeAliasExcludes); + } + break; + } + } + } + + function bindPropertyWorker(node: PropertyDeclaration | PropertySignature) { + return bindPropertyOrMethodOrAccessor(node, SymbolFlags.Property | (node.questionToken ? SymbolFlags.Optional : SymbolFlags.None), SymbolFlags.PropertyExcludes); + } + + function bindAnonymousTypeWorker(node: TypeLiteralNode | MappedTypeNode | JSDocTypeLiteral | JSDocRecordType) { + return bindAnonymousDeclaration(node, SymbolFlags.TypeLiteral, "__type"); + } + function checkTypePredicate(node: TypePredicateNode) { const { parameterName, type } = node; if (parameterName && parameterName.kind === SyntaxKind.Identifier) { @@ -2556,10 +2576,8 @@ namespace ts { } function bindPropertyOrMethodOrAccessor(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags) { - if (!isDeclarationFile(file) && !isInAmbientContext(node)) { - if (isAsyncFunction(node)) { - emitFlags |= NodeFlags.HasAsyncFunctions; - } + if (!isDeclarationFile(file) && !isInAmbientContext(node) && isAsyncFunction(node)) { + emitFlags |= NodeFlags.HasAsyncFunctions; } if (currentFlow && isObjectLiteralOrClassExpressionMethod(node)) { @@ -2571,10 +2589,6 @@ namespace ts { : declareSymbolAndAddToSymbolTable(node, symbolFlags, symbolExcludes); } - function bindJSDocProperty(node: JSDocPropertyTag) { - return declareSymbolAndAddToSymbolTable(node, SymbolFlags.Property, SymbolFlags.PropertyExcludes); - } - // reachability checks function shouldReportErrorOnModuleDeclaration(node: ModuleDeclaration): boolean {