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

Function maybeAddJsSyntheticRestParameter

test/fixtures/snapshot/typescript.js:59702–59731  ·  view source on GitHub ↗

* A JS function gets a synthetic rest parameter if it references `arguments` AND: * 1. It has no parameters but at least one `@param` with a type that starts with `...` * OR * 2. It has at least one parameter, and the last parameter has a matching `@param` with a type that

(declaration, parameters)

Source from the content-addressed store, hash-verified

59700 * 2. It has at least one parameter, and the last parameter has a matching `@param` with a type that starts with `...`
59701 */
59702 function maybeAddJsSyntheticRestParameter(declaration, parameters) {
59703 if (ts.isJSDocSignature(declaration) || !containsArgumentsReference(declaration)) {
59704 return false;
59705 }
59706 var lastParam = ts.lastOrUndefined(declaration.parameters);
59707 var lastParamTags = lastParam ? ts.getJSDocParameterTags(lastParam) : ts.getJSDocTags(declaration).filter(ts.isJSDocParameterTag);
59708 var lastParamVariadicType = ts.firstDefined(lastParamTags, function (p) {
59709 return p.typeExpression && ts.isJSDocVariadicType(p.typeExpression.type) ? p.typeExpression.type : undefined;
59710 });
59711 var syntheticArgsSymbol = createSymbol(3 /* SymbolFlags.Variable */, "args", 32768 /* CheckFlags.RestParameter */);
59712 if (lastParamVariadicType) {
59713 // Parameter has effective annotation, lock in type
59714 syntheticArgsSymbol.type = createArrayType(getTypeFromTypeNode(lastParamVariadicType.type));
59715 }
59716 else {
59717 // Parameter has no annotation
59718 // By using a `DeferredType` symbol, we allow the type of this rest arg to be overriden by contextual type assignment so long as its type hasn't been
59719 // cached by `getTypeOfSymbol` yet.
59720 syntheticArgsSymbol.checkFlags |= 65536 /* CheckFlags.DeferredType */;
59721 syntheticArgsSymbol.deferralParent = neverType;
59722 syntheticArgsSymbol.deferralConstituents = [anyArrayType];
59723 syntheticArgsSymbol.deferralWriteConstituents = [anyArrayType];
59724 }
59725 if (lastParamVariadicType) {
59726 // Replace the last parameter with a rest parameter.
59727 parameters.pop();
59728 }
59729 parameters.push(syntheticArgsSymbol);
59730 return true;
59731 }
59732 function getSignatureOfTypeTag(node) {
59733 // should be attached to a function declaration or expression
59734 if (!(ts.isInJSFile(node) && ts.isFunctionLikeDeclaration(node)))

Callers 1

Calls 7

createSymbolFunction · 0.85
createArrayTypeFunction · 0.85
getTypeFromTypeNodeFunction · 0.85
popMethod · 0.80
filterMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…