MCPcopy Create free account
hub / github.com/microsoft/typescript-go / getExpandedParameters

Method getExpandedParameters

internal/checker/nodebuilderimpl.go:1906–1992  ·  view source on GitHub ↗
(sig *Signature, skipUnionExpanding bool)

Source from the content-addressed store, hash-verified

1904}
1905
1906func (c *Checker) getExpandedParameters(sig *Signature, skipUnionExpanding bool) [][]*ast.Symbol {
1907 if signatureHasRestParameter(sig) {
1908 restIndex := len(sig.parameters) - 1
1909 restSymbol := sig.parameters[restIndex]
1910 restType := c.getTypeOfSymbol(restSymbol)
1911 getUniqAssociatedNamesFromTupleType := func(t *Type, restSymbol *ast.Symbol) []string {
1912 names := core.MapIndex(t.Target().AsTupleType().elementInfos, func(info TupleElementInfo, i int) string {
1913 return c.getTupleElementLabel(info, restSymbol, i)
1914 })
1915 if len(names) > 0 {
1916 duplicates := []int{}
1917 uniqueNames := make(map[string]bool)
1918 for i, name := range names {
1919 _, ok := uniqueNames[name]
1920 if ok {
1921 duplicates = append(duplicates, i)
1922 } else {
1923 uniqueNames[name] = true
1924 }
1925 }
1926 counters := make(map[string]int)
1927 for _, i := range duplicates {
1928 counter, ok := counters[names[i]]
1929 if !ok {
1930 counter = 1
1931 }
1932 var name string
1933 for true {
1934 name = fmt.Sprintf("%s_%d", names[i], counter)
1935 _, ok := uniqueNames[name]
1936 if ok {
1937 counter++
1938 continue
1939 } else {
1940 uniqueNames[name] = true
1941 break
1942 }
1943 }
1944 names[i] = name
1945 counters[names[i]] = counter + 1
1946 }
1947 }
1948 return names
1949 }
1950 expandSignatureParametersWithTupleMembers := func(restType *Type, restIndex int, restSymbol *ast.Symbol) []*ast.Symbol {
1951 elementTypes := c.getTypeArguments(restType)
1952 associatedNames := getUniqAssociatedNamesFromTupleType(restType, restSymbol)
1953 restParams := core.MapIndex(elementTypes, func(t *Type, i int) *ast.Symbol {
1954 // Lookup the label from the individual tuple passed in before falling back to the signature `rest` parameter name
1955 // TODO: getTupleElementLabel can no longer fail, investigate if this lack of falliability meaningfully changes output
1956 // var name *string
1957 // if associatedNames != nil && associatedNames[i] != nil {
1958 // name = associatedNames[i]
1959 // } else {
1960 // name = c.getParameterNameAtPosition(sig, restIndex+i, restType)
1961 // }
1962 name := associatedNames[i]
1963 flags := restType.Target().AsTupleType().elementInfos[i].flags

Callers 3

GetExpandedParametersMethod · 0.95
enterSignatureScopeMethod · 0.80
pseudoTypeToNodeMethod · 0.80

Calls 15

getTypeOfSymbolMethod · 0.95
getTupleElementLabelMethod · 0.95
getTypeArgumentsMethod · 0.95
newSymbolExMethod · 0.95
createArrayTypeMethod · 0.95
MapIndexFunction · 0.92
ConcatenateFunction · 0.92
EveryFunction · 0.92
MapFunction · 0.92
lenFunction · 0.85
AsTupleTypeMethod · 0.80

Tested by

no test coverage detected