@@ -3935,12 +3935,12 @@ namespace ts {
3935
3935
return typeCopy;
3936
3936
}
3937
3937
3938
- function forEachSymbolTableInScope<T>(enclosingDeclaration: Node | undefined, callback: (symbolTable: SymbolTable) => T): T {
3938
+ function forEachSymbolTableInScope<T>(enclosingDeclaration: Node | undefined, callback: (symbolTable: SymbolTable, ignoreQualification?: boolean, isLocalNameLookup?: boolean ) => T): T {
3939
3939
let result: T;
3940
3940
for (let location = enclosingDeclaration; location; location = location.parent) {
3941
3941
// Locals of a source file are not in scope (because they get merged into the global symbol table)
3942
3942
if (location.locals && !isGlobalSourceFile(location)) {
3943
- if (result = callback(location.locals)) {
3943
+ if (result = callback(location.locals, /*ignoreQualification*/ undefined, /*isLocalNameLookup*/ true )) {
3944
3944
return result;
3945
3945
}
3946
3946
}
@@ -3955,7 +3955,7 @@ namespace ts {
3955
3955
// `sym` may not have exports if this module declaration is backed by the symbol for a `const` that's being rewritten
3956
3956
// into a namespace - in such cases, it's best to just let the namespace appear empty (the const members couldn't have referred
3957
3957
// to one another anyway)
3958
- if (result = callback(sym?.exports || emptySymbols)) {
3958
+ if (result = callback(sym?.exports || emptySymbols, /*ignoreQualification*/ undefined, /*isLocalNameLookup*/ true )) {
3959
3959
return result;
3960
3960
}
3961
3961
break;
@@ -3983,7 +3983,7 @@ namespace ts {
3983
3983
}
3984
3984
}
3985
3985
3986
- return callback(globals);
3986
+ return callback(globals, /*ignoreQualification*/ undefined, /*isLocalNameLookup*/ true );
3987
3987
}
3988
3988
3989
3989
function getQualifiedLeftMeaning(rightMeaning: SymbolFlags) {
@@ -4006,12 +4006,12 @@ namespace ts {
4006
4006
/**
4007
4007
* @param {ignoreQualification} boolean Set when a symbol is being looked for through the exports of another symbol (meaning we have a route to qualify it already)
4008
4008
*/
4009
- function getAccessibleSymbolChainFromSymbolTable(symbols: SymbolTable, ignoreQualification?: boolean): Symbol[] | undefined {
4009
+ function getAccessibleSymbolChainFromSymbolTable(symbols: SymbolTable, ignoreQualification?: boolean, isLocalNameLookup?: boolean ): Symbol[] | undefined {
4010
4010
if (!pushIfUnique(visitedSymbolTables!, symbols)) {
4011
4011
return undefined;
4012
4012
}
4013
4013
4014
- const result = trySymbolTable(symbols, ignoreQualification);
4014
+ const result = trySymbolTable(symbols, ignoreQualification, isLocalNameLookup );
4015
4015
visitedSymbolTables!.pop();
4016
4016
return result;
4017
4017
}
@@ -4032,7 +4032,7 @@ namespace ts {
4032
4032
(ignoreQualification || canQualifySymbol(getMergedSymbol(symbolFromSymbolTable), meaning));
4033
4033
}
4034
4034
4035
- function trySymbolTable(symbols: SymbolTable, ignoreQualification: boolean | undefined): Symbol[] | undefined {
4035
+ function trySymbolTable(symbols: SymbolTable, ignoreQualification: boolean | undefined, isLocalNameLookup: boolean | undefined ): Symbol[] | undefined {
4036
4036
// If symbol is directly available by its name in the symbol table
4037
4037
if (isAccessible(symbols.get(symbol!.escapedName)!, /*resolvedAliasSymbol*/ undefined, ignoreQualification)) {
4038
4038
return [symbol!];
@@ -4046,6 +4046,8 @@ namespace ts {
4046
4046
&& !(isUMDExportSymbol(symbolFromSymbolTable) && enclosingDeclaration && isExternalModule(getSourceFileOfNode(enclosingDeclaration)))
4047
4047
// If `!useOnlyExternalAliasing`, we can use any type of alias to get the name
4048
4048
&& (!useOnlyExternalAliasing || some(symbolFromSymbolTable.declarations, isExternalModuleImportEqualsDeclaration))
4049
+ // If we're looking up a local name to reference directly, omit namespace reexports, otherwise when we're trawling through an export list to make a dotted name, we can keep it
4050
+ && (isLocalNameLookup ? !some(symbolFromSymbolTable.declarations, isNamespaceReexportDeclaration) : true)
4049
4051
// While exports are generally considered to be in scope, export-specifier declared symbols are _not_
4050
4052
// See similar comment in `resolveName` for details
4051
4053
&& (ignoreQualification || !getDeclarationOfKind(symbolFromSymbolTable, SyntaxKind.ExportSpecifier))
@@ -4160,7 +4162,7 @@ namespace ts {
4160
4162
return hasAccessibleDeclarations;
4161
4163
}
4162
4164
}
4163
- else if (allowModules) {
4165
+ if (allowModules) {
4164
4166
if (some(symbol.declarations, hasNonGlobalAugmentationExternalModuleSymbol)) {
4165
4167
if (shouldComputeAliasesToMakeVisible) {
4166
4168
earlyModuleBail = true;
@@ -15022,7 +15024,7 @@ namespace ts {
15022
15024
// purposes of resolution. This means such types aren't subject to the instatiation depth limiter.
15023
15025
while (true) {
15024
15026
const isUnwrapped = isTypicalNondistributiveConditional(root);
15025
- const checkType = instantiateType(unwrapNondistributiveConditionalTuple(root, root.checkType), mapper);
15027
+ const checkType = instantiateType(unwrapNondistributiveConditionalTuple(root, getActualTypeVariable( root.checkType) ), mapper);
15026
15028
const checkTypeInstantiable = isGenericObjectType(checkType) || isGenericIndexType(checkType);
15027
15029
const extendsType = instantiateType(unwrapNondistributiveConditionalTuple(root, root.extendsType), mapper);
15028
15030
if (checkType === wildcardType || extendsType === wildcardType) {
@@ -17929,7 +17931,7 @@ namespace ts {
17929
17931
let result = Ternary.True;
17930
17932
const sourceTypes = source.types;
17931
17933
for (const sourceType of sourceTypes) {
17932
- const related = typeRelatedToSomeType(sourceType, target, /*reportErrors*/ false, IntersectionState.None );
17934
+ const related = typeRelatedToSomeType(sourceType, target, /*reportErrors*/ false);
17933
17935
if (!related) {
17934
17936
return Ternary.False;
17935
17937
}
@@ -17938,29 +17940,29 @@ namespace ts {
17938
17940
return result;
17939
17941
}
17940
17942
17941
- function typeRelatedToSomeType(source: Type, target: UnionOrIntersectionType, reportErrors: boolean, intersectionState: IntersectionState ): Ternary {
17943
+ function typeRelatedToSomeType(source: Type, target: UnionOrIntersectionType, reportErrors: boolean): Ternary {
17942
17944
const targetTypes = target.types;
17943
17945
if (target.flags & TypeFlags.Union) {
17944
17946
if (containsType(targetTypes, source)) {
17945
17947
return Ternary.True;
17946
17948
}
17947
17949
const match = getMatchingUnionConstituentForType(<UnionType>target, source);
17948
17950
if (match) {
17949
- const related = isRelatedTo(source, match, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState );
17951
+ const related = isRelatedTo(source, match, /*reportErrors*/ false);
17950
17952
if (related) {
17951
17953
return related;
17952
17954
}
17953
17955
}
17954
17956
}
17955
17957
for (const type of targetTypes) {
17956
- const related = isRelatedTo(source, type, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState );
17958
+ const related = isRelatedTo(source, type, /*reportErrors*/ false);
17957
17959
if (related) {
17958
17960
return related;
17959
17961
}
17960
17962
}
17961
17963
if (reportErrors) {
17962
17964
const bestMatchingType = getBestMatchingType(source, target, isRelatedTo);
17963
- isRelatedTo(source, bestMatchingType || targetTypes[targetTypes.length - 1], /*reportErrors*/ true, /*headMessage*/ undefined, intersectionState );
17965
+ isRelatedTo(source, bestMatchingType || targetTypes[targetTypes.length - 1], /*reportErrors*/ true);
17964
17966
}
17965
17967
return Ternary.False;
17966
17968
}
@@ -18220,7 +18222,7 @@ namespace ts {
18220
18222
eachTypeRelatedToType(source as UnionType, target, reportErrors && !(source.flags & TypeFlags.Primitive), intersectionState & ~IntersectionState.UnionIntersectionCheck);
18221
18223
}
18222
18224
if (target.flags & TypeFlags.Union) {
18223
- return typeRelatedToSomeType(getRegularTypeOfObjectLiteral(source), <UnionType>target, reportErrors && !(source.flags & TypeFlags.Primitive) && !(target.flags & TypeFlags.Primitive), intersectionState & ~IntersectionState.UnionIntersectionCheck );
18225
+ return typeRelatedToSomeType(getRegularTypeOfObjectLiteral(source), <UnionType>target, reportErrors && !(source.flags & TypeFlags.Primitive) && !(target.flags & TypeFlags.Primitive));
18224
18226
}
18225
18227
if (target.flags & TypeFlags.Intersection) {
18226
18228
return typeRelatedToEachType(getRegularTypeOfObjectLiteral(source), target as IntersectionType, reportErrors, IntersectionState.Target);
@@ -19954,6 +19956,9 @@ namespace ts {
19954
19956
// of those literal types. Otherwise, return the leftmost type for which no type to the
19955
19957
// right is a supertype.
19956
19958
function getSupertypeOrUnion(types: Type[]): Type {
19959
+ if (types.length === 1) {
19960
+ return types[0];
19961
+ }
19957
19962
return literalTypesWithSameBaseType(types) ?
19958
19963
getUnionType(types) :
19959
19964
reduceLeft(types, (s, t) => isTypeSubtypeOf(s, t) ? t : s)!;
@@ -22023,7 +22028,7 @@ namespace ts {
22023
22028
// The candidate key property name is the name of the first property with a unit type in one of the
22024
22029
// constituent types.
22025
22030
const keyPropertyName = forEach(types, t =>
22026
- t.flags & (TypeFlags.Object | TypeFlags.Intersection | TypeFlags. InstantiableNonPrimitive) ?
22031
+ t.flags & (TypeFlags.Object | TypeFlags.InstantiableNonPrimitive) ?
22027
22032
forEach(getPropertiesOfType(t), p => isUnitType(getTypeOfSymbol(p)) ? p.escapedName : undefined) :
22028
22033
undefined);
22029
22034
const mapByKeyProperty = keyPropertyName && mapTypesByKeyProperty(types, keyPropertyName);
@@ -23816,7 +23821,16 @@ namespace ts {
23816
23821
23817
23822
function getNarrowedType(type: Type, candidate: Type, assumeTrue: boolean, isRelated: (source: Type, target: Type) => boolean) {
23818
23823
if (!assumeTrue) {
23819
- return filterType(type, t => !isRelated(t, candidate));
23824
+ return filterType(type, t => {
23825
+ if (!isRelated(t, candidate)) {
23826
+ return true;
23827
+ }
23828
+ const constraint = getBaseConstraintOfType(t);
23829
+ if (constraint && constraint !== t) {
23830
+ return !isRelated(constraint, candidate);
23831
+ }
23832
+ return false;
23833
+ });
23820
23834
}
23821
23835
// If the current type is a union type, remove all constituents that couldn't be instances of
23822
23836
// the candidate type. If one or more constituents remain, return a union of those.
@@ -38301,7 +38315,10 @@ namespace ts {
38301
38315
}
38302
38316
38303
38317
function checkExportAssignment(node: ExportAssignment) {
38304
- if (checkGrammarModuleElementContext(node, Diagnostics.An_export_assignment_can_only_be_used_in_a_module)) {
38318
+ const illegalContextMessage = node.isExportEquals
38319
+ ? Diagnostics.An_export_assignment_must_be_at_the_top_level_of_a_file_or_module_declaration
38320
+ : Diagnostics.A_default_export_must_be_at_the_top_level_of_a_file_or_module_declaration;
38321
+ if (checkGrammarModuleElementContext(node, illegalContextMessage)) {
38305
38322
// If we hit an export assignment in an illegal context, just bail out to avoid cascading errors.
38306
38323
return;
38307
38324
}
0 commit comments