Skip to content

Commit 567f563

Browse files
committed
Create spread property types eagerly
This avoids the need for a synthetic symbol and later code called from getTypeOfSymbol.
1 parent f03fecb commit 567f563

File tree

3 files changed

+16
-30
lines changed

3 files changed

+16
-30
lines changed

src/compiler/checker.ts

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3550,9 +3550,6 @@ namespace ts {
35503550
if (symbol.flags & SymbolFlags.Instantiated) {
35513551
return getTypeOfInstantiatedSymbol(symbol);
35523552
}
3553-
if (symbol.flags & SymbolFlags.SyntheticProperty && symbol.syntheticKind === SyntheticSymbolKind.Spread) {
3554-
return getTypeOfSpreadProperty(symbol);
3555-
}
35563553
if (symbol.flags & (SymbolFlags.Variable | SymbolFlags.Property)) {
35573554
return getTypeOfVariableOrParameterOrProperty(symbol);
35583555
}
@@ -3571,14 +3568,6 @@ namespace ts {
35713568
return unknownType;
35723569
}
35733570

3574-
function getTypeOfSpreadProperty(symbol: Symbol) {
3575-
const links = getSymbolLinks(symbol);
3576-
if (!links.type) {
3577-
links.type = getUnionType([getTypeOfSymbol(links.leftSpread), getTypeOfSymbol(links.rightSpread)]);
3578-
}
3579-
return links.type;
3580-
}
3581-
35823571
function getTargetType(type: Type): Type {
35833572
return getObjectFlags(type) & ObjectFlags.Reference ? (<TypeReference>type).target : type;
35843573
}
@@ -4588,7 +4577,6 @@ namespace ts {
45884577
propTypes.push(type);
45894578
}
45904579
const result = <TransientSymbol>createSymbol(SymbolFlags.Property | SymbolFlags.Transient | SymbolFlags.SyntheticProperty | commonFlags, name);
4591-
result.syntheticKind = SyntheticSymbolKind.UnionOrIntersection;
45924580
result.containingType = containingType;
45934581
result.hasNonUniformType = hasNonUniformType;
45944582
result.isPartial = isPartial;
@@ -5932,9 +5920,9 @@ namespace ts {
59325920
const rightProp = members[leftProp.name];
59335921
if (rightProp.flags & SymbolFlags.Optional) {
59345922
const declarations: Declaration[] = concatenate(leftProp.declarations, rightProp.declarations);
5935-
const flags = SymbolFlags.Property | SymbolFlags.Transient | SymbolFlags.SyntheticProperty | (leftProp.flags & SymbolFlags.Optional);
5923+
const flags = SymbolFlags.Property | SymbolFlags.Transient | (leftProp.flags & SymbolFlags.Optional);
59365924
const result = <TransientSymbol>createSymbol(flags, leftProp.name);
5937-
result.syntheticKind = SyntheticSymbolKind.Spread;
5925+
result.type = getUnionType([getTypeOfSymbol(leftProp), getTypeOfSymbol(rightProp)]);
59385926
result.leftSpread = leftProp;
59395927
result.rightSpread = rightProp;
59405928
result.declarations = declarations;
@@ -19220,23 +19208,21 @@ namespace ts {
1922019208

1922119209
function getRootSymbols(symbol: Symbol): Symbol[] {
1922219210
if (symbol.flags & SymbolFlags.SyntheticProperty) {
19223-
if (symbol.syntheticKind === SyntheticSymbolKind.Spread) {
19224-
const links = getSymbolLinks(symbol);
19225-
return [links.leftSpread, links.rightSpread];
19226-
}
19227-
else {
19228-
const symbols: Symbol[] = [];
19229-
const name = symbol.name;
19230-
forEach(getSymbolLinks(symbol).containingType.types, t => {
19231-
const symbol = getPropertyOfType(t, name);
19232-
if (symbol) {
19233-
symbols.push(symbol);
19234-
}
19235-
});
19236-
return symbols;
19237-
}
19211+
const symbols: Symbol[] = [];
19212+
const name = symbol.name;
19213+
forEach(getSymbolLinks(symbol).containingType.types, t => {
19214+
const symbol = getPropertyOfType(t, name);
19215+
if (symbol) {
19216+
symbols.push(symbol);
19217+
}
19218+
});
19219+
return symbols;
1923819220
}
1923919221
else if (symbol.flags & SymbolFlags.Transient) {
19222+
if ((symbol as SymbolLinks).leftSpread) {
19223+
const links = symbol as SymbolLinks;
19224+
return [links.leftSpread, links.rightSpread];
19225+
}
1924019226
let target: Symbol;
1924119227
let next = symbol;
1924219228
while (next = getSymbolLinks(next).target) {

src/compiler/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2590,7 +2590,6 @@ namespace ts {
25902590
/* @internal */ isReferenced?: boolean; // True if the symbol is referenced elsewhere
25912591
/* @internal */ isReplaceableByMethod?: boolean; // Can this Javascript class property be replaced by a method symbol?
25922592
/* @internal */ isAssigned?: boolean; // True if the symbol is a parameter with assignments
2593-
/* @internal */ syntheticKind?: SyntheticSymbolKind; // Synthetic symbols are either spread or union/intersection
25942593
}
25952594

25962595
/* @internal */

src/compiler/utilities.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4311,6 +4311,7 @@ namespace ts {
43114311
namespace ts {
43124312
export function getDefaultLibFileName(options: CompilerOptions): string {
43134313
switch (options.target) {
4314+
case ScriptTarget.ESNext:
43144315
case ScriptTarget.ES2017:
43154316
return "lib.es2017.d.ts";
43164317
case ScriptTarget.ES2016:

0 commit comments

Comments
 (0)