From 567f5636e3e4c9bf4790f99fd8bb2e07afcb8561 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Mon, 7 Nov 2016 13:02:05 -0800 Subject: [PATCH] Create spread property types eagerly This avoids the need for a synthetic symbol and later code called from getTypeOfSymbol. --- src/compiler/checker.ts | 44 +++++++++++++-------------------------- src/compiler/types.ts | 1 - src/compiler/utilities.ts | 1 + 3 files changed, 16 insertions(+), 30 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b3200ab239b..73e4e273d66 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3550,9 +3550,6 @@ namespace ts { if (symbol.flags & SymbolFlags.Instantiated) { return getTypeOfInstantiatedSymbol(symbol); } - if (symbol.flags & SymbolFlags.SyntheticProperty && symbol.syntheticKind === SyntheticSymbolKind.Spread) { - return getTypeOfSpreadProperty(symbol); - } if (symbol.flags & (SymbolFlags.Variable | SymbolFlags.Property)) { return getTypeOfVariableOrParameterOrProperty(symbol); } @@ -3571,14 +3568,6 @@ namespace ts { return unknownType; } - function getTypeOfSpreadProperty(symbol: Symbol) { - const links = getSymbolLinks(symbol); - if (!links.type) { - links.type = getUnionType([getTypeOfSymbol(links.leftSpread), getTypeOfSymbol(links.rightSpread)]); - } - return links.type; - } - function getTargetType(type: Type): Type { return getObjectFlags(type) & ObjectFlags.Reference ? (type).target : type; } @@ -4588,7 +4577,6 @@ namespace ts { propTypes.push(type); } const result = createSymbol(SymbolFlags.Property | SymbolFlags.Transient | SymbolFlags.SyntheticProperty | commonFlags, name); - result.syntheticKind = SyntheticSymbolKind.UnionOrIntersection; result.containingType = containingType; result.hasNonUniformType = hasNonUniformType; result.isPartial = isPartial; @@ -5932,9 +5920,9 @@ namespace ts { const rightProp = members[leftProp.name]; if (rightProp.flags & SymbolFlags.Optional) { const declarations: Declaration[] = concatenate(leftProp.declarations, rightProp.declarations); - const flags = SymbolFlags.Property | SymbolFlags.Transient | SymbolFlags.SyntheticProperty | (leftProp.flags & SymbolFlags.Optional); + const flags = SymbolFlags.Property | SymbolFlags.Transient | (leftProp.flags & SymbolFlags.Optional); const result = createSymbol(flags, leftProp.name); - result.syntheticKind = SyntheticSymbolKind.Spread; + result.type = getUnionType([getTypeOfSymbol(leftProp), getTypeOfSymbol(rightProp)]); result.leftSpread = leftProp; result.rightSpread = rightProp; result.declarations = declarations; @@ -19220,23 +19208,21 @@ namespace ts { function getRootSymbols(symbol: Symbol): Symbol[] { if (symbol.flags & SymbolFlags.SyntheticProperty) { - if (symbol.syntheticKind === SyntheticSymbolKind.Spread) { - const links = getSymbolLinks(symbol); - return [links.leftSpread, links.rightSpread]; - } - else { - const symbols: Symbol[] = []; - const name = symbol.name; - forEach(getSymbolLinks(symbol).containingType.types, t => { - const symbol = getPropertyOfType(t, name); - if (symbol) { - symbols.push(symbol); - } - }); - return symbols; - } + const symbols: Symbol[] = []; + const name = symbol.name; + forEach(getSymbolLinks(symbol).containingType.types, t => { + const symbol = getPropertyOfType(t, name); + if (symbol) { + symbols.push(symbol); + } + }); + return symbols; } else if (symbol.flags & SymbolFlags.Transient) { + if ((symbol as SymbolLinks).leftSpread) { + const links = symbol as SymbolLinks; + return [links.leftSpread, links.rightSpread]; + } let target: Symbol; let next = symbol; while (next = getSymbolLinks(next).target) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index dcff28d6a48..61bbff691bc 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2590,7 +2590,6 @@ namespace ts { /* @internal */ isReferenced?: boolean; // True if the symbol is referenced elsewhere /* @internal */ isReplaceableByMethod?: boolean; // Can this Javascript class property be replaced by a method symbol? /* @internal */ isAssigned?: boolean; // True if the symbol is a parameter with assignments - /* @internal */ syntheticKind?: SyntheticSymbolKind; // Synthetic symbols are either spread or union/intersection } /* @internal */ diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index b668fe6eb15..53a4ad33f34 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -4311,6 +4311,7 @@ namespace ts { namespace ts { export function getDefaultLibFileName(options: CompilerOptions): string { switch (options.target) { + case ScriptTarget.ESNext: case ScriptTarget.ES2017: return "lib.es2017.d.ts"; case ScriptTarget.ES2016: