MCPcopy Index your code
hub / github.com/nodejs/node / isOptionalParameter

Function isOptionalParameter

test/fixtures/snapshot/typescript.js:59547–59567  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

59545 return symbol && withAugmentations ? getMergedSymbol(symbol) : symbol;
59546 }
59547 function isOptionalParameter(node) {
59548 if (ts.hasQuestionToken(node) || isOptionalJSDocPropertyLikeTag(node) || isJSDocOptionalParameter(node)) {
59549 return true;
59550 }
59551 if (node.initializer) {
59552 var signature = getSignatureFromDeclaration(node.parent);
59553 var parameterIndex = node.parent.parameters.indexOf(node);
59554 ts.Debug.assert(parameterIndex >= 0);
59555 // Only consider syntactic or instantiated parameters as optional, not `void` parameters as this function is used
59556 // in grammar checks and checking for `void` too early results in parameter types widening too early
59557 // and causes some noImplicitAny errors to be lost.
59558 return parameterIndex >= getMinArgumentCount(signature, 1 /* MinArgumentCountFlags.StrongArityForUntypedJS */ | 2 /* MinArgumentCountFlags.VoidIsNonOptional */);
59559 }
59560 var iife = ts.getImmediatelyInvokedFunctionExpression(node.parent);
59561 if (iife) {
59562 return !node.type &&
59563 !node.dotDotDotToken &&
59564 node.parent.parameters.indexOf(node) >= iife.arguments.length;
59565 }
59566 return false;
59567 }
59568 function isOptionalPropertyDeclaration(node) {
59569 return ts.isPropertyDeclaration(node) && node.questionToken;
59570 }

Calls 6

isJSDocOptionalParameterFunction · 0.85
getMinArgumentCountFunction · 0.85
assertMethod · 0.80
indexOfMethod · 0.45

Tested by

no test coverage detected