diff --git a/internal/parser/jsdoc.go b/internal/parser/jsdoc.go index a3eec501ce..7ba7f6ca13 100644 --- a/internal/parser/jsdoc.go +++ b/internal/parser/jsdoc.go @@ -133,7 +133,7 @@ func (p *Parser) parseJSDocComment(parent *ast.Node, start int, end int, fullSta // +3 for leading `/**` p.scanner.ResetPos(start + 3) p.setContextFlags(ast.NodeFlagsJSDoc, true) - p.parsingContexts = p.parsingContexts | ParsingContexts(PCJSDocComment) + p.parsingContexts |= 1 << PCJSDocComment comment := p.parseJSDocCommentWorker(start, end, fullStart, initialIndent) // move jsdoc diagnostics to jsdocDiagnostics -- for JS files only diff --git a/internal/parser/parser.go b/internal/parser/parser.go index 615286cf6b..fdb9fafe56 100644 --- a/internal/parser/parser.go +++ b/internal/parser/parser.go @@ -345,7 +345,7 @@ func (p *Parser) parseSourceFileWorker() *ast.SourceFile { if eof.Kind != ast.KindEndOfFile { panic("Expected end of file token from scanner.") } - if len(p.reparseList) > 0 { + if len(p.reparseList) != 0 { statements = append(statements, p.reparseList...) p.reparseList = nil } @@ -504,7 +504,7 @@ func (p *Parser) parseListIndex(kind ParsingContext, parseElement func(p *Parser for i := 0; !p.isListTerminator(kind); i++ { if p.isListElement(kind, false /*inErrorRecovery*/) { elt := parseElement(p, len(list)) - if len(p.reparseList) > 0 { + if len(p.reparseList) != 0 { for _, e := range p.reparseList { // Propagate @typedef type alias declarations outwards to a context that permits them. if (ast.IsJSTypeAliasDeclaration(e) || ast.IsJSImportDeclaration(e)) && kind != PCSourceElements && kind != PCBlockStatements { diff --git a/internal/parser/reparser.go b/internal/parser/reparser.go index c795ad3d82..2b8c04d6d6 100644 --- a/internal/parser/reparser.go +++ b/internal/parser/reparser.go @@ -111,8 +111,9 @@ func (p *Parser) reparseUnhosted(tag *ast.Node, parent *ast.Node, jsDoc *ast.Nod p.finishReparsedNode(importDeclaration, tag) p.reparseList = append(p.reparseList, importDeclaration) case ast.KindJSDocOverloadTag: - if fun, ok := getFunctionLikeHost(parent); ok { - p.reparseList = append(p.reparseList, p.reparseJSDocSignature(tag.AsJSDocOverloadTag().TypeExpression, fun, jsDoc, tag, fun.Modifiers())) + // Create overload signatures only for function, method, and constructor declarations outside object literals + if (ast.IsFunctionDeclaration(parent) || ast.IsMethodDeclaration(parent) || ast.IsConstructorDeclaration(parent)) && p.parsingContexts&(1< void; }; -declare function Example2(value: any, secretAccessKey: any, sessionToken: any): any; -declare function Example2(): any; declare const example2: { /** * Example 2 @@ -138,7 +135,6 @@ declare const example2: { */ constructor: () => void; }; -declare function evaluate(): any; type callback = (error: any, result: any) => any; declare const example3: { /** diff --git a/testdata/baselines/reference/submodule/compiler/jsFileAlternativeUseOfOverloadTag.js.diff b/testdata/baselines/reference/submodule/compiler/jsFileAlternativeUseOfOverloadTag.js.diff index f2d21bc5a2..a7fb84a241 100644 --- a/testdata/baselines/reference/submodule/compiler/jsFileAlternativeUseOfOverloadTag.js.diff +++ b/testdata/baselines/reference/submodule/compiler/jsFileAlternativeUseOfOverloadTag.js.diff @@ -5,7 +5,6 @@ //// [jsFileAlternativeUseOfOverloadTag.d.ts] -declare namespace example1 { -+declare function Example1(value: any): any; +declare const example1: { /** * @overload Example1(value) @@ -58,8 +57,6 @@ -declare namespace example3 { + constructor: (value: any, options: any) => void; +}; -+declare function Example2(value: any, secretAccessKey: any, sessionToken: any): any; -+declare function Example2(): any; +declare const example2: { + /** + * Example 2 @@ -81,13 +78,12 @@ + */ + constructor: () => void; +}; -+declare function evaluate(): any; +type callback = (error: any, result: any) => any; +declare const example3: { /** * @overload evaluate(options = {}, [callback]) * Evaluate something -@@= skipped -63, +48 lines =@@ +@@= skipped -63, +44 lines =@@ * @param result [String] * @see callback */