From ed8cebad3a4730b570cb34d6b74ff53b4c38980e Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 14 Mar 2019 14:12:17 -0700 Subject: [PATCH 1/4] Handle huge unions better in createUnionOrIntersectionProperty --- src/compiler/checker.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5d48697610155..a4750ea0fa107 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7769,7 +7769,7 @@ namespace ts { } function createUnionOrIntersectionProperty(containingType: UnionOrIntersectionType, name: __String): Symbol | undefined { - let props: Symbol[] | undefined; + const propSet = createMap(); let indexTypes: Type[] | undefined; const isUnion = containingType.flags & TypeFlags.Union; const excludeModifiers = isUnion ? ModifierFlags.NonPublicAccessibilityModifier : 0; @@ -7784,7 +7784,7 @@ namespace ts { const modifiers = prop ? getDeclarationModifierFlagsFromSymbol(prop) : 0; if (prop && !(modifiers & excludeModifiers)) { commonFlags &= prop.flags; - props = appendIfUnique(props, prop); + propSet.set("" + getSymbolId(prop), prop); checkFlags |= (isReadonlySymbol(prop) ? CheckFlags.Readonly : 0) | (!(modifiers & ModifierFlags.NonPublicAccessibilityModifier) ? CheckFlags.ContainsPublic : 0) | (modifiers & ModifierFlags.Protected ? CheckFlags.ContainsProtected : 0) | @@ -7806,6 +7806,7 @@ namespace ts { } } } + const props = arrayFrom(propSet.values()); if (!props) { return undefined; } From 528e86307a804b7304dbc72256408dc9c8ade74c Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 14 Mar 2019 14:43:17 -0700 Subject: [PATCH 2/4] Mimic first-in-wins behavior of pushIfUnique to retain order --- src/compiler/checker.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a4750ea0fa107..38e4fe2520d4c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7784,7 +7784,10 @@ namespace ts { const modifiers = prop ? getDeclarationModifierFlagsFromSymbol(prop) : 0; if (prop && !(modifiers & excludeModifiers)) { commonFlags &= prop.flags; - propSet.set("" + getSymbolId(prop), prop); + const id = "" + getSymbolId(prop); + if (!propSet.has(id)) { + propSet.set(id, prop); + } checkFlags |= (isReadonlySymbol(prop) ? CheckFlags.Readonly : 0) | (!(modifiers & ModifierFlags.NonPublicAccessibilityModifier) ? CheckFlags.ContainsPublic : 0) | (modifiers & ModifierFlags.Protected ? CheckFlags.ContainsProtected : 0) | From eb21c09bdbde891644012e4402280c16d204646b Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 14 Mar 2019 14:47:21 -0700 Subject: [PATCH 3/4] !props -> props.length === 0 (why dont we warn on that ffs) --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 38e4fe2520d4c..5337073a7c744 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7810,7 +7810,7 @@ namespace ts { } } const props = arrayFrom(propSet.values()); - if (!props) { + if (props.length === 0) { return undefined; } if (props.length === 1 && !(checkFlags & CheckFlags.Partial) && !indexTypes) { From 92234c02da57e5f241ddfbcf479746a2ab37e499 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Mon, 18 Mar 2019 16:07:25 -0700 Subject: [PATCH 4/4] Avoid collection into an array if there are no properties --- src/compiler/checker.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0c6a372ed3b24..2b951a2e60abb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7812,10 +7812,10 @@ namespace ts { } } } - const props = arrayFrom(propSet.values()); - if (props.length === 0) { + if (!propSet.size) { return undefined; } + const props = arrayFrom(propSet.values()); if (props.length === 1 && !(checkFlags & CheckFlags.Partial) && !indexTypes) { return props[0]; }