Skip to content

Commit be5f50f

Browse files
committed
Merge branch master into type-only-2
2 parents 8b4c235 + 38eccba commit be5f50f

File tree

184 files changed

+4959
-1506
lines changed

Some content is hidden

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

184 files changed

+4959
-1506
lines changed

lib/cancellationToken.js

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

lib/ja/diagnosticMessages.generated.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@
454454
"Generic_type_0_requires_1_type_argument_s_2314": "ジェネリック型 '{0}' には {1} 個の型引数が必要です。",
455455
"Generic_type_0_requires_between_1_and_2_type_arguments_2707": "ジェネリック型 '{0}' には、{1} 個から {2} 個までの型引数が必要です。",
456456
"Generic_type_instantiation_is_excessively_deep_and_possibly_infinite_2550": "ジェネリック型のインスタンス化は非常に深く、無限である可能性があります。",
457-
"Getter_and_setter_accessors_do_not_agree_in_visibility_2379": "ゲッターおよびセッターで表示が許可されていません",
457+
"Getter_and_setter_accessors_do_not_agree_in_visibility_2379": "ゲッターおよびセッターでの表示が許可されていません",
458458
"Global_module_exports_may_only_appear_at_top_level_1316": "グローバル モジュールのエクスポートは最上位レベルにのみ出現可能です。",
459459
"Global_module_exports_may_only_appear_in_declaration_files_1315": "グローバル モジュールのエクスポートは宣言ファイルにのみ出現可能です。",
460460
"Global_module_exports_may_only_appear_in_module_files_1314": "グローバル モジュールのエクスポートはモジュール ファイルにのみ出現可能です。",

lib/lib.esnext.bigint.d.ts

+325-325
Large diffs are not rendered by default.

lib/tsc.js

+80-52
Large diffs are not rendered by default.

lib/tsserver.js

+343-149
Large diffs are not rendered by default.

lib/tsserverlibrary.js

+343-149
Large diffs are not rendered by default.

lib/typescript.js

+334-134
Large diffs are not rendered by default.

lib/typescriptServices.js

+334-134
Large diffs are not rendered by default.

lib/typingsInstaller.js

+93-63
Large diffs are not rendered by default.

lib/zh-tw/diagnosticMessages.generated.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@
454454
"Generic_type_0_requires_1_type_argument_s_2314": "泛型類型 '{0}' 需要 {1} 個型別引數。",
455455
"Generic_type_0_requires_between_1_and_2_type_arguments_2707": "泛型型別 '{0}' 需要介於 {1} 和 {2} 之間的型別引數。",
456456
"Generic_type_instantiation_is_excessively_deep_and_possibly_infinite_2550": "泛型類型具現化的深度過深,而且可能是無限深。",
457-
"Getter_and_setter_accessors_do_not_agree_in_visibility_2379": "getter 和 setter 存取子的可視性不符",
457+
"Getter_and_setter_accessors_do_not_agree_in_visibility_2379": "getter 和 setter 存取子的可見度不符",
458458
"Global_module_exports_may_only_appear_at_top_level_1316": "全域模組匯出只能顯示在最上層。",
459459
"Global_module_exports_may_only_appear_in_declaration_files_1315": "全域模組匯出只能顯示在宣告檔案中。",
460460
"Global_module_exports_may_only_appear_in_module_files_1314": "全域模組匯出只能顯示在模組檔案中。",

src/cancellationToken/cancellationToken.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ interface ServerCancellationToken {
99
}
1010

1111
function pipeExists(name: string): boolean {
12-
try {
13-
fs.statSync(name);
14-
return true;
15-
}
16-
catch (e) {
17-
return false;
18-
}
12+
// Unlike statSync, existsSync doesn't throw an exception if the target doesn't exist.
13+
// A comment in the node code suggests they're stuck with that decision for back compat
14+
// (https://github.com/nodejs/node/blob/9da241b600182a9ff400f6efc24f11a6303c27f7/lib/fs.js#L222).
15+
// Caveat: If a named pipe does exist, the first call to existsSync will return true, as for
16+
// statSync. Subsequent calls will return false, whereas statSync would throw an exception
17+
// indicating that the pipe was busy. The difference is immaterial, since our statSync
18+
// implementation returned false from its catch block.
19+
return fs.existsSync(name);
1920
}
2021

2122
function createCancellationToken(args: string[]): ServerCancellationToken {

src/compiler/binder.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ namespace ts {
861861
case SyntaxKind.ThisKeyword:
862862
case SyntaxKind.PropertyAccessExpression:
863863
case SyntaxKind.ElementAccessExpression:
864-
return isNarrowableReference(expr);
864+
return containsNarrowableReference(expr);
865865
case SyntaxKind.CallExpression:
866866
return hasNarrowableArgument(<CallExpression>expr);
867867
case SyntaxKind.ParenthesizedExpression:
@@ -879,20 +879,23 @@ namespace ts {
879879
function isNarrowableReference(expr: Expression): boolean {
880880
return expr.kind === SyntaxKind.Identifier || expr.kind === SyntaxKind.ThisKeyword || expr.kind === SyntaxKind.SuperKeyword ||
881881
(isPropertyAccessExpression(expr) || isNonNullExpression(expr) || isParenthesizedExpression(expr)) && isNarrowableReference(expr.expression) ||
882-
isElementAccessExpression(expr) && isStringOrNumericLiteralLike(expr.argumentExpression) && isNarrowableReference(expr.expression) ||
883-
isOptionalChain(expr);
882+
isElementAccessExpression(expr) && isStringOrNumericLiteralLike(expr.argumentExpression) && isNarrowableReference(expr.expression);
883+
}
884+
885+
function containsNarrowableReference(expr: Expression): boolean {
886+
return isNarrowableReference(expr) || isOptionalChain(expr) && containsNarrowableReference(expr.expression);
884887
}
885888

886889
function hasNarrowableArgument(expr: CallExpression) {
887890
if (expr.arguments) {
888891
for (const argument of expr.arguments) {
889-
if (isNarrowableReference(argument)) {
892+
if (containsNarrowableReference(argument)) {
890893
return true;
891894
}
892895
}
893896
}
894897
if (expr.expression.kind === SyntaxKind.PropertyAccessExpression &&
895-
isNarrowableReference((<PropertyAccessExpression>expr.expression).expression)) {
898+
containsNarrowableReference((<PropertyAccessExpression>expr.expression).expression)) {
896899
return true;
897900
}
898901
return false;
@@ -909,7 +912,7 @@ namespace ts {
909912
function isNarrowingBinaryExpression(expr: BinaryExpression) {
910913
switch (expr.operatorToken.kind) {
911914
case SyntaxKind.EqualsToken:
912-
return isNarrowableReference(expr.left);
915+
return containsNarrowableReference(expr.left);
913916
case SyntaxKind.EqualsEqualsToken:
914917
case SyntaxKind.ExclamationEqualsToken:
915918
case SyntaxKind.EqualsEqualsEqualsToken:
@@ -938,7 +941,7 @@ namespace ts {
938941
return isNarrowableOperand((<BinaryExpression>expr).right);
939942
}
940943
}
941-
return isNarrowableReference(expr);
944+
return containsNarrowableReference(expr);
942945
}
943946

944947
function createBranchLabel(): FlowLabel {

src/compiler/checker.ts

+53-15
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ namespace ts {
306306

307307
const emptySymbols = createSymbolTable();
308308
const identityMapper: (type: Type) => Type = identity;
309+
const arrayVariances = [VarianceFlags.Covariant];
309310

310311
const compilerOptions = host.getCompilerOptions();
311312
const languageVersion = getEmitScriptTarget(compilerOptions);
@@ -570,9 +571,12 @@ namespace ts {
570571
isArrayLikeType,
571572
isTypeInvalidDueToUnionDiscriminant,
572573
getAllPossiblePropertiesOfTypes,
573-
getSuggestionForNonexistentProperty: (node, type) => getSuggestionForNonexistentProperty(node, type),
574+
getSuggestedSymbolForNonexistentProperty,
575+
getSuggestionForNonexistentProperty,
576+
getSuggestedSymbolForNonexistentSymbol: (location, name, meaning) => getSuggestedSymbolForNonexistentSymbol(location, escapeLeadingUnderscores(name), meaning),
574577
getSuggestionForNonexistentSymbol: (location, name, meaning) => getSuggestionForNonexistentSymbol(location, escapeLeadingUnderscores(name), meaning),
575-
getSuggestionForNonexistentExport: (node, target) => getSuggestionForNonexistentExport(node, target),
578+
getSuggestedSymbolForNonexistentModule,
579+
getSuggestionForNonexistentExport,
576580
getBaseConstraintOfType,
577581
getDefaultFromTypeParameter: type => type && type.flags & TypeFlags.TypeParameter ? getDefaultFromTypeParameter(type as TypeParameter) : undefined,
578582
resolveName(name, location, meaning, excludeGlobals) {
@@ -2372,7 +2376,7 @@ namespace ts {
23722376
}
23732377
}
23742378
else {
2375-
if (moduleSymbol.exports && moduleSymbol.exports.has(InternalSymbolName.Default)) {
2379+
if (moduleSymbol.exports?.has(InternalSymbolName.Default)) {
23762380
error(
23772381
name,
23782382
Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead,
@@ -2381,7 +2385,7 @@ namespace ts {
23812385
);
23822386
}
23832387
else {
2384-
error(name, Diagnostics.Module_0_has_no_exported_member_1, moduleName, declarationName);
2388+
reportNonExportedMember(name, declarationName, moduleSymbol, moduleName);
23852389
}
23862390
}
23872391
}
@@ -2390,6 +2394,27 @@ namespace ts {
23902394
}
23912395
}
23922396

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+
23932418
function getTargetOfImportSpecifier(node: ImportSpecifier, dontResolveAlias: boolean): Symbol | undefined {
23942419
checkAliasDeclarationForTypeOnlyMarker(node);
23952420
return getExternalModuleMember(node.parent.parent.parent, node, dontResolveAlias);
@@ -15371,6 +15396,9 @@ namespace ts {
1537115396
source.aliasTypeArguments && source.aliasSymbol === target.aliasSymbol &&
1537215397
!(source.aliasTypeArgumentsContainsMarker || target.aliasTypeArgumentsContainsMarker)) {
1537315398
const variances = getAliasVariances(source.aliasSymbol);
15399+
if (variances === emptyArray) {
15400+
return Ternary.Maybe;
15401+
}
1537415402
const varianceResult = relateVariances(source.aliasTypeArguments, target.aliasTypeArguments, variances, intersectionState);
1537515403
if (varianceResult !== undefined) {
1537615404
return varianceResult;
@@ -15567,6 +15595,12 @@ namespace ts {
1556715595
// type references (which are intended by be compared structurally). Obtain the variance
1556815596
// information for the type parameters and relate the type arguments accordingly.
1556915597
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+
}
1557015604
const varianceResult = relateVariances(getTypeArguments(<TypeReference>source), getTypeArguments(<TypeReference>target), variances, intersectionState);
1557115605
if (varianceResult !== undefined) {
1557215606
return varianceResult;
@@ -16386,8 +16420,7 @@ namespace ts {
1638616420
// a digest of the type comparisons that occur for each type argument when instantiations of the
1638716421
// generic type are structurally compared. We infer the variance information by comparing
1638816422
// 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.
1639116424
function getVariancesWorker<TCache extends { variances?: VarianceFlags[] }>(typeParameters: readonly TypeParameter[] = emptyArray, cache: TCache, createMarkerType: (input: TCache, param: TypeParameter, marker: Type) => Type): VarianceFlags[] {
1639216425
let variances = cache.variances;
1639316426
if (!variances) {
@@ -16430,9 +16463,9 @@ namespace ts {
1643016463
}
1643116464

1643216465
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.
1643416467
if (type === globalArrayType || type === globalReadonlyArrayType || type.objectFlags & ObjectFlags.Tuple) {
16435-
return emptyArray;
16468+
return arrayVariances;
1643616469
}
1643716470
return getVariancesWorker(type.typeParameters, type, getMarkerTypeReference);
1643816471
}
@@ -26626,13 +26659,18 @@ namespace ts {
2662626659
if (!(node.flags & NodeFlags.AwaitContext)) {
2662726660
if (isTopLevelAwait(node)) {
2662826661
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);
2663426672
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);
2663626674
diagnostics.add(diagnostic);
2663726675
}
2663826676
}
@@ -26642,7 +26680,7 @@ namespace ts {
2664226680
const sourceFile = getSourceFileOfNode(node);
2664326681
if (!hasParseDiagnostics(sourceFile)) {
2664426682
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);
2664626684
const func = getContainingFunction(node);
2664726685
if (func && func.kind !== SyntaxKind.Constructor && (getFunctionFlags(func) & FunctionFlags.Async) === 0) {
2664826686
const relatedInfo = createDiagnosticForNode(func, Diagnostics.Did_you_mean_to_mark_this_function_as_async);

src/compiler/commandLineParser.ts

+7
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ namespace ts {
480480
error: ImportsNotUsedAsValues.Error
481481
}),
482482
affectsEmit: true,
483+
affectsSemanticDiagnostics: true,
483484
category: Diagnostics.Advanced_Options,
484485
description: Diagnostics.Specify_emit_Slashchecking_behavior_for_imports_that_are_only_used_for_types
485486
},
@@ -742,12 +743,15 @@ namespace ts {
742743
{
743744
name: "experimentalDecorators",
744745
type: "boolean",
746+
affectsSemanticDiagnostics: true,
745747
category: Diagnostics.Experimental_Options,
746748
description: Diagnostics.Enables_experimental_support_for_ES7_decorators
747749
},
748750
{
749751
name: "emitDecoratorMetadata",
750752
type: "boolean",
753+
affectsSemanticDiagnostics: true,
754+
affectsEmit: true,
751755
category: Diagnostics.Experimental_Options,
752756
description: Diagnostics.Enables_experimental_support_for_emitting_type_metadata_for_decorators
753757
},
@@ -762,6 +766,7 @@ namespace ts {
762766
{
763767
name: "resolveJsonModule",
764768
type: "boolean",
769+
affectsModuleResolution: true,
765770
category: Diagnostics.Advanced_Options,
766771
description: Diagnostics.Include_modules_imported_with_json_extension
767772
},
@@ -946,6 +951,7 @@ namespace ts {
946951
{
947952
name: "forceConsistentCasingInFileNames",
948953
type: "boolean",
954+
affectsModuleResolution: true,
949955
category: Diagnostics.Advanced_Options,
950956
description: Diagnostics.Disallow_inconsistently_cased_references_to_the_same_file
951957
},
@@ -967,6 +973,7 @@ namespace ts {
967973
name: "useDefineForClassFields",
968974
type: "boolean",
969975
affectsSemanticDiagnostics: true,
976+
affectsEmit: true,
970977
category: Diagnostics.Advanced_Options,
971978
description: Diagnostics.Emit_class_fields_with_Define_instead_of_Set,
972979
},

src/compiler/core.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,11 @@ namespace ts {
12691269
return result;
12701270
}
12711271

1272+
/**
1273+
* Creates a new object by adding the own properties of `second`, then the own properties of `first`.
1274+
*
1275+
* NOTE: This means that if a property exists in both `first` and `second`, the property in `first` will be chosen.
1276+
*/
12721277
export function extend<T1, T2>(first: T1, second: T2): T1 & T2 {
12731278
const result: T1 & T2 = <any>{};
12741279
for (const id in second) {

0 commit comments

Comments
 (0)