Skip to content

Ensure we don't copy OrderedMaps #1003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 31, 2025
Merged
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
4 changes: 2 additions & 2 deletions internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -20072,7 +20072,7 @@ func (c *Checker) createUnionOrIntersectionProperty(containingType *Type, name s
if singleProp == nil || isUnion &&
(propSet.Size() != 0 || checkFlags&ast.CheckFlagsPartial != 0) &&
checkFlags&(ast.CheckFlagsContainsPrivate|ast.CheckFlagsContainsProtected) != 0 &&
!(propSet.Size() != 0 && c.hasCommonDeclaration(propSet)) {
!(propSet.Size() != 0 && c.hasCommonDeclaration(&propSet)) {
// No property was found, or, in a union, a property has a private or protected declaration in one
// constituent, but is missing or has a different declaration in another constituent.
return nil
Expand Down Expand Up @@ -20194,7 +20194,7 @@ func isPrototypeProperty(symbol *ast.Symbol) bool {
return symbol.Flags&ast.SymbolFlagsMethod != 0 || symbol.CheckFlags&ast.CheckFlagsSyntheticMethod != 0
}

func (c *Checker) hasCommonDeclaration(symbols collections.OrderedSet[*ast.Symbol]) bool {
func (c *Checker) hasCommonDeclaration(symbols *collections.OrderedSet[*ast.Symbol]) bool {
var commonDeclarations core.Set[*ast.Node]
for symbol := range symbols.Values() {
if len(symbol.Declarations) == 0 {
Expand Down
14 changes: 13 additions & 1 deletion internal/collections/ordered_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,22 @@ import (

// OrderedMap is an insertion ordered map.
type OrderedMap[K comparable, V any] struct {
_ noCopy
keys []K
mp map[K]V
}

// noCopy may be embedded into structs which must not be copied
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be we should do this for orderedSet and syncmap as well ?

// after the first use.
//
// See https://golang.org/issues/8005#issuecomment-190753527
// for details.
type noCopy struct{}

// Lock is a no-op used by -copylocks checker from `go vet`.
func (*noCopy) Lock() {}
func (*noCopy) Unlock() {}

// NewOrderedMapWithSizeHint creates a new OrderedMap with a hint for the number of elements it will contain.
func NewOrderedMapWithSizeHint[K comparable, V any](hint int) *OrderedMap[K, V] {
m := newMapWithSizeHint[K, V](hint)
Expand Down Expand Up @@ -191,7 +203,7 @@ func (m *OrderedMap[K, V]) clone() OrderedMap[K, V] {
}
}

func (m OrderedMap[K, V]) MarshalJSON() ([]byte, error) {
func (m *OrderedMap[K, V]) MarshalJSON() ([]byte, error) {
if len(m.mp) == 0 {
return []byte("{}"), nil
}
Expand Down
4 changes: 2 additions & 2 deletions internal/tsoptions/tsconfigparsing.go
Original file line number Diff line number Diff line change
Expand Up @@ -1471,7 +1471,7 @@ func hasFileWithHigherPriorityExtension(file string, extensions [][]string, hasF

// Removes files included via wildcard expansion with a lower extension priority that have already been included.
// file is the path to the file.
func removeWildcardFilesWithLowerPriorityExtension(file string, wildcardFiles collections.OrderedMap[string, string], extensions [][]string, keyMapper func(value string) string) {
func removeWildcardFilesWithLowerPriorityExtension(file string, wildcardFiles *collections.OrderedMap[string, string], extensions [][]string, keyMapper func(value string) string) {
var extensionGroup []string
for _, group := range extensions {
if tspath.FileExtensionIsOneOf(file, group) {
Expand Down Expand Up @@ -1575,7 +1575,7 @@ func getFileNamesFromConfigSpecs(
// extension due to the user-defined order of entries in the
// "include" array. If there is a lower priority extension in the
// same directory, we should remove it.
removeWildcardFilesWithLowerPriorityExtension(file, wildcardFileMap, supportedExtensions, keyMappper)
removeWildcardFilesWithLowerPriorityExtension(file, &wildcardFileMap, supportedExtensions, keyMappper)
key := keyMappper(file)
if !literalFileMap.Has(key) && !wildcardFileMap.Has(key) {
wildcardFileMap.Set(key, file)
Expand Down