Skip to content

Commit 2662e62

Browse files
committed
Merge branch 'master' of https://github.com/Microsoft/TypeScript into noErrorTruncation-affectsSemanticDiagnostics
2 parents 3f139f6 + da61231 commit 2662e62

File tree

140 files changed

+3964
-1371
lines changed

Some content is hidden

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

140 files changed

+3964
-1371
lines changed

lib/cancellationToken.js

Lines changed: 1 addition & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/ja/diagnosticMessages.generated.json

Lines changed: 1 addition & 1 deletion
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

Lines changed: 325 additions & 325 deletions
Large diffs are not rendered by default.

lib/tsc.js

Lines changed: 80 additions & 52 deletions
Large diffs are not rendered by default.

lib/tsserver.js

Lines changed: 343 additions & 149 deletions
Large diffs are not rendered by default.

lib/tsserverlibrary.js

Lines changed: 343 additions & 149 deletions
Large diffs are not rendered by default.

lib/typescript.js

Lines changed: 334 additions & 134 deletions
Large diffs are not rendered by default.

lib/typescriptServices.js

Lines changed: 334 additions & 134 deletions
Large diffs are not rendered by default.

lib/typingsInstaller.js

Lines changed: 93 additions & 63 deletions
Large diffs are not rendered by default.

lib/zh-tw/diagnosticMessages.generated.json

Lines changed: 1 addition & 1 deletion
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/compiler/checker.ts

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2355,7 +2355,7 @@ namespace ts {
23552355
}
23562356
}
23572357
else {
2358-
if (moduleSymbol.exports && moduleSymbol.exports.has(InternalSymbolName.Default)) {
2358+
if (moduleSymbol.exports?.has(InternalSymbolName.Default)) {
23592359
error(
23602360
name,
23612361
Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead,
@@ -2364,7 +2364,7 @@ namespace ts {
23642364
);
23652365
}
23662366
else {
2367-
error(name, Diagnostics.Module_0_has_no_exported_member_1, moduleName, declarationName);
2367+
reportNonExportedMember(name, declarationName, moduleSymbol, moduleName);
23682368
}
23692369
}
23702370
}
@@ -2373,6 +2373,27 @@ namespace ts {
23732373
}
23742374
}
23752375

2376+
function reportNonExportedMember(name: Identifier, declarationName: string, moduleSymbol: Symbol, moduleName: string): void {
2377+
const localSymbol = moduleSymbol.valueDeclaration.locals?.get(name.escapedText);
2378+
const exports = moduleSymbol.exports;
2379+
2380+
if (localSymbol) {
2381+
const exportedSymbol = exports && !exports.has(InternalSymbolName.ExportEquals)
2382+
? find(symbolsToArray(exports), symbol => !!getSymbolIfSameReference(symbol, localSymbol))
2383+
: undefined;
2384+
const diagnostic = exportedSymbol
2385+
? error(name, Diagnostics.Module_0_declares_1_locally_but_it_is_exported_as_2, moduleName, declarationName, symbolToString(exportedSymbol))
2386+
: error(name, Diagnostics.Module_0_declares_1_locally_but_it_is_not_exported, moduleName, declarationName);
2387+
2388+
addRelatedInfo(diagnostic,
2389+
createDiagnosticForNode(localSymbol.valueDeclaration, Diagnostics._0_is_declared_here, declarationName)
2390+
);
2391+
}
2392+
else {
2393+
error(name, Diagnostics.Module_0_has_no_exported_member_1, moduleName, declarationName);
2394+
}
2395+
}
2396+
23762397
function getTargetOfImportSpecifier(node: ImportSpecifier, dontResolveAlias: boolean): Symbol | undefined {
23772398
const resolved = getExternalModuleMember(node.parent.parent.parent, node, dontResolveAlias);
23782399
if (resolved && node.parent.parent.isTypeOnly) {
@@ -19054,6 +19075,8 @@ namespace ts {
1905419075
return getExplicitTypeOfSymbol(symbol.flags & SymbolFlags.Alias ? resolveAlias(symbol) : symbol, diagnostic);
1905519076
case SyntaxKind.ThisKeyword:
1905619077
return getExplicitThisType(node);
19078+
case SyntaxKind.SuperKeyword:
19079+
return checkSuperExpression(node);
1905719080
case SyntaxKind.PropertyAccessExpression:
1905819081
const type = getTypeOfDottedName((<PropertyAccessExpression>node).expression, diagnostic);
1905919082
const prop = type && getPropertyOfType(type, (<PropertyAccessExpression>node).name.escapedText);
@@ -26665,13 +26688,18 @@ namespace ts {
2666526688
if (!(node.flags & NodeFlags.AwaitContext)) {
2666626689
if (isTopLevelAwait(node)) {
2666726690
const sourceFile = getSourceFileOfNode(node);
26668-
if ((moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.System) ||
26669-
languageVersion < ScriptTarget.ES2017 ||
26670-
!isEffectiveExternalModule(sourceFile, compilerOptions)) {
26671-
if (!hasParseDiagnostics(sourceFile)) {
26672-
const span = getSpanOfTokenAtPosition(sourceFile, node.pos);
26691+
if (!hasParseDiagnostics(sourceFile)) {
26692+
let span: TextSpan | undefined;
26693+
if (!isEffectiveExternalModule(sourceFile, compilerOptions)) {
26694+
if (!span) span = getSpanOfTokenAtPosition(sourceFile, node.pos);
26695+
const diagnostic = createFileDiagnostic(sourceFile, span.start, span.length,
26696+
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);
26697+
diagnostics.add(diagnostic);
26698+
}
26699+
if ((moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.System) || languageVersion < ScriptTarget.ES2017) {
26700+
span = getSpanOfTokenAtPosition(sourceFile, node.pos);
2667326701
const diagnostic = createFileDiagnostic(sourceFile, span.start, span.length,
26674-
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);
26702+
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);
2667526703
diagnostics.add(diagnostic);
2667626704
}
2667726705
}
@@ -26681,7 +26709,7 @@ namespace ts {
2668126709
const sourceFile = getSourceFileOfNode(node);
2668226710
if (!hasParseDiagnostics(sourceFile)) {
2668326711
const span = getSpanOfTokenAtPosition(sourceFile, node.pos);
26684-
const diagnostic = createFileDiagnostic(sourceFile, span.start, span.length, Diagnostics.await_expression_is_only_allowed_within_an_async_function);
26712+
const diagnostic = createFileDiagnostic(sourceFile, span.start, span.length, Diagnostics.await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules);
2668526713
const func = getContainingFunction(node);
2668626714
if (func && func.kind !== SyntaxKind.Constructor && (getFunctionFlags(func) & FunctionFlags.Async) === 0) {
2668726715
const relatedInfo = createDiagnosticForNode(func, Diagnostics.Did_you_mean_to_mark_this_function_as_async);

src/compiler/commandLineParser.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,12 +743,15 @@ namespace ts {
743743
{
744744
name: "experimentalDecorators",
745745
type: "boolean",
746+
affectsSemanticDiagnostics: true,
746747
category: Diagnostics.Experimental_Options,
747748
description: Diagnostics.Enables_experimental_support_for_ES7_decorators
748749
},
749750
{
750751
name: "emitDecoratorMetadata",
751752
type: "boolean",
753+
affectsSemanticDiagnostics: true,
754+
affectsEmit: true,
752755
category: Diagnostics.Experimental_Options,
753756
description: Diagnostics.Enables_experimental_support_for_emitting_type_metadata_for_decorators
754757
},
@@ -763,6 +766,7 @@ namespace ts {
763766
{
764767
name: "resolveJsonModule",
765768
type: "boolean",
769+
affectsModuleResolution: true,
766770
category: Diagnostics.Advanced_Options,
767771
description: Diagnostics.Include_modules_imported_with_json_extension
768772
},
@@ -948,6 +952,7 @@ namespace ts {
948952
{
949953
name: "forceConsistentCasingInFileNames",
950954
type: "boolean",
955+
affectsModuleResolution: true,
951956
category: Diagnostics.Advanced_Options,
952957
description: Diagnostics.Disallow_inconsistently_cased_references_to_the_same_file
953958
},
@@ -969,6 +974,7 @@ namespace ts {
969974
name: "useDefineForClassFields",
970975
type: "boolean",
971976
affectsSemanticDiagnostics: true,
977+
affectsEmit: true,
972978
category: Diagnostics.Advanced_Options,
973979
description: Diagnostics.Emit_class_fields_with_Define_instead_of_Set,
974980
},

src/compiler/core.ts

Lines changed: 5 additions & 0 deletions
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) {

src/compiler/diagnosticMessages.json

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@
863863
"category": "Error",
864864
"code": 1300
865865
},
866-
"'await' expression is only allowed within an async function.": {
866+
"'await' expressions are only allowed within async functions and at the top levels of modules.": {
867867
"category": "Error",
868868
"code": 1308
869869
},
@@ -1055,10 +1055,6 @@
10551055
"category": "Error",
10561056
"code": 1359
10571057
},
1058-
"Did you mean to parenthesize this function type?": {
1059-
"category": "Error",
1060-
"code": 1360
1061-
},
10621058
"Type-only {0} must reference a type, but '{1}' is a value.": {
10631059
"category": "Error",
10641060
"code": 1361
@@ -1085,7 +1081,7 @@
10851081
},
10861082
"Split all invalid type-only imports": {
10871083
"category": "Message",
1088-
"code": 1377
1084+
"code": 1367
10891085
},
10901086
"Specify emit/checking behavior for imports that are only used for types": {
10911087
"category": "Message",
@@ -1115,10 +1111,14 @@
11151111
"category": "Message",
11161112
"code": 1374
11171113
},
1118-
"'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.": {
1114+
"'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.": {
11191115
"category": "Error",
11201116
"code": 1375
11211117
},
1118+
"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.": {
1119+
"category": "Error",
1120+
"code": 1376
1121+
},
11221122
"The types of '{0}' are incompatible between these types.": {
11231123
"category": "Error",
11241124
"code": 2200
@@ -1764,6 +1764,14 @@
17641764
"category": "Error",
17651765
"code": 2458
17661766
},
1767+
"Module '{0}' declares '{1}' locally, but it is not exported.": {
1768+
"category": "Error",
1769+
"code": 2459
1770+
},
1771+
"Module '{0}' declares '{1}' locally, but it is exported as '{2}'.": {
1772+
"category": "Error",
1773+
"code": 2460
1774+
},
17671775
"Type '{0}' is not an array type.": {
17681776
"category": "Error",
17691777
"code": 2461
@@ -4924,7 +4932,7 @@
49244932
"category": "Message",
49254933
"code": 90003
49264934
},
4927-
"Remove declaration for: '{0}'": {
4935+
"Remove unused declaration for: '{0}'": {
49284936
"category": "Message",
49294937
"code": 90004
49304938
},
@@ -5416,6 +5424,18 @@
54165424
"category": "Message",
54175425
"code": 95096
54185426
},
5427+
"Add 'export {}' to make this file into a module": {
5428+
"category": "Message",
5429+
"code": 95097
5430+
},
5431+
"Set the 'target' option in your configuration file to '{0}'": {
5432+
"category": "Message",
5433+
"code": 95098
5434+
},
5435+
"Set the 'module' option in your configuration file to '{0}'": {
5436+
"category": "Message",
5437+
"code": 95099
5438+
},
54195439

54205440
"No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": {
54215441
"category": "Error",
@@ -5429,10 +5449,6 @@
54295449
"category": "Error",
54305450
"code": 18007
54315451
},
5432-
"'#!' can only be used at the start of a file.": {
5433-
"category": "Error",
5434-
"code": 18008
5435-
},
54365452
"Private identifiers cannot be used as parameters": {
54375453
"category": "Error",
54385454
"code": 18009

src/compiler/program.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,14 +571,14 @@ namespace ts {
571571
return false;
572572
}
573573

574-
// If number of files in the program do not match, it is not up-to-date
575-
if (program.getRootFileNames().length !== rootFileNames.length) {
574+
// If root file names don't match
575+
if (!arrayIsEqualTo(program.getRootFileNames(), rootFileNames)) {
576576
return false;
577577
}
578578

579579
let seenResolvedRefs: ResolvedProjectReference[] | undefined;
580580

581-
// If project references dont match
581+
// If project references don't match
582582
if (!arrayIsEqualTo(program.getProjectReferences(), projectReferences, projectReferenceUptoDate)) {
583583
return false;
584584
}

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4278,7 +4278,7 @@ namespace ts {
42784278
}
42794279

42804280
export function isDottedName(node: Expression): boolean {
4281-
return node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.ThisKeyword ||
4281+
return node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.ThisKeyword || node.kind === SyntaxKind.SuperKeyword ||
42824282
node.kind === SyntaxKind.PropertyAccessExpression && isDottedName((<PropertyAccessExpression>node).expression) ||
42834283
node.kind === SyntaxKind.ParenthesizedExpression && isDottedName((<ParenthesizedExpression>node).expression);
42844284
}

src/harness/fourslashImpl.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ namespace FourSlash {
254254
const tsConfig = ts.convertCompilerOptionsFromJson(configJson.config.compilerOptions, baseDirectory, file.fileName);
255255

256256
if (!tsConfig.errors || !tsConfig.errors.length) {
257-
compilationOptions = ts.extend(compilationOptions, tsConfig.options);
257+
compilationOptions = ts.extend(tsConfig.options, compilationOptions);
258258
}
259259
}
260260
configFileName = file.fileName;
@@ -860,10 +860,10 @@ namespace FourSlash {
860860

861861
if (kind !== undefined || kindModifiers !== undefined) {
862862
if (actual.kind !== kind) {
863-
this.raiseError(`Unexpected kind for ${actual.name}: Expected ${kind}, actual ${actual.kind}`);
863+
this.raiseError(`Unexpected kind for ${actual.name}: Expected '${kind}', actual '${actual.kind}'`);
864864
}
865865
if (actual.kindModifiers !== (kindModifiers || "")) {
866-
this.raiseError(`Bad kind modifiers for ${actual.name}: Expected ${kindModifiers || ""}, actual ${actual.kindModifiers}`);
866+
this.raiseError(`Bad kindModifiers for ${actual.name}: Expected ${kindModifiers || ""}, actual ${actual.kindModifiers}`);
867867
}
868868
}
869869

@@ -2574,6 +2574,10 @@ namespace FourSlash {
25742574
if (typeof options.description === "string") {
25752575
assert.equal(action.description, options.description);
25762576
}
2577+
else if (Array.isArray(options.description)) {
2578+
const description = ts.formatStringFromArgs(options.description[0], options.description, 1);
2579+
assert.equal(action.description, description);
2580+
}
25772581
else {
25782582
assert.match(action.description, templateToRegExp(options.description.template));
25792583
}
@@ -2869,7 +2873,7 @@ namespace FourSlash {
28692873

28702874
private verifyNavigationTreeOrBar(json: any, tree: any, name: "Tree" | "Bar", options: { checkSpans?: boolean } | undefined) {
28712875
if (JSON.stringify(tree, replacer) !== JSON.stringify(json)) {
2872-
this.raiseError(`verifyNavigation${name} failed - expected: ${stringify(json)}, got: ${stringify(tree, replacer)}`);
2876+
this.raiseError(`verifyNavigation${name} failed - \n${showTextDiff(stringify(json), stringify(tree, replacer))}`);
28732877
}
28742878

28752879
function replacer(key: string, value: any) {

0 commit comments

Comments
 (0)