Merge pull request #13905 from Microsoft/optionalParametersInJSFunctions

Treat function paramters in a .js file with no JSDoc as optional
This commit is contained in:
Mohamed Hegazy
2017-02-09 16:46:19 -08:00
committed by GitHub
7 changed files with 120 additions and 1 deletions

View File

@@ -5241,6 +5241,7 @@ namespace ts {
let hasThisParameter: boolean;
const iife = getImmediatelyInvokedFunctionExpression(declaration);
const isJSConstructSignature = isJSDocConstructSignature(declaration);
const isUntypedSignatureInJSFile = !iife && !isJSConstructSignature && isInJavaScriptFile(declaration) && !hasJSDocParameterTags(declaration);
// If this is a JSDoc construct signature, then skip the first parameter in the
// parameter list. The first parameter represents the return type of the construct
@@ -5269,7 +5270,8 @@ namespace ts {
// Record a new minimum argument count if this is not an optional parameter
const isOptionalParameter = param.initializer || param.questionToken || param.dotDotDotToken ||
iife && parameters.length > iife.arguments.length && !param.type ||
isJSDocOptionalParameter(param);
isJSDocOptionalParameter(param) ||
isUntypedSignatureInJSFile;
if (!isOptionalParameter) {
minArgumentCount = parameters.length;
}

View File

@@ -1518,6 +1518,11 @@ namespace ts {
return map(getJSDocs(node), doc => doc.comment);
}
export function hasJSDocParameterTags(node: FunctionLikeDeclaration | SignatureDeclaration) {
const parameterTags = getJSDocTags(node, SyntaxKind.JSDocParameterTag);
return parameterTags && parameterTags.length > 0;
}
function getJSDocTags(node: Node, kind: SyntaxKind): JSDocTag[] {
const docs = getJSDocs(node);
if (docs) {