mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-14 19:16:17 -06:00
Improve JSDoc function checking
1. Remove checkJSDocFunctionType in favour of checkSignature. 2. Check that 'new', in addition to 'this', must be the first parameter. 3. Remove prematurely added JSDoc-quickfix test.
This commit is contained in:
parent
6e861fd3e6
commit
f1145c35ca
@ -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 ((<Identifier>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:
|
||||
|
||||
@ -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
|
||||
},
|
||||
|
||||
@ -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,
|
||||
|
||||
|
||||
@ -4873,6 +4873,7 @@ namespace ts {
|
||||
case SyntaxKind.ConstructSignature:
|
||||
case SyntaxKind.IndexSignature:
|
||||
case SyntaxKind.FunctionType:
|
||||
case SyntaxKind.JSDocFunctionType:
|
||||
case SyntaxKind.ConstructorType:
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1,4 +0,0 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
//// var x: [|?|] = 12;
|
||||
|
||||
verify.rangeAfterCodeFix("any");
|
||||
Loading…
x
Reference in New Issue
Block a user