diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index fa44b6a3f5b..7d7c9cb89d6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -17863,9 +17863,9 @@ namespace ts { if (node.questionToken && isBindingPattern(node.name) && (func as FunctionLikeDeclaration).body) { error(node, Diagnostics.A_binding_pattern_parameter_cannot_be_optional_in_an_implementation_signature); } - if ((node.name).text === "this") { + if (node.name && ((node.name as Identifier).text === "this" || (node.name as Identifier).text === "new")) { if (indexOf(func.parameters, node) !== 0) { - error(node, Diagnostics.A_this_parameter_must_be_the_first_parameter); + error(node, Diagnostics.A_0_parameter_must_be_the_first_parameter, (node.name as Identifier).text as string); } if (func.kind === SyntaxKind.Constructor || func.kind === SyntaxKind.ConstructSignature || func.kind === SyntaxKind.ConstructorType) { error(node, Diagnostics.A_constructor_cannot_have_a_this_parameter); @@ -19370,14 +19370,6 @@ namespace ts { } } - function checkJSDocFunctionType(node: JSDocFunctionType) { - for (const p of node.parameters) { - // don't bother with normal parameter checking since jsdoc function parameters only consist of a type - checkSourceElement(p.type); - } - checkSourceElement(node.type); - } - function checkFunctionOrMethodDeclaration(node: FunctionDeclaration | MethodDeclaration): void { checkJSDoc(node); checkDecorators(node); @@ -19923,6 +19915,11 @@ namespace ts { function checkVariableLikeDeclaration(node: VariableLikeDeclaration) { checkDecorators(node); checkSourceElement(node.type); + + // JSDoc `function(string, string): string` syntax results in parameters with no name + if (!node.name) { + return; + } // For a computed property, just check the initializer and exit // Do not use hasDynamicName here, because that returns false for well known symbols. // We want to perform checkComputedPropertyName for all computed properties, including @@ -22042,7 +22039,7 @@ namespace ts { case SyntaxKind.JSDocParameterTag: return checkSourceElement((node as JSDocParameterTag).typeExpression); case SyntaxKind.JSDocFunctionType: - checkJSDocFunctionType(node as JSDocFunctionType); + checkSignatureDeclaration(node as JSDocFunctionType); // falls through case SyntaxKind.JSDocVariadicType: case SyntaxKind.JSDocNonNullableType: diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 9881d32d775..7cd6108576c 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2064,7 +2064,7 @@ "category": "Error", "code": 2679 }, - "A 'this' parameter must be the first parameter.": { + "A '{0}' parameter must be the first parameter.": { "category": "Error", "code": 2680 }, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 85e859603d7..c10cc299728 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -441,7 +441,7 @@ namespace ts { // we guarantee that users won't have to pay the price of walking the tree if a dynamic import isn't used. /* @internal */ PossiblyContainsDynamicImport = 1 << 19, - JSDoc = 1 << 20, // If node was parsed inside jsdoc + JSDoc = 1 << 20, // If node was parsed inside jsdoc BlockScoped = Let | Const, diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index dcfad8e776e..3a4ece29f75 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -4873,6 +4873,7 @@ namespace ts { case SyntaxKind.ConstructSignature: case SyntaxKind.IndexSignature: case SyntaxKind.FunctionType: + case SyntaxKind.JSDocFunctionType: case SyntaxKind.ConstructorType: return true; } diff --git a/tests/cases/fourslash/codeFixChangeJSDocSyntax1.ts b/tests/cases/fourslash/codeFixChangeJSDocSyntax1.ts deleted file mode 100644 index 93107ef669b..00000000000 --- a/tests/cases/fourslash/codeFixChangeJSDocSyntax1.ts +++ /dev/null @@ -1,4 +0,0 @@ -/// -//// var x: [|?|] = 12; - -verify.rangeAfterCodeFix("any");