From a51449fbaaa94572c26550f7f3d7424f28b253ca Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 6 Dec 2025 18:22:01 +0100 Subject: [PATCH 1/3] Process @overload tags only in limited contexts --- internal/parser/parser.go | 4 ++-- internal/parser/reparser.go | 29 +++++++++++++---------------- 2 files changed, 15 insertions(+), 18 deletions(-) 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< Date: Sat, 6 Dec 2025 18:23:22 +0100 Subject: [PATCH 2/3] Fix incorrect parsingContexts flag setting logic --- internal/parser/jsdoc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 9c9fd61abb0c307514712ba1034c0dea9b663ef6 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 6 Dec 2025 18:24:59 +0100 Subject: [PATCH 3/3] Accept new baselines --- .../submodule/compiler/jsFileAlternativeUseOfOverloadTag.js | 4 ---- .../compiler/jsFileAlternativeUseOfOverloadTag.js.diff | 6 +----- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/testdata/baselines/reference/submodule/compiler/jsFileAlternativeUseOfOverloadTag.js b/testdata/baselines/reference/submodule/compiler/jsFileAlternativeUseOfOverloadTag.js index ebe7145997..a33418fdbf 100644 --- a/testdata/baselines/reference/submodule/compiler/jsFileAlternativeUseOfOverloadTag.js +++ b/testdata/baselines/reference/submodule/compiler/jsFileAlternativeUseOfOverloadTag.js @@ -106,7 +106,6 @@ const example3 = { //// [jsFileAlternativeUseOfOverloadTag.d.ts] -declare function Example1(value: any): any; declare const example1: { /** * @overload Example1(value) @@ -115,8 +114,6 @@ declare const example1: { */ 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 @@ -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 */