@@ -306,6 +306,7 @@ namespace ts {
306
306
307
307
const emptySymbols = createSymbolTable();
308
308
const identityMapper: (type: Type) => Type = identity;
309
+ const arrayVariances = [VarianceFlags.Covariant];
309
310
310
311
const compilerOptions = host.getCompilerOptions();
311
312
const languageVersion = getEmitScriptTarget(compilerOptions);
@@ -570,9 +571,12 @@ namespace ts {
570
571
isArrayLikeType,
571
572
isTypeInvalidDueToUnionDiscriminant,
572
573
getAllPossiblePropertiesOfTypes,
573
- getSuggestionForNonexistentProperty: (node, type) => getSuggestionForNonexistentProperty(node, type),
574
+ getSuggestedSymbolForNonexistentProperty,
575
+ getSuggestionForNonexistentProperty,
576
+ getSuggestedSymbolForNonexistentSymbol: (location, name, meaning) => getSuggestedSymbolForNonexistentSymbol(location, escapeLeadingUnderscores(name), meaning),
574
577
getSuggestionForNonexistentSymbol: (location, name, meaning) => getSuggestionForNonexistentSymbol(location, escapeLeadingUnderscores(name), meaning),
575
- getSuggestionForNonexistentExport: (node, target) => getSuggestionForNonexistentExport(node, target),
578
+ getSuggestedSymbolForNonexistentModule,
579
+ getSuggestionForNonexistentExport,
576
580
getBaseConstraintOfType,
577
581
getDefaultFromTypeParameter: type => type && type.flags & TypeFlags.TypeParameter ? getDefaultFromTypeParameter(type as TypeParameter) : undefined,
578
582
resolveName(name, location, meaning, excludeGlobals) {
@@ -2372,7 +2376,7 @@ namespace ts {
2372
2376
}
2373
2377
}
2374
2378
else {
2375
- if (moduleSymbol.exports && moduleSymbol.exports .has(InternalSymbolName.Default)) {
2379
+ if (moduleSymbol.exports? .has(InternalSymbolName.Default)) {
2376
2380
error(
2377
2381
name,
2378
2382
Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead,
@@ -2381,7 +2385,7 @@ namespace ts {
2381
2385
);
2382
2386
}
2383
2387
else {
2384
- error (name, Diagnostics.Module_0_has_no_exported_member_1, moduleName, declarationName );
2388
+ reportNonExportedMember (name, declarationName, moduleSymbol, moduleName );
2385
2389
}
2386
2390
}
2387
2391
}
@@ -2390,6 +2394,27 @@ namespace ts {
2390
2394
}
2391
2395
}
2392
2396
2397
+ function reportNonExportedMember(name: Identifier, declarationName: string, moduleSymbol: Symbol, moduleName: string): void {
2398
+ const localSymbol = moduleSymbol.valueDeclaration.locals?.get(name.escapedText);
2399
+ const exports = moduleSymbol.exports;
2400
+
2401
+ if (localSymbol) {
2402
+ const exportedSymbol = exports && !exports.has(InternalSymbolName.ExportEquals)
2403
+ ? find(symbolsToArray(exports), symbol => !!getSymbolIfSameReference(symbol, localSymbol))
2404
+ : undefined;
2405
+ const diagnostic = exportedSymbol
2406
+ ? error(name, Diagnostics.Module_0_declares_1_locally_but_it_is_exported_as_2, moduleName, declarationName, symbolToString(exportedSymbol))
2407
+ : error(name, Diagnostics.Module_0_declares_1_locally_but_it_is_not_exported, moduleName, declarationName);
2408
+
2409
+ addRelatedInfo(diagnostic,
2410
+ createDiagnosticForNode(localSymbol.valueDeclaration, Diagnostics._0_is_declared_here, declarationName)
2411
+ );
2412
+ }
2413
+ else {
2414
+ error(name, Diagnostics.Module_0_has_no_exported_member_1, moduleName, declarationName);
2415
+ }
2416
+ }
2417
+
2393
2418
function getTargetOfImportSpecifier(node: ImportSpecifier, dontResolveAlias: boolean): Symbol | undefined {
2394
2419
checkAliasDeclarationForTypeOnlyMarker(node);
2395
2420
return getExternalModuleMember(node.parent.parent.parent, node, dontResolveAlias);
@@ -15371,6 +15396,9 @@ namespace ts {
15371
15396
source.aliasTypeArguments && source.aliasSymbol === target.aliasSymbol &&
15372
15397
!(source.aliasTypeArgumentsContainsMarker || target.aliasTypeArgumentsContainsMarker)) {
15373
15398
const variances = getAliasVariances(source.aliasSymbol);
15399
+ if (variances === emptyArray) {
15400
+ return Ternary.Maybe;
15401
+ }
15374
15402
const varianceResult = relateVariances(source.aliasTypeArguments, target.aliasTypeArguments, variances, intersectionState);
15375
15403
if (varianceResult !== undefined) {
15376
15404
return varianceResult;
@@ -15567,6 +15595,12 @@ namespace ts {
15567
15595
// type references (which are intended by be compared structurally). Obtain the variance
15568
15596
// information for the type parameters and relate the type arguments accordingly.
15569
15597
const variances = getVariances((<TypeReference>source).target);
15598
+ // We return Ternary.Maybe for a recursive invocation of getVariances (signalled by emptyArray). This
15599
+ // effectively means we measure variance only from type parameter occurrences that aren't nested in
15600
+ // recursive instantiations of the generic type.
15601
+ if (variances === emptyArray) {
15602
+ return Ternary.Maybe;
15603
+ }
15570
15604
const varianceResult = relateVariances(getTypeArguments(<TypeReference>source), getTypeArguments(<TypeReference>target), variances, intersectionState);
15571
15605
if (varianceResult !== undefined) {
15572
15606
return varianceResult;
@@ -16386,8 +16420,7 @@ namespace ts {
16386
16420
// a digest of the type comparisons that occur for each type argument when instantiations of the
16387
16421
// generic type are structurally compared. We infer the variance information by comparing
16388
16422
// instantiations of the generic type for type arguments with known relations. The function
16389
- // returns the emptyArray singleton if we're not in strictFunctionTypes mode or if the function
16390
- // has been invoked recursively for the given generic type.
16423
+ // returns the emptyArray singleton when invoked recursively for the given generic type.
16391
16424
function getVariancesWorker<TCache extends { variances?: VarianceFlags[] }>(typeParameters: readonly TypeParameter[] = emptyArray, cache: TCache, createMarkerType: (input: TCache, param: TypeParameter, marker: Type) => Type): VarianceFlags[] {
16392
16425
let variances = cache.variances;
16393
16426
if (!variances) {
@@ -16430,9 +16463,9 @@ namespace ts {
16430
16463
}
16431
16464
16432
16465
function getVariances(type: GenericType): VarianceFlags[] {
16433
- // Arrays and tuples are known to be covariant, no need to spend time computing this (emptyArray implies covariance for all parameters)
16466
+ // Arrays and tuples are known to be covariant, no need to spend time computing this.
16434
16467
if (type === globalArrayType || type === globalReadonlyArrayType || type.objectFlags & ObjectFlags.Tuple) {
16435
- return emptyArray ;
16468
+ return arrayVariances ;
16436
16469
}
16437
16470
return getVariancesWorker(type.typeParameters, type, getMarkerTypeReference);
16438
16471
}
@@ -26626,13 +26659,18 @@ namespace ts {
26626
26659
if (!(node.flags & NodeFlags.AwaitContext)) {
26627
26660
if (isTopLevelAwait(node)) {
26628
26661
const sourceFile = getSourceFileOfNode(node);
26629
- if ((moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.System) ||
26630
- languageVersion < ScriptTarget.ES2017 ||
26631
- !isEffectiveExternalModule(sourceFile, compilerOptions)) {
26632
- if (!hasParseDiagnostics(sourceFile)) {
26633
- const span = getSpanOfTokenAtPosition(sourceFile, node.pos);
26662
+ if (!hasParseDiagnostics(sourceFile)) {
26663
+ let span: TextSpan | undefined;
26664
+ if (!isEffectiveExternalModule(sourceFile, compilerOptions)) {
26665
+ if (!span) span = getSpanOfTokenAtPosition(sourceFile, node.pos);
26666
+ const diagnostic = createFileDiagnostic(sourceFile, span.start, span.length,
26667
+ Diagnostics.await_expressions_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_this_file_has_no_imports_or_exports_Consider_adding_an_empty_export_to_make_this_file_a_module);
26668
+ diagnostics.add(diagnostic);
26669
+ }
26670
+ if ((moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.System) || languageVersion < ScriptTarget.ES2017) {
26671
+ span = getSpanOfTokenAtPosition(sourceFile, node.pos);
26634
26672
const diagnostic = createFileDiagnostic(sourceFile, span.start, span.length,
26635
- Diagnostics.await_outside_of_an_async_function_is_only_allowed_at_the_top_level_of_a_module_when_module_is_esnext_or_system_and_target_is_es2017_or_higher );
26673
+ Diagnostics.Top_level_await_expressions_are_only_allowed_when_the_module_option_is_set_to_esnext_or_system_and_the_target_option_is_set_to_es2017_or_higher );
26636
26674
diagnostics.add(diagnostic);
26637
26675
}
26638
26676
}
@@ -26642,7 +26680,7 @@ namespace ts {
26642
26680
const sourceFile = getSourceFileOfNode(node);
26643
26681
if (!hasParseDiagnostics(sourceFile)) {
26644
26682
const span = getSpanOfTokenAtPosition(sourceFile, node.pos);
26645
- const diagnostic = createFileDiagnostic(sourceFile, span.start, span.length, Diagnostics.await_expression_is_only_allowed_within_an_async_function );
26683
+ const diagnostic = createFileDiagnostic(sourceFile, span.start, span.length, Diagnostics.await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules );
26646
26684
const func = getContainingFunction(node);
26647
26685
if (func && func.kind !== SyntaxKind.Constructor && (getFunctionFlags(func) & FunctionFlags.Async) === 0) {
26648
26686
const relatedInfo = createDiagnosticForNode(func, Diagnostics.Did_you_mean_to_mark_this_function_as_async);
0 commit comments