Skip to content

Commit 909d519

Browse files
committed
Merge branch 'master' into declaration-emit-performance
2 parents 1360db8 + e5395ef commit 909d519

File tree

75 files changed

+2070
-6620
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+2070
-6620
lines changed

package-lock.json

+20-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/compiler/binder.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2768,8 +2768,8 @@ namespace ts {
27682768

27692769
function bindExportAssignment(node: ExportAssignment) {
27702770
if (!container.symbol || !container.symbol.exports) {
2771-
// Export assignment in some sort of block construct
2772-
bindAnonymousDeclaration(node, SymbolFlags.Alias, getDeclarationName(node)!);
2771+
// Incorrect export assignment in some sort of block construct
2772+
bindAnonymousDeclaration(node, SymbolFlags.Value, getDeclarationName(node)!);
27732773
}
27742774
else {
27752775
const flags = exportAssignmentIsAlias(node)

src/compiler/checker.ts

+23-18
Original file line numberDiff line numberDiff line change
@@ -3935,12 +3935,12 @@ namespace ts {
39353935
return typeCopy;
39363936
}
39373937

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 {
39393939
let result: T;
39403940
for (let location = enclosingDeclaration; location; location = location.parent) {
39413941
// Locals of a source file are not in scope (because they get merged into the global symbol table)
39423942
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)) {
39443944
return result;
39453945
}
39463946
}
@@ -3955,7 +3955,7 @@ namespace ts {
39553955
// `sym` may not have exports if this module declaration is backed by the symbol for a `const` that's being rewritten
39563956
// into a namespace - in such cases, it's best to just let the namespace appear empty (the const members couldn't have referred
39573957
// 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)) {
39593959
return result;
39603960
}
39613961
break;
@@ -3976,14 +3976,14 @@ namespace ts {
39763976
(table || (table = createSymbolTable())).set(key, memberSymbol);
39773977
}
39783978
});
3979-
if (table && (result = callback(table, /*ignoreQualification*/ undefined, location))) {
3979+
if (table && (result = callback(table, /*ignoreQualification*/ undefined, /*isLocalNameLookup*/ false, location))) {
39803980
return result;
39813981
}
39823982
break;
39833983
}
39843984
}
39853985

3986-
return callback(globals);
3986+
return callback(globals, /*ignoreQualification*/ undefined, /*isLocalNameLookup*/ true);
39873987
}
39883988

39893989
function getQualifiedLeftMeaning(rightMeaning: SymbolFlags) {
@@ -3998,7 +3998,7 @@ namespace ts {
39983998
const links = getSymbolLinks(symbol);
39993999
const cache = (links.accessibleChainCache ||= new Map());
40004000
// 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);
40024002
const key = `${useOnlyExternalAliasing ? 0 : 1}|${firstRelevantLocation && getNodeId(firstRelevantLocation)}|${meaning}`;
40034003
if (cache.has(key)) {
40044004
return cache.get(key);
@@ -4016,12 +4016,12 @@ namespace ts {
40164016
/**
40174017
* @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)
40184018
*/
4019-
function getAccessibleSymbolChainFromSymbolTable(symbols: SymbolTable, ignoreQualification?: boolean): Symbol[] | undefined {
4019+
function getAccessibleSymbolChainFromSymbolTable(symbols: SymbolTable, ignoreQualification?: boolean, isLocalNameLookup?: boolean): Symbol[] | undefined {
40204020
if (!pushIfUnique(visitedSymbolTables!, symbols)) {
40214021
return undefined;
40224022
}
40234023

4024-
const result = trySymbolTable(symbols, ignoreQualification);
4024+
const result = trySymbolTable(symbols, ignoreQualification, isLocalNameLookup);
40254025
visitedSymbolTables!.pop();
40264026
return result;
40274027
}
@@ -4042,7 +4042,7 @@ namespace ts {
40424042
(ignoreQualification || canQualifySymbol(getMergedSymbol(symbolFromSymbolTable), meaning));
40434043
}
40444044

4045-
function trySymbolTable(symbols: SymbolTable, ignoreQualification: boolean | undefined): Symbol[] | undefined {
4045+
function trySymbolTable(symbols: SymbolTable, ignoreQualification: boolean | undefined, isLocalNameLookup: boolean | undefined): Symbol[] | undefined {
40464046
// If symbol is directly available by its name in the symbol table
40474047
if (isAccessible(symbols.get(symbol!.escapedName)!, /*resolvedAliasSymbol*/ undefined, ignoreQualification)) {
40484048
return [symbol!];
@@ -4056,6 +4056,8 @@ namespace ts {
40564056
&& !(isUMDExportSymbol(symbolFromSymbolTable) && enclosingDeclaration && isExternalModule(getSourceFileOfNode(enclosingDeclaration)))
40574057
// If `!useOnlyExternalAliasing`, we can use any type of alias to get the name
40584058
&& (!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)
40594061
// While exports are generally considered to be in scope, export-specifier declared symbols are _not_
40604062
// See similar comment in `resolveName` for details
40614063
&& (ignoreQualification || !getDeclarationOfKind(symbolFromSymbolTable, SyntaxKind.ExportSpecifier))
@@ -4170,7 +4172,7 @@ namespace ts {
41704172
return hasAccessibleDeclarations;
41714173
}
41724174
}
4173-
else if (allowModules) {
4175+
if (allowModules) {
41744176
if (some(symbol.declarations, hasNonGlobalAugmentationExternalModuleSymbol)) {
41754177
if (shouldComputeAliasesToMakeVisible) {
41764178
earlyModuleBail = true;
@@ -18012,7 +18014,7 @@ namespace ts {
1801218014
let result = Ternary.True;
1801318015
const sourceTypes = source.types;
1801418016
for (const sourceType of sourceTypes) {
18015-
const related = typeRelatedToSomeType(sourceType, target, /*reportErrors*/ false, IntersectionState.None);
18017+
const related = typeRelatedToSomeType(sourceType, target, /*reportErrors*/ false);
1801618018
if (!related) {
1801718019
return Ternary.False;
1801818020
}
@@ -18021,29 +18023,29 @@ namespace ts {
1802118023
return result;
1802218024
}
1802318025

18024-
function typeRelatedToSomeType(source: Type, target: UnionOrIntersectionType, reportErrors: boolean, intersectionState: IntersectionState): Ternary {
18026+
function typeRelatedToSomeType(source: Type, target: UnionOrIntersectionType, reportErrors: boolean): Ternary {
1802518027
const targetTypes = target.types;
1802618028
if (target.flags & TypeFlags.Union) {
1802718029
if (containsType(targetTypes, source)) {
1802818030
return Ternary.True;
1802918031
}
1803018032
const match = getMatchingUnionConstituentForType(<UnionType>target, source);
1803118033
if (match) {
18032-
const related = isRelatedTo(source, match, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState);
18034+
const related = isRelatedTo(source, match, /*reportErrors*/ false);
1803318035
if (related) {
1803418036
return related;
1803518037
}
1803618038
}
1803718039
}
1803818040
for (const type of targetTypes) {
18039-
const related = isRelatedTo(source, type, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState);
18041+
const related = isRelatedTo(source, type, /*reportErrors*/ false);
1804018042
if (related) {
1804118043
return related;
1804218044
}
1804318045
}
1804418046
if (reportErrors) {
1804518047
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);
1804718049
}
1804818050
return Ternary.False;
1804918051
}
@@ -18303,7 +18305,7 @@ namespace ts {
1830318305
eachTypeRelatedToType(source as UnionType, target, reportErrors && !(source.flags & TypeFlags.Primitive), intersectionState & ~IntersectionState.UnionIntersectionCheck);
1830418306
}
1830518307
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));
1830718309
}
1830818310
if (target.flags & TypeFlags.Intersection) {
1830918311
return typeRelatedToEachType(getRegularTypeOfObjectLiteral(source), target as IntersectionType, reportErrors, IntersectionState.Target);
@@ -22109,7 +22111,7 @@ namespace ts {
2210922111
// The candidate key property name is the name of the first property with a unit type in one of the
2211022112
// constituent types.
2211122113
const keyPropertyName = forEach(types, t =>
22112-
t.flags & (TypeFlags.Object | TypeFlags.Intersection | TypeFlags.InstantiableNonPrimitive) ?
22114+
t.flags & (TypeFlags.Object | TypeFlags.InstantiableNonPrimitive) ?
2211322115
forEach(getPropertiesOfType(t), p => isUnitType(getTypeOfSymbol(p)) ? p.escapedName : undefined) :
2211422116
undefined);
2211522117
const mapByKeyProperty = keyPropertyName && mapTypesByKeyProperty(types, keyPropertyName);
@@ -38396,7 +38398,10 @@ namespace ts {
3839638398
}
3839738399

3839838400
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)) {
3840038405
// If we hit an export assignment in an illegal context, just bail out to avoid cascading errors.
3840138406
return;
3840238407
}

src/compiler/diagnosticMessages.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@
743743
"category": "Error",
744744
"code": 1230
745745
},
746-
"An export assignment can only be used in a module.": {
746+
"An export assignment must be at the top level of a file or module declaration.": {
747747
"category": "Error",
748748
"code": 1231
749749
},
@@ -847,6 +847,10 @@
847847
"category": "Error",
848848
"code": 1257
849849
},
850+
"A default export must be at the top level of a file or module declaration.": {
851+
"category": "Error",
852+
"code": 1258
853+
},
850854
"Module '{0}' can only be default-imported using the '{1}' flag": {
851855
"category": "Error",
852856
"code": 1259

0 commit comments

Comments
 (0)