mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-24 04:30:53 -06:00
Create spread property types eagerly
This avoids the need for a synthetic symbol and later code called from getTypeOfSymbol.
This commit is contained in:
parent
f03fecbd31
commit
567f5636e3
@ -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 ? (<TypeReference>type).target : type;
|
||||
}
|
||||
@ -4588,7 +4577,6 @@ namespace ts {
|
||||
propTypes.push(type);
|
||||
}
|
||||
const result = <TransientSymbol>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 = <TransientSymbol>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) {
|
||||
|
||||
@ -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 */
|
||||
|
||||
@ -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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user