Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions tsc/internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ type Checker struct {
memberIndexSlotsArena core.Arena[uint32]
freeTypeSets *temporaryTypeSet
freePropertyCounts *temporaryPropertyCounts
freeNameSets []map[string]struct{}
mergedSymbols map[*ast.Symbol]*ast.Symbol
mergedExportsChecked collections.Set[*ast.Symbol]
factory ast.NodeFactory
Expand Down Expand Up @@ -19328,12 +19329,13 @@ func (c *Checker) getPropertiesOfObjectType(t *Type) []*ast.Symbol {
func (c *Checker) getPropertiesOfUnionOrIntersectionType(t *Type) []*ast.Symbol {
d := t.AsUnionOrIntersectionType()
if d.resolvedProperties == nil {
var checked collections.Set[string]
checked := c.getTemporaryNameSet()
defer c.releaseTemporaryNameSet(checked)
props := []*ast.Symbol{}
for _, current := range d.types {
for _, prop := range c.getPropertiesOfType(current) {
if !checked.Has(prop.Name()) {
checked.Add(prop.Name())
if _, ok := checked[prop.Name()]; !ok {
checked[prop.Name()] = struct{}{}
combinedProp := c.getPropertyOfUnionOrIntersectionType(t, prop.Name(), t.flags&TypeFlagsIntersection != 0 /*skipObjectFunctionPropertyAugment*/)
if combinedProp != nil {
props = append(props, combinedProp)
Expand Down
20 changes: 20 additions & 0 deletions tsc/internal/checker/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,26 @@ func (c *Checker) releaseTemporaryPropertyCounts(counts *temporaryPropertyCounts
c.freePropertyCounts = counts
}

// Property enumeration of a combined type may recursively enumerate other
// combined types, so each call borrows a separate name set.
func (c *Checker) getTemporaryNameSet() map[string]struct{} {
if n := len(c.freeNameSets); n != 0 {
set := c.freeNameSets[n-1]
c.freeNameSets = c.freeNameSets[:n-1]
return set
}
return make(map[string]struct{})
}

func (c *Checker) releaseTemporaryNameSet(set map[string]struct{}) {
// Do not retain unusually large tables in the free list.
if len(set) > 4096 {
return
}
clear(set)
c.freeNameSets = append(c.freeNameSets, set)
}

func (s *orderedSet[T]) contains(value T) bool {
if s.valuesByKey == nil {
return slices.Contains(s.values, value)
Expand Down
Loading