Skip to content

Commit d45f3ef

Browse files
committed
Defer creation of map object in createUnionOrIntersectionProperty
1 parent 1cc7a53 commit d45f3ef

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/compiler/checker.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10353,7 +10353,8 @@ namespace ts {
1035310353
}
1035410354

1035510355
function createUnionOrIntersectionProperty(containingType: UnionOrIntersectionType, name: __String): Symbol | undefined {
10356-
const propSet = createMap<Symbol>();
10356+
let singleProp: Symbol | undefined;
10357+
let propSet: Map<Symbol> | undefined;
1035710358
let indexTypes: Type[] | undefined;
1035810359
const isUnion = containingType.flags & TypeFlags.Union;
1035910360
const excludeModifiers = isUnion ? ModifierFlags.NonPublicAccessibilityModifier : 0;
@@ -10373,9 +10374,18 @@ namespace ts {
1037310374
else {
1037410375
optionalFlag &= prop.flags;
1037510376
}
10376-
const id = "" + getSymbolId(prop);
10377-
if (!propSet.has(id)) {
10378-
propSet.set(id, prop);
10377+
if (!singleProp) {
10378+
singleProp = prop;
10379+
}
10380+
else if (prop !== singleProp) {
10381+
if (!propSet) {
10382+
propSet = createMap<Symbol>();
10383+
propSet.set("" + getSymbolId(singleProp), singleProp);
10384+
}
10385+
const id = "" + getSymbolId(prop);
10386+
if (!propSet.has(id)) {
10387+
propSet.set(id, prop);
10388+
}
1037910389
}
1038010390
checkFlags |= (isReadonlySymbol(prop) ? CheckFlags.Readonly : 0) |
1038110391
(!(modifiers & ModifierFlags.NonPublicAccessibilityModifier) ? CheckFlags.ContainsPublic : 0) |
@@ -10402,13 +10412,13 @@ namespace ts {
1040210412
}
1040310413
}
1040410414
}
10405-
if (!propSet.size) {
10415+
if (!singleProp) {
1040610416
return undefined;
1040710417
}
10408-
const props = arrayFrom(propSet.values());
10409-
if (props.length === 1 && !(checkFlags & CheckFlags.ReadPartial) && !indexTypes) {
10410-
return props[0];
10418+
if (!propSet && !(checkFlags & CheckFlags.ReadPartial) && !indexTypes) {
10419+
return singleProp;
1041110420
}
10421+
const props = propSet ? arrayFrom(propSet.values()) : [singleProp];
1041210422
let declarations: Declaration[] | undefined;
1041310423
let firstType: Type | undefined;
1041410424
let nameType: Type | undefined;

0 commit comments

Comments
 (0)