@@ -3935,12 +3935,12 @@ namespace ts {
3935
3935
return typeCopy;
3936
3936
}
3937
3937
3938
- function forEachSymbolTableInScope<T>(enclosingDeclaration: Node | undefined, callback: (symbolTable: SymbolTable, ignoreQualification?: boolean, scopeNode?: Node) => T): T {
3938
+ function forEachSymbolTableInScope<T>(enclosingDeclaration: Node | undefined, callback: (symbolTable: SymbolTable, ignoreQualification?: boolean, isLocalNameLookup?: boolean, scopeNode?: Node) => 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, /*ignoreQualification*/ undefined, location)) {
3943
+ if (result = callback(location.locals, /*ignoreQualification*/ undefined, /*isLocalNameLookup*/ true, location)) {
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, /*ignoreQualification*/ undefined, location)) {
3958
+ if (result = callback(sym?.exports || emptySymbols, /*ignoreQualification*/ undefined, /*isLocalNameLookup*/ true, location)) {
3959
3959
return result;
3960
3960
}
3961
3961
break;
@@ -3976,14 +3976,14 @@ namespace ts {
3976
3976
(table || (table = createSymbolTable())).set(key, memberSymbol);
3977
3977
}
3978
3978
});
3979
- if (table && (result = callback(table, /*ignoreQualification*/ undefined, location))) {
3979
+ if (table && (result = callback(table, /*ignoreQualification*/ undefined, /*isLocalNameLookup*/ false, location))) {
3980
3980
return result;
3981
3981
}
3982
3982
break;
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) {
@@ -3998,7 +3998,7 @@ namespace ts {
3998
3998
const links = getSymbolLinks(symbol);
3999
3999
const cache = (links.accessibleChainCache ||= new Map());
4000
4000
// Go from enclosingDeclaration to the first scope we check, so the cache is keyed off the scope and thus shared more
4001
- const firstRelevantLocation = forEachSymbolTableInScope(enclosingDeclaration, (_, __, node) => node);
4001
+ const firstRelevantLocation = forEachSymbolTableInScope(enclosingDeclaration, (_, __, ___, node) => node);
4002
4002
const key = `${useOnlyExternalAliasing ? 0 : 1}|${firstRelevantLocation && getNodeId(firstRelevantLocation)}|${meaning}`;
4003
4003
if (cache.has(key)) {
4004
4004
return cache.get(key);
@@ -4016,12 +4016,12 @@ namespace ts {
4016
4016
/**
4017
4017
* @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)
4018
4018
*/
4019
- function getAccessibleSymbolChainFromSymbolTable(symbols: SymbolTable, ignoreQualification?: boolean): Symbol[] | undefined {
4019
+ function getAccessibleSymbolChainFromSymbolTable(symbols: SymbolTable, ignoreQualification?: boolean, isLocalNameLookup?: boolean ): Symbol[] | undefined {
4020
4020
if (!pushIfUnique(visitedSymbolTables!, symbols)) {
4021
4021
return undefined;
4022
4022
}
4023
4023
4024
- const result = trySymbolTable(symbols, ignoreQualification);
4024
+ const result = trySymbolTable(symbols, ignoreQualification, isLocalNameLookup );
4025
4025
visitedSymbolTables!.pop();
4026
4026
return result;
4027
4027
}
@@ -4042,7 +4042,7 @@ namespace ts {
4042
4042
(ignoreQualification || canQualifySymbol(getMergedSymbol(symbolFromSymbolTable), meaning));
4043
4043
}
4044
4044
4045
- function trySymbolTable(symbols: SymbolTable, ignoreQualification: boolean | undefined): Symbol[] | undefined {
4045
+ function trySymbolTable(symbols: SymbolTable, ignoreQualification: boolean | undefined, isLocalNameLookup: boolean | undefined ): Symbol[] | undefined {
4046
4046
// If symbol is directly available by its name in the symbol table
4047
4047
if (isAccessible(symbols.get(symbol!.escapedName)!, /*resolvedAliasSymbol*/ undefined, ignoreQualification)) {
4048
4048
return [symbol!];
@@ -4056,6 +4056,8 @@ namespace ts {
4056
4056
&& !(isUMDExportSymbol(symbolFromSymbolTable) && enclosingDeclaration && isExternalModule(getSourceFileOfNode(enclosingDeclaration)))
4057
4057
// If `!useOnlyExternalAliasing`, we can use any type of alias to get the name
4058
4058
&& (!useOnlyExternalAliasing || some(symbolFromSymbolTable.declarations, isExternalModuleImportEqualsDeclaration))
4059
+ // 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
4060
+ && (isLocalNameLookup ? !some(symbolFromSymbolTable.declarations, isNamespaceReexportDeclaration) : true)
4059
4061
// While exports are generally considered to be in scope, export-specifier declared symbols are _not_
4060
4062
// See similar comment in `resolveName` for details
4061
4063
&& (ignoreQualification || !getDeclarationOfKind(symbolFromSymbolTable, SyntaxKind.ExportSpecifier))
@@ -4170,7 +4172,7 @@ namespace ts {
4170
4172
return hasAccessibleDeclarations;
4171
4173
}
4172
4174
}
4173
- else if (allowModules) {
4175
+ if (allowModules) {
4174
4176
if (some(symbol.declarations, hasNonGlobalAugmentationExternalModuleSymbol)) {
4175
4177
if (shouldComputeAliasesToMakeVisible) {
4176
4178
earlyModuleBail = true;
@@ -18012,7 +18014,7 @@ namespace ts {
18012
18014
let result = Ternary.True;
18013
18015
const sourceTypes = source.types;
18014
18016
for (const sourceType of sourceTypes) {
18015
- const related = typeRelatedToSomeType(sourceType, target, /*reportErrors*/ false, IntersectionState.None );
18017
+ const related = typeRelatedToSomeType(sourceType, target, /*reportErrors*/ false);
18016
18018
if (!related) {
18017
18019
return Ternary.False;
18018
18020
}
@@ -18021,29 +18023,29 @@ namespace ts {
18021
18023
return result;
18022
18024
}
18023
18025
18024
- function typeRelatedToSomeType(source: Type, target: UnionOrIntersectionType, reportErrors: boolean, intersectionState: IntersectionState ): Ternary {
18026
+ function typeRelatedToSomeType(source: Type, target: UnionOrIntersectionType, reportErrors: boolean): Ternary {
18025
18027
const targetTypes = target.types;
18026
18028
if (target.flags & TypeFlags.Union) {
18027
18029
if (containsType(targetTypes, source)) {
18028
18030
return Ternary.True;
18029
18031
}
18030
18032
const match = getMatchingUnionConstituentForType(<UnionType>target, source);
18031
18033
if (match) {
18032
- const related = isRelatedTo(source, match, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState );
18034
+ const related = isRelatedTo(source, match, /*reportErrors*/ false);
18033
18035
if (related) {
18034
18036
return related;
18035
18037
}
18036
18038
}
18037
18039
}
18038
18040
for (const type of targetTypes) {
18039
- const related = isRelatedTo(source, type, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState );
18041
+ const related = isRelatedTo(source, type, /*reportErrors*/ false);
18040
18042
if (related) {
18041
18043
return related;
18042
18044
}
18043
18045
}
18044
18046
if (reportErrors) {
18045
18047
const bestMatchingType = getBestMatchingType(source, target, isRelatedTo);
18046
- isRelatedTo(source, bestMatchingType || targetTypes[targetTypes.length - 1], /*reportErrors*/ true, /*headMessage*/ undefined, intersectionState );
18048
+ isRelatedTo(source, bestMatchingType || targetTypes[targetTypes.length - 1], /*reportErrors*/ true);
18047
18049
}
18048
18050
return Ternary.False;
18049
18051
}
@@ -18303,7 +18305,7 @@ namespace ts {
18303
18305
eachTypeRelatedToType(source as UnionType, target, reportErrors && !(source.flags & TypeFlags.Primitive), intersectionState & ~IntersectionState.UnionIntersectionCheck);
18304
18306
}
18305
18307
if (target.flags & TypeFlags.Union) {
18306
- return typeRelatedToSomeType(getRegularTypeOfObjectLiteral(source), <UnionType>target, reportErrors && !(source.flags & TypeFlags.Primitive) && !(target.flags & TypeFlags.Primitive), intersectionState & ~IntersectionState.UnionIntersectionCheck );
18308
+ return typeRelatedToSomeType(getRegularTypeOfObjectLiteral(source), <UnionType>target, reportErrors && !(source.flags & TypeFlags.Primitive) && !(target.flags & TypeFlags.Primitive));
18307
18309
}
18308
18310
if (target.flags & TypeFlags.Intersection) {
18309
18311
return typeRelatedToEachType(getRegularTypeOfObjectLiteral(source), target as IntersectionType, reportErrors, IntersectionState.Target);
@@ -22109,7 +22111,7 @@ namespace ts {
22109
22111
// The candidate key property name is the name of the first property with a unit type in one of the
22110
22112
// constituent types.
22111
22113
const keyPropertyName = forEach(types, t =>
22112
- t.flags & (TypeFlags.Object | TypeFlags.Intersection | TypeFlags. InstantiableNonPrimitive) ?
22114
+ t.flags & (TypeFlags.Object | TypeFlags.InstantiableNonPrimitive) ?
22113
22115
forEach(getPropertiesOfType(t), p => isUnitType(getTypeOfSymbol(p)) ? p.escapedName : undefined) :
22114
22116
undefined);
22115
22117
const mapByKeyProperty = keyPropertyName && mapTypesByKeyProperty(types, keyPropertyName);
@@ -38396,7 +38398,10 @@ namespace ts {
38396
38398
}
38397
38399
38398
38400
function checkExportAssignment(node: ExportAssignment) {
38399
- if (checkGrammarModuleElementContext(node, Diagnostics.An_export_assignment_can_only_be_used_in_a_module)) {
38401
+ const illegalContextMessage = node.isExportEquals
38402
+ ? Diagnostics.An_export_assignment_must_be_at_the_top_level_of_a_file_or_module_declaration
38403
+ : Diagnostics.A_default_export_must_be_at_the_top_level_of_a_file_or_module_declaration;
38404
+ if (checkGrammarModuleElementContext(node, illegalContextMessage)) {
38400
38405
// If we hit an export assignment in an illegal context, just bail out to avoid cascading errors.
38401
38406
return;
38402
38407
}
0 commit comments