Skip to content

Commit 4028fbe

Browse files
committed
Merge branch 'master' into assumeChangesAffectShape
2 parents d52da06 + cfed79b commit 4028fbe

File tree

71 files changed

+2661
-353
lines changed

Some content is hidden

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

71 files changed

+2661
-353
lines changed

package-lock.json

Lines changed: 20 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/compiler/binder.ts

Lines changed: 2 additions & 2 deletions
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

Lines changed: 35 additions & 18 deletions
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) => T): T {
3938+
function forEachSymbolTableInScope<T>(enclosingDeclaration: Node | undefined, callback: (symbolTable: SymbolTable, ignoreQualification?: boolean, isLocalNameLookup?: boolean) => 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)) {
3943+
if (result = callback(location.locals, /*ignoreQualification*/ undefined, /*isLocalNameLookup*/ true)) {
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)) {
3958+
if (result = callback(sym?.exports || emptySymbols, /*ignoreQualification*/ undefined, /*isLocalNameLookup*/ true)) {
39593959
return result;
39603960
}
39613961
break;
@@ -3983,7 +3983,7 @@ namespace ts {
39833983
}
39843984
}
39853985

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

39893989
function getQualifiedLeftMeaning(rightMeaning: SymbolFlags) {
@@ -4006,12 +4006,12 @@ namespace ts {
40064006
/**
40074007
* @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)
40084008
*/
4009-
function getAccessibleSymbolChainFromSymbolTable(symbols: SymbolTable, ignoreQualification?: boolean): Symbol[] | undefined {
4009+
function getAccessibleSymbolChainFromSymbolTable(symbols: SymbolTable, ignoreQualification?: boolean, isLocalNameLookup?: boolean): Symbol[] | undefined {
40104010
if (!pushIfUnique(visitedSymbolTables!, symbols)) {
40114011
return undefined;
40124012
}
40134013

4014-
const result = trySymbolTable(symbols, ignoreQualification);
4014+
const result = trySymbolTable(symbols, ignoreQualification, isLocalNameLookup);
40154015
visitedSymbolTables!.pop();
40164016
return result;
40174017
}
@@ -4032,7 +4032,7 @@ namespace ts {
40324032
(ignoreQualification || canQualifySymbol(getMergedSymbol(symbolFromSymbolTable), meaning));
40334033
}
40344034

4035-
function trySymbolTable(symbols: SymbolTable, ignoreQualification: boolean | undefined): Symbol[] | undefined {
4035+
function trySymbolTable(symbols: SymbolTable, ignoreQualification: boolean | undefined, isLocalNameLookup: boolean | undefined): Symbol[] | undefined {
40364036
// If symbol is directly available by its name in the symbol table
40374037
if (isAccessible(symbols.get(symbol!.escapedName)!, /*resolvedAliasSymbol*/ undefined, ignoreQualification)) {
40384038
return [symbol!];
@@ -4046,6 +4046,8 @@ namespace ts {
40464046
&& !(isUMDExportSymbol(symbolFromSymbolTable) && enclosingDeclaration && isExternalModule(getSourceFileOfNode(enclosingDeclaration)))
40474047
// If `!useOnlyExternalAliasing`, we can use any type of alias to get the name
40484048
&& (!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)
40494051
// While exports are generally considered to be in scope, export-specifier declared symbols are _not_
40504052
// See similar comment in `resolveName` for details
40514053
&& (ignoreQualification || !getDeclarationOfKind(symbolFromSymbolTable, SyntaxKind.ExportSpecifier))
@@ -4160,7 +4162,7 @@ namespace ts {
41604162
return hasAccessibleDeclarations;
41614163
}
41624164
}
4163-
else if (allowModules) {
4165+
if (allowModules) {
41644166
if (some(symbol.declarations, hasNonGlobalAugmentationExternalModuleSymbol)) {
41654167
if (shouldComputeAliasesToMakeVisible) {
41664168
earlyModuleBail = true;
@@ -15022,7 +15024,7 @@ namespace ts {
1502215024
// purposes of resolution. This means such types aren't subject to the instatiation depth limiter.
1502315025
while (true) {
1502415026
const isUnwrapped = isTypicalNondistributiveConditional(root);
15025-
const checkType = instantiateType(unwrapNondistributiveConditionalTuple(root, root.checkType), mapper);
15027+
const checkType = instantiateType(unwrapNondistributiveConditionalTuple(root, getActualTypeVariable(root.checkType)), mapper);
1502615028
const checkTypeInstantiable = isGenericObjectType(checkType) || isGenericIndexType(checkType);
1502715029
const extendsType = instantiateType(unwrapNondistributiveConditionalTuple(root, root.extendsType), mapper);
1502815030
if (checkType === wildcardType || extendsType === wildcardType) {
@@ -17929,7 +17931,7 @@ namespace ts {
1792917931
let result = Ternary.True;
1793017932
const sourceTypes = source.types;
1793117933
for (const sourceType of sourceTypes) {
17932-
const related = typeRelatedToSomeType(sourceType, target, /*reportErrors*/ false, IntersectionState.None);
17934+
const related = typeRelatedToSomeType(sourceType, target, /*reportErrors*/ false);
1793317935
if (!related) {
1793417936
return Ternary.False;
1793517937
}
@@ -17938,29 +17940,29 @@ namespace ts {
1793817940
return result;
1793917941
}
1794017942

17941-
function typeRelatedToSomeType(source: Type, target: UnionOrIntersectionType, reportErrors: boolean, intersectionState: IntersectionState): Ternary {
17943+
function typeRelatedToSomeType(source: Type, target: UnionOrIntersectionType, reportErrors: boolean): Ternary {
1794217944
const targetTypes = target.types;
1794317945
if (target.flags & TypeFlags.Union) {
1794417946
if (containsType(targetTypes, source)) {
1794517947
return Ternary.True;
1794617948
}
1794717949
const match = getMatchingUnionConstituentForType(<UnionType>target, source);
1794817950
if (match) {
17949-
const related = isRelatedTo(source, match, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState);
17951+
const related = isRelatedTo(source, match, /*reportErrors*/ false);
1795017952
if (related) {
1795117953
return related;
1795217954
}
1795317955
}
1795417956
}
1795517957
for (const type of targetTypes) {
17956-
const related = isRelatedTo(source, type, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState);
17958+
const related = isRelatedTo(source, type, /*reportErrors*/ false);
1795717959
if (related) {
1795817960
return related;
1795917961
}
1796017962
}
1796117963
if (reportErrors) {
1796217964
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);
1796417966
}
1796517967
return Ternary.False;
1796617968
}
@@ -18220,7 +18222,7 @@ namespace ts {
1822018222
eachTypeRelatedToType(source as UnionType, target, reportErrors && !(source.flags & TypeFlags.Primitive), intersectionState & ~IntersectionState.UnionIntersectionCheck);
1822118223
}
1822218224
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));
1822418226
}
1822518227
if (target.flags & TypeFlags.Intersection) {
1822618228
return typeRelatedToEachType(getRegularTypeOfObjectLiteral(source), target as IntersectionType, reportErrors, IntersectionState.Target);
@@ -19954,6 +19956,9 @@ namespace ts {
1995419956
// of those literal types. Otherwise, return the leftmost type for which no type to the
1995519957
// right is a supertype.
1995619958
function getSupertypeOrUnion(types: Type[]): Type {
19959+
if (types.length === 1) {
19960+
return types[0];
19961+
}
1995719962
return literalTypesWithSameBaseType(types) ?
1995819963
getUnionType(types) :
1995919964
reduceLeft(types, (s, t) => isTypeSubtypeOf(s, t) ? t : s)!;
@@ -22023,7 +22028,7 @@ namespace ts {
2202322028
// The candidate key property name is the name of the first property with a unit type in one of the
2202422029
// constituent types.
2202522030
const keyPropertyName = forEach(types, t =>
22026-
t.flags & (TypeFlags.Object | TypeFlags.Intersection | TypeFlags.InstantiableNonPrimitive) ?
22031+
t.flags & (TypeFlags.Object | TypeFlags.InstantiableNonPrimitive) ?
2202722032
forEach(getPropertiesOfType(t), p => isUnitType(getTypeOfSymbol(p)) ? p.escapedName : undefined) :
2202822033
undefined);
2202922034
const mapByKeyProperty = keyPropertyName && mapTypesByKeyProperty(types, keyPropertyName);
@@ -23816,7 +23821,16 @@ namespace ts {
2381623821

2381723822
function getNarrowedType(type: Type, candidate: Type, assumeTrue: boolean, isRelated: (source: Type, target: Type) => boolean) {
2381823823
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+
});
2382023834
}
2382123835
// If the current type is a union type, remove all constituents that couldn't be instances of
2382223836
// the candidate type. If one or more constituents remain, return a union of those.
@@ -38301,7 +38315,10 @@ namespace ts {
3830138315
}
3830238316

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

src/compiler/diagnosticMessages.json

Lines changed: 5 additions & 1 deletion
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)