From 2c7b39aa4467eaeaa28d5650d286ff7e49e3f9f8 Mon Sep 17 00:00:00 2001 From: Alexander T Date: Thu, 5 Jul 2018 11:04:04 +0300 Subject: [PATCH 01/96] Change message for import *-ing an export=. Update baselines --- src/compiler/checker.ts | 3 +- src/compiler/diagnosticMessages.json | 2 +- .../reference/api/tsserverlibrary.d.ts | 2 +- .../es6ExportEqualsInterop.errors.txt | 36 +++++++++---------- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 207d7317078..669938b597d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2269,7 +2269,8 @@ namespace ts { const symbol = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias); if (!dontResolveAlias && symbol) { if (!(symbol.flags & (SymbolFlags.Module | SymbolFlags.Variable))) { - error(referencingLocation, Diagnostics.Module_0_resolves_to_a_non_module_entity_and_cannot_be_imported_using_this_construct, symbolToString(moduleSymbol!)); + error(referencingLocation, Diagnostics.ECMAScript_imports_can_only_reference_an_export_declaration_with_the_esModuleInterop_flag_enabled_and_by_using_default_imports); + return symbol; } if (compilerOptions.esModuleInterop) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 40a4c4d09d4..75e2d35c471 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1744,7 +1744,7 @@ "category": "Error", "code": 2496 }, - "Module '{0}' resolves to a non-module entity and cannot be imported using this construct.": { + "ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports.": { "category": "Error", "code": 2497 }, diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 99452b93d47..a251e4d9361 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -5266,7 +5266,7 @@ declare namespace ts { Using_a_string_in_a_for_of_statement_is_only_supported_in_ECMAScript_5_and_higher: DiagnosticMessage; Type_0_is_not_an_array_type_or_a_string_type: DiagnosticMessage; The_arguments_object_cannot_be_referenced_in_an_arrow_function_in_ES3_and_ES5_Consider_using_a_standard_function_expression: DiagnosticMessage; - Module_0_resolves_to_a_non_module_entity_and_cannot_be_imported_using_this_construct: DiagnosticMessage; + ECMAScript_imports_can_only_reference_an_export_declaration_with_the_esModuleInterop_flag_enabled_and_by_using_default_imports: DiagnosticMessage; Module_0_uses_export_and_cannot_be_used_with_export_Asterisk: DiagnosticMessage; An_interface_can_only_extend_an_identifier_Slashqualified_name_with_optional_type_arguments: DiagnosticMessage; A_class_can_only_implement_an_identifier_Slashqualified_name_with_optional_type_arguments: DiagnosticMessage; diff --git a/tests/baselines/reference/es6ExportEqualsInterop.errors.txt b/tests/baselines/reference/es6ExportEqualsInterop.errors.txt index 4675136d081..2d29884065c 100644 --- a/tests/baselines/reference/es6ExportEqualsInterop.errors.txt +++ b/tests/baselines/reference/es6ExportEqualsInterop.errors.txt @@ -11,24 +11,24 @@ tests/cases/compiler/main.ts(33,8): error TS1192: Module '"function"' has no def tests/cases/compiler/main.ts(34,8): error TS1192: Module '"function-module"' has no default export. tests/cases/compiler/main.ts(35,8): error TS1192: Module '"class"' has no default export. tests/cases/compiler/main.ts(36,8): error TS1192: Module '"class-module"' has no default export. -tests/cases/compiler/main.ts(39,21): error TS2497: Module '"interface"' resolves to a non-module entity and cannot be imported using this construct. -tests/cases/compiler/main.ts(45,21): error TS2497: Module '"function"' resolves to a non-module entity and cannot be imported using this construct. -tests/cases/compiler/main.ts(47,21): error TS2497: Module '"class"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(39,21): error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. +tests/cases/compiler/main.ts(45,21): error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. +tests/cases/compiler/main.ts(47,21): error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. tests/cases/compiler/main.ts(50,1): error TS2693: 'y1' only refers to a type, but is being used as a value here. tests/cases/compiler/main.ts(56,4): error TS2339: Property 'a' does not exist on type '() => any'. tests/cases/compiler/main.ts(58,4): error TS2339: Property 'a' does not exist on type 'typeof Foo'. tests/cases/compiler/main.ts(62,10): error TS2305: Module '"interface"' has no exported member 'a'. -tests/cases/compiler/main.ts(62,25): error TS2497: Module '"interface"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(62,25): error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. tests/cases/compiler/main.ts(68,10): error TS2305: Module '"function"' has no exported member 'a'. -tests/cases/compiler/main.ts(68,25): error TS2497: Module '"function"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(68,25): error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. tests/cases/compiler/main.ts(70,10): error TS2305: Module '"class"' has no exported member 'a'. -tests/cases/compiler/main.ts(70,25): error TS2497: Module '"class"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(70,25): error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. tests/cases/compiler/main.ts(85,10): error TS2305: Module '"interface"' has no exported member 'a'. -tests/cases/compiler/main.ts(85,25): error TS2497: Module '"interface"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(85,25): error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. tests/cases/compiler/main.ts(91,10): error TS2305: Module '"function"' has no exported member 'a'. -tests/cases/compiler/main.ts(91,25): error TS2497: Module '"function"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(91,25): error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. tests/cases/compiler/main.ts(93,10): error TS2305: Module '"class"' has no exported member 'a'. -tests/cases/compiler/main.ts(93,25): error TS2497: Module '"class"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(93,25): error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. tests/cases/compiler/main.ts(97,15): error TS2498: Module '"interface"' uses 'export =' and cannot be used with 'export *'. tests/cases/compiler/main.ts(98,15): error TS2498: Module '"variable"' uses 'export =' and cannot be used with 'export *'. tests/cases/compiler/main.ts(99,15): error TS2498: Module '"interface-variable"' uses 'export =' and cannot be used with 'export *'. @@ -108,7 +108,7 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses // namespace import import * as y1 from "interface"; ~~~~~~~~~~~ -!!! error TS2497: Module '"interface"' resolves to a non-module entity and cannot be imported using this construct. +!!! error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. import * as y2 from "variable"; import * as y3 from "interface-variable"; import * as y4 from "module"; @@ -116,11 +116,11 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses import * as y6 from "variable-module"; import * as y7 from "function"; ~~~~~~~~~~ -!!! error TS2497: Module '"function"' resolves to a non-module entity and cannot be imported using this construct. +!!! error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. import * as y8 from "function-module"; import * as y9 from "class"; ~~~~~~~ -!!! error TS2497: Module '"class"' resolves to a non-module entity and cannot be imported using this construct. +!!! error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. import * as y0 from "class-module"; y1.a; @@ -145,7 +145,7 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses ~ !!! error TS2305: Module '"interface"' has no exported member 'a'. ~~~~~~~~~~~ -!!! error TS2497: Module '"interface"' resolves to a non-module entity and cannot be imported using this construct. +!!! error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. import { a as a2 } from "variable"; import { a as a3 } from "interface-variable"; import { a as a4 } from "module"; @@ -155,13 +155,13 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses ~ !!! error TS2305: Module '"function"' has no exported member 'a'. ~~~~~~~~~~ -!!! error TS2497: Module '"function"' resolves to a non-module entity and cannot be imported using this construct. +!!! error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. import { a as a8 } from "function-module"; import { a as a9 } from "class"; ~ !!! error TS2305: Module '"class"' has no exported member 'a'. ~~~~~~~ -!!! error TS2497: Module '"class"' resolves to a non-module entity and cannot be imported using this construct. +!!! error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. import { a as a0 } from "class-module"; a1; @@ -180,7 +180,7 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses ~ !!! error TS2305: Module '"interface"' has no exported member 'a'. ~~~~~~~~~~~ -!!! error TS2497: Module '"interface"' resolves to a non-module entity and cannot be imported using this construct. +!!! error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. export { a as a2 } from "variable"; export { a as a3 } from "interface-variable"; export { a as a4 } from "module"; @@ -190,13 +190,13 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses ~ !!! error TS2305: Module '"function"' has no exported member 'a'. ~~~~~~~~~~ -!!! error TS2497: Module '"function"' resolves to a non-module entity and cannot be imported using this construct. +!!! error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. export { a as a8 } from "function-module"; export { a as a9 } from "class"; ~ !!! error TS2305: Module '"class"' has no exported member 'a'. ~~~~~~~ -!!! error TS2497: Module '"class"' resolves to a non-module entity and cannot be imported using this construct. +!!! error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. export { a as a0 } from "class-module"; // export-star From 312a5f9951bc1402daa09a81bb00c13a9bae42dd Mon Sep 17 00:00:00 2001 From: Alexander T Date: Wed, 11 Jul 2018 14:55:11 +0300 Subject: [PATCH 02/96] Change message for import *-ing an export= based on module type. Update tests/baselines --- src/compiler/checker.ts | 8 ++++- src/compiler/diagnosticMessages.json | 2 +- .../es6ExportEqualsInterop.errors.txt | 36 +++++++++---------- ...EqualsExportModuleCommonJsError.errors.txt | 15 ++++++++ ...s6ImportEqualsExportModuleCommonJsError.js | 26 ++++++++++++++ ...ortEqualsExportModuleCommonJsError.symbols | 16 +++++++++ ...mportEqualsExportModuleCommonJsError.types | 16 +++++++++ ...rtEqualsExportModuleEs2015Error.errors.txt | 18 ++++++++++ .../es6ImportEqualsExportModuleEs2015Error.js | 22 ++++++++++++ ...mportEqualsExportModuleEs2015Error.symbols | 16 +++++++++ ...6ImportEqualsExportModuleEs2015Error.types | 16 +++++++++ ...s6ImportEqualsExportModuleCommonJsError.ts | 11 ++++++ .../es6ImportEqualsExportModuleEs2015Error.ts | 11 ++++++ 13 files changed, 193 insertions(+), 20 deletions(-) create mode 100644 tests/baselines/reference/es6ImportEqualsExportModuleCommonJsError.errors.txt create mode 100644 tests/baselines/reference/es6ImportEqualsExportModuleCommonJsError.js create mode 100644 tests/baselines/reference/es6ImportEqualsExportModuleCommonJsError.symbols create mode 100644 tests/baselines/reference/es6ImportEqualsExportModuleCommonJsError.types create mode 100644 tests/baselines/reference/es6ImportEqualsExportModuleEs2015Error.errors.txt create mode 100644 tests/baselines/reference/es6ImportEqualsExportModuleEs2015Error.js create mode 100644 tests/baselines/reference/es6ImportEqualsExportModuleEs2015Error.symbols create mode 100644 tests/baselines/reference/es6ImportEqualsExportModuleEs2015Error.types create mode 100644 tests/cases/compiler/es6ImportEqualsExportModuleCommonJsError.ts create mode 100644 tests/cases/compiler/es6ImportEqualsExportModuleEs2015Error.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7561255c25b..02efec7ba13 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2281,9 +2281,15 @@ namespace ts { // combine other declarations with the module or variable (e.g. a class/module, function/module, interface/variable). function resolveESModuleSymbol(moduleSymbol: Symbol | undefined, referencingLocation: Node, dontResolveAlias: boolean): Symbol | undefined { const symbol = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias); + if (!dontResolveAlias && symbol) { if (!(symbol.flags & (SymbolFlags.Module | SymbolFlags.Variable)) && !getDeclarationOfKind(symbol, SyntaxKind.SourceFile)) { - error(referencingLocation, Diagnostics.ECMAScript_imports_can_only_reference_an_export_declaration_with_the_esModuleInterop_flag_enabled_and_by_using_default_imports); + const compilerOptionName = moduleKind >= ModuleKind.ES2015 + ? "allowSyntheticDefaultImports" + : "esModuleInterop"; + + error(referencingLocation, Diagnostics.When_writing_ECMAScript_imports_callable_export_style_modules_can_only_be_imported_by_turning_on_the_0_flag_and_using_a_default_import, compilerOptionName); + return symbol; } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index da818948870..365014ab318 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1744,7 +1744,7 @@ "category": "Error", "code": 2496 }, - "ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports.": { + "When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the '{0}' flag and using a default import.": { "category": "Error", "code": 2497 }, diff --git a/tests/baselines/reference/es6ExportEqualsInterop.errors.txt b/tests/baselines/reference/es6ExportEqualsInterop.errors.txt index 2d29884065c..bebe3f45940 100644 --- a/tests/baselines/reference/es6ExportEqualsInterop.errors.txt +++ b/tests/baselines/reference/es6ExportEqualsInterop.errors.txt @@ -11,24 +11,24 @@ tests/cases/compiler/main.ts(33,8): error TS1192: Module '"function"' has no def tests/cases/compiler/main.ts(34,8): error TS1192: Module '"function-module"' has no default export. tests/cases/compiler/main.ts(35,8): error TS1192: Module '"class"' has no default export. tests/cases/compiler/main.ts(36,8): error TS1192: Module '"class-module"' has no default export. -tests/cases/compiler/main.ts(39,21): error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. -tests/cases/compiler/main.ts(45,21): error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. -tests/cases/compiler/main.ts(47,21): error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. +tests/cases/compiler/main.ts(39,21): error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. +tests/cases/compiler/main.ts(45,21): error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. +tests/cases/compiler/main.ts(47,21): error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. tests/cases/compiler/main.ts(50,1): error TS2693: 'y1' only refers to a type, but is being used as a value here. tests/cases/compiler/main.ts(56,4): error TS2339: Property 'a' does not exist on type '() => any'. tests/cases/compiler/main.ts(58,4): error TS2339: Property 'a' does not exist on type 'typeof Foo'. tests/cases/compiler/main.ts(62,10): error TS2305: Module '"interface"' has no exported member 'a'. -tests/cases/compiler/main.ts(62,25): error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. +tests/cases/compiler/main.ts(62,25): error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. tests/cases/compiler/main.ts(68,10): error TS2305: Module '"function"' has no exported member 'a'. -tests/cases/compiler/main.ts(68,25): error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. +tests/cases/compiler/main.ts(68,25): error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. tests/cases/compiler/main.ts(70,10): error TS2305: Module '"class"' has no exported member 'a'. -tests/cases/compiler/main.ts(70,25): error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. +tests/cases/compiler/main.ts(70,25): error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. tests/cases/compiler/main.ts(85,10): error TS2305: Module '"interface"' has no exported member 'a'. -tests/cases/compiler/main.ts(85,25): error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. +tests/cases/compiler/main.ts(85,25): error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. tests/cases/compiler/main.ts(91,10): error TS2305: Module '"function"' has no exported member 'a'. -tests/cases/compiler/main.ts(91,25): error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. +tests/cases/compiler/main.ts(91,25): error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. tests/cases/compiler/main.ts(93,10): error TS2305: Module '"class"' has no exported member 'a'. -tests/cases/compiler/main.ts(93,25): error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. +tests/cases/compiler/main.ts(93,25): error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. tests/cases/compiler/main.ts(97,15): error TS2498: Module '"interface"' uses 'export =' and cannot be used with 'export *'. tests/cases/compiler/main.ts(98,15): error TS2498: Module '"variable"' uses 'export =' and cannot be used with 'export *'. tests/cases/compiler/main.ts(99,15): error TS2498: Module '"interface-variable"' uses 'export =' and cannot be used with 'export *'. @@ -108,7 +108,7 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses // namespace import import * as y1 from "interface"; ~~~~~~~~~~~ -!!! error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. +!!! error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. import * as y2 from "variable"; import * as y3 from "interface-variable"; import * as y4 from "module"; @@ -116,11 +116,11 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses import * as y6 from "variable-module"; import * as y7 from "function"; ~~~~~~~~~~ -!!! error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. +!!! error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. import * as y8 from "function-module"; import * as y9 from "class"; ~~~~~~~ -!!! error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. +!!! error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. import * as y0 from "class-module"; y1.a; @@ -145,7 +145,7 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses ~ !!! error TS2305: Module '"interface"' has no exported member 'a'. ~~~~~~~~~~~ -!!! error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. +!!! error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. import { a as a2 } from "variable"; import { a as a3 } from "interface-variable"; import { a as a4 } from "module"; @@ -155,13 +155,13 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses ~ !!! error TS2305: Module '"function"' has no exported member 'a'. ~~~~~~~~~~ -!!! error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. +!!! error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. import { a as a8 } from "function-module"; import { a as a9 } from "class"; ~ !!! error TS2305: Module '"class"' has no exported member 'a'. ~~~~~~~ -!!! error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. +!!! error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. import { a as a0 } from "class-module"; a1; @@ -180,7 +180,7 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses ~ !!! error TS2305: Module '"interface"' has no exported member 'a'. ~~~~~~~~~~~ -!!! error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. +!!! error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. export { a as a2 } from "variable"; export { a as a3 } from "interface-variable"; export { a as a4 } from "module"; @@ -190,13 +190,13 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses ~ !!! error TS2305: Module '"function"' has no exported member 'a'. ~~~~~~~~~~ -!!! error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. +!!! error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. export { a as a8 } from "function-module"; export { a as a9 } from "class"; ~ !!! error TS2305: Module '"class"' has no exported member 'a'. ~~~~~~~ -!!! error TS2497: ECMAScript imports can only reference an 'export =' declaration with the 'esModuleInterop' flag enabled and by using default imports. +!!! error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. export { a as a0 } from "class-module"; // export-star diff --git a/tests/baselines/reference/es6ImportEqualsExportModuleCommonJsError.errors.txt b/tests/baselines/reference/es6ImportEqualsExportModuleCommonJsError.errors.txt new file mode 100644 index 00000000000..96d2f55ed27 --- /dev/null +++ b/tests/baselines/reference/es6ImportEqualsExportModuleCommonJsError.errors.txt @@ -0,0 +1,15 @@ +tests/cases/compiler/main.ts(1,20): error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. + + +==== tests/cases/compiler/a.ts (0 errors) ==== + class a { } + export = a; + +==== tests/cases/compiler/main.ts (1 errors) ==== + import * as a from "./a"; + ~~~~~ +!!! error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. + a; + + + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportEqualsExportModuleCommonJsError.js b/tests/baselines/reference/es6ImportEqualsExportModuleCommonJsError.js new file mode 100644 index 00000000000..37f127721ce --- /dev/null +++ b/tests/baselines/reference/es6ImportEqualsExportModuleCommonJsError.js @@ -0,0 +1,26 @@ +//// [tests/cases/compiler/es6ImportEqualsExportModuleCommonJsError.ts] //// + +//// [a.ts] +class a { } +export = a; + +//// [main.ts] +import * as a from "./a"; +a; + + + + +//// [a.js] +"use strict"; +var a = /** @class */ (function () { + function a() { + } + return a; +}()); +module.exports = a; +//// [main.js] +"use strict"; +exports.__esModule = true; +var a = require("./a"); +a; diff --git a/tests/baselines/reference/es6ImportEqualsExportModuleCommonJsError.symbols b/tests/baselines/reference/es6ImportEqualsExportModuleCommonJsError.symbols new file mode 100644 index 00000000000..071f2fb5725 --- /dev/null +++ b/tests/baselines/reference/es6ImportEqualsExportModuleCommonJsError.symbols @@ -0,0 +1,16 @@ +=== tests/cases/compiler/a.ts === +class a { } +>a : Symbol(a, Decl(a.ts, 0, 0)) + +export = a; +>a : Symbol(a, Decl(a.ts, 0, 0)) + +=== tests/cases/compiler/main.ts === +import * as a from "./a"; +>a : Symbol(a, Decl(main.ts, 0, 6)) + +a; +>a : Symbol(a, Decl(main.ts, 0, 6)) + + + diff --git a/tests/baselines/reference/es6ImportEqualsExportModuleCommonJsError.types b/tests/baselines/reference/es6ImportEqualsExportModuleCommonJsError.types new file mode 100644 index 00000000000..652d7d6241b --- /dev/null +++ b/tests/baselines/reference/es6ImportEqualsExportModuleCommonJsError.types @@ -0,0 +1,16 @@ +=== tests/cases/compiler/a.ts === +class a { } +>a : a + +export = a; +>a : a + +=== tests/cases/compiler/main.ts === +import * as a from "./a"; +>a : typeof a + +a; +>a : typeof a + + + diff --git a/tests/baselines/reference/es6ImportEqualsExportModuleEs2015Error.errors.txt b/tests/baselines/reference/es6ImportEqualsExportModuleEs2015Error.errors.txt new file mode 100644 index 00000000000..ee3e9cfff17 --- /dev/null +++ b/tests/baselines/reference/es6ImportEqualsExportModuleEs2015Error.errors.txt @@ -0,0 +1,18 @@ +tests/cases/compiler/a.ts(2,1): error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead. +tests/cases/compiler/main.ts(1,20): error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'allowSyntheticDefaultImports' flag and using a default import. + + +==== tests/cases/compiler/a.ts (1 errors) ==== + class a { } + export = a; + ~~~~~~~~~~~ +!!! error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead. + +==== tests/cases/compiler/main.ts (1 errors) ==== + import * as a from "./a"; + ~~~~~ +!!! error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'allowSyntheticDefaultImports' flag and using a default import. + a; + + + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportEqualsExportModuleEs2015Error.js b/tests/baselines/reference/es6ImportEqualsExportModuleEs2015Error.js new file mode 100644 index 00000000000..603f158946e --- /dev/null +++ b/tests/baselines/reference/es6ImportEqualsExportModuleEs2015Error.js @@ -0,0 +1,22 @@ +//// [tests/cases/compiler/es6ImportEqualsExportModuleEs2015Error.ts] //// + +//// [a.ts] +class a { } +export = a; + +//// [main.ts] +import * as a from "./a"; +a; + + + + +//// [a.js] +var a = /** @class */ (function () { + function a() { + } + return a; +}()); +//// [main.js] +import * as a from "./a"; +a; diff --git a/tests/baselines/reference/es6ImportEqualsExportModuleEs2015Error.symbols b/tests/baselines/reference/es6ImportEqualsExportModuleEs2015Error.symbols new file mode 100644 index 00000000000..071f2fb5725 --- /dev/null +++ b/tests/baselines/reference/es6ImportEqualsExportModuleEs2015Error.symbols @@ -0,0 +1,16 @@ +=== tests/cases/compiler/a.ts === +class a { } +>a : Symbol(a, Decl(a.ts, 0, 0)) + +export = a; +>a : Symbol(a, Decl(a.ts, 0, 0)) + +=== tests/cases/compiler/main.ts === +import * as a from "./a"; +>a : Symbol(a, Decl(main.ts, 0, 6)) + +a; +>a : Symbol(a, Decl(main.ts, 0, 6)) + + + diff --git a/tests/baselines/reference/es6ImportEqualsExportModuleEs2015Error.types b/tests/baselines/reference/es6ImportEqualsExportModuleEs2015Error.types new file mode 100644 index 00000000000..652d7d6241b --- /dev/null +++ b/tests/baselines/reference/es6ImportEqualsExportModuleEs2015Error.types @@ -0,0 +1,16 @@ +=== tests/cases/compiler/a.ts === +class a { } +>a : a + +export = a; +>a : a + +=== tests/cases/compiler/main.ts === +import * as a from "./a"; +>a : typeof a + +a; +>a : typeof a + + + diff --git a/tests/cases/compiler/es6ImportEqualsExportModuleCommonJsError.ts b/tests/cases/compiler/es6ImportEqualsExportModuleCommonJsError.ts new file mode 100644 index 00000000000..577e606c249 --- /dev/null +++ b/tests/cases/compiler/es6ImportEqualsExportModuleCommonJsError.ts @@ -0,0 +1,11 @@ +// @module: commonjs + +// @filename: a.ts +class a { } +export = a; + +// @filename: main.ts +import * as a from "./a"; +a; + + diff --git a/tests/cases/compiler/es6ImportEqualsExportModuleEs2015Error.ts b/tests/cases/compiler/es6ImportEqualsExportModuleEs2015Error.ts new file mode 100644 index 00000000000..a5505b0e90e --- /dev/null +++ b/tests/cases/compiler/es6ImportEqualsExportModuleEs2015Error.ts @@ -0,0 +1,11 @@ +// @module: es2015 + +// @filename: a.ts +class a { } +export = a; + +// @filename: main.ts +import * as a from "./a"; +a; + + From d4f6b9b0a66e27de05debaf4ef4e2d733fe1ccfb Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Fri, 27 Jul 2018 21:08:22 +0200 Subject: [PATCH 03/96] allow BindingPattern in FunctionRestParameter also add downlevel emit for the destructured rest param Part of #6275 --- src/compiler/checker.ts | 4 --- src/compiler/transformers/es2015.ts | 26 ++++++++++++++++--- .../iterableArrayPattern14.errors.txt | 23 ---------------- .../iterableArrayPattern15.errors.txt | 23 ---------------- .../iterableArrayPattern16.errors.txt | 5 +--- .../iterableArrayPattern17.errors.txt | 5 +--- .../iterableArrayPattern20.errors.txt | 23 ---------------- .../iterableArrayPattern25.errors.txt | 5 +--- .../iterableArrayPattern26.errors.txt | 5 +--- .../iterableArrayPattern27.errors.txt | 8 ------ .../iterableArrayPattern28.errors.txt | 5 +--- .../iterableArrayPattern29.errors.txt | 5 +--- ...estParameterWithBindingPattern1.errors.txt | 7 ----- .../restParameterWithBindingPattern1.js | 8 +++++- ...estParameterWithBindingPattern2.errors.txt | 7 ----- .../restParameterWithBindingPattern2.js | 8 +++++- 16 files changed, 42 insertions(+), 125 deletions(-) delete mode 100644 tests/baselines/reference/iterableArrayPattern14.errors.txt delete mode 100644 tests/baselines/reference/iterableArrayPattern15.errors.txt delete mode 100644 tests/baselines/reference/iterableArrayPattern20.errors.txt delete mode 100644 tests/baselines/reference/iterableArrayPattern27.errors.txt delete mode 100644 tests/baselines/reference/restParameterWithBindingPattern1.errors.txt delete mode 100644 tests/baselines/reference/restParameterWithBindingPattern2.errors.txt diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2b255da7ae3..441de3a4253 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -28570,10 +28570,6 @@ namespace ts { checkGrammarForDisallowedTrailingComma(parameters, Diagnostics.A_rest_parameter_or_binding_pattern_may_not_have_a_trailing_comma); } - if (isBindingPattern(parameter.name)) { - return grammarErrorOnNode(parameter.name, Diagnostics.A_rest_element_cannot_contain_a_binding_pattern); - } - if (parameter.questionToken) { return grammarErrorOnNode(parameter.questionToken, Diagnostics.A_rest_parameter_cannot_be_optional); } diff --git a/src/compiler/transformers/es2015.ts b/src/compiler/transformers/es2015.ts index bffdc5809b0..89c87fa82b3 100644 --- a/src/compiler/transformers/es2015.ts +++ b/src/compiler/transformers/es2015.ts @@ -1340,8 +1340,8 @@ namespace ts { * part of a constructor declaration with a * synthesized call to `super` */ - function shouldAddRestParameter(node: ParameterDeclaration | undefined, inConstructorWithSynthesizedSuper: boolean) { - return node && node.dotDotDotToken && node.name.kind === SyntaxKind.Identifier && !inConstructorWithSynthesizedSuper; + function shouldAddRestParameter(node: ParameterDeclaration | undefined, inConstructorWithSynthesizedSuper: boolean): node is ParameterDeclaration { + return !!(node && node.dotDotDotToken && !inConstructorWithSynthesizedSuper); } /** @@ -1360,11 +1360,11 @@ namespace ts { } // `declarationName` is the name of the local declaration for the parameter. - const declarationName = getMutableClone(parameter!.name); + const declarationName = parameter.name.kind === SyntaxKind.Identifier ? getMutableClone(parameter.name) : createTempVariable(/*recordTempVariable*/ undefined); setEmitFlags(declarationName, EmitFlags.NoSourceMap); // `expressionName` is the name of the parameter used in expressions. - const expressionName = getSynthesizedClone(parameter!.name); + const expressionName = parameter.name.kind === SyntaxKind.Identifier ? getSynthesizedClone(parameter.name) : declarationName; const restIndex = node.parameters.length - 1; const temp = createLoopVariable(); @@ -1429,6 +1429,24 @@ namespace ts { setEmitFlags(forStatement, EmitFlags.CustomPrologue); startOnNewLine(forStatement); statements.push(forStatement); + + if (parameter.name.kind !== SyntaxKind.Identifier) { + // do the actual destructuring of the rest parameter if necessary + statements.push( + setEmitFlags( + setTextRange( + createVariableStatement( + /*modifiers*/ undefined, + createVariableDeclarationList( + flattenDestructuringBinding(parameter, visitor, context, FlattenLevel.All, expressionName), + ) + ), + parameter + ), + EmitFlags.CustomPrologue + ) + ); + } } /** diff --git a/tests/baselines/reference/iterableArrayPattern14.errors.txt b/tests/baselines/reference/iterableArrayPattern14.errors.txt deleted file mode 100644 index 664f73e13a0..00000000000 --- a/tests/baselines/reference/iterableArrayPattern14.errors.txt +++ /dev/null @@ -1,23 +0,0 @@ -tests/cases/conformance/es6/destructuring/iterableArrayPattern14.ts(16,17): error TS2501: A rest element cannot contain a binding pattern. - - -==== tests/cases/conformance/es6/destructuring/iterableArrayPattern14.ts (1 errors) ==== - class Bar { x } - class Foo extends Bar { y } - class FooIterator { - next() { - return { - value: new Foo, - done: false - }; - } - - [Symbol.iterator]() { - return this; - } - } - - function fun(...[a, ...b]) { } - ~~~~~~~~~ -!!! error TS2501: A rest element cannot contain a binding pattern. - fun(new FooIterator); \ No newline at end of file diff --git a/tests/baselines/reference/iterableArrayPattern15.errors.txt b/tests/baselines/reference/iterableArrayPattern15.errors.txt deleted file mode 100644 index ce7559de94f..00000000000 --- a/tests/baselines/reference/iterableArrayPattern15.errors.txt +++ /dev/null @@ -1,23 +0,0 @@ -tests/cases/conformance/es6/destructuring/iterableArrayPattern15.ts(16,17): error TS2501: A rest element cannot contain a binding pattern. - - -==== tests/cases/conformance/es6/destructuring/iterableArrayPattern15.ts (1 errors) ==== - class Bar { x } - class Foo extends Bar { y } - class FooIterator { - next() { - return { - value: new Foo, - done: false - }; - } - - [Symbol.iterator]() { - return this; - } - } - - function fun(...[a, b]: Bar[]) { } - ~~~~~~ -!!! error TS2501: A rest element cannot contain a binding pattern. - fun(...new FooIterator); \ No newline at end of file diff --git a/tests/baselines/reference/iterableArrayPattern16.errors.txt b/tests/baselines/reference/iterableArrayPattern16.errors.txt index b07d8c976a5..2de26b3a721 100644 --- a/tests/baselines/reference/iterableArrayPattern16.errors.txt +++ b/tests/baselines/reference/iterableArrayPattern16.errors.txt @@ -1,13 +1,10 @@ -tests/cases/conformance/es6/destructuring/iterableArrayPattern16.ts(1,17): error TS2501: A rest element cannot contain a binding pattern. tests/cases/conformance/es6/destructuring/iterableArrayPattern16.ts(2,5): error TS2345: Argument of type 'FooIterator' is not assignable to parameter of type '[Bar, Bar]'. Property '0' is missing in type 'FooIterator'. tests/cases/conformance/es6/destructuring/iterableArrayPattern16.ts(2,12): error TS2449: Class 'FooIteratorIterator' used before its declaration. -==== tests/cases/conformance/es6/destructuring/iterableArrayPattern16.ts (3 errors) ==== +==== tests/cases/conformance/es6/destructuring/iterableArrayPattern16.ts (2 errors) ==== function fun(...[a, b]: [Bar, Bar][]) { } - ~~~~~~ -!!! error TS2501: A rest element cannot contain a binding pattern. fun(...new FooIteratorIterator); ~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type 'FooIterator' is not assignable to parameter of type '[Bar, Bar]'. diff --git a/tests/baselines/reference/iterableArrayPattern17.errors.txt b/tests/baselines/reference/iterableArrayPattern17.errors.txt index d22d8580c71..09f8b8695a7 100644 --- a/tests/baselines/reference/iterableArrayPattern17.errors.txt +++ b/tests/baselines/reference/iterableArrayPattern17.errors.txt @@ -1,9 +1,8 @@ -tests/cases/conformance/es6/destructuring/iterableArrayPattern17.ts(16,17): error TS2501: A rest element cannot contain a binding pattern. tests/cases/conformance/es6/destructuring/iterableArrayPattern17.ts(17,5): error TS2345: Argument of type 'FooIterator' is not assignable to parameter of type 'Bar'. Property 'x' is missing in type 'FooIterator'. -==== tests/cases/conformance/es6/destructuring/iterableArrayPattern17.ts (2 errors) ==== +==== tests/cases/conformance/es6/destructuring/iterableArrayPattern17.ts (1 errors) ==== class Bar { x } class Foo extends Bar { y } class FooIterator { @@ -20,8 +19,6 @@ tests/cases/conformance/es6/destructuring/iterableArrayPattern17.ts(17,5): error } function fun(...[a, b]: Bar[]) { } - ~~~~~~ -!!! error TS2501: A rest element cannot contain a binding pattern. fun(new FooIterator); ~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type 'FooIterator' is not assignable to parameter of type 'Bar'. diff --git a/tests/baselines/reference/iterableArrayPattern20.errors.txt b/tests/baselines/reference/iterableArrayPattern20.errors.txt deleted file mode 100644 index 23f133238ce..00000000000 --- a/tests/baselines/reference/iterableArrayPattern20.errors.txt +++ /dev/null @@ -1,23 +0,0 @@ -tests/cases/conformance/es6/destructuring/iterableArrayPattern20.ts(16,17): error TS2501: A rest element cannot contain a binding pattern. - - -==== tests/cases/conformance/es6/destructuring/iterableArrayPattern20.ts (1 errors) ==== - class Bar { x } - class Foo extends Bar { y } - class FooArrayIterator { - next() { - return { - value: [new Foo], - done: false - }; - } - - [Symbol.iterator]() { - return this; - } - } - - function fun(...[[a = new Foo], b = [new Foo]]: Bar[][]) { } - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2501: A rest element cannot contain a binding pattern. - fun(...new FooArrayIterator); \ No newline at end of file diff --git a/tests/baselines/reference/iterableArrayPattern25.errors.txt b/tests/baselines/reference/iterableArrayPattern25.errors.txt index 19f2dca07f3..0161be07d4b 100644 --- a/tests/baselines/reference/iterableArrayPattern25.errors.txt +++ b/tests/baselines/reference/iterableArrayPattern25.errors.txt @@ -1,11 +1,8 @@ -tests/cases/conformance/es6/destructuring/iterableArrayPattern25.ts(1,33): error TS2501: A rest element cannot contain a binding pattern. tests/cases/conformance/es6/destructuring/iterableArrayPattern25.ts(2,1): error TS2554: Expected 2 arguments, but got 1. -==== tests/cases/conformance/es6/destructuring/iterableArrayPattern25.ts (2 errors) ==== +==== tests/cases/conformance/es6/destructuring/iterableArrayPattern25.ts (1 errors) ==== function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]) { } - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2501: A rest element cannot contain a binding pattern. takeFirstTwoEntries(new Map([["", 0], ["hello", 1]])); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2554: Expected 2 arguments, but got 1. \ No newline at end of file diff --git a/tests/baselines/reference/iterableArrayPattern26.errors.txt b/tests/baselines/reference/iterableArrayPattern26.errors.txt index a5eff0afb0d..9fb3e688039 100644 --- a/tests/baselines/reference/iterableArrayPattern26.errors.txt +++ b/tests/baselines/reference/iterableArrayPattern26.errors.txt @@ -1,12 +1,9 @@ -tests/cases/conformance/es6/destructuring/iterableArrayPattern26.ts(1,33): error TS2501: A rest element cannot contain a binding pattern. tests/cases/conformance/es6/destructuring/iterableArrayPattern26.ts(2,21): error TS2345: Argument of type 'Map' is not assignable to parameter of type '[string, number]'. Property '0' is missing in type 'Map'. -==== tests/cases/conformance/es6/destructuring/iterableArrayPattern26.ts (2 errors) ==== +==== tests/cases/conformance/es6/destructuring/iterableArrayPattern26.ts (1 errors) ==== function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]: [string, number][]) { } - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2501: A rest element cannot contain a binding pattern. takeFirstTwoEntries(new Map([["", 0], ["hello", 1]])); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type 'Map' is not assignable to parameter of type '[string, number]'. diff --git a/tests/baselines/reference/iterableArrayPattern27.errors.txt b/tests/baselines/reference/iterableArrayPattern27.errors.txt deleted file mode 100644 index 99914ddc508..00000000000 --- a/tests/baselines/reference/iterableArrayPattern27.errors.txt +++ /dev/null @@ -1,8 +0,0 @@ -tests/cases/conformance/es6/destructuring/iterableArrayPattern27.ts(1,33): error TS2501: A rest element cannot contain a binding pattern. - - -==== tests/cases/conformance/es6/destructuring/iterableArrayPattern27.ts (1 errors) ==== - function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]: [string, number][]) { } - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2501: A rest element cannot contain a binding pattern. - takeFirstTwoEntries(...new Map([["", 0], ["hello", 1]])); \ No newline at end of file diff --git a/tests/baselines/reference/iterableArrayPattern28.errors.txt b/tests/baselines/reference/iterableArrayPattern28.errors.txt index 7ca750cd81f..264cb8e7885 100644 --- a/tests/baselines/reference/iterableArrayPattern28.errors.txt +++ b/tests/baselines/reference/iterableArrayPattern28.errors.txt @@ -1,4 +1,3 @@ -tests/cases/conformance/es6/destructuring/iterableArrayPattern28.ts(1,33): error TS2501: A rest element cannot contain a binding pattern. tests/cases/conformance/es6/destructuring/iterableArrayPattern28.ts(2,32): error TS2345: Argument of type '([string, number] | [string, boolean])[]' is not assignable to parameter of type 'ReadonlyArray<[string, number]>'. Types of property 'concat' are incompatible. Type '{ (...items: ConcatArray<[string, number] | [string, boolean]>[]): ([string, number] | [string, boolean])[]; (...items: ([string, number] | [string, boolean] | ConcatArray<[string, number] | [string, boolean]>)[]): ([string, number] | [string, boolean])[]; }' is not assignable to type '{ (...items: ConcatArray<[string, number]>[]): [string, number][]; (...items: ([string, number] | ConcatArray<[string, number]>)[]): [string, number][]; }'. @@ -8,10 +7,8 @@ tests/cases/conformance/es6/destructuring/iterableArrayPattern28.ts(2,32): error Type 'boolean' is not assignable to type 'number'. -==== tests/cases/conformance/es6/destructuring/iterableArrayPattern28.ts (2 errors) ==== +==== tests/cases/conformance/es6/destructuring/iterableArrayPattern28.ts (1 errors) ==== function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]: [string, number][]) { } - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2501: A rest element cannot contain a binding pattern. takeFirstTwoEntries(...new Map([["", 0], ["hello", true]])); ~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '([string, number] | [string, boolean])[]' is not assignable to parameter of type 'ReadonlyArray<[string, number]>'. diff --git a/tests/baselines/reference/iterableArrayPattern29.errors.txt b/tests/baselines/reference/iterableArrayPattern29.errors.txt index 29e5d0d2a3f..a978e357cdf 100644 --- a/tests/baselines/reference/iterableArrayPattern29.errors.txt +++ b/tests/baselines/reference/iterableArrayPattern29.errors.txt @@ -1,12 +1,9 @@ -tests/cases/conformance/es6/destructuring/iterableArrayPattern29.ts(1,33): error TS2501: A rest element cannot contain a binding pattern. tests/cases/conformance/es6/destructuring/iterableArrayPattern29.ts(2,21): error TS2345: Argument of type '[string, boolean]' is not assignable to parameter of type '[string, number]'. Type 'boolean' is not assignable to type 'number'. -==== tests/cases/conformance/es6/destructuring/iterableArrayPattern29.ts (2 errors) ==== +==== tests/cases/conformance/es6/destructuring/iterableArrayPattern29.ts (1 errors) ==== function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]: [string, number][]) { } - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2501: A rest element cannot contain a binding pattern. takeFirstTwoEntries(...new Map([["", true], ["hello", true]])); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '[string, boolean]' is not assignable to parameter of type '[string, number]'. diff --git a/tests/baselines/reference/restParameterWithBindingPattern1.errors.txt b/tests/baselines/reference/restParameterWithBindingPattern1.errors.txt deleted file mode 100644 index 7194159a220..00000000000 --- a/tests/baselines/reference/restParameterWithBindingPattern1.errors.txt +++ /dev/null @@ -1,7 +0,0 @@ -tests/cases/compiler/restParameterWithBindingPattern1.ts(1,15): error TS2501: A rest element cannot contain a binding pattern. - - -==== tests/cases/compiler/restParameterWithBindingPattern1.ts (1 errors) ==== - function a(...{a, b}) { } - ~~~~~~ -!!! error TS2501: A rest element cannot contain a binding pattern. \ No newline at end of file diff --git a/tests/baselines/reference/restParameterWithBindingPattern1.js b/tests/baselines/reference/restParameterWithBindingPattern1.js index 9fb45768afe..eca1a760471 100644 --- a/tests/baselines/reference/restParameterWithBindingPattern1.js +++ b/tests/baselines/reference/restParameterWithBindingPattern1.js @@ -2,4 +2,10 @@ function a(...{a, b}) { } //// [restParameterWithBindingPattern1.js] -function a() { } +function a() { + var _a = []; + for (var _i = 0; _i < arguments.length; _i++) { + _a[_i] = arguments[_i]; + } + var a = _a.a, b = _a.b; +} diff --git a/tests/baselines/reference/restParameterWithBindingPattern2.errors.txt b/tests/baselines/reference/restParameterWithBindingPattern2.errors.txt deleted file mode 100644 index e69e1c2ba78..00000000000 --- a/tests/baselines/reference/restParameterWithBindingPattern2.errors.txt +++ /dev/null @@ -1,7 +0,0 @@ -tests/cases/compiler/restParameterWithBindingPattern2.ts(1,15): error TS2501: A rest element cannot contain a binding pattern. - - -==== tests/cases/compiler/restParameterWithBindingPattern2.ts (1 errors) ==== - function a(...[a, b]) { } - ~~~~~~ -!!! error TS2501: A rest element cannot contain a binding pattern. \ No newline at end of file diff --git a/tests/baselines/reference/restParameterWithBindingPattern2.js b/tests/baselines/reference/restParameterWithBindingPattern2.js index 5c97769acbb..348023d7aa4 100644 --- a/tests/baselines/reference/restParameterWithBindingPattern2.js +++ b/tests/baselines/reference/restParameterWithBindingPattern2.js @@ -2,4 +2,10 @@ function a(...[a, b]) { } //// [restParameterWithBindingPattern2.js] -function a() { } +function a() { + var _a = []; + for (var _i = 0; _i < arguments.length; _i++) { + _a[_i] = arguments[_i]; + } + var a = _a[0], b = _a[1]; +} From 421a5f2698fd3efa7ac2cbd898934d8c2e6d95ac Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Sat, 28 Jul 2018 08:50:08 +0200 Subject: [PATCH 04/96] add additional test for grammar and type checking --- .../restParameterWithBindingPattern3.errors.txt | 10 ++++++++++ .../reference/restParameterWithBindingPattern3.js | 11 +++++++++++ .../restParameterWithBindingPattern3.symbols | 6 ++++++ .../reference/restParameterWithBindingPattern3.types | 8 ++++++++ .../restParameterWithBindingPattern4.errors.txt | 7 +++++++ .../reference/restParameterWithBindingPattern4.js | 11 +++++++++++ .../restParameterWithBindingPattern4.symbols | 5 +++++ .../reference/restParameterWithBindingPattern4.types | 6 ++++++ .../reference/restParameterWithBindingPattern5.js | 11 +++++++++++ .../restParameterWithBindingPattern5.symbols | 7 +++++++ .../reference/restParameterWithBindingPattern5.types | 7 +++++++ .../restParameterWithBindingPattern6.errors.txt | 7 +++++++ .../reference/restParameterWithBindingPattern6.js | 11 +++++++++++ .../restParameterWithBindingPattern6.symbols | 6 ++++++ .../reference/restParameterWithBindingPattern6.types | 8 ++++++++ .../compiler/restParameterWithBindingPattern3.ts | 1 + .../compiler/restParameterWithBindingPattern4.ts | 1 + .../compiler/restParameterWithBindingPattern5.ts | 1 + .../compiler/restParameterWithBindingPattern6.ts | 1 + 19 files changed, 125 insertions(+) create mode 100644 tests/baselines/reference/restParameterWithBindingPattern3.errors.txt create mode 100644 tests/baselines/reference/restParameterWithBindingPattern3.js create mode 100644 tests/baselines/reference/restParameterWithBindingPattern3.symbols create mode 100644 tests/baselines/reference/restParameterWithBindingPattern3.types create mode 100644 tests/baselines/reference/restParameterWithBindingPattern4.errors.txt create mode 100644 tests/baselines/reference/restParameterWithBindingPattern4.js create mode 100644 tests/baselines/reference/restParameterWithBindingPattern4.symbols create mode 100644 tests/baselines/reference/restParameterWithBindingPattern4.types create mode 100644 tests/baselines/reference/restParameterWithBindingPattern5.js create mode 100644 tests/baselines/reference/restParameterWithBindingPattern5.symbols create mode 100644 tests/baselines/reference/restParameterWithBindingPattern5.types create mode 100644 tests/baselines/reference/restParameterWithBindingPattern6.errors.txt create mode 100644 tests/baselines/reference/restParameterWithBindingPattern6.js create mode 100644 tests/baselines/reference/restParameterWithBindingPattern6.symbols create mode 100644 tests/baselines/reference/restParameterWithBindingPattern6.types create mode 100644 tests/cases/compiler/restParameterWithBindingPattern3.ts create mode 100644 tests/cases/compiler/restParameterWithBindingPattern4.ts create mode 100644 tests/cases/compiler/restParameterWithBindingPattern5.ts create mode 100644 tests/cases/compiler/restParameterWithBindingPattern6.ts diff --git a/tests/baselines/reference/restParameterWithBindingPattern3.errors.txt b/tests/baselines/reference/restParameterWithBindingPattern3.errors.txt new file mode 100644 index 00000000000..8b278ed3783 --- /dev/null +++ b/tests/baselines/reference/restParameterWithBindingPattern3.errors.txt @@ -0,0 +1,10 @@ +tests/cases/compiler/restParameterWithBindingPattern3.ts(1,16): error TS2322: Type '1' is not assignable to type 'string'. +tests/cases/compiler/restParameterWithBindingPattern3.ts(1,23): error TS2322: Type 'true' is not assignable to type 'string'. + + +==== tests/cases/compiler/restParameterWithBindingPattern3.ts (2 errors) ==== + function a(...[a = 1, b = true]: string[]) { } + ~ +!!! error TS2322: Type '1' is not assignable to type 'string'. + ~ +!!! error TS2322: Type 'true' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/restParameterWithBindingPattern3.js b/tests/baselines/reference/restParameterWithBindingPattern3.js new file mode 100644 index 00000000000..86bda118119 --- /dev/null +++ b/tests/baselines/reference/restParameterWithBindingPattern3.js @@ -0,0 +1,11 @@ +//// [restParameterWithBindingPattern3.ts] +function a(...[a = 1, b = true]: string[]) { } + +//// [restParameterWithBindingPattern3.js] +function a() { + var _a = []; + for (var _i = 0; _i < arguments.length; _i++) { + _a[_i] = arguments[_i]; + } + var _b = _a[0], a = _b === void 0 ? 1 : _b, _c = _a[1], b = _c === void 0 ? true : _c; +} diff --git a/tests/baselines/reference/restParameterWithBindingPattern3.symbols b/tests/baselines/reference/restParameterWithBindingPattern3.symbols new file mode 100644 index 00000000000..09ffc4d8adc --- /dev/null +++ b/tests/baselines/reference/restParameterWithBindingPattern3.symbols @@ -0,0 +1,6 @@ +=== tests/cases/compiler/restParameterWithBindingPattern3.ts === +function a(...[a = 1, b = true]: string[]) { } +>a : Symbol(a, Decl(restParameterWithBindingPattern3.ts, 0, 0)) +>a : Symbol(a, Decl(restParameterWithBindingPattern3.ts, 0, 15)) +>b : Symbol(b, Decl(restParameterWithBindingPattern3.ts, 0, 21)) + diff --git a/tests/baselines/reference/restParameterWithBindingPattern3.types b/tests/baselines/reference/restParameterWithBindingPattern3.types new file mode 100644 index 00000000000..09b2f9143fe --- /dev/null +++ b/tests/baselines/reference/restParameterWithBindingPattern3.types @@ -0,0 +1,8 @@ +=== tests/cases/compiler/restParameterWithBindingPattern3.ts === +function a(...[a = 1, b = true]: string[]) { } +>a : (...[a, b]: string[]) => void +>a : string +>1 : 1 +>b : string +>true : true + diff --git a/tests/baselines/reference/restParameterWithBindingPattern4.errors.txt b/tests/baselines/reference/restParameterWithBindingPattern4.errors.txt new file mode 100644 index 00000000000..355ab26c6c5 --- /dev/null +++ b/tests/baselines/reference/restParameterWithBindingPattern4.errors.txt @@ -0,0 +1,7 @@ +tests/cases/compiler/restParameterWithBindingPattern4.ts(1,23): error TS1186: A rest element cannot have an initializer. + + +==== tests/cases/compiler/restParameterWithBindingPattern4.ts (1 errors) ==== + function a(...[...foo = []]: string[]) { } + ~ +!!! error TS1186: A rest element cannot have an initializer. \ No newline at end of file diff --git a/tests/baselines/reference/restParameterWithBindingPattern4.js b/tests/baselines/reference/restParameterWithBindingPattern4.js new file mode 100644 index 00000000000..348fa5a02bb --- /dev/null +++ b/tests/baselines/reference/restParameterWithBindingPattern4.js @@ -0,0 +1,11 @@ +//// [restParameterWithBindingPattern4.ts] +function a(...[...foo = []]: string[]) { } + +//// [restParameterWithBindingPattern4.js] +function a() { + var _a = []; + for (var _i = 0; _i < arguments.length; _i++) { + _a[_i] = arguments[_i]; + } + var _b = _a.slice(0), foo = _b === void 0 ? [] : _b; +} diff --git a/tests/baselines/reference/restParameterWithBindingPattern4.symbols b/tests/baselines/reference/restParameterWithBindingPattern4.symbols new file mode 100644 index 00000000000..f281620423e --- /dev/null +++ b/tests/baselines/reference/restParameterWithBindingPattern4.symbols @@ -0,0 +1,5 @@ +=== tests/cases/compiler/restParameterWithBindingPattern4.ts === +function a(...[...foo = []]: string[]) { } +>a : Symbol(a, Decl(restParameterWithBindingPattern4.ts, 0, 0)) +>foo : Symbol(foo, Decl(restParameterWithBindingPattern4.ts, 0, 15)) + diff --git a/tests/baselines/reference/restParameterWithBindingPattern4.types b/tests/baselines/reference/restParameterWithBindingPattern4.types new file mode 100644 index 00000000000..f4af66e9be7 --- /dev/null +++ b/tests/baselines/reference/restParameterWithBindingPattern4.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/restParameterWithBindingPattern4.ts === +function a(...[...foo = []]: string[]) { } +>a : (...[...foo]: string[]) => void +>foo : string[] +>[] : undefined[] + diff --git a/tests/baselines/reference/restParameterWithBindingPattern5.js b/tests/baselines/reference/restParameterWithBindingPattern5.js new file mode 100644 index 00000000000..4bff99068e0 --- /dev/null +++ b/tests/baselines/reference/restParameterWithBindingPattern5.js @@ -0,0 +1,11 @@ +//// [restParameterWithBindingPattern5.ts] +function a(...{0: a, length, 3: d}: [boolean, string, number]) { } + +//// [restParameterWithBindingPattern5.js] +function a() { + var _a = []; + for (var _i = 0; _i < arguments.length; _i++) { + _a[_i] = arguments[_i]; + } + var a = _a[0], length = _a.length, d = _a[3]; +} diff --git a/tests/baselines/reference/restParameterWithBindingPattern5.symbols b/tests/baselines/reference/restParameterWithBindingPattern5.symbols new file mode 100644 index 00000000000..a59b24f64f4 --- /dev/null +++ b/tests/baselines/reference/restParameterWithBindingPattern5.symbols @@ -0,0 +1,7 @@ +=== tests/cases/compiler/restParameterWithBindingPattern5.ts === +function a(...{0: a, length, 3: d}: [boolean, string, number]) { } +>a : Symbol(a, Decl(restParameterWithBindingPattern5.ts, 0, 0)) +>a : Symbol(a, Decl(restParameterWithBindingPattern5.ts, 0, 15)) +>length : Symbol(length, Decl(restParameterWithBindingPattern5.ts, 0, 20)) +>d : Symbol(d, Decl(restParameterWithBindingPattern5.ts, 0, 28)) + diff --git a/tests/baselines/reference/restParameterWithBindingPattern5.types b/tests/baselines/reference/restParameterWithBindingPattern5.types new file mode 100644 index 00000000000..6986660adcd --- /dev/null +++ b/tests/baselines/reference/restParameterWithBindingPattern5.types @@ -0,0 +1,7 @@ +=== tests/cases/compiler/restParameterWithBindingPattern5.ts === +function a(...{0: a, length, 3: d}: [boolean, string, number]) { } +>a : (__0_0: boolean, __0_1: string, __0_2: number) => void +>a : boolean +>length : 3 +>d : string | number | boolean + diff --git a/tests/baselines/reference/restParameterWithBindingPattern6.errors.txt b/tests/baselines/reference/restParameterWithBindingPattern6.errors.txt new file mode 100644 index 00000000000..6f590b2bb67 --- /dev/null +++ b/tests/baselines/reference/restParameterWithBindingPattern6.errors.txt @@ -0,0 +1,7 @@ +tests/cases/compiler/restParameterWithBindingPattern6.ts(1,23): error TS2493: Tuple type '[boolean, string, number]' with length '3' cannot be assigned to tuple with length '4'. + + +==== tests/cases/compiler/restParameterWithBindingPattern6.ts (1 errors) ==== + function a(...[a, , , d]: [boolean, string, number]) { } + ~ +!!! error TS2493: Tuple type '[boolean, string, number]' with length '3' cannot be assigned to tuple with length '4'. \ No newline at end of file diff --git a/tests/baselines/reference/restParameterWithBindingPattern6.js b/tests/baselines/reference/restParameterWithBindingPattern6.js new file mode 100644 index 00000000000..02101d0fcdb --- /dev/null +++ b/tests/baselines/reference/restParameterWithBindingPattern6.js @@ -0,0 +1,11 @@ +//// [restParameterWithBindingPattern6.ts] +function a(...[a, , , d]: [boolean, string, number]) { } + +//// [restParameterWithBindingPattern6.js] +function a() { + var _a = []; + for (var _i = 0; _i < arguments.length; _i++) { + _a[_i] = arguments[_i]; + } + var a = _a[0], d = _a[3]; +} diff --git a/tests/baselines/reference/restParameterWithBindingPattern6.symbols b/tests/baselines/reference/restParameterWithBindingPattern6.symbols new file mode 100644 index 00000000000..2c16d11e33f --- /dev/null +++ b/tests/baselines/reference/restParameterWithBindingPattern6.symbols @@ -0,0 +1,6 @@ +=== tests/cases/compiler/restParameterWithBindingPattern6.ts === +function a(...[a, , , d]: [boolean, string, number]) { } +>a : Symbol(a, Decl(restParameterWithBindingPattern6.ts, 0, 0)) +>a : Symbol(a, Decl(restParameterWithBindingPattern6.ts, 0, 15)) +>d : Symbol(d, Decl(restParameterWithBindingPattern6.ts, 0, 21)) + diff --git a/tests/baselines/reference/restParameterWithBindingPattern6.types b/tests/baselines/reference/restParameterWithBindingPattern6.types new file mode 100644 index 00000000000..f0062077458 --- /dev/null +++ b/tests/baselines/reference/restParameterWithBindingPattern6.types @@ -0,0 +1,8 @@ +=== tests/cases/compiler/restParameterWithBindingPattern6.ts === +function a(...[a, , , d]: [boolean, string, number]) { } +>a : (__0_0: boolean, __0_1: string, __0_2: number) => void +>a : boolean +> : undefined +> : undefined +>d : any + diff --git a/tests/cases/compiler/restParameterWithBindingPattern3.ts b/tests/cases/compiler/restParameterWithBindingPattern3.ts new file mode 100644 index 00000000000..920e00ac2e8 --- /dev/null +++ b/tests/cases/compiler/restParameterWithBindingPattern3.ts @@ -0,0 +1 @@ +function a(...[a = 1, b = true]: string[]) { } \ No newline at end of file diff --git a/tests/cases/compiler/restParameterWithBindingPattern4.ts b/tests/cases/compiler/restParameterWithBindingPattern4.ts new file mode 100644 index 00000000000..fee0067bd50 --- /dev/null +++ b/tests/cases/compiler/restParameterWithBindingPattern4.ts @@ -0,0 +1 @@ +function a(...[...foo = []]: string[]) { } \ No newline at end of file diff --git a/tests/cases/compiler/restParameterWithBindingPattern5.ts b/tests/cases/compiler/restParameterWithBindingPattern5.ts new file mode 100644 index 00000000000..7707a99b11e --- /dev/null +++ b/tests/cases/compiler/restParameterWithBindingPattern5.ts @@ -0,0 +1 @@ +function a(...{0: a, length, 3: d}: [boolean, string, number]) { } \ No newline at end of file diff --git a/tests/cases/compiler/restParameterWithBindingPattern6.ts b/tests/cases/compiler/restParameterWithBindingPattern6.ts new file mode 100644 index 00000000000..ae95ad8c4d9 --- /dev/null +++ b/tests/cases/compiler/restParameterWithBindingPattern6.ts @@ -0,0 +1 @@ +function a(...[a, , , d]: [boolean, string, number]) { } \ No newline at end of file From 3894d0524c918883763a658bd0c11c3b9cc2af36 Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Mon, 30 Jul 2018 16:13:22 +0200 Subject: [PATCH 05/96] merge tests --- ...estParameterWithBindingPattern3.errors.txt | 16 ++++++++-- .../restParameterWithBindingPattern3.js | 29 ++++++++++++++++++- .../restParameterWithBindingPattern3.symbols | 15 ++++++++++ .../restParameterWithBindingPattern3.types | 18 ++++++++++++ ...estParameterWithBindingPattern4.errors.txt | 7 ----- .../restParameterWithBindingPattern4.js | 11 ------- .../restParameterWithBindingPattern4.symbols | 5 ---- .../restParameterWithBindingPattern4.types | 6 ---- .../restParameterWithBindingPattern5.js | 11 ------- .../restParameterWithBindingPattern5.symbols | 7 ----- .../restParameterWithBindingPattern5.types | 7 ----- ...estParameterWithBindingPattern6.errors.txt | 7 ----- .../restParameterWithBindingPattern6.js | 11 ------- .../restParameterWithBindingPattern6.symbols | 6 ---- .../restParameterWithBindingPattern6.types | 8 ----- .../restParameterWithBindingPattern3.ts | 8 ++++- .../restParameterWithBindingPattern4.ts | 1 - .../restParameterWithBindingPattern5.ts | 1 - .../restParameterWithBindingPattern6.ts | 1 - 19 files changed, 82 insertions(+), 93 deletions(-) delete mode 100644 tests/baselines/reference/restParameterWithBindingPattern4.errors.txt delete mode 100644 tests/baselines/reference/restParameterWithBindingPattern4.js delete mode 100644 tests/baselines/reference/restParameterWithBindingPattern4.symbols delete mode 100644 tests/baselines/reference/restParameterWithBindingPattern4.types delete mode 100644 tests/baselines/reference/restParameterWithBindingPattern5.js delete mode 100644 tests/baselines/reference/restParameterWithBindingPattern5.symbols delete mode 100644 tests/baselines/reference/restParameterWithBindingPattern5.types delete mode 100644 tests/baselines/reference/restParameterWithBindingPattern6.errors.txt delete mode 100644 tests/baselines/reference/restParameterWithBindingPattern6.js delete mode 100644 tests/baselines/reference/restParameterWithBindingPattern6.symbols delete mode 100644 tests/baselines/reference/restParameterWithBindingPattern6.types delete mode 100644 tests/cases/compiler/restParameterWithBindingPattern4.ts delete mode 100644 tests/cases/compiler/restParameterWithBindingPattern5.ts delete mode 100644 tests/cases/compiler/restParameterWithBindingPattern6.ts diff --git a/tests/baselines/reference/restParameterWithBindingPattern3.errors.txt b/tests/baselines/reference/restParameterWithBindingPattern3.errors.txt index 8b278ed3783..ea6bda983d8 100644 --- a/tests/baselines/reference/restParameterWithBindingPattern3.errors.txt +++ b/tests/baselines/reference/restParameterWithBindingPattern3.errors.txt @@ -1,10 +1,22 @@ tests/cases/compiler/restParameterWithBindingPattern3.ts(1,16): error TS2322: Type '1' is not assignable to type 'string'. tests/cases/compiler/restParameterWithBindingPattern3.ts(1,23): error TS2322: Type 'true' is not assignable to type 'string'. +tests/cases/compiler/restParameterWithBindingPattern3.ts(3,23): error TS1186: A rest element cannot have an initializer. +tests/cases/compiler/restParameterWithBindingPattern3.ts(7,23): error TS2493: Tuple type '[boolean, string, number]' with length '3' cannot be assigned to tuple with length '4'. -==== tests/cases/compiler/restParameterWithBindingPattern3.ts (2 errors) ==== +==== tests/cases/compiler/restParameterWithBindingPattern3.ts (4 errors) ==== function a(...[a = 1, b = true]: string[]) { } ~ !!! error TS2322: Type '1' is not assignable to type 'string'. ~ -!!! error TS2322: Type 'true' is not assignable to type 'string'. \ No newline at end of file +!!! error TS2322: Type 'true' is not assignable to type 'string'. + + function b(...[...foo = []]: string[]) { } + ~ +!!! error TS1186: A rest element cannot have an initializer. + + function c(...{0: a, length, 3: d}: [boolean, string, number]) { } + + function d(...[a, , , d]: [boolean, string, number]) { } + ~ +!!! error TS2493: Tuple type '[boolean, string, number]' with length '3' cannot be assigned to tuple with length '4'. \ No newline at end of file diff --git a/tests/baselines/reference/restParameterWithBindingPattern3.js b/tests/baselines/reference/restParameterWithBindingPattern3.js index 86bda118119..da3531633b6 100644 --- a/tests/baselines/reference/restParameterWithBindingPattern3.js +++ b/tests/baselines/reference/restParameterWithBindingPattern3.js @@ -1,5 +1,11 @@ //// [restParameterWithBindingPattern3.ts] -function a(...[a = 1, b = true]: string[]) { } +function a(...[a = 1, b = true]: string[]) { } + +function b(...[...foo = []]: string[]) { } + +function c(...{0: a, length, 3: d}: [boolean, string, number]) { } + +function d(...[a, , , d]: [boolean, string, number]) { } //// [restParameterWithBindingPattern3.js] function a() { @@ -9,3 +15,24 @@ function a() { } var _b = _a[0], a = _b === void 0 ? 1 : _b, _c = _a[1], b = _c === void 0 ? true : _c; } +function b() { + var _a = []; + for (var _i = 0; _i < arguments.length; _i++) { + _a[_i] = arguments[_i]; + } + var _b = _a.slice(0), foo = _b === void 0 ? [] : _b; +} +function c() { + var _a = []; + for (var _i = 0; _i < arguments.length; _i++) { + _a[_i] = arguments[_i]; + } + var a = _a[0], length = _a.length, d = _a[3]; +} +function d() { + var _a = []; + for (var _i = 0; _i < arguments.length; _i++) { + _a[_i] = arguments[_i]; + } + var a = _a[0], d = _a[3]; +} diff --git a/tests/baselines/reference/restParameterWithBindingPattern3.symbols b/tests/baselines/reference/restParameterWithBindingPattern3.symbols index 09ffc4d8adc..2694c7327da 100644 --- a/tests/baselines/reference/restParameterWithBindingPattern3.symbols +++ b/tests/baselines/reference/restParameterWithBindingPattern3.symbols @@ -4,3 +4,18 @@ function a(...[a = 1, b = true]: string[]) { } >a : Symbol(a, Decl(restParameterWithBindingPattern3.ts, 0, 15)) >b : Symbol(b, Decl(restParameterWithBindingPattern3.ts, 0, 21)) +function b(...[...foo = []]: string[]) { } +>b : Symbol(b, Decl(restParameterWithBindingPattern3.ts, 0, 46)) +>foo : Symbol(foo, Decl(restParameterWithBindingPattern3.ts, 2, 15)) + +function c(...{0: a, length, 3: d}: [boolean, string, number]) { } +>c : Symbol(c, Decl(restParameterWithBindingPattern3.ts, 2, 42)) +>a : Symbol(a, Decl(restParameterWithBindingPattern3.ts, 4, 15)) +>length : Symbol(length, Decl(restParameterWithBindingPattern3.ts, 4, 20)) +>d : Symbol(d, Decl(restParameterWithBindingPattern3.ts, 4, 28)) + +function d(...[a, , , d]: [boolean, string, number]) { } +>d : Symbol(d, Decl(restParameterWithBindingPattern3.ts, 4, 66)) +>a : Symbol(a, Decl(restParameterWithBindingPattern3.ts, 6, 15)) +>d : Symbol(d, Decl(restParameterWithBindingPattern3.ts, 6, 21)) + diff --git a/tests/baselines/reference/restParameterWithBindingPattern3.types b/tests/baselines/reference/restParameterWithBindingPattern3.types index 09b2f9143fe..7ab8bdf621a 100644 --- a/tests/baselines/reference/restParameterWithBindingPattern3.types +++ b/tests/baselines/reference/restParameterWithBindingPattern3.types @@ -6,3 +6,21 @@ function a(...[a = 1, b = true]: string[]) { } >b : string >true : true +function b(...[...foo = []]: string[]) { } +>b : (...[...foo]: string[]) => void +>foo : string[] +>[] : undefined[] + +function c(...{0: a, length, 3: d}: [boolean, string, number]) { } +>c : (__0_0: boolean, __0_1: string, __0_2: number) => void +>a : boolean +>length : 3 +>d : string | number | boolean + +function d(...[a, , , d]: [boolean, string, number]) { } +>d : (__0_0: boolean, __0_1: string, __0_2: number) => void +>a : boolean +> : undefined +> : undefined +>d : any + diff --git a/tests/baselines/reference/restParameterWithBindingPattern4.errors.txt b/tests/baselines/reference/restParameterWithBindingPattern4.errors.txt deleted file mode 100644 index 355ab26c6c5..00000000000 --- a/tests/baselines/reference/restParameterWithBindingPattern4.errors.txt +++ /dev/null @@ -1,7 +0,0 @@ -tests/cases/compiler/restParameterWithBindingPattern4.ts(1,23): error TS1186: A rest element cannot have an initializer. - - -==== tests/cases/compiler/restParameterWithBindingPattern4.ts (1 errors) ==== - function a(...[...foo = []]: string[]) { } - ~ -!!! error TS1186: A rest element cannot have an initializer. \ No newline at end of file diff --git a/tests/baselines/reference/restParameterWithBindingPattern4.js b/tests/baselines/reference/restParameterWithBindingPattern4.js deleted file mode 100644 index 348fa5a02bb..00000000000 --- a/tests/baselines/reference/restParameterWithBindingPattern4.js +++ /dev/null @@ -1,11 +0,0 @@ -//// [restParameterWithBindingPattern4.ts] -function a(...[...foo = []]: string[]) { } - -//// [restParameterWithBindingPattern4.js] -function a() { - var _a = []; - for (var _i = 0; _i < arguments.length; _i++) { - _a[_i] = arguments[_i]; - } - var _b = _a.slice(0), foo = _b === void 0 ? [] : _b; -} diff --git a/tests/baselines/reference/restParameterWithBindingPattern4.symbols b/tests/baselines/reference/restParameterWithBindingPattern4.symbols deleted file mode 100644 index f281620423e..00000000000 --- a/tests/baselines/reference/restParameterWithBindingPattern4.symbols +++ /dev/null @@ -1,5 +0,0 @@ -=== tests/cases/compiler/restParameterWithBindingPattern4.ts === -function a(...[...foo = []]: string[]) { } ->a : Symbol(a, Decl(restParameterWithBindingPattern4.ts, 0, 0)) ->foo : Symbol(foo, Decl(restParameterWithBindingPattern4.ts, 0, 15)) - diff --git a/tests/baselines/reference/restParameterWithBindingPattern4.types b/tests/baselines/reference/restParameterWithBindingPattern4.types deleted file mode 100644 index f4af66e9be7..00000000000 --- a/tests/baselines/reference/restParameterWithBindingPattern4.types +++ /dev/null @@ -1,6 +0,0 @@ -=== tests/cases/compiler/restParameterWithBindingPattern4.ts === -function a(...[...foo = []]: string[]) { } ->a : (...[...foo]: string[]) => void ->foo : string[] ->[] : undefined[] - diff --git a/tests/baselines/reference/restParameterWithBindingPattern5.js b/tests/baselines/reference/restParameterWithBindingPattern5.js deleted file mode 100644 index 4bff99068e0..00000000000 --- a/tests/baselines/reference/restParameterWithBindingPattern5.js +++ /dev/null @@ -1,11 +0,0 @@ -//// [restParameterWithBindingPattern5.ts] -function a(...{0: a, length, 3: d}: [boolean, string, number]) { } - -//// [restParameterWithBindingPattern5.js] -function a() { - var _a = []; - for (var _i = 0; _i < arguments.length; _i++) { - _a[_i] = arguments[_i]; - } - var a = _a[0], length = _a.length, d = _a[3]; -} diff --git a/tests/baselines/reference/restParameterWithBindingPattern5.symbols b/tests/baselines/reference/restParameterWithBindingPattern5.symbols deleted file mode 100644 index a59b24f64f4..00000000000 --- a/tests/baselines/reference/restParameterWithBindingPattern5.symbols +++ /dev/null @@ -1,7 +0,0 @@ -=== tests/cases/compiler/restParameterWithBindingPattern5.ts === -function a(...{0: a, length, 3: d}: [boolean, string, number]) { } ->a : Symbol(a, Decl(restParameterWithBindingPattern5.ts, 0, 0)) ->a : Symbol(a, Decl(restParameterWithBindingPattern5.ts, 0, 15)) ->length : Symbol(length, Decl(restParameterWithBindingPattern5.ts, 0, 20)) ->d : Symbol(d, Decl(restParameterWithBindingPattern5.ts, 0, 28)) - diff --git a/tests/baselines/reference/restParameterWithBindingPattern5.types b/tests/baselines/reference/restParameterWithBindingPattern5.types deleted file mode 100644 index 6986660adcd..00000000000 --- a/tests/baselines/reference/restParameterWithBindingPattern5.types +++ /dev/null @@ -1,7 +0,0 @@ -=== tests/cases/compiler/restParameterWithBindingPattern5.ts === -function a(...{0: a, length, 3: d}: [boolean, string, number]) { } ->a : (__0_0: boolean, __0_1: string, __0_2: number) => void ->a : boolean ->length : 3 ->d : string | number | boolean - diff --git a/tests/baselines/reference/restParameterWithBindingPattern6.errors.txt b/tests/baselines/reference/restParameterWithBindingPattern6.errors.txt deleted file mode 100644 index 6f590b2bb67..00000000000 --- a/tests/baselines/reference/restParameterWithBindingPattern6.errors.txt +++ /dev/null @@ -1,7 +0,0 @@ -tests/cases/compiler/restParameterWithBindingPattern6.ts(1,23): error TS2493: Tuple type '[boolean, string, number]' with length '3' cannot be assigned to tuple with length '4'. - - -==== tests/cases/compiler/restParameterWithBindingPattern6.ts (1 errors) ==== - function a(...[a, , , d]: [boolean, string, number]) { } - ~ -!!! error TS2493: Tuple type '[boolean, string, number]' with length '3' cannot be assigned to tuple with length '4'. \ No newline at end of file diff --git a/tests/baselines/reference/restParameterWithBindingPattern6.js b/tests/baselines/reference/restParameterWithBindingPattern6.js deleted file mode 100644 index 02101d0fcdb..00000000000 --- a/tests/baselines/reference/restParameterWithBindingPattern6.js +++ /dev/null @@ -1,11 +0,0 @@ -//// [restParameterWithBindingPattern6.ts] -function a(...[a, , , d]: [boolean, string, number]) { } - -//// [restParameterWithBindingPattern6.js] -function a() { - var _a = []; - for (var _i = 0; _i < arguments.length; _i++) { - _a[_i] = arguments[_i]; - } - var a = _a[0], d = _a[3]; -} diff --git a/tests/baselines/reference/restParameterWithBindingPattern6.symbols b/tests/baselines/reference/restParameterWithBindingPattern6.symbols deleted file mode 100644 index 2c16d11e33f..00000000000 --- a/tests/baselines/reference/restParameterWithBindingPattern6.symbols +++ /dev/null @@ -1,6 +0,0 @@ -=== tests/cases/compiler/restParameterWithBindingPattern6.ts === -function a(...[a, , , d]: [boolean, string, number]) { } ->a : Symbol(a, Decl(restParameterWithBindingPattern6.ts, 0, 0)) ->a : Symbol(a, Decl(restParameterWithBindingPattern6.ts, 0, 15)) ->d : Symbol(d, Decl(restParameterWithBindingPattern6.ts, 0, 21)) - diff --git a/tests/baselines/reference/restParameterWithBindingPattern6.types b/tests/baselines/reference/restParameterWithBindingPattern6.types deleted file mode 100644 index f0062077458..00000000000 --- a/tests/baselines/reference/restParameterWithBindingPattern6.types +++ /dev/null @@ -1,8 +0,0 @@ -=== tests/cases/compiler/restParameterWithBindingPattern6.ts === -function a(...[a, , , d]: [boolean, string, number]) { } ->a : (__0_0: boolean, __0_1: string, __0_2: number) => void ->a : boolean -> : undefined -> : undefined ->d : any - diff --git a/tests/cases/compiler/restParameterWithBindingPattern3.ts b/tests/cases/compiler/restParameterWithBindingPattern3.ts index 920e00ac2e8..93d0daae538 100644 --- a/tests/cases/compiler/restParameterWithBindingPattern3.ts +++ b/tests/cases/compiler/restParameterWithBindingPattern3.ts @@ -1 +1,7 @@ -function a(...[a = 1, b = true]: string[]) { } \ No newline at end of file +function a(...[a = 1, b = true]: string[]) { } + +function b(...[...foo = []]: string[]) { } + +function c(...{0: a, length, 3: d}: [boolean, string, number]) { } + +function d(...[a, , , d]: [boolean, string, number]) { } \ No newline at end of file diff --git a/tests/cases/compiler/restParameterWithBindingPattern4.ts b/tests/cases/compiler/restParameterWithBindingPattern4.ts deleted file mode 100644 index fee0067bd50..00000000000 --- a/tests/cases/compiler/restParameterWithBindingPattern4.ts +++ /dev/null @@ -1 +0,0 @@ -function a(...[...foo = []]: string[]) { } \ No newline at end of file diff --git a/tests/cases/compiler/restParameterWithBindingPattern5.ts b/tests/cases/compiler/restParameterWithBindingPattern5.ts deleted file mode 100644 index 7707a99b11e..00000000000 --- a/tests/cases/compiler/restParameterWithBindingPattern5.ts +++ /dev/null @@ -1 +0,0 @@ -function a(...{0: a, length, 3: d}: [boolean, string, number]) { } \ No newline at end of file diff --git a/tests/cases/compiler/restParameterWithBindingPattern6.ts b/tests/cases/compiler/restParameterWithBindingPattern6.ts deleted file mode 100644 index ae95ad8c4d9..00000000000 --- a/tests/cases/compiler/restParameterWithBindingPattern6.ts +++ /dev/null @@ -1 +0,0 @@ -function a(...[a, , , d]: [boolean, string, number]) { } \ No newline at end of file From 5b122dbad6d72e6df49e2e0dc5f07a4f601ba699 Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Mon, 30 Jul 2018 16:22:25 +0200 Subject: [PATCH 06/96] test sourceMap --- .../restParameterWithBindingPattern2.js | 1 + .../restParameterWithBindingPattern2.js.map | 2 + ...ParameterWithBindingPattern2.sourcemap.txt | 90 +++++++++++++++++++ .../restParameterWithBindingPattern2.ts | 2 + 4 files changed, 95 insertions(+) create mode 100644 tests/baselines/reference/restParameterWithBindingPattern2.js.map create mode 100644 tests/baselines/reference/restParameterWithBindingPattern2.sourcemap.txt diff --git a/tests/baselines/reference/restParameterWithBindingPattern2.js b/tests/baselines/reference/restParameterWithBindingPattern2.js index 348023d7aa4..acef0954194 100644 --- a/tests/baselines/reference/restParameterWithBindingPattern2.js +++ b/tests/baselines/reference/restParameterWithBindingPattern2.js @@ -9,3 +9,4 @@ function a() { } var a = _a[0], b = _a[1]; } +//# sourceMappingURL=restParameterWithBindingPattern2.js.map \ No newline at end of file diff --git a/tests/baselines/reference/restParameterWithBindingPattern2.js.map b/tests/baselines/reference/restParameterWithBindingPattern2.js.map new file mode 100644 index 00000000000..1e25b0f14be --- /dev/null +++ b/tests/baselines/reference/restParameterWithBindingPattern2.js.map @@ -0,0 +1,2 @@ +//// [restParameterWithBindingPattern2.js.map] +{"version":3,"file":"restParameterWithBindingPattern2.js","sourceRoot":"","sources":["restParameterWithBindingPattern2.ts"],"names":[],"mappings":"AAAA,SAAS,CAAC;IAAC,YAAS;SAAT,UAAS,EAAT,qBAAS,EAAT,IAAS;QAAT,uBAAS;;IAAT,IAAI,SAAC,EAAE,SAAC,CAAC;AAAI,CAAC"} \ No newline at end of file diff --git a/tests/baselines/reference/restParameterWithBindingPattern2.sourcemap.txt b/tests/baselines/reference/restParameterWithBindingPattern2.sourcemap.txt new file mode 100644 index 00000000000..7cd85ba9deb --- /dev/null +++ b/tests/baselines/reference/restParameterWithBindingPattern2.sourcemap.txt @@ -0,0 +1,90 @@ +=================================================================== +JsFile: restParameterWithBindingPattern2.js +mapUrl: restParameterWithBindingPattern2.js.map +sourceRoot: +sources: restParameterWithBindingPattern2.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/restParameterWithBindingPattern2.js +sourceFile:restParameterWithBindingPattern2.ts +------------------------------------------------------------------- +>>>function a() { +1 > +2 >^^^^^^^^^ +3 > ^ +4 > ^^^^^^^-> +1 > +2 >function +3 > a +1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0) +2 >Emitted(1, 10) Source(1, 10) + SourceIndex(0) +3 >Emitted(1, 11) Source(1, 11) + SourceIndex(0) +--- +>>> var _a = []; +1->^^^^ +2 > ^^^^^^^^^^^^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1->( +2 > ...[a, b] +1->Emitted(2, 5) Source(1, 12) + SourceIndex(0) +2 >Emitted(2, 17) Source(1, 21) + SourceIndex(0) +--- +>>> for (var _i = 0; _i < arguments.length; _i++) { +1->^^^^^^^^^ +2 > ^^^^^^^^^^ +3 > ^^ +4 > ^^^^^^^^^^^^^^^^^^^^^ +5 > ^^ +6 > ^^^^ +1-> +2 > ...[a, b] +3 > +4 > ...[a, b] +5 > +6 > ...[a, b] +1->Emitted(3, 10) Source(1, 12) + SourceIndex(0) +2 >Emitted(3, 20) Source(1, 21) + SourceIndex(0) +3 >Emitted(3, 22) Source(1, 12) + SourceIndex(0) +4 >Emitted(3, 43) Source(1, 21) + SourceIndex(0) +5 >Emitted(3, 45) Source(1, 12) + SourceIndex(0) +6 >Emitted(3, 49) Source(1, 21) + SourceIndex(0) +--- +>>> _a[_i] = arguments[_i]; +1 >^^^^^^^^ +2 > ^^^^^^^^^^^^^^^^^^^^^^^ +1 > +2 > ...[a, b] +1 >Emitted(4, 9) Source(1, 12) + SourceIndex(0) +2 >Emitted(4, 32) Source(1, 21) + SourceIndex(0) +--- +>>> } +>>> var a = _a[0], b = _a[1]; +1 >^^^^ +2 > ^^^^ +3 > ^^^^^^^^^ +4 > ^^ +5 > ^^^^^^^^^ +6 > ^ +1 > +2 > ...[ +3 > a +4 > , +5 > b +6 > ] +1 >Emitted(6, 5) Source(1, 12) + SourceIndex(0) +2 >Emitted(6, 9) Source(1, 16) + SourceIndex(0) +3 >Emitted(6, 18) Source(1, 17) + SourceIndex(0) +4 >Emitted(6, 20) Source(1, 19) + SourceIndex(0) +5 >Emitted(6, 29) Source(1, 20) + SourceIndex(0) +6 >Emitted(6, 30) Source(1, 21) + SourceIndex(0) +--- +>>>} +1 > +2 >^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 >) { +2 >} +1 >Emitted(7, 1) Source(1, 25) + SourceIndex(0) +2 >Emitted(7, 2) Source(1, 26) + SourceIndex(0) +--- +>>>//# sourceMappingURL=restParameterWithBindingPattern2.js.map \ No newline at end of file diff --git a/tests/cases/compiler/restParameterWithBindingPattern2.ts b/tests/cases/compiler/restParameterWithBindingPattern2.ts index 85076703b79..d7057885040 100644 --- a/tests/cases/compiler/restParameterWithBindingPattern2.ts +++ b/tests/cases/compiler/restParameterWithBindingPattern2.ts @@ -1 +1,3 @@ +// @sourcemap: true + function a(...[a, b]) { } \ No newline at end of file From 63c80ddaf5e046befdff3e6c6e19564ff193ea99 Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Wed, 1 Aug 2018 11:12:47 +0200 Subject: [PATCH 07/96] additional test --- .../restParameterWithBindingPattern1.js | 1 + .../restParameterWithBindingPattern1.js.map | 2 + ...ParameterWithBindingPattern1.sourcemap.txt | 90 +++++++++++++++++++ ...estParameterWithBindingPattern3.errors.txt | 15 +++- .../restParameterWithBindingPattern3.js | 20 ++++- .../restParameterWithBindingPattern3.symbols | 6 ++ .../restParameterWithBindingPattern3.types | 9 ++ .../restParameterWithBindingPattern1.ts | 2 + .../restParameterWithBindingPattern3.ts | 4 +- 9 files changed, 145 insertions(+), 4 deletions(-) create mode 100644 tests/baselines/reference/restParameterWithBindingPattern1.js.map create mode 100644 tests/baselines/reference/restParameterWithBindingPattern1.sourcemap.txt diff --git a/tests/baselines/reference/restParameterWithBindingPattern1.js b/tests/baselines/reference/restParameterWithBindingPattern1.js index eca1a760471..d872d232450 100644 --- a/tests/baselines/reference/restParameterWithBindingPattern1.js +++ b/tests/baselines/reference/restParameterWithBindingPattern1.js @@ -9,3 +9,4 @@ function a() { } var a = _a.a, b = _a.b; } +//# sourceMappingURL=restParameterWithBindingPattern1.js.map \ No newline at end of file diff --git a/tests/baselines/reference/restParameterWithBindingPattern1.js.map b/tests/baselines/reference/restParameterWithBindingPattern1.js.map new file mode 100644 index 00000000000..94c277257b9 --- /dev/null +++ b/tests/baselines/reference/restParameterWithBindingPattern1.js.map @@ -0,0 +1,2 @@ +//// [restParameterWithBindingPattern1.js.map] +{"version":3,"file":"restParameterWithBindingPattern1.js","sourceRoot":"","sources":["restParameterWithBindingPattern1.ts"],"names":[],"mappings":"AAAA,SAAS,CAAC;IAAC,YAAS;SAAT,UAAS,EAAT,qBAAS,EAAT,IAAS;QAAT,uBAAS;;IAAT,IAAI,QAAC,EAAE,QAAC,CAAC;AAAI,CAAC"} \ No newline at end of file diff --git a/tests/baselines/reference/restParameterWithBindingPattern1.sourcemap.txt b/tests/baselines/reference/restParameterWithBindingPattern1.sourcemap.txt new file mode 100644 index 00000000000..a5aa2351bc0 --- /dev/null +++ b/tests/baselines/reference/restParameterWithBindingPattern1.sourcemap.txt @@ -0,0 +1,90 @@ +=================================================================== +JsFile: restParameterWithBindingPattern1.js +mapUrl: restParameterWithBindingPattern1.js.map +sourceRoot: +sources: restParameterWithBindingPattern1.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/restParameterWithBindingPattern1.js +sourceFile:restParameterWithBindingPattern1.ts +------------------------------------------------------------------- +>>>function a() { +1 > +2 >^^^^^^^^^ +3 > ^ +4 > ^^^^^^^-> +1 > +2 >function +3 > a +1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0) +2 >Emitted(1, 10) Source(1, 10) + SourceIndex(0) +3 >Emitted(1, 11) Source(1, 11) + SourceIndex(0) +--- +>>> var _a = []; +1->^^^^ +2 > ^^^^^^^^^^^^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1->( +2 > ...{a, b} +1->Emitted(2, 5) Source(1, 12) + SourceIndex(0) +2 >Emitted(2, 17) Source(1, 21) + SourceIndex(0) +--- +>>> for (var _i = 0; _i < arguments.length; _i++) { +1->^^^^^^^^^ +2 > ^^^^^^^^^^ +3 > ^^ +4 > ^^^^^^^^^^^^^^^^^^^^^ +5 > ^^ +6 > ^^^^ +1-> +2 > ...{a, b} +3 > +4 > ...{a, b} +5 > +6 > ...{a, b} +1->Emitted(3, 10) Source(1, 12) + SourceIndex(0) +2 >Emitted(3, 20) Source(1, 21) + SourceIndex(0) +3 >Emitted(3, 22) Source(1, 12) + SourceIndex(0) +4 >Emitted(3, 43) Source(1, 21) + SourceIndex(0) +5 >Emitted(3, 45) Source(1, 12) + SourceIndex(0) +6 >Emitted(3, 49) Source(1, 21) + SourceIndex(0) +--- +>>> _a[_i] = arguments[_i]; +1 >^^^^^^^^ +2 > ^^^^^^^^^^^^^^^^^^^^^^^ +1 > +2 > ...{a, b} +1 >Emitted(4, 9) Source(1, 12) + SourceIndex(0) +2 >Emitted(4, 32) Source(1, 21) + SourceIndex(0) +--- +>>> } +>>> var a = _a.a, b = _a.b; +1 >^^^^ +2 > ^^^^ +3 > ^^^^^^^^ +4 > ^^ +5 > ^^^^^^^^ +6 > ^ +1 > +2 > ...{ +3 > a +4 > , +5 > b +6 > } +1 >Emitted(6, 5) Source(1, 12) + SourceIndex(0) +2 >Emitted(6, 9) Source(1, 16) + SourceIndex(0) +3 >Emitted(6, 17) Source(1, 17) + SourceIndex(0) +4 >Emitted(6, 19) Source(1, 19) + SourceIndex(0) +5 >Emitted(6, 27) Source(1, 20) + SourceIndex(0) +6 >Emitted(6, 28) Source(1, 21) + SourceIndex(0) +--- +>>>} +1 > +2 >^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 >) { +2 >} +1 >Emitted(7, 1) Source(1, 25) + SourceIndex(0) +2 >Emitted(7, 2) Source(1, 26) + SourceIndex(0) +--- +>>>//# sourceMappingURL=restParameterWithBindingPattern1.js.map \ No newline at end of file diff --git a/tests/baselines/reference/restParameterWithBindingPattern3.errors.txt b/tests/baselines/reference/restParameterWithBindingPattern3.errors.txt index ea6bda983d8..2ad62269f50 100644 --- a/tests/baselines/reference/restParameterWithBindingPattern3.errors.txt +++ b/tests/baselines/reference/restParameterWithBindingPattern3.errors.txt @@ -2,9 +2,12 @@ tests/cases/compiler/restParameterWithBindingPattern3.ts(1,16): error TS2322: Ty tests/cases/compiler/restParameterWithBindingPattern3.ts(1,23): error TS2322: Type 'true' is not assignable to type 'string'. tests/cases/compiler/restParameterWithBindingPattern3.ts(3,23): error TS1186: A rest element cannot have an initializer. tests/cases/compiler/restParameterWithBindingPattern3.ts(7,23): error TS2493: Tuple type '[boolean, string, number]' with length '3' cannot be assigned to tuple with length '4'. +tests/cases/compiler/restParameterWithBindingPattern3.ts(9,19): error TS2322: Type '1' is not assignable to type 'boolean'. +tests/cases/compiler/restParameterWithBindingPattern3.ts(9,29): error TS2322: Type 'true' is not assignable to type 'string'. +tests/cases/compiler/restParameterWithBindingPattern3.ts(9,48): error TS2566: A rest element cannot have a property name. -==== tests/cases/compiler/restParameterWithBindingPattern3.ts (4 errors) ==== +==== tests/cases/compiler/restParameterWithBindingPattern3.ts (7 errors) ==== function a(...[a = 1, b = true]: string[]) { } ~ !!! error TS2322: Type '1' is not assignable to type 'string'. @@ -19,4 +22,12 @@ tests/cases/compiler/restParameterWithBindingPattern3.ts(7,23): error TS2493: Tu function d(...[a, , , d]: [boolean, string, number]) { } ~ -!!! error TS2493: Tuple type '[boolean, string, number]' with length '3' cannot be assigned to tuple with length '4'. \ No newline at end of file +!!! error TS2493: Tuple type '[boolean, string, number]' with length '3' cannot be assigned to tuple with length '4'. + + function e(...{0: a = 1, 1: b = true, ...rest: rest}: [boolean, string, number]) { } + ~ +!!! error TS2322: Type '1' is not assignable to type 'boolean'. + ~ +!!! error TS2322: Type 'true' is not assignable to type 'string'. + ~~~~ +!!! error TS2566: A rest element cannot have a property name. \ No newline at end of file diff --git a/tests/baselines/reference/restParameterWithBindingPattern3.js b/tests/baselines/reference/restParameterWithBindingPattern3.js index da3531633b6..00342e7f741 100644 --- a/tests/baselines/reference/restParameterWithBindingPattern3.js +++ b/tests/baselines/reference/restParameterWithBindingPattern3.js @@ -5,9 +5,20 @@ function b(...[...foo = []]: string[]) { } function c(...{0: a, length, 3: d}: [boolean, string, number]) { } -function d(...[a, , , d]: [boolean, string, number]) { } +function d(...[a, , , d]: [boolean, string, number]) { } + +function e(...{0: a = 1, 1: b = true, ...rest: rest}: [boolean, string, number]) { } //// [restParameterWithBindingPattern3.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) + t[p[i]] = s[p[i]]; + return t; +}; function a() { var _a = []; for (var _i = 0; _i < arguments.length; _i++) { @@ -36,3 +47,10 @@ function d() { } var a = _a[0], d = _a[3]; } +function e() { + var _a = []; + for (var _i = 0; _i < arguments.length; _i++) { + _a[_i] = arguments[_i]; + } + var _b = _a[0], a = _b === void 0 ? 1 : _b, _c = _a[1], b = _c === void 0 ? true : _c, rest = __rest(_a, [0, 1]); +} diff --git a/tests/baselines/reference/restParameterWithBindingPattern3.symbols b/tests/baselines/reference/restParameterWithBindingPattern3.symbols index 2694c7327da..eecaba6d339 100644 --- a/tests/baselines/reference/restParameterWithBindingPattern3.symbols +++ b/tests/baselines/reference/restParameterWithBindingPattern3.symbols @@ -19,3 +19,9 @@ function d(...[a, , , d]: [boolean, string, number]) { } >a : Symbol(a, Decl(restParameterWithBindingPattern3.ts, 6, 15)) >d : Symbol(d, Decl(restParameterWithBindingPattern3.ts, 6, 21)) +function e(...{0: a = 1, 1: b = true, ...rest: rest}: [boolean, string, number]) { } +>e : Symbol(e, Decl(restParameterWithBindingPattern3.ts, 6, 56)) +>a : Symbol(a, Decl(restParameterWithBindingPattern3.ts, 8, 15)) +>b : Symbol(b, Decl(restParameterWithBindingPattern3.ts, 8, 24)) +>rest : Symbol(rest, Decl(restParameterWithBindingPattern3.ts, 8, 37)) + diff --git a/tests/baselines/reference/restParameterWithBindingPattern3.types b/tests/baselines/reference/restParameterWithBindingPattern3.types index 7ab8bdf621a..95a058dfe5c 100644 --- a/tests/baselines/reference/restParameterWithBindingPattern3.types +++ b/tests/baselines/reference/restParameterWithBindingPattern3.types @@ -24,3 +24,12 @@ function d(...[a, , , d]: [boolean, string, number]) { } > : undefined >d : any +function e(...{0: a = 1, 1: b = true, ...rest: rest}: [boolean, string, number]) { } +>e : (__0_0: boolean, __0_1: string, __0_2: number) => void +>a : boolean +>1 : 1 +>b : string +>true : true +>rest : any +>rest : { [n: number]: string | number | boolean; 2: number; length: 3; toString(): string; toLocaleString(): string; pop(): string | number | boolean; push(...items: (string | number | boolean)[]): number; concat(...items: ConcatArray[]): (string | number | boolean)[]; concat(...items: (string | number | boolean | ConcatArray)[]): (string | number | boolean)[]; join(separator?: string): string; reverse(): (string | number | boolean)[]; shift(): string | number | boolean; slice(start?: number, end?: number): (string | number | boolean)[]; sort(compareFn?: (a: string | number | boolean, b: string | number | boolean) => number): [boolean, string, number]; splice(start: number, deleteCount?: number): (string | number | boolean)[]; splice(start: number, deleteCount: number, ...items: (string | number | boolean)[]): (string | number | boolean)[]; unshift(...items: (string | number | boolean)[]): number; indexOf(searchElement: string | number | boolean, fromIndex?: number): number; lastIndexOf(searchElement: string | number | boolean, fromIndex?: number): number; every(callbackfn: (value: string | number | boolean, index: number, array: (string | number | boolean)[]) => boolean, thisArg?: any): boolean; some(callbackfn: (value: string | number | boolean, index: number, array: (string | number | boolean)[]) => boolean, thisArg?: any): boolean; forEach(callbackfn: (value: string | number | boolean, index: number, array: (string | number | boolean)[]) => void, thisArg?: any): void; map(callbackfn: (value: string | number | boolean, index: number, array: (string | number | boolean)[]) => U, thisArg?: any): U[]; filter(callbackfn: (value: string | number | boolean, index: number, array: (string | number | boolean)[]) => value is S, thisArg?: any): S[]; filter(callbackfn: (value: string | number | boolean, index: number, array: (string | number | boolean)[]) => any, thisArg?: any): (string | number | boolean)[]; reduce(callbackfn: (previousValue: string | number | boolean, currentValue: string | number | boolean, currentIndex: number, array: (string | number | boolean)[]) => string | number | boolean): string | number | boolean; reduce(callbackfn: (previousValue: string | number | boolean, currentValue: string | number | boolean, currentIndex: number, array: (string | number | boolean)[]) => string | number | boolean, initialValue: string | number | boolean): string | number | boolean; reduce(callbackfn: (previousValue: U, currentValue: string | number | boolean, currentIndex: number, array: (string | number | boolean)[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: string | number | boolean, currentValue: string | number | boolean, currentIndex: number, array: (string | number | boolean)[]) => string | number | boolean): string | number | boolean; reduceRight(callbackfn: (previousValue: string | number | boolean, currentValue: string | number | boolean, currentIndex: number, array: (string | number | boolean)[]) => string | number | boolean, initialValue: string | number | boolean): string | number | boolean; reduceRight(callbackfn: (previousValue: U, currentValue: string | number | boolean, currentIndex: number, array: (string | number | boolean)[]) => U, initialValue: U): U; } + diff --git a/tests/cases/compiler/restParameterWithBindingPattern1.ts b/tests/cases/compiler/restParameterWithBindingPattern1.ts index 1004b047844..bd6a3b9bbda 100644 --- a/tests/cases/compiler/restParameterWithBindingPattern1.ts +++ b/tests/cases/compiler/restParameterWithBindingPattern1.ts @@ -1 +1,3 @@ +// @sourcemap: true + function a(...{a, b}) { } \ No newline at end of file diff --git a/tests/cases/compiler/restParameterWithBindingPattern3.ts b/tests/cases/compiler/restParameterWithBindingPattern3.ts index 93d0daae538..f0792354c40 100644 --- a/tests/cases/compiler/restParameterWithBindingPattern3.ts +++ b/tests/cases/compiler/restParameterWithBindingPattern3.ts @@ -4,4 +4,6 @@ function b(...[...foo = []]: string[]) { } function c(...{0: a, length, 3: d}: [boolean, string, number]) { } -function d(...[a, , , d]: [boolean, string, number]) { } \ No newline at end of file +function d(...[a, , , d]: [boolean, string, number]) { } + +function e(...{0: a = 1, 1: b = true, ...rest: rest}: [boolean, string, number]) { } \ No newline at end of file From 77494d629468533cbb237ece5f18a6d7ad306b2f Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Tue, 7 Aug 2018 15:35:43 -0700 Subject: [PATCH 08/96] getScriptInfoOrConfig: Canonicalize tsconfig path before lookup --- src/server/editorServices.ts | 2 +- .../unittests/tsserverProjectSystem.ts | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 56026bb70d4..895ba0cbc39 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -1804,7 +1804,7 @@ namespace ts.server { const path = toNormalizedPath(uncheckedFileName); const info = this.getScriptInfoForNormalizedPath(path); if (info) return info; - const configProject = this.configuredProjects.get(uncheckedFileName); + const configProject = this.configuredProjects.get(this.toCanonicalFileName(uncheckedFileName)); return configProject && configProject.getCompilerOptions().configFile; } diff --git a/src/testRunner/unittests/tsserverProjectSystem.ts b/src/testRunner/unittests/tsserverProjectSystem.ts index c89d29ffc5b..7e41cf44201 100644 --- a/src/testRunner/unittests/tsserverProjectSystem.ts +++ b/src/testRunner/unittests/tsserverProjectSystem.ts @@ -9717,6 +9717,43 @@ export function Test2() { }); }); + describe("tsserverProjectSystem refactors", () => { + it("handles canonicalization of tsconfig path", () => { + const aTs: File = { path: "/Foo/a.ts", content: "const x = 0;" }; + const tsconfig: File = { path: "/Foo/tsconfig.json", content: '{ "files": ["./a.ts"] }' }; + const session = createSession(createServerHost([aTs, tsconfig])); + openFilesForSession([aTs], session); + + const result = executeSessionRequest(session, protocol.CommandTypes.GetEditsForRefactor, { + file: aTs.path, + startLine: 1, + startOffset: 1, + endLine: 2, + endOffset: aTs.content.length, + refactor: "Move to a new file", + action: "Move to a new file", + }); + assert.deepEqual(result, { + edits: [ + { + fileName: aTs.path, + textChanges: [{ start: { line: 1, offset: 1 }, end: { line: 1, offset: aTs.content.length + 1 }, newText: "" }], + }, + { + fileName: tsconfig.path, + textChanges: [{ start: { line: 1, offset: 21 }, end: { line: 1, offset: 21 }, newText: ', "./x.ts"' }], + }, + { + fileName: "/Foo/x.ts", + textChanges: [{ start: { line: 0, offset: 0 }, end: { line: 0, offset: 0 }, newText: "const x = 0;" }], + }, + ], + renameFilename: undefined, + renameLocation: undefined, + }); + }); + }); + function makeReferenceItem(file: File, isDefinition: boolean, text: string, lineText: string, options?: SpanFromSubstringOptions): protocol.ReferencesResponseItem { return { ...protocolFileSpanFromSubstring(file, text, options), From ac460e30e74f40ffc84d1868d975be2297cc4832 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Fri, 10 Aug 2018 11:50:39 -0700 Subject: [PATCH 09/96] code review --- src/server/editorServices.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 895ba0cbc39..9a74ff3e53f 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -1804,7 +1804,7 @@ namespace ts.server { const path = toNormalizedPath(uncheckedFileName); const info = this.getScriptInfoForNormalizedPath(path); if (info) return info; - const configProject = this.configuredProjects.get(this.toCanonicalFileName(uncheckedFileName)); + const configProject = this.configuredProjects.get(this.toCanonicalFileName(path)); return configProject && configProject.getCompilerOptions().configFile; } From 0f5d62630b7faa5b0820a8859bd5159d9472366e Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Mon, 17 Sep 2018 11:26:35 -0700 Subject: [PATCH 10/96] Use this.toPath --- src/server/editorServices.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 21eb931d491..606e3bbe405 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -1884,7 +1884,7 @@ namespace ts.server { const path = toNormalizedPath(uncheckedFileName); const info = this.getScriptInfoForNormalizedPath(path); if (info) return info; - const configProject = this.configuredProjects.get(this.toCanonicalFileName(path)); + const configProject = this.configuredProjects.get(this.toPath(uncheckedFileName)); return configProject && configProject.getCompilerOptions().configFile; } From 7c92d09e23bc6c94e4e1bd7bb893163f0e32f875 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 12 Dec 2018 13:00:30 -0800 Subject: [PATCH 11/96] When removing the errors for the exports from the file, apart from removing transitive exports, remove the diagnostics of file that import these exports Fixes #28983 --- src/compiler/builder.ts | 11 +- src/testRunner/unittests/tscWatchMode.ts | 175 +++++++++++++++++++---- 2 files changed, 159 insertions(+), 27 deletions(-) diff --git a/src/compiler/builder.ts b/src/compiler/builder.ts index 637e77c545f..7973a4cc8dd 100644 --- a/src/compiler/builder.ts +++ b/src/compiler/builder.ts @@ -281,10 +281,19 @@ namespace ts { } // If exported from path is not from cache and exported modules has path, all files referencing file exported from are affected - return !!forEachEntry(state.exportedModulesMap!, (exportedModules, exportedFromPath) => + if (forEachEntry(state.exportedModulesMap!, (exportedModules, exportedFromPath) => !state.currentAffectedFilesExportedModulesMap!.has(exportedFromPath) && // If we already iterated this through cache, ignore it exportedModules.has(filePath) && removeSemanticDiagnosticsOfFileAndExportsOfFile(state, exportedFromPath as Path, seenFileAndExportsOfFile) + )) { + return true; + } + + // Remove diagnostics of files that import this file (without going to exports of referencing files) + return !!forEachEntry(state.referencedMap!, (referencesInFile, referencingFilePath) => + referencesInFile.has(filePath) && + !seenFileAndExportsOfFile.has(referencingFilePath) && // Not already removed diagnostic file + removeSemanticDiagnosticsOf(state, referencingFilePath as Path) // Dont add to seen since this is not yet done with the export removal ); } diff --git a/src/testRunner/unittests/tscWatchMode.ts b/src/testRunner/unittests/tscWatchMode.ts index 65f64b9da78..38acc2963e2 100644 --- a/src/testRunner/unittests/tscWatchMode.ts +++ b/src/testRunner/unittests/tscWatchMode.ts @@ -27,11 +27,18 @@ namespace ts.tscWatch { return () => watch.getCurrentProgram(); } + interface Watch { + (): Program; + getBuilderProgram(): EmitAndSemanticDiagnosticsBuilderProgram; + } + export function createWatchOfConfigFile(configFileName: string, host: WatchedSystem, maxNumberOfFilesToIterateForInvalidation?: number) { const compilerHost = createWatchCompilerHostOfConfigFile(configFileName, {}, host); compilerHost.maxNumberOfFilesToIterateForInvalidation = maxNumberOfFilesToIterateForInvalidation; const watch = createWatchProgram(compilerHost); - return () => watch.getCurrentProgram().getProgram(); + const result = (() => watch.getCurrentProgram().getProgram()) as Watch; + result.getBuilderProgram = () => watch.getCurrentProgram(); + return result; } function createWatchOfFilesAndCompilerOptions(rootFiles: string[], host: WatchedSystem, options: CompilerOptions = {}, maxNumberOfFilesToIterateForInvalidation?: number) { @@ -182,7 +189,22 @@ namespace ts.tscWatch { assert.equal(host.exitCode, expectedExitCode); } - function getDiagnosticOfFileFrom(file: SourceFile | undefined, text: string, start: number | undefined, length: number | undefined, message: DiagnosticMessage): Diagnostic { + function isDiagnosticMessageChain(message: DiagnosticMessage | DiagnosticMessageChain): message is DiagnosticMessageChain { + return !!(message as DiagnosticMessageChain).messageText; + } + function getDiagnosticOfFileFrom(file: SourceFile | undefined, start: number | undefined, length: number | undefined, message: DiagnosticMessage | DiagnosticMessageChain, ..._args: (string | number)[]): Diagnostic { + let text: DiagnosticMessageChain | string; + if (isDiagnosticMessageChain(message)) { + text = message; + } + else { + text = getLocaleSpecificMessage(message); + + if (arguments.length > 4) { + text = formatStringFromArgs(text, arguments, 4); + } + } + return { file, start, @@ -194,24 +216,12 @@ namespace ts.tscWatch { }; } - function getDiagnosticWithoutFile(message: DiagnosticMessage, ..._args: (string | number)[]): Diagnostic { - let text = getLocaleSpecificMessage(message); - - if (arguments.length > 1) { - text = formatStringFromArgs(text, arguments, 1); - } - - return getDiagnosticOfFileFrom(/*file*/ undefined, text, /*start*/ undefined, /*length*/ undefined, message); + function getDiagnosticWithoutFile(message: DiagnosticMessage | DiagnosticMessageChain, ...args: (string | number)[]): Diagnostic { + return getDiagnosticOfFileFrom(/*file*/ undefined, /*start*/ undefined, /*length*/ undefined, message, ...args); } - function getDiagnosticOfFile(file: SourceFile, start: number, length: number, message: DiagnosticMessage, ..._args: (string | number)[]): Diagnostic { - let text = getLocaleSpecificMessage(message); - - if (arguments.length > 4) { - text = formatStringFromArgs(text, arguments, 4); - } - - return getDiagnosticOfFileFrom(file, text, start, length, message); + function getDiagnosticOfFile(file: SourceFile, start: number, length: number, message: DiagnosticMessage | DiagnosticMessageChain, ...args: (string | number)[]): Diagnostic { + return getDiagnosticOfFileFrom(file, start, length, message, ...args); } function getUnknownCompilerOption(program: Program, configFile: File, option: string) { @@ -219,15 +229,9 @@ namespace ts.tscWatch { return getDiagnosticOfFile(program.getCompilerOptions().configFile!, configFile.content.indexOf(quotedOption), quotedOption.length, Diagnostics.Unknown_compiler_option_0, option); } - function getDiagnosticOfFileFromProgram(program: Program, filePath: string, start: number, length: number, message: DiagnosticMessage, ..._args: (string | number)[]): Diagnostic { - let text = getLocaleSpecificMessage(message); - - if (arguments.length > 5) { - text = formatStringFromArgs(text, arguments, 5); - } - + function getDiagnosticOfFileFromProgram(program: Program, filePath: string, start: number, length: number, message: DiagnosticMessage | DiagnosticMessageChain, ...args: (string | number)[]): Diagnostic { return getDiagnosticOfFileFrom(program.getSourceFileByPath(toPath(filePath, program.getCurrentDirectory(), s => s.toLowerCase()))!, - text, start, length, message); + start, length, message, ...args); } function getDiagnosticModuleNotFoundOfFile(program: Program, file: File, moduleName: string) { @@ -1706,6 +1710,125 @@ interface Document { }); }); + describe("Emit times and Error updates in builder after program changes", () => { + function getOutputFileStampAndError(host: WatchedSystem, watch: Watch, file: File) { + const builderProgram = watch.getBuilderProgram(); + const state = builderProgram.getState(); + return { + file, + fileStamp: host.getModifiedTime(file.path.replace(".ts", ".js")), + errors: builderProgram.getSemanticDiagnostics(watch().getSourceFileByPath(file.path as Path)), + errorsFromOldState: !!state.semanticDiagnosticsFromOldState && state.semanticDiagnosticsFromOldState.has(file.path) + }; + } + + function getOutputFileStampsAndErrors(host: WatchedSystem, watch: Watch, directoryFiles: ReadonlyArray) { + return directoryFiles.map(d => getOutputFileStampAndError(host, watch, d)); + } + + function findStampAndErrors(stampsAndErrors: ReadonlyArray>, file: File) { + return find(stampsAndErrors, info => info.file === file)!; + } + + function verifyOutputFileStampsAndErrors( + file: File, + emitExpected: boolean, + errorRefershExpected: boolean, + beforeChangeFileStampsAndErrors: ReadonlyArray>, + afterChangeFileStampsAndErrors: ReadonlyArray> + ) { + const beforeChange = findStampAndErrors(beforeChangeFileStampsAndErrors, file); + const afterChange = findStampAndErrors(afterChangeFileStampsAndErrors, file); + if (emitExpected) { + assert.notStrictEqual(afterChange.fileStamp, beforeChange.fileStamp, `Expected emit for file ${file.path}`); + } + else { + assert.strictEqual(afterChange.fileStamp, beforeChange.fileStamp, `Did not expect new emit for file ${file.path}`); + } + if (errorRefershExpected) { + if (afterChange.errors !== emptyArray || beforeChange.errors !== emptyArray) { + assert.notStrictEqual(afterChange.errors, beforeChange.errors, `Expected new errors for file ${file.path}`); + } + assert.isFalse(afterChange.errorsFromOldState, `Expected errors to be not copied from old state for file ${file.path}`); + } + else { + assert.strictEqual(afterChange.errors, beforeChange.errors, `Expected errors to not change for file ${file.path}`); + assert.isTrue(afterChange.errorsFromOldState, `Expected errors to be copied from old state for file ${file.path}`); + } + } + + it("updates errors in file not exporting a deep multilevel import that changes", () => { + const currentDirectory = "/user/username/projects/myproject"; + const aFile: File = { + path: `${currentDirectory}/a.ts`, + content: `export interface Point { + name: string; + c: Coords; +} +export interface Coords { + x2: number; + y: number; +}` + }; + const bFile: File = { + path: `${currentDirectory}/b.ts`, + content: `import { Point } from "./a"; +export interface PointWrapper extends Point { +}` + }; + const cFile: File = { + path: `${currentDirectory}/c.ts`, + content: `import { PointWrapper } from "./b"; +export function getPoint(): PointWrapper { + return { + name: "test", + c: { + x: 1, + y: 2 + } + } +};` + }; + const dFile: File = { + path: `${currentDirectory}/d.ts`, + content: `import { getPoint } from "./c"; +getPoint().c.x;` + }; + const eFile: File = { + path: `${currentDirectory}/e.ts`, + content: `import "./d";` + }; + const config: File = { + path: `${currentDirectory}/tsconfig.json`, + content: `{}` + }; + const directoryFiles = [aFile, bFile, cFile, dFile, eFile]; + const files = [...directoryFiles, config, libFile]; + const host = createWatchedSystem(files, { currentDirectory }); + const watch = createWatchOfConfigFile("tsconfig.json", host); + checkProgramActualFiles(watch(), [aFile.path, bFile.path, cFile.path, dFile.path, eFile.path, libFile.path]); + checkOutputErrorsInitial(host, [ + getDiagnosticOfFileFromProgram(watch(), cFile.path, cFile.content.indexOf("x: 1"), 4, chainDiagnosticMessages( + chainDiagnosticMessages(/*details*/ undefined, Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, "x", "Coords"), + Diagnostics.Type_0_is_not_assignable_to_type_1, + "{ x: number; y: number; }", + "Coords" + )), + getDiagnosticOfFileFromProgram(watch(), dFile.path, dFile.content.lastIndexOf("x"), 1, Diagnostics.Property_0_does_not_exist_on_type_1, "x", "Coords") + ]); + const beforeChange = getOutputFileStampsAndErrors(host, watch, directoryFiles); + host.writeFile(aFile.path, aFile.content.replace("x2", "x")); + host.runQueuedTimeoutCallbacks(); + checkOutputErrorsIncremental(host, emptyArray); + const afterChange = getOutputFileStampsAndErrors(host, watch, directoryFiles); + verifyOutputFileStampsAndErrors(aFile, /*emitExpected*/ true, /*errorRefershExpected*/ true, beforeChange, afterChange); + verifyOutputFileStampsAndErrors(bFile, /*emitExpected*/ true, /*errorRefershExpected*/ true, beforeChange, afterChange); + verifyOutputFileStampsAndErrors(cFile, /*emitExpected*/ false, /*errorRefershExpected*/ true, beforeChange, afterChange); + verifyOutputFileStampsAndErrors(dFile, /*emitExpected*/ false, /*errorRefershExpected*/ true, beforeChange, afterChange); + verifyOutputFileStampsAndErrors(eFile, /*emitExpected*/ false, /*errorRefershExpected*/ false, beforeChange, afterChange); + }); + }); + describe("tsc-watch emit with outFile or out setting", () => { function createWatchForOut(out?: string, outFile?: string) { const host = createWatchedSystem([]); From f97a2b3f904b6194deea7166d083ea2b124bcd15 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 12 Dec 2018 15:33:46 -0800 Subject: [PATCH 12/96] Add more tests that verify semantic diagnostics cache --- src/testRunner/unittests/tscWatchMode.ts | 417 ++++++++++++----------- 1 file changed, 213 insertions(+), 204 deletions(-) diff --git a/src/testRunner/unittests/tscWatchMode.ts b/src/testRunner/unittests/tscWatchMode.ts index 38acc2963e2..87e3e736367 100644 --- a/src/testRunner/unittests/tscWatchMode.ts +++ b/src/testRunner/unittests/tscWatchMode.ts @@ -1319,92 +1319,6 @@ export default test;`; } }); - it("updates errors when deep import file changes", () => { - const currentDirectory = "/user/username/projects/myproject"; - const aFile: File = { - path: `${currentDirectory}/a.ts`, - content: `import {B} from './b'; -declare var console: any; -let b = new B(); -console.log(b.c.d);` - }; - const bFile: File = { - path: `${currentDirectory}/b.ts`, - content: `import {C} from './c'; -export class B -{ - c = new C(); -}` - }; - const cFile: File = { - path: `${currentDirectory}/c.ts`, - content: `export class C -{ - d = 1; -}` - }; - const config: File = { - path: `${currentDirectory}/tsconfig.json`, - content: `{}` - }; - const files = [aFile, bFile, cFile, config, libFile]; - const host = createWatchedSystem(files, { currentDirectory }); - const watch = createWatchOfConfigFile("tsconfig.json", host); - checkProgramActualFiles(watch(), [aFile.path, bFile.path, cFile.path, libFile.path]); - checkOutputErrorsInitial(host, emptyArray); - const modifiedTimeOfAJs = host.getModifiedTime(`${currentDirectory}/a.js`); - host.writeFile(cFile.path, cFile.content.replace("d", "d2")); - host.runQueuedTimeoutCallbacks(); - checkOutputErrorsIncremental(host, [ - getDiagnosticOfFileFromProgram(watch(), aFile.path, aFile.content.lastIndexOf("d"), 1, Diagnostics.Property_0_does_not_exist_on_type_1, "d", "C") - ]); - // File a need not be rewritten - assert.equal(host.getModifiedTime(`${currentDirectory}/a.js`), modifiedTimeOfAJs); - }); - - it("updates errors when deep import through declaration file changes", () => { - const currentDirectory = "/user/username/projects/myproject"; - const aFile: File = { - path: `${currentDirectory}/a.ts`, - content: `import {B} from './b'; -declare var console: any; -let b = new B(); -console.log(b.c.d);` - }; - const bFile: File = { - path: `${currentDirectory}/b.d.ts`, - content: `import {C} from './c'; -export class B -{ - c: C; -}` - }; - const cFile: File = { - path: `${currentDirectory}/c.d.ts`, - content: `export class C -{ - d: number; -}` - }; - const config: File = { - path: `${currentDirectory}/tsconfig.json`, - content: `{}` - }; - const files = [aFile, bFile, cFile, config, libFile]; - const host = createWatchedSystem(files, { currentDirectory }); - const watch = createWatchOfConfigFile("tsconfig.json", host); - checkProgramActualFiles(watch(), [aFile.path, bFile.path, cFile.path, libFile.path]); - checkOutputErrorsInitial(host, emptyArray); - const modifiedTimeOfAJs = host.getModifiedTime(`${currentDirectory}/a.js`); - host.writeFile(cFile.path, cFile.content.replace("d", "d2")); - host.runQueuedTimeoutCallbacks(); - checkOutputErrorsIncremental(host, [ - getDiagnosticOfFileFromProgram(watch(), aFile.path, aFile.content.lastIndexOf("d"), 1, Diagnostics.Property_0_does_not_exist_on_type_1, "d", "C") - ]); - // File a need not be rewritten - assert.equal(host.getModifiedTime(`${currentDirectory}/a.js`), modifiedTimeOfAJs); - }); - it("updates errors when strictNullChecks changes", () => { const currentDirectory = "/user/username/projects/myproject"; const aFile: File = { @@ -1477,98 +1391,6 @@ foo().hello` checkOutputErrorsIncremental(host, emptyArray); }); - describe("updates errors when file transitively exported file changes", () => { - const projectLocation = "/user/username/projects/myproject"; - const config: File = { - path: `${projectLocation}/tsconfig.json`, - content: JSON.stringify({ - files: ["app.ts"], - compilerOptions: { baseUrl: "." } - }) - }; - const app: File = { - path: `${projectLocation}/app.ts`, - content: `import { Data } from "lib2/public"; -export class App { - public constructor() { - new Data().test(); - } -}` - }; - const lib2Public: File = { - path: `${projectLocation}/lib2/public.ts`, - content: `export * from "./data";` - }; - const lib2Data: File = { - path: `${projectLocation}/lib2/data.ts`, - content: `import { ITest } from "lib1/public"; -export class Data { - public test() { - const result: ITest = { - title: "title" - } - return result; - } -}` - }; - const lib1Public: File = { - path: `${projectLocation}/lib1/public.ts`, - content: `export * from "./tools/public";` - }; - const lib1ToolsPublic: File = { - path: `${projectLocation}/lib1/tools/public.ts`, - content: `export * from "./tools.interface";` - }; - const lib1ToolsInterface: File = { - path: `${projectLocation}/lib1/tools/tools.interface.ts`, - content: `export interface ITest { - title: string; -}` - }; - - function verifyTransitiveExports(filesWithoutConfig: ReadonlyArray) { - const files = [config, ...filesWithoutConfig]; - const host = createWatchedSystem(files, { currentDirectory: projectLocation }); - const watch = createWatchOfConfigFile(config.path, host); - checkProgramActualFiles(watch(), filesWithoutConfig.map(f => f.path)); - checkOutputErrorsInitial(host, emptyArray); - - host.writeFile(lib1ToolsInterface.path, lib1ToolsInterface.content.replace("title", "title2")); - host.checkTimeoutQueueLengthAndRun(1); - checkProgramActualFiles(watch(), filesWithoutConfig.map(f => f.path)); - checkOutputErrorsIncremental(host, [ - "lib2/data.ts(5,13): error TS2322: Type '{ title: string; }' is not assignable to type 'ITest'.\n Object literal may only specify known properties, but 'title' does not exist in type 'ITest'. Did you mean to write 'title2'?\n" - ]); - - } - it("when there are no circular import and exports", () => { - verifyTransitiveExports([libFile, app, lib2Public, lib2Data, lib1Public, lib1ToolsPublic, lib1ToolsInterface]); - }); - - it("when there are circular import and exports", () => { - const lib2Data: File = { - path: `${projectLocation}/lib2/data.ts`, - content: `import { ITest } from "lib1/public"; import { Data2 } from "./data2"; -export class Data { - public dat?: Data2; public test() { - const result: ITest = { - title: "title" - } - return result; - } -}` - }; - const lib2Data2: File = { - path: `${projectLocation}/lib2/data2.ts`, - content: `import { Data } from "./data"; -export class Data2 { - public dat?: Data; -}` - }; - verifyTransitiveExports([libFile, app, lib2Public, lib2Data, lib2Data2, lib1Public, lib1ToolsPublic, lib1ToolsInterface]); - }); - }); - describe("updates errors in lib file", () => { const currentDirectory = "/user/username/projects/myproject"; const field = "fullscreen"; @@ -1711,6 +1533,11 @@ interface Document { }); describe("Emit times and Error updates in builder after program changes", () => { + const currentDirectory = "/user/username/projects/myproject"; + const config: File = { + path: `${currentDirectory}/tsconfig.json`, + content: `{}` + }; function getOutputFileStampAndError(host: WatchedSystem, watch: Watch, file: File) { const builderProgram = watch.getBuilderProgram(); const state = builderProgram.getState(); @@ -1757,8 +1584,108 @@ interface Document { } } + interface VerifyEmitAndErrorUpdates { + change: (host: WatchedSystem) => void; + getInitialErrors: (watch: Watch) => ReadonlyArray | ReadonlyArray; + getIncrementalErrors: (watch: Watch) => ReadonlyArray | ReadonlyArray; + filesWithNewEmit: ReadonlyArray; + filesWithOnlyErrorRefresh: ReadonlyArray; + filesNotTouched: ReadonlyArray; + configFile?: File; + } + + function verifyEmitAndErrorUpdates({ filesWithNewEmit, filesWithOnlyErrorRefresh, filesNotTouched, configFile = config, change, getInitialErrors, getIncrementalErrors }: VerifyEmitAndErrorUpdates) { + const nonLibFiles = [...filesWithNewEmit, ...filesWithOnlyErrorRefresh, ...filesNotTouched]; + const files = [...nonLibFiles, configFile, libFile]; + const host = createWatchedSystem(files, { currentDirectory }); + const watch = createWatchOfConfigFile("tsconfig.json", host); + checkProgramActualFiles(watch(), [...nonLibFiles.map(f => f.path), libFile.path]); + checkOutputErrorsInitial(host, getInitialErrors(watch)); + const beforeChange = getOutputFileStampsAndErrors(host, watch, nonLibFiles); + change(host); + host.runQueuedTimeoutCallbacks(); + checkOutputErrorsIncremental(host, getIncrementalErrors(watch)); + const afterChange = getOutputFileStampsAndErrors(host, watch, nonLibFiles); + filesWithNewEmit.forEach(file => verifyOutputFileStampsAndErrors(file, /*emitExpected*/ true, /*errorRefershExpected*/ true, beforeChange, afterChange)); + filesWithOnlyErrorRefresh.forEach(file => verifyOutputFileStampsAndErrors(file, /*emitExpected*/ false, /*errorRefershExpected*/ true, beforeChange, afterChange)); + filesNotTouched.forEach(file => verifyOutputFileStampsAndErrors(file, /*emitExpected*/ false, /*errorRefershExpected*/ false, beforeChange, afterChange)); + } + + describe("deep import changes", () => { + const aFile: File = { + path: `${currentDirectory}/a.ts`, + content: `import {B} from './b'; +declare var console: any; +let b = new B(); +console.log(b.c.d);` + }; + + function verifyDeepImportChange(bFile: File, cFile: File) { + const filesWithNewEmit: File[] = []; + const filesWithOnlyErrorRefresh = [aFile]; + addImportedModule(bFile); + addImportedModule(cFile); + verifyEmitAndErrorUpdates({ + filesWithNewEmit, + filesWithOnlyErrorRefresh, + filesNotTouched: emptyArray, + change: host => host.writeFile(cFile.path, cFile.content.replace("d", "d2")), + getInitialErrors: () => emptyArray, + getIncrementalErrors: watch => [ + getDiagnosticOfFileFromProgram(watch(), aFile.path, aFile.content.lastIndexOf("d"), 1, Diagnostics.Property_0_does_not_exist_on_type_1, "d", "C") + ] + }); + + function addImportedModule(file: File) { + if (file.path.endsWith(".d.ts")) { + filesWithOnlyErrorRefresh.push(file); + } + else { + filesWithNewEmit.push(file); + } + } + } + + it("updates errors when deep import file changes", () => { + const bFile: File = { + path: `${currentDirectory}/b.ts`, + content: `import {C} from './c'; +export class B +{ + c = new C(); +}` + }; + const cFile: File = { + path: `${currentDirectory}/c.ts`, + content: `export class C +{ + d = 1; +}` + }; + verifyDeepImportChange(bFile, cFile); + }); + + it("updates errors when deep import through declaration file changes", () => { + const bFile: File = { + path: `${currentDirectory}/b.d.ts`, + content: `import {C} from './c'; +export class B +{ + c: C; +}` + }; + const cFile: File = { + path: `${currentDirectory}/c.d.ts`, + content: `export class C +{ + d: number; +}` + }; + verifyDeepImportChange(bFile, cFile); + }); + }); + it("updates errors in file not exporting a deep multilevel import that changes", () => { - const currentDirectory = "/user/username/projects/myproject"; const aFile: File = { path: `${currentDirectory}/a.ts`, content: `export interface Point { @@ -1798,34 +1725,116 @@ getPoint().c.x;` path: `${currentDirectory}/e.ts`, content: `import "./d";` }; + verifyEmitAndErrorUpdates({ + filesWithNewEmit: [aFile, bFile], + filesWithOnlyErrorRefresh: [cFile, dFile], + filesNotTouched: [eFile], + change: host => host.writeFile(aFile.path, aFile.content.replace("x2", "x")), + getInitialErrors: watch => [ + getDiagnosticOfFileFromProgram(watch(), cFile.path, cFile.content.indexOf("x: 1"), 4, chainDiagnosticMessages( + chainDiagnosticMessages(/*details*/ undefined, Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, "x", "Coords"), + Diagnostics.Type_0_is_not_assignable_to_type_1, + "{ x: number; y: number; }", + "Coords" + )), + getDiagnosticOfFileFromProgram(watch(), dFile.path, dFile.content.lastIndexOf("x"), 1, Diagnostics.Property_0_does_not_exist_on_type_1, "x", "Coords") + ], + getIncrementalErrors: () => emptyArray + }); + }); + + describe("updates errors when file transitively exported file changes", () => { const config: File = { path: `${currentDirectory}/tsconfig.json`, - content: `{}` + content: JSON.stringify({ + files: ["app.ts"], + compilerOptions: { baseUrl: "." } + }) }; - const directoryFiles = [aFile, bFile, cFile, dFile, eFile]; - const files = [...directoryFiles, config, libFile]; - const host = createWatchedSystem(files, { currentDirectory }); - const watch = createWatchOfConfigFile("tsconfig.json", host); - checkProgramActualFiles(watch(), [aFile.path, bFile.path, cFile.path, dFile.path, eFile.path, libFile.path]); - checkOutputErrorsInitial(host, [ - getDiagnosticOfFileFromProgram(watch(), cFile.path, cFile.content.indexOf("x: 1"), 4, chainDiagnosticMessages( - chainDiagnosticMessages(/*details*/ undefined, Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, "x", "Coords"), - Diagnostics.Type_0_is_not_assignable_to_type_1, - "{ x: number; y: number; }", - "Coords" - )), - getDiagnosticOfFileFromProgram(watch(), dFile.path, dFile.content.lastIndexOf("x"), 1, Diagnostics.Property_0_does_not_exist_on_type_1, "x", "Coords") - ]); - const beforeChange = getOutputFileStampsAndErrors(host, watch, directoryFiles); - host.writeFile(aFile.path, aFile.content.replace("x2", "x")); - host.runQueuedTimeoutCallbacks(); - checkOutputErrorsIncremental(host, emptyArray); - const afterChange = getOutputFileStampsAndErrors(host, watch, directoryFiles); - verifyOutputFileStampsAndErrors(aFile, /*emitExpected*/ true, /*errorRefershExpected*/ true, beforeChange, afterChange); - verifyOutputFileStampsAndErrors(bFile, /*emitExpected*/ true, /*errorRefershExpected*/ true, beforeChange, afterChange); - verifyOutputFileStampsAndErrors(cFile, /*emitExpected*/ false, /*errorRefershExpected*/ true, beforeChange, afterChange); - verifyOutputFileStampsAndErrors(dFile, /*emitExpected*/ false, /*errorRefershExpected*/ true, beforeChange, afterChange); - verifyOutputFileStampsAndErrors(eFile, /*emitExpected*/ false, /*errorRefershExpected*/ false, beforeChange, afterChange); + const app: File = { + path: `${currentDirectory}/app.ts`, + content: `import { Data } from "lib2/public"; +export class App { + public constructor() { + new Data().test(); + } +}` + }; + const lib2Public: File = { + path: `${currentDirectory}/lib2/public.ts`, + content: `export * from "./data";` + }; + const lib2Data: File = { + path: `${currentDirectory}/lib2/data.ts`, + content: `import { ITest } from "lib1/public"; +export class Data { + public test() { + const result: ITest = { + title: "title" + } + return result; + } +}` + }; + const lib1Public: File = { + path: `${currentDirectory}/lib1/public.ts`, + content: `export * from "./tools/public";` + }; + const lib1ToolsPublic: File = { + path: `${currentDirectory}/lib1/tools/public.ts`, + content: `export * from "./tools.interface";` + }; + const lib1ToolsInterface: File = { + path: `${currentDirectory}/lib1/tools/tools.interface.ts`, + content: `export interface ITest { + title: string; +}` + }; + + function verifyTransitiveExports(lib2Data: File, lib2Data2?: File) { + const filesWithNewEmit = [lib1ToolsInterface, lib1ToolsPublic]; + const filesWithOnlyErrorRefresh = [app, lib2Public, lib1Public, lib2Data]; + if (lib2Data2) { + filesWithOnlyErrorRefresh.push(lib2Data2); + } + verifyEmitAndErrorUpdates({ + filesWithNewEmit, + filesWithOnlyErrorRefresh, + filesNotTouched: emptyArray, + configFile: config, + change: host => host.writeFile(lib1ToolsInterface.path, lib1ToolsInterface.content.replace("title", "title2")), + getInitialErrors: () => emptyArray, + getIncrementalErrors: () => [ + "lib2/data.ts(5,13): error TS2322: Type '{ title: string; }' is not assignable to type 'ITest'.\n Object literal may only specify known properties, but 'title' does not exist in type 'ITest'. Did you mean to write 'title2'?\n" + ] + }); + } + it("when there are no circular import and exports", () => { + verifyTransitiveExports(lib2Data); + }); + + it("when there are circular import and exports", () => { + const lib2Data: File = { + path: `${currentDirectory}/lib2/data.ts`, + content: `import { ITest } from "lib1/public"; import { Data2 } from "./data2"; +export class Data { + public dat?: Data2; public test() { + const result: ITest = { + title: "title" + } + return result; + } +}` + }; + const lib2Data2: File = { + path: `${currentDirectory}/lib2/data2.ts`, + content: `import { Data } from "./data"; +export class Data2 { + public dat?: Data; +}` + }; + verifyTransitiveExports(lib2Data, lib2Data2); + }); }); }); From c70cd38e98f98756186a640332c9bdcd8b91825a Mon Sep 17 00:00:00 2001 From: Alexander T Date: Thu, 25 Oct 2018 18:38:13 +0300 Subject: [PATCH 13/96] --downlevelIteration errors should mention using later targets --- src/compiler/checker.ts | 2 +- tests/baselines/reference/ES5For-ofTypeCheck14.errors.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4305227dab7..78726896a95 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -25209,7 +25209,7 @@ namespace ts { ? downlevelIteration ? Diagnostics.Type_0_is_not_an_array_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator : isIterable - ? Diagnostics.Type_0_is_not_an_array_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators + ? Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators : Diagnostics.Type_0_is_not_an_array_type : downlevelIteration ? Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator diff --git a/tests/baselines/reference/ES5For-ofTypeCheck14.errors.txt b/tests/baselines/reference/ES5For-ofTypeCheck14.errors.txt index 3a03491f110..316a7a63a3b 100644 --- a/tests/baselines/reference/ES5For-ofTypeCheck14.errors.txt +++ b/tests/baselines/reference/ES5For-ofTypeCheck14.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck14.ts(2,17): error TS2568: Type 'Set' is not an array type. Use compiler option '--downlevelIteration' to allow iterating of iterators. +tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck14.ts(2,17): error TS2568: Type 'Set' is not an array type. Either use the '--downlevelIteration' compiler option to allow iterating on iterators, or set the '--target' option to 'es2015' or above. ==== tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck14.ts (1 errors) ==== var union: string | Set for (const e of union) { } ~~~~~ -!!! error TS2568: Type 'Set' is not an array type. Use compiler option '--downlevelIteration' to allow iterating of iterators. \ No newline at end of file +!!! error TS2568: Type 'Set' is not an array type. Either use the '--downlevelIteration' compiler option to allow iterating on iterators, or set the '--target' option to 'es2015' or above. \ No newline at end of file From 7eff4b2eb0c66197e97e1e9b961d8335d4e7e317 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 18 Dec 2018 08:52:21 +0200 Subject: [PATCH 14/96] update baseline --- tests/baselines/reference/ES5For-ofTypeCheck14.errors.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/baselines/reference/ES5For-ofTypeCheck14.errors.txt b/tests/baselines/reference/ES5For-ofTypeCheck14.errors.txt index 316a7a63a3b..1fde67722db 100644 --- a/tests/baselines/reference/ES5For-ofTypeCheck14.errors.txt +++ b/tests/baselines/reference/ES5For-ofTypeCheck14.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck14.ts(2,17): error TS2568: Type 'Set' is not an array type. Either use the '--downlevelIteration' compiler option to allow iterating on iterators, or set the '--target' option to 'es2015' or above. +tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck14.ts(2,17): error TS2569: Type 'Set' is not an array type or a string type. Use compiler option '--downlevelIteration' to allow iterating of iterators. ==== tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck14.ts (1 errors) ==== var union: string | Set for (const e of union) { } ~~~~~ -!!! error TS2568: Type 'Set' is not an array type. Either use the '--downlevelIteration' compiler option to allow iterating on iterators, or set the '--target' option to 'es2015' or above. \ No newline at end of file +!!! error TS2569: Type 'Set' is not an array type or a string type. Use compiler option '--downlevelIteration' to allow iterating of iterators. \ No newline at end of file From 332c88e57db6a5450b2aae3ef0465d134daffdbc Mon Sep 17 00:00:00 2001 From: Alexander T Date: Tue, 18 Dec 2018 10:39:32 +0200 Subject: [PATCH 15/96] PR feedback: change error #2497 message --- src/compiler/checker.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f451c91046b..b70d5cf876b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2381,7 +2381,7 @@ namespace ts { ? "allowSyntheticDefaultImports" : "esModuleInterop"; - error(referencingLocation, Diagnostics.When_writing_ECMAScript_imports_callable_export_style_modules_can_only_be_imported_by_turning_on_the_0_flag_and_using_a_default_import, compilerOptionName); + error(referencingLocation, Diagnostics.This_module_can_only_be_imported_with_ECMAScript_imports_by_turning_on_the_0_flag_and_using_a_default_import, compilerOptionName); return symbol; } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 907940c4f6a..a27aa17efb9 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1768,7 +1768,7 @@ "category": "Error", "code": 2496 }, - "When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the '{0}' flag and using a default import.": { + "This module can only be imported with ECMAScript imports by turning on the '{0}' flag and using a default import.": { "category": "Error", "code": 2497 }, From 4e46f4b95a7773b290aa8c8e56a01d505d33a4b9 Mon Sep 17 00:00:00 2001 From: Alexander T Date: Tue, 18 Dec 2018 10:41:04 +0200 Subject: [PATCH 16/96] update baseline --- .../es6ExportEqualsInterop.errors.txt | 36 +++++++++---------- ...EqualsExportModuleCommonJsError.errors.txt | 4 +-- ...rtEqualsExportModuleEs2015Error.errors.txt | 4 +-- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/tests/baselines/reference/es6ExportEqualsInterop.errors.txt b/tests/baselines/reference/es6ExportEqualsInterop.errors.txt index bebe3f45940..986aae2245f 100644 --- a/tests/baselines/reference/es6ExportEqualsInterop.errors.txt +++ b/tests/baselines/reference/es6ExportEqualsInterop.errors.txt @@ -11,24 +11,24 @@ tests/cases/compiler/main.ts(33,8): error TS1192: Module '"function"' has no def tests/cases/compiler/main.ts(34,8): error TS1192: Module '"function-module"' has no default export. tests/cases/compiler/main.ts(35,8): error TS1192: Module '"class"' has no default export. tests/cases/compiler/main.ts(36,8): error TS1192: Module '"class-module"' has no default export. -tests/cases/compiler/main.ts(39,21): error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. -tests/cases/compiler/main.ts(45,21): error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. -tests/cases/compiler/main.ts(47,21): error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. +tests/cases/compiler/main.ts(39,21): error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. +tests/cases/compiler/main.ts(45,21): error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. +tests/cases/compiler/main.ts(47,21): error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. tests/cases/compiler/main.ts(50,1): error TS2693: 'y1' only refers to a type, but is being used as a value here. tests/cases/compiler/main.ts(56,4): error TS2339: Property 'a' does not exist on type '() => any'. tests/cases/compiler/main.ts(58,4): error TS2339: Property 'a' does not exist on type 'typeof Foo'. tests/cases/compiler/main.ts(62,10): error TS2305: Module '"interface"' has no exported member 'a'. -tests/cases/compiler/main.ts(62,25): error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. +tests/cases/compiler/main.ts(62,25): error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. tests/cases/compiler/main.ts(68,10): error TS2305: Module '"function"' has no exported member 'a'. -tests/cases/compiler/main.ts(68,25): error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. +tests/cases/compiler/main.ts(68,25): error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. tests/cases/compiler/main.ts(70,10): error TS2305: Module '"class"' has no exported member 'a'. -tests/cases/compiler/main.ts(70,25): error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. +tests/cases/compiler/main.ts(70,25): error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. tests/cases/compiler/main.ts(85,10): error TS2305: Module '"interface"' has no exported member 'a'. -tests/cases/compiler/main.ts(85,25): error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. +tests/cases/compiler/main.ts(85,25): error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. tests/cases/compiler/main.ts(91,10): error TS2305: Module '"function"' has no exported member 'a'. -tests/cases/compiler/main.ts(91,25): error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. +tests/cases/compiler/main.ts(91,25): error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. tests/cases/compiler/main.ts(93,10): error TS2305: Module '"class"' has no exported member 'a'. -tests/cases/compiler/main.ts(93,25): error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. +tests/cases/compiler/main.ts(93,25): error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. tests/cases/compiler/main.ts(97,15): error TS2498: Module '"interface"' uses 'export =' and cannot be used with 'export *'. tests/cases/compiler/main.ts(98,15): error TS2498: Module '"variable"' uses 'export =' and cannot be used with 'export *'. tests/cases/compiler/main.ts(99,15): error TS2498: Module '"interface-variable"' uses 'export =' and cannot be used with 'export *'. @@ -108,7 +108,7 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses // namespace import import * as y1 from "interface"; ~~~~~~~~~~~ -!!! error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. +!!! error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. import * as y2 from "variable"; import * as y3 from "interface-variable"; import * as y4 from "module"; @@ -116,11 +116,11 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses import * as y6 from "variable-module"; import * as y7 from "function"; ~~~~~~~~~~ -!!! error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. +!!! error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. import * as y8 from "function-module"; import * as y9 from "class"; ~~~~~~~ -!!! error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. +!!! error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. import * as y0 from "class-module"; y1.a; @@ -145,7 +145,7 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses ~ !!! error TS2305: Module '"interface"' has no exported member 'a'. ~~~~~~~~~~~ -!!! error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. +!!! error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. import { a as a2 } from "variable"; import { a as a3 } from "interface-variable"; import { a as a4 } from "module"; @@ -155,13 +155,13 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses ~ !!! error TS2305: Module '"function"' has no exported member 'a'. ~~~~~~~~~~ -!!! error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. +!!! error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. import { a as a8 } from "function-module"; import { a as a9 } from "class"; ~ !!! error TS2305: Module '"class"' has no exported member 'a'. ~~~~~~~ -!!! error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. +!!! error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. import { a as a0 } from "class-module"; a1; @@ -180,7 +180,7 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses ~ !!! error TS2305: Module '"interface"' has no exported member 'a'. ~~~~~~~~~~~ -!!! error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. +!!! error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. export { a as a2 } from "variable"; export { a as a3 } from "interface-variable"; export { a as a4 } from "module"; @@ -190,13 +190,13 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses ~ !!! error TS2305: Module '"function"' has no exported member 'a'. ~~~~~~~~~~ -!!! error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. +!!! error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. export { a as a8 } from "function-module"; export { a as a9 } from "class"; ~ !!! error TS2305: Module '"class"' has no exported member 'a'. ~~~~~~~ -!!! error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. +!!! error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. export { a as a0 } from "class-module"; // export-star diff --git a/tests/baselines/reference/es6ImportEqualsExportModuleCommonJsError.errors.txt b/tests/baselines/reference/es6ImportEqualsExportModuleCommonJsError.errors.txt index 96d2f55ed27..1c19b4c3104 100644 --- a/tests/baselines/reference/es6ImportEqualsExportModuleCommonJsError.errors.txt +++ b/tests/baselines/reference/es6ImportEqualsExportModuleCommonJsError.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/main.ts(1,20): error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. +tests/cases/compiler/main.ts(1,20): error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. ==== tests/cases/compiler/a.ts (0 errors) ==== @@ -8,7 +8,7 @@ tests/cases/compiler/main.ts(1,20): error TS2497: When writing ECMAScript import ==== tests/cases/compiler/main.ts (1 errors) ==== import * as a from "./a"; ~~~~~ -!!! error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'esModuleInterop' flag and using a default import. +!!! error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. a; diff --git a/tests/baselines/reference/es6ImportEqualsExportModuleEs2015Error.errors.txt b/tests/baselines/reference/es6ImportEqualsExportModuleEs2015Error.errors.txt index ee3e9cfff17..4aa467f8b6a 100644 --- a/tests/baselines/reference/es6ImportEqualsExportModuleEs2015Error.errors.txt +++ b/tests/baselines/reference/es6ImportEqualsExportModuleEs2015Error.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/a.ts(2,1): error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead. -tests/cases/compiler/main.ts(1,20): error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'allowSyntheticDefaultImports' flag and using a default import. +tests/cases/compiler/main.ts(1,20): error TS2497: This module can only be imported with ECMAScript imports by turning on the 'allowSyntheticDefaultImports' flag and using a default import. ==== tests/cases/compiler/a.ts (1 errors) ==== @@ -11,7 +11,7 @@ tests/cases/compiler/main.ts(1,20): error TS2497: When writing ECMAScript import ==== tests/cases/compiler/main.ts (1 errors) ==== import * as a from "./a"; ~~~~~ -!!! error TS2497: When writing ECMAScript imports, callable 'export ='-style modules can only be imported by turning on the 'allowSyntheticDefaultImports' flag and using a default import. +!!! error TS2497: This module can only be imported with ECMAScript imports by turning on the 'allowSyntheticDefaultImports' flag and using a default import. a; From 93acaac0875ca28bba5b1b3ab626ebf571c3d1e4 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 20 Dec 2018 07:17:42 -0800 Subject: [PATCH 17/96] Fix discriminant property check --- src/compiler/checker.ts | 46 +++++++++++++++++------------------------ src/compiler/types.ts | 20 ++++++++++-------- 2 files changed, 30 insertions(+), 36 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 23c5568f2e5..cf630f5e6fd 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7669,38 +7669,37 @@ namespace ts { return props[0]; } let declarations: Declaration[] | undefined; - let commonType: Type | undefined; + let firstType: Type | undefined; let nameType: Type | undefined; const propTypes: Type[] = []; - let first = true; - let commonValueDeclaration: Declaration | undefined; + let firstValueDeclaration: Declaration | undefined; let hasNonUniformValueDeclaration = false; for (const prop of props) { - if (!commonValueDeclaration) { - commonValueDeclaration = prop.valueDeclaration; + if (!firstValueDeclaration) { + firstValueDeclaration = prop.valueDeclaration; } - else if (prop.valueDeclaration !== commonValueDeclaration) { + else if (prop.valueDeclaration !== firstValueDeclaration) { hasNonUniformValueDeclaration = true; } declarations = addRange(declarations, prop.declarations); const type = getTypeOfSymbol(prop); - if (first) { - commonType = type; + if (!firstType) { + firstType = type; nameType = prop.nameType; - first = false; } - else { - if (type !== commonType) { - checkFlags |= CheckFlags.HasNonUniformType; - } + else if (type !== firstType) { + checkFlags |= CheckFlags.HasNonUniformType; + } + if (isLiteralType(type)) { + checkFlags |= CheckFlags.HasLiteralType; } propTypes.push(type); } addRange(propTypes, indexTypes); const result = createSymbol(SymbolFlags.Property | commonFlags, name, syntheticFlag | checkFlags); result.containingType = containingType; - if (!hasNonUniformValueDeclaration && commonValueDeclaration) { - result.valueDeclaration = commonValueDeclaration; + if (!hasNonUniformValueDeclaration && firstValueDeclaration) { + result.valueDeclaration = firstValueDeclaration; } result.declarations = declarations!; result.nameType = nameType; @@ -14814,17 +14813,8 @@ namespace ts { } function isDiscriminantType(type: Type): boolean { - if (type.flags & TypeFlags.Union) { - if (type.flags & (TypeFlags.Boolean | TypeFlags.EnumLiteral)) { - return true; - } - let combined = 0; - for (const t of (type).types) combined |= t.flags; - if (combined & TypeFlags.Unit && !(combined & TypeFlags.Instantiable)) { - return true; - } - } - return false; + return !!(type.flags & TypeFlags.Union && + (type.flags & (TypeFlags.Boolean | TypeFlags.EnumLiteral) || !isGenericIndexType(type))); } function isDiscriminantProperty(type: Type | undefined, name: __String) { @@ -14832,7 +14822,9 @@ namespace ts { const prop = getUnionOrIntersectionProperty(type, name); if (prop && getCheckFlags(prop) & CheckFlags.SyntheticProperty) { if ((prop).isDiscriminantProperty === undefined) { - (prop).isDiscriminantProperty = !!((prop).checkFlags & CheckFlags.HasNonUniformType) && isDiscriminantType(getTypeOfSymbol(prop)); + (prop).isDiscriminantProperty = + ((prop).checkFlags & CheckFlags.Discriminant) === CheckFlags.Discriminant && + isDiscriminantType(getTypeOfSymbol(prop)); } return !!(prop).isDiscriminantProperty; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index b70b4e4d3d0..6e2e480503a 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3677,15 +3677,17 @@ namespace ts { Readonly = 1 << 3, // Readonly transient symbol Partial = 1 << 4, // Synthetic property present in some but not all constituents HasNonUniformType = 1 << 5, // Synthetic property with non-uniform type in constituents - ContainsPublic = 1 << 6, // Synthetic property with public constituent(s) - ContainsProtected = 1 << 7, // Synthetic property with protected constituent(s) - ContainsPrivate = 1 << 8, // Synthetic property with private constituent(s) - ContainsStatic = 1 << 9, // Synthetic property with static constituent(s) - Late = 1 << 10, // Late-bound symbol for a computed property with a dynamic name - ReverseMapped = 1 << 11, // Property of reverse-inferred homomorphic mapped type - OptionalParameter = 1 << 12, // Optional parameter - RestParameter = 1 << 13, // Rest parameter - Synthetic = SyntheticProperty | SyntheticMethod + HasLiteralType = 1 << 6, // Synthetic property with at least one literal type in constituents + ContainsPublic = 1 << 7, // Synthetic property with public constituent(s) + ContainsProtected = 1 << 8, // Synthetic property with protected constituent(s) + ContainsPrivate = 1 << 9, // Synthetic property with private constituent(s) + ContainsStatic = 1 << 10, // Synthetic property with static constituent(s) + Late = 1 << 11, // Late-bound symbol for a computed property with a dynamic name + ReverseMapped = 1 << 12, // Property of reverse-inferred homomorphic mapped type + OptionalParameter = 1 << 13, // Optional parameter + RestParameter = 1 << 14, // Rest parameter + Synthetic = SyntheticProperty | SyntheticMethod, + Discriminant = HasNonUniformType | HasLiteralType } /* @internal */ From 3e93461fc84108bdcd8abafbcbf96b5c8bbcc284 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 20 Dec 2018 07:21:49 -0800 Subject: [PATCH 18/96] Add regression test --- .../compiler/discriminantPropertyCheck.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/cases/compiler/discriminantPropertyCheck.ts b/tests/cases/compiler/discriminantPropertyCheck.ts index 16fb847bdf0..a24fe07973b 100644 --- a/tests/cases/compiler/discriminantPropertyCheck.ts +++ b/tests/cases/compiler/discriminantPropertyCheck.ts @@ -99,3 +99,25 @@ function func2(inst: Instance) { } } } + +// Repro from #29106 + +const f = (_a: string, _b: string): void => {}; + +interface A { + a?: string; + b?: string; +} + +interface B { + a: string; + b: string; +} + +type U = A | B; + +const u: U = {} as any; + +u.a && u.b && f(u.a, u.b); + +u.b && u.a && f(u.a, u.b); From 017c11acaa0747481f978bb76a25c32315f3f5a7 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 20 Dec 2018 07:21:56 -0800 Subject: [PATCH 19/96] Accept new baselines --- .../discriminantPropertyCheck.errors.txt | 22 ++++++ .../reference/discriminantPropertyCheck.js | 27 ++++++++ .../discriminantPropertyCheck.symbols | 66 ++++++++++++++++++ .../reference/discriminantPropertyCheck.types | 68 +++++++++++++++++++ 4 files changed, 183 insertions(+) diff --git a/tests/baselines/reference/discriminantPropertyCheck.errors.txt b/tests/baselines/reference/discriminantPropertyCheck.errors.txt index a57e17ed81e..313116edde5 100644 --- a/tests/baselines/reference/discriminantPropertyCheck.errors.txt +++ b/tests/baselines/reference/discriminantPropertyCheck.errors.txt @@ -106,4 +106,26 @@ tests/cases/compiler/discriminantPropertyCheck.ts(65,9): error TS2532: Object is } } } + + // Repro from #29106 + + const f = (_a: string, _b: string): void => {}; + + interface A { + a?: string; + b?: string; + } + + interface B { + a: string; + b: string; + } + + type U = A | B; + + const u: U = {} as any; + + u.a && u.b && f(u.a, u.b); + + u.b && u.a && f(u.a, u.b); \ No newline at end of file diff --git a/tests/baselines/reference/discriminantPropertyCheck.js b/tests/baselines/reference/discriminantPropertyCheck.js index e58f28dc5a1..8b2c6f122bc 100644 --- a/tests/baselines/reference/discriminantPropertyCheck.js +++ b/tests/baselines/reference/discriminantPropertyCheck.js @@ -98,6 +98,28 @@ function func2(inst: Instance) { } } } + +// Repro from #29106 + +const f = (_a: string, _b: string): void => {}; + +interface A { + a?: string; + b?: string; +} + +interface B { + a: string; + b: string; +} + +type U = A | B; + +const u: U = {} as any; + +u.a && u.b && f(u.a, u.b); + +u.b && u.a && f(u.a, u.b); //// [discriminantPropertyCheck.js] @@ -161,3 +183,8 @@ function func2(inst) { } } } +// Repro from #29106 +var f = function (_a, _b) { }; +var u = {}; +u.a && u.b && f(u.a, u.b); +u.b && u.a && f(u.a, u.b); diff --git a/tests/baselines/reference/discriminantPropertyCheck.symbols b/tests/baselines/reference/discriminantPropertyCheck.symbols index 564cc55e3d3..78884eaf69f 100644 --- a/tests/baselines/reference/discriminantPropertyCheck.symbols +++ b/tests/baselines/reference/discriminantPropertyCheck.symbols @@ -311,3 +311,69 @@ function func2(inst: Instance) { } } +// Repro from #29106 + +const f = (_a: string, _b: string): void => {}; +>f : Symbol(f, Decl(discriminantPropertyCheck.ts, 102, 5)) +>_a : Symbol(_a, Decl(discriminantPropertyCheck.ts, 102, 11)) +>_b : Symbol(_b, Decl(discriminantPropertyCheck.ts, 102, 22)) + +interface A { +>A : Symbol(A, Decl(discriminantPropertyCheck.ts, 102, 47)) + + a?: string; +>a : Symbol(A.a, Decl(discriminantPropertyCheck.ts, 104, 13)) + + b?: string; +>b : Symbol(A.b, Decl(discriminantPropertyCheck.ts, 105, 13)) +} + +interface B { +>B : Symbol(B, Decl(discriminantPropertyCheck.ts, 107, 1)) + + a: string; +>a : Symbol(B.a, Decl(discriminantPropertyCheck.ts, 109, 13)) + + b: string; +>b : Symbol(B.b, Decl(discriminantPropertyCheck.ts, 110, 12)) +} + +type U = A | B; +>U : Symbol(U, Decl(discriminantPropertyCheck.ts, 112, 1)) +>A : Symbol(A, Decl(discriminantPropertyCheck.ts, 102, 47)) +>B : Symbol(B, Decl(discriminantPropertyCheck.ts, 107, 1)) + +const u: U = {} as any; +>u : Symbol(u, Decl(discriminantPropertyCheck.ts, 116, 5)) +>U : Symbol(U, Decl(discriminantPropertyCheck.ts, 112, 1)) + +u.a && u.b && f(u.a, u.b); +>u.a : Symbol(a, Decl(discriminantPropertyCheck.ts, 104, 13), Decl(discriminantPropertyCheck.ts, 109, 13)) +>u : Symbol(u, Decl(discriminantPropertyCheck.ts, 116, 5)) +>a : Symbol(a, Decl(discriminantPropertyCheck.ts, 104, 13), Decl(discriminantPropertyCheck.ts, 109, 13)) +>u.b : Symbol(b, Decl(discriminantPropertyCheck.ts, 105, 13), Decl(discriminantPropertyCheck.ts, 110, 12)) +>u : Symbol(u, Decl(discriminantPropertyCheck.ts, 116, 5)) +>b : Symbol(b, Decl(discriminantPropertyCheck.ts, 105, 13), Decl(discriminantPropertyCheck.ts, 110, 12)) +>f : Symbol(f, Decl(discriminantPropertyCheck.ts, 102, 5)) +>u.a : Symbol(a, Decl(discriminantPropertyCheck.ts, 104, 13), Decl(discriminantPropertyCheck.ts, 109, 13)) +>u : Symbol(u, Decl(discriminantPropertyCheck.ts, 116, 5)) +>a : Symbol(a, Decl(discriminantPropertyCheck.ts, 104, 13), Decl(discriminantPropertyCheck.ts, 109, 13)) +>u.b : Symbol(b, Decl(discriminantPropertyCheck.ts, 105, 13), Decl(discriminantPropertyCheck.ts, 110, 12)) +>u : Symbol(u, Decl(discriminantPropertyCheck.ts, 116, 5)) +>b : Symbol(b, Decl(discriminantPropertyCheck.ts, 105, 13), Decl(discriminantPropertyCheck.ts, 110, 12)) + +u.b && u.a && f(u.a, u.b); +>u.b : Symbol(b, Decl(discriminantPropertyCheck.ts, 105, 13), Decl(discriminantPropertyCheck.ts, 110, 12)) +>u : Symbol(u, Decl(discriminantPropertyCheck.ts, 116, 5)) +>b : Symbol(b, Decl(discriminantPropertyCheck.ts, 105, 13), Decl(discriminantPropertyCheck.ts, 110, 12)) +>u.a : Symbol(a, Decl(discriminantPropertyCheck.ts, 104, 13), Decl(discriminantPropertyCheck.ts, 109, 13)) +>u : Symbol(u, Decl(discriminantPropertyCheck.ts, 116, 5)) +>a : Symbol(a, Decl(discriminantPropertyCheck.ts, 104, 13), Decl(discriminantPropertyCheck.ts, 109, 13)) +>f : Symbol(f, Decl(discriminantPropertyCheck.ts, 102, 5)) +>u.a : Symbol(a, Decl(discriminantPropertyCheck.ts, 104, 13), Decl(discriminantPropertyCheck.ts, 109, 13)) +>u : Symbol(u, Decl(discriminantPropertyCheck.ts, 116, 5)) +>a : Symbol(a, Decl(discriminantPropertyCheck.ts, 104, 13), Decl(discriminantPropertyCheck.ts, 109, 13)) +>u.b : Symbol(b, Decl(discriminantPropertyCheck.ts, 105, 13), Decl(discriminantPropertyCheck.ts, 110, 12)) +>u : Symbol(u, Decl(discriminantPropertyCheck.ts, 116, 5)) +>b : Symbol(b, Decl(discriminantPropertyCheck.ts, 105, 13), Decl(discriminantPropertyCheck.ts, 110, 12)) + diff --git a/tests/baselines/reference/discriminantPropertyCheck.types b/tests/baselines/reference/discriminantPropertyCheck.types index 4f34ceafc43..c243ef5e798 100644 --- a/tests/baselines/reference/discriminantPropertyCheck.types +++ b/tests/baselines/reference/discriminantPropertyCheck.types @@ -310,3 +310,71 @@ function func2(inst: Instance) { } } +// Repro from #29106 + +const f = (_a: string, _b: string): void => {}; +>f : (_a: string, _b: string) => void +>(_a: string, _b: string): void => {} : (_a: string, _b: string) => void +>_a : string +>_b : string + +interface A { + a?: string; +>a : string | undefined + + b?: string; +>b : string | undefined +} + +interface B { + a: string; +>a : string + + b: string; +>b : string +} + +type U = A | B; +>U : U + +const u: U = {} as any; +>u : U +>{} as any : any +>{} : {} + +u.a && u.b && f(u.a, u.b); +>u.a && u.b && f(u.a, u.b) : void | "" | undefined +>u.a && u.b : string | undefined +>u.a : string | undefined +>u : U +>a : string | undefined +>u.b : string | undefined +>u : U +>b : string | undefined +>f(u.a, u.b) : void +>f : (_a: string, _b: string) => void +>u.a : string +>u : U +>a : string +>u.b : string +>u : U +>b : string + +u.b && u.a && f(u.a, u.b); +>u.b && u.a && f(u.a, u.b) : void | "" | undefined +>u.b && u.a : string | undefined +>u.b : string | undefined +>u : U +>b : string | undefined +>u.a : string | undefined +>u : U +>a : string | undefined +>f(u.a, u.b) : void +>f : (_a: string, _b: string) => void +>u.a : string +>u : U +>a : string +>u.b : string +>u : U +>b : string + From 565ab7a9710dd0d83b0b044e92ec3a564a9ff8d5 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 21 Dec 2018 12:50:53 -0800 Subject: [PATCH 20/96] Properly compute lower bound of key type in a mapped type --- src/compiler/checker.ts | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 23c5568f2e5..ce35ddd522d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7084,6 +7084,39 @@ namespace ts { setStructuredTypeMembers(type, members, emptyArray, emptyArray, stringIndexInfo, undefined); } + // Return the lower bound of the key type in a mapped type. Intuitively, the lower + // bound includes those keys that are known to always be present, for example because + // because of constraints on type parameters (e.g. 'keyof T' for a constrained T). + function getLowerBoundOfKeyType(type: Type): Type { + if (type.flags & (TypeFlags.Any | TypeFlags.Primitive)) { + return type; + } + if (type.flags & TypeFlags.Index) { + return getIndexType(getApparentType((type).type)); + } + if (type.flags & TypeFlags.Conditional) { + return getLowerBoundOfConditionalType(type); + } + if (type.flags & TypeFlags.Union) { + return getUnionType(sameMap((type).types, getLowerBoundOfKeyType)); + } + if (type.flags & TypeFlags.Intersection) { + return getIntersectionType(sameMap((type).types, getLowerBoundOfKeyType)); + } + return neverType; + } + + function getLowerBoundOfConditionalType(type: ConditionalType) { + if (type.root.isDistributive) { + const constraint = getLowerBoundOfKeyType(type.checkType); + if (constraint !== type.checkType) { + const mapper = makeUnaryTypeMapper(type.root.checkType, constraint); + return getConditionalTypeInstantiation(type, combineTypeMappers(mapper, type.mapper)); + } + } + return type; + } + /** Resolve the members of a mapped type { [P in K]: T } */ function resolveMappedTypeMembers(type: MappedType) { const members: SymbolTable = createSymbolTable(); @@ -7112,10 +7145,7 @@ namespace ts { } } else { - // If the key type is a 'keyof X', obtain 'keyof C' where C is the base constraint of X. - // Then iterate over the constituents of the key type. - const iterationType = constraintType.flags & TypeFlags.Index ? getIndexType(getApparentType((constraintType).type)) : constraintType; - forEachType(iterationType, addMemberForKeyType); + forEachType(getLowerBoundOfKeyType(constraintType), addMemberForKeyType); } setStructuredTypeMembers(type, members, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo); From 7ad2661625633f932c76eaca6daca00b0835ce65 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 21 Dec 2018 12:51:01 -0800 Subject: [PATCH 21/96] Add tests --- .../types/mapped/mappedTypeConstraints.ts | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/cases/conformance/types/mapped/mappedTypeConstraints.ts diff --git a/tests/cases/conformance/types/mapped/mappedTypeConstraints.ts b/tests/cases/conformance/types/mapped/mappedTypeConstraints.ts new file mode 100644 index 00000000000..3710f2b9bef --- /dev/null +++ b/tests/cases/conformance/types/mapped/mappedTypeConstraints.ts @@ -0,0 +1,36 @@ +// @strict: true + +function f0(obj: Pick>) { + obj.b; +} + +function f1(obj: Pick>) { + obj.b; +} + +function f2(obj: Pick) { + obj.b; +} + +function f3(obj: Pick) { + obj.a; + obj.b; + obj.c; +} + +function f4(obj: Record | 'c', string>) { + obj.a; + obj.c; +} + +// Repro from #28821 + +type TargetProps = { + foo: string, + bar: string +}; + +const modifier = (targetProps: T) => { + let {bar, ...rest} = targetProps; + rest.foo; +}; From 194496f5ade09001e1973711d6abaa08a5c09599 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 21 Dec 2018 12:51:20 -0800 Subject: [PATCH 22/96] Accept new baselines --- .../reference/mappedTypeConstraints.js | 70 +++++++++ .../reference/mappedTypeConstraints.symbols | 140 ++++++++++++++++++ .../reference/mappedTypeConstraints.types | 110 ++++++++++++++ 3 files changed, 320 insertions(+) create mode 100644 tests/baselines/reference/mappedTypeConstraints.js create mode 100644 tests/baselines/reference/mappedTypeConstraints.symbols create mode 100644 tests/baselines/reference/mappedTypeConstraints.types diff --git a/tests/baselines/reference/mappedTypeConstraints.js b/tests/baselines/reference/mappedTypeConstraints.js new file mode 100644 index 00000000000..0565af1c6ec --- /dev/null +++ b/tests/baselines/reference/mappedTypeConstraints.js @@ -0,0 +1,70 @@ +//// [mappedTypeConstraints.ts] +function f0(obj: Pick>) { + obj.b; +} + +function f1(obj: Pick>) { + obj.b; +} + +function f2(obj: Pick) { + obj.b; +} + +function f3(obj: Pick) { + obj.a; + obj.b; + obj.c; +} + +function f4(obj: Record | 'c', string>) { + obj.a; + obj.c; +} + +// Repro from #28821 + +type TargetProps = { + foo: string, + bar: string +}; + +const modifier = (targetProps: T) => { + let {bar, ...rest} = targetProps; + rest.foo; +}; + + +//// [mappedTypeConstraints.js] +"use strict"; +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) + t[p[i]] = s[p[i]]; + return t; +}; +function f0(obj) { + obj.b; +} +function f1(obj) { + obj.b; +} +function f2(obj) { + obj.b; +} +function f3(obj) { + obj.a; + obj.b; + obj.c; +} +function f4(obj) { + obj.a; + obj.c; +} +var modifier = function (targetProps) { + var bar = targetProps.bar, rest = __rest(targetProps, ["bar"]); + rest.foo; +}; diff --git a/tests/baselines/reference/mappedTypeConstraints.symbols b/tests/baselines/reference/mappedTypeConstraints.symbols new file mode 100644 index 00000000000..3601ffc3de8 --- /dev/null +++ b/tests/baselines/reference/mappedTypeConstraints.symbols @@ -0,0 +1,140 @@ +=== tests/cases/conformance/types/mapped/mappedTypeConstraints.ts === +function f0(obj: Pick>) { +>f0 : Symbol(f0, Decl(mappedTypeConstraints.ts, 0, 0)) +>T : Symbol(T, Decl(mappedTypeConstraints.ts, 0, 12)) +>a : Symbol(a, Decl(mappedTypeConstraints.ts, 0, 23)) +>b : Symbol(b, Decl(mappedTypeConstraints.ts, 0, 34)) +>obj : Symbol(obj, Decl(mappedTypeConstraints.ts, 0, 48)) +>Pick : Symbol(Pick, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(mappedTypeConstraints.ts, 0, 12)) +>Extract : Symbol(Extract, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(mappedTypeConstraints.ts, 0, 12)) + + obj.b; +>obj.b : Symbol(b, Decl(mappedTypeConstraints.ts, 0, 34)) +>obj : Symbol(obj, Decl(mappedTypeConstraints.ts, 0, 48)) +>b : Symbol(b, Decl(mappedTypeConstraints.ts, 0, 34)) +} + +function f1(obj: Pick>) { +>f1 : Symbol(f1, Decl(mappedTypeConstraints.ts, 2, 1)) +>T : Symbol(T, Decl(mappedTypeConstraints.ts, 4, 12)) +>a : Symbol(a, Decl(mappedTypeConstraints.ts, 4, 23)) +>b : Symbol(b, Decl(mappedTypeConstraints.ts, 4, 34)) +>obj : Symbol(obj, Decl(mappedTypeConstraints.ts, 4, 48)) +>Pick : Symbol(Pick, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(mappedTypeConstraints.ts, 4, 12)) +>Exclude : Symbol(Exclude, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(mappedTypeConstraints.ts, 4, 12)) + + obj.b; +>obj.b : Symbol(b, Decl(mappedTypeConstraints.ts, 4, 34)) +>obj : Symbol(obj, Decl(mappedTypeConstraints.ts, 4, 48)) +>b : Symbol(b, Decl(mappedTypeConstraints.ts, 4, 34)) +} + +function f2(obj: Pick) { +>f2 : Symbol(f2, Decl(mappedTypeConstraints.ts, 6, 1)) +>T : Symbol(T, Decl(mappedTypeConstraints.ts, 8, 12)) +>a : Symbol(a, Decl(mappedTypeConstraints.ts, 8, 23)) +>b : Symbol(b, Decl(mappedTypeConstraints.ts, 8, 34)) +>U : Symbol(U, Decl(mappedTypeConstraints.ts, 8, 47)) +>b : Symbol(b, Decl(mappedTypeConstraints.ts, 8, 59)) +>c : Symbol(c, Decl(mappedTypeConstraints.ts, 8, 70)) +>obj : Symbol(obj, Decl(mappedTypeConstraints.ts, 8, 84)) +>Pick : Symbol(Pick, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(mappedTypeConstraints.ts, 8, 12)) +>U : Symbol(U, Decl(mappedTypeConstraints.ts, 8, 47)) +>T : Symbol(T, Decl(mappedTypeConstraints.ts, 8, 12)) +>U : Symbol(U, Decl(mappedTypeConstraints.ts, 8, 47)) + + obj.b; +>obj.b : Symbol(b, Decl(mappedTypeConstraints.ts, 8, 34), Decl(mappedTypeConstraints.ts, 8, 59)) +>obj : Symbol(obj, Decl(mappedTypeConstraints.ts, 8, 84)) +>b : Symbol(b, Decl(mappedTypeConstraints.ts, 8, 34), Decl(mappedTypeConstraints.ts, 8, 59)) +} + +function f3(obj: Pick) { +>f3 : Symbol(f3, Decl(mappedTypeConstraints.ts, 10, 1)) +>T : Symbol(T, Decl(mappedTypeConstraints.ts, 12, 12)) +>a : Symbol(a, Decl(mappedTypeConstraints.ts, 12, 23)) +>b : Symbol(b, Decl(mappedTypeConstraints.ts, 12, 34)) +>U : Symbol(U, Decl(mappedTypeConstraints.ts, 12, 47)) +>b : Symbol(b, Decl(mappedTypeConstraints.ts, 12, 59)) +>c : Symbol(c, Decl(mappedTypeConstraints.ts, 12, 70)) +>obj : Symbol(obj, Decl(mappedTypeConstraints.ts, 12, 84)) +>Pick : Symbol(Pick, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(mappedTypeConstraints.ts, 12, 12)) +>U : Symbol(U, Decl(mappedTypeConstraints.ts, 12, 47)) +>T : Symbol(T, Decl(mappedTypeConstraints.ts, 12, 12)) +>U : Symbol(U, Decl(mappedTypeConstraints.ts, 12, 47)) + + obj.a; +>obj.a : Symbol(a, Decl(mappedTypeConstraints.ts, 12, 23)) +>obj : Symbol(obj, Decl(mappedTypeConstraints.ts, 12, 84)) +>a : Symbol(a, Decl(mappedTypeConstraints.ts, 12, 23)) + + obj.b; +>obj.b : Symbol(b, Decl(mappedTypeConstraints.ts, 12, 34), Decl(mappedTypeConstraints.ts, 12, 59)) +>obj : Symbol(obj, Decl(mappedTypeConstraints.ts, 12, 84)) +>b : Symbol(b, Decl(mappedTypeConstraints.ts, 12, 34), Decl(mappedTypeConstraints.ts, 12, 59)) + + obj.c; +>obj.c : Symbol(c, Decl(mappedTypeConstraints.ts, 12, 70)) +>obj : Symbol(obj, Decl(mappedTypeConstraints.ts, 12, 84)) +>c : Symbol(c, Decl(mappedTypeConstraints.ts, 12, 70)) +} + +function f4(obj: Record | 'c', string>) { +>f4 : Symbol(f4, Decl(mappedTypeConstraints.ts, 16, 1)) +>T : Symbol(T, Decl(mappedTypeConstraints.ts, 18, 12)) +>a : Symbol(a, Decl(mappedTypeConstraints.ts, 18, 23)) +>b : Symbol(b, Decl(mappedTypeConstraints.ts, 18, 34)) +>obj : Symbol(obj, Decl(mappedTypeConstraints.ts, 18, 48)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) +>Exclude : Symbol(Exclude, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(mappedTypeConstraints.ts, 18, 12)) + + obj.a; +>obj.a : Symbol(a) +>obj : Symbol(obj, Decl(mappedTypeConstraints.ts, 18, 48)) +>a : Symbol(a) + + obj.c; +>obj.c : Symbol(c) +>obj : Symbol(obj, Decl(mappedTypeConstraints.ts, 18, 48)) +>c : Symbol(c) +} + +// Repro from #28821 + +type TargetProps = { +>TargetProps : Symbol(TargetProps, Decl(mappedTypeConstraints.ts, 21, 1)) + + foo: string, +>foo : Symbol(foo, Decl(mappedTypeConstraints.ts, 25, 20)) + + bar: string +>bar : Symbol(bar, Decl(mappedTypeConstraints.ts, 26, 16)) + +}; + +const modifier = (targetProps: T) => { +>modifier : Symbol(modifier, Decl(mappedTypeConstraints.ts, 30, 5)) +>T : Symbol(T, Decl(mappedTypeConstraints.ts, 30, 18)) +>TargetProps : Symbol(TargetProps, Decl(mappedTypeConstraints.ts, 21, 1)) +>targetProps : Symbol(targetProps, Decl(mappedTypeConstraints.ts, 30, 41)) +>T : Symbol(T, Decl(mappedTypeConstraints.ts, 30, 18)) + + let {bar, ...rest} = targetProps; +>bar : Symbol(bar, Decl(mappedTypeConstraints.ts, 31, 9)) +>rest : Symbol(rest, Decl(mappedTypeConstraints.ts, 31, 13)) +>targetProps : Symbol(targetProps, Decl(mappedTypeConstraints.ts, 30, 41)) + + rest.foo; +>rest.foo : Symbol(foo, Decl(mappedTypeConstraints.ts, 25, 20)) +>rest : Symbol(rest, Decl(mappedTypeConstraints.ts, 31, 13)) +>foo : Symbol(foo, Decl(mappedTypeConstraints.ts, 25, 20)) + +}; + diff --git a/tests/baselines/reference/mappedTypeConstraints.types b/tests/baselines/reference/mappedTypeConstraints.types new file mode 100644 index 00000000000..3e42e2a2e98 --- /dev/null +++ b/tests/baselines/reference/mappedTypeConstraints.types @@ -0,0 +1,110 @@ +=== tests/cases/conformance/types/mapped/mappedTypeConstraints.ts === +function f0(obj: Pick>) { +>f0 : (obj: Pick>) => void +>a : string +>b : string +>obj : Pick> + + obj.b; +>obj.b : T["b"] +>obj : Pick> +>b : T["b"] +} + +function f1(obj: Pick>) { +>f1 : (obj: Pick>) => void +>a : string +>b : string +>obj : Pick> + + obj.b; +>obj.b : T["b"] +>obj : Pick> +>b : T["b"] +} + +function f2(obj: Pick) { +>f2 : (obj: Pick) => void +>a : string +>b : string +>b : string +>c : string +>obj : Pick + + obj.b; +>obj.b : (T | U)["b"] +>obj : Pick +>b : (T | U)["b"] +} + +function f3(obj: Pick) { +>f3 : (obj: Pick) => void +>a : string +>b : string +>b : string +>c : string +>obj : Pick + + obj.a; +>obj.a : (T & U)["a"] +>obj : Pick +>a : (T & U)["a"] + + obj.b; +>obj.b : (T & U)["b"] +>obj : Pick +>b : (T & U)["b"] + + obj.c; +>obj.c : (T & U)["c"] +>obj : Pick +>c : (T & U)["c"] +} + +function f4(obj: Record | 'c', string>) { +>f4 : (obj: Record<"c" | Exclude, string>) => void +>a : string +>b : string +>obj : Record<"c" | Exclude, string> + + obj.a; +>obj.a : string +>obj : Record<"c" | Exclude, string> +>a : string + + obj.c; +>obj.c : string +>obj : Record<"c" | Exclude, string> +>c : string +} + +// Repro from #28821 + +type TargetProps = { +>TargetProps : TargetProps + + foo: string, +>foo : string + + bar: string +>bar : string + +}; + +const modifier = (targetProps: T) => { +>modifier : (targetProps: T) => void +>(targetProps: T) => { let {bar, ...rest} = targetProps; rest.foo;} : (targetProps: T) => void +>targetProps : T + + let {bar, ...rest} = targetProps; +>bar : string +>rest : Pick> +>targetProps : T + + rest.foo; +>rest.foo : T["foo"] +>rest : Pick> +>foo : T["foo"] + +}; + From 7c93affd7dc0efc508362d335d50bf9626808a46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=96=87=E7=92=90?= Date: Tue, 25 Dec 2018 17:30:04 +0800 Subject: [PATCH 23/96] fix typeof completions broken --- src/compiler/checker.ts | 4 ++-- src/compiler/types.ts | 2 +- src/services/completions.ts | 2 +- .../fourslash/completionTypeofExpressions.ts | 15 +++++++++++++++ 4 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 tests/cases/fourslash/completionTypeofExpressions.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 23c5568f2e5..e570b44313e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -19263,8 +19263,8 @@ namespace ts { } } - function isValidPropertyAccessForCompletions(node: PropertyAccessExpression | ImportTypeNode, type: Type, property: Symbol): boolean { - return isValidPropertyAccessWithType(node, node.kind !== SyntaxKind.ImportType && node.expression.kind === SyntaxKind.SuperKeyword, property.escapedName, type) + function isValidPropertyAccessForCompletions(node: PropertyAccessExpression | ImportTypeNode | QualifiedName, type: Type, property: Symbol): boolean { + return isValidPropertyAccessWithType(node, node.kind === SyntaxKind.PropertyAccessExpression && node.expression.kind === SyntaxKind.SuperKeyword, property.escapedName, type) && (!(property.flags & SymbolFlags.Method) || isValidMethodAccess(property, type)); } function isValidMethodAccess(method: Symbol, actualThisType: Type): boolean { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index b70b4e4d3d0..0a2ab39ac92 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3108,7 +3108,7 @@ namespace ts { getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): string | number | undefined; isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName | ImportTypeNode, propertyName: string): boolean; /** Exclude accesses to private properties or methods with a `this` parameter that `type` doesn't satisfy. */ - /* @internal */ isValidPropertyAccessForCompletions(node: PropertyAccessExpression | ImportTypeNode, type: Type, property: Symbol): boolean; + /* @internal */ isValidPropertyAccessForCompletions(node: PropertyAccessExpression | ImportTypeNode | QualifiedName, type: Type, property: Symbol): boolean; /** Follow all aliases to get the original symbol. */ getAliasedSymbol(symbol: Symbol): Symbol; /** Follow a *single* alias to get the immediately aliased symbol. */ diff --git a/src/services/completions.ts b/src/services/completions.ts index 43f00c58acf..bbcee4dd47e 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -913,7 +913,7 @@ namespace ts.Completions { } else { for (const symbol of type.getApparentProperties()) { - if (typeChecker.isValidPropertyAccessForCompletions(node.kind === SyntaxKind.ImportType ? node : node.parent, type, symbol)) { + if (typeChecker.isValidPropertyAccessForCompletions(node.kind === SyntaxKind.ImportType ? node : node.parent, type, symbol)) { addPropertySymbol(symbol); } } diff --git a/tests/cases/fourslash/completionTypeofExpressions.ts b/tests/cases/fourslash/completionTypeofExpressions.ts new file mode 100644 index 00000000000..407fd8d7678 --- /dev/null +++ b/tests/cases/fourslash/completionTypeofExpressions.ts @@ -0,0 +1,15 @@ +/// + +//// const x = "str"; +//// function test(arg: typeof x./*1*/) {} +//// function test1(arg: typeof (x./*2*/)) {} + +verify.completions({ + marker: "1", + includes: ['length'] +}); + +verify.completions({ + marker: "2", + includes: ['length'] +}); From 3f7a9a906b91660afd655976064ea4ac4b1f3294 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 27 Dec 2018 13:45:13 -1000 Subject: [PATCH 24/96] Type parameter defaults can only reference previously declared type parameters --- src/compiler/checker.ts | 32 ++++++++++++++++++++-------- src/compiler/diagnosticMessages.json | 4 ++++ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 23c5568f2e5..c63a5dce46f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7928,22 +7928,17 @@ namespace ts { const numTypeArguments = length(typeArguments); if (isJavaScriptImplicitAny || (numTypeArguments >= minTypeArgumentCount && numTypeArguments <= numTypeParameters)) { const result = typeArguments ? typeArguments.slice() : []; - - // Map an unsatisfied type parameter with a default type. - // If a type parameter does not have a default type, or if the default type - // is a forward reference, the empty object type is used. - const baseDefaultType = getDefaultTypeArgumentType(isJavaScriptImplicitAny); - const circularityMapper = createTypeMapper(typeParameters!, map(typeParameters!, () => baseDefaultType)); + // Map invalid forward references in default types to the error type for (let i = numTypeArguments; i < numTypeParameters; i++) { - result[i] = instantiateType(getConstraintFromTypeParameter(typeParameters![i]) || baseDefaultType, circularityMapper); + result[i] = errorType; } + const baseDefaultType = getDefaultTypeArgumentType(isJavaScriptImplicitAny); for (let i = numTypeArguments; i < numTypeParameters; i++) { - const mapper = createTypeMapper(typeParameters!, result); let defaultType = getDefaultFromTypeParameter(typeParameters![i]); if (isJavaScriptImplicitAny && defaultType && isTypeIdenticalTo(defaultType, emptyObjectType)) { defaultType = anyType; } - result[i] = defaultType ? instantiateType(defaultType, mapper) : baseDefaultType; + result[i] = defaultType ? instantiateType(defaultType, createTypeMapper(typeParameters!, result)) : baseDefaultType; } result.length = typeParameters!.length; return result; @@ -26465,6 +26460,7 @@ namespace ts { if (produceDiagnostics) { if (node.default) { seenDefault = true; + checkTypeParametersNotReferenced(node.default, typeParameterDeclarations, i); } else if (seenDefault) { error(node, Diagnostics.Required_type_parameters_may_not_follow_optional_type_parameters); @@ -26479,6 +26475,24 @@ namespace ts { } } + /** Check that type parameter defaults only reference previously declared type parameters */ + function checkTypeParametersNotReferenced(root: TypeNode, typeParameters: ReadonlyArray, index: number) { + visit(root); + function visit(node: Node) { + if (node.kind === SyntaxKind.TypeReference) { + const type = getTypeFromTypeReference(node); + if (type.flags & TypeFlags.TypeParameter) { + for (let i = index; i < typeParameters.length; i++) { + if (type.symbol === getSymbolOfNode(typeParameters[i])) { + error(node, Diagnostics.Type_parameter_defaults_can_only_reference_previously_declared_type_parameters); + } + } + } + } + forEachChild(node, visit); + } + } + /** Check that type parameter lists are identical across multiple declarations */ function checkTypeParameterListsIdentical(symbol: Symbol) { if (symbol.declarations.length === 1) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index b0dfb85ce6d..57f4c4c5611 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2537,6 +2537,10 @@ "category": "Error", "code": 2743 }, + "Type parameter defaults can only reference previously declared type parameters.": { + "category": "Error", + "code": 2744 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", From 5e1d490e589d8f06c1dd9e9bd079db0c50bddc28 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 27 Dec 2018 14:00:00 -1000 Subject: [PATCH 25/96] Accept new baselines --- .../reference/genericDefaults.errors.txt | 528 ++++++++++++++++++ tests/baselines/reference/genericDefaults.js | 4 +- .../baselines/reference/genericDefaults.types | 54 +- .../subclassThisTypeAssignable.errors.txt | 34 ++ .../subclassThisTypeAssignable.types | 4 +- ...UsesConstraintOnCircularDefault.errors.txt | 15 +- ...faultUsesConstraintOnCircularDefault.types | 4 +- 7 files changed, 602 insertions(+), 41 deletions(-) create mode 100644 tests/baselines/reference/genericDefaults.errors.txt create mode 100644 tests/baselines/reference/subclassThisTypeAssignable.errors.txt diff --git a/tests/baselines/reference/genericDefaults.errors.txt b/tests/baselines/reference/genericDefaults.errors.txt new file mode 100644 index 00000000000..0c7d9ccb21d --- /dev/null +++ b/tests/baselines/reference/genericDefaults.errors.txt @@ -0,0 +1,528 @@ +tests/cases/compiler/genericDefaults.ts(44,26): error TS2744: Type parameter defaults can only reference previously declared type parameters. +tests/cases/compiler/genericDefaults.ts(237,26): error TS2744: Type parameter defaults can only reference previously declared type parameters. +tests/cases/compiler/genericDefaults.ts(254,29): error TS2744: Type parameter defaults can only reference previously declared type parameters. +tests/cases/compiler/genericDefaults.ts(277,26): error TS2744: Type parameter defaults can only reference previously declared type parameters. +tests/cases/compiler/genericDefaults.ts(292,29): error TS2744: Type parameter defaults can only reference previously declared type parameters. +tests/cases/compiler/genericDefaults.ts(314,26): error TS2744: Type parameter defaults can only reference previously declared type parameters. +tests/cases/compiler/genericDefaults.ts(332,29): error TS2744: Type parameter defaults can only reference previously declared type parameters. +tests/cases/compiler/genericDefaults.ts(357,26): error TS2744: Type parameter defaults can only reference previously declared type parameters. +tests/cases/compiler/genericDefaults.ts(375,29): error TS2744: Type parameter defaults can only reference previously declared type parameters. +tests/cases/compiler/genericDefaults.ts(423,19): error TS2744: Type parameter defaults can only reference previously declared type parameters. +tests/cases/compiler/genericDefaults.ts(427,19): error TS2744: Type parameter defaults can only reference previously declared type parameters. + + +==== tests/cases/compiler/genericDefaults.ts (11 errors) ==== + interface A { a: number; } + interface B { b: number; } + interface C { c: number; } + interface D { d: number; } + interface AB { a: number; b: number; } + interface BC { b: number; c: number; } + + declare const a: A; + declare const b: B; + declare const c: C; + declare const d: D; + declare const ab: AB; + declare const bc: BC; + declare const x: any; + + // function without type parameters + declare function f00(a?: A): A; + // no inference + f00(); + f00(a); + + // function with a type parameter without a default + declare function f01(a?: T): T; + // inference + f01(); + f01(a); + // no inference, fully supplied + f01(); + f01(a); + + // function with a type paramter with a default + declare function f02(a?: T): T; + // inference + f02(); + f02(a); + f02(b); + // no inference, fully supplied + f02(); + f02(a); + f02(); + f02(b); + + // function with a type parameter with a default that refers to itself + declare function f03(a?: T): T; + ~ +!!! error TS2744: Type parameter defaults can only reference previously declared type parameters. + // inference + f03(); + f03(a); + f03(b); + // no inference, fully supplied + f03(); + f03(a); + f03(); + f03(b); + + // function with a type paramter without a default and a type parameter with a default + declare function f04(a?: T, b?: U): [T, U]; + // inference + f04(); + f04(a); + f04(a, b); + f04(a, c); + // no inference, partially supplied + f04(); + f04(a); + f04(a, b); + // no inference, fully supplied + f04(); + f04(a); + f04(a, b); + f04(); + f04(a); + f04(a, c); + + // function with a type parameter without a default and a type parameter with a default that refers to an earlier type parameter + declare function f05(a?: T, b?: U): [T, U]; + // inference + f05(); + f05(a); + f05(a, a); + f05(a, b); + // no inference, partially supplied + f05(); + f05(a); + f05(a, a); + // no inference, fully supplied + f05(); + f05(a); + f05(a, b); + + // function with a type parameter with a default that refers to an earlier type parameter with a default + declare function f06(a?: T, b?: U): [T, U]; + // inference + f06(); + f06(a); + f06(a, a); + f06(a, b); + f06(b, a); + f06(b, b); + // no inference, partially supplied + f06(); + f06(a); + f06(a, a); + f06(); + f06(b); + f06(b, b); + // no inference, fully supplied + f06(); + f06(a); + f06(a, b); + f06(); + f06(b); + f06(b, c); + + // function with a type parameter without a default and a type parameter with a default that refers to an earlier type parameter with a default + declare function f07(a?: T, b?: U, c?: V): [T, U, V]; + // inference + f07(); + f07(a, b); + f07(a, c); + f07(a, b, b); + f07(a, b, c); + f07(a, c, b); + f07(a, c, c); + // no inference, partially supplied + f07(); + f07(a); + f07(a, b); + f07(a, b, b); + f07(); + f07(a); + f07(a, b); + f07(a, b, b); + f07(); + f07(a); + f07(a, c); + f07(a, c, c); + // no inference, fully supplied + f07(); + f07(a); + f07(a, b); + f07(a, b, c); + f07(); + f07(a); + f07(a, c); + f07(a, c, d); + + // function with a type parameter with a default that refers to an earlier type parameter with a constraint + declare function f08(a?: T, b?: U): [T, U]; + // inference + f08(); + f08(a); + f08(a, a); + f08(a, b); + // no inference, partially supplied + f08(); + f08(a); + f08(a, a); + // no inference, fully supplied + f08(); + f08(a); + f08(a, b); + + // function with a type parameter with a constraint and a default that refers to an earlier type parameter + declare function f09(a?: T, b?: U): [T, U]; + // inference + f09(); + f09(a); + f09(a, a); + f09(a, ab); + // no inference, partially supplied + f09(); + f09(a); + f09(a, a); + f09(a, ab); + // no inference, fully supplied + f09(); + f09(a); + f09(a, ab); + + // function with a type parameter with a constraint and a default that refers to an earlier type parameter with a constraint + declare function f10(a?: T, b?: U): [T, U]; + // inference + f10(); + f10(a); + f10(a, a); + f10(a, ab); + // no inference, partially supplied + f10(); + f10(a); + f10(a, a); + f10(a, ab); + // no inference, fully supplied + f10(); + f10(a); + f10(a, a); + f10(a, ab); + f10(); + f10(a); + f10(a, ab); + + // function with a type parameter with a default that refers to an earier type parameter in a union + declare function f11(a?: T, b?: U): [T, U]; + // inference + f11(); + f11(a); + f11(a, a); + f11(a, b); + f11(a, c); + // no inference, partially supplied + f11(); + f11(a); + f11(a, a); + f11(a, b); + // no inference, fully supplied + f11(); + f11(a); + f11(a, c); + + // function with a type parameter with a default that refers to an earlier type parameter in an intersection + declare function f12(a?: T, b?: U): [T, U]; + // inference + f12(); + f12(a); + f12(a, a); + f12(a, b); + f12(a, c); + // no inference, partially supplied + f12(); + f12(a); + f12(a, ab); + // no inference, fully supplied + f12(); + f12(a); + f12(a, c); + + // function with a type parameter with a default that refers to a later type parameter with a default + declare function f13(a?: T, b?: U): [T, U]; + ~ +!!! error TS2744: Type parameter defaults can only reference previously declared type parameters. + // inference + f13(); + f13(a); + f13(a, b); + f13(a, c); + // no inference, partially supplied + f13(); + f13(a); + f13(a, b); + // no inference, fully supplied + f13(); + f13(a); + f13(a, c); + f13(a, c); + + // function with a type parameter without a default and a type parameter with a default that refers to a later type parameter with a default + declare function f14(a?: T, b?: U, c?: V): [T, U, V]; + ~ +!!! error TS2744: Type parameter defaults can only reference previously declared type parameters. + // inference + f14(); + f14(a); + f14(a, b); + f14(a, b, c); + f14(a, b, d); + // no inference, partially supplied + f14(); + f14(a); + f14(a, b); + f14(a, b, c); + f14(); + f14(a); + f14(a, b); + f14(a, b, c); + // no inference fully supplied + f14(); + f14(a); + f14(a, b); + f14(a, b, d); + + // function with two type parameters with defaults that mutually refer to each other + declare function f15(a?: T, b?: U): [T, U]; + ~ +!!! error TS2744: Type parameter defaults can only reference previously declared type parameters. + // inference + f15(); + f15(a); + f15(a, b); + // no inference, partially supplied + f15(); + f15(a); + f15(a, a); + // no inference, fully supplied + f15(); + f15(a); + f15(a, b); + + // function with a type parameter without a default and two type parameters with defaults that mutually refer to each other + declare function f16(a?: T, b?: U, c?: V): [T, U, V]; + ~ +!!! error TS2744: Type parameter defaults can only reference previously declared type parameters. + // no inference + f16(); + f16(a); + f16(a, b); + f16(a, b, b); + // no inference, partially supplied + f16(); + f16(a); + f16(a, b); + f16(a, b, b); + f16(); + f16(a); + f16(a, b); + f16(a, b, b); + // no inference, fully supplied + f16(); + f16(a); + f16(a, b); + f16(a, b, d); + + // function with a type parameter with a default that refers to a later type parameter with a default that refers to an earlier type parameter in a union + declare function f17(a?: T, b?: U): [T, U]; + ~ +!!! error TS2744: Type parameter defaults can only reference previously declared type parameters. + // inference + f17(); + f17(a); + f17(a, a); + f17(a, b); + f17(a, c); + // no inference, partially supplied + f17(); + f17(a); + f17(a, a); + f17(a, b); + // no inference, fully supplied + f17(); + f17(a); + f17(a, c); + + // function with a type parameter without a default and a type parameter with a default that refers to a later type parameter with a default that refers to an earlier type parameter in a union + declare function f18(a?: T, b?: U, c?: V): [T, U, V]; + ~ +!!! error TS2744: Type parameter defaults can only reference previously declared type parameters. + // inference + f18(); + f18(a); + f18(a, b); + f18(a, b, b); + f18(a, b, c); + // no inference, partially supplied + f18(); + f18(a); + f18(a, b); + f18(a, b, b); + f18(a, b, c); + f18(); + f18(a); + f18(a, b); + f18(a, b, b); + f18(a, b, c); + // no inference, fully supplied + f18(); + f18(a); + f18(a, b); + f18(a, b, d); + + // function with a type parameter with a default that refers to a later type parameter with a default that refers to an earlier type parameter in an intersection + declare function f19(a?: T, b?: U): [T, U]; + ~ +!!! error TS2744: Type parameter defaults can only reference previously declared type parameters. + // inference + f19(); + f19(a); + f19(a, a); + f19(a, b); + f19(a, ab); + f19(a, c); + // no inference, partially supplied + f19(); + f19(a); + f19(a, ab); + // no inference, fully supplied + f19(); + f19(a); + f19(a, c); + + // function with a type parameter without a default and a type parameter with a default that refers to a later type parameter with a default that refers to an earlier type parameter in an intersection + declare function f20(a?: T, b?: U, c?: V): [T, U, V]; + ~ +!!! error TS2744: Type parameter defaults can only reference previously declared type parameters. + // inference + f20(); + f20(a); + f20(a, b); + f20(a, b, c); + // no inference, partially supplied + f20(); + f20(a); + f20(a, b); + f20(a, b, bc); + f20(); + f20(a); + f20(a, b); + f20(a, b, bc); + // no inference, fully supplied + f20(); + f20(a); + f20(a, b); + f20(a, b, d); + + interface i00 { a: T; } + const i00c00 = (x).a; + const i00c01 = (>x).a; + + interface i01 { a: [T, U]; } + const i01c00 = (>x).a; + const i01c01 = (>x).a; + + interface i02 { a: [T, U]; } + const i02c00 = (>x).a; + const i02c01 = (>x).a; + const i02c02 = (>x).a; + const i02c03 = (>x).a; + const i02c04 = (>x).a; + + interface i03 { a: [T, U]; } + const i03c00 = (>x).a; + const i03c01 = (>x).a; + const i03c02 = (>x).a; + const i03c03 = (>x).a; + const i03c04 = (>x).a; + + interface i04 {} + interface i04 {} + interface i04 {} + interface i04 {} + + interface i05 { a: T; } + ~ +!!! error TS2744: Type parameter defaults can only reference previously declared type parameters. + const i05c00 = (x).a; + const i05c01 = (>x).a; + + interface i06 { a: [T, U]; } + ~ +!!! error TS2744: Type parameter defaults can only reference previously declared type parameters. + const i06c00 = (x).a; + const i06c01 = (>x).a; + const i06c02 = (>x).a; + + interface i07 { a: A; } + interface i07 { b: A; } + const i07c00 = (x).a; + const i07c01 = (x).b; + const i07c02 = (>x).a; + const i07c03 = (>x).b; + + interface Base01 { a: T; } + interface Base01Constructor { new (a?: T): Base01; } + + declare const Base01: Base01Constructor; + const Base01c00 = new Base01(); + const Base01c01 = new Base01(1); + const Base01c02 = new Base01(); + const Base01c03 = new Base01(1); + + declare class Derived01 extends Base01 { } + const Derived01c00 = new Derived01(); + const Derived01c01 = new Derived01(1); + const Derived01c02 = new Derived01(); + const Derived01c03 = new Derived01(1); + + declare class Derived02 extends Base01 { } + const Derived02c00 = new Derived02(); + const Derived02c01 = new Derived02(1); + const Derived02c02 = new Derived02(); + const Derived02c03 = new Derived02(1); + + // https://github.com/Microsoft/TypeScript/issues/16211 + interface Base02 {} + interface Base02Constructor { new (a: T): Base02 & T; } + declare const Base02: Base02Constructor; + declare class Derived03 extends Base02 {} + const Derived03c00 = new Derived03(ab); + const Derived03c01 = Derived03c00.a; + type DerivedProps = keyof Derived03; + + type t00 = { a: T; } + const t00c00 = (x).a; + const t00c01 = (>x).a; + + type t01 = { a: [T, U]; } + const t01c00 = (>x).a; + const t01c01 = (>x).a; + + type t02 = { a: [T, U]; } + const t02c00 = (>x).a; + const t02c01 = (>x).a; + const t02c02 = (>x).a; + const t02c03 = (>x).a; + const t02c04 = (>x).a; + + type t03 = { a: [T, U]; } + const t03c00 = (>x).a; + const t03c01 = (>x).a; + const t03c02 = (>x).a; + const t03c03 = (>x).a; + const t03c04 = (>x).a; + + // https://github.com/Microsoft/TypeScript/issues/16221 + interface SelfReference> {} \ No newline at end of file diff --git a/tests/baselines/reference/genericDefaults.js b/tests/baselines/reference/genericDefaults.js index be6b76ea43c..4cd1127724f 100644 --- a/tests/baselines/reference/genericDefaults.js +++ b/tests/baselines/reference/genericDefaults.js @@ -949,12 +949,12 @@ interface i04 { interface i05 { a: T; } -declare const i05c00: {}; +declare const i05c00: any; declare const i05c01: number; interface i06 { a: [T, U]; } -declare const i06c00: [{}, {}]; +declare const i06c00: [any, any]; declare const i06c01: [number, number]; declare const i06c02: [number, string]; interface i07 { diff --git a/tests/baselines/reference/genericDefaults.types b/tests/baselines/reference/genericDefaults.types index 839994cc965..c439d96a08b 100644 --- a/tests/baselines/reference/genericDefaults.types +++ b/tests/baselines/reference/genericDefaults.types @@ -1015,22 +1015,22 @@ f14(a, b, d); // no inference, partially supplied f14(); ->f14() : [A, {}, C] +>f14() : [A, any, C] >f14 : (a?: T, b?: U, c?: V) => [T, U, V] f14(a); ->f14(a) : [A, {}, C] +>f14(a) : [A, any, C] >f14 : (a?: T, b?: U, c?: V) => [T, U, V] >a : A f14(a, b); ->f14(a, b) : [A, {}, C] +>f14(a, b) : [A, any, C] >f14 : (a?: T, b?: U, c?: V) => [T, U, V] >a : A >b : B f14(a, b, c); ->f14(a, b, c) : [A, {}, C] +>f14(a, b, c) : [A, any, C] >f14 : (a?: T, b?: U, c?: V) => [T, U, V] >a : A >b : B @@ -1167,22 +1167,22 @@ f16(a, b, b); // no inference, partially supplied f16(); ->f16() : [A, {}, {}] +>f16() : [A, any, any] >f16 : (a?: T, b?: U, c?: V) => [T, U, V] f16(a); ->f16(a) : [A, {}, {}] +>f16(a) : [A, any, any] >f16 : (a?: T, b?: U, c?: V) => [T, U, V] >a : A f16(a, b); ->f16(a, b) : [A, {}, {}] +>f16(a, b) : [A, any, any] >f16 : (a?: T, b?: U, c?: V) => [T, U, V] >a : A >b : B f16(a, b, b); ->f16(a, b, b) : [A, {}, {}] +>f16(a, b, b) : [A, any, any] >f16 : (a?: T, b?: U, c?: V) => [T, U, V] >a : A >b : B @@ -1344,29 +1344,29 @@ f18(a, b, c); // no inference, partially supplied f18(); ->f18() : [A, {}, {} | C] +>f18() : [A, any, any] >f18 : (a?: T, b?: U, c?: V) => [T, U, V] f18(a); ->f18(a) : [A, {}, {} | C] +>f18(a) : [A, any, any] >f18 : (a?: T, b?: U, c?: V) => [T, U, V] >a : A f18(a, b); ->f18(a, b) : [A, {}, {} | C] +>f18(a, b) : [A, any, any] >f18 : (a?: T, b?: U, c?: V) => [T, U, V] >a : A >b : B f18(a, b, b); ->f18(a, b, b) : [A, {}, {} | C] +>f18(a, b, b) : [A, any, any] >f18 : (a?: T, b?: U, c?: V) => [T, U, V] >a : A >b : B >b : B f18(a, b, c); ->f18(a, b, c) : [A, {}, {} | C] +>f18(a, b, c) : [A, any, any] >f18 : (a?: T, b?: U, c?: V) => [T, U, V] >a : A >b : B @@ -1528,22 +1528,22 @@ f20(a, b, c); // no inference, partially supplied f20(); ->f20() : [A, {}, C] +>f20() : [A, any, any] >f20 : (a?: T, b?: U, c?: V) => [T, U, V] f20(a); ->f20(a) : [A, {}, C] +>f20(a) : [A, any, any] >f20 : (a?: T, b?: U, c?: V) => [T, U, V] >a : A f20(a, b); ->f20(a, b) : [A, {}, C] +>f20(a, b) : [A, any, any] >f20 : (a?: T, b?: U, c?: V) => [T, U, V] >a : A >b : B f20(a, b, bc); ->f20(a, b, bc) : [A, {}, C] +>f20(a, b, bc) : [A, any, any] >f20 : (a?: T, b?: U, c?: V) => [T, U, V] >a : A >b : B @@ -1727,12 +1727,12 @@ interface i05 { a: T; } >a : T const i05c00 = (x).a; ->i05c00 : {} ->(x).a : {} ->(x) : i05<{}> ->x : i05<{}> +>i05c00 : any +>(x).a : any +>(x) : i05 +>x : i05 >x : any ->a : {} +>a : any const i05c01 = (>x).a; >i05c01 : number @@ -1746,12 +1746,12 @@ interface i06 { a: [T, U]; } >a : [T, U] const i06c00 = (x).a; ->i06c00 : [{}, {}] ->(x).a : [{}, {}] ->(x) : i06<{}, {}> ->x : i06<{}, {}> +>i06c00 : [any, any] +>(x).a : [any, any] +>(x) : i06 +>x : i06 >x : any ->a : [{}, {}] +>a : [any, any] const i06c01 = (>x).a; >i06c01 : [number, number] diff --git a/tests/baselines/reference/subclassThisTypeAssignable.errors.txt b/tests/baselines/reference/subclassThisTypeAssignable.errors.txt new file mode 100644 index 00000000000..f1d661695d1 --- /dev/null +++ b/tests/baselines/reference/subclassThisTypeAssignable.errors.txt @@ -0,0 +1,34 @@ +tests/cases/compiler/tile1.ts(6,81): error TS2744: Type parameter defaults can only reference previously declared type parameters. + + +==== tests/cases/compiler/tile1.ts (1 errors) ==== + interface Lifecycle { + oninit?(vnode: Vnode): number; + [_: number]: any; + } + + interface Vnode = Lifecycle> { + ~~~~~ +!!! error TS2744: Type parameter defaults can only reference previously declared type parameters. + tag: Component; + } + + interface Component { + view(this: State, vnode: Vnode): number; + } + + interface ClassComponent extends Lifecycle> { + oninit?(vnode: Vnode): number; + view(vnode: Vnode): number; + } + + interface MyAttrs { id: number } + class C implements ClassComponent { + view(v: Vnode) { return 0; } + } + + const test8: ClassComponent = new C(); +==== tests/cases/compiler/file1.js (0 errors) ==== + /** @type {ClassComponent} */ + const test9 = new C(); + \ No newline at end of file diff --git a/tests/baselines/reference/subclassThisTypeAssignable.types b/tests/baselines/reference/subclassThisTypeAssignable.types index 711b0056277..9608613f1ff 100644 --- a/tests/baselines/reference/subclassThisTypeAssignable.types +++ b/tests/baselines/reference/subclassThisTypeAssignable.types @@ -37,8 +37,8 @@ class C implements ClassComponent { >C : C view(v: Vnode) { return 0; } ->view : (v: Vnode>>) => number ->v : Vnode>> +>view : (v: Vnode>) => number +>v : Vnode> >0 : 0 } diff --git a/tests/baselines/reference/typeArgumentDefaultUsesConstraintOnCircularDefault.errors.txt b/tests/baselines/reference/typeArgumentDefaultUsesConstraintOnCircularDefault.errors.txt index 71e3ef04627..a886b48d5a2 100644 --- a/tests/baselines/reference/typeArgumentDefaultUsesConstraintOnCircularDefault.errors.txt +++ b/tests/baselines/reference/typeArgumentDefaultUsesConstraintOnCircularDefault.errors.txt @@ -1,18 +1,17 @@ -tests/cases/compiler/typeArgumentDefaultUsesConstraintOnCircularDefault.ts(3,18): error TS2322: Type '{ foo: string; }' is not assignable to type 'Test'. - Object literal may only specify known properties, and 'foo' does not exist in type 'Test'. -tests/cases/compiler/typeArgumentDefaultUsesConstraintOnCircularDefault.ts(5,19): error TS2322: Type '{}' is not assignable to type 'string'. +tests/cases/compiler/typeArgumentDefaultUsesConstraintOnCircularDefault.ts(1,30): error TS2744: Type parameter defaults can only reference previously declared type parameters. +tests/cases/compiler/typeArgumentDefaultUsesConstraintOnCircularDefault.ts(3,18): error TS2322: Type '{ foo: string; }' is not assignable to type 'Test'. + Object literal may only specify known properties, and 'foo' does not exist in type 'Test'. ==== tests/cases/compiler/typeArgumentDefaultUsesConstraintOnCircularDefault.ts (2 errors) ==== type Test = { value: T }; + ~ +!!! error TS2744: Type parameter defaults can only reference previously declared type parameters. let zz: Test = { foo: "abc" }; // should error on comparison with Test ~~~~~~~~~~ -!!! error TS2322: Type '{ foo: string; }' is not assignable to type 'Test'. -!!! error TS2322: Object literal may only specify known properties, and 'foo' does not exist in type 'Test'. +!!! error TS2322: Type '{ foo: string; }' is not assignable to type 'Test'. +!!! error TS2322: Object literal may only specify known properties, and 'foo' does not exist in type 'Test'. let zzy: Test = { value: {} }; // should error - ~~~~~ -!!! error TS2322: Type '{}' is not assignable to type 'string'. -!!! related TS6500 tests/cases/compiler/typeArgumentDefaultUsesConstraintOnCircularDefault.ts:1:37: The expected type comes from property 'value' which is declared here on type 'Test' \ No newline at end of file diff --git a/tests/baselines/reference/typeArgumentDefaultUsesConstraintOnCircularDefault.types b/tests/baselines/reference/typeArgumentDefaultUsesConstraintOnCircularDefault.types index 7c0d469da46..46477c7ffb3 100644 --- a/tests/baselines/reference/typeArgumentDefaultUsesConstraintOnCircularDefault.types +++ b/tests/baselines/reference/typeArgumentDefaultUsesConstraintOnCircularDefault.types @@ -4,13 +4,13 @@ type Test = { value: T }; >value : T let zz: Test = { foo: "abc" }; // should error on comparison with Test ->zz : Test +>zz : Test >{ foo: "abc" } : { foo: string; } >foo : string >"abc" : "abc" let zzy: Test = { value: {} }; // should error ->zzy : Test +>zzy : Test >{ value: {} } : { value: {}; } >value : {} >{} : {} From a400a8afecca46517e728ec0fba672372248280c Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 27 Dec 2018 14:05:14 -1000 Subject: [PATCH 26/96] Add regression test --- ...peArgumentDefaultUsesConstraintOnCircularDefault.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/cases/compiler/typeArgumentDefaultUsesConstraintOnCircularDefault.ts b/tests/cases/compiler/typeArgumentDefaultUsesConstraintOnCircularDefault.ts index b8361ea5714..ca5a270f6e7 100644 --- a/tests/cases/compiler/typeArgumentDefaultUsesConstraintOnCircularDefault.ts +++ b/tests/cases/compiler/typeArgumentDefaultUsesConstraintOnCircularDefault.ts @@ -1,5 +1,11 @@ -type Test = { value: T }; +type Test = { value: T }; // Error let zz: Test = { foo: "abc" }; // should error on comparison with Test -let zzy: Test = { value: {} }; // should error +let zzy: Test = { value: {} }; + +// Simplified repro from #28873 + +class C1 {} + +class C2 = any> {} From 8a72a19b7ae9fd0429dd837df9b7d2eeb550926a Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 27 Dec 2018 14:05:24 -1000 Subject: [PATCH 27/96] Accept new baselines --- ...UsesConstraintOnCircularDefault.errors.txt | 10 ++++++-- ...tDefaultUsesConstraintOnCircularDefault.js | 23 ++++++++++++++++--- ...ultUsesConstraintOnCircularDefault.symbols | 16 +++++++++++-- ...faultUsesConstraintOnCircularDefault.types | 12 ++++++++-- 4 files changed, 52 insertions(+), 9 deletions(-) diff --git a/tests/baselines/reference/typeArgumentDefaultUsesConstraintOnCircularDefault.errors.txt b/tests/baselines/reference/typeArgumentDefaultUsesConstraintOnCircularDefault.errors.txt index a886b48d5a2..756c1f9da3e 100644 --- a/tests/baselines/reference/typeArgumentDefaultUsesConstraintOnCircularDefault.errors.txt +++ b/tests/baselines/reference/typeArgumentDefaultUsesConstraintOnCircularDefault.errors.txt @@ -4,7 +4,7 @@ tests/cases/compiler/typeArgumentDefaultUsesConstraintOnCircularDefault.ts(3,18) ==== tests/cases/compiler/typeArgumentDefaultUsesConstraintOnCircularDefault.ts (2 errors) ==== - type Test = { value: T }; + type Test = { value: T }; // Error ~ !!! error TS2744: Type parameter defaults can only reference previously declared type parameters. @@ -13,5 +13,11 @@ tests/cases/compiler/typeArgumentDefaultUsesConstraintOnCircularDefault.ts(3,18) !!! error TS2322: Type '{ foo: string; }' is not assignable to type 'Test'. !!! error TS2322: Object literal may only specify known properties, and 'foo' does not exist in type 'Test'. - let zzy: Test = { value: {} }; // should error + let zzy: Test = { value: {} }; + + // Simplified repro from #28873 + + class C1 {} + + class C2 = any> {} \ No newline at end of file diff --git a/tests/baselines/reference/typeArgumentDefaultUsesConstraintOnCircularDefault.js b/tests/baselines/reference/typeArgumentDefaultUsesConstraintOnCircularDefault.js index 296a0063fe2..a50e7cab397 100644 --- a/tests/baselines/reference/typeArgumentDefaultUsesConstraintOnCircularDefault.js +++ b/tests/baselines/reference/typeArgumentDefaultUsesConstraintOnCircularDefault.js @@ -1,11 +1,28 @@ //// [typeArgumentDefaultUsesConstraintOnCircularDefault.ts] -type Test = { value: T }; +type Test = { value: T }; // Error let zz: Test = { foo: "abc" }; // should error on comparison with Test -let zzy: Test = { value: {} }; // should error +let zzy: Test = { value: {} }; + +// Simplified repro from #28873 + +class C1 {} + +class C2 = any> {} //// [typeArgumentDefaultUsesConstraintOnCircularDefault.js] var zz = { foo: "abc" }; // should error on comparison with Test -var zzy = { value: {} }; // should error +var zzy = { value: {} }; +// Simplified repro from #28873 +var C1 = /** @class */ (function () { + function C1() { + } + return C1; +}()); +var C2 = /** @class */ (function () { + function C2() { + } + return C2; +}()); diff --git a/tests/baselines/reference/typeArgumentDefaultUsesConstraintOnCircularDefault.symbols b/tests/baselines/reference/typeArgumentDefaultUsesConstraintOnCircularDefault.symbols index 2181e341889..4c227899de9 100644 --- a/tests/baselines/reference/typeArgumentDefaultUsesConstraintOnCircularDefault.symbols +++ b/tests/baselines/reference/typeArgumentDefaultUsesConstraintOnCircularDefault.symbols @@ -1,5 +1,5 @@ === tests/cases/compiler/typeArgumentDefaultUsesConstraintOnCircularDefault.ts === -type Test = { value: T }; +type Test = { value: T }; // Error >Test : Symbol(Test, Decl(typeArgumentDefaultUsesConstraintOnCircularDefault.ts, 0, 0)) >T : Symbol(T, Decl(typeArgumentDefaultUsesConstraintOnCircularDefault.ts, 0, 10)) >T : Symbol(T, Decl(typeArgumentDefaultUsesConstraintOnCircularDefault.ts, 0, 10)) @@ -11,8 +11,20 @@ let zz: Test = { foo: "abc" }; // should error on comparison with Test >Test : Symbol(Test, Decl(typeArgumentDefaultUsesConstraintOnCircularDefault.ts, 0, 0)) >foo : Symbol(foo, Decl(typeArgumentDefaultUsesConstraintOnCircularDefault.ts, 2, 16)) -let zzy: Test = { value: {} }; // should error +let zzy: Test = { value: {} }; >zzy : Symbol(zzy, Decl(typeArgumentDefaultUsesConstraintOnCircularDefault.ts, 4, 3)) >Test : Symbol(Test, Decl(typeArgumentDefaultUsesConstraintOnCircularDefault.ts, 0, 0)) >value : Symbol(value, Decl(typeArgumentDefaultUsesConstraintOnCircularDefault.ts, 4, 17)) +// Simplified repro from #28873 + +class C1 {} +>C1 : Symbol(C1, Decl(typeArgumentDefaultUsesConstraintOnCircularDefault.ts, 4, 30)) +>T : Symbol(T, Decl(typeArgumentDefaultUsesConstraintOnCircularDefault.ts, 8, 9)) +>C1 : Symbol(C1, Decl(typeArgumentDefaultUsesConstraintOnCircularDefault.ts, 4, 30)) + +class C2 = any> {} +>C2 : Symbol(C2, Decl(typeArgumentDefaultUsesConstraintOnCircularDefault.ts, 8, 31)) +>T : Symbol(T, Decl(typeArgumentDefaultUsesConstraintOnCircularDefault.ts, 10, 9)) +>C2 : Symbol(C2, Decl(typeArgumentDefaultUsesConstraintOnCircularDefault.ts, 8, 31)) + diff --git a/tests/baselines/reference/typeArgumentDefaultUsesConstraintOnCircularDefault.types b/tests/baselines/reference/typeArgumentDefaultUsesConstraintOnCircularDefault.types index 46477c7ffb3..91078dad884 100644 --- a/tests/baselines/reference/typeArgumentDefaultUsesConstraintOnCircularDefault.types +++ b/tests/baselines/reference/typeArgumentDefaultUsesConstraintOnCircularDefault.types @@ -1,5 +1,5 @@ === tests/cases/compiler/typeArgumentDefaultUsesConstraintOnCircularDefault.ts === -type Test = { value: T }; +type Test = { value: T }; // Error >Test : Test >value : T @@ -9,9 +9,17 @@ let zz: Test = { foo: "abc" }; // should error on comparison with Test >foo : string >"abc" : "abc" -let zzy: Test = { value: {} }; // should error +let zzy: Test = { value: {} }; >zzy : Test >{ value: {} } : { value: {}; } >value : {} >{} : {} +// Simplified repro from #28873 + +class C1 {} +>C1 : C1 + +class C2 = any> {} +>C2 : C2 + From c46090b8dcf629396ddcfab2f499c6d1f1127bf4 Mon Sep 17 00:00:00 2001 From: Benjamin Lichtman Date: Thu, 27 Dec 2018 17:01:05 -0800 Subject: [PATCH 28/96] Show template literal in navtree function call args --- src/services/navigationBar.ts | 2 +- .../navigationBarAnonymousClassAndFunctionExpressions.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 760d6e71031..60f1283f7e6 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -660,7 +660,7 @@ namespace ts.NavigationBar { else if (isCallExpression(parent)) { const name = getCalledExpressionName(parent.expression); if (name !== undefined) { - const args = mapDefined(parent.arguments, a => isStringLiteral(a) ? a.getText(curSourceFile) : undefined).join(", "); + const args = mapDefined(parent.arguments, a => isStringLiteralLike(a) ? a.getText(curSourceFile) : undefined).join(", "); return `${name}(${args}) callback`; } } diff --git a/tests/cases/fourslash/navigationBarAnonymousClassAndFunctionExpressions.ts b/tests/cases/fourslash/navigationBarAnonymousClassAndFunctionExpressions.ts index 23fe81fe48e..ad1ba1e72f9 100644 --- a/tests/cases/fourslash/navigationBarAnonymousClassAndFunctionExpressions.ts +++ b/tests/cases/fourslash/navigationBarAnonymousClassAndFunctionExpressions.ts @@ -18,7 +18,7 @@ //// // These will only show up as childItems. //// function z() {} //// console.log(function() {}) -//// describe("this", 'function', () => {}); +//// describe("this", 'function', `is a function`, `but this ${"wont"} show`, () => {}); //// [].map(() => {}); ////}) ////(function classes() { @@ -77,7 +77,7 @@ verify.navigationTree({ "kind": "function" }, { - "text": `describe("this", 'function') callback`, + "text": `describe("this", 'function', \`is a function\`) callback`, "kind": "function" }, { @@ -199,7 +199,7 @@ verify.navigationBar([ "kind": "function" }, { - "text": `describe("this", 'function') callback`, + "text": `describe("this", 'function', \`is a function\`) callback`, "kind": "function" }, { From 4a664d690b352feecbfba4a335608fb5f263c446 Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Fri, 28 Dec 2018 07:21:29 -0800 Subject: [PATCH 29/96] Update user baselines (#29187) --- tests/baselines/reference/user/follow-redirects.log | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/baselines/reference/user/follow-redirects.log b/tests/baselines/reference/user/follow-redirects.log index 565dd1e208e..7e3f419696e 100644 --- a/tests/baselines/reference/user/follow-redirects.log +++ b/tests/baselines/reference/user/follow-redirects.log @@ -1,12 +1,13 @@ Exit Code: 1 Standard output: -node_modules/follow-redirects/index.js(97,10): error TS2339: Property 'emit' does not exist on type 'RedirectableRequest'. -node_modules/follow-redirects/index.js(98,10): error TS2339: Property 'abort' does not exist on type 'RedirectableRequest'. -node_modules/follow-redirects/index.js(156,10): error TS2339: Property 'emit' does not exist on type 'RedirectableRequest'. -node_modules/follow-redirects/index.js(222,12): error TS2339: Property 'emit' does not exist on type 'RedirectableRequest'. -node_modules/follow-redirects/index.js(256,35): error TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'. +node_modules/follow-redirects/index.js(105,10): error TS2339: Property 'emit' does not exist on type 'RedirectableRequest'. +node_modules/follow-redirects/index.js(106,10): error TS2339: Property 'abort' does not exist on type 'RedirectableRequest'. +node_modules/follow-redirects/index.js(173,10): error TS2339: Property 'emit' does not exist on type 'RedirectableRequest'. +node_modules/follow-redirects/index.js(212,16): error TS2339: Property 'emit' does not exist on type 'RedirectableRequest'. +node_modules/follow-redirects/index.js(259,12): error TS2339: Property 'emit' does not exist on type 'RedirectableRequest'. +node_modules/follow-redirects/index.js(293,35): error TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'. Type 'undefined' is not assignable to type 'string'. -node_modules/follow-redirects/index.js(269,10): error TS2339: Property 'emit' does not exist on type 'RedirectableRequest'. +node_modules/follow-redirects/index.js(306,10): error TS2339: Property 'emit' does not exist on type 'RedirectableRequest'. From 0165e80e7c6e0fbfb365390b1fe5521b7107b1c2 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 28 Dec 2018 09:30:14 -1000 Subject: [PATCH 30/96] Don't widen contextually typed literals in initializer expressions --- src/compiler/checker.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 23c5568f2e5..c3b04af565f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4919,7 +4919,7 @@ namespace ts { if (strictNullChecks && declaration.initializer && !(getFalsyFlags(checkDeclarationInitializer(declaration)) & TypeFlags.Undefined)) { type = getTypeWithFacts(type, TypeFacts.NEUndefined); } - return declaration.initializer && !getContextualTypeForVariableLikeDeclaration(walkUpBindingElementsAndPatterns(declaration)) ? + return declaration.initializer && !getEffectiveTypeAnnotationNode(walkUpBindingElementsAndPatterns(declaration)) ? getUnionType([type, checkDeclarationInitializer(declaration)], UnionReduction.Subtype) : type; } @@ -22810,7 +22810,8 @@ namespace ts { const type = getTypeOfExpression(initializer, /*cache*/ true); const widened = getCombinedNodeFlags(declaration) & NodeFlags.Const || isDeclarationReadonly(declaration) || - isTypeAssertion(initializer) ? type : getWidenedLiteralType(type); + isTypeAssertion(initializer) || + isLiteralOfContextualType(type, getContextualType(initializer)) ? type : getWidenedLiteralType(type); if (isInJSFile(declaration)) { if (widened.flags & TypeFlags.Nullable) { reportImplicitAny(declaration, anyType); From 93b4302d35662f1d197d5b4835e78b3fe2df0383 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 28 Dec 2018 09:36:23 -1000 Subject: [PATCH 31/96] Accept new baselines --- .../destructuringArrayBindingPatternAndAssignment3.types | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.types index 389b6b5e5f5..0fb81ba6aa3 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.types +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.types @@ -45,8 +45,8 @@ const [f, g = f, h = i, i = f] = [1]; // error for h = i >c : number >d : number >c : number ->e : number ->e : number +>e : any +>e : any })([1]); >[1] : number[] From 7f4d1ac475a776d2e7f1eecf8f312b438eff23d1 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 28 Dec 2018 09:38:19 -1000 Subject: [PATCH 32/96] Add regression test --- .../destructuringInitializerContextualTypeFromContext.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/cases/compiler/destructuringInitializerContextualTypeFromContext.ts b/tests/cases/compiler/destructuringInitializerContextualTypeFromContext.ts index 6153b1e3a80..6b109e22271 100644 --- a/tests/cases/compiler/destructuringInitializerContextualTypeFromContext.ts +++ b/tests/cases/compiler/destructuringInitializerContextualTypeFromContext.ts @@ -1,3 +1,5 @@ +// @strict: true + interface SFC

{ (props: P & { children?: any }): any | null; } @@ -16,4 +18,9 @@ const Child: SFC = ({ children, name = "Artemis", ...props -}) => `name: ${name} props: ${JSON.stringify(props)}`; \ No newline at end of file +}) => `name: ${name} props: ${JSON.stringify(props)}`; + +// Repro from #29189 + +declare function f(g: (as: string[]) => void): void +f(([_1, _2 = undefined]) => undefined) From 73b1dcb78fbb07e1926827a05fe3b9648ef88d11 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 28 Dec 2018 09:38:24 -1000 Subject: [PATCH 33/96] Accept new baselines --- ...ingInitializerContextualTypeFromContext.js | 13 +++++++++++- ...itializerContextualTypeFromContext.symbols | 14 +++++++++++++ ...InitializerContextualTypeFromContext.types | 20 +++++++++++++++++-- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/tests/baselines/reference/destructuringInitializerContextualTypeFromContext.js b/tests/baselines/reference/destructuringInitializerContextualTypeFromContext.js index 2dd6b4ea11a..1215d343df0 100644 --- a/tests/baselines/reference/destructuringInitializerContextualTypeFromContext.js +++ b/tests/baselines/reference/destructuringInitializerContextualTypeFromContext.js @@ -17,9 +17,16 @@ const Child: SFC = ({ children, name = "Artemis", ...props -}) => `name: ${name} props: ${JSON.stringify(props)}`; +}) => `name: ${name} props: ${JSON.stringify(props)}`; + +// Repro from #29189 + +declare function f(g: (as: string[]) => void): void +f(([_1, _2 = undefined]) => undefined) + //// [destructuringInitializerContextualTypeFromContext.js] +"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { @@ -48,3 +55,7 @@ var Child = function (_a) { var children = _a.children, _b = _a.name, name = _b === void 0 ? "Artemis" : _b, props = __rest(_a, ["children", "name"]); return "name: " + name + " props: " + JSON.stringify(props); }; +f(function (_a) { + var _1 = _a[0], _b = _a[1], _2 = _b === void 0 ? undefined : _b; + return undefined; +}); diff --git a/tests/baselines/reference/destructuringInitializerContextualTypeFromContext.symbols b/tests/baselines/reference/destructuringInitializerContextualTypeFromContext.symbols index 317a09ee105..8ae1b56e20f 100644 --- a/tests/baselines/reference/destructuringInitializerContextualTypeFromContext.symbols +++ b/tests/baselines/reference/destructuringInitializerContextualTypeFromContext.symbols @@ -56,3 +56,17 @@ const Child: SFC = ({ >stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) >props : Symbol(props, Decl(destructuringInitializerContextualTypeFromContext.ts, 16, 21)) +// Repro from #29189 + +declare function f(g: (as: string[]) => void): void +>f : Symbol(f, Decl(destructuringInitializerContextualTypeFromContext.ts, 18, 54)) +>g : Symbol(g, Decl(destructuringInitializerContextualTypeFromContext.ts, 22, 19)) +>as : Symbol(as, Decl(destructuringInitializerContextualTypeFromContext.ts, 22, 23)) + +f(([_1, _2 = undefined]) => undefined) +>f : Symbol(f, Decl(destructuringInitializerContextualTypeFromContext.ts, 18, 54)) +>_1 : Symbol(_1, Decl(destructuringInitializerContextualTypeFromContext.ts, 23, 4)) +>_2 : Symbol(_2, Decl(destructuringInitializerContextualTypeFromContext.ts, 23, 7)) +>undefined : Symbol(undefined) +>undefined : Symbol(undefined) + diff --git a/tests/baselines/reference/destructuringInitializerContextualTypeFromContext.types b/tests/baselines/reference/destructuringInitializerContextualTypeFromContext.types index fa76e2eef25..4018d4bed3f 100644 --- a/tests/baselines/reference/destructuringInitializerContextualTypeFromContext.types +++ b/tests/baselines/reference/destructuringInitializerContextualTypeFromContext.types @@ -50,8 +50,24 @@ const Child: SFC = ({ >`name: ${name} props: ${JSON.stringify(props)}` : string >name : "Apollo" | "Artemis" | "Dionysus" | "Persephone" >JSON.stringify(props) : string ->JSON.stringify : { (value: any, replacer?: (key: string, value: any) => any, space?: string | number): string; (value: any, replacer?: (string | number)[], space?: string | number): string; } +>JSON.stringify : { (value: any, replacer?: ((key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; } >JSON : JSON ->stringify : { (value: any, replacer?: (key: string, value: any) => any, space?: string | number): string; (value: any, replacer?: (string | number)[], space?: string | number): string; } +>stringify : { (value: any, replacer?: ((key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; } >props : {} +// Repro from #29189 + +declare function f(g: (as: string[]) => void): void +>f : (g: (as: string[]) => void) => void +>g : (as: string[]) => void +>as : string[] + +f(([_1, _2 = undefined]) => undefined) +>f(([_1, _2 = undefined]) => undefined) : void +>f : (g: (as: string[]) => void) => void +>([_1, _2 = undefined]) => undefined : ([_1, _2]: string[]) => undefined +>_1 : string +>_2 : string | undefined +>undefined : undefined +>undefined : undefined + From 2dd6e20ef9d39185909f206d619b5dc0a85bf4c7 Mon Sep 17 00:00:00 2001 From: Benjamin Lichtman Date: Fri, 28 Dec 2018 16:37:59 -0800 Subject: [PATCH 34/96] Only provide suggestion for outermost async fix --- .../codefixes/convertToAsyncFunction.ts | 10 ++--- src/services/suggestionDiagnostics.ts | 45 ++++++++++++------- .../services/convertToAsyncFunction.ts | 42 ++++++++++++----- ...ertToAsyncFunction_OutermostOnlyFailure.ts | 16 +++++++ ...ertToAsyncFunction_OutermostOnlySuccess.js | 15 +++++++ ...ertToAsyncFunction_OutermostOnlySuccess.ts | 15 +++++++ .../convertToAsyncFunction_bindingPattern.js | 4 +- .../convertToAsyncFunction_bindingPattern.ts | 4 +- ...yncFunction_bindingPatternNameCollision.js | 4 +- ...yncFunction_bindingPatternNameCollision.ts | 4 +- ...allbackReturnsRejectedPromiseInTryBlock.js | 4 +- ...allbackReturnsRejectedPromiseInTryBlock.ts | 4 +- ...tToAsyncFunction_catchBlockUniqueParams.js | 8 ++-- ...tToAsyncFunction_catchBlockUniqueParams.ts | 8 ++-- ...oAsyncFunction_runEffectfulContinuation.js | 4 +- ...oAsyncFunction_runEffectfulContinuation.ts | 4 +- ...oAsyncFunction_simpleFunctionExpression.js | 4 +- ...oAsyncFunction_simpleFunctionExpression.ts | 4 +- ...ctionExpressionAssignedToBindingPattern.js | 4 +- ...ctionExpressionAssignedToBindingPattern.ts | 4 +- ...nction_simpleFunctionExpressionWithName.js | 4 +- ...nction_simpleFunctionExpressionWithName.ts | 4 +- 22 files changed, 148 insertions(+), 67 deletions(-) create mode 100644 tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_OutermostOnlyFailure.ts create mode 100644 tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_OutermostOnlySuccess.js create mode 100644 tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_OutermostOnlySuccess.ts diff --git a/src/services/codefixes/convertToAsyncFunction.ts b/src/services/codefixes/convertToAsyncFunction.ts index aae1d205de3..daf1d89b39a 100644 --- a/src/services/codefixes/convertToAsyncFunction.ts +++ b/src/services/codefixes/convertToAsyncFunction.ts @@ -60,7 +60,7 @@ namespace ts.codefix { const setOfExpressionsToReturn = getAllPromiseExpressionsToReturn(functionToConvert, checker); const functionToConvertRenamed = renameCollidingVarNames(functionToConvert, checker, synthNamesMap, context, setOfExpressionsToReturn, originalTypeMap, allVarNames); const constIdentifiers = getConstIdentifiers(synthNamesMap); - const returnStatements = functionToConvertRenamed.body && isBlock(functionToConvertRenamed.body) ? getReturnStatementsWithPromiseHandlers(functionToConvertRenamed.body) : emptyArray; + const returnStatements = functionToConvertRenamed.body && isBlock(functionToConvertRenamed.body) ? getReturnStatementsWithPromiseHandlers(functionToConvertRenamed.body, checker) : emptyArray; const transformer: Transformer = { checker, synthNamesMap, allVarNames, setOfExpressionsToReturn, constIdentifiers, originalTypeMap, isInJSFile: isInJavascript }; if (!returnStatements.length) { @@ -87,10 +87,10 @@ namespace ts.codefix { } } - function getReturnStatementsWithPromiseHandlers(body: Block): ReadonlyArray { + function getReturnStatementsWithPromiseHandlers(body: Block, checker: TypeChecker): ReadonlyArray { const res: ReturnStatement[] = []; forEachReturnStatement(body, ret => { - if (isReturnStatementWithFixablePromiseHandler(ret)) res.push(ret); + if (isReturnStatementWithFixablePromiseHandler(ret, checker)) res.push(ret); }); return res; } @@ -450,7 +450,7 @@ namespace ts.codefix { seenReturnStatement = true; } - if (isReturnStatementWithFixablePromiseHandler(statement)) { + if (isReturnStatementWithFixablePromiseHandler(statement, transformer.checker)) { refactoredStmts = refactoredStmts.concat(getInnerTransformationBody(transformer, [statement], prevArgName)); } else { @@ -466,7 +466,7 @@ namespace ts.codefix { seenReturnStatement); } else { - const innerRetStmts = isFixablePromiseHandler(funcBody) ? [createReturn(funcBody)] : emptyArray; + const innerRetStmts = isFixablePromiseHandler(funcBody, transformer.checker) ? [createReturn(funcBody)] : emptyArray; const innerCbBody = getInnerTransformationBody(transformer, innerRetStmts, prevArgName); if (innerCbBody.length > 0) { diff --git a/src/services/suggestionDiagnostics.ts b/src/services/suggestionDiagnostics.ts index 5c175146e34..6749f56f88a 100644 --- a/src/services/suggestionDiagnostics.ts +++ b/src/services/suggestionDiagnostics.ts @@ -1,5 +1,7 @@ /* @internal */ namespace ts { + const visitedNestedConvertibleFunctions = createMap(); + export function computeSuggestionDiagnostics(sourceFile: SourceFile, program: Program, cancellationToken: CancellationToken): DiagnosticWithLocation[] { program.getSemanticDiagnostics(sourceFile, cancellationToken); const diags: DiagnosticWithLocation[] = []; @@ -13,6 +15,7 @@ namespace ts { const isJsFile = isSourceFileJS(sourceFile); + visitedNestedConvertibleFunctions.clear(); check(sourceFile); if (getAllowSyntheticDefaultImports(program.getCompilerOptions())) { @@ -114,17 +117,21 @@ namespace ts { } function addConvertToAsyncFunctionDiagnostics(node: FunctionLikeDeclaration, checker: TypeChecker, diags: Push): void { - if (!isAsyncFunction(node) && - node.body && - isBlock(node.body) && - hasReturnStatementWithPromiseHandler(node.body) && - returnsPromise(node, checker)) { + if (!visitedNestedConvertibleFunctions.has(getKeyFromNode(node)) && isConvertableFunction(node, checker)) { diags.push(createDiagnosticForNode( !node.name && isVariableDeclaration(node.parent) && isIdentifier(node.parent.name) ? node.parent.name : node, Diagnostics.This_may_be_converted_to_an_async_function)); } } + function isConvertableFunction(node: FunctionLikeDeclaration, checker: TypeChecker) { + return !isAsyncFunction(node) && + node.body && + isBlock(node.body) && + hasReturnStatementWithPromiseHandler(node.body, checker) && + returnsPromise(node, checker); + } + function returnsPromise(node: FunctionLikeDeclaration, checker: TypeChecker): boolean { const functionType = checker.getTypeAtLocation(node); const callSignatures = checker.getSignaturesOfType(functionType, SignatureKind.Call); @@ -136,25 +143,25 @@ namespace ts { return isBinaryExpression(commonJsModuleIndicator) ? commonJsModuleIndicator.left : commonJsModuleIndicator; } - function hasReturnStatementWithPromiseHandler(body: Block): boolean { - return !!forEachReturnStatement(body, isReturnStatementWithFixablePromiseHandler); + function hasReturnStatementWithPromiseHandler(body: Block, checker: TypeChecker): boolean { + return !!forEachReturnStatement(body, stmt => isReturnStatementWithFixablePromiseHandler(stmt, checker)); } - export function isReturnStatementWithFixablePromiseHandler(node: Node): node is ReturnStatement { - return isReturnStatement(node) && !!node.expression && isFixablePromiseHandler(node.expression); + export function isReturnStatementWithFixablePromiseHandler(node: Node, checker: TypeChecker): node is ReturnStatement { + return isReturnStatement(node) && !!node.expression && isFixablePromiseHandler(node.expression, checker); } // Should be kept up to date with transformExpression in convertToAsyncFunction.ts - export function isFixablePromiseHandler(node: Node): boolean { + export function isFixablePromiseHandler(node: Node, checker: TypeChecker): boolean { // ensure outermost call exists and is a promise handler - if (!isPromiseHandler(node) || !node.arguments.every(isFixablePromiseArgument)) { + if (!isPromiseHandler(node) || !node.arguments.every((arg) => isFixablePromiseArgument(arg, checker))) { return false; } // ensure all chained calls are valid let currentNode = node.expression; while (isPromiseHandler(currentNode) || isPropertyAccessExpression(currentNode)) { - if (isCallExpression(currentNode) && !currentNode.arguments.every(isFixablePromiseArgument)) { + if (isCallExpression(currentNode) && !currentNode.arguments.every(arg => isFixablePromiseArgument(arg, checker))) { return false; } currentNode = currentNode.expression; @@ -167,16 +174,24 @@ namespace ts { } // should be kept up to date with getTransformationBody in convertToAsyncFunction.ts - function isFixablePromiseArgument(arg: Expression): boolean { + function isFixablePromiseArgument(arg: Expression, checker: TypeChecker): boolean { switch (arg.kind) { - case SyntaxKind.NullKeyword: - case SyntaxKind.Identifier: // identifier includes undefined case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: + if (isConvertableFunction(arg as FunctionLikeDeclaration, checker)) { + visitedNestedConvertibleFunctions.set(getKeyFromNode(arg as FunctionLikeDeclaration), true); + } + /* falls through */ + case SyntaxKind.NullKeyword: + case SyntaxKind.Identifier: // identifier includes undefined return true; default: return false; } } + + function getKeyFromNode(exp: FunctionLikeDeclaration) { + return `${exp.pos.toString()}:${exp.end.toString()}`; + } } diff --git a/src/testRunner/unittests/services/convertToAsyncFunction.ts b/src/testRunner/unittests/services/convertToAsyncFunction.ts index b89e684183b..8c426effa4c 100644 --- a/src/testRunner/unittests/services/convertToAsyncFunction.ts +++ b/src/testRunner/unittests/services/convertToAsyncFunction.ts @@ -255,7 +255,7 @@ interface String { charAt: any; } interface Array {}` }; - function testConvertToAsyncFunction(caption: string, text: string, baselineFolder: string, includeLib?: boolean, expectFailure = false) { + function testConvertToAsyncFunction(caption: string, text: string, baselineFolder: string, includeLib?: boolean, expectFailure = false, onlyProvideAction = false) { const t = extractTest(text); const selectionRange = t.ranges.get("selection")!; if (!selectionRange) { @@ -307,7 +307,7 @@ interface Array {}` const actions = codefix.getFixes(context); const action = find(actions, action => action.description === Diagnostics.Convert_to_async_function.message); - if (expectFailure) { + if (expectFailure && !onlyProvideAction) { assert.isNotTrue(action && action.changes.length > 0); return; } @@ -1151,25 +1151,25 @@ function [#|f|]() { _testConvertToAsyncFunction("convertToAsyncFunction_simpleFunctionExpression", ` const [#|foo|] = function () { return fetch('https://typescriptlang.org').then(result => { console.log(result) }); -} +} `); _testConvertToAsyncFunction("convertToAsyncFunction_simpleFunctionExpressionWithName", ` const foo = function [#|f|]() { return fetch('https://typescriptlang.org').then(result => { console.log(result) }); -} +} `); _testConvertToAsyncFunction("convertToAsyncFunction_simpleFunctionExpressionAssignedToBindingPattern", ` const { length } = [#|function|] () { return fetch('https://typescriptlang.org').then(result => { console.log(result) }); -} +} `); _testConvertToAsyncFunction("convertToAsyncFunction_catchBlockUniqueParams", ` function [#|f|]() { - return Promise.resolve().then(x => 1).catch(x => "a").then(x => !!x); -} + return Promise.resolve().then(x => 1).catch(x => "a").then(x => !!x); +} `); _testConvertToAsyncFunction("convertToAsyncFunction_bindingPattern", ` @@ -1178,7 +1178,7 @@ function [#|f|]() { } function res({ status, trailer }){ console.log(status); -} +} `); _testConvertToAsyncFunction("convertToAsyncFunction_bindingPatternNameCollision", ` @@ -1188,7 +1188,7 @@ function [#|f|]() { } function res({ status, trailer }){ console.log(status); -} +} `); _testConvertToAsyncFunctionFailed("convertToAsyncFunction_thenArgumentNotFunction", ` @@ -1209,7 +1209,7 @@ function [#|f|]() { } function res(result) { return Promise.resolve().then(x => console.log(result)); -} +} `); _testConvertToAsyncFunction("convertToAsyncFunction_callbackReturnsPromise", ` @@ -1241,7 +1241,7 @@ function [#|f|]() { return Promise.resolve(1) .then(x => Promise.reject(x)) .catch(err => console.log(err)); -} +} `); _testConvertToAsyncFunction("convertToAsyncFunction_nestedPromises", ` @@ -1266,6 +1266,22 @@ _testConvertToAsyncFunction("convertToAsyncFunction_exportModifier", ` export function [#|foo|]() { return fetch('https://typescriptlang.org').then(s => console.log(s)); } +`); + +_testConvertToAsyncFunction("convertToAsyncFunction_OutermostOnlySuccess", ` +function [#|foo|]() { + return fetch('a').then(() => { + return fetch('b').then(() => 'c'); + }) +} +`); + +_testConvertToAsyncFunctionFailedSuggestion("convertToAsyncFunction_OutermostOnlyFailure", ` +function foo() { + return fetch('a').then([#|() => {|] + return fetch('b').then(() => 'c'); + }) +} `); }); @@ -1276,4 +1292,8 @@ export function [#|foo|]() { function _testConvertToAsyncFunctionFailed(caption: string, text: string) { testConvertToAsyncFunction(caption, text, "convertToAsyncFunction", /*includeLib*/ true, /*expectFailure*/ true); } + + function _testConvertToAsyncFunctionFailedSuggestion(caption: string, text: string) { + testConvertToAsyncFunction(caption, text, "convertToAsyncFunction", /*includeLib*/ true, /*expectFailure*/ true, /*onlyProvideAction*/ true); + } } diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_OutermostOnlyFailure.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_OutermostOnlyFailure.ts new file mode 100644 index 00000000000..8c3d9745fe8 --- /dev/null +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_OutermostOnlyFailure.ts @@ -0,0 +1,16 @@ +// ==ORIGINAL== + +function foo() { + return fetch('a').then(/*[#|*/() => {/*|]*/ + return fetch('b').then(() => 'c'); + }) +} + +// ==ASYNC FUNCTION::Convert to async function== + +function foo() { + return fetch('a').then(async () => { + await fetch('b'); + return 'c'; + }) +} diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_OutermostOnlySuccess.js b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_OutermostOnlySuccess.js new file mode 100644 index 00000000000..d710dd925f8 --- /dev/null +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_OutermostOnlySuccess.js @@ -0,0 +1,15 @@ +// ==ORIGINAL== + +function /*[#|*/foo/*|]*/() { + return fetch('a').then(() => { + return fetch('b').then(() => 'c'); + }) +} + +// ==ASYNC FUNCTION::Convert to async function== + +async function foo() { + await fetch('a'); + await fetch('b'); + return 'c'; +} diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_OutermostOnlySuccess.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_OutermostOnlySuccess.ts new file mode 100644 index 00000000000..d710dd925f8 --- /dev/null +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_OutermostOnlySuccess.ts @@ -0,0 +1,15 @@ +// ==ORIGINAL== + +function /*[#|*/foo/*|]*/() { + return fetch('a').then(() => { + return fetch('b').then(() => 'c'); + }) +} + +// ==ASYNC FUNCTION::Convert to async function== + +async function foo() { + await fetch('a'); + await fetch('b'); + return 'c'; +} diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_bindingPattern.js b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_bindingPattern.js index f06ce44e78b..45852e51aee 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_bindingPattern.js +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_bindingPattern.js @@ -5,7 +5,7 @@ function /*[#|*/f/*|]*/() { } function res({ status, trailer }){ console.log(status); -} +} // ==ASYNC FUNCTION::Convert to async function== @@ -15,4 +15,4 @@ async function f() { } function res({ status, trailer }){ console.log(status); -} +} diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_bindingPattern.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_bindingPattern.ts index f06ce44e78b..45852e51aee 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_bindingPattern.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_bindingPattern.ts @@ -5,7 +5,7 @@ function /*[#|*/f/*|]*/() { } function res({ status, trailer }){ console.log(status); -} +} // ==ASYNC FUNCTION::Convert to async function== @@ -15,4 +15,4 @@ async function f() { } function res({ status, trailer }){ console.log(status); -} +} diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_bindingPatternNameCollision.js b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_bindingPatternNameCollision.js index 6813472966a..40488dbe73c 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_bindingPatternNameCollision.js +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_bindingPatternNameCollision.js @@ -6,7 +6,7 @@ function /*[#|*/f/*|]*/() { } function res({ status, trailer }){ console.log(status); -} +} // ==ASYNC FUNCTION::Convert to async function== @@ -17,4 +17,4 @@ async function f() { } function res({ status, trailer }){ console.log(status); -} +} diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_bindingPatternNameCollision.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_bindingPatternNameCollision.ts index 6813472966a..40488dbe73c 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_bindingPatternNameCollision.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_bindingPatternNameCollision.ts @@ -6,7 +6,7 @@ function /*[#|*/f/*|]*/() { } function res({ status, trailer }){ console.log(status); -} +} // ==ASYNC FUNCTION::Convert to async function== @@ -17,4 +17,4 @@ async function f() { } function res({ status, trailer }){ console.log(status); -} +} diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_callbackReturnsRejectedPromiseInTryBlock.js b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_callbackReturnsRejectedPromiseInTryBlock.js index 2cfd6ba951e..bbbcee9d86b 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_callbackReturnsRejectedPromiseInTryBlock.js +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_callbackReturnsRejectedPromiseInTryBlock.js @@ -4,7 +4,7 @@ function /*[#|*/f/*|]*/() { return Promise.resolve(1) .then(x => Promise.reject(x)) .catch(err => console.log(err)); -} +} // ==ASYNC FUNCTION::Convert to async function== @@ -16,4 +16,4 @@ async function f() { catch (err) { return console.log(err); } -} +} diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_callbackReturnsRejectedPromiseInTryBlock.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_callbackReturnsRejectedPromiseInTryBlock.ts index 2cfd6ba951e..bbbcee9d86b 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_callbackReturnsRejectedPromiseInTryBlock.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_callbackReturnsRejectedPromiseInTryBlock.ts @@ -4,7 +4,7 @@ function /*[#|*/f/*|]*/() { return Promise.resolve(1) .then(x => Promise.reject(x)) .catch(err => console.log(err)); -} +} // ==ASYNC FUNCTION::Convert to async function== @@ -16,4 +16,4 @@ async function f() { catch (err) { return console.log(err); } -} +} diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_catchBlockUniqueParams.js b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_catchBlockUniqueParams.js index 2600adec16b..fa5d3babf72 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_catchBlockUniqueParams.js +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_catchBlockUniqueParams.js @@ -1,8 +1,8 @@ // ==ORIGINAL== function /*[#|*/f/*|]*/() { - return Promise.resolve().then(x => 1).catch(x => "a").then(x => !!x); -} + return Promise.resolve().then(x => 1).catch(x => "a").then(x => !!x); +} // ==ASYNC FUNCTION::Convert to async function== @@ -15,5 +15,5 @@ async function f() { catch (x_1) { x_2 = "a"; } - return !!x_2; -} + return !!x_2; +} diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_catchBlockUniqueParams.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_catchBlockUniqueParams.ts index 5c4daf076a0..15ec7ce93cf 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_catchBlockUniqueParams.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_catchBlockUniqueParams.ts @@ -1,8 +1,8 @@ // ==ORIGINAL== function /*[#|*/f/*|]*/() { - return Promise.resolve().then(x => 1).catch(x => "a").then(x => !!x); -} + return Promise.resolve().then(x => 1).catch(x => "a").then(x => !!x); +} // ==ASYNC FUNCTION::Convert to async function== @@ -15,5 +15,5 @@ async function f() { catch (x_1) { x_2 = "a"; } - return !!x_2; -} + return !!x_2; +} diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_runEffectfulContinuation.js b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_runEffectfulContinuation.js index 4753c67cdae..ffbf5c4e835 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_runEffectfulContinuation.js +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_runEffectfulContinuation.js @@ -5,7 +5,7 @@ function /*[#|*/f/*|]*/() { } function res(result) { return Promise.resolve().then(x => console.log(result)); -} +} // ==ASYNC FUNCTION::Convert to async function== @@ -16,4 +16,4 @@ async function f() { } function res(result) { return Promise.resolve().then(x => console.log(result)); -} +} diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_runEffectfulContinuation.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_runEffectfulContinuation.ts index 4753c67cdae..ffbf5c4e835 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_runEffectfulContinuation.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_runEffectfulContinuation.ts @@ -5,7 +5,7 @@ function /*[#|*/f/*|]*/() { } function res(result) { return Promise.resolve().then(x => console.log(result)); -} +} // ==ASYNC FUNCTION::Convert to async function== @@ -16,4 +16,4 @@ async function f() { } function res(result) { return Promise.resolve().then(x => console.log(result)); -} +} diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_simpleFunctionExpression.js b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_simpleFunctionExpression.js index a92497ca937..d3696bcf039 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_simpleFunctionExpression.js +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_simpleFunctionExpression.js @@ -2,11 +2,11 @@ const /*[#|*/foo/*|]*/ = function () { return fetch('https://typescriptlang.org').then(result => { console.log(result) }); -} +} // ==ASYNC FUNCTION::Convert to async function== const foo = async function () { const result = await fetch('https://typescriptlang.org'); console.log(result); -} +} diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_simpleFunctionExpression.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_simpleFunctionExpression.ts index a92497ca937..d3696bcf039 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_simpleFunctionExpression.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_simpleFunctionExpression.ts @@ -2,11 +2,11 @@ const /*[#|*/foo/*|]*/ = function () { return fetch('https://typescriptlang.org').then(result => { console.log(result) }); -} +} // ==ASYNC FUNCTION::Convert to async function== const foo = async function () { const result = await fetch('https://typescriptlang.org'); console.log(result); -} +} diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_simpleFunctionExpressionAssignedToBindingPattern.js b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_simpleFunctionExpressionAssignedToBindingPattern.js index b34c369046f..9f108e9e2a4 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_simpleFunctionExpressionAssignedToBindingPattern.js +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_simpleFunctionExpressionAssignedToBindingPattern.js @@ -2,11 +2,11 @@ const { length } = /*[#|*/function/*|]*/ () { return fetch('https://typescriptlang.org').then(result => { console.log(result) }); -} +} // ==ASYNC FUNCTION::Convert to async function== const { length } = async function () { const result = await fetch('https://typescriptlang.org'); console.log(result); -} +} diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_simpleFunctionExpressionAssignedToBindingPattern.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_simpleFunctionExpressionAssignedToBindingPattern.ts index b34c369046f..9f108e9e2a4 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_simpleFunctionExpressionAssignedToBindingPattern.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_simpleFunctionExpressionAssignedToBindingPattern.ts @@ -2,11 +2,11 @@ const { length } = /*[#|*/function/*|]*/ () { return fetch('https://typescriptlang.org').then(result => { console.log(result) }); -} +} // ==ASYNC FUNCTION::Convert to async function== const { length } = async function () { const result = await fetch('https://typescriptlang.org'); console.log(result); -} +} diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_simpleFunctionExpressionWithName.js b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_simpleFunctionExpressionWithName.js index 8316ee98b5b..155f28eae83 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_simpleFunctionExpressionWithName.js +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_simpleFunctionExpressionWithName.js @@ -2,11 +2,11 @@ const foo = function /*[#|*/f/*|]*/() { return fetch('https://typescriptlang.org').then(result => { console.log(result) }); -} +} // ==ASYNC FUNCTION::Convert to async function== const foo = async function f() { const result = await fetch('https://typescriptlang.org'); console.log(result); -} +} diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_simpleFunctionExpressionWithName.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_simpleFunctionExpressionWithName.ts index 8316ee98b5b..155f28eae83 100644 --- a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_simpleFunctionExpressionWithName.ts +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_simpleFunctionExpressionWithName.ts @@ -2,11 +2,11 @@ const foo = function /*[#|*/f/*|]*/() { return fetch('https://typescriptlang.org').then(result => { console.log(result) }); -} +} // ==ASYNC FUNCTION::Convert to async function== const foo = async function f() { const result = await fetch('https://typescriptlang.org'); console.log(result); -} +} From b466336a3e7a9ce91825a370891f5913724f93b6 Mon Sep 17 00:00:00 2001 From: Benjamin Lichtman Date: Mon, 31 Dec 2018 14:04:48 -0800 Subject: [PATCH 35/96] Add class expression to set of nodes for outlining --- src/services/outliningElementsCollector.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/services/outliningElementsCollector.ts b/src/services/outliningElementsCollector.ts index 9d2c61a1a7d..5e3ab31c46a 100644 --- a/src/services/outliningElementsCollector.ts +++ b/src/services/outliningElementsCollector.ts @@ -175,6 +175,7 @@ namespace ts.OutliningElementsCollector { case SyntaxKind.ModuleBlock: return spanForNode(n.parent); case SyntaxKind.ClassDeclaration: + case SyntaxKind.ClassExpression: case SyntaxKind.InterfaceDeclaration: case SyntaxKind.EnumDeclaration: case SyntaxKind.CaseBlock: From adcb27827261ce10ffef6f215515f154fb0c9a9d Mon Sep 17 00:00:00 2001 From: Benjamin Lichtman Date: Mon, 31 Dec 2018 14:11:08 -0800 Subject: [PATCH 36/96] Add test --- tests/cases/fourslash/getOutliningSpans.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/cases/fourslash/getOutliningSpans.ts b/tests/cases/fourslash/getOutliningSpans.ts index f4d1eb33e23..5cc8ea1012c 100644 --- a/tests/cases/fourslash/getOutliningSpans.ts +++ b/tests/cases/fourslash/getOutliningSpans.ts @@ -25,6 +25,12 @@ //// //// }|] ////}|] +////// class expressions +//// (new class[| { +//// bla()[| { +//// +//// }|] +//// }|]) ////switch(1)[| { //// case 1: break; ////}|] From 6c34520281419eeb6c1c3b143c10c9e8b275601b Mon Sep 17 00:00:00 2001 From: Benjamin Lichtman Date: Mon, 31 Dec 2018 14:37:31 -0800 Subject: [PATCH 37/96] Use normal start for spans for args --- src/services/outliningElementsCollector.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/outliningElementsCollector.ts b/src/services/outliningElementsCollector.ts index 9d2c61a1a7d..5337c49a370 100644 --- a/src/services/outliningElementsCollector.ts +++ b/src/services/outliningElementsCollector.ts @@ -206,10 +206,10 @@ namespace ts.OutliningElementsCollector { } function spanForObjectOrArrayLiteral(node: Node, open: SyntaxKind.OpenBraceToken | SyntaxKind.OpenBracketToken = SyntaxKind.OpenBraceToken): OutliningSpan | undefined { - // If the block has no leading keywords and is inside an array literal, + // If the block has no leading keywords and is inside an array literal or call expression, // we only want to collapse the span of the block. // Otherwise, the collapsed section will include the end of the previous line. - return spanForNode(node, /*autoCollapse*/ false, /*useFullStart*/ !isArrayLiteralExpression(node.parent), open); + return spanForNode(node, /*autoCollapse*/ false, /*useFullStart*/ !isArrayLiteralExpression(node.parent) && !isCallExpression(node.parent), open); } function spanForNode(hintSpanNode: Node, autoCollapse = false, useFullStart = true, open: SyntaxKind.OpenBraceToken | SyntaxKind.OpenBracketToken = SyntaxKind.OpenBraceToken): OutliningSpan | undefined { From a2661319288047155a86806a1473b25be94eb643 Mon Sep 17 00:00:00 2001 From: Benjamin Lichtman Date: Mon, 31 Dec 2018 14:43:56 -0800 Subject: [PATCH 38/96] Add test --- tests/cases/fourslash/getOutliningSpans.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/cases/fourslash/getOutliningSpans.ts b/tests/cases/fourslash/getOutliningSpans.ts index f4d1eb33e23..51a181ccfc4 100644 --- a/tests/cases/fourslash/getOutliningSpans.ts +++ b/tests/cases/fourslash/getOutliningSpans.ts @@ -96,5 +96,18 @@ //////outline after a deeply nested node ////class AfterNestedNodes[| { ////}|] +////// function arguments +////function f(x: number[], y: number[])[| { +//// return 3; +////}|] +////f( +////// single line array literal span won't render in VS +//// [|[0]|], +//// [|[ +//// 1, +//// 2 +//// ]|] +////); + verify.outliningSpansInCurrentFile(test.ranges(), "code"); From 34970d8a692f9532af2aff146558f81e94c1cd8f Mon Sep 17 00:00:00 2001 From: Benjamin Lichtman Date: Mon, 31 Dec 2018 15:10:22 -0800 Subject: [PATCH 39/96] give jsdoc outline span before func exp assigned to var --- src/services/outliningElementsCollector.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/services/outliningElementsCollector.ts b/src/services/outliningElementsCollector.ts index 5e3ab31c46a..3f4d345be8c 100644 --- a/src/services/outliningElementsCollector.ts +++ b/src/services/outliningElementsCollector.ts @@ -37,6 +37,10 @@ namespace ts.OutliningElementsCollector { addOutliningForLeadingCommentsForNode(n, sourceFile, cancellationToken, out); } + if (isFunctionExpressionAssignedToVariable(n)) { + addOutliningForLeadingCommentsForNode(n.parent.parent.parent, sourceFile, cancellationToken, out); + } + const span = getOutliningSpanForNode(n, sourceFile); if (span) out.push(span); @@ -54,6 +58,12 @@ namespace ts.OutliningElementsCollector { } depthRemaining++; } + + function isFunctionExpressionAssignedToVariable(n: Node) { + return (isFunctionExpression(n) || isArrowFunction(n)) && + n.parent && n.parent.parent && n.parent.parent.parent && + isVariableStatement(n.parent.parent.parent); + } } function addRegionOutliningSpans(sourceFile: SourceFile, out: Push): void { From bb2f3001917ae61caa2c0a98ac25bea84df0aa9a Mon Sep 17 00:00:00 2001 From: Benjamin Lichtman Date: Mon, 31 Dec 2018 15:15:47 -0800 Subject: [PATCH 40/96] Add test --- tests/cases/fourslash/getOutliningForBlockComments.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/cases/fourslash/getOutliningForBlockComments.ts b/tests/cases/fourslash/getOutliningForBlockComments.ts index 66838d0db75..cc0bbc3c310 100644 --- a/tests/cases/fourslash/getOutliningForBlockComments.ts +++ b/tests/cases/fourslash/getOutliningForBlockComments.ts @@ -99,6 +99,17 @@ //// return 1; //// }|] ////}|] +//// +////// Over a function expression assigned to a variable +//// [|/** +//// * Return a sum +//// * @param {Number} y +//// * @param {Number} z +//// * @returns {Number} the sum of y and z +//// */|] +//// const sum2 = (y, z) =>[| { +//// return y + z; +//// }|]; verify.outliningSpansInCurrentFile(test.ranges()); From 048d04684bd79722c83c42ccf2530e491cde54a9 Mon Sep 17 00:00:00 2001 From: Benjamin Lichtman Date: Mon, 31 Dec 2018 15:56:54 -0800 Subject: [PATCH 41/96] use existing util functions --- src/compiler/utilities.ts | 2 +- src/services/outliningElementsCollector.ts | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 23c92216c56..9c6b27de13c 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2121,7 +2121,7 @@ namespace ts { : undefined; } - function getSingleInitializerOfVariableStatementOrPropertyDeclaration(node: Node): Expression | undefined { + export function getSingleInitializerOfVariableStatementOrPropertyDeclaration(node: Node): Expression | undefined { switch (node.kind) { case SyntaxKind.VariableStatement: const v = getSingleVariableOfVariableStatement(node); diff --git a/src/services/outliningElementsCollector.ts b/src/services/outliningElementsCollector.ts index 3f4d345be8c..c6080277fc7 100644 --- a/src/services/outliningElementsCollector.ts +++ b/src/services/outliningElementsCollector.ts @@ -60,9 +60,11 @@ namespace ts.OutliningElementsCollector { } function isFunctionExpressionAssignedToVariable(n: Node) { - return (isFunctionExpression(n) || isArrowFunction(n)) && - n.parent && n.parent.parent && n.parent.parent.parent && - isVariableStatement(n.parent.parent.parent); + if (!isFunctionExpression(n) && !isArrowFunction(n)) { + return false; + } + const ancestor = findAncestor(n, isVariableStatement); + return !!ancestor && getSingleInitializerOfVariableStatementOrPropertyDeclaration(ancestor) === n; } } From 28e68a68919c1a82ea2a1d78c560768a5b585e73 Mon Sep 17 00:00:00 2001 From: Benjamin Lichtman Date: Mon, 31 Dec 2018 16:00:24 -0800 Subject: [PATCH 42/96] Fix spelling of convertible --- src/services/suggestionDiagnostics.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/services/suggestionDiagnostics.ts b/src/services/suggestionDiagnostics.ts index 6749f56f88a..b6783d79bae 100644 --- a/src/services/suggestionDiagnostics.ts +++ b/src/services/suggestionDiagnostics.ts @@ -117,14 +117,14 @@ namespace ts { } function addConvertToAsyncFunctionDiagnostics(node: FunctionLikeDeclaration, checker: TypeChecker, diags: Push): void { - if (!visitedNestedConvertibleFunctions.has(getKeyFromNode(node)) && isConvertableFunction(node, checker)) { + if (!visitedNestedConvertibleFunctions.has(getKeyFromNode(node)) && isConvertibleFunction(node, checker)) { diags.push(createDiagnosticForNode( !node.name && isVariableDeclaration(node.parent) && isIdentifier(node.parent.name) ? node.parent.name : node, Diagnostics.This_may_be_converted_to_an_async_function)); } } - function isConvertableFunction(node: FunctionLikeDeclaration, checker: TypeChecker) { + function isConvertibleFunction(node: FunctionLikeDeclaration, checker: TypeChecker) { return !isAsyncFunction(node) && node.body && isBlock(node.body) && @@ -179,7 +179,7 @@ namespace ts { case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: - if (isConvertableFunction(arg as FunctionLikeDeclaration, checker)) { + if (isConvertibleFunction(arg as FunctionLikeDeclaration, checker)) { visitedNestedConvertibleFunctions.set(getKeyFromNode(arg as FunctionLikeDeclaration), true); } /* falls through */ From cb57f17aba3d6d5a5e1cb9e2e9ba4d78f4736b7b Mon Sep 17 00:00:00 2001 From: Benjamin Lichtman Date: Mon, 31 Dec 2018 16:25:26 -0800 Subject: [PATCH 43/96] Simplify approach --- .../codefixes/convertToAsyncFunction.ts | 10 ++++---- src/services/suggestionDiagnostics.ts | 25 +++++++++---------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/services/codefixes/convertToAsyncFunction.ts b/src/services/codefixes/convertToAsyncFunction.ts index daf1d89b39a..aae1d205de3 100644 --- a/src/services/codefixes/convertToAsyncFunction.ts +++ b/src/services/codefixes/convertToAsyncFunction.ts @@ -60,7 +60,7 @@ namespace ts.codefix { const setOfExpressionsToReturn = getAllPromiseExpressionsToReturn(functionToConvert, checker); const functionToConvertRenamed = renameCollidingVarNames(functionToConvert, checker, synthNamesMap, context, setOfExpressionsToReturn, originalTypeMap, allVarNames); const constIdentifiers = getConstIdentifiers(synthNamesMap); - const returnStatements = functionToConvertRenamed.body && isBlock(functionToConvertRenamed.body) ? getReturnStatementsWithPromiseHandlers(functionToConvertRenamed.body, checker) : emptyArray; + const returnStatements = functionToConvertRenamed.body && isBlock(functionToConvertRenamed.body) ? getReturnStatementsWithPromiseHandlers(functionToConvertRenamed.body) : emptyArray; const transformer: Transformer = { checker, synthNamesMap, allVarNames, setOfExpressionsToReturn, constIdentifiers, originalTypeMap, isInJSFile: isInJavascript }; if (!returnStatements.length) { @@ -87,10 +87,10 @@ namespace ts.codefix { } } - function getReturnStatementsWithPromiseHandlers(body: Block, checker: TypeChecker): ReadonlyArray { + function getReturnStatementsWithPromiseHandlers(body: Block): ReadonlyArray { const res: ReturnStatement[] = []; forEachReturnStatement(body, ret => { - if (isReturnStatementWithFixablePromiseHandler(ret, checker)) res.push(ret); + if (isReturnStatementWithFixablePromiseHandler(ret)) res.push(ret); }); return res; } @@ -450,7 +450,7 @@ namespace ts.codefix { seenReturnStatement = true; } - if (isReturnStatementWithFixablePromiseHandler(statement, transformer.checker)) { + if (isReturnStatementWithFixablePromiseHandler(statement)) { refactoredStmts = refactoredStmts.concat(getInnerTransformationBody(transformer, [statement], prevArgName)); } else { @@ -466,7 +466,7 @@ namespace ts.codefix { seenReturnStatement); } else { - const innerRetStmts = isFixablePromiseHandler(funcBody, transformer.checker) ? [createReturn(funcBody)] : emptyArray; + const innerRetStmts = isFixablePromiseHandler(funcBody) ? [createReturn(funcBody)] : emptyArray; const innerCbBody = getInnerTransformationBody(transformer, innerRetStmts, prevArgName); if (innerCbBody.length > 0) { diff --git a/src/services/suggestionDiagnostics.ts b/src/services/suggestionDiagnostics.ts index b6783d79bae..63691a72c8b 100644 --- a/src/services/suggestionDiagnostics.ts +++ b/src/services/suggestionDiagnostics.ts @@ -117,7 +117,8 @@ namespace ts { } function addConvertToAsyncFunctionDiagnostics(node: FunctionLikeDeclaration, checker: TypeChecker, diags: Push): void { - if (!visitedNestedConvertibleFunctions.has(getKeyFromNode(node)) && isConvertibleFunction(node, checker)) { + // need to check function before checking map so that deeper levels of nested callbacks are checked + if (isConvertibleFunction(node, checker) && !visitedNestedConvertibleFunctions.has(getKeyFromNode(node))) { diags.push(createDiagnosticForNode( !node.name && isVariableDeclaration(node.parent) && isIdentifier(node.parent.name) ? node.parent.name : node, Diagnostics.This_may_be_converted_to_an_async_function)); @@ -128,7 +129,7 @@ namespace ts { return !isAsyncFunction(node) && node.body && isBlock(node.body) && - hasReturnStatementWithPromiseHandler(node.body, checker) && + hasReturnStatementWithPromiseHandler(node.body) && returnsPromise(node, checker); } @@ -143,25 +144,25 @@ namespace ts { return isBinaryExpression(commonJsModuleIndicator) ? commonJsModuleIndicator.left : commonJsModuleIndicator; } - function hasReturnStatementWithPromiseHandler(body: Block, checker: TypeChecker): boolean { - return !!forEachReturnStatement(body, stmt => isReturnStatementWithFixablePromiseHandler(stmt, checker)); + function hasReturnStatementWithPromiseHandler(body: Block): boolean { + return !!forEachReturnStatement(body, isReturnStatementWithFixablePromiseHandler); } - export function isReturnStatementWithFixablePromiseHandler(node: Node, checker: TypeChecker): node is ReturnStatement { - return isReturnStatement(node) && !!node.expression && isFixablePromiseHandler(node.expression, checker); + export function isReturnStatementWithFixablePromiseHandler(node: Node): node is ReturnStatement { + return isReturnStatement(node) && !!node.expression && isFixablePromiseHandler(node.expression); } // Should be kept up to date with transformExpression in convertToAsyncFunction.ts - export function isFixablePromiseHandler(node: Node, checker: TypeChecker): boolean { + export function isFixablePromiseHandler(node: Node): boolean { // ensure outermost call exists and is a promise handler - if (!isPromiseHandler(node) || !node.arguments.every((arg) => isFixablePromiseArgument(arg, checker))) { + if (!isPromiseHandler(node) || !node.arguments.every(isFixablePromiseArgument)) { return false; } // ensure all chained calls are valid let currentNode = node.expression; while (isPromiseHandler(currentNode) || isPropertyAccessExpression(currentNode)) { - if (isCallExpression(currentNode) && !currentNode.arguments.every(arg => isFixablePromiseArgument(arg, checker))) { + if (isCallExpression(currentNode) && !currentNode.arguments.every(isFixablePromiseArgument)) { return false; } currentNode = currentNode.expression; @@ -174,14 +175,12 @@ namespace ts { } // should be kept up to date with getTransformationBody in convertToAsyncFunction.ts - function isFixablePromiseArgument(arg: Expression, checker: TypeChecker): boolean { + function isFixablePromiseArgument(arg: Expression): boolean { switch (arg.kind) { case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: - if (isConvertibleFunction(arg as FunctionLikeDeclaration, checker)) { - visitedNestedConvertibleFunctions.set(getKeyFromNode(arg as FunctionLikeDeclaration), true); - } + visitedNestedConvertibleFunctions.set(getKeyFromNode(arg as FunctionLikeDeclaration), true); /* falls through */ case SyntaxKind.NullKeyword: case SyntaxKind.Identifier: // identifier includes undefined From 24cc284d19811001183152a4e5782543594fa590 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 2 Jan 2019 15:39:15 -0800 Subject: [PATCH 44/96] The assert that cached value of config file existance is always correct, might not be true if file watcher is not invoked before creating configured project Fixes #29191 --- src/server/editorServices.ts | 3 +- .../unittests/tsserver/externalProjects.ts | 58 +++++++++++++++++++ src/testRunner/unittests/tsserver/helpers.ts | 19 +++++- 3 files changed, 77 insertions(+), 3 deletions(-) diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 3050c976231..a823fe6d586 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -1277,7 +1277,8 @@ namespace ts.server { private setConfigFileExistenceByNewConfiguredProject(project: ConfiguredProject) { const configFileExistenceInfo = this.getConfigFileExistenceInfo(project); if (configFileExistenceInfo) { - Debug.assert(configFileExistenceInfo.exists); + // The existance might not be set if the file watcher is not invoked by the time config project is created by external project + configFileExistenceInfo.exists = true; // close existing watcher if (configFileExistenceInfo.configFileWatcherForRootOfInferredProject) { const configFileName = project.getConfigFilePath(); diff --git a/src/testRunner/unittests/tsserver/externalProjects.ts b/src/testRunner/unittests/tsserver/externalProjects.ts index 12a97151f4e..2055141538a 100644 --- a/src/testRunner/unittests/tsserver/externalProjects.ts +++ b/src/testRunner/unittests/tsserver/externalProjects.ts @@ -760,5 +760,63 @@ namespace ts.projectSystem { assert.equal(project2.pendingReload, ConfigFileProgramReloadLevel.None); // External project referenced configured project loaded checkProjectActualFiles(project2, [config.path, f1.path]); }); + + it("handles creation of external project with jsconfig before jsconfig creation watcher is invoked", () => { + const projectLocation = `/user/username/projects/WebApplication36/WebApplication36`; + const projectFileName = `${projectLocation}/WebApplication36.csproj`; + const tsconfig: File = { + path: `${projectLocation}/tsconfig.json`, + content: "{}" + }; + const files = [libFile, tsconfig]; + const host = createServerHost(files); + const service = createProjectService(host); + + // Create external project + service.openExternalProjects([{ + projectFileName, + rootFiles: [{ fileName: tsconfig.path }], + options: { allowJs: false } + }]); + checkNumberOfProjects(service, { configuredProjects: 1 }); + const configProject = service.configuredProjects.get(tsconfig.path.toLowerCase())!; + checkProjectActualFiles(configProject, [tsconfig.path]); + + // write js file, open external project and open it for edit + const jsFilePath = `${projectLocation}/javascript.js`; + host.writeFile(jsFilePath, ""); + service.openExternalProjects([{ + projectFileName, + rootFiles: [{ fileName: tsconfig.path }, { fileName: jsFilePath }], + options: { allowJs: false } + }]); + service.applyChangesInOpenFiles([ + { fileName: jsFilePath, scriptKind: ScriptKind.JS, content: "" } + ], /*changedFiles*/ undefined, /*closedFiles*/ undefined); + checkNumberOfProjects(service, { configuredProjects: 1, inferredProjects: 1 }); + checkProjectActualFiles(configProject, [tsconfig.path]); + const inferredProject = service.inferredProjects[0]; + checkProjectActualFiles(inferredProject, [libFile.path, jsFilePath]); + + // write jsconfig file + const jsConfig: File = { + path: `${projectLocation}/jsconfig.json`, + content: "{}" + }; + // Dont invoke file creation watchers as the repro suggests + host.ensureFileOrFolder(jsConfig, /*ignoreWatchInvokedWithTriggerAsFileCreate*/ true); + + // Open external project + service.openExternalProjects([{ + projectFileName, + rootFiles: [{ fileName: jsConfig.path }, { fileName: tsconfig.path }, { fileName: jsFilePath }], + options: { allowJs: false } + }]); + checkNumberOfProjects(service, { configuredProjects: 2, inferredProjects: 1 }); + checkProjectActualFiles(configProject, [tsconfig.path]); + assert.isTrue(inferredProject.isOrphan()); + const jsConfigProject = service.configuredProjects.get(jsConfig.path.toLowerCase())!; + checkProjectActualFiles(jsConfigProject, [jsConfig.path, jsFilePath, libFile.path]); + }); }); } diff --git a/src/testRunner/unittests/tsserver/helpers.ts b/src/testRunner/unittests/tsserver/helpers.ts index 1db6a9b36c8..3e79451cd11 100644 --- a/src/testRunner/unittests/tsserver/helpers.ts +++ b/src/testRunner/unittests/tsserver/helpers.ts @@ -57,8 +57,8 @@ namespace ts.projectSystem { export const nullLogger: server.Logger = { close: noop, - hasLevel: () => false, - loggingEnabled: () => false, + hasLevel: returnFalse, + loggingEnabled: returnFalse, perftrc: noop, info: noop, msg: noop, @@ -80,6 +80,21 @@ namespace ts.projectSystem { return { logger, hasErrorMsg: () => hasErrorMsg }; } + export function createLoggerWritingToConsole(): server.Logger { + const { close, startGroup, endGroup, getLogFileName } = nullLogger; + return { + close, + hasLevel: returnTrue, + loggingEnabled: returnTrue, + perftrc: s => console.log(s), + info: s => console.log(s), + msg: (s, type) => console.log(`${type}:: ${s}`), + startGroup, + endGroup, + getLogFileName + }; + } + export class TestTypingsInstaller extends TI.TypingsInstaller implements server.ITypingsInstaller { protected projectService!: server.ProjectService; constructor( From 6a9ad0e2ebbb68dbccc3614d0587a108257d7f59 Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Thu, 3 Jan 2019 16:20:46 +0100 Subject: [PATCH 45/96] Fix crash in organizeImports Fixes: #29236 --- src/services/organizeImports.ts | 11 +++-------- src/testRunner/unittests/services/organizeImports.ts | 10 ++++++++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/services/organizeImports.ts b/src/services/organizeImports.ts index 9c504357102..c2a7ea180bb 100644 --- a/src/services/organizeImports.ts +++ b/src/services/organizeImports.ts @@ -28,12 +28,12 @@ namespace ts.OrganizeImports { organizeImportsWorker(topLevelExportDecls, coalesceExports); for (const ambientModule of sourceFile.statements.filter(isAmbientModule)) { - const ambientModuleBody = getModuleBlock(ambientModule as ModuleDeclaration)!; // TODO: GH#18217 + if (!ambientModule.body) { continue; } - const ambientModuleImportDecls = ambientModuleBody.statements.filter(isImportDeclaration); + const ambientModuleImportDecls = ambientModule.body.statements.filter(isImportDeclaration); organizeImportsWorker(ambientModuleImportDecls, coalesceAndOrganizeImports); - const ambientModuleExportDecls = ambientModuleBody.statements.filter(isExportDeclaration); + const ambientModuleExportDecls = ambientModule.body.statements.filter(isExportDeclaration); organizeImportsWorker(ambientModuleExportDecls, coalesceExports); } @@ -81,11 +81,6 @@ namespace ts.OrganizeImports { } } - function getModuleBlock(moduleDecl: ModuleDeclaration): ModuleBlock | undefined { - const body = moduleDecl.body; - return body && !isIdentifier(body) ? (isModuleBlock(body) ? body : getModuleBlock(body)) : undefined; - } - function removeUnusedImports(oldImports: ReadonlyArray, sourceFile: SourceFile, program: Program) { const typeChecker = program.getTypeChecker(); const jsxNamespace = typeChecker.getJsxNamespace(); diff --git a/src/testRunner/unittests/services/organizeImports.ts b/src/testRunner/unittests/services/organizeImports.ts index 1421780a4b4..d3fe55f9686 100644 --- a/src/testRunner/unittests/services/organizeImports.ts +++ b/src/testRunner/unittests/services/organizeImports.ts @@ -274,6 +274,16 @@ export const Other = 1; assert.isEmpty(changes); }); + it("doesn't crash on shorthand ambient module", () => { + const testFile = { + path: "/a.ts", + content: "declare module '*';", + }; + const languageService = makeLanguageService(testFile); + const changes = languageService.organizeImports({ type: "file", fileName: testFile.path }, testFormatSettings, emptyOptions); + assert.isEmpty(changes); + }); + testOrganizeImports("Renamed_used", { path: "/test.ts", From e68f495b44e7306bd138679cbd7170ffe5def689 Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Thu, 3 Jan 2019 17:51:13 +0100 Subject: [PATCH 46/96] update baselines --- .../reference/iterableArrayPattern28.errors.txt | 1 - .../restParameterWithBindingPattern3.errors.txt | 9 ++++++--- .../reference/restParameterWithBindingPattern3.types | 6 +++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/baselines/reference/iterableArrayPattern28.errors.txt b/tests/baselines/reference/iterableArrayPattern28.errors.txt index 886dce4ca16..f90bba07c1a 100644 --- a/tests/baselines/reference/iterableArrayPattern28.errors.txt +++ b/tests/baselines/reference/iterableArrayPattern28.errors.txt @@ -1,4 +1,3 @@ -tests/cases/conformance/es6/destructuring/iterableArrayPattern28.ts(1,33): error TS2501: A rest element cannot contain a binding pattern. tests/cases/conformance/es6/destructuring/iterableArrayPattern28.ts(2,52): error TS2322: Type 'true' is not assignable to type 'number'. diff --git a/tests/baselines/reference/restParameterWithBindingPattern3.errors.txt b/tests/baselines/reference/restParameterWithBindingPattern3.errors.txt index 2ad62269f50..96f066ca194 100644 --- a/tests/baselines/reference/restParameterWithBindingPattern3.errors.txt +++ b/tests/baselines/reference/restParameterWithBindingPattern3.errors.txt @@ -1,13 +1,14 @@ tests/cases/compiler/restParameterWithBindingPattern3.ts(1,16): error TS2322: Type '1' is not assignable to type 'string'. tests/cases/compiler/restParameterWithBindingPattern3.ts(1,23): error TS2322: Type 'true' is not assignable to type 'string'. tests/cases/compiler/restParameterWithBindingPattern3.ts(3,23): error TS1186: A rest element cannot have an initializer. -tests/cases/compiler/restParameterWithBindingPattern3.ts(7,23): error TS2493: Tuple type '[boolean, string, number]' with length '3' cannot be assigned to tuple with length '4'. +tests/cases/compiler/restParameterWithBindingPattern3.ts(5,30): error TS2493: Tuple type '[boolean, string, number]' of length '3' has no element at index '3'. +tests/cases/compiler/restParameterWithBindingPattern3.ts(7,23): error TS2493: Tuple type '[boolean, string, number]' of length '3' has no element at index '3'. tests/cases/compiler/restParameterWithBindingPattern3.ts(9,19): error TS2322: Type '1' is not assignable to type 'boolean'. tests/cases/compiler/restParameterWithBindingPattern3.ts(9,29): error TS2322: Type 'true' is not assignable to type 'string'. tests/cases/compiler/restParameterWithBindingPattern3.ts(9,48): error TS2566: A rest element cannot have a property name. -==== tests/cases/compiler/restParameterWithBindingPattern3.ts (7 errors) ==== +==== tests/cases/compiler/restParameterWithBindingPattern3.ts (8 errors) ==== function a(...[a = 1, b = true]: string[]) { } ~ !!! error TS2322: Type '1' is not assignable to type 'string'. @@ -19,10 +20,12 @@ tests/cases/compiler/restParameterWithBindingPattern3.ts(9,48): error TS2566: A !!! error TS1186: A rest element cannot have an initializer. function c(...{0: a, length, 3: d}: [boolean, string, number]) { } + ~ +!!! error TS2493: Tuple type '[boolean, string, number]' of length '3' has no element at index '3'. function d(...[a, , , d]: [boolean, string, number]) { } ~ -!!! error TS2493: Tuple type '[boolean, string, number]' with length '3' cannot be assigned to tuple with length '4'. +!!! error TS2493: Tuple type '[boolean, string, number]' of length '3' has no element at index '3'. function e(...{0: a = 1, 1: b = true, ...rest: rest}: [boolean, string, number]) { } ~ diff --git a/tests/baselines/reference/restParameterWithBindingPattern3.types b/tests/baselines/reference/restParameterWithBindingPattern3.types index 95a058dfe5c..1385bde0c3f 100644 --- a/tests/baselines/reference/restParameterWithBindingPattern3.types +++ b/tests/baselines/reference/restParameterWithBindingPattern3.types @@ -15,14 +15,14 @@ function c(...{0: a, length, 3: d}: [boolean, string, number]) { } >c : (__0_0: boolean, __0_1: string, __0_2: number) => void >a : boolean >length : 3 ->d : string | number | boolean +>d : undefined function d(...[a, , , d]: [boolean, string, number]) { } >d : (__0_0: boolean, __0_1: string, __0_2: number) => void >a : boolean > : undefined > : undefined ->d : any +>d : undefined function e(...{0: a = 1, 1: b = true, ...rest: rest}: [boolean, string, number]) { } >e : (__0_0: boolean, __0_1: string, __0_2: number) => void @@ -31,5 +31,5 @@ function e(...{0: a = 1, 1: b = true, ...rest: rest}: [boolean, string, number]) >b : string >true : true >rest : any ->rest : { [n: number]: string | number | boolean; 2: number; length: 3; toString(): string; toLocaleString(): string; pop(): string | number | boolean; push(...items: (string | number | boolean)[]): number; concat(...items: ConcatArray[]): (string | number | boolean)[]; concat(...items: (string | number | boolean | ConcatArray)[]): (string | number | boolean)[]; join(separator?: string): string; reverse(): (string | number | boolean)[]; shift(): string | number | boolean; slice(start?: number, end?: number): (string | number | boolean)[]; sort(compareFn?: (a: string | number | boolean, b: string | number | boolean) => number): [boolean, string, number]; splice(start: number, deleteCount?: number): (string | number | boolean)[]; splice(start: number, deleteCount: number, ...items: (string | number | boolean)[]): (string | number | boolean)[]; unshift(...items: (string | number | boolean)[]): number; indexOf(searchElement: string | number | boolean, fromIndex?: number): number; lastIndexOf(searchElement: string | number | boolean, fromIndex?: number): number; every(callbackfn: (value: string | number | boolean, index: number, array: (string | number | boolean)[]) => boolean, thisArg?: any): boolean; some(callbackfn: (value: string | number | boolean, index: number, array: (string | number | boolean)[]) => boolean, thisArg?: any): boolean; forEach(callbackfn: (value: string | number | boolean, index: number, array: (string | number | boolean)[]) => void, thisArg?: any): void; map(callbackfn: (value: string | number | boolean, index: number, array: (string | number | boolean)[]) => U, thisArg?: any): U[]; filter(callbackfn: (value: string | number | boolean, index: number, array: (string | number | boolean)[]) => value is S, thisArg?: any): S[]; filter(callbackfn: (value: string | number | boolean, index: number, array: (string | number | boolean)[]) => any, thisArg?: any): (string | number | boolean)[]; reduce(callbackfn: (previousValue: string | number | boolean, currentValue: string | number | boolean, currentIndex: number, array: (string | number | boolean)[]) => string | number | boolean): string | number | boolean; reduce(callbackfn: (previousValue: string | number | boolean, currentValue: string | number | boolean, currentIndex: number, array: (string | number | boolean)[]) => string | number | boolean, initialValue: string | number | boolean): string | number | boolean; reduce(callbackfn: (previousValue: U, currentValue: string | number | boolean, currentIndex: number, array: (string | number | boolean)[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: string | number | boolean, currentValue: string | number | boolean, currentIndex: number, array: (string | number | boolean)[]) => string | number | boolean): string | number | boolean; reduceRight(callbackfn: (previousValue: string | number | boolean, currentValue: string | number | boolean, currentIndex: number, array: (string | number | boolean)[]) => string | number | boolean, initialValue: string | number | boolean): string | number | boolean; reduceRight(callbackfn: (previousValue: U, currentValue: string | number | boolean, currentIndex: number, array: (string | number | boolean)[]) => U, initialValue: U): U; } +>rest : { [n: number]: string | number | boolean; 0: boolean; 1: string; 2: number; length: 3; toString(): string; toLocaleString(): string; pop(): string | number | boolean; push(...items: (string | number | boolean)[]): number; concat(...items: ConcatArray[]): (string | number | boolean)[]; concat(...items: (string | number | boolean | ConcatArray)[]): (string | number | boolean)[]; join(separator?: string): string; reverse(): (string | number | boolean)[]; shift(): string | number | boolean; slice(start?: number, end?: number): (string | number | boolean)[]; sort(compareFn?: (a: string | number | boolean, b: string | number | boolean) => number): [boolean, string, number]; splice(start: number, deleteCount?: number): (string | number | boolean)[]; splice(start: number, deleteCount: number, ...items: (string | number | boolean)[]): (string | number | boolean)[]; unshift(...items: (string | number | boolean)[]): number; indexOf(searchElement: string | number | boolean, fromIndex?: number): number; lastIndexOf(searchElement: string | number | boolean, fromIndex?: number): number; every(callbackfn: (value: string | number | boolean, index: number, array: (string | number | boolean)[]) => boolean, thisArg?: any): boolean; some(callbackfn: (value: string | number | boolean, index: number, array: (string | number | boolean)[]) => boolean, thisArg?: any): boolean; forEach(callbackfn: (value: string | number | boolean, index: number, array: (string | number | boolean)[]) => void, thisArg?: any): void; map(callbackfn: (value: string | number | boolean, index: number, array: (string | number | boolean)[]) => U, thisArg?: any): U[]; filter(callbackfn: (value: string | number | boolean, index: number, array: (string | number | boolean)[]) => value is S, thisArg?: any): S[]; filter(callbackfn: (value: string | number | boolean, index: number, array: (string | number | boolean)[]) => any, thisArg?: any): (string | number | boolean)[]; reduce(callbackfn: (previousValue: string | number | boolean, currentValue: string | number | boolean, currentIndex: number, array: (string | number | boolean)[]) => string | number | boolean): string | number | boolean; reduce(callbackfn: (previousValue: string | number | boolean, currentValue: string | number | boolean, currentIndex: number, array: (string | number | boolean)[]) => string | number | boolean, initialValue: string | number | boolean): string | number | boolean; reduce(callbackfn: (previousValue: U, currentValue: string | number | boolean, currentIndex: number, array: (string | number | boolean)[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: string | number | boolean, currentValue: string | number | boolean, currentIndex: number, array: (string | number | boolean)[]) => string | number | boolean): string | number | boolean; reduceRight(callbackfn: (previousValue: string | number | boolean, currentValue: string | number | boolean, currentIndex: number, array: (string | number | boolean)[]) => string | number | boolean, initialValue: string | number | boolean): string | number | boolean; reduceRight(callbackfn: (previousValue: U, currentValue: string | number | boolean, currentIndex: number, array: (string | number | boolean)[]) => U, initialValue: U): U; } From d8ee4116ef0a1e2733c8b4888453257e689bcda3 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 3 Jan 2019 12:46:39 -0800 Subject: [PATCH 47/96] Fix function declaration without body to be checked as context sensitive Fixes #29032 --- src/compiler/checker.ts | 3 +-- ...TypeArgumentInferenceWithMethodWithoutBody.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 tests/cases/fourslash/quickInfoTypeArgumentInferenceWithMethodWithoutBody.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 20e6310f771..54f878ebef0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11040,8 +11040,7 @@ namespace ts { function hasContextSensitiveReturnExpression(node: FunctionLikeDeclaration) { // TODO(anhans): A block should be context-sensitive if it has a context-sensitive return value. - const body = node.body!; - return body.kind === SyntaxKind.Block ? false : isContextSensitive(body); + return !node.body || node.body.kind === SyntaxKind.Block ? false : isContextSensitive(node.body); } function isContextSensitiveFunctionOrObjectLiteralMethod(func: Node): func is FunctionExpression | ArrowFunction | MethodDeclaration { diff --git a/tests/cases/fourslash/quickInfoTypeArgumentInferenceWithMethodWithoutBody.ts b/tests/cases/fourslash/quickInfoTypeArgumentInferenceWithMethodWithoutBody.ts new file mode 100644 index 00000000000..82cdd8882e2 --- /dev/null +++ b/tests/cases/fourslash/quickInfoTypeArgumentInferenceWithMethodWithoutBody.ts @@ -0,0 +1,16 @@ +/// + +////interface ProxyHandler { +//// getPrototypeOf?(target: T): object | null; +////} +////interface ProxyConstructor { +//// new (target: T, handler: ProxyHandler): T; +////} +////declare var Proxy: ProxyConstructor; +////let target = {} +////let proxy = new /**/Proxy(target, { +//// getPrototypeOf() +////}) + +goTo.marker(""); +verify.quickInfoExists(); From f4a6fb79da8eef224ca21046e0cb22d8d44fa012 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 3 Jan 2019 13:29:43 -0800 Subject: [PATCH 48/96] Replace ternary expression --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 54f878ebef0..de44e8bb37c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11040,7 +11040,7 @@ namespace ts { function hasContextSensitiveReturnExpression(node: FunctionLikeDeclaration) { // TODO(anhans): A block should be context-sensitive if it has a context-sensitive return value. - return !node.body || node.body.kind === SyntaxKind.Block ? false : isContextSensitive(node.body); + return !!node.body && node.body.kind !== SyntaxKind.Block && isContextSensitive(node.body); } function isContextSensitiveFunctionOrObjectLiteralMethod(func: Node): func is FunctionExpression | ArrowFunction | MethodDeclaration { From a633f95da7341b476ad84c215b6466e8b6215272 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 3 Jan 2019 14:07:25 -0800 Subject: [PATCH 49/96] Do not cache semantic diagnostics with --isolated modules Fixes #28332 --- src/compiler/builder.ts | 18 ++++-- .../unittests/tscWatch/programUpdates.ts | 56 ++++++++++++++++++- 2 files changed, 66 insertions(+), 8 deletions(-) diff --git a/src/compiler/builder.ts b/src/compiler/builder.ts index 7973a4cc8dd..62dd670fbc5 100644 --- a/src/compiler/builder.ts +++ b/src/compiler/builder.ts @@ -64,7 +64,9 @@ namespace ts { const state = BuilderState.create(newProgram, getCanonicalFileName, oldState) as BuilderProgramState; state.program = newProgram; const compilerOptions = newProgram.getCompilerOptions(); - if (!compilerOptions.outFile && !compilerOptions.out) { + // With --out or --outFile, any change affects all semantic diagnostics so no need to cache them + // With --isolatedModules, emitting changed file doesnt emit dependent files so we cant know of dependent files to retrieve errors so dont cache the errors + if (!compilerOptions.outFile && !compilerOptions.out && !compilerOptions.isolatedModules) { state.semanticDiagnosticsPerFile = createMap>(); } state.changedFilesSet = createMap(); @@ -338,15 +340,19 @@ namespace ts { */ function getSemanticDiagnosticsOfFile(state: BuilderProgramState, sourceFile: SourceFile, cancellationToken?: CancellationToken): ReadonlyArray { const path = sourceFile.path; - const cachedDiagnostics = state.semanticDiagnosticsPerFile!.get(path); - // Report the semantic diagnostics from the cache if we already have those diagnostics present - if (cachedDiagnostics) { - return cachedDiagnostics; + if (state.semanticDiagnosticsPerFile) { + const cachedDiagnostics = state.semanticDiagnosticsPerFile.get(path); + // Report the semantic diagnostics from the cache if we already have those diagnostics present + if (cachedDiagnostics) { + return cachedDiagnostics; + } } // Diagnostics werent cached, get them from program, and cache the result const diagnostics = state.program.getSemanticDiagnostics(sourceFile, cancellationToken); - state.semanticDiagnosticsPerFile!.set(path, diagnostics); + if (state.semanticDiagnosticsPerFile) { + state.semanticDiagnosticsPerFile.set(path, diagnostics); + } return diagnostics; } diff --git a/src/testRunner/unittests/tscWatch/programUpdates.ts b/src/testRunner/unittests/tscWatch/programUpdates.ts index 45ff6fba7c5..b322c08bfe7 100644 --- a/src/testRunner/unittests/tscWatch/programUpdates.ts +++ b/src/testRunner/unittests/tscWatch/programUpdates.ts @@ -1281,7 +1281,59 @@ interface Document { checkProgramActualFiles(watch(), [aFile.path, bFile.path, libFile.path]); } }); + + it("reports errors correctly with isolatedModules", () => { + const currentDirectory = "/user/username/projects/myproject"; + const aFile: File = { + path: `${currentDirectory}/a.ts`, + content: `export const a: string = "";` + }; + const bFile: File = { + path: `${currentDirectory}/b.ts`, + content: `import { a } from "./a"; +const b: string = a;` + }; + const configFile: File = { + path: `${currentDirectory}/tsconfig.json`, + content: JSON.stringify({ + compilerOptions: { + isolatedModules: true + } + }) + }; + + const files = [aFile, bFile, libFile, configFile]; + + const host = createWatchedSystem(files, { currentDirectory }); + const watch = createWatchOfConfigFile("tsconfig.json", host); + verifyProgramFiles(); + checkOutputErrorsInitial(host, emptyArray); + assert.equal(host.readFile(`${currentDirectory}/a.js`), `"use strict"; +exports.__esModule = true; +exports.a = ""; +`, "Contents of a.js"); + assert.equal(host.readFile(`${currentDirectory}/b.js`), `"use strict"; +exports.__esModule = true; +var a_1 = require("./a"); +var b = a_1.a; +`, "Contents of b.js"); + const modifiedTime = host.getModifiedTime(`${currentDirectory}/b.js`); + + host.writeFile(aFile.path, `export const a: number = 1`); + host.runQueuedTimeoutCallbacks(); + verifyProgramFiles(); + checkOutputErrorsIncremental(host, [ + getDiagnosticOfFileFromProgram(watch(), bFile.path, bFile.content.indexOf("b"), 1, Diagnostics.Type_0_is_not_assignable_to_type_1, "number", "string") + ]); + assert.equal(host.readFile(`${currentDirectory}/a.js`), `"use strict"; +exports.__esModule = true; +exports.a = 1; +`, "Contents of a.js"); + assert.equal(host.getModifiedTime(`${currentDirectory}/b.js`), modifiedTime, "Timestamp of b.js"); + + function verifyProgramFiles() { + checkProgramActualFiles(watch(), [aFile.path, bFile.path, libFile.path]); + } + }); }); - - } From 7a2b2cebbf28aed17b1436c0147c87ae7c149af8 Mon Sep 17 00:00:00 2001 From: Martin Probst Date: Fri, 4 Jan 2019 17:13:14 +0100 Subject: [PATCH 50/96] Do not emit code for `@extends` tags in JS. (#29244) When transpiling JavaScript, TS3.1+ emits `@extends` tags as code. E.g. /** @extends {SuperClass} */ class SubClass {} Causes an ES5 emit that references SuperClass: /** * @extends {SomeBase} */ var SubClass = /** @class */ (function (_super) { __extends(SubClass, _super); function SubClass() { return _super !== null && _super.apply(this, arguments) || this; } return SubClass; }(SomeBase)); Note the literal references to `SomeBase`. This appears to be an accidental effect of 0f55566cf4. It refactored `getEffectiveBaseTypeNode` for type checking, but missed an instance where it is also used for emit logic. This change fixes the problem by specifically getting the heritage clauses directly off the AST. Change-Id: I3128a757e5924e2528c61230a90ac13650852542 --- src/compiler/transformers/es2015.ts | 2 +- tests/baselines/reference/extendsJavaScript.js | 18 ++++++++++++++++++ .../reference/extendsJavaScript.symbols | 9 +++++++++ .../reference/extendsJavaScript.types | 9 +++++++++ tests/cases/compiler/extendsJavaScript.ts | 11 +++++++++++ 5 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/extendsJavaScript.js create mode 100644 tests/baselines/reference/extendsJavaScript.symbols create mode 100644 tests/baselines/reference/extendsJavaScript.types create mode 100644 tests/cases/compiler/extendsJavaScript.ts diff --git a/src/compiler/transformers/es2015.ts b/src/compiler/transformers/es2015.ts index 66f635a31e9..6cbd962a816 100644 --- a/src/compiler/transformers/es2015.ts +++ b/src/compiler/transformers/es2015.ts @@ -780,7 +780,7 @@ namespace ts { enableSubstitutionsForBlockScopedBindings(); } - const extendsClauseElement = getEffectiveBaseTypeNode(node); + const extendsClauseElement = getClassExtendsHeritageElement(node); const classFunction = createFunctionExpression( /*modifiers*/ undefined, /*asteriskToken*/ undefined, diff --git a/tests/baselines/reference/extendsJavaScript.js b/tests/baselines/reference/extendsJavaScript.js new file mode 100644 index 00000000000..c9fbdbaf587 --- /dev/null +++ b/tests/baselines/reference/extendsJavaScript.js @@ -0,0 +1,18 @@ +//// [extendsJavaScript.js] +/** + * @extends {SomeBase} + */ +class MyClass { + +} + + +//// [extendsJavaScript.js] +/** + * @extends {SomeBase} + */ +var MyClass = /** @class */ (function () { + function MyClass() { + } + return MyClass; +}()); diff --git a/tests/baselines/reference/extendsJavaScript.symbols b/tests/baselines/reference/extendsJavaScript.symbols new file mode 100644 index 00000000000..db070bf9d6b --- /dev/null +++ b/tests/baselines/reference/extendsJavaScript.symbols @@ -0,0 +1,9 @@ +=== tests/cases/compiler/extendsJavaScript.js === +/** + * @extends {SomeBase} + */ +class MyClass { +>MyClass : Symbol(MyClass, Decl(extendsJavaScript.js, 0, 0)) + +} + diff --git a/tests/baselines/reference/extendsJavaScript.types b/tests/baselines/reference/extendsJavaScript.types new file mode 100644 index 00000000000..e4d34df51aa --- /dev/null +++ b/tests/baselines/reference/extendsJavaScript.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/extendsJavaScript.js === +/** + * @extends {SomeBase} + */ +class MyClass { +>MyClass : MyClass + +} + diff --git a/tests/cases/compiler/extendsJavaScript.ts b/tests/cases/compiler/extendsJavaScript.ts new file mode 100644 index 00000000000..f938bbc9faf --- /dev/null +++ b/tests/cases/compiler/extendsJavaScript.ts @@ -0,0 +1,11 @@ +// @allowJs: true +// @checkJs: false +// @outDir: ./out +// @filename: extendsJavaScript.js + +/** + * @extends {SomeBase} + */ +class MyClass { + +} From dcf825e3cd24c9ec6f06fc6118bd4d4cb0ac831f Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Fri, 4 Jan 2019 12:59:11 -0800 Subject: [PATCH 51/96] Add types entry to tslint build to prevent inclusion of unwanted types installed via user tests --- scripts/tslint/tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/tslint/tsconfig.json b/scripts/tslint/tsconfig.json index 045abc24f6b..e9f90ad4266 100644 --- a/scripts/tslint/tsconfig.json +++ b/scripts/tslint/tsconfig.json @@ -12,6 +12,7 @@ "module": "commonjs", "outDir": "../../built/local/tslint", "baseUrl": "../..", + "types": ["node"], "paths": { "typescript": ["lib/typescript.d.ts"] } From 93249db692ed705327f27c0d81bd997fbf2cc9b6 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 4 Jan 2019 14:07:57 -0800 Subject: [PATCH 52/96] Use the sourceFile to determine the jsxNamespace at the location for organizingImports Fixes #28827 --- src/services/codefixes/importFixes.ts | 2 +- src/services/organizeImports.ts | 2 +- .../unittests/services/organizeImports.ts | 28 +++++++++++++++++++ .../reference/organizeImports/JsxPragmaTsx.ts | 15 ++++++++++ 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/organizeImports/JsxPragmaTsx.ts diff --git a/src/services/codefixes/importFixes.ts b/src/services/codefixes/importFixes.ts index 14bfc8b2761..8006d1a0cfd 100644 --- a/src/services/codefixes/importFixes.ts +++ b/src/services/codefixes/importFixes.ts @@ -375,7 +375,7 @@ namespace ts.codefix { const symbolName = isJsxOpeningLikeElement(symbolToken.parent) && symbolToken.parent.tagName === symbolToken && (isIntrinsicJsxName(symbolToken.text) || checker.resolveName(symbolToken.text, symbolToken, SymbolFlags.All, /*excludeGlobals*/ false)) - ? checker.getJsxNamespace() + ? checker.getJsxNamespace(sourceFile) : symbolToken.text; // "default" is a keyword and not a legal identifier for the import, so we don't expect it here Debug.assert(symbolName !== InternalSymbolName.Default); diff --git a/src/services/organizeImports.ts b/src/services/organizeImports.ts index c2a7ea180bb..157ba98e262 100644 --- a/src/services/organizeImports.ts +++ b/src/services/organizeImports.ts @@ -83,7 +83,7 @@ namespace ts.OrganizeImports { function removeUnusedImports(oldImports: ReadonlyArray, sourceFile: SourceFile, program: Program) { const typeChecker = program.getTypeChecker(); - const jsxNamespace = typeChecker.getJsxNamespace(); + const jsxNamespace = typeChecker.getJsxNamespace(sourceFile); const jsxElementsPresent = !!(sourceFile.transformFlags & TransformFlags.ContainsJsx); const usedImports: ImportDeclaration[] = []; diff --git a/src/testRunner/unittests/services/organizeImports.ts b/src/testRunner/unittests/services/organizeImports.ts index d3fe55f9686..8116b1e268a 100644 --- a/src/testRunner/unittests/services/organizeImports.ts +++ b/src/testRunner/unittests/services/organizeImports.ts @@ -596,6 +596,34 @@ import { React, Other } from "react"; }, reactLibFile); + testOrganizeImports("JsxPragmaTsx", + { + path: "/test.tsx", + content: `/** @jsx jsx */ + +import { Global, jsx } from '@emotion/core'; +import * as React from 'react'; + +export const App: React.FunctionComponent = _ =>

Hello!

+`, + }, + { + path: "/@emotion/core/index.d.ts", + content: `import { createElement } from 'react' +export const jsx: typeof createElement; +export function Global(props: any): ReactElement;` + }, + { + path: reactLibFile.path, + content: `${reactLibFile.content} +export namespace React { + interface FunctionComponent { + } +} +` + } + ); + describe("Exports", () => { testOrganizeExports("MoveToTop", diff --git a/tests/baselines/reference/organizeImports/JsxPragmaTsx.ts b/tests/baselines/reference/organizeImports/JsxPragmaTsx.ts new file mode 100644 index 00000000000..38321115919 --- /dev/null +++ b/tests/baselines/reference/organizeImports/JsxPragmaTsx.ts @@ -0,0 +1,15 @@ +// ==ORIGINAL== +/** @jsx jsx */ + +import { Global, jsx } from '@emotion/core'; +import * as React from 'react'; + +export const App: React.FunctionComponent = _ =>

Hello!

+ +// ==ORGANIZED== +/** @jsx jsx */ + +import { Global, jsx } from '@emotion/core'; +import * as React from 'react'; + +export const App: React.FunctionComponent = _ =>

Hello!

From ec5224f114fa9aed1d231439ac265557603f8972 Mon Sep 17 00:00:00 2001 From: csigs Date: Mon, 7 Jan 2019 16:10:20 +0000 Subject: [PATCH 53/96] LEGO: check in for master to temporary branch. --- .../diagnosticMessages.generated.json.lcl | 6 +- .../diagnosticMessages.generated.json.lcl | 20262 ++++++++-------- 2 files changed, 10134 insertions(+), 10134 deletions(-) diff --git a/src/loc/lcl/cht/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/cht/diagnosticMessages/diagnosticMessages.generated.json.lcl index ec3ab3244b0..32430664b71 100644 --- a/src/loc/lcl/cht/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/cht/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -2083,7 +2083,7 @@ - + @@ -7567,7 +7567,7 @@ - + @@ -9172,7 +9172,7 @@ - + diff --git a/src/loc/lcl/trk/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/trk/diagnosticMessages/diagnosticMessages.generated.json.lcl index 7fade1f0ae3..0b60df175fe 100644 --- a/src/loc/lcl/trk/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/trk/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -1,10132 +1,10132 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - or -. For example '{0}' or '{1}'.]]> - - veya - biçiminde olmalıdır. Örneğin, '{0}' veya '{1}'.]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - type.]]> - - türü olmalıdır.]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ()' instead.]]> - - ()' kullanın.]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + or -. For example '{0}' or '{1}'.]]> + + veya - biçiminde olmalıdır. Örneğin, '{0}' veya '{1}'.]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + type.]]> + + türü olmalıdır.]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ()' instead.]]> + + ()' kullanın.]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 945eed8d9bfd8fd5c2c218c6cb92720bef61e971 Mon Sep 17 00:00:00 2001 From: Alexander T Date: Tue, 8 Jan 2019 10:54:08 +0200 Subject: [PATCH 54/96] PR feedback: change error #2497 message --- src/compiler/checker.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- .../es6ExportEqualsInterop.errors.txt | 36 +++++++++---------- ...EqualsExportModuleCommonJsError.errors.txt | 4 +-- ...rtEqualsExportModuleEs2015Error.errors.txt | 4 +-- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d213e4e01bf..061a6110afc 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2415,7 +2415,7 @@ namespace ts { ? "allowSyntheticDefaultImports" : "esModuleInterop"; - error(referencingLocation, Diagnostics.This_module_can_only_be_imported_with_ECMAScript_imports_by_turning_on_the_0_flag_and_using_a_default_import, compilerOptionName); + error(referencingLocation, Diagnostics.This_module_can_only_be_referenced_with_ECMAScript_imports_Slashexports_by_turning_on_the_0_flag_and_referencing_its_default_export, compilerOptionName); return symbol; } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index cccb3dcb983..136e601dbe8 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1776,7 +1776,7 @@ "category": "Error", "code": 2496 }, - "This module can only be imported with ECMAScript imports by turning on the '{0}' flag and using a default import.": { + "This module can only be referenced with ECMAScript imports/exports by turning on the '{0}' flag and referencing its default export.": { "category": "Error", "code": 2497 }, diff --git a/tests/baselines/reference/es6ExportEqualsInterop.errors.txt b/tests/baselines/reference/es6ExportEqualsInterop.errors.txt index 986aae2245f..5b8e83b3cca 100644 --- a/tests/baselines/reference/es6ExportEqualsInterop.errors.txt +++ b/tests/baselines/reference/es6ExportEqualsInterop.errors.txt @@ -11,24 +11,24 @@ tests/cases/compiler/main.ts(33,8): error TS1192: Module '"function"' has no def tests/cases/compiler/main.ts(34,8): error TS1192: Module '"function-module"' has no default export. tests/cases/compiler/main.ts(35,8): error TS1192: Module '"class"' has no default export. tests/cases/compiler/main.ts(36,8): error TS1192: Module '"class-module"' has no default export. -tests/cases/compiler/main.ts(39,21): error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. -tests/cases/compiler/main.ts(45,21): error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. -tests/cases/compiler/main.ts(47,21): error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. +tests/cases/compiler/main.ts(39,21): error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export. +tests/cases/compiler/main.ts(45,21): error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export. +tests/cases/compiler/main.ts(47,21): error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export. tests/cases/compiler/main.ts(50,1): error TS2693: 'y1' only refers to a type, but is being used as a value here. tests/cases/compiler/main.ts(56,4): error TS2339: Property 'a' does not exist on type '() => any'. tests/cases/compiler/main.ts(58,4): error TS2339: Property 'a' does not exist on type 'typeof Foo'. tests/cases/compiler/main.ts(62,10): error TS2305: Module '"interface"' has no exported member 'a'. -tests/cases/compiler/main.ts(62,25): error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. +tests/cases/compiler/main.ts(62,25): error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export. tests/cases/compiler/main.ts(68,10): error TS2305: Module '"function"' has no exported member 'a'. -tests/cases/compiler/main.ts(68,25): error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. +tests/cases/compiler/main.ts(68,25): error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export. tests/cases/compiler/main.ts(70,10): error TS2305: Module '"class"' has no exported member 'a'. -tests/cases/compiler/main.ts(70,25): error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. +tests/cases/compiler/main.ts(70,25): error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export. tests/cases/compiler/main.ts(85,10): error TS2305: Module '"interface"' has no exported member 'a'. -tests/cases/compiler/main.ts(85,25): error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. +tests/cases/compiler/main.ts(85,25): error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export. tests/cases/compiler/main.ts(91,10): error TS2305: Module '"function"' has no exported member 'a'. -tests/cases/compiler/main.ts(91,25): error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. +tests/cases/compiler/main.ts(91,25): error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export. tests/cases/compiler/main.ts(93,10): error TS2305: Module '"class"' has no exported member 'a'. -tests/cases/compiler/main.ts(93,25): error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. +tests/cases/compiler/main.ts(93,25): error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export. tests/cases/compiler/main.ts(97,15): error TS2498: Module '"interface"' uses 'export =' and cannot be used with 'export *'. tests/cases/compiler/main.ts(98,15): error TS2498: Module '"variable"' uses 'export =' and cannot be used with 'export *'. tests/cases/compiler/main.ts(99,15): error TS2498: Module '"interface-variable"' uses 'export =' and cannot be used with 'export *'. @@ -108,7 +108,7 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses // namespace import import * as y1 from "interface"; ~~~~~~~~~~~ -!!! error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. +!!! error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export. import * as y2 from "variable"; import * as y3 from "interface-variable"; import * as y4 from "module"; @@ -116,11 +116,11 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses import * as y6 from "variable-module"; import * as y7 from "function"; ~~~~~~~~~~ -!!! error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. +!!! error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export. import * as y8 from "function-module"; import * as y9 from "class"; ~~~~~~~ -!!! error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. +!!! error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export. import * as y0 from "class-module"; y1.a; @@ -145,7 +145,7 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses ~ !!! error TS2305: Module '"interface"' has no exported member 'a'. ~~~~~~~~~~~ -!!! error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. +!!! error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export. import { a as a2 } from "variable"; import { a as a3 } from "interface-variable"; import { a as a4 } from "module"; @@ -155,13 +155,13 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses ~ !!! error TS2305: Module '"function"' has no exported member 'a'. ~~~~~~~~~~ -!!! error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. +!!! error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export. import { a as a8 } from "function-module"; import { a as a9 } from "class"; ~ !!! error TS2305: Module '"class"' has no exported member 'a'. ~~~~~~~ -!!! error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. +!!! error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export. import { a as a0 } from "class-module"; a1; @@ -180,7 +180,7 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses ~ !!! error TS2305: Module '"interface"' has no exported member 'a'. ~~~~~~~~~~~ -!!! error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. +!!! error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export. export { a as a2 } from "variable"; export { a as a3 } from "interface-variable"; export { a as a4 } from "module"; @@ -190,13 +190,13 @@ tests/cases/compiler/main.ts(106,15): error TS2498: Module '"class-module"' uses ~ !!! error TS2305: Module '"function"' has no exported member 'a'. ~~~~~~~~~~ -!!! error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. +!!! error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export. export { a as a8 } from "function-module"; export { a as a9 } from "class"; ~ !!! error TS2305: Module '"class"' has no exported member 'a'. ~~~~~~~ -!!! error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. +!!! error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export. export { a as a0 } from "class-module"; // export-star diff --git a/tests/baselines/reference/es6ImportEqualsExportModuleCommonJsError.errors.txt b/tests/baselines/reference/es6ImportEqualsExportModuleCommonJsError.errors.txt index 1c19b4c3104..3d8301d3ca1 100644 --- a/tests/baselines/reference/es6ImportEqualsExportModuleCommonJsError.errors.txt +++ b/tests/baselines/reference/es6ImportEqualsExportModuleCommonJsError.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/main.ts(1,20): error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. +tests/cases/compiler/main.ts(1,20): error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export. ==== tests/cases/compiler/a.ts (0 errors) ==== @@ -8,7 +8,7 @@ tests/cases/compiler/main.ts(1,20): error TS2497: This module can only be import ==== tests/cases/compiler/main.ts (1 errors) ==== import * as a from "./a"; ~~~~~ -!!! error TS2497: This module can only be imported with ECMAScript imports by turning on the 'esModuleInterop' flag and using a default import. +!!! error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export. a; diff --git a/tests/baselines/reference/es6ImportEqualsExportModuleEs2015Error.errors.txt b/tests/baselines/reference/es6ImportEqualsExportModuleEs2015Error.errors.txt index 4aa467f8b6a..94c05e068f5 100644 --- a/tests/baselines/reference/es6ImportEqualsExportModuleEs2015Error.errors.txt +++ b/tests/baselines/reference/es6ImportEqualsExportModuleEs2015Error.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/a.ts(2,1): error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead. -tests/cases/compiler/main.ts(1,20): error TS2497: This module can only be imported with ECMAScript imports by turning on the 'allowSyntheticDefaultImports' flag and using a default import. +tests/cases/compiler/main.ts(1,20): error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'allowSyntheticDefaultImports' flag and referencing its default export. ==== tests/cases/compiler/a.ts (1 errors) ==== @@ -11,7 +11,7 @@ tests/cases/compiler/main.ts(1,20): error TS2497: This module can only be import ==== tests/cases/compiler/main.ts (1 errors) ==== import * as a from "./a"; ~~~~~ -!!! error TS2497: This module can only be imported with ECMAScript imports by turning on the 'allowSyntheticDefaultImports' flag and using a default import. +!!! error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'allowSyntheticDefaultImports' flag and referencing its default export. a; From 19c72c758ae1dcf9eb892ae7927f7b4ab5f0ebd7 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 8 Jan 2019 11:05:55 -0800 Subject: [PATCH 55/96] Allow untyped calls on unions of untyped things (#29265) --- src/compiler/checker.ts | 6 +-- .../unionOfFunctionAndSignatureIsCallable.js | 25 +++++++++++ ...onOfFunctionAndSignatureIsCallable.symbols | 38 ++++++++++++++++ ...nionOfFunctionAndSignatureIsCallable.types | 45 +++++++++++++++++++ .../unionOfFunctionAndSignatureIsCallable.ts | 11 +++++ 5 files changed, 122 insertions(+), 3 deletions(-) create mode 100644 tests/baselines/reference/unionOfFunctionAndSignatureIsCallable.js create mode 100644 tests/baselines/reference/unionOfFunctionAndSignatureIsCallable.symbols create mode 100644 tests/baselines/reference/unionOfFunctionAndSignatureIsCallable.types create mode 100644 tests/cases/compiler/unionOfFunctionAndSignatureIsCallable.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index de44e8bb37c..86822e24878 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6930,7 +6930,7 @@ namespace ts { function resolveUnionTypeMembers(type: UnionType) { // The members and properties collections are empty for union types. To get all properties of a union // type use getPropertiesOfType (only the language service uses this). - const callSignatures = getUnionSignatures(map(type.types, t => getSignaturesOfType(t, SignatureKind.Call))); + const callSignatures = getUnionSignatures(map(type.types, t => t === globalFunctionType ? [unknownSignature] : getSignaturesOfType(t, SignatureKind.Call))); const constructSignatures = getUnionSignatures(map(type.types, t => getSignaturesOfType(t, SignatureKind.Construct))); const stringIndexInfo = getUnionIndexInfo(type.types, IndexKind.String); const numberIndexInfo = getUnionIndexInfo(type.types, IndexKind.Number); @@ -20506,9 +20506,9 @@ namespace ts { * If FuncExpr is of type Any, or of an object type that has no call or construct signatures * but is a subtype of the Function interface, the call is an untyped function call. */ - function isUntypedFunctionCall(funcType: Type, apparentFuncType: Type, numCallSignatures: number, numConstructSignatures: number) { + function isUntypedFunctionCall(funcType: Type, apparentFuncType: Type, numCallSignatures: number, numConstructSignatures: number): boolean { // We exclude union types because we may have a union of function types that happen to have no common signatures. - return isTypeAny(funcType) || isTypeAny(apparentFuncType) && funcType.flags & TypeFlags.TypeParameter || + return isTypeAny(funcType) || isTypeAny(apparentFuncType) && !!(funcType.flags & TypeFlags.TypeParameter) || !numCallSignatures && !numConstructSignatures && !(apparentFuncType.flags & (TypeFlags.Union | TypeFlags.Never)) && isTypeAssignableTo(funcType, globalFunctionType); } diff --git a/tests/baselines/reference/unionOfFunctionAndSignatureIsCallable.js b/tests/baselines/reference/unionOfFunctionAndSignatureIsCallable.js new file mode 100644 index 00000000000..eb3e073eec6 --- /dev/null +++ b/tests/baselines/reference/unionOfFunctionAndSignatureIsCallable.js @@ -0,0 +1,25 @@ +//// [unionOfFunctionAndSignatureIsCallable.ts] +function f1(c1: Function, c2: () => object, callable: typeof c1 | typeof c2) { + const a = c1(); + const b = c2(); + const c = callable(); +} + +function f2(fetcherParams: object | (() => object)) { + const data = typeof fetcherParams === 'function' + ? fetcherParams() + : fetcherParams +} + + +//// [unionOfFunctionAndSignatureIsCallable.js] +function f1(c1, c2, callable) { + var a = c1(); + var b = c2(); + var c = callable(); +} +function f2(fetcherParams) { + var data = typeof fetcherParams === 'function' + ? fetcherParams() + : fetcherParams; +} diff --git a/tests/baselines/reference/unionOfFunctionAndSignatureIsCallable.symbols b/tests/baselines/reference/unionOfFunctionAndSignatureIsCallable.symbols new file mode 100644 index 00000000000..0ab573e4297 --- /dev/null +++ b/tests/baselines/reference/unionOfFunctionAndSignatureIsCallable.symbols @@ -0,0 +1,38 @@ +=== tests/cases/compiler/unionOfFunctionAndSignatureIsCallable.ts === +function f1(c1: Function, c2: () => object, callable: typeof c1 | typeof c2) { +>f1 : Symbol(f1, Decl(unionOfFunctionAndSignatureIsCallable.ts, 0, 0)) +>c1 : Symbol(c1, Decl(unionOfFunctionAndSignatureIsCallable.ts, 0, 12)) +>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>c2 : Symbol(c2, Decl(unionOfFunctionAndSignatureIsCallable.ts, 0, 25)) +>callable : Symbol(callable, Decl(unionOfFunctionAndSignatureIsCallable.ts, 0, 43)) +>c1 : Symbol(c1, Decl(unionOfFunctionAndSignatureIsCallable.ts, 0, 12)) +>c2 : Symbol(c2, Decl(unionOfFunctionAndSignatureIsCallable.ts, 0, 25)) + + const a = c1(); +>a : Symbol(a, Decl(unionOfFunctionAndSignatureIsCallable.ts, 1, 9)) +>c1 : Symbol(c1, Decl(unionOfFunctionAndSignatureIsCallable.ts, 0, 12)) + + const b = c2(); +>b : Symbol(b, Decl(unionOfFunctionAndSignatureIsCallable.ts, 2, 9)) +>c2 : Symbol(c2, Decl(unionOfFunctionAndSignatureIsCallable.ts, 0, 25)) + + const c = callable(); +>c : Symbol(c, Decl(unionOfFunctionAndSignatureIsCallable.ts, 3, 9)) +>callable : Symbol(callable, Decl(unionOfFunctionAndSignatureIsCallable.ts, 0, 43)) +} + +function f2(fetcherParams: object | (() => object)) { +>f2 : Symbol(f2, Decl(unionOfFunctionAndSignatureIsCallable.ts, 4, 1)) +>fetcherParams : Symbol(fetcherParams, Decl(unionOfFunctionAndSignatureIsCallable.ts, 6, 12)) + + const data = typeof fetcherParams === 'function' +>data : Symbol(data, Decl(unionOfFunctionAndSignatureIsCallable.ts, 7, 9)) +>fetcherParams : Symbol(fetcherParams, Decl(unionOfFunctionAndSignatureIsCallable.ts, 6, 12)) + + ? fetcherParams() +>fetcherParams : Symbol(fetcherParams, Decl(unionOfFunctionAndSignatureIsCallable.ts, 6, 12)) + + : fetcherParams +>fetcherParams : Symbol(fetcherParams, Decl(unionOfFunctionAndSignatureIsCallable.ts, 6, 12)) +} + diff --git a/tests/baselines/reference/unionOfFunctionAndSignatureIsCallable.types b/tests/baselines/reference/unionOfFunctionAndSignatureIsCallable.types new file mode 100644 index 00000000000..96e49d80d50 --- /dev/null +++ b/tests/baselines/reference/unionOfFunctionAndSignatureIsCallable.types @@ -0,0 +1,45 @@ +=== tests/cases/compiler/unionOfFunctionAndSignatureIsCallable.ts === +function f1(c1: Function, c2: () => object, callable: typeof c1 | typeof c2) { +>f1 : (c1: Function, c2: () => object, callable: Function | (() => object)) => void +>c1 : Function +>c2 : () => object +>callable : Function | (() => object) +>c1 : Function +>c2 : () => object + + const a = c1(); +>a : any +>c1() : any +>c1 : Function + + const b = c2(); +>b : object +>c2() : object +>c2 : () => object + + const c = callable(); +>c : any +>callable() : any +>callable : Function | (() => object) +} + +function f2(fetcherParams: object | (() => object)) { +>f2 : (fetcherParams: object | (() => object)) => void +>fetcherParams : object | (() => object) + + const data = typeof fetcherParams === 'function' +>data : any +>typeof fetcherParams === 'function' ? fetcherParams() : fetcherParams : any +>typeof fetcherParams === 'function' : boolean +>typeof fetcherParams : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" +>fetcherParams : object | (() => object) +>'function' : "function" + + ? fetcherParams() +>fetcherParams() : any +>fetcherParams : Function | (() => object) + + : fetcherParams +>fetcherParams : object +} + diff --git a/tests/cases/compiler/unionOfFunctionAndSignatureIsCallable.ts b/tests/cases/compiler/unionOfFunctionAndSignatureIsCallable.ts new file mode 100644 index 00000000000..8555ed715cd --- /dev/null +++ b/tests/cases/compiler/unionOfFunctionAndSignatureIsCallable.ts @@ -0,0 +1,11 @@ +function f1(c1: Function, c2: () => object, callable: typeof c1 | typeof c2) { + const a = c1(); + const b = c2(); + const c = callable(); +} + +function f2(fetcherParams: object | (() => object)) { + const data = typeof fetcherParams === 'function' + ? fetcherParams() + : fetcherParams +} From ad85e4fd22ee3870a5b9ed0ec830828b36ed22fa Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 8 Jan 2019 11:20:54 -0800 Subject: [PATCH 56/96] Fix gulp baseline-accept (#29301) * Fix gulp baseline-accept I think it was ported incorrectly from jake and then never used. * Re-add read:false to baselineDelete --- scripts/build/baselineAccept.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/build/baselineAccept.js b/scripts/build/baselineAccept.js index 4710161027e..df61b87cd32 100644 --- a/scripts/build/baselineAccept.js +++ b/scripts/build/baselineAccept.js @@ -12,7 +12,7 @@ function baselineAccept(subfolder = "") { } function baselineCopy(subfolder = "") { - return gulp.src([`${localBaseline}${subfolder ? `${subfolder}/` : ``}**`, `!${localBaseline}${subfolder}/**/*.delete`], { base: localBaseline, read: false }) + return gulp.src([`${localBaseline}${subfolder ? `${subfolder}/` : ``}**`, `!${localBaseline}${subfolder}/**/*.delete`], { base: localBaseline }) .pipe(gulp.dest(refBaseline)); } @@ -21,4 +21,4 @@ function baselineDelete(subfolder = "") { .pipe(rm()) .pipe(rename({ extname: "" })) .pipe(rm(refBaseline)); -} \ No newline at end of file +} From 08f738fc426fb0cad970bd70397c780514c2857d Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 8 Jan 2019 15:18:52 -0800 Subject: [PATCH 57/96] There is no need to check for file presence when trying to rename imports based on file rename Fixes #29031 --- src/services/getEditsForFileRename.ts | 31 ++++++++++++++++----------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/services/getEditsForFileRename.ts b/src/services/getEditsForFileRename.ts index ae031da5728..66cc88c2677 100644 --- a/src/services/getEditsForFileRename.ts +++ b/src/services/getEditsForFileRename.ts @@ -151,7 +151,7 @@ namespace ts { const toImport = oldFromNew !== undefined // If we're at the new location (file was already renamed), need to redo module resolution starting from the old location. // TODO:GH#18217 - ? getSourceFileToImportFromResolved(resolveModuleName(importLiteral.text, oldImportFromPath, program.getCompilerOptions(), host as ModuleResolutionHost), oldToNew, host) + ? getSourceFileToImportFromResolved(resolveModuleName(importLiteral.text, oldImportFromPath, program.getCompilerOptions(), host as ModuleResolutionHost), oldToNew) : getSourceFileToImport(importedModuleSymbol, importLiteral, sourceFile, program, host, oldToNew); // Need an update if the imported file moved, or the importing file moved and was using a relative path. @@ -192,28 +192,35 @@ namespace ts { const resolved = host.resolveModuleNames ? host.getResolvedModuleWithFailedLookupLocationsFromCache && host.getResolvedModuleWithFailedLookupLocationsFromCache(importLiteral.text, importingSourceFile.fileName) : program.getResolvedModuleWithFailedLookupLocationsFromCache(importLiteral.text, importingSourceFile.fileName); - return getSourceFileToImportFromResolved(resolved, oldToNew, host); + return getSourceFileToImportFromResolved(resolved, oldToNew); } } - function getSourceFileToImportFromResolved(resolved: ResolvedModuleWithFailedLookupLocations | undefined, oldToNew: PathUpdater, host: LanguageServiceHost): ToImport | undefined { + function getSourceFileToImportFromResolved(resolved: ResolvedModuleWithFailedLookupLocations | undefined, oldToNew: PathUpdater): ToImport | undefined { // Search through all locations looking for a moved file, and only then test already existing files. // This is because if `a.ts` is compiled to `a.js` and `a.ts` is moved, we don't want to resolve anything to `a.js`, but to `a.ts`'s new location. - return tryEach(tryGetNewFile) || tryEach(tryGetOldFile); + if (!resolved) return undefined; - function tryEach(cb: (oldFileName: string) => ToImport | undefined): ToImport | undefined { - return resolved && ( - (resolved.resolvedModule && cb(resolved.resolvedModule.resolvedFileName)) || firstDefined(resolved.failedLookupLocations, cb)); + // First try resolved module + if (resolved.resolvedModule) { + const result = tryChange(resolved.resolvedModule.resolvedFileName); + if (result) return result; } - function tryGetNewFile(oldFileName: string): ToImport | undefined { - const newFileName = oldToNew(oldFileName); - return newFileName !== undefined && host.fileExists!(newFileName) ? { newFileName, updated: true } : undefined; // TODO: GH#18217 + // Then failed lookups except package.json since we dont want to touch them (only included ts/js files) + const result = forEach(resolved.failedLookupLocations, tryChangeWithIgnoringPackageJson); + if (result) return result; + + // If nothing changed, then result is resolved module file thats not updated + return resolved.resolvedModule && { newFileName: resolved.resolvedModule.resolvedFileName, updated: false }; + + function tryChangeWithIgnoringPackageJson(oldFileName: string) { + return !endsWith(oldFileName, "/package.json") ? tryChange(oldFileName) : undefined; } - function tryGetOldFile(oldFileName: string): ToImport | undefined { + function tryChange(oldFileName: string) { const newFileName = oldToNew(oldFileName); - return host.fileExists!(oldFileName) ? newFileName !== undefined ? { newFileName, updated: true } : { newFileName: oldFileName, updated: false } : undefined; // TODO: GH#18217 + return newFileName && { newFileName, updated: true }; } } From 76c9d9f71758b31c885bef994311bf90928503c7 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 8 Jan 2019 16:08:43 -0800 Subject: [PATCH 58/96] Fix the failing test case --- src/testRunner/unittests/tsserver/refactors.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/testRunner/unittests/tsserver/refactors.ts b/src/testRunner/unittests/tsserver/refactors.ts index 31603ded8cd..04eb552c316 100644 --- a/src/testRunner/unittests/tsserver/refactors.ts +++ b/src/testRunner/unittests/tsserver/refactors.ts @@ -144,7 +144,7 @@ namespace ts.projectSystem { }, { fileName: "/Foo/x.ts", - textChanges: [{ start: { line: 0, offset: 0 }, end: { line: 0, offset: 0 }, newText: "const x = 0;" }], + textChanges: [{ start: { line: 0, offset: 0 }, end: { line: 0, offset: 0 }, newText: "const x = 0;\n" }], }, ], renameFilename: undefined, From 46482e14a46bfe1f5fb27255369ccd378aa41da9 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 8 Jan 2019 16:21:46 -0800 Subject: [PATCH 59/96] Verify that completion with new identifier location returns isNewIdentifierLocation: true Fixes #24009 Signed-off-by: Sheetal Nandi --- completionAtDottedNamespace.ts | 5 +++++ src/services/completions.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 completionAtDottedNamespace.ts diff --git a/completionAtDottedNamespace.ts b/completionAtDottedNamespace.ts new file mode 100644 index 00000000000..cbf16435a91 --- /dev/null +++ b/completionAtDottedNamespace.ts @@ -0,0 +1,5 @@ +/// + +////namespace wwer./**/w + +verify.completions({ marker: "", exact: [], isNewIdentifierLocation: true }); diff --git a/src/services/completions.ts b/src/services/completions.ts index bbcee4dd47e..8203b66549b 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -104,7 +104,7 @@ namespace ts.Completions { getJSCompletionEntries(sourceFile, location!.pos, uniqueNames, compilerOptions.target!, entries); // TODO: GH#18217 } else { - if ((!symbols || symbols.length === 0) && keywordFilters === KeywordCompletionFilters.None) { + if (!isNewIdentifierLocation && (!symbols || symbols.length === 0) && keywordFilters === KeywordCompletionFilters.None) { return undefined; } From 3f5c0b81a3b641d14c13bd27187f44ff637c270a Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 9 Jan 2019 10:28:53 -0800 Subject: [PATCH 60/96] Fix existing test --- tests/cases/fourslash/completionListBuilderLocations_Modules.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cases/fourslash/completionListBuilderLocations_Modules.ts b/tests/cases/fourslash/completionListBuilderLocations_Modules.ts index a98d65e255d..29530ccbdef 100644 --- a/tests/cases/fourslash/completionListBuilderLocations_Modules.ts +++ b/tests/cases/fourslash/completionListBuilderLocations_Modules.ts @@ -7,5 +7,5 @@ verify.completions( { marker: "moduleName1", exact: completion.globals, isNewIdentifierLocation: true }, - { marker: "moduleName2", exact: undefined }, + { marker: "moduleName2", exact: [], isNewIdentifierLocation: true }, ); From b52a7fc3eaea93574626b8cf5e47f205dae2a428 Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Wed, 9 Jan 2019 19:35:22 +0100 Subject: [PATCH 61/96] Exclude JSDoc @extends from 'super()' checks (#29308) * Exclude JSDoc @extends from 'super()' checks This fixes a similar problem as #29244 where JSDoc `@extends` * fix check 'super can only be referenced in a derived class' --- src/compiler/checker.ts | 6 ++-- ...ckSuperCallBeforeThisAccessing9.errors.txt | 22 ++++++++++++ ...checkSuperCallBeforeThisAccessing9.symbols | 31 ++++++++++++++++ .../checkSuperCallBeforeThisAccessing9.types | 35 +++++++++++++++++++ .../checkSuperCallBeforeThisAccessing9.ts | 21 +++++++++++ 5 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing9.errors.txt create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing9.symbols create mode 100644 tests/baselines/reference/checkSuperCallBeforeThisAccessing9.types create mode 100644 tests/cases/compiler/checkSuperCallBeforeThisAccessing9.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 86822e24878..41f4d8bef68 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16625,7 +16625,7 @@ namespace ts { function checkThisBeforeSuper(node: Node, container: Node, diagnosticMessage: DiagnosticMessage) { const containingClassDecl = container.parent; - const baseTypeNode = getEffectiveBaseTypeNode(containingClassDecl); + const baseTypeNode = getClassExtendsHeritageElement(containingClassDecl); // If a containing class does not have extends clause or the class extends null // skip checking whether super statement is called before "this" accessing. @@ -16974,7 +16974,7 @@ namespace ts { // at this point the only legal case for parent is ClassLikeDeclaration const classLikeDeclaration = container.parent; - if (!getEffectiveBaseTypeNode(classLikeDeclaration)) { + if (!getClassExtendsHeritageElement(classLikeDeclaration)) { error(node, Diagnostics.super_can_only_be_referenced_in_a_derived_class); return errorType; } @@ -23575,7 +23575,7 @@ namespace ts { // Constructors of classes with no extends clause may not contain super calls, whereas // constructors of derived classes must contain at least one super call somewhere in their function body. const containingClassDecl = node.parent; - if (getEffectiveBaseTypeNode(containingClassDecl)) { + if (getClassExtendsHeritageElement(containingClassDecl)) { captureLexicalThis(node.parent, containingClassDecl); const classExtendsNull = classDeclarationExtendsNull(containingClassDecl); const superCall = getSuperCallInConstructor(node); diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing9.errors.txt b/tests/baselines/reference/checkSuperCallBeforeThisAccessing9.errors.txt new file mode 100644 index 00000000000..5d67f88c847 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing9.errors.txt @@ -0,0 +1,22 @@ +tests/cases/compiler/noSuperInJSDocExtends.js(14,9): error TS2335: 'super' can only be referenced in a derived class. + + +==== tests/cases/compiler/noSuperInJSDocExtends.js (1 errors) ==== + class Based { } + /** @extends {Based} */ + class Derived { + constructor() { + this; + this.x = 10; + var that = this; + } + } + + /** @extends {Based} */ + class Derived2 { + constructor() { + super(); + ~~~~~ +!!! error TS2335: 'super' can only be referenced in a derived class. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing9.symbols b/tests/baselines/reference/checkSuperCallBeforeThisAccessing9.symbols new file mode 100644 index 00000000000..f900a4986eb --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing9.symbols @@ -0,0 +1,31 @@ +=== tests/cases/compiler/noSuperInJSDocExtends.js === +class Based { } +>Based : Symbol(Based, Decl(noSuperInJSDocExtends.js, 0, 0)) + +/** @extends {Based} */ +class Derived { +>Derived : Symbol(Derived, Decl(noSuperInJSDocExtends.js, 0, 15)) + + constructor() { + this; +>this : Symbol(Derived, Decl(noSuperInJSDocExtends.js, 0, 15)) + + this.x = 10; +>this.x : Symbol(Derived.x, Decl(noSuperInJSDocExtends.js, 4, 13)) +>this : Symbol(Derived, Decl(noSuperInJSDocExtends.js, 0, 15)) +>x : Symbol(Derived.x, Decl(noSuperInJSDocExtends.js, 4, 13)) + + var that = this; +>that : Symbol(that, Decl(noSuperInJSDocExtends.js, 6, 11)) +>this : Symbol(Derived, Decl(noSuperInJSDocExtends.js, 0, 15)) + } +} + +/** @extends {Based} */ +class Derived2 { +>Derived2 : Symbol(Derived2, Decl(noSuperInJSDocExtends.js, 8, 1)) + + constructor() { + super(); + } +} diff --git a/tests/baselines/reference/checkSuperCallBeforeThisAccessing9.types b/tests/baselines/reference/checkSuperCallBeforeThisAccessing9.types new file mode 100644 index 00000000000..577256400b2 --- /dev/null +++ b/tests/baselines/reference/checkSuperCallBeforeThisAccessing9.types @@ -0,0 +1,35 @@ +=== tests/cases/compiler/noSuperInJSDocExtends.js === +class Based { } +>Based : Based + +/** @extends {Based} */ +class Derived { +>Derived : Derived + + constructor() { + this; +>this : this + + this.x = 10; +>this.x = 10 : 10 +>this.x : number +>this : this +>x : number +>10 : 10 + + var that = this; +>that : this +>this : this + } +} + +/** @extends {Based} */ +class Derived2 { +>Derived2 : Derived2 + + constructor() { + super(); +>super() : void +>super : any + } +} diff --git a/tests/cases/compiler/checkSuperCallBeforeThisAccessing9.ts b/tests/cases/compiler/checkSuperCallBeforeThisAccessing9.ts new file mode 100644 index 00000000000..a6b7102b2a5 --- /dev/null +++ b/tests/cases/compiler/checkSuperCallBeforeThisAccessing9.ts @@ -0,0 +1,21 @@ +// @allowJs: true +// @checkJs: true +// @noEmit: true + +// @filename: noSuperInJSDocExtends.js +class Based { } +/** @extends {Based} */ +class Derived { + constructor() { + this; + this.x = 10; + var that = this; + } +} + +/** @extends {Based} */ +class Derived2 { + constructor() { + super(); + } +} \ No newline at end of file From d0aff9bdcd95ee5ed260a6ab21137e9e220c9895 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 9 Jan 2019 14:23:57 -0800 Subject: [PATCH 62/96] Fix crash (#29333) --- src/compiler/transformers/ts.ts | 1 + ...decoratorWithNegativeLiteralTypeNoCrash.js | 28 +++++++++++++++++++ ...atorWithNegativeLiteralTypeNoCrash.symbols | 15 ++++++++++ ...oratorWithNegativeLiteralTypeNoCrash.types | 19 +++++++++++++ ...decoratorWithNegativeLiteralTypeNoCrash.ts | 8 ++++++ 5 files changed, 71 insertions(+) create mode 100644 tests/baselines/reference/decoratorWithNegativeLiteralTypeNoCrash.js create mode 100644 tests/baselines/reference/decoratorWithNegativeLiteralTypeNoCrash.symbols create mode 100644 tests/baselines/reference/decoratorWithNegativeLiteralTypeNoCrash.types create mode 100644 tests/cases/compiler/decoratorWithNegativeLiteralTypeNoCrash.ts diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 700c0c8af25..a22c6df8d06 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -1898,6 +1898,7 @@ namespace ts { case SyntaxKind.StringLiteral: return createIdentifier("String"); + case SyntaxKind.PrefixUnaryExpression: case SyntaxKind.NumericLiteral: return createIdentifier("Number"); diff --git a/tests/baselines/reference/decoratorWithNegativeLiteralTypeNoCrash.js b/tests/baselines/reference/decoratorWithNegativeLiteralTypeNoCrash.js new file mode 100644 index 00000000000..57b548cdf99 --- /dev/null +++ b/tests/baselines/reference/decoratorWithNegativeLiteralTypeNoCrash.js @@ -0,0 +1,28 @@ +//// [decoratorWithNegativeLiteralTypeNoCrash.ts] +class A { + @decorator + public field1: -1 = -1; +} +function decorator(target: any, field: any) {} + +//// [decoratorWithNegativeLiteralTypeNoCrash.js] +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +var A = /** @class */ (function () { + function A() { + this.field1 = -1; + } + __decorate([ + decorator, + __metadata("design:type", Number) + ], A.prototype, "field1", void 0); + return A; +}()); +function decorator(target, field) { } diff --git a/tests/baselines/reference/decoratorWithNegativeLiteralTypeNoCrash.symbols b/tests/baselines/reference/decoratorWithNegativeLiteralTypeNoCrash.symbols new file mode 100644 index 00000000000..e89854249a0 --- /dev/null +++ b/tests/baselines/reference/decoratorWithNegativeLiteralTypeNoCrash.symbols @@ -0,0 +1,15 @@ +=== tests/cases/compiler/decoratorWithNegativeLiteralTypeNoCrash.ts === +class A { +>A : Symbol(A, Decl(decoratorWithNegativeLiteralTypeNoCrash.ts, 0, 0)) + + @decorator +>decorator : Symbol(decorator, Decl(decoratorWithNegativeLiteralTypeNoCrash.ts, 3, 1)) + + public field1: -1 = -1; +>field1 : Symbol(A.field1, Decl(decoratorWithNegativeLiteralTypeNoCrash.ts, 0, 9)) +} +function decorator(target: any, field: any) {} +>decorator : Symbol(decorator, Decl(decoratorWithNegativeLiteralTypeNoCrash.ts, 3, 1)) +>target : Symbol(target, Decl(decoratorWithNegativeLiteralTypeNoCrash.ts, 4, 19)) +>field : Symbol(field, Decl(decoratorWithNegativeLiteralTypeNoCrash.ts, 4, 31)) + diff --git a/tests/baselines/reference/decoratorWithNegativeLiteralTypeNoCrash.types b/tests/baselines/reference/decoratorWithNegativeLiteralTypeNoCrash.types new file mode 100644 index 00000000000..45f4ff03451 --- /dev/null +++ b/tests/baselines/reference/decoratorWithNegativeLiteralTypeNoCrash.types @@ -0,0 +1,19 @@ +=== tests/cases/compiler/decoratorWithNegativeLiteralTypeNoCrash.ts === +class A { +>A : A + + @decorator +>decorator : (target: any, field: any) => void + + public field1: -1 = -1; +>field1 : -1 +>-1 : -1 +>1 : 1 +>-1 : -1 +>1 : 1 +} +function decorator(target: any, field: any) {} +>decorator : (target: any, field: any) => void +>target : any +>field : any + diff --git a/tests/cases/compiler/decoratorWithNegativeLiteralTypeNoCrash.ts b/tests/cases/compiler/decoratorWithNegativeLiteralTypeNoCrash.ts new file mode 100644 index 00000000000..720b68a7c16 --- /dev/null +++ b/tests/cases/compiler/decoratorWithNegativeLiteralTypeNoCrash.ts @@ -0,0 +1,8 @@ +// @target: es5 +// @experimentalDecorators: true +// @emitDecoratorMetadata: true +class A { + @decorator + public field1: -1 = -1; +} +function decorator(target: any, field: any) {} \ No newline at end of file From 7174e6a39d9e1238ab1c76efd055bac1deb58d1d Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Wed, 9 Jan 2019 15:50:50 -0800 Subject: [PATCH 63/96] Update user baselines (#29336) --- tests/baselines/reference/user/puppeteer.log | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/baselines/reference/user/puppeteer.log b/tests/baselines/reference/user/puppeteer.log index 9d6c2b26482..30875ee5560 100644 --- a/tests/baselines/reference/user/puppeteer.log +++ b/tests/baselines/reference/user/puppeteer.log @@ -62,9 +62,9 @@ lib/Page.js(936,3): error TS2322: Type '{ width: number; height: number; }' is n lib/Page.js(937,3): error TS2322: Type '{ width: number; height: number; }' is not assignable to type 'string'. lib/Page.js(938,3): error TS2322: Type '{ width: number; height: number; }' is not assignable to type 'string'. lib/TaskQueue.js(7,14): error TS7014: Function type, which lacks return-type annotation, implicitly has an 'any' return type. -lib/externs.d.ts(3,29): error TS2497: Module '"/puppeteer/puppeteer/lib/Target"' resolves to a non-module entity and cannot be imported using this construct. -lib/externs.d.ts(5,32): error TS2497: Module '"/puppeteer/puppeteer/lib/TaskQueue"' resolves to a non-module entity and cannot be imported using this construct. -lib/externs.d.ts(9,37): error TS2497: Module '"/puppeteer/puppeteer/lib/ElementHandle"' resolves to a non-module entity and cannot be imported using this construct. +lib/externs.d.ts(3,29): error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'allowSyntheticDefaultImports' flag and referencing its default export. +lib/externs.d.ts(5,32): error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'allowSyntheticDefaultImports' flag and referencing its default export. +lib/externs.d.ts(9,37): error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'allowSyntheticDefaultImports' flag and referencing its default export. lib/externs.d.ts(16,26): error TS2503: Cannot find namespace 'Protocol'. lib/externs.d.ts(16,69): error TS2503: Cannot find namespace 'Protocol'. lib/externs.d.ts(17,28): error TS2503: Cannot find namespace 'Protocol'. From e16be71c08f13d61adf24bd55a15ebd51104b44c Mon Sep 17 00:00:00 2001 From: Gabriela Britto Date: Wed, 9 Jan 2019 15:52:05 -0800 Subject: [PATCH 64/96] Add diagnostic message for JSDoc qualified param name without top level param --- src/compiler/diagnosticMessages.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 57f4c4c5611..58ec73c3cab 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -4266,6 +4266,10 @@ "category": "Error", "code": 8031 }, + "Qualified name '{0}' is not allowed without a leading '@param {object} {1}'.": { + "category": "Error", + "code": 8032 + }, "Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clause.": { "category": "Error", "code": 9002 From dd0a612cc9317034c87e2cf6ddec1370ef0e0ddb Mon Sep 17 00:00:00 2001 From: Gabriela Britto Date: Wed, 9 Jan 2019 16:08:14 -0800 Subject: [PATCH 65/96] Use specific error message for qualified param name without leading top level param name --- src/compiler/checker.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index de44e8bb37c..68ad0afaf5f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -24757,9 +24757,17 @@ namespace ts { return; } if (!containsArgumentsReference(decl)) { - error(node.name, - Diagnostics.JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name, - idText(node.name.kind === SyntaxKind.QualifiedName ? node.name.right : node.name)); + if (isQualifiedName(node.name)) { + error(node.name, + Diagnostics.Qualified_name_0_is_not_allowed_without_a_leading_param_object_1, + entityNameToString(node.name), + entityNameToString(node.name.left)); + } + else { + error(node.name, + Diagnostics.JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name, + idText(node.name)); + } } else if (findLast(getJSDocTags(decl), isJSDocParameterTag) === node && node.typeExpression && node.typeExpression.type && From 70148a4b5514175f7bd3ee51cfa208e6d2c7a95d Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 9 Jan 2019 16:10:28 -0800 Subject: [PATCH 66/96] Improve logic that determines when to resolve conditional types --- src/compiler/checker.ts | 134 ++++++++++++++++++++-------------------- src/compiler/types.ts | 4 +- 2 files changed, 71 insertions(+), 67 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index de44e8bb37c..44cc7478e13 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -444,10 +444,10 @@ namespace ts { const circularConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); const resolvingDefaultType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); - const markerSuperType = createType(TypeFlags.TypeParameter); - const markerSubType = createType(TypeFlags.TypeParameter); + const markerSuperType = createTypeParameter(); + const markerSubType = createTypeParameter(); markerSubType.constraint = markerSuperType; - const markerOtherType = createType(TypeFlags.TypeParameter); + const markerOtherType = createTypeParameter(); const noTypePredicate = createIdentifierTypePredicate("<>", 0, anyType); @@ -663,7 +663,6 @@ namespace ts { const subtypeRelation = createMap(); const assignableRelation = createMap(); - const definitelyAssignableRelation = createMap(); const comparableRelation = createMap(); const identityRelation = createMap(); const enumRelation = createMap(); @@ -2745,6 +2744,12 @@ namespace ts { return getUnionType(arrayFrom(typeofEQFacts.keys(), getLiteralType)); } + function createTypeParameter(symbol?: Symbol) { + const type = createType(TypeFlags.TypeParameter); + if (symbol) type.symbol = symbol; + return type; + } + // A reserved member name starts with two underscores, but the third character cannot be an underscore // or the @ symbol. A third underscore indicates an escaped form of an identifer that started // with at least two underscores. The @ character indicates that the name is denoted by a well known ES @@ -6085,9 +6090,8 @@ namespace ts { (type).instantiations.set(getTypeListId(type.typeParameters), type); (type).target = type; (type).typeArguments = type.typeParameters; - type.thisType = createType(TypeFlags.TypeParameter); + type.thisType = createTypeParameter(symbol); type.thisType.isThisType = true; - type.thisType.symbol = symbol; type.thisType.constraint = type; } } @@ -6228,20 +6232,12 @@ namespace ts { function getDeclaredTypeOfTypeParameter(symbol: Symbol): TypeParameter { const links = getSymbolLinks(symbol); - if (!links.declaredType) { - const type = createType(TypeFlags.TypeParameter); - type.symbol = symbol; - links.declaredType = type; - } - return links.declaredType; + return links.declaredType || (links.declaredType = createTypeParameter(symbol)); } function getDeclaredTypeOfAlias(symbol: Symbol): Type { const links = getSymbolLinks(symbol); - if (!links.declaredType) { - links.declaredType = getDeclaredTypeOfSymbol(resolveAlias(symbol)); - } - return links.declaredType; + return links.declaredType || (links.declaredType = getDeclaredTypeOfSymbol(resolveAlias(symbol))); } function getDeclaredTypeOfSymbol(symbol: Symbol): Type { @@ -7413,7 +7409,7 @@ namespace ts { if (type.root.isDistributive) { const simplified = getSimplifiedType(type.checkType); const constraint = simplified === type.checkType ? getConstraintOfType(simplified) : simplified; - if (constraint) { + if (constraint && constraint !== type.checkType) { const mapper = makeUnaryTypeMapper(type.root.checkType, constraint); const instantiated = getConditionalTypeInstantiation(type, combineTypeMappers(mapper, type.mapper)); if (!(instantiated.flags & TypeFlags.Never)) { @@ -9049,7 +9045,7 @@ namespace ts { if (arity) { typeParameters = new Array(arity); for (let i = 0; i < arity; i++) { - const typeParameter = typeParameters[i] = createType(TypeFlags.TypeParameter); + const typeParameter = typeParameters[i] = createTypeParameter(); if (i < maxLength) { const property = createSymbol(SymbolFlags.Property | (i >= minLength ? SymbolFlags.Optional : 0), "" + i as __String); property.type = typeParameter; @@ -9070,7 +9066,7 @@ namespace ts { type.instantiations.set(getTypeListId(type.typeParameters), type); type.target = type; type.typeArguments = type.typeParameters; - type.thisType = createType(TypeFlags.TypeParameter); + type.thisType = createTypeParameter(); type.thisType.isThisType = true; type.thisType.constraint = type; type.declaredProperties = properties; @@ -9971,7 +9967,7 @@ namespace ts { if (checkType === wildcardType || extendsType === wildcardType) { return wildcardType; } - const checkTypeInstantiable = maybeTypeOfKind(checkType, TypeFlags.Instantiable); + const checkTypeInstantiable = maybeTypeOfKind(checkType, TypeFlags.Instantiable | TypeFlags.GenericMappedType); let combinedMapper: TypeMapper | undefined; if (root.inferTypeParameters) { const context = createInferenceContext(root.inferTypeParameters, /*signature*/ undefined, InferenceFlags.None); @@ -9986,7 +9982,7 @@ namespace ts { // Instantiate the extends type including inferences for 'infer T' type parameters const inferredExtendsType = combinedMapper ? instantiateType(root.extendsType, combinedMapper) : extendsType; // We attempt to resolve the conditional type only when the check and extends types are non-generic - if (!checkTypeInstantiable && !maybeTypeOfKind(inferredExtendsType, TypeFlags.Instantiable)) { + if (!checkTypeInstantiable && !maybeTypeOfKind(inferredExtendsType, TypeFlags.Instantiable | TypeFlags.GenericMappedType)) { if (inferredExtendsType.flags & TypeFlags.AnyOrUnknown) { return instantiateType(root.trueType, mapper); } @@ -9998,14 +9994,15 @@ namespace ts { // types with type parameters mapped to the wildcard type, the most permissive instantiations // possible (the wildcard type is assignable to and from all types). If those are not related, // then no instatiations will be and we can just return the false branch type. - if (!isTypeAssignableTo(getWildcardInstantiation(checkType), getWildcardInstantiation(inferredExtendsType))) { + if (!isTypeAssignableTo(getPermissiveInstantiation(checkType), getPermissiveInstantiation(inferredExtendsType))) { return instantiateType(root.falseType, mapper); } - // Return trueType for a definitely true extends check. The definitely assignable relation excludes - // type variable constraints from consideration. Without the definitely assignable relation, the type + // Return trueType for a definitely true extends check. We check instantiations of the two + // types with type parameters mapped to their restrictive form, i.e. a form of the type parameter + // that has no constraint. This ensures that, for example, the type // type Foo = T extends { x: string } ? string : number - // would immediately resolve to 'string' instead of being deferred. - if (checkTypeRelatedTo(checkType, inferredExtendsType, definitelyAssignableRelation, /*errorNode*/ undefined)) { + // doesn't immediately resolve to 'string' instead of being deferred. + if (isTypeAssignableTo(getRestrictiveInstantiation(checkType), getRestrictiveInstantiation(inferredExtendsType))) { return instantiateType(root.trueType, combinedMapper || mapper); } } @@ -10611,13 +10608,20 @@ namespace ts { return t => t === source ? target : baseMapper(t); } - function wildcardMapper(type: Type) { + function permissiveMapper(type: Type) { return type.flags & TypeFlags.TypeParameter ? wildcardType : type; } + function getRestrictiveTypeParameter(tp: TypeParameter) { + return !tp.constraint ? tp : tp.restrictiveInstantiation || (tp.restrictiveInstantiation = createTypeParameter(tp.symbol)); + } + + function restrictiveMapper(type: Type) { + return type.flags & TypeFlags.TypeParameter ? getRestrictiveTypeParameter(type) : type; + } + function cloneTypeParameter(typeParameter: TypeParameter): TypeParameter { - const result = createType(TypeFlags.TypeParameter); - result.symbol = typeParameter.symbol; + const result = createTypeParameter(typeParameter.symbol); result.target = typeParameter; return result; } @@ -10969,9 +10973,14 @@ namespace ts { return type; } - function getWildcardInstantiation(type: Type) { + function getPermissiveInstantiation(type: Type) { return type.flags & (TypeFlags.Primitive | TypeFlags.AnyOrUnknown | TypeFlags.Never) ? type : - type.wildcardInstantiation || (type.wildcardInstantiation = instantiateType(type, wildcardMapper)); + type.permissiveInstantiation || (type.permissiveInstantiation = instantiateType(type, permissiveMapper)); + } + + function getRestrictiveInstantiation(type: Type) { + return type.flags & (TypeFlags.Primitive | TypeFlags.AnyOrUnknown | TypeFlags.Never) ? type : + type.restrictiveInstantiation || (type.restrictiveInstantiation = instantiateType(type, restrictiveMapper)); } function instantiateIndexInfo(info: IndexInfo | undefined, mapper: TypeMapper): IndexInfo | undefined { @@ -11644,7 +11653,7 @@ namespace ts { if (s & TypeFlags.Null && (!strictNullChecks || t & TypeFlags.Null)) return true; if (s & TypeFlags.Object && t & TypeFlags.NonPrimitive) return true; if (s & TypeFlags.UniqueESSymbol || t & TypeFlags.UniqueESSymbol) return false; - if (relation === assignableRelation || relation === definitelyAssignableRelation || relation === comparableRelation) { + if (relation === assignableRelation || relation === comparableRelation) { if (s & TypeFlags.Any) return true; // Type number or any numeric literal type is assignable to any numeric enum type or any // numeric enum literal type. This rule exists for backwards compatibility reasons because @@ -11836,7 +11845,7 @@ namespace ts { target = (target).regularType; } if (source.flags & TypeFlags.Substitution) { - source = relation === definitelyAssignableRelation ? (source).typeVariable : (source).substitute; + source = (source).substitute; } if (target.flags & TypeFlags.Substitution) { target = (target).typeVariable; @@ -12022,7 +12031,7 @@ namespace ts { } if (isExcessPropertyCheckTarget(target)) { const isComparingJsxAttributes = !!(getObjectFlags(source) & ObjectFlags.JsxAttributes); - if ((relation === assignableRelation || relation === definitelyAssignableRelation || relation === comparableRelation) && + if ((relation === assignableRelation || relation === comparableRelation) && (isTypeSubsetOf(globalObjectType, target) || (!isComparingJsxAttributes && isEmptyObjectType(target)))) { return false; } @@ -12425,24 +12434,22 @@ namespace ts { } // A type S is assignable to keyof T if S is assignable to keyof C, where C is the // simplified form of T or, if T doesn't simplify, the constraint of T. - if (relation !== definitelyAssignableRelation) { - const simplified = getSimplifiedType((target).type); - const constraint = simplified !== (target).type ? simplified : getConstraintOfType((target).type); - if (constraint) { - // We require Ternary.True here such that circular constraints don't cause - // false positives. For example, given 'T extends { [K in keyof T]: string }', - // 'keyof T' has itself as its constraint and produces a Ternary.Maybe when - // related to other types. - if (isRelatedTo(source, getIndexType(constraint, (target as IndexType).stringsOnly), reportErrors) === Ternary.True) { - return Ternary.True; - } + const simplified = getSimplifiedType((target).type); + const constraint = simplified !== (target).type ? simplified : getConstraintOfType((target).type); + if (constraint) { + // We require Ternary.True here such that circular constraints don't cause + // false positives. For example, given 'T extends { [K in keyof T]: string }', + // 'keyof T' has itself as its constraint and produces a Ternary.Maybe when + // related to other types. + if (isRelatedTo(source, getIndexType(constraint, (target as IndexType).stringsOnly), reportErrors) === Ternary.True) { + return Ternary.True; } } } else if (target.flags & TypeFlags.IndexedAccess) { // A type S is related to a type T[K], where T and K aren't both type variables, if S is related to C, // where C is the base constraint of T[K] - if (relation !== identityRelation && relation !== definitelyAssignableRelation && + if (relation !== identityRelation && !(isGenericObjectType((target).objectType) && isGenericIndexType((target).indexType))) { const constraint = getBaseConstraintOfType(target); if (constraint && constraint !== target) { @@ -12485,26 +12492,24 @@ namespace ts { return result; } } - if (relation !== definitelyAssignableRelation) { - const constraint = getConstraintOfType(source); - if (!constraint || (source.flags & TypeFlags.TypeParameter && constraint.flags & TypeFlags.Any)) { - // A type variable with no constraint is not related to the non-primitive object type. - if (result = isRelatedTo(emptyObjectType, extractTypesOfKind(target, ~TypeFlags.NonPrimitive))) { - errorInfo = saveErrorInfo; - return result; - } - } - // hi-speed no-this-instantiation check (less accurate, but avoids costly `this`-instantiation when the constraint will suffice), see #28231 for report on why this is needed - else if (result = isRelatedTo(constraint, target, /*reportErrors*/ false, /*headMessage*/ undefined, isIntersectionConstituent)) { - errorInfo = saveErrorInfo; - return result; - } - // slower, fuller, this-instantiated check (necessary when comparing raw `this` types from base classes), see `subclassWithPolymorphicThisIsAssignable.ts` test for example - else if (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, reportErrors, /*headMessage*/ undefined, isIntersectionConstituent)) { + const constraint = getConstraintOfType(source); + if (!constraint || (source.flags & TypeFlags.TypeParameter && constraint.flags & TypeFlags.Any)) { + // A type variable with no constraint is not related to the non-primitive object type. + if (result = isRelatedTo(emptyObjectType, extractTypesOfKind(target, ~TypeFlags.NonPrimitive))) { errorInfo = saveErrorInfo; return result; } } + // hi-speed no-this-instantiation check (less accurate, but avoids costly `this`-instantiation when the constraint will suffice), see #28231 for report on why this is needed + else if (result = isRelatedTo(constraint, target, /*reportErrors*/ false, /*headMessage*/ undefined, isIntersectionConstituent)) { + errorInfo = saveErrorInfo; + return result; + } + // slower, fuller, this-instantiated check (necessary when comparing raw `this` types from base classes), see `subclassWithPolymorphicThisIsAssignable.ts` test for example + else if (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, reportErrors, /*headMessage*/ undefined, isIntersectionConstituent)) { + errorInfo = saveErrorInfo; + return result; + } } else if (source.flags & TypeFlags.Index) { if (result = isRelatedTo(keyofConstraintType, target, reportErrors)) { @@ -12528,7 +12533,7 @@ namespace ts { } } } - else if (relation !== definitelyAssignableRelation) { + else { const distributiveConstraint = getConstraintOfDistributiveConditionalType(source); if (distributiveConstraint) { if (result = isRelatedTo(distributiveConstraint, target, reportErrors)) { @@ -12559,9 +12564,6 @@ namespace ts { } return Ternary.False; } - if (relation === definitelyAssignableRelation && isGenericMappedType(source)) { - return Ternary.False; - } const sourceIsPrimitive = !!(source.flags & TypeFlags.Primitive); if (relation !== identityRelation) { source = getApparentType(source); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 5c42d3eb510..e46a3d70403 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3916,7 +3916,9 @@ namespace ts { aliasTypeArguments?: ReadonlyArray; // Alias type arguments (if any) /* @internal */ aliasTypeArgumentsContainsMarker?: boolean; // Alias type arguments (if any) /* @internal */ - wildcardInstantiation?: Type; // Instantiation with type parameters mapped to wildcard type + permissiveInstantiation?: Type; // Instantiation with type parameters mapped to wildcard type + /* @internal */ + restrictiveInstantiation?: Type; // Instantiation with type parameters mapped to unconstrained form /* @internal */ immediateBaseConstraint?: Type; // Immediate base constraint cache } From 9fda7014cac88cd0885af42fccfb113ef289aadc Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 9 Jan 2019 16:16:24 -0800 Subject: [PATCH 67/96] Add regression tests --- .../conformance/types/conditional/conditionalTypes1.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/cases/conformance/types/conditional/conditionalTypes1.ts b/tests/cases/conformance/types/conditional/conditionalTypes1.ts index f5c67f678eb..2e8690a228b 100644 --- a/tests/cases/conformance/types/conditional/conditionalTypes1.ts +++ b/tests/cases/conformance/types/conditional/conditionalTypes1.ts @@ -353,3 +353,11 @@ declare function assign(o: T, a: RecursivePartial): void; var a = {o: 1, b: 2, c: [{a: 1, c: '213'}]} assign(a, {o: 2, c: {0: {a: 2, c: '213123'}}}) + +// Repros from #23843 + +type Weird1 = ((a: U) => never) extends + ((a: U) => never) ? never : never; + +type Weird2 = ((a: U) => U) extends + ((a: U) => infer T) ? T : never; From 0c1c97e5013e957da26e15390e5268cb63c1884e Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 9 Jan 2019 16:16:31 -0800 Subject: [PATCH 68/96] Accept new baselines --- .../reference/conditionalTypes1.errors.txt | 8 ++++++ .../baselines/reference/conditionalTypes1.js | 10 +++++++ .../reference/conditionalTypes1.symbols | 27 +++++++++++++++++++ .../reference/conditionalTypes1.types | 18 +++++++++++++ 4 files changed, 63 insertions(+) diff --git a/tests/baselines/reference/conditionalTypes1.errors.txt b/tests/baselines/reference/conditionalTypes1.errors.txt index 8bf05c043ce..62239eca7b8 100644 --- a/tests/baselines/reference/conditionalTypes1.errors.txt +++ b/tests/baselines/reference/conditionalTypes1.errors.txt @@ -471,4 +471,12 @@ tests/cases/conformance/types/conditional/conditionalTypes1.ts(288,43): error TS var a = {o: 1, b: 2, c: [{a: 1, c: '213'}]} assign(a, {o: 2, c: {0: {a: 2, c: '213123'}}}) + + // Repros from #23843 + + type Weird1 = ((a: U) => never) extends + ((a: U) => never) ? never : never; + + type Weird2 = ((a: U) => U) extends + ((a: U) => infer T) ? T : never; \ No newline at end of file diff --git a/tests/baselines/reference/conditionalTypes1.js b/tests/baselines/reference/conditionalTypes1.js index 552a80d58a5..7ce19ce17e7 100644 --- a/tests/baselines/reference/conditionalTypes1.js +++ b/tests/baselines/reference/conditionalTypes1.js @@ -351,6 +351,14 @@ declare function assign(o: T, a: RecursivePartial): void; var a = {o: 1, b: 2, c: [{a: 1, c: '213'}]} assign(a, {o: 2, c: {0: {a: 2, c: '213123'}}}) + +// Repros from #23843 + +type Weird1 = ((a: U) => never) extends + ((a: U) => never) ? never : never; + +type Weird2 = ((a: U) => U) extends + ((a: U) => infer T) ? T : never; //// [conditionalTypes1.js] @@ -715,3 +723,5 @@ declare var a: { c: string; }[]; }; +declare type Weird1 = ((a: U) => never) extends ((a: U) => never) ? never : never; +declare type Weird2 = ((a: U) => U) extends ((a: U) => infer T) ? T : never; diff --git a/tests/baselines/reference/conditionalTypes1.symbols b/tests/baselines/reference/conditionalTypes1.symbols index 19f0ae83890..e5c6ae3d6c7 100644 --- a/tests/baselines/reference/conditionalTypes1.symbols +++ b/tests/baselines/reference/conditionalTypes1.symbols @@ -1371,3 +1371,30 @@ assign(a, {o: 2, c: {0: {a: 2, c: '213123'}}}) >a : Symbol(a, Decl(conditionalTypes1.ts, 351, 25)) >c : Symbol(c, Decl(conditionalTypes1.ts, 351, 30)) +// Repros from #23843 + +type Weird1 = ((a: U) => never) extends +>Weird1 : Symbol(Weird1, Decl(conditionalTypes1.ts, 351, 46)) +>U : Symbol(U, Decl(conditionalTypes1.ts, 355, 16)) +>a : Symbol(a, Decl(conditionalTypes1.ts, 355, 35)) +>U : Symbol(U, Decl(conditionalTypes1.ts, 355, 16)) + + ((a: U) => never) ? never : never; +>U : Symbol(U, Decl(conditionalTypes1.ts, 356, 6)) +>a : Symbol(a, Decl(conditionalTypes1.ts, 356, 22)) +>U : Symbol(U, Decl(conditionalTypes1.ts, 356, 6)) + +type Weird2 = ((a: U) => U) extends +>Weird2 : Symbol(Weird2, Decl(conditionalTypes1.ts, 356, 54)) +>U : Symbol(U, Decl(conditionalTypes1.ts, 358, 16)) +>a : Symbol(a, Decl(conditionalTypes1.ts, 358, 35)) +>U : Symbol(U, Decl(conditionalTypes1.ts, 358, 16)) +>U : Symbol(U, Decl(conditionalTypes1.ts, 358, 16)) + + ((a: U) => infer T) ? T : never; +>U : Symbol(U, Decl(conditionalTypes1.ts, 359, 6)) +>a : Symbol(a, Decl(conditionalTypes1.ts, 359, 22)) +>U : Symbol(U, Decl(conditionalTypes1.ts, 359, 6)) +>T : Symbol(T, Decl(conditionalTypes1.ts, 359, 36)) +>T : Symbol(T, Decl(conditionalTypes1.ts, 359, 36)) + diff --git a/tests/baselines/reference/conditionalTypes1.types b/tests/baselines/reference/conditionalTypes1.types index 00d1965eea4..08fdb4b2f29 100644 --- a/tests/baselines/reference/conditionalTypes1.types +++ b/tests/baselines/reference/conditionalTypes1.types @@ -1054,3 +1054,21 @@ assign(a, {o: 2, c: {0: {a: 2, c: '213123'}}}) >c : string >'213123' : "213123" +// Repros from #23843 + +type Weird1 = ((a: U) => never) extends +>Weird1 : never +>a : U + + ((a: U) => never) ? never : never; +>true : true +>a : U + +type Weird2 = ((a: U) => U) extends +>Weird2 : boolean +>a : U + + ((a: U) => infer T) ? T : never; +>true : true +>a : U + From e2524e375029d49de5de8c1393b8d362381aa6c4 Mon Sep 17 00:00:00 2001 From: Gabriela Britto Date: Thu, 10 Jan 2019 09:55:06 -0800 Subject: [PATCH 69/96] Add test for qualified name param without top level object error --- .../paramTagNestedWithoutTopLevelObject.errors.txt | 12 ++++++++++++ .../paramTagNestedWithoutTopLevelObject.symbols | 11 +++++++++++ .../paramTagNestedWithoutTopLevelObject.types | 13 +++++++++++++ .../jsdoc/paramTagNestedWithoutTopLevelObject.ts | 11 +++++++++++ 4 files changed, 47 insertions(+) create mode 100644 tests/baselines/reference/paramTagNestedWithoutTopLevelObject.errors.txt create mode 100644 tests/baselines/reference/paramTagNestedWithoutTopLevelObject.symbols create mode 100644 tests/baselines/reference/paramTagNestedWithoutTopLevelObject.types create mode 100644 tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject.ts diff --git a/tests/baselines/reference/paramTagNestedWithoutTopLevelObject.errors.txt b/tests/baselines/reference/paramTagNestedWithoutTopLevelObject.errors.txt new file mode 100644 index 00000000000..7cfe6e03670 --- /dev/null +++ b/tests/baselines/reference/paramTagNestedWithoutTopLevelObject.errors.txt @@ -0,0 +1,12 @@ +tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject.js(2,20): error TS8032: Qualified name 'xyz.p' is not allowed without a leading '@param {object} xyz'. + + +==== tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject.js (1 errors) ==== + /** + * @param {number} xyz.p + ~~~~~ +!!! error TS8032: Qualified name 'xyz.p' is not allowed without a leading '@param {object} xyz'. + */ + function g(xyz) { + xyz.x; + } \ No newline at end of file diff --git a/tests/baselines/reference/paramTagNestedWithoutTopLevelObject.symbols b/tests/baselines/reference/paramTagNestedWithoutTopLevelObject.symbols new file mode 100644 index 00000000000..63e7e4980b8 --- /dev/null +++ b/tests/baselines/reference/paramTagNestedWithoutTopLevelObject.symbols @@ -0,0 +1,11 @@ +=== tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject.js === +/** + * @param {number} xyz.p + */ +function g(xyz) { +>g : Symbol(g, Decl(paramTagNestedWithoutTopLevelObject.js, 0, 0)) +>xyz : Symbol(xyz, Decl(paramTagNestedWithoutTopLevelObject.js, 3, 11)) + + xyz.x; +>xyz : Symbol(xyz, Decl(paramTagNestedWithoutTopLevelObject.js, 3, 11)) +} diff --git a/tests/baselines/reference/paramTagNestedWithoutTopLevelObject.types b/tests/baselines/reference/paramTagNestedWithoutTopLevelObject.types new file mode 100644 index 00000000000..d65efd8678a --- /dev/null +++ b/tests/baselines/reference/paramTagNestedWithoutTopLevelObject.types @@ -0,0 +1,13 @@ +=== tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject.js === +/** + * @param {number} xyz.p + */ +function g(xyz) { +>g : (xyz: any) => void +>xyz : any + + xyz.x; +>xyz.x : any +>xyz : any +>x : any +} diff --git a/tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject.ts b/tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject.ts new file mode 100644 index 00000000000..2285ae623ff --- /dev/null +++ b/tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject.ts @@ -0,0 +1,11 @@ +// @noEmit: true +// @allowJs: true +// @checkJs: true +// @Filename: paramTagNestedWithoutTopLevelObject.js + +/** + * @param {number} xyz.p + */ +function g(xyz) { + xyz.x; +} \ No newline at end of file From ebe193c6d7757ecfe998634823beb2045f63aec1 Mon Sep 17 00:00:00 2001 From: Gabriela Britto Date: Thu, 10 Jan 2019 14:05:10 -0800 Subject: [PATCH 70/96] Minor refactor in paramTagNestedWithoutTopLevelObject.ts --- .../paramTagNestedWithoutTopLevelObject.errors.txt | 2 +- .../reference/paramTagNestedWithoutTopLevelObject.symbols | 2 +- .../reference/paramTagNestedWithoutTopLevelObject.types | 8 ++++---- .../jsdoc/paramTagNestedWithoutTopLevelObject.ts | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/baselines/reference/paramTagNestedWithoutTopLevelObject.errors.txt b/tests/baselines/reference/paramTagNestedWithoutTopLevelObject.errors.txt index 7cfe6e03670..8ee7b3ba989 100644 --- a/tests/baselines/reference/paramTagNestedWithoutTopLevelObject.errors.txt +++ b/tests/baselines/reference/paramTagNestedWithoutTopLevelObject.errors.txt @@ -8,5 +8,5 @@ tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject.js(2,20): erro !!! error TS8032: Qualified name 'xyz.p' is not allowed without a leading '@param {object} xyz'. */ function g(xyz) { - xyz.x; + return xyz.p; } \ No newline at end of file diff --git a/tests/baselines/reference/paramTagNestedWithoutTopLevelObject.symbols b/tests/baselines/reference/paramTagNestedWithoutTopLevelObject.symbols index 63e7e4980b8..d8a28a638ff 100644 --- a/tests/baselines/reference/paramTagNestedWithoutTopLevelObject.symbols +++ b/tests/baselines/reference/paramTagNestedWithoutTopLevelObject.symbols @@ -6,6 +6,6 @@ function g(xyz) { >g : Symbol(g, Decl(paramTagNestedWithoutTopLevelObject.js, 0, 0)) >xyz : Symbol(xyz, Decl(paramTagNestedWithoutTopLevelObject.js, 3, 11)) - xyz.x; + return xyz.p; >xyz : Symbol(xyz, Decl(paramTagNestedWithoutTopLevelObject.js, 3, 11)) } diff --git a/tests/baselines/reference/paramTagNestedWithoutTopLevelObject.types b/tests/baselines/reference/paramTagNestedWithoutTopLevelObject.types index d65efd8678a..cc339b84b30 100644 --- a/tests/baselines/reference/paramTagNestedWithoutTopLevelObject.types +++ b/tests/baselines/reference/paramTagNestedWithoutTopLevelObject.types @@ -3,11 +3,11 @@ * @param {number} xyz.p */ function g(xyz) { ->g : (xyz: any) => void +>g : (xyz: any) => any >xyz : any - xyz.x; ->xyz.x : any + return xyz.p; +>xyz.p : any >xyz : any ->x : any +>p : any } diff --git a/tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject.ts b/tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject.ts index 2285ae623ff..03c79ce9e1c 100644 --- a/tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject.ts +++ b/tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject.ts @@ -7,5 +7,5 @@ * @param {number} xyz.p */ function g(xyz) { - xyz.x; + return xyz.p; } \ No newline at end of file From 76f444e338218b9496d0c3ee5df7901dfe8dce6a Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 10 Jan 2019 14:45:19 -0800 Subject: [PATCH 71/96] Allow nonnull assertions in references (#29351) --- src/compiler/binder.ts | 2 +- src/compiler/checker.ts | 11 + .../reference/nonNullReferenceMatching.js | 54 ++++ .../nonNullReferenceMatching.symbols | 193 +++++++++++++ .../reference/nonNullReferenceMatching.types | 262 ++++++++++++++++++ .../compiler/nonNullReferenceMatching.ts | 34 +++ 6 files changed, 555 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/nonNullReferenceMatching.js create mode 100644 tests/baselines/reference/nonNullReferenceMatching.symbols create mode 100644 tests/baselines/reference/nonNullReferenceMatching.types create mode 100644 tests/cases/compiler/nonNullReferenceMatching.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 7216af4e817..f0e17261810 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -753,7 +753,7 @@ namespace ts { function isNarrowableReference(expr: Expression): boolean { return expr.kind === SyntaxKind.Identifier || expr.kind === SyntaxKind.ThisKeyword || expr.kind === SyntaxKind.SuperKeyword || - isPropertyAccessExpression(expr) && isNarrowableReference(expr.expression) || + (isPropertyAccessExpression(expr) || isNonNullExpression(expr) || isParenthesizedExpression(expr)) && isNarrowableReference(expr.expression) || isElementAccessExpression(expr) && expr.argumentExpression && (isStringLiteral(expr.argumentExpression) || isNumericLiteral(expr.argumentExpression)) && isNarrowableReference(expr.expression); diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 92e3b10842b..3bb26e83dd8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14773,6 +14773,9 @@ namespace ts { return symbol !== unknownSymbol ? (isConstraintPosition(node) ? "@" : "") + getSymbolId(symbol) : undefined; case SyntaxKind.ThisKeyword: return "0"; + case SyntaxKind.NonNullExpression: + case SyntaxKind.ParenthesizedExpression: + return getFlowCacheKey((node).expression); case SyntaxKind.PropertyAccessExpression: case SyntaxKind.ElementAccessExpression: const propName = getAccessedPropertyName(node); @@ -14785,6 +14788,11 @@ namespace ts { } function isMatchingReference(source: Node, target: Node): boolean { + switch (target.kind) { + case SyntaxKind.ParenthesizedExpression: + case SyntaxKind.NonNullExpression: + return isMatchingReference(source, (target as NonNullExpression | ParenthesizedExpression).expression); + } switch (source.kind) { case SyntaxKind.Identifier: return target.kind === SyntaxKind.Identifier && getResolvedSymbol(source) === getResolvedSymbol(target) || @@ -14794,6 +14802,9 @@ namespace ts { return target.kind === SyntaxKind.ThisKeyword; case SyntaxKind.SuperKeyword: return target.kind === SyntaxKind.SuperKeyword; + case SyntaxKind.NonNullExpression: + case SyntaxKind.ParenthesizedExpression: + return isMatchingReference((source as NonNullExpression | ParenthesizedExpression).expression, target); case SyntaxKind.PropertyAccessExpression: case SyntaxKind.ElementAccessExpression: return isAccessExpression(target) && diff --git a/tests/baselines/reference/nonNullReferenceMatching.js b/tests/baselines/reference/nonNullReferenceMatching.js new file mode 100644 index 00000000000..abb0d5a96db --- /dev/null +++ b/tests/baselines/reference/nonNullReferenceMatching.js @@ -0,0 +1,54 @@ +//// [nonNullReferenceMatching.ts] +type ElementRef = (element: HTMLElement | null) => void; + +type ThumbProps = { + elementRef?: ElementRef; +} + +type ComponentProps = { + thumbYProps?: ThumbProps; + thumbXProps: ThumbProps; +} + +class Component { + props!: ComponentProps; + public thumbYElementRef = (ref: HTMLElement | null) => { + typeof this.props.thumbYProps!.elementRef === 'function' && this.props.thumbYProps!.elementRef(ref); + + typeof (this.props.thumbYProps!.elementRef) === 'function' && this.props.thumbYProps!.elementRef(ref); + + typeof ((this.props).thumbYProps!.elementRef)! === 'function' && this.props.thumbYProps!.elementRef(ref); + + typeof this.props.thumbXProps.elementRef === 'function' && this.props.thumbXProps.elementRef(ref); + + typeof this.props.thumbXProps.elementRef === 'function' && (this.props).thumbXProps.elementRef(ref); + + typeof this.props.thumbXProps.elementRef === 'function' && (this.props.thumbXProps).elementRef(ref); + + typeof this.props.thumbXProps.elementRef === 'function' && ((this.props)!.thumbXProps)!.elementRef(ref); + + typeof (this.props.thumbXProps).elementRef === 'function' && ((this.props)!.thumbXProps)!.elementRef(ref); + + typeof this.props!.thumbXProps!.elementRef === 'function' && ((this.props)!.thumbXProps)!.elementRef(ref); + }; +} + +//// [nonNullReferenceMatching.js] +"use strict"; +var Component = /** @class */ (function () { + function Component() { + var _this = this; + this.thumbYElementRef = function (ref) { + typeof _this.props.thumbYProps.elementRef === 'function' && _this.props.thumbYProps.elementRef(ref); + typeof (_this.props.thumbYProps.elementRef) === 'function' && _this.props.thumbYProps.elementRef(ref); + typeof ((_this.props).thumbYProps.elementRef) === 'function' && _this.props.thumbYProps.elementRef(ref); + typeof _this.props.thumbXProps.elementRef === 'function' && _this.props.thumbXProps.elementRef(ref); + typeof _this.props.thumbXProps.elementRef === 'function' && (_this.props).thumbXProps.elementRef(ref); + typeof _this.props.thumbXProps.elementRef === 'function' && (_this.props.thumbXProps).elementRef(ref); + typeof _this.props.thumbXProps.elementRef === 'function' && ((_this.props).thumbXProps).elementRef(ref); + typeof (_this.props.thumbXProps).elementRef === 'function' && ((_this.props).thumbXProps).elementRef(ref); + typeof _this.props.thumbXProps.elementRef === 'function' && ((_this.props).thumbXProps).elementRef(ref); + }; + } + return Component; +}()); diff --git a/tests/baselines/reference/nonNullReferenceMatching.symbols b/tests/baselines/reference/nonNullReferenceMatching.symbols new file mode 100644 index 00000000000..ee9c608cea4 --- /dev/null +++ b/tests/baselines/reference/nonNullReferenceMatching.symbols @@ -0,0 +1,193 @@ +=== tests/cases/compiler/nonNullReferenceMatching.ts === +type ElementRef = (element: HTMLElement | null) => void; +>ElementRef : Symbol(ElementRef, Decl(nonNullReferenceMatching.ts, 0, 0)) +>element : Symbol(element, Decl(nonNullReferenceMatching.ts, 0, 19)) +>HTMLElement : Symbol(HTMLElement, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) + +type ThumbProps = { +>ThumbProps : Symbol(ThumbProps, Decl(nonNullReferenceMatching.ts, 0, 56)) + + elementRef?: ElementRef; +>elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>ElementRef : Symbol(ElementRef, Decl(nonNullReferenceMatching.ts, 0, 0)) +} + +type ComponentProps = { +>ComponentProps : Symbol(ComponentProps, Decl(nonNullReferenceMatching.ts, 4, 1)) + + thumbYProps?: ThumbProps; +>thumbYProps : Symbol(thumbYProps, Decl(nonNullReferenceMatching.ts, 6, 23)) +>ThumbProps : Symbol(ThumbProps, Decl(nonNullReferenceMatching.ts, 0, 56)) + + thumbXProps: ThumbProps; +>thumbXProps : Symbol(thumbXProps, Decl(nonNullReferenceMatching.ts, 7, 29)) +>ThumbProps : Symbol(ThumbProps, Decl(nonNullReferenceMatching.ts, 0, 56)) +} + +class Component { +>Component : Symbol(Component, Decl(nonNullReferenceMatching.ts, 9, 1)) + + props!: ComponentProps; +>props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>ComponentProps : Symbol(ComponentProps, Decl(nonNullReferenceMatching.ts, 4, 1)) + + public thumbYElementRef = (ref: HTMLElement | null) => { +>thumbYElementRef : Symbol(Component.thumbYElementRef, Decl(nonNullReferenceMatching.ts, 12, 27)) +>ref : Symbol(ref, Decl(nonNullReferenceMatching.ts, 13, 31)) +>HTMLElement : Symbol(HTMLElement, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) + + typeof this.props.thumbYProps!.elementRef === 'function' && this.props.thumbYProps!.elementRef(ref); +>this.props.thumbYProps!.elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>this.props.thumbYProps : Symbol(thumbYProps, Decl(nonNullReferenceMatching.ts, 6, 23)) +>this.props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>this : Symbol(Component, Decl(nonNullReferenceMatching.ts, 9, 1)) +>props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>thumbYProps : Symbol(thumbYProps, Decl(nonNullReferenceMatching.ts, 6, 23)) +>elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>this.props.thumbYProps!.elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>this.props.thumbYProps : Symbol(thumbYProps, Decl(nonNullReferenceMatching.ts, 6, 23)) +>this.props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>this : Symbol(Component, Decl(nonNullReferenceMatching.ts, 9, 1)) +>props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>thumbYProps : Symbol(thumbYProps, Decl(nonNullReferenceMatching.ts, 6, 23)) +>elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>ref : Symbol(ref, Decl(nonNullReferenceMatching.ts, 13, 31)) + + typeof (this.props.thumbYProps!.elementRef) === 'function' && this.props.thumbYProps!.elementRef(ref); +>this.props.thumbYProps!.elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>this.props.thumbYProps : Symbol(thumbYProps, Decl(nonNullReferenceMatching.ts, 6, 23)) +>this.props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>this : Symbol(Component, Decl(nonNullReferenceMatching.ts, 9, 1)) +>props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>thumbYProps : Symbol(thumbYProps, Decl(nonNullReferenceMatching.ts, 6, 23)) +>elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>this.props.thumbYProps!.elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>this.props.thumbYProps : Symbol(thumbYProps, Decl(nonNullReferenceMatching.ts, 6, 23)) +>this.props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>this : Symbol(Component, Decl(nonNullReferenceMatching.ts, 9, 1)) +>props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>thumbYProps : Symbol(thumbYProps, Decl(nonNullReferenceMatching.ts, 6, 23)) +>elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>ref : Symbol(ref, Decl(nonNullReferenceMatching.ts, 13, 31)) + + typeof ((this.props).thumbYProps!.elementRef)! === 'function' && this.props.thumbYProps!.elementRef(ref); +>(this.props).thumbYProps!.elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>(this.props).thumbYProps : Symbol(thumbYProps, Decl(nonNullReferenceMatching.ts, 6, 23)) +>this.props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>this : Symbol(Component, Decl(nonNullReferenceMatching.ts, 9, 1)) +>props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>thumbYProps : Symbol(thumbYProps, Decl(nonNullReferenceMatching.ts, 6, 23)) +>elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>this.props.thumbYProps!.elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>this.props.thumbYProps : Symbol(thumbYProps, Decl(nonNullReferenceMatching.ts, 6, 23)) +>this.props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>this : Symbol(Component, Decl(nonNullReferenceMatching.ts, 9, 1)) +>props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>thumbYProps : Symbol(thumbYProps, Decl(nonNullReferenceMatching.ts, 6, 23)) +>elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>ref : Symbol(ref, Decl(nonNullReferenceMatching.ts, 13, 31)) + + typeof this.props.thumbXProps.elementRef === 'function' && this.props.thumbXProps.elementRef(ref); +>this.props.thumbXProps.elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>this.props.thumbXProps : Symbol(thumbXProps, Decl(nonNullReferenceMatching.ts, 7, 29)) +>this.props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>this : Symbol(Component, Decl(nonNullReferenceMatching.ts, 9, 1)) +>props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>thumbXProps : Symbol(thumbXProps, Decl(nonNullReferenceMatching.ts, 7, 29)) +>elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>this.props.thumbXProps.elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>this.props.thumbXProps : Symbol(thumbXProps, Decl(nonNullReferenceMatching.ts, 7, 29)) +>this.props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>this : Symbol(Component, Decl(nonNullReferenceMatching.ts, 9, 1)) +>props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>thumbXProps : Symbol(thumbXProps, Decl(nonNullReferenceMatching.ts, 7, 29)) +>elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>ref : Symbol(ref, Decl(nonNullReferenceMatching.ts, 13, 31)) + + typeof this.props.thumbXProps.elementRef === 'function' && (this.props).thumbXProps.elementRef(ref); +>this.props.thumbXProps.elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>this.props.thumbXProps : Symbol(thumbXProps, Decl(nonNullReferenceMatching.ts, 7, 29)) +>this.props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>this : Symbol(Component, Decl(nonNullReferenceMatching.ts, 9, 1)) +>props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>thumbXProps : Symbol(thumbXProps, Decl(nonNullReferenceMatching.ts, 7, 29)) +>elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>(this.props).thumbXProps.elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>(this.props).thumbXProps : Symbol(thumbXProps, Decl(nonNullReferenceMatching.ts, 7, 29)) +>this.props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>this : Symbol(Component, Decl(nonNullReferenceMatching.ts, 9, 1)) +>props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>thumbXProps : Symbol(thumbXProps, Decl(nonNullReferenceMatching.ts, 7, 29)) +>elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>ref : Symbol(ref, Decl(nonNullReferenceMatching.ts, 13, 31)) + + typeof this.props.thumbXProps.elementRef === 'function' && (this.props.thumbXProps).elementRef(ref); +>this.props.thumbXProps.elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>this.props.thumbXProps : Symbol(thumbXProps, Decl(nonNullReferenceMatching.ts, 7, 29)) +>this.props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>this : Symbol(Component, Decl(nonNullReferenceMatching.ts, 9, 1)) +>props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>thumbXProps : Symbol(thumbXProps, Decl(nonNullReferenceMatching.ts, 7, 29)) +>elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>(this.props.thumbXProps).elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>this.props.thumbXProps : Symbol(thumbXProps, Decl(nonNullReferenceMatching.ts, 7, 29)) +>this.props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>this : Symbol(Component, Decl(nonNullReferenceMatching.ts, 9, 1)) +>props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>thumbXProps : Symbol(thumbXProps, Decl(nonNullReferenceMatching.ts, 7, 29)) +>elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>ref : Symbol(ref, Decl(nonNullReferenceMatching.ts, 13, 31)) + + typeof this.props.thumbXProps.elementRef === 'function' && ((this.props)!.thumbXProps)!.elementRef(ref); +>this.props.thumbXProps.elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>this.props.thumbXProps : Symbol(thumbXProps, Decl(nonNullReferenceMatching.ts, 7, 29)) +>this.props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>this : Symbol(Component, Decl(nonNullReferenceMatching.ts, 9, 1)) +>props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>thumbXProps : Symbol(thumbXProps, Decl(nonNullReferenceMatching.ts, 7, 29)) +>elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>((this.props)!.thumbXProps)!.elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>(this.props)!.thumbXProps : Symbol(thumbXProps, Decl(nonNullReferenceMatching.ts, 7, 29)) +>this.props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>this : Symbol(Component, Decl(nonNullReferenceMatching.ts, 9, 1)) +>props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>thumbXProps : Symbol(thumbXProps, Decl(nonNullReferenceMatching.ts, 7, 29)) +>elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>ref : Symbol(ref, Decl(nonNullReferenceMatching.ts, 13, 31)) + + typeof (this.props.thumbXProps).elementRef === 'function' && ((this.props)!.thumbXProps)!.elementRef(ref); +>(this.props.thumbXProps).elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>this.props.thumbXProps : Symbol(thumbXProps, Decl(nonNullReferenceMatching.ts, 7, 29)) +>this.props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>this : Symbol(Component, Decl(nonNullReferenceMatching.ts, 9, 1)) +>props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>thumbXProps : Symbol(thumbXProps, Decl(nonNullReferenceMatching.ts, 7, 29)) +>elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>((this.props)!.thumbXProps)!.elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>(this.props)!.thumbXProps : Symbol(thumbXProps, Decl(nonNullReferenceMatching.ts, 7, 29)) +>this.props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>this : Symbol(Component, Decl(nonNullReferenceMatching.ts, 9, 1)) +>props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>thumbXProps : Symbol(thumbXProps, Decl(nonNullReferenceMatching.ts, 7, 29)) +>elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>ref : Symbol(ref, Decl(nonNullReferenceMatching.ts, 13, 31)) + + typeof this.props!.thumbXProps!.elementRef === 'function' && ((this.props)!.thumbXProps)!.elementRef(ref); +>this.props!.thumbXProps!.elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>this.props!.thumbXProps : Symbol(thumbXProps, Decl(nonNullReferenceMatching.ts, 7, 29)) +>this.props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>this : Symbol(Component, Decl(nonNullReferenceMatching.ts, 9, 1)) +>props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>thumbXProps : Symbol(thumbXProps, Decl(nonNullReferenceMatching.ts, 7, 29)) +>elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>((this.props)!.thumbXProps)!.elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>(this.props)!.thumbXProps : Symbol(thumbXProps, Decl(nonNullReferenceMatching.ts, 7, 29)) +>this.props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>this : Symbol(Component, Decl(nonNullReferenceMatching.ts, 9, 1)) +>props : Symbol(Component.props, Decl(nonNullReferenceMatching.ts, 11, 17)) +>thumbXProps : Symbol(thumbXProps, Decl(nonNullReferenceMatching.ts, 7, 29)) +>elementRef : Symbol(elementRef, Decl(nonNullReferenceMatching.ts, 2, 19)) +>ref : Symbol(ref, Decl(nonNullReferenceMatching.ts, 13, 31)) + + }; +} diff --git a/tests/baselines/reference/nonNullReferenceMatching.types b/tests/baselines/reference/nonNullReferenceMatching.types new file mode 100644 index 00000000000..03ef70177c0 --- /dev/null +++ b/tests/baselines/reference/nonNullReferenceMatching.types @@ -0,0 +1,262 @@ +=== tests/cases/compiler/nonNullReferenceMatching.ts === +type ElementRef = (element: HTMLElement | null) => void; +>ElementRef : ElementRef +>element : HTMLElement | null +>null : null + +type ThumbProps = { +>ThumbProps : ThumbProps + + elementRef?: ElementRef; +>elementRef : ElementRef | undefined +} + +type ComponentProps = { +>ComponentProps : ComponentProps + + thumbYProps?: ThumbProps; +>thumbYProps : ThumbProps | undefined + + thumbXProps: ThumbProps; +>thumbXProps : ThumbProps +} + +class Component { +>Component : Component + + props!: ComponentProps; +>props : ComponentProps + + public thumbYElementRef = (ref: HTMLElement | null) => { +>thumbYElementRef : (ref: HTMLElement | null) => void +>(ref: HTMLElement | null) => { typeof this.props.thumbYProps!.elementRef === 'function' && this.props.thumbYProps!.elementRef(ref); typeof (this.props.thumbYProps!.elementRef) === 'function' && this.props.thumbYProps!.elementRef(ref); typeof ((this.props).thumbYProps!.elementRef)! === 'function' && this.props.thumbYProps!.elementRef(ref); typeof this.props.thumbXProps.elementRef === 'function' && this.props.thumbXProps.elementRef(ref); typeof this.props.thumbXProps.elementRef === 'function' && (this.props).thumbXProps.elementRef(ref); typeof this.props.thumbXProps.elementRef === 'function' && (this.props.thumbXProps).elementRef(ref); typeof this.props.thumbXProps.elementRef === 'function' && ((this.props)!.thumbXProps)!.elementRef(ref); typeof (this.props.thumbXProps).elementRef === 'function' && ((this.props)!.thumbXProps)!.elementRef(ref); typeof this.props!.thumbXProps!.elementRef === 'function' && ((this.props)!.thumbXProps)!.elementRef(ref); } : (ref: HTMLElement | null) => void +>ref : HTMLElement | null +>null : null + + typeof this.props.thumbYProps!.elementRef === 'function' && this.props.thumbYProps!.elementRef(ref); +>typeof this.props.thumbYProps!.elementRef === 'function' && this.props.thumbYProps!.elementRef(ref) : false | void +>typeof this.props.thumbYProps!.elementRef === 'function' : boolean +>typeof this.props.thumbYProps!.elementRef : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" +>this.props.thumbYProps!.elementRef : ElementRef | undefined +>this.props.thumbYProps! : ThumbProps +>this.props.thumbYProps : ThumbProps | undefined +>this.props : ComponentProps +>this : this +>props : ComponentProps +>thumbYProps : ThumbProps | undefined +>elementRef : ElementRef | undefined +>'function' : "function" +>this.props.thumbYProps!.elementRef(ref) : void +>this.props.thumbYProps!.elementRef : ElementRef +>this.props.thumbYProps! : ThumbProps +>this.props.thumbYProps : ThumbProps | undefined +>this.props : ComponentProps +>this : this +>props : ComponentProps +>thumbYProps : ThumbProps | undefined +>elementRef : ElementRef +>ref : HTMLElement | null + + typeof (this.props.thumbYProps!.elementRef) === 'function' && this.props.thumbYProps!.elementRef(ref); +>typeof (this.props.thumbYProps!.elementRef) === 'function' && this.props.thumbYProps!.elementRef(ref) : false | void +>typeof (this.props.thumbYProps!.elementRef) === 'function' : boolean +>typeof (this.props.thumbYProps!.elementRef) : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" +>(this.props.thumbYProps!.elementRef) : ElementRef | undefined +>this.props.thumbYProps!.elementRef : ElementRef | undefined +>this.props.thumbYProps! : ThumbProps +>this.props.thumbYProps : ThumbProps | undefined +>this.props : ComponentProps +>this : this +>props : ComponentProps +>thumbYProps : ThumbProps | undefined +>elementRef : ElementRef | undefined +>'function' : "function" +>this.props.thumbYProps!.elementRef(ref) : void +>this.props.thumbYProps!.elementRef : ElementRef +>this.props.thumbYProps! : ThumbProps +>this.props.thumbYProps : ThumbProps | undefined +>this.props : ComponentProps +>this : this +>props : ComponentProps +>thumbYProps : ThumbProps | undefined +>elementRef : ElementRef +>ref : HTMLElement | null + + typeof ((this.props).thumbYProps!.elementRef)! === 'function' && this.props.thumbYProps!.elementRef(ref); +>typeof ((this.props).thumbYProps!.elementRef)! === 'function' && this.props.thumbYProps!.elementRef(ref) : false | void +>typeof ((this.props).thumbYProps!.elementRef)! === 'function' : boolean +>typeof ((this.props).thumbYProps!.elementRef)! : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" +>((this.props).thumbYProps!.elementRef)! : ElementRef +>((this.props).thumbYProps!.elementRef) : ElementRef | undefined +>(this.props).thumbYProps!.elementRef : ElementRef | undefined +>(this.props).thumbYProps! : ThumbProps +>(this.props).thumbYProps : ThumbProps | undefined +>(this.props) : ComponentProps +>this.props : ComponentProps +>this : this +>props : ComponentProps +>thumbYProps : ThumbProps | undefined +>elementRef : ElementRef | undefined +>'function' : "function" +>this.props.thumbYProps!.elementRef(ref) : void +>this.props.thumbYProps!.elementRef : ElementRef +>this.props.thumbYProps! : ThumbProps +>this.props.thumbYProps : ThumbProps | undefined +>this.props : ComponentProps +>this : this +>props : ComponentProps +>thumbYProps : ThumbProps | undefined +>elementRef : ElementRef +>ref : HTMLElement | null + + typeof this.props.thumbXProps.elementRef === 'function' && this.props.thumbXProps.elementRef(ref); +>typeof this.props.thumbXProps.elementRef === 'function' && this.props.thumbXProps.elementRef(ref) : false | void +>typeof this.props.thumbXProps.elementRef === 'function' : boolean +>typeof this.props.thumbXProps.elementRef : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" +>this.props.thumbXProps.elementRef : ElementRef | undefined +>this.props.thumbXProps : ThumbProps +>this.props : ComponentProps +>this : this +>props : ComponentProps +>thumbXProps : ThumbProps +>elementRef : ElementRef | undefined +>'function' : "function" +>this.props.thumbXProps.elementRef(ref) : void +>this.props.thumbXProps.elementRef : ElementRef +>this.props.thumbXProps : ThumbProps +>this.props : ComponentProps +>this : this +>props : ComponentProps +>thumbXProps : ThumbProps +>elementRef : ElementRef +>ref : HTMLElement | null + + typeof this.props.thumbXProps.elementRef === 'function' && (this.props).thumbXProps.elementRef(ref); +>typeof this.props.thumbXProps.elementRef === 'function' && (this.props).thumbXProps.elementRef(ref) : false | void +>typeof this.props.thumbXProps.elementRef === 'function' : boolean +>typeof this.props.thumbXProps.elementRef : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" +>this.props.thumbXProps.elementRef : ElementRef | undefined +>this.props.thumbXProps : ThumbProps +>this.props : ComponentProps +>this : this +>props : ComponentProps +>thumbXProps : ThumbProps +>elementRef : ElementRef | undefined +>'function' : "function" +>(this.props).thumbXProps.elementRef(ref) : void +>(this.props).thumbXProps.elementRef : ElementRef +>(this.props).thumbXProps : ThumbProps +>(this.props) : ComponentProps +>this.props : ComponentProps +>this : this +>props : ComponentProps +>thumbXProps : ThumbProps +>elementRef : ElementRef +>ref : HTMLElement | null + + typeof this.props.thumbXProps.elementRef === 'function' && (this.props.thumbXProps).elementRef(ref); +>typeof this.props.thumbXProps.elementRef === 'function' && (this.props.thumbXProps).elementRef(ref) : false | void +>typeof this.props.thumbXProps.elementRef === 'function' : boolean +>typeof this.props.thumbXProps.elementRef : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" +>this.props.thumbXProps.elementRef : ElementRef | undefined +>this.props.thumbXProps : ThumbProps +>this.props : ComponentProps +>this : this +>props : ComponentProps +>thumbXProps : ThumbProps +>elementRef : ElementRef | undefined +>'function' : "function" +>(this.props.thumbXProps).elementRef(ref) : void +>(this.props.thumbXProps).elementRef : ElementRef +>(this.props.thumbXProps) : ThumbProps +>this.props.thumbXProps : ThumbProps +>this.props : ComponentProps +>this : this +>props : ComponentProps +>thumbXProps : ThumbProps +>elementRef : ElementRef +>ref : HTMLElement | null + + typeof this.props.thumbXProps.elementRef === 'function' && ((this.props)!.thumbXProps)!.elementRef(ref); +>typeof this.props.thumbXProps.elementRef === 'function' && ((this.props)!.thumbXProps)!.elementRef(ref) : false | void +>typeof this.props.thumbXProps.elementRef === 'function' : boolean +>typeof this.props.thumbXProps.elementRef : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" +>this.props.thumbXProps.elementRef : ElementRef | undefined +>this.props.thumbXProps : ThumbProps +>this.props : ComponentProps +>this : this +>props : ComponentProps +>thumbXProps : ThumbProps +>elementRef : ElementRef | undefined +>'function' : "function" +>((this.props)!.thumbXProps)!.elementRef(ref) : void +>((this.props)!.thumbXProps)!.elementRef : ElementRef +>((this.props)!.thumbXProps)! : ThumbProps +>((this.props)!.thumbXProps) : ThumbProps +>(this.props)!.thumbXProps : ThumbProps +>(this.props)! : ComponentProps +>(this.props) : ComponentProps +>this.props : ComponentProps +>this : this +>props : ComponentProps +>thumbXProps : ThumbProps +>elementRef : ElementRef +>ref : HTMLElement | null + + typeof (this.props.thumbXProps).elementRef === 'function' && ((this.props)!.thumbXProps)!.elementRef(ref); +>typeof (this.props.thumbXProps).elementRef === 'function' && ((this.props)!.thumbXProps)!.elementRef(ref) : false | void +>typeof (this.props.thumbXProps).elementRef === 'function' : boolean +>typeof (this.props.thumbXProps).elementRef : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" +>(this.props.thumbXProps).elementRef : ElementRef | undefined +>(this.props.thumbXProps) : ThumbProps +>this.props.thumbXProps : ThumbProps +>this.props : ComponentProps +>this : this +>props : ComponentProps +>thumbXProps : ThumbProps +>elementRef : ElementRef | undefined +>'function' : "function" +>((this.props)!.thumbXProps)!.elementRef(ref) : void +>((this.props)!.thumbXProps)!.elementRef : ElementRef +>((this.props)!.thumbXProps)! : ThumbProps +>((this.props)!.thumbXProps) : ThumbProps +>(this.props)!.thumbXProps : ThumbProps +>(this.props)! : ComponentProps +>(this.props) : ComponentProps +>this.props : ComponentProps +>this : this +>props : ComponentProps +>thumbXProps : ThumbProps +>elementRef : ElementRef +>ref : HTMLElement | null + + typeof this.props!.thumbXProps!.elementRef === 'function' && ((this.props)!.thumbXProps)!.elementRef(ref); +>typeof this.props!.thumbXProps!.elementRef === 'function' && ((this.props)!.thumbXProps)!.elementRef(ref) : false | void +>typeof this.props!.thumbXProps!.elementRef === 'function' : boolean +>typeof this.props!.thumbXProps!.elementRef : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" +>this.props!.thumbXProps!.elementRef : ElementRef | undefined +>this.props!.thumbXProps! : ThumbProps +>this.props!.thumbXProps : ThumbProps +>this.props! : ComponentProps +>this.props : ComponentProps +>this : this +>props : ComponentProps +>thumbXProps : ThumbProps +>elementRef : ElementRef | undefined +>'function' : "function" +>((this.props)!.thumbXProps)!.elementRef(ref) : void +>((this.props)!.thumbXProps)!.elementRef : ElementRef +>((this.props)!.thumbXProps)! : ThumbProps +>((this.props)!.thumbXProps) : ThumbProps +>(this.props)!.thumbXProps : ThumbProps +>(this.props)! : ComponentProps +>(this.props) : ComponentProps +>this.props : ComponentProps +>this : this +>props : ComponentProps +>thumbXProps : ThumbProps +>elementRef : ElementRef +>ref : HTMLElement | null + + }; +} diff --git a/tests/cases/compiler/nonNullReferenceMatching.ts b/tests/cases/compiler/nonNullReferenceMatching.ts new file mode 100644 index 00000000000..1295c3ce9a7 --- /dev/null +++ b/tests/cases/compiler/nonNullReferenceMatching.ts @@ -0,0 +1,34 @@ +// @strict: true +type ElementRef = (element: HTMLElement | null) => void; + +type ThumbProps = { + elementRef?: ElementRef; +} + +type ComponentProps = { + thumbYProps?: ThumbProps; + thumbXProps: ThumbProps; +} + +class Component { + props!: ComponentProps; + public thumbYElementRef = (ref: HTMLElement | null) => { + typeof this.props.thumbYProps!.elementRef === 'function' && this.props.thumbYProps!.elementRef(ref); + + typeof (this.props.thumbYProps!.elementRef) === 'function' && this.props.thumbYProps!.elementRef(ref); + + typeof ((this.props).thumbYProps!.elementRef)! === 'function' && this.props.thumbYProps!.elementRef(ref); + + typeof this.props.thumbXProps.elementRef === 'function' && this.props.thumbXProps.elementRef(ref); + + typeof this.props.thumbXProps.elementRef === 'function' && (this.props).thumbXProps.elementRef(ref); + + typeof this.props.thumbXProps.elementRef === 'function' && (this.props.thumbXProps).elementRef(ref); + + typeof this.props.thumbXProps.elementRef === 'function' && ((this.props)!.thumbXProps)!.elementRef(ref); + + typeof (this.props.thumbXProps).elementRef === 'function' && ((this.props)!.thumbXProps)!.elementRef(ref); + + typeof this.props!.thumbXProps!.elementRef === 'function' && ((this.props)!.thumbXProps)!.elementRef(ref); + }; +} \ No newline at end of file From aba0b700b638498a7774003b053074193c890103 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 10 Jan 2019 14:48:15 -0800 Subject: [PATCH 72/96] Allow circular umd-merged-with-augmentation refs to resolve to the module as intended (#29335) --- src/compiler/checker.ts | 8 ++++ ...rgedWithGlobalAugmentationIsNotCircular.js | 31 +++++++++++++ ...ithGlobalAugmentationIsNotCircular.symbols | 42 ++++++++++++++++++ ...dWithGlobalAugmentationIsNotCircular.types | 44 +++++++++++++++++++ ...rgedWithGlobalAugmentationIsNotCircular.ts | 26 +++++++++++ 5 files changed, 151 insertions(+) create mode 100644 tests/baselines/reference/umdNamespaceMergedWithGlobalAugmentationIsNotCircular.js create mode 100644 tests/baselines/reference/umdNamespaceMergedWithGlobalAugmentationIsNotCircular.symbols create mode 100644 tests/baselines/reference/umdNamespaceMergedWithGlobalAugmentationIsNotCircular.types create mode 100644 tests/cases/compiler/umdNamespaceMergedWithGlobalAugmentationIsNotCircular.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3bb26e83dd8..b1f73584c49 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5431,6 +5431,10 @@ namespace ts { // Handle variable, parameter or property if (!pushTypeResolution(symbol, TypeSystemPropertyName.Type)) { + // Symbol is property of some kind that is merged with something - should use `getTypeOfFuncClassEnumModule` and not `getTypeOfVariableOrParameterOrProperty` + if (symbol.flags & SymbolFlags.ValueModule) { + return getTypeOfFuncClassEnumModule(symbol); + } return errorType; } let type: Type | undefined; @@ -5486,6 +5490,10 @@ namespace ts { } if (!popTypeResolution()) { + // Symbol is property of some kind that is merged with something - should use `getTypeOfFuncClassEnumModule` and not `getTypeOfVariableOrParameterOrProperty` + if (symbol.flags & SymbolFlags.ValueModule) { + return getTypeOfFuncClassEnumModule(symbol); + } type = reportCircularityError(symbol); } return type; diff --git a/tests/baselines/reference/umdNamespaceMergedWithGlobalAugmentationIsNotCircular.js b/tests/baselines/reference/umdNamespaceMergedWithGlobalAugmentationIsNotCircular.js new file mode 100644 index 00000000000..377082fa5d5 --- /dev/null +++ b/tests/baselines/reference/umdNamespaceMergedWithGlobalAugmentationIsNotCircular.js @@ -0,0 +1,31 @@ +//// [tests/cases/compiler/umdNamespaceMergedWithGlobalAugmentationIsNotCircular.ts] //// + +//// [global.d.ts] +declare global { + const React: typeof import("./module"); +} + +export { }; + +//// [module.d.ts] +export = React; +export as namespace React; + +declare namespace React { + function createRef(): any; +} + +//// [some_module.ts] +export { }; +React.createRef; + +//// [emits.ts] +console.log("hello"); +React.createRef; + +//// [some_module.js] +React.createRef; +//// [emits.js] +"use strict"; +console.log("hello"); +React.createRef; diff --git a/tests/baselines/reference/umdNamespaceMergedWithGlobalAugmentationIsNotCircular.symbols b/tests/baselines/reference/umdNamespaceMergedWithGlobalAugmentationIsNotCircular.symbols new file mode 100644 index 00000000000..24a9885b294 --- /dev/null +++ b/tests/baselines/reference/umdNamespaceMergedWithGlobalAugmentationIsNotCircular.symbols @@ -0,0 +1,42 @@ +=== tests/cases/compiler/global.d.ts === +declare global { +>global : Symbol(global, Decl(global.d.ts, 0, 0)) + + const React: typeof import("./module"); +>React : Symbol(React, Decl(module.d.ts, 1, 26), Decl(global.d.ts, 1, 9)) +} + +export { }; + +=== tests/cases/compiler/module.d.ts === +export = React; +>React : Symbol(React, Decl(module.d.ts, 1, 26)) + +export as namespace React; +>React : Symbol(React, Decl(module.d.ts, 0, 15)) + +declare namespace React { +>React : Symbol(React, Decl(module.d.ts, 1, 26), Decl(global.d.ts, 1, 9)) + + function createRef(): any; +>createRef : Symbol(createRef, Decl(module.d.ts, 3, 25)) +} + +=== tests/cases/compiler/some_module.ts === +export { }; +React.createRef; +>React.createRef : Symbol(React.createRef, Decl(module.d.ts, 3, 25)) +>React : Symbol(React, Decl(module.d.ts, 1, 26), Decl(global.d.ts, 1, 9)) +>createRef : Symbol(React.createRef, Decl(module.d.ts, 3, 25)) + +=== tests/cases/compiler/emits.ts === +console.log("hello"); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) + +React.createRef; +>React.createRef : Symbol(React.createRef, Decl(module.d.ts, 3, 25)) +>React : Symbol(React, Decl(module.d.ts, 1, 26), Decl(global.d.ts, 1, 9)) +>createRef : Symbol(React.createRef, Decl(module.d.ts, 3, 25)) + diff --git a/tests/baselines/reference/umdNamespaceMergedWithGlobalAugmentationIsNotCircular.types b/tests/baselines/reference/umdNamespaceMergedWithGlobalAugmentationIsNotCircular.types new file mode 100644 index 00000000000..2c0ce91aec8 --- /dev/null +++ b/tests/baselines/reference/umdNamespaceMergedWithGlobalAugmentationIsNotCircular.types @@ -0,0 +1,44 @@ +=== tests/cases/compiler/global.d.ts === +declare global { +>global : typeof global + + const React: typeof import("./module"); +>React : typeof React +} + +export { }; + +=== tests/cases/compiler/module.d.ts === +export = React; +>React : typeof React + +export as namespace React; +>React : typeof React + +declare namespace React { +>React : typeof React + + function createRef(): any; +>createRef : () => any +} + +=== tests/cases/compiler/some_module.ts === +export { }; +React.createRef; +>React.createRef : () => any +>React : typeof React +>createRef : () => any + +=== tests/cases/compiler/emits.ts === +console.log("hello"); +>console.log("hello") : void +>console.log : (message?: any, ...optionalParams: any[]) => void +>console : Console +>log : (message?: any, ...optionalParams: any[]) => void +>"hello" : "hello" + +React.createRef; +>React.createRef : () => any +>React : typeof React +>createRef : () => any + diff --git a/tests/cases/compiler/umdNamespaceMergedWithGlobalAugmentationIsNotCircular.ts b/tests/cases/compiler/umdNamespaceMergedWithGlobalAugmentationIsNotCircular.ts new file mode 100644 index 00000000000..81346aca1b4 --- /dev/null +++ b/tests/cases/compiler/umdNamespaceMergedWithGlobalAugmentationIsNotCircular.ts @@ -0,0 +1,26 @@ +// @strict: true +// @module: esnext +// @moduleResolution: node +// @target: es2018 +// @filename: global.d.ts +declare global { + const React: typeof import("./module"); +} + +export { }; + +// @filename: module.d.ts +export = React; +export as namespace React; + +declare namespace React { + function createRef(): any; +} + +// @filename: some_module.ts +export { }; +React.createRef; + +// @filename: emits.ts +console.log("hello"); +React.createRef; \ No newline at end of file From b3633fab5275f2a3b2c29e2b9f4ba5106e002dfa Mon Sep 17 00:00:00 2001 From: Gabriela Britto Date: Thu, 10 Jan 2019 15:04:16 -0800 Subject: [PATCH 73/96] Add more tests for qualified name param without top level object error --- ...aramTagNestedWithoutTopLevelObject4.errors.txt | 12 ++++++++++++ .../paramTagNestedWithoutTopLevelObject4.symbols | 11 +++++++++++ .../paramTagNestedWithoutTopLevelObject4.types | 15 +++++++++++++++ .../jsdoc/paramTagNestedWithoutTopLevelObject2.ts | 12 ++++++++++++ .../jsdoc/paramTagNestedWithoutTopLevelObject3.ts | 12 ++++++++++++ .../jsdoc/paramTagNestedWithoutTopLevelObject4.ts | 11 +++++++++++ 6 files changed, 73 insertions(+) create mode 100644 tests/baselines/reference/paramTagNestedWithoutTopLevelObject4.errors.txt create mode 100644 tests/baselines/reference/paramTagNestedWithoutTopLevelObject4.symbols create mode 100644 tests/baselines/reference/paramTagNestedWithoutTopLevelObject4.types create mode 100644 tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject2.ts create mode 100644 tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject3.ts create mode 100644 tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject4.ts diff --git a/tests/baselines/reference/paramTagNestedWithoutTopLevelObject4.errors.txt b/tests/baselines/reference/paramTagNestedWithoutTopLevelObject4.errors.txt new file mode 100644 index 00000000000..74ca02ef006 --- /dev/null +++ b/tests/baselines/reference/paramTagNestedWithoutTopLevelObject4.errors.txt @@ -0,0 +1,12 @@ +tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject4.js(2,20): error TS8032: Qualified name 'xyz.bar.p' is not allowed without a leading '@param {object} xyz.bar'. + + +==== tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject4.js (1 errors) ==== + /** + * @param {number} xyz.bar.p + ~~~~~~~~~ +!!! error TS8032: Qualified name 'xyz.bar.p' is not allowed without a leading '@param {object} xyz.bar'. + */ + function g(xyz) { + return xyz.bar.p; + } \ No newline at end of file diff --git a/tests/baselines/reference/paramTagNestedWithoutTopLevelObject4.symbols b/tests/baselines/reference/paramTagNestedWithoutTopLevelObject4.symbols new file mode 100644 index 00000000000..6f8e1ffa643 --- /dev/null +++ b/tests/baselines/reference/paramTagNestedWithoutTopLevelObject4.symbols @@ -0,0 +1,11 @@ +=== tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject4.js === +/** + * @param {number} xyz.bar.p + */ +function g(xyz) { +>g : Symbol(g, Decl(paramTagNestedWithoutTopLevelObject4.js, 0, 0)) +>xyz : Symbol(xyz, Decl(paramTagNestedWithoutTopLevelObject4.js, 3, 11)) + + return xyz.bar.p; +>xyz : Symbol(xyz, Decl(paramTagNestedWithoutTopLevelObject4.js, 3, 11)) +} diff --git a/tests/baselines/reference/paramTagNestedWithoutTopLevelObject4.types b/tests/baselines/reference/paramTagNestedWithoutTopLevelObject4.types new file mode 100644 index 00000000000..8b9843bdbee --- /dev/null +++ b/tests/baselines/reference/paramTagNestedWithoutTopLevelObject4.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject4.js === +/** + * @param {number} xyz.bar.p + */ +function g(xyz) { +>g : (xyz: any) => any +>xyz : any + + return xyz.bar.p; +>xyz.bar.p : any +>xyz.bar : any +>xyz : any +>bar : any +>p : any +} diff --git a/tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject2.ts b/tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject2.ts new file mode 100644 index 00000000000..a6a68aa0861 --- /dev/null +++ b/tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject2.ts @@ -0,0 +1,12 @@ +// @noEmit: true +// @allowJs: true +// @checkJs: true +// @Filename: paramTagNestedWithoutTopLevelObject2.js + +/** + * @param {object} xyz.bar + * @param {number} xyz.bar.p + */ +function g(xyz) { + return xyz.bar.p; +} \ No newline at end of file diff --git a/tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject3.ts b/tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject3.ts new file mode 100644 index 00000000000..8307688a0cd --- /dev/null +++ b/tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject3.ts @@ -0,0 +1,12 @@ +// @noEmit: true +// @allowJs: true +// @checkJs: true +// @Filename: paramTagNestedWithoutTopLevelObject3.js + +/** + * @param {object} xyz + * @param {number} xyz.bar.p + */ +function g(xyz) { + return xyz.bar.p; +} \ No newline at end of file diff --git a/tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject4.ts b/tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject4.ts new file mode 100644 index 00000000000..5840308fa0d --- /dev/null +++ b/tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject4.ts @@ -0,0 +1,11 @@ +// @noEmit: true +// @allowJs: true +// @checkJs: true +// @Filename: paramTagNestedWithoutTopLevelObject4.js + +/** + * @param {number} xyz.bar.p + */ +function g(xyz) { + return xyz.bar.p; +} \ No newline at end of file From ed5775865a971b74bbbd0f430214e5fb96beed5b Mon Sep 17 00:00:00 2001 From: Gabriela Britto Date: Thu, 10 Jan 2019 15:45:00 -0800 Subject: [PATCH 74/96] Add missing baseline references --- ...ramTagNestedWithoutTopLevelObject2.errors.txt | 13 +++++++++++++ .../paramTagNestedWithoutTopLevelObject2.symbols | 12 ++++++++++++ .../paramTagNestedWithoutTopLevelObject2.types | 16 ++++++++++++++++ ...ramTagNestedWithoutTopLevelObject3.errors.txt | 13 +++++++++++++ .../paramTagNestedWithoutTopLevelObject3.symbols | 12 ++++++++++++ .../paramTagNestedWithoutTopLevelObject3.types | 16 ++++++++++++++++ 6 files changed, 82 insertions(+) create mode 100644 tests/baselines/reference/paramTagNestedWithoutTopLevelObject2.errors.txt create mode 100644 tests/baselines/reference/paramTagNestedWithoutTopLevelObject2.symbols create mode 100644 tests/baselines/reference/paramTagNestedWithoutTopLevelObject2.types create mode 100644 tests/baselines/reference/paramTagNestedWithoutTopLevelObject3.errors.txt create mode 100644 tests/baselines/reference/paramTagNestedWithoutTopLevelObject3.symbols create mode 100644 tests/baselines/reference/paramTagNestedWithoutTopLevelObject3.types diff --git a/tests/baselines/reference/paramTagNestedWithoutTopLevelObject2.errors.txt b/tests/baselines/reference/paramTagNestedWithoutTopLevelObject2.errors.txt new file mode 100644 index 00000000000..d3e94e1cff4 --- /dev/null +++ b/tests/baselines/reference/paramTagNestedWithoutTopLevelObject2.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject2.js(2,20): error TS8032: Qualified name 'xyz.bar' is not allowed without a leading '@param {object} xyz'. + + +==== tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject2.js (1 errors) ==== + /** + * @param {object} xyz.bar + ~~~~~~~ +!!! error TS8032: Qualified name 'xyz.bar' is not allowed without a leading '@param {object} xyz'. + * @param {number} xyz.bar.p + */ + function g(xyz) { + return xyz.bar.p; + } \ No newline at end of file diff --git a/tests/baselines/reference/paramTagNestedWithoutTopLevelObject2.symbols b/tests/baselines/reference/paramTagNestedWithoutTopLevelObject2.symbols new file mode 100644 index 00000000000..e6acfb7cbc4 --- /dev/null +++ b/tests/baselines/reference/paramTagNestedWithoutTopLevelObject2.symbols @@ -0,0 +1,12 @@ +=== tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject2.js === +/** + * @param {object} xyz.bar + * @param {number} xyz.bar.p + */ +function g(xyz) { +>g : Symbol(g, Decl(paramTagNestedWithoutTopLevelObject2.js, 0, 0)) +>xyz : Symbol(xyz, Decl(paramTagNestedWithoutTopLevelObject2.js, 4, 11)) + + return xyz.bar.p; +>xyz : Symbol(xyz, Decl(paramTagNestedWithoutTopLevelObject2.js, 4, 11)) +} diff --git a/tests/baselines/reference/paramTagNestedWithoutTopLevelObject2.types b/tests/baselines/reference/paramTagNestedWithoutTopLevelObject2.types new file mode 100644 index 00000000000..2f6598ffa2d --- /dev/null +++ b/tests/baselines/reference/paramTagNestedWithoutTopLevelObject2.types @@ -0,0 +1,16 @@ +=== tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject2.js === +/** + * @param {object} xyz.bar + * @param {number} xyz.bar.p + */ +function g(xyz) { +>g : (xyz: any) => any +>xyz : any + + return xyz.bar.p; +>xyz.bar.p : any +>xyz.bar : any +>xyz : any +>bar : any +>p : any +} diff --git a/tests/baselines/reference/paramTagNestedWithoutTopLevelObject3.errors.txt b/tests/baselines/reference/paramTagNestedWithoutTopLevelObject3.errors.txt new file mode 100644 index 00000000000..d73f35cfcb2 --- /dev/null +++ b/tests/baselines/reference/paramTagNestedWithoutTopLevelObject3.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject3.js(3,20): error TS8032: Qualified name 'xyz.bar.p' is not allowed without a leading '@param {object} xyz.bar'. + + +==== tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject3.js (1 errors) ==== + /** + * @param {object} xyz + * @param {number} xyz.bar.p + ~~~~~~~~~ +!!! error TS8032: Qualified name 'xyz.bar.p' is not allowed without a leading '@param {object} xyz.bar'. + */ + function g(xyz) { + return xyz.bar.p; + } \ No newline at end of file diff --git a/tests/baselines/reference/paramTagNestedWithoutTopLevelObject3.symbols b/tests/baselines/reference/paramTagNestedWithoutTopLevelObject3.symbols new file mode 100644 index 00000000000..a350edded90 --- /dev/null +++ b/tests/baselines/reference/paramTagNestedWithoutTopLevelObject3.symbols @@ -0,0 +1,12 @@ +=== tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject3.js === +/** + * @param {object} xyz + * @param {number} xyz.bar.p + */ +function g(xyz) { +>g : Symbol(g, Decl(paramTagNestedWithoutTopLevelObject3.js, 0, 0)) +>xyz : Symbol(xyz, Decl(paramTagNestedWithoutTopLevelObject3.js, 4, 11)) + + return xyz.bar.p; +>xyz : Symbol(xyz, Decl(paramTagNestedWithoutTopLevelObject3.js, 4, 11)) +} diff --git a/tests/baselines/reference/paramTagNestedWithoutTopLevelObject3.types b/tests/baselines/reference/paramTagNestedWithoutTopLevelObject3.types new file mode 100644 index 00000000000..a2bb9ddf329 --- /dev/null +++ b/tests/baselines/reference/paramTagNestedWithoutTopLevelObject3.types @@ -0,0 +1,16 @@ +=== tests/cases/conformance/jsdoc/paramTagNestedWithoutTopLevelObject3.js === +/** + * @param {object} xyz + * @param {number} xyz.bar.p + */ +function g(xyz) { +>g : (xyz: any) => any +>xyz : any + + return xyz.bar.p; +>xyz.bar.p : any +>xyz.bar : any +>xyz : any +>bar : any +>p : any +} From 9d16225bc2c96a06589f8e9b5f8a60d79a82d31e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=96=87=E7=92=90?= Date: Fri, 11 Jan 2019 13:34:18 +0800 Subject: [PATCH 75/96] emit jsx type arguments --- src/compiler/emitter.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 9c09ed79a77..62aba51afec 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2561,6 +2561,7 @@ namespace ts { function emitJsxSelfClosingElement(node: JsxSelfClosingElement) { writePunctuation("<"); emitJsxTagName(node.tagName); + emitTypeArguments(node, node.typeArguments); writeSpace(); emit(node.attributes); writePunctuation("/>"); @@ -2577,6 +2578,7 @@ namespace ts { if (isJsxOpeningElement(node)) { emitJsxTagName(node.tagName); + emitTypeArguments(node, node.typeArguments); if (node.attributes.properties && node.attributes.properties.length > 0) { writeSpace(); } From 11b150129a988fe43bd74f6d349f19edb799f19b Mon Sep 17 00:00:00 2001 From: Martin Probst Date: Fri, 14 Dec 2018 14:26:32 +0100 Subject: [PATCH 76/96] Do not process library reference directives with noLib set. When a user sets `noLib`, this indicates that they will supply their own list of `lib*.d.ts` files as part of input sources. In this situation, TypeScript should not try to resolve library reference directives. This avoids a problem where TypeScript loads a file that e.g. contains `/// `. Previously, TypeScript would use its builtin ts.libMap and attempt to load builtin libraries from the TypeScript installation, instead of respecting the user-supplied set of libraries. --- src/compiler/program.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 080b17b8cbe..271bdab976e 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -2227,8 +2227,9 @@ namespace ts { processReferencedFiles(file, isDefaultLib); processTypeReferenceDirectives(file); } - - processLibReferenceDirectives(file); + if (!options.noLib) { + processLibReferenceDirectives(file); + } modulesWithElidedImports.set(file.path, false); processImportedModules(file); @@ -2315,8 +2316,10 @@ namespace ts { processReferencedFiles(file, isDefaultLib); processTypeReferenceDirectives(file); } + if (!options.noLib) { + processLibReferenceDirectives(file); + } - processLibReferenceDirectives(file); // always process imported modules to record module name resolutions processImportedModules(file); From cc7ddaed281f9ab72586fd4028d6f11f3459fd5f Mon Sep 17 00:00:00 2001 From: Martin Probst Date: Sat, 15 Dec 2018 16:43:37 +0100 Subject: [PATCH 77/96] Add tests for noLib with . --- .../baselines/reference/libReferenceNoLib.js | 51 +++++++++++++++++++ .../reference/libReferenceNoLib.symbols | 40 +++++++++++++++ .../reference/libReferenceNoLib.types | 24 +++++++++ .../declarationEmit/libReferenceNoLib.ts | 21 ++++++++ 4 files changed, 136 insertions(+) create mode 100644 tests/baselines/reference/libReferenceNoLib.js create mode 100644 tests/baselines/reference/libReferenceNoLib.symbols create mode 100644 tests/baselines/reference/libReferenceNoLib.types create mode 100644 tests/cases/conformance/declarationEmit/libReferenceNoLib.ts diff --git a/tests/baselines/reference/libReferenceNoLib.js b/tests/baselines/reference/libReferenceNoLib.js new file mode 100644 index 00000000000..21d1cbbe177 --- /dev/null +++ b/tests/baselines/reference/libReferenceNoLib.js @@ -0,0 +1,51 @@ +//// [tests/cases/conformance/declarationEmit/libReferenceNoLib.ts] //// + +//// [fakelib.ts] +// Test that passing noLib disables resolution. + +interface Object { } +interface Array { } +interface String { } +interface Boolean { } +interface Number { } +interface Function { } +interface RegExp { } +interface IArguments { } + + +//// [file1.ts] +/// +export declare interface HTMLElement { field: string; } +export const elem: HTMLElement = { field: 'a' }; + + +//// [fakelib.js] +// Test that passing noLib disables resolution. +//// [file1.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.elem = { field: 'a' }; + + +//// [fakelib.d.ts] +interface Object { +} +interface Array { +} +interface String { +} +interface Boolean { +} +interface Number { +} +interface Function { +} +interface RegExp { +} +interface IArguments { +} +//// [file1.d.ts] +export declare interface HTMLElement { + field: string; +} +export declare const elem: HTMLElement; diff --git a/tests/baselines/reference/libReferenceNoLib.symbols b/tests/baselines/reference/libReferenceNoLib.symbols new file mode 100644 index 00000000000..5f180fd1eed --- /dev/null +++ b/tests/baselines/reference/libReferenceNoLib.symbols @@ -0,0 +1,40 @@ +=== tests/cases/conformance/declarationEmit/fakelib.ts === +// Test that passing noLib disables resolution. + +interface Object { } +>Object : Symbol(Object, Decl(fakelib.ts, 0, 0)) + +interface Array { } +>Array : Symbol(Array, Decl(fakelib.ts, 2, 20)) +>T : Symbol(T, Decl(fakelib.ts, 3, 16)) + +interface String { } +>String : Symbol(String, Decl(fakelib.ts, 3, 22)) + +interface Boolean { } +>Boolean : Symbol(Boolean, Decl(fakelib.ts, 4, 20)) + +interface Number { } +>Number : Symbol(Number, Decl(fakelib.ts, 5, 21)) + +interface Function { } +>Function : Symbol(Function, Decl(fakelib.ts, 6, 20)) + +interface RegExp { } +>RegExp : Symbol(RegExp, Decl(fakelib.ts, 7, 22)) + +interface IArguments { } +>IArguments : Symbol(IArguments, Decl(fakelib.ts, 8, 20)) + + +=== tests/cases/conformance/declarationEmit/file1.ts === +/// +export declare interface HTMLElement { field: string; } +>HTMLElement : Symbol(HTMLElement, Decl(file1.ts, 0, 0)) +>field : Symbol(HTMLElement.field, Decl(file1.ts, 1, 38)) + +export const elem: HTMLElement = { field: 'a' }; +>elem : Symbol(elem, Decl(file1.ts, 2, 12)) +>HTMLElement : Symbol(HTMLElement, Decl(file1.ts, 0, 0)) +>field : Symbol(field, Decl(file1.ts, 2, 34)) + diff --git a/tests/baselines/reference/libReferenceNoLib.types b/tests/baselines/reference/libReferenceNoLib.types new file mode 100644 index 00000000000..0b2733c2265 --- /dev/null +++ b/tests/baselines/reference/libReferenceNoLib.types @@ -0,0 +1,24 @@ +=== tests/cases/conformance/declarationEmit/fakelib.ts === +// Test that passing noLib disables resolution. +No type information for this code. +No type information for this code.interface Object { } +No type information for this code.interface Array { } +No type information for this code.interface String { } +No type information for this code.interface Boolean { } +No type information for this code.interface Number { } +No type information for this code.interface Function { } +No type information for this code.interface RegExp { } +No type information for this code.interface IArguments { } +No type information for this code. +No type information for this code. +No type information for this code.=== tests/cases/conformance/declarationEmit/file1.ts === +/// +export declare interface HTMLElement { field: string; } +>field : string + +export const elem: HTMLElement = { field: 'a' }; +>elem : HTMLElement +>{ field: 'a' } : { field: string; } +>field : string +>'a' : "a" + diff --git a/tests/cases/conformance/declarationEmit/libReferenceNoLib.ts b/tests/cases/conformance/declarationEmit/libReferenceNoLib.ts new file mode 100644 index 00000000000..d29da9a5bc5 --- /dev/null +++ b/tests/cases/conformance/declarationEmit/libReferenceNoLib.ts @@ -0,0 +1,21 @@ +// @target: esnext +// @module: commonjs +// @noLib: true +// @declaration: true +// Test that passing noLib disables resolution. + +// @filename: fakelib.ts +interface Object { } +interface Array { } +interface String { } +interface Boolean { } +interface Number { } +interface Function { } +interface RegExp { } +interface IArguments { } + + +// @filename: file1.ts +/// +export declare interface HTMLElement { field: string; } +export const elem: HTMLElement = { field: 'a' }; From f3f5877c5f7659851fc7494b6c15bc5cb12834af Mon Sep 17 00:00:00 2001 From: Martin Probst Date: Fri, 11 Jan 2019 08:36:16 +0100 Subject: [PATCH 78/96] Add tests for noLib with and bundling. --- .../reference/libReferenceNoLibBundle.js | 53 +++++++++++++++++++ .../reference/libReferenceNoLibBundle.symbols | 40 ++++++++++++++ .../reference/libReferenceNoLibBundle.types | 24 +++++++++ .../libReferenceNoLibBundle.ts | 23 ++++++++ 4 files changed, 140 insertions(+) create mode 100644 tests/baselines/reference/libReferenceNoLibBundle.js create mode 100644 tests/baselines/reference/libReferenceNoLibBundle.symbols create mode 100644 tests/baselines/reference/libReferenceNoLibBundle.types create mode 100644 tests/cases/conformance/declarationEmit/libReferenceNoLibBundle.ts diff --git a/tests/baselines/reference/libReferenceNoLibBundle.js b/tests/baselines/reference/libReferenceNoLibBundle.js new file mode 100644 index 00000000000..a881f11a8a1 --- /dev/null +++ b/tests/baselines/reference/libReferenceNoLibBundle.js @@ -0,0 +1,53 @@ +//// [tests/cases/conformance/declarationEmit/libReferenceNoLibBundle.ts] //// + +//// [fakelib.ts] +// Test that passing noLib disables resolution. + +interface Object { } +interface Array { } +interface String { } +interface Boolean { } +interface Number { } +interface Function { } +interface RegExp { } +interface IArguments { } + + +//// [file1.ts] +/// +export declare interface HTMLElement { field: string; } +export const elem: HTMLElement = { field: 'a' }; + + +//// [bundle.js] +// Test that passing noLib disables resolution. +define("file1", ["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.elem = { field: 'a' }; +}); + + +//// [bundle.d.ts] +interface Object { +} +interface Array { +} +interface String { +} +interface Boolean { +} +interface Number { +} +interface Function { +} +interface RegExp { +} +interface IArguments { +} +declare module "file1" { + export interface HTMLElement { + field: string; + } + export const elem: HTMLElement; +} diff --git a/tests/baselines/reference/libReferenceNoLibBundle.symbols b/tests/baselines/reference/libReferenceNoLibBundle.symbols new file mode 100644 index 00000000000..5f180fd1eed --- /dev/null +++ b/tests/baselines/reference/libReferenceNoLibBundle.symbols @@ -0,0 +1,40 @@ +=== tests/cases/conformance/declarationEmit/fakelib.ts === +// Test that passing noLib disables resolution. + +interface Object { } +>Object : Symbol(Object, Decl(fakelib.ts, 0, 0)) + +interface Array { } +>Array : Symbol(Array, Decl(fakelib.ts, 2, 20)) +>T : Symbol(T, Decl(fakelib.ts, 3, 16)) + +interface String { } +>String : Symbol(String, Decl(fakelib.ts, 3, 22)) + +interface Boolean { } +>Boolean : Symbol(Boolean, Decl(fakelib.ts, 4, 20)) + +interface Number { } +>Number : Symbol(Number, Decl(fakelib.ts, 5, 21)) + +interface Function { } +>Function : Symbol(Function, Decl(fakelib.ts, 6, 20)) + +interface RegExp { } +>RegExp : Symbol(RegExp, Decl(fakelib.ts, 7, 22)) + +interface IArguments { } +>IArguments : Symbol(IArguments, Decl(fakelib.ts, 8, 20)) + + +=== tests/cases/conformance/declarationEmit/file1.ts === +/// +export declare interface HTMLElement { field: string; } +>HTMLElement : Symbol(HTMLElement, Decl(file1.ts, 0, 0)) +>field : Symbol(HTMLElement.field, Decl(file1.ts, 1, 38)) + +export const elem: HTMLElement = { field: 'a' }; +>elem : Symbol(elem, Decl(file1.ts, 2, 12)) +>HTMLElement : Symbol(HTMLElement, Decl(file1.ts, 0, 0)) +>field : Symbol(field, Decl(file1.ts, 2, 34)) + diff --git a/tests/baselines/reference/libReferenceNoLibBundle.types b/tests/baselines/reference/libReferenceNoLibBundle.types new file mode 100644 index 00000000000..0b2733c2265 --- /dev/null +++ b/tests/baselines/reference/libReferenceNoLibBundle.types @@ -0,0 +1,24 @@ +=== tests/cases/conformance/declarationEmit/fakelib.ts === +// Test that passing noLib disables resolution. +No type information for this code. +No type information for this code.interface Object { } +No type information for this code.interface Array { } +No type information for this code.interface String { } +No type information for this code.interface Boolean { } +No type information for this code.interface Number { } +No type information for this code.interface Function { } +No type information for this code.interface RegExp { } +No type information for this code.interface IArguments { } +No type information for this code. +No type information for this code. +No type information for this code.=== tests/cases/conformance/declarationEmit/file1.ts === +/// +export declare interface HTMLElement { field: string; } +>field : string + +export const elem: HTMLElement = { field: 'a' }; +>elem : HTMLElement +>{ field: 'a' } : { field: string; } +>field : string +>'a' : "a" + diff --git a/tests/cases/conformance/declarationEmit/libReferenceNoLibBundle.ts b/tests/cases/conformance/declarationEmit/libReferenceNoLibBundle.ts new file mode 100644 index 00000000000..18f0b5387c5 --- /dev/null +++ b/tests/cases/conformance/declarationEmit/libReferenceNoLibBundle.ts @@ -0,0 +1,23 @@ +// @target: esnext +// @module: amd +// @noLib: true +// @declaration: true +// @outFile: bundle.js + +// Test that passing noLib disables resolution. + +// @filename: fakelib.ts +interface Object { } +interface Array { } +interface String { } +interface Boolean { } +interface Number { } +interface Function { } +interface RegExp { } +interface IArguments { } + + +// @filename: file1.ts +/// +export declare interface HTMLElement { field: string; } +export const elem: HTMLElement = { field: 'a' }; From 8d28f9230cb3b4e032218b8019da22e61dd9abdd Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Fri, 11 Jan 2019 09:20:12 -0500 Subject: [PATCH 79/96] Added codefix to enable experimentalDecorators in the user's config file Starts on #29035 by creating a codefix to enable the `experimentalDecorators` setting in a user's config file, if one exists. The issue's discussion also mentions giving a more precise error message if the user has a jsconfig or tsconfig or creating one if not; I'd rather tackle those in separate PRs to keep this one small. Doesn't create the code action if no config file is present. Otherwise keeps to the precedent of returning without action when the config file contents aren't the expected JSON structure (looking at `fixCannotFindModule.ts`). Moves a couple JSON helpers from that file into the sibling `helpers.ts` so both codefixes can use them. --- src/compiler/diagnosticMessages.json | 4 ++ src/services/codefixes/fixCannotFindModule.ts | 14 +---- .../fixEnableExperimentalDecorators.ts | 60 +++++++++++++++++++ src/services/codefixes/helpers.ts | 8 +++ src/services/tsconfig.json | 1 + ...rimentalDecorators_blankCompilerOptions.ts | 26 ++++++++ ...talDecorators_disabledInCompilerOptions.ts | 27 +++++++++ ...mentalDecorators_missingCompilerOptions.ts | 22 +++++++ ...EnableExperimentalDecorators_noTsconfig.ts | 10 ++++ 9 files changed, 161 insertions(+), 11 deletions(-) create mode 100644 src/services/codefixes/fixEnableExperimentalDecorators.ts create mode 100644 tests/cases/fourslash/codefixEnableExperimentalDecorators_blankCompilerOptions.ts create mode 100644 tests/cases/fourslash/codefixEnableExperimentalDecorators_disabledInCompilerOptions.ts create mode 100644 tests/cases/fourslash/codefixEnableExperimentalDecorators_missingCompilerOptions.ts create mode 100644 tests/cases/fourslash/codefixEnableExperimentalDecorators_noTsconfig.ts diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 9a918507dc4..5bcaf448599 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -4811,5 +4811,9 @@ "Add names to all parameters without names": { "category": "Message", "code": 95073 + }, + "Enable the 'experimentalDecorators' option in your configuration file": { + "category": "Message", + "code": 95074 } } diff --git a/src/services/codefixes/fixCannotFindModule.ts b/src/services/codefixes/fixCannotFindModule.ts index 1c7070c74bf..1baaa9714f2 100644 --- a/src/services/codefixes/fixCannotFindModule.ts +++ b/src/services/codefixes/fixCannotFindModule.ts @@ -74,7 +74,7 @@ namespace ts.codefix { const tsconfigObjectLiteral = getTsConfigObjectLiteralExpression(configFile); if (!tsconfigObjectLiteral) return undefined; - const compilerOptionsProperty = findProperty(tsconfigObjectLiteral, "compilerOptions"); + const compilerOptionsProperty = findJsonProperty(tsconfigObjectLiteral, "compilerOptions"); if (!compilerOptionsProperty) { const newCompilerOptions = createObjectLiteral([makeDefaultBaseUrl(), makeDefaultPaths()]); changes.insertNodeAtObjectStart(configFile, tsconfigObjectLiteral, createJsonPropertyAssignment("compilerOptions", newCompilerOptions)); @@ -94,7 +94,7 @@ namespace ts.codefix { return createJsonPropertyAssignment("baseUrl", createStringLiteral(defaultBaseUrl)); } function getOrAddBaseUrl(changes: textChanges.ChangeTracker, tsconfig: TsConfigSourceFile, compilerOptions: ObjectLiteralExpression): string { - const baseUrlProp = findProperty(compilerOptions, "baseUrl"); + const baseUrlProp = findJsonProperty(compilerOptions, "baseUrl"); if (baseUrlProp) { return isStringLiteral(baseUrlProp.initializer) ? baseUrlProp.initializer.text : defaultBaseUrl; } @@ -112,7 +112,7 @@ namespace ts.codefix { return createJsonPropertyAssignment("paths", createObjectLiteral([makeDefaultPathMapping()])); } function getOrAddPathMapping(changes: textChanges.ChangeTracker, tsconfig: TsConfigSourceFile, compilerOptions: ObjectLiteralExpression) { - const paths = findProperty(compilerOptions, "paths"); + const paths = findJsonProperty(compilerOptions, "paths"); if (!paths || !isObjectLiteralExpression(paths.initializer)) { changes.insertNodeAtObjectStart(tsconfig, compilerOptions, makeDefaultPaths()); return defaultTypesDirectoryName; @@ -129,14 +129,6 @@ namespace ts.codefix { return defaultTypesDirectoryName; } - function createJsonPropertyAssignment(name: string, initializer: Expression) { - return createPropertyAssignment(createStringLiteral(name), initializer); - } - - function findProperty(obj: ObjectLiteralExpression, name: string): PropertyAssignment | undefined { - return find(obj.properties, (p): p is PropertyAssignment => isPropertyAssignment(p) && !!p.name && isStringLiteral(p.name) && p.name.text === name); - } - function getInstallCommand(fileName: string, packageName: string): InstallPackageAction { return { type: "install package", file: fileName, packageName }; } diff --git a/src/services/codefixes/fixEnableExperimentalDecorators.ts b/src/services/codefixes/fixEnableExperimentalDecorators.ts new file mode 100644 index 00000000000..8179abdfd1d --- /dev/null +++ b/src/services/codefixes/fixEnableExperimentalDecorators.ts @@ -0,0 +1,60 @@ +/* @internal */ +namespace ts.codefix { + const fixId = "enableExperimentalDecorators"; + const errorCodes = [ + Diagnostics.Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Set_the_experimentalDecorators_option_to_remove_this_warning.code + ]; + registerCodeFix({ + errorCodes, + getCodeActions: (context) => { + const { configFile } = context.program.getCompilerOptions(); + if (configFile === undefined) { + return undefined; + } + + const changes = textChanges.ChangeTracker.with(context, changeTracker => makeChange(changeTracker, configFile)); + return [createCodeFixActionNoFixId(fixId, changes, Diagnostics.Enable_the_experimentalDecorators_option_in_your_configuration_file)]; + }, + fixIds: [fixId], + }); + + function makeChange(changeTracker: textChanges.ChangeTracker, configFile: TsConfigSourceFile) { + const tsconfigObjectLiteral = getTsConfigObjectLiteralExpression(configFile); + if (tsconfigObjectLiteral === undefined) { + return; + } + + const compilerOptionsProperty = findJsonProperty(tsconfigObjectLiteral, "compilerOptions"); + if (compilerOptionsProperty === undefined) { + changeTracker.insertNodeAtObjectStart(configFile, tsconfigObjectLiteral, createCompilerOptionsAssignment()); + return; + } + + const compilerOptions = compilerOptionsProperty.initializer; + if (!isObjectLiteralExpression(compilerOptions)) { + return; + } + + const experimentalDecoratorsProperty = findJsonProperty(compilerOptions, "experimentalDecorators"); + + if (experimentalDecoratorsProperty === undefined) { + changeTracker.insertNodeAtObjectStart(configFile, compilerOptions, createExperimentalDecoratorsAssignment()); + } + else { + changeTracker.replaceNodeWithText(configFile, experimentalDecoratorsProperty.initializer, "true"); + } + } + + function createCompilerOptionsAssignment() { + return createJsonPropertyAssignment( + "compilerOptions", + createObjectLiteral([ + createExperimentalDecoratorsAssignment(), + ]), + ); + } + + function createExperimentalDecoratorsAssignment() { + return createJsonPropertyAssignment("experimentalDecorators", createTrue()); + } +} diff --git a/src/services/codefixes/helpers.ts b/src/services/codefixes/helpers.ts index 461771c0b5e..0344f51a854 100644 --- a/src/services/codefixes/helpers.ts +++ b/src/services/codefixes/helpers.ts @@ -1,5 +1,13 @@ /* @internal */ namespace ts.codefix { + export function createJsonPropertyAssignment(name: string, initializer: Expression) { + return createPropertyAssignment(createStringLiteral(name), initializer); + } + + export function findJsonProperty(obj: ObjectLiteralExpression, name: string): PropertyAssignment | undefined { + return find(obj.properties, (p): p is PropertyAssignment => isPropertyAssignment(p) && !!p.name && isStringLiteral(p.name) && p.name.text === name); + } + /** * Finds members of the resolved type that are missing in the class pointed to by class decl * and generates source code for the missing members. diff --git a/src/services/tsconfig.json b/src/services/tsconfig.json index 15044416f84..21be663055a 100644 --- a/src/services/tsconfig.json +++ b/src/services/tsconfig.json @@ -61,6 +61,7 @@ "codefixes/fixClassDoesntImplementInheritedAbstractMember.ts", "codefixes/fixClassSuperMustPrecedeThisAccess.ts", "codefixes/fixConstructorForDerivedNeedSuperCall.ts", + "codefixes/fixEnableExperimentalDecorators.ts", "codefixes/fixExtendsInterfaceBecomesImplements.ts", "codefixes/fixForgottenThisPropertyAccess.ts", "codefixes/fixUnusedIdentifier.ts", diff --git a/tests/cases/fourslash/codefixEnableExperimentalDecorators_blankCompilerOptions.ts b/tests/cases/fourslash/codefixEnableExperimentalDecorators_blankCompilerOptions.ts new file mode 100644 index 00000000000..0e19b42d921 --- /dev/null +++ b/tests/cases/fourslash/codefixEnableExperimentalDecorators_blankCompilerOptions.ts @@ -0,0 +1,26 @@ +/// + +// @Filename: /dir/a.ts +////declare const decorator: any; +////class A { +//// @decorator method() {}; +////}; + +// @Filename: /dir/tsconfig.json +////{ +//// "compilerOptions": { +//// } +////} + +goTo.file("/dir/a.ts"); +verify.codeFix({ + description: "Enable the 'experimentalDecorators' option in your configuration file", + newFileContent: { + "/dir/tsconfig.json": +`{ + "compilerOptions": { + "experimentalDecorators": true, + } +}`, + }, +}); diff --git a/tests/cases/fourslash/codefixEnableExperimentalDecorators_disabledInCompilerOptions.ts b/tests/cases/fourslash/codefixEnableExperimentalDecorators_disabledInCompilerOptions.ts new file mode 100644 index 00000000000..056e7e15a48 --- /dev/null +++ b/tests/cases/fourslash/codefixEnableExperimentalDecorators_disabledInCompilerOptions.ts @@ -0,0 +1,27 @@ +/// + +// @Filename: /dir/a.ts +////declare const decorator: any; +////class A { +//// @decorator method() {}; +////}; + +// @Filename: /dir/tsconfig.json +////{ +//// "compilerOptions": { +//// "experimentalDecorators": false, +//// } +////} + +goTo.file("/dir/a.ts"); +verify.codeFix({ + description: "Enable the 'experimentalDecorators' option in your configuration file", + newFileContent: { + "/dir/tsconfig.json": +`{ + "compilerOptions": { + "experimentalDecorators": true, + } +}`, + }, +}); diff --git a/tests/cases/fourslash/codefixEnableExperimentalDecorators_missingCompilerOptions.ts b/tests/cases/fourslash/codefixEnableExperimentalDecorators_missingCompilerOptions.ts new file mode 100644 index 00000000000..6d7006f3ce1 --- /dev/null +++ b/tests/cases/fourslash/codefixEnableExperimentalDecorators_missingCompilerOptions.ts @@ -0,0 +1,22 @@ +/// + +// @Filename: /dir/a.ts +////declare const decorator: any; +////class A { +//// @decorator method() {}; +////}; + +// @Filename: /dir/tsconfig.json +////{ +////} + +goTo.file("/dir/a.ts"); +verify.codeFix({ + description: "Enable the 'experimentalDecorators' option in your configuration file", + newFileContent: { + "/dir/tsconfig.json": +`{ + "compilerOptions": { "experimentalDecorators": true }, +}`, + }, +}); diff --git a/tests/cases/fourslash/codefixEnableExperimentalDecorators_noTsconfig.ts b/tests/cases/fourslash/codefixEnableExperimentalDecorators_noTsconfig.ts new file mode 100644 index 00000000000..8430fd0734b --- /dev/null +++ b/tests/cases/fourslash/codefixEnableExperimentalDecorators_noTsconfig.ts @@ -0,0 +1,10 @@ +/// + +// @Filename: /dir/a.ts +////declare const decorator: any; +////class A { +//// @decorator method() {}; +////}; + +goTo.file("/dir/a.ts"); +verify.not.codeFixAvailable(); From 7b6adae6dd438e2393d55f8b8a932c82ad67a10a Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Fri, 11 Jan 2019 15:05:24 -0500 Subject: [PATCH 80/96] Extracted compilerOptions setting to helper function --- .../fixEnableExperimentalDecorators.ts | 38 +------------- src/services/codefixes/helpers.ts | 50 ++++++++++++++++--- 2 files changed, 43 insertions(+), 45 deletions(-) diff --git a/src/services/codefixes/fixEnableExperimentalDecorators.ts b/src/services/codefixes/fixEnableExperimentalDecorators.ts index 8179abdfd1d..8aeefe48a47 100644 --- a/src/services/codefixes/fixEnableExperimentalDecorators.ts +++ b/src/services/codefixes/fixEnableExperimentalDecorators.ts @@ -19,42 +19,6 @@ namespace ts.codefix { }); function makeChange(changeTracker: textChanges.ChangeTracker, configFile: TsConfigSourceFile) { - const tsconfigObjectLiteral = getTsConfigObjectLiteralExpression(configFile); - if (tsconfigObjectLiteral === undefined) { - return; - } - - const compilerOptionsProperty = findJsonProperty(tsconfigObjectLiteral, "compilerOptions"); - if (compilerOptionsProperty === undefined) { - changeTracker.insertNodeAtObjectStart(configFile, tsconfigObjectLiteral, createCompilerOptionsAssignment()); - return; - } - - const compilerOptions = compilerOptionsProperty.initializer; - if (!isObjectLiteralExpression(compilerOptions)) { - return; - } - - const experimentalDecoratorsProperty = findJsonProperty(compilerOptions, "experimentalDecorators"); - - if (experimentalDecoratorsProperty === undefined) { - changeTracker.insertNodeAtObjectStart(configFile, compilerOptions, createExperimentalDecoratorsAssignment()); - } - else { - changeTracker.replaceNodeWithText(configFile, experimentalDecoratorsProperty.initializer, "true"); - } - } - - function createCompilerOptionsAssignment() { - return createJsonPropertyAssignment( - "compilerOptions", - createObjectLiteral([ - createExperimentalDecoratorsAssignment(), - ]), - ); - } - - function createExperimentalDecoratorsAssignment() { - return createJsonPropertyAssignment("experimentalDecorators", createTrue()); + setJsonCompilerOptionValue(changeTracker, configFile, "experimentalDecorators", createTrue()); } } diff --git a/src/services/codefixes/helpers.ts b/src/services/codefixes/helpers.ts index 0344f51a854..66488d5d697 100644 --- a/src/services/codefixes/helpers.ts +++ b/src/services/codefixes/helpers.ts @@ -1,13 +1,5 @@ /* @internal */ namespace ts.codefix { - export function createJsonPropertyAssignment(name: string, initializer: Expression) { - return createPropertyAssignment(createStringLiteral(name), initializer); - } - - export function findJsonProperty(obj: ObjectLiteralExpression, name: string): PropertyAssignment | undefined { - return find(obj.properties, (p): p is PropertyAssignment => isPropertyAssignment(p) && !!p.name && isStringLiteral(p.name) && p.name.text === name); - } - /** * Finds members of the resolved type that are missing in the class pointed to by class decl * and generates source code for the missing members. @@ -257,4 +249,46 @@ namespace ts.codefix { } return undefined; } + + export function setJsonCompilerOptionValue( + changeTracker: textChanges.ChangeTracker, + configFile: TsConfigSourceFile, + optionName: string, + optionValue: Expression, + ) { + const tsconfigObjectLiteral = getTsConfigObjectLiteralExpression(configFile); + if (!tsconfigObjectLiteral) return undefined; + + const compilerOptionsProperty = findJsonProperty(tsconfigObjectLiteral, "compilerOptions"); + if (compilerOptionsProperty === undefined) { + changeTracker.insertNodeAtObjectStart(configFile, tsconfigObjectLiteral, createJsonPropertyAssignment( + "compilerOptions", + createObjectLiteral([ + createJsonPropertyAssignment(optionName, optionValue), + ]))); + return; + } + + const compilerOptions = compilerOptionsProperty.initializer; + if (!isObjectLiteralExpression(compilerOptions)) { + return; + } + + const optionProperty = findJsonProperty(compilerOptions, optionName); + + if (optionProperty === undefined) { + changeTracker.insertNodeAtObjectStart(configFile, compilerOptions, createJsonPropertyAssignment(optionName, optionValue)); + } + else { + changeTracker.replaceNode(configFile, optionProperty.initializer, optionValue); + } + } + + export function createJsonPropertyAssignment(name: string, initializer: Expression) { + return createPropertyAssignment(createStringLiteral(name), initializer); + } + + export function findJsonProperty(obj: ObjectLiteralExpression, name: string): PropertyAssignment | undefined { + return find(obj.properties, (p): p is PropertyAssignment => isPropertyAssignment(p) && !!p.name && isStringLiteral(p.name) && p.name.text === name); + } } From a0764178377441c1f4736b43e20b2aafa55504b1 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 11 Jan 2019 22:13:29 +0200 Subject: [PATCH 81/96] remove unused error message 2568 --- src/compiler/diagnosticMessages.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 4abdf2b0bb7..a534e41992e 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2056,10 +2056,6 @@ "category": "Error", "code": 2567 }, - "Type '{0}' is not an array type. Use compiler option '--downlevelIteration' to allow iterating of iterators.": { - "category": "Error", - "code": 2568 - }, "Type '{0}' is not an array type or a string type. Use compiler option '--downlevelIteration' to allow iterating of iterators.": { "category": "Error", "code": 2569 From b23664adf722f45fef4799342392bc43c70ec848 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 11 Jan 2019 10:57:53 -0800 Subject: [PATCH 82/96] Test to verify external source map range addition --- src/testRunner/unittests/customTransforms.ts | 35 ++++++++++++++++++- .../sourceMapExternalSourceFiles.js | 7 ++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/customTransforms/sourceMapExternalSourceFiles.js diff --git a/src/testRunner/unittests/customTransforms.ts b/src/testRunner/unittests/customTransforms.ts index 304c0a55c59..aef9ed745ec 100644 --- a/src/testRunner/unittests/customTransforms.ts +++ b/src/testRunner/unittests/customTransforms.ts @@ -95,6 +95,39 @@ namespace ts { module: ModuleKind.ES2015, emitDecoratorMetadata: true, experimentalDecorators: true - }); + }); + + emitsCorrectly("sourceMapExternalSourceFiles", + [ + { + file: "source.ts", + // The text of length 'changed' is made to be on two lines so we know the line map change + text: `\`multi + line\` +'change'` + }, + ], + { + before: [ + context => node => visitNode(node, function visitor(node: Node): Node { + if (isStringLiteral(node) && node.text === "change") { + const text = "'changed'"; + const lineMap = computeLineStarts(text); + setSourceMapRange(node, { + pos: 0, end: text.length, source: { + text, + fileName: "another.html", + lineMap, + getLineAndCharacterOfPosition: pos => computeLineAndCharacterOfPosition(lineMap, pos) + } + }); + return node; + } + return visitEachChild(node, visitor, context); + }) + ] + }, + { sourceMap: true } + ); }); } diff --git a/tests/baselines/reference/customTransforms/sourceMapExternalSourceFiles.js b/tests/baselines/reference/customTransforms/sourceMapExternalSourceFiles.js new file mode 100644 index 00000000000..69406cfe308 --- /dev/null +++ b/tests/baselines/reference/customTransforms/sourceMapExternalSourceFiles.js @@ -0,0 +1,7 @@ +// [source.js.map] +{"version":3,"file":"source.js","sourceRoot":"","sources":["source.ts","another.html"],"names":[],"mappings":"AAAA,iCACyB,CAAA;ACDzB,QACE,CDCM"} + +// [source.js] +"multi\n line"; +'change'; +//# sourceMappingURL=source.js.map \ No newline at end of file From 021c63f1c365c54b6c061d8e4fd0c5cd9f796fa9 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 11 Jan 2019 12:24:33 -0800 Subject: [PATCH 83/96] Use the SourceMapSource to get line and column instead of current source file Fixes #29300 --- src/compiler/emitter.ts | 2 +- .../reference/customTransforms/sourceMapExternalSourceFiles.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 9c09ed79a77..0afd8ee761c 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4389,7 +4389,7 @@ namespace ts { return; } - const { line: sourceLine, character: sourceCharacter } = getLineAndCharacterOfPosition(currentSourceFile!, pos); + const { line: sourceLine, character: sourceCharacter } = getLineAndCharacterOfPosition(sourceMapSource, pos); sourceMapGenerator!.addMapping( writer.getLine(), writer.getColumn(), diff --git a/tests/baselines/reference/customTransforms/sourceMapExternalSourceFiles.js b/tests/baselines/reference/customTransforms/sourceMapExternalSourceFiles.js index 69406cfe308..7191d615fc6 100644 --- a/tests/baselines/reference/customTransforms/sourceMapExternalSourceFiles.js +++ b/tests/baselines/reference/customTransforms/sourceMapExternalSourceFiles.js @@ -1,5 +1,5 @@ // [source.js.map] -{"version":3,"file":"source.js","sourceRoot":"","sources":["source.ts","another.html"],"names":[],"mappings":"AAAA,iCACyB,CAAA;ACDzB,QACE,CDCM"} +{"version":3,"file":"source.js","sourceRoot":"","sources":["source.ts","another.html"],"names":[],"mappings":"AAAA,iCACyB,CAAA;ACDzB,QAAS,CDED"} // [source.js] "multi\n line"; From fadd95f72b5ad7f7f1cffa2b6ac82f612694462c Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Fri, 11 Jan 2019 14:24:49 -0800 Subject: [PATCH 84/96] Fix unneeded cast lints (#29383) --- src/compiler/builder.ts | 3 ++- src/compiler/parser.ts | 13 +++++++------ src/harness/compiler.ts | 5 +++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/compiler/builder.ts b/src/compiler/builder.ts index 62dd670fbc5..06615b3a97f 100644 --- a/src/compiler/builder.ts +++ b/src/compiler/builder.ts @@ -78,7 +78,8 @@ namespace ts { if (useOldState) { // Verify the sanity of old state if (!oldState!.currentChangedFilePath) { - Debug.assert(!oldState!.affectedFiles && (!oldState!.currentAffectedFilesSignatures || !oldState!.currentAffectedFilesSignatures!.size), "Cannot reuse if only few affected files of currentChangedFile were iterated"); + const affectedSignatures = oldState!.currentAffectedFilesSignatures; + Debug.assert(!oldState!.affectedFiles && (!affectedSignatures || !affectedSignatures.size), "Cannot reuse if only few affected files of currentChangedFile were iterated"); } if (canCopySemanticDiagnostics) { Debug.assert(!forEachKey(oldState!.changedFilesSet, path => oldState!.semanticDiagnosticsPerFile!.has(path)), "Semantic diagnostics shouldnt be available for changed files"); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index f976f77ea98..53e45505014 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -7774,17 +7774,18 @@ namespace ts { const libReferenceDirectives = context.libReferenceDirectives; forEach(toArray(entryOrList), (arg: PragmaPseudoMap["reference"]) => { // TODO: GH#18217 + const { types, lib, path } = arg!.arguments; if (arg!.arguments["no-default-lib"]) { context.hasNoDefaultLib = true; } - else if (arg!.arguments.types) { - typeReferenceDirectives.push({ pos: arg!.arguments.types!.pos, end: arg!.arguments.types!.end, fileName: arg!.arguments.types!.value }); + else if (types) { + typeReferenceDirectives.push({ pos: types.pos, end: types.end, fileName: types.value }); } - else if (arg!.arguments.lib) { - libReferenceDirectives.push({ pos: arg!.arguments.lib!.pos, end: arg!.arguments.lib!.end, fileName: arg!.arguments.lib!.value }); + else if (lib) { + libReferenceDirectives.push({ pos: lib.pos, end: lib.end, fileName: lib.value }); } - else if (arg!.arguments.path) { - referencedFiles.push({ pos: arg!.arguments.path!.pos, end: arg!.arguments.path!.end, fileName: arg!.arguments.path!.value }); + else if (path) { + referencedFiles.push({ pos: path.pos, end: path.end, fileName: path.value }); } else { reportDiagnostic(arg!.range.pos, arg!.range.end - arg!.range.pos, Diagnostics.Invalid_reference_directive_syntax); diff --git a/src/harness/compiler.ts b/src/harness/compiler.ts index 532a2d65578..70bda90ef32 100644 --- a/src/harness/compiler.ts +++ b/src/harness/compiler.ts @@ -183,8 +183,9 @@ namespace compiler { } public getSourceMapRecord(): string | undefined { - if (this.result!.sourceMaps && this.result!.sourceMaps!.length > 0) { - return Harness.SourceMapRecorder.getSourceMapRecord(this.result!.sourceMaps!, this.program!, Array.from(this.js.values()).filter(d => !ts.fileExtensionIs(d.file, ts.Extension.Json)), Array.from(this.dts.values())); + const maps = this.result!.sourceMaps; + if (maps && maps.length > 0) { + return Harness.SourceMapRecorder.getSourceMapRecord(maps, this.program!, Array.from(this.js.values()).filter(d => !ts.fileExtensionIs(d.file, ts.Extension.Json)), Array.from(this.dts.values())); } } From d029fae35ce6a49cf6eba6ea981d1d1299569fe2 Mon Sep 17 00:00:00 2001 From: Benjamin Lichtman Date: Fri, 11 Jan 2019 14:45:08 -0800 Subject: [PATCH 85/96] Add user preference to opt-in to renaming import paths --- src/harness/client.ts | 5 +++-- src/harness/fourslash.ts | 18 ++++++++++-------- src/harness/harnessLanguageService.ts | 4 ++-- src/server/protocol.ts | 1 + src/server/session.ts | 5 +++-- src/services/rename.ts | 8 ++++---- src/services/services.ts | 4 ++-- src/services/shims.ts | 6 +++--- src/services/types.ts | 6 +++++- src/testRunner/unittests/tsserver/rename.ts | 14 ++++++++++++-- .../reference/api/tsserverlibrary.d.ts | 6 +++++- tests/baselines/reference/api/typescript.d.ts | 5 ++++- .../findAllRefs_importType_exportEquals.ts | 1 + tests/cases/fourslash/fourslash.ts | 4 ++-- tests/cases/fourslash/renameImport.ts | 1 + 15 files changed, 58 insertions(+), 30 deletions(-) diff --git a/src/harness/client.ts b/src/harness/client.ts index 27365e3ecf1..937b859853b 100644 --- a/src/harness/client.ts +++ b/src/harness/client.ts @@ -384,7 +384,8 @@ namespace ts.server { return notImplemented(); } - getRenameInfo(fileName: string, position: number, findInStrings?: boolean, findInComments?: boolean): RenameInfo { + getRenameInfo(fileName: string, position: number, _options?: RenameInfoOptions, findInStrings?: boolean, findInComments?: boolean): RenameInfo { + // not using options they should be sent with a RenameInfo request, which this function does not perform const args: protocol.RenameRequestArgs = { ...this.createFileLocationRequestArgs(fileName, position), findInStrings, findInComments }; const request = this.processRequest(CommandNames.Rename, args); @@ -428,7 +429,7 @@ namespace ts.server { this.lastRenameEntry.inputs.position !== position || this.lastRenameEntry.inputs.findInStrings !== findInStrings || this.lastRenameEntry.inputs.findInComments !== findInComments) { - this.getRenameInfo(fileName, position, findInStrings, findInComments); + this.getRenameInfo(fileName, position, { allowRenameOfImportPath: true }, findInStrings, findInComments); } return this.lastRenameEntry!.locations; diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index db1c326a504..fd11236501d 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -1308,8 +1308,9 @@ Actual: ${stringify(fullActual)}`); } } - public verifyRenameInfoSucceeded(displayName: string | undefined, fullDisplayName: string | undefined, kind: string | undefined, kindModifiers: string | undefined, fileToRename: string | undefined, expectedRange: Range | undefined): void { - const renameInfo = this.languageService.getRenameInfo(this.activeFile.fileName, this.currentCaretPosition); + public verifyRenameInfoSucceeded(displayName: string | undefined, fullDisplayName: string | undefined, kind: string | undefined, kindModifiers: string | undefined, fileToRename: string | undefined, expectedRange: Range | undefined, allowRenameOfImportPath: boolean | undefined): void { + allowRenameOfImportPath = allowRenameOfImportPath === undefined ? true : allowRenameOfImportPath; + const renameInfo = this.languageService.getRenameInfo(this.activeFile.fileName, this.currentCaretPosition, { allowRenameOfImportPath }); if (!renameInfo.canRename) { throw this.raiseError("Rename did not succeed"); } @@ -1334,8 +1335,9 @@ Actual: ${stringify(fullActual)}`); } } - public verifyRenameInfoFailed(message?: string) { - const renameInfo = this.languageService.getRenameInfo(this.activeFile.fileName, this.currentCaretPosition); + public verifyRenameInfoFailed(message?: string, allowRenameOfImportPath?: boolean) { + allowRenameOfImportPath = allowRenameOfImportPath === undefined ? true : allowRenameOfImportPath; + const renameInfo = this.languageService.getRenameInfo(this.activeFile.fileName, this.currentCaretPosition, { allowRenameOfImportPath }); if (renameInfo.canRename) { throw this.raiseError("Rename was expected to fail"); } @@ -4091,12 +4093,12 @@ namespace FourSlashInterface { this.state.verifySemanticClassifications(classifications); } - public renameInfoSucceeded(displayName?: string, fullDisplayName?: string, kind?: string, kindModifiers?: string, fileToRename?: string, expectedRange?: FourSlash.Range) { - this.state.verifyRenameInfoSucceeded(displayName, fullDisplayName, kind, kindModifiers, fileToRename, expectedRange); + public renameInfoSucceeded(displayName?: string, fullDisplayName?: string, kind?: string, kindModifiers?: string, fileToRename?: string, expectedRange?: FourSlash.Range, allowRenameOfImportPath?: boolean) { + this.state.verifyRenameInfoSucceeded(displayName, fullDisplayName, kind, kindModifiers, fileToRename, expectedRange, allowRenameOfImportPath); } - public renameInfoFailed(message?: string) { - this.state.verifyRenameInfoFailed(message); + public renameInfoFailed(message?: string, allowRenameOfImportPath?: boolean) { + this.state.verifyRenameInfoFailed(message, allowRenameOfImportPath); } public renameLocations(startRanges: ArrayOrSingle, options: RenameLocationsOptions) { diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index 581d5cc045d..d233ddf4585 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -469,8 +469,8 @@ namespace Harness.LanguageService { getSignatureHelpItems(fileName: string, position: number, options: ts.SignatureHelpItemsOptions | undefined): ts.SignatureHelpItems { return unwrapJSONCallResult(this.shim.getSignatureHelpItems(fileName, position, options)); } - getRenameInfo(fileName: string, position: number): ts.RenameInfo { - return unwrapJSONCallResult(this.shim.getRenameInfo(fileName, position)); + getRenameInfo(fileName: string, position: number, options?: ts.RenameInfoOptions): ts.RenameInfo { + return unwrapJSONCallResult(this.shim.getRenameInfo(fileName, position, options)); } findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): ts.RenameLocation[] { return unwrapJSONCallResult(this.shim.findRenameLocations(fileName, position, findInStrings, findInComments)); diff --git a/src/server/protocol.ts b/src/server/protocol.ts index 193621da82a..8b9df926d82 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -2905,6 +2905,7 @@ namespace ts.server.protocol { readonly importModuleSpecifierPreference?: "relative" | "non-relative"; readonly allowTextChangesInNewFiles?: boolean; readonly lazyConfiguredProjectsFromExternalProject?: boolean; + readonly allowRenameOfImportPath?: boolean; } export interface CompilerOptions { diff --git a/src/server/session.ts b/src/server/session.ts index d534f445ee3..8c300b121e1 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -1177,7 +1177,8 @@ namespace ts.server { private getRenameInfo(args: protocol.FileLocationRequestArgs): RenameInfo { const { file, project } = this.getFileAndProject(args); const position = this.getPositionInFile(args, file); - return project.getLanguageService().getRenameInfo(file, position); + const preferences = this.getHostPreferences(); + return project.getLanguageService().getRenameInfo(file, position, { allowRenameOfImportPath: preferences.allowRenameOfImportPath }); } private getProjects(args: protocol.FileRequestArgs, getScriptInfoEnsuringProjectsUptoDate?: boolean, ignoreNoProjectError?: boolean): Projects { @@ -1236,7 +1237,7 @@ namespace ts.server { if (!simplifiedResult) return locations; const defaultProject = this.getDefaultProject(args); - const renameInfo: protocol.RenameInfo = this.mapRenameInfo(defaultProject.getLanguageService().getRenameInfo(file, position), Debug.assertDefined(this.projectService.getScriptInfo(file))); + const renameInfo: protocol.RenameInfo = this.mapRenameInfo(defaultProject.getLanguageService().getRenameInfo(file, position, { allowRenameOfImportPath: this.getHostPreferences().allowRenameOfImportPath }), Debug.assertDefined(this.projectService.getScriptInfo(file))); return { info: renameInfo, locs: this.toSpanGroups(locations) }; } diff --git a/src/services/rename.ts b/src/services/rename.ts index a51d79797bf..cef53d251ed 100644 --- a/src/services/rename.ts +++ b/src/services/rename.ts @@ -1,14 +1,14 @@ /* @internal */ namespace ts.Rename { - export function getRenameInfo(program: Program, sourceFile: SourceFile, position: number): RenameInfo { + export function getRenameInfo(program: Program, sourceFile: SourceFile, position: number, options?: RenameInfoOptions): RenameInfo { const node = getTouchingPropertyName(sourceFile, position); const renameInfo = node && nodeIsEligibleForRename(node) - ? getRenameInfoForNode(node, program.getTypeChecker(), sourceFile, declaration => program.isSourceFileDefaultLibrary(declaration.getSourceFile())) + ? getRenameInfoForNode(node, program.getTypeChecker(), sourceFile, options || {}, declaration => program.isSourceFileDefaultLibrary(declaration.getSourceFile())) : undefined; return renameInfo || getRenameInfoError(Diagnostics.You_cannot_rename_this_element); } - function getRenameInfoForNode(node: Node, typeChecker: TypeChecker, sourceFile: SourceFile, isDefinedInLibraryFile: (declaration: Node) => boolean): RenameInfo | undefined { + function getRenameInfoForNode(node: Node, typeChecker: TypeChecker, sourceFile: SourceFile, options: RenameInfoOptions, isDefinedInLibraryFile: (declaration: Node) => boolean): RenameInfo | undefined { const symbol = typeChecker.getSymbolAtLocation(node); if (!symbol) return; // Only allow a symbol to be renamed if it actually has at least one declaration. @@ -26,7 +26,7 @@ namespace ts.Rename { } if (isStringLiteralLike(node) && tryGetImportFromModuleSpecifier(node)) { - return getRenameInfoForModule(node, sourceFile, symbol); + return options.allowRenameOfImportPath ? getRenameInfoForModule(node, sourceFile, symbol) : undefined; } const kind = SymbolDisplay.getSymbolKind(typeChecker, symbol, node); diff --git a/src/services/services.ts b/src/services/services.ts index 15f9709cb38..6bf6566da36 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2062,9 +2062,9 @@ namespace ts { } } - function getRenameInfo(fileName: string, position: number): RenameInfo { + function getRenameInfo(fileName: string, position: number, options?: RenameInfoOptions): RenameInfo { synchronizeHostData(); - return Rename.getRenameInfo(program, getValidSourceFile(fileName), position); + return Rename.getRenameInfo(program, getValidSourceFile(fileName), position, options); } function getRefactorContext(file: SourceFile, positionOrRange: number | TextRange, preferences: UserPreferences, formatOptions?: FormatCodeSettings): RefactorContext { diff --git a/src/services/shims.ts b/src/services/shims.ts index ff66680bdbc..33ea4333e6f 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -164,7 +164,7 @@ namespace ts { * Returns a JSON-encoded value of the type: * { canRename: boolean, localizedErrorMessage: string, displayName: string, fullDisplayName: string, kind: string, kindModifiers: string, triggerSpan: { start; length } } */ - getRenameInfo(fileName: string, position: number): string; + getRenameInfo(fileName: string, position: number, options?: RenameInfoOptions): string; /** * Returns a JSON-encoded value of the type: @@ -831,10 +831,10 @@ namespace ts { ); } - public getRenameInfo(fileName: string, position: number): string { + public getRenameInfo(fileName: string, position: number, options?: RenameInfoOptions): string { return this.forwardJSONCall( `getRenameInfo('${fileName}', ${position})`, - () => this.languageService.getRenameInfo(fileName, position) + () => this.languageService.getRenameInfo(fileName, position, options) ); } diff --git a/src/services/types.ts b/src/services/types.ts index 5100a999306..b45a816d6e0 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -294,7 +294,7 @@ namespace ts { getSignatureHelpItems(fileName: string, position: number, options: SignatureHelpItemsOptions | undefined): SignatureHelpItems | undefined; - getRenameInfo(fileName: string, position: number): RenameInfo; + getRenameInfo(fileName: string, position: number, options?: RenameInfoOptions): RenameInfo; findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): ReadonlyArray | undefined; getDefinitionAtPosition(fileName: string, position: number): ReadonlyArray | undefined; @@ -848,6 +848,10 @@ namespace ts { localizedErrorMessage: string; } + export interface RenameInfoOptions { + readonly allowRenameOfImportPath?: boolean; + } + export interface SignatureHelpParameter { name: string; documentation: SymbolDisplayPart[]; diff --git a/src/testRunner/unittests/tsserver/rename.ts b/src/testRunner/unittests/tsserver/rename.ts index 75c08bb8bb0..4e95e79e31f 100644 --- a/src/testRunner/unittests/tsserver/rename.ts +++ b/src/testRunner/unittests/tsserver/rename.ts @@ -7,8 +7,18 @@ namespace ts.projectSystem { const session = createSession(createServerHost([aTs, bTs])); openFilesForSession([bTs], session); - const response = executeSessionRequest(session, protocol.CommandTypes.Rename, protocolFileLocationFromSubstring(bTs, 'a";')); - assert.deepEqual(response, { + const response1 = executeSessionRequest(session, protocol.CommandTypes.Rename, protocolFileLocationFromSubstring(bTs, 'a";')); + assert.deepEqual(response1, { + info: { + canRename: false, + localizedErrorMessage: "You cannot rename this element." + }, + locs: [{ file: bTs.path, locs: [protocolRenameSpanFromSubstring(bTs.content, "./a")] }], + }); + + session.getProjectService().setHostConfiguration({ preferences: { allowRenameOfImportPath: true } }); + const response2 = executeSessionRequest(session, protocol.CommandTypes.Rename, protocolFileLocationFromSubstring(bTs, 'a";')); + assert.deepEqual(response2, { info: { canRename: true, fileToRename: aTs.path, diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 91f492ddd1d..30effc9e91a 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -4706,7 +4706,7 @@ declare namespace ts { getNameOrDottedNameSpan(fileName: string, startPos: number, endPos: number): TextSpan | undefined; getBreakpointStatementAtPosition(fileName: string, position: number): TextSpan | undefined; getSignatureHelpItems(fileName: string, position: number, options: SignatureHelpItemsOptions | undefined): SignatureHelpItems | undefined; - getRenameInfo(fileName: string, position: number): RenameInfo; + getRenameInfo(fileName: string, position: number, options?: RenameInfoOptions): RenameInfo; findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): ReadonlyArray | undefined; getDefinitionAtPosition(fileName: string, position: number): ReadonlyArray | undefined; getDefinitionAndBoundSpan(fileName: string, position: number): DefinitionInfoAndBoundSpan | undefined; @@ -5150,6 +5150,9 @@ declare namespace ts { canRename: false; localizedErrorMessage: string; } + interface RenameInfoOptions { + readonly allowRenameOfImportPath?: boolean; + } interface SignatureHelpParameter { name: string; documentation: SymbolDisplayPart[]; @@ -7923,6 +7926,7 @@ declare namespace ts.server.protocol { readonly importModuleSpecifierPreference?: "relative" | "non-relative"; readonly allowTextChangesInNewFiles?: boolean; readonly lazyConfiguredProjectsFromExternalProject?: boolean; + readonly allowRenameOfImportPath?: boolean; } interface CompilerOptions { allowJs?: boolean; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 0e693f698f2..cd6d45a1647 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -4706,7 +4706,7 @@ declare namespace ts { getNameOrDottedNameSpan(fileName: string, startPos: number, endPos: number): TextSpan | undefined; getBreakpointStatementAtPosition(fileName: string, position: number): TextSpan | undefined; getSignatureHelpItems(fileName: string, position: number, options: SignatureHelpItemsOptions | undefined): SignatureHelpItems | undefined; - getRenameInfo(fileName: string, position: number): RenameInfo; + getRenameInfo(fileName: string, position: number, options?: RenameInfoOptions): RenameInfo; findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): ReadonlyArray | undefined; getDefinitionAtPosition(fileName: string, position: number): ReadonlyArray | undefined; getDefinitionAndBoundSpan(fileName: string, position: number): DefinitionInfoAndBoundSpan | undefined; @@ -5150,6 +5150,9 @@ declare namespace ts { canRename: false; localizedErrorMessage: string; } + interface RenameInfoOptions { + readonly allowRenameOfImportPath?: boolean; + } interface SignatureHelpParameter { name: string; documentation: SymbolDisplayPart[]; diff --git a/tests/cases/fourslash/findAllRefs_importType_exportEquals.ts b/tests/cases/fourslash/findAllRefs_importType_exportEquals.ts index 496fa8a9d3b..3734b7a2e88 100644 --- a/tests/cases/fourslash/findAllRefs_importType_exportEquals.ts +++ b/tests/cases/fourslash/findAllRefs_importType_exportEquals.ts @@ -27,4 +27,5 @@ verify.renameLocations(r2, [r0, r1, r2]); for (const range of [r3b, r4b]) { goTo.rangeStart(range); verify.renameInfoSucceeded(/*displayName*/ "/a.ts", /*fullDisplayName*/ "/a.ts", /*kind*/ "module", /*kindModifiers*/ "", /*fileToRename*/ "/a.ts", range); + verify.renameInfoFailed("You cannot rename this element.", /*allowRenameOfImportPath*/ false); } diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 293c8d21574..ed71f8893b8 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -282,8 +282,8 @@ declare namespace FourSlashInterface { text: string; textSpan?: TextSpan; }[]): void; - renameInfoSucceeded(displayName?: string, fullDisplayName?: string, kind?: string, kindModifiers?: string, fileToRename?: string, range?: Range): void; - renameInfoFailed(message?: string): void; + renameInfoSucceeded(displayName?: string, fullDisplayName?: string, kind?: string, kindModifiers?: string, fileToRename?: string, range?: Range, allowRenameOfImportPath?: boolean): void; + renameInfoFailed(message?: string, allowRenameOfImportPath?: boolean): void; renameLocations(startRanges: ArrayOrSingle, options: RenameLocationsOptions): void; /** Verify the quick info available at the current marker. */ diff --git a/tests/cases/fourslash/renameImport.ts b/tests/cases/fourslash/renameImport.ts index 6fdef347205..8292da4013d 100644 --- a/tests/cases/fourslash/renameImport.ts +++ b/tests/cases/fourslash/renameImport.ts @@ -27,6 +27,7 @@ goTo.eachRange(range => { const name = target === "dir" ? "/dir" : target === "dir/index" ? "/dir/index.ts" : "/a.ts"; const kind = target === "dir" ? "directory" : "module"; verify.renameInfoSucceeded(/*displayName*/ name, /*fullDisplayName*/ name, /*kind*/ kind, /*kindModifiers*/ "", /*fileToRename*/ name, range); + verify.renameInfoFailed("You cannot rename this element.", /*allowRenameOfImportPath*/ false); }); goTo.marker("global"); From c88016d397b1fef00b6f4f39f0be1510e3d358ef Mon Sep 17 00:00:00 2001 From: Benjamin Lichtman Date: Fri, 11 Jan 2019 14:52:47 -0800 Subject: [PATCH 86/96] Fix comment --- src/harness/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/harness/client.ts b/src/harness/client.ts index 937b859853b..1c7c0adb834 100644 --- a/src/harness/client.ts +++ b/src/harness/client.ts @@ -385,7 +385,7 @@ namespace ts.server { } getRenameInfo(fileName: string, position: number, _options?: RenameInfoOptions, findInStrings?: boolean, findInComments?: boolean): RenameInfo { - // not using options they should be sent with a RenameInfo request, which this function does not perform + // Not passing along 'options' because server should already have those from the 'configure' command const args: protocol.RenameRequestArgs = { ...this.createFileLocationRequestArgs(fileName, position), findInStrings, findInComments }; const request = this.processRequest(CommandNames.Rename, args); From dc0f4afe5e449bbc2eea7012c0260da080620d4e Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Mon, 14 Jan 2019 13:53:04 -0800 Subject: [PATCH 87/96] Save & recalculate declare flag modifier on late printed statements (#29412) * Save & recalculate declre flag modifier on late printed statements * Accept related baseline updates --- src/compiler/transformers/declarations.ts | 3 + ...arationEmitLocalClassHasRequiredDeclare.js | 54 +++ ...onEmitLocalClassHasRequiredDeclare.symbols | 27 ++ ...tionEmitLocalClassHasRequiredDeclare.types | 23 ++ .../getEmitOutputWithEmitterErrors2.baseline | 2 +- .../moduleAugmentationImportsAndExports2.js | 2 +- .../moduleAugmentationImportsAndExports3.js | 2 +- .../moduleAugmentationImportsAndExports5.js | 45 +-- .../reference/privacyAccessorDeclFile.js | 273 +-------------- .../privacyFunctionParameterDeclFile.js | 293 +--------------- .../privacyFunctionReturnTypeDeclFile.js | 331 +----------------- ...yLocalInternalReferenceImportWithExport.js | 85 +---- ...calInternalReferenceImportWithoutExport.js | 81 +---- .../privacyTypeParameterOfFunctionDeclFile.js | 159 +-------- .../privacyTypeParametersOfClassDeclFile.js | 64 +--- ...rivacyTypeParametersOfInterfaceDeclFile.js | 109 +----- .../baselines/reference/privacyVarDeclFile.js | 213 +---------- ...arationEmitLocalClassHasRequiredDeclare.ts | 16 + 18 files changed, 137 insertions(+), 1645 deletions(-) create mode 100644 tests/baselines/reference/declarationEmitLocalClassHasRequiredDeclare.js create mode 100644 tests/baselines/reference/declarationEmitLocalClassHasRequiredDeclare.symbols create mode 100644 tests/baselines/reference/declarationEmitLocalClassHasRequiredDeclare.types create mode 100644 tests/cases/compiler/declarationEmitLocalClassHasRequiredDeclare.ts diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index b54cf5bb858..d03c3b8d30b 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -634,7 +634,10 @@ namespace ts { if (!isLateVisibilityPaintedStatement(i)) { return Debug.fail(`Late replaced statement was found which is not handled by the declaration transformer!: ${(ts as any).SyntaxKind ? (ts as any).SyntaxKind[(i as any).kind] : (i as any).kind}`); } + const priorNeedsDeclare = needsDeclare; + needsDeclare = i.parent && isSourceFile(i.parent) && !(isExternalModule(i.parent) && isBundledEmit); const result = transformTopLevelDeclaration(i, /*privateDeclaration*/ true); + needsDeclare = priorNeedsDeclare; lateStatementReplacementMap.set("" + getOriginalNodeId(i), result); } diff --git a/tests/baselines/reference/declarationEmitLocalClassHasRequiredDeclare.js b/tests/baselines/reference/declarationEmitLocalClassHasRequiredDeclare.js new file mode 100644 index 00000000000..4845bc413c4 --- /dev/null +++ b/tests/baselines/reference/declarationEmitLocalClassHasRequiredDeclare.js @@ -0,0 +1,54 @@ +//// [declarationEmitLocalClassHasRequiredDeclare.ts] +export declare namespace A { + namespace X { } +} + +class X { } + +export class A { + static X = X; +} + +export declare namespace Y { + +} + +export class Y { } + +//// [declarationEmitLocalClassHasRequiredDeclare.js] +"use strict"; +exports.__esModule = true; +var X = /** @class */ (function () { + function X() { + } + return X; +}()); +var A = /** @class */ (function () { + function A() { + } + A.X = X; + return A; +}()); +exports.A = A; +var Y = /** @class */ (function () { + function Y() { + } + return Y; +}()); +exports.Y = Y; + + +//// [declarationEmitLocalClassHasRequiredDeclare.d.ts] +export declare namespace A { + namespace X { } +} +declare class X { +} +export declare class A { + static X: typeof X; +} +export declare namespace Y { +} +export declare class Y { +} +export {}; diff --git a/tests/baselines/reference/declarationEmitLocalClassHasRequiredDeclare.symbols b/tests/baselines/reference/declarationEmitLocalClassHasRequiredDeclare.symbols new file mode 100644 index 00000000000..27cb72b00e0 --- /dev/null +++ b/tests/baselines/reference/declarationEmitLocalClassHasRequiredDeclare.symbols @@ -0,0 +1,27 @@ +=== tests/cases/compiler/declarationEmitLocalClassHasRequiredDeclare.ts === +export declare namespace A { +>A : Symbol(A, Decl(declarationEmitLocalClassHasRequiredDeclare.ts, 0, 0), Decl(declarationEmitLocalClassHasRequiredDeclare.ts, 4, 11)) + + namespace X { } +>X : Symbol(X, Decl(declarationEmitLocalClassHasRequiredDeclare.ts, 0, 28), Decl(declarationEmitLocalClassHasRequiredDeclare.ts, 6, 16)) +} + +class X { } +>X : Symbol(X, Decl(declarationEmitLocalClassHasRequiredDeclare.ts, 2, 1)) + +export class A { +>A : Symbol(A, Decl(declarationEmitLocalClassHasRequiredDeclare.ts, 0, 0), Decl(declarationEmitLocalClassHasRequiredDeclare.ts, 4, 11)) + + static X = X; +>X : Symbol(A.X, Decl(declarationEmitLocalClassHasRequiredDeclare.ts, 0, 28), Decl(declarationEmitLocalClassHasRequiredDeclare.ts, 6, 16)) +>X : Symbol(X, Decl(declarationEmitLocalClassHasRequiredDeclare.ts, 2, 1)) +} + +export declare namespace Y { +>Y : Symbol(Y, Decl(declarationEmitLocalClassHasRequiredDeclare.ts, 8, 1), Decl(declarationEmitLocalClassHasRequiredDeclare.ts, 12, 1)) + +} + +export class Y { } +>Y : Symbol(Y, Decl(declarationEmitLocalClassHasRequiredDeclare.ts, 8, 1), Decl(declarationEmitLocalClassHasRequiredDeclare.ts, 12, 1)) + diff --git a/tests/baselines/reference/declarationEmitLocalClassHasRequiredDeclare.types b/tests/baselines/reference/declarationEmitLocalClassHasRequiredDeclare.types new file mode 100644 index 00000000000..130f87cd013 --- /dev/null +++ b/tests/baselines/reference/declarationEmitLocalClassHasRequiredDeclare.types @@ -0,0 +1,23 @@ +=== tests/cases/compiler/declarationEmitLocalClassHasRequiredDeclare.ts === +export declare namespace A { + namespace X { } +} + +class X { } +>X : X + +export class A { +>A : A + + static X = X; +>X : typeof X +>X : typeof X +} + +export declare namespace Y { + +} + +export class Y { } +>Y : Y + diff --git a/tests/baselines/reference/getEmitOutputWithEmitterErrors2.baseline b/tests/baselines/reference/getEmitOutputWithEmitterErrors2.baseline index 46ba9652cc7..7ca62fca61e 100644 --- a/tests/baselines/reference/getEmitOutputWithEmitterErrors2.baseline +++ b/tests/baselines/reference/getEmitOutputWithEmitterErrors2.baseline @@ -16,7 +16,7 @@ define(["require", "exports"], function (require, exports) { }); FileName : /tests/cases/fourslash/inputFile.d.ts -class C { +declare class C { } export declare module M { var foo: C; diff --git a/tests/baselines/reference/moduleAugmentationImportsAndExports2.js b/tests/baselines/reference/moduleAugmentationImportsAndExports2.js index fcb68f78c15..9c07fcbd933 100644 --- a/tests/baselines/reference/moduleAugmentationImportsAndExports2.js +++ b/tests/baselines/reference/moduleAugmentationImportsAndExports2.js @@ -77,7 +77,7 @@ export declare class B { n: number; } //// [f3.d.ts] -namespace N { +declare namespace N { interface Ifc { a: any; } diff --git a/tests/baselines/reference/moduleAugmentationImportsAndExports3.js b/tests/baselines/reference/moduleAugmentationImportsAndExports3.js index abfccd0d424..8229de12e5f 100644 --- a/tests/baselines/reference/moduleAugmentationImportsAndExports3.js +++ b/tests/baselines/reference/moduleAugmentationImportsAndExports3.js @@ -75,7 +75,7 @@ export declare class B { n: number; } //// [f3.d.ts] -namespace N { +declare namespace N { interface Ifc { a: any; } diff --git a/tests/baselines/reference/moduleAugmentationImportsAndExports5.js b/tests/baselines/reference/moduleAugmentationImportsAndExports5.js index a1e63f7463c..aa6111a807e 100644 --- a/tests/baselines/reference/moduleAugmentationImportsAndExports5.js +++ b/tests/baselines/reference/moduleAugmentationImportsAndExports5.js @@ -80,7 +80,7 @@ export declare class B { } //// [f3.d.ts] import { B } from "./f2"; -namespace N { +declare namespace N { interface Ifc { a: number; } @@ -100,46 +100,3 @@ declare module "./f1" { export {}; //// [f4.d.ts] import "./f3"; - - -//// [DtsFileErrors] - - -tests/cases/compiler/f3.d.ts(2,1): error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. - - -==== tests/cases/compiler/f1.d.ts (0 errors) ==== - export declare class A { - } - -==== tests/cases/compiler/f2.d.ts (0 errors) ==== - export declare class B { - n: number; - } - -==== tests/cases/compiler/f3.d.ts (1 errors) ==== - import { B } from "./f2"; - namespace N { - ~~~~~~~~~ -!!! error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. - interface Ifc { - a: number; - } - interface Cls { - b: number; - } - } - import I = N.Ifc; - import C = N.Cls; - declare module "./f1" { - interface A { - foo(): B; - bar(): I; - baz(): C; - } - } - export {}; - -==== tests/cases/compiler/f4.d.ts (0 errors) ==== - import "./f3"; - \ No newline at end of file diff --git a/tests/baselines/reference/privacyAccessorDeclFile.js b/tests/baselines/reference/privacyAccessorDeclFile.js index 0edef02a54d..8a3a7b2d2de 100644 --- a/tests/baselines/reference/privacyAccessorDeclFile.js +++ b/tests/baselines/reference/privacyAccessorDeclFile.js @@ -3557,7 +3557,7 @@ var publicModuleInGlobal; //// [privacyAccessorDeclFile_externalModule.d.ts] -class privateClass { +declare class privateClass { } export declare class publicClass { } @@ -3815,274 +3815,3 @@ declare module publicModuleInGlobal { myPublicMethod: privateModule.publicClass; } } - - -//// [DtsFileErrors] - - -tests/cases/compiler/privacyAccessorDeclFile_externalModule.d.ts(1,1): error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. - - -==== tests/cases/compiler/privacyAccessorDeclFile_externalModule.d.ts (1 errors) ==== - class privateClass { - ~~~~~ -!!! error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. - } - export declare class publicClass { - } - export declare class publicClassWithWithPrivateGetAccessorTypes { - static readonly myPublicStaticMethod: privateClass; - private static readonly myPrivateStaticMethod; - readonly myPublicMethod: privateClass; - private readonly myPrivateMethod; - static readonly myPublicStaticMethod1: privateClass; - private static readonly myPrivateStaticMethod1; - readonly myPublicMethod1: privateClass; - private readonly myPrivateMethod1; - } - export declare class publicClassWithWithPublicGetAccessorTypes { - static readonly myPublicStaticMethod: publicClass; - private static readonly myPrivateStaticMethod; - readonly myPublicMethod: publicClass; - private readonly myPrivateMethod; - static readonly myPublicStaticMethod1: publicClass; - private static readonly myPrivateStaticMethod1; - readonly myPublicMethod1: publicClass; - private readonly myPrivateMethod1; - } - export declare class publicClassWithWithPrivateSetAccessorTypes { - static myPublicStaticMethod: privateClass; - private static myPrivateStaticMethod; - myPublicMethod: privateClass; - private myPrivateMethod; - } - export declare class publicClassWithWithPublicSetAccessorTypes { - static myPublicStaticMethod: publicClass; - private static myPrivateStaticMethod; - myPublicMethod: publicClass; - private myPrivateMethod; - } - export declare class publicClassWithPrivateModuleGetAccessorTypes { - static readonly myPublicStaticMethod: privateModule.publicClass; - readonly myPublicMethod: privateModule.publicClass; - static readonly myPublicStaticMethod1: privateModule.publicClass; - readonly myPublicMethod1: privateModule.publicClass; - } - export declare class publicClassWithPrivateModuleSetAccessorTypes { - static myPublicStaticMethod: privateModule.publicClass; - myPublicMethod: privateModule.publicClass; - } - export declare module publicModule { - class privateClass { - } - class publicClass { - } - class publicClassWithWithPrivateGetAccessorTypes { - static readonly myPublicStaticMethod: privateClass; - private static readonly myPrivateStaticMethod; - readonly myPublicMethod: privateClass; - private readonly myPrivateMethod; - static readonly myPublicStaticMethod1: privateClass; - private static readonly myPrivateStaticMethod1; - readonly myPublicMethod1: privateClass; - private readonly myPrivateMethod1; - } - class publicClassWithWithPublicGetAccessorTypes { - static readonly myPublicStaticMethod: publicClass; - private static readonly myPrivateStaticMethod; - readonly myPublicMethod: publicClass; - private readonly myPrivateMethod; - static readonly myPublicStaticMethod1: publicClass; - private static readonly myPrivateStaticMethod1; - readonly myPublicMethod1: publicClass; - private readonly myPrivateMethod1; - } - class publicClassWithWithPrivateSetAccessorTypes { - static myPublicStaticMethod: privateClass; - private static myPrivateStaticMethod; - myPublicMethod: privateClass; - private myPrivateMethod; - } - class publicClassWithWithPublicSetAccessorTypes { - static myPublicStaticMethod: publicClass; - private static myPrivateStaticMethod; - myPublicMethod: publicClass; - private myPrivateMethod; - } - class publicClassWithPrivateModuleGetAccessorTypes { - static readonly myPublicStaticMethod: privateModule.publicClass; - readonly myPublicMethod: privateModule.publicClass; - static readonly myPublicStaticMethod1: privateModule.publicClass; - readonly myPublicMethod1: privateModule.publicClass; - } - class publicClassWithPrivateModuleSetAccessorTypes { - static myPublicStaticMethod: privateModule.publicClass; - myPublicMethod: privateModule.publicClass; - } - } - declare module privateModule { - class privateClass { - } - class publicClass { - } - class publicClassWithWithPrivateGetAccessorTypes { - static readonly myPublicStaticMethod: privateClass; - private static readonly myPrivateStaticMethod; - readonly myPublicMethod: privateClass; - private readonly myPrivateMethod; - static readonly myPublicStaticMethod1: privateClass; - private static readonly myPrivateStaticMethod1; - readonly myPublicMethod1: privateClass; - private readonly myPrivateMethod1; - } - class publicClassWithWithPublicGetAccessorTypes { - static readonly myPublicStaticMethod: publicClass; - private static readonly myPrivateStaticMethod; - readonly myPublicMethod: publicClass; - private readonly myPrivateMethod; - static readonly myPublicStaticMethod1: publicClass; - private static readonly myPrivateStaticMethod1; - readonly myPublicMethod1: publicClass; - private readonly myPrivateMethod1; - } - class publicClassWithWithPrivateSetAccessorTypes { - static myPublicStaticMethod: privateClass; - private static myPrivateStaticMethod; - myPublicMethod: privateClass; - private myPrivateMethod; - } - class publicClassWithWithPublicSetAccessorTypes { - static myPublicStaticMethod: publicClass; - private static myPrivateStaticMethod; - myPublicMethod: publicClass; - private myPrivateMethod; - } - class publicClassWithPrivateModuleGetAccessorTypes { - static readonly myPublicStaticMethod: privateModule.publicClass; - readonly myPublicMethod: privateModule.publicClass; - static readonly myPublicStaticMethod1: publicClass; - readonly myPublicMethod1: publicClass; - } - class publicClassWithPrivateModuleSetAccessorTypes { - static myPublicStaticMethod: privateModule.publicClass; - myPublicMethod: privateModule.publicClass; - } - } - export {}; - -==== tests/cases/compiler/privacyAccessorDeclFile_GlobalFile.d.ts (0 errors) ==== - declare class publicClassInGlobal { - } - declare class publicClassInGlobalWithPublicGetAccessorTypes { - static readonly myPublicStaticMethod: publicClassInGlobal; - private static readonly myPrivateStaticMethod; - readonly myPublicMethod: publicClassInGlobal; - private readonly myPrivateMethod; - static readonly myPublicStaticMethod1: publicClassInGlobal; - private static readonly myPrivateStaticMethod1; - readonly myPublicMethod1: publicClassInGlobal; - private readonly myPrivateMethod1; - } - declare class publicClassInGlobalWithWithPublicSetAccessorTypes { - static myPublicStaticMethod: publicClassInGlobal; - private static myPrivateStaticMethod; - myPublicMethod: publicClassInGlobal; - private myPrivateMethod; - } - declare module publicModuleInGlobal { - class privateClass { - } - class publicClass { - } - module privateModule { - class privateClass { - } - class publicClass { - } - class publicClassWithWithPrivateGetAccessorTypes { - static readonly myPublicStaticMethod: privateClass; - private static readonly myPrivateStaticMethod; - readonly myPublicMethod: privateClass; - private readonly myPrivateMethod; - static readonly myPublicStaticMethod1: privateClass; - private static readonly myPrivateStaticMethod1; - readonly myPublicMethod1: privateClass; - private readonly myPrivateMethod1; - } - class publicClassWithWithPublicGetAccessorTypes { - static readonly myPublicStaticMethod: publicClass; - private static readonly myPrivateStaticMethod; - readonly myPublicMethod: publicClass; - private readonly myPrivateMethod; - static readonly myPublicStaticMethod1: publicClass; - private static readonly myPrivateStaticMethod1; - readonly myPublicMethod1: publicClass; - private readonly myPrivateMethod1; - } - class publicClassWithWithPrivateSetAccessorTypes { - static myPublicStaticMethod: privateClass; - private static myPrivateStaticMethod; - myPublicMethod: privateClass; - private myPrivateMethod; - } - class publicClassWithWithPublicSetAccessorTypes { - static myPublicStaticMethod: publicClass; - private static myPrivateStaticMethod; - myPublicMethod: publicClass; - private myPrivateMethod; - } - class publicClassWithPrivateModuleGetAccessorTypes { - static readonly myPublicStaticMethod: privateModule.publicClass; - readonly myPublicMethod: privateModule.publicClass; - static readonly myPublicStaticMethod1: publicClass; - readonly myPublicMethod1: publicClass; - } - class publicClassWithPrivateModuleSetAccessorTypes { - static myPublicStaticMethod: privateModule.publicClass; - myPublicMethod: privateModule.publicClass; - } - } - class publicClassWithWithPrivateGetAccessorTypes { - static readonly myPublicStaticMethod: privateClass; - private static readonly myPrivateStaticMethod; - readonly myPublicMethod: privateClass; - private readonly myPrivateMethod; - static readonly myPublicStaticMethod1: privateClass; - private static readonly myPrivateStaticMethod1; - readonly myPublicMethod1: privateClass; - private readonly myPrivateMethod1; - } - class publicClassWithWithPublicGetAccessorTypes { - static readonly myPublicStaticMethod: publicClass; - private static readonly myPrivateStaticMethod; - readonly myPublicMethod: publicClass; - private readonly myPrivateMethod; - static readonly myPublicStaticMethod1: publicClass; - private static readonly myPrivateStaticMethod1; - readonly myPublicMethod1: publicClass; - private readonly myPrivateMethod1; - } - class publicClassWithWithPrivateSetAccessorTypes { - static myPublicStaticMethod: privateClass; - private static myPrivateStaticMethod; - myPublicMethod: privateClass; - private myPrivateMethod; - } - class publicClassWithWithPublicSetAccessorTypes { - static myPublicStaticMethod: publicClass; - private static myPrivateStaticMethod; - myPublicMethod: publicClass; - private myPrivateMethod; - } - class publicClassWithPrivateModuleGetAccessorTypes { - static readonly myPublicStaticMethod: privateModule.publicClass; - readonly myPublicMethod: privateModule.publicClass; - static readonly myPublicStaticMethod1: privateModule.publicClass; - readonly myPublicMethod1: privateModule.publicClass; - } - class publicClassWithPrivateModuleSetAccessorTypes { - static myPublicStaticMethod: privateModule.publicClass; - myPublicMethod: privateModule.publicClass; - } - } - \ No newline at end of file diff --git a/tests/baselines/reference/privacyFunctionParameterDeclFile.js b/tests/baselines/reference/privacyFunctionParameterDeclFile.js index b6827934bf2..e287ef7c3d5 100644 --- a/tests/baselines/reference/privacyFunctionParameterDeclFile.js +++ b/tests/baselines/reference/privacyFunctionParameterDeclFile.js @@ -1281,7 +1281,7 @@ var publicModuleInGlobal; //// [privacyFunctionParameterDeclFile_externalModule.d.ts] -class privateClass { +declare class privateClass { } export declare class publicClass { } @@ -1559,294 +1559,3 @@ declare module publicModuleInGlobal { function publicFunctionWithPrivateModuleParameterTypes(param: privateModule.publicClass): void; function publicAmbientFunctionWithPrivateModuleParameterTypes(param: privateModule.publicClass): void; } - - -//// [DtsFileErrors] - - -tests/cases/compiler/privacyFunctionParameterDeclFile_externalModule.d.ts(1,1): error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. - - -==== tests/cases/compiler/privacyFunctionParameterDeclFile_externalModule.d.ts (1 errors) ==== - class privateClass { - ~~~~~ -!!! error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. - } - export declare class publicClass { - } - export interface publicInterfaceWithPrivateParmeterTypes { - new (param: privateClass): publicClass; - (param: privateClass): publicClass; - myMethod(param: privateClass): void; - } - export interface publicInterfaceWithPublicParmeterTypes { - new (param: publicClass): publicClass; - (param: publicClass): publicClass; - myMethod(param: publicClass): void; - } - export declare class publicClassWithWithPrivateParmeterTypes { - private param1; - param2: privateClass; - static myPublicStaticMethod(param: privateClass): void; - private static myPrivateStaticMethod; - myPublicMethod(param: privateClass): void; - private myPrivateMethod; - constructor(param: privateClass, param1: privateClass, param2: privateClass); - } - export declare class publicClassWithWithPublicParmeterTypes { - private param1; - param2: publicClass; - static myPublicStaticMethod(param: publicClass): void; - private static myPrivateStaticMethod; - myPublicMethod(param: publicClass): void; - private myPrivateMethod; - constructor(param: publicClass, param1: publicClass, param2: publicClass); - } - export declare function publicFunctionWithPrivateParmeterTypes(param: privateClass): void; - export declare function publicFunctionWithPublicParmeterTypes(param: publicClass): void; - export declare function publicAmbientFunctionWithPrivateParmeterTypes(param: privateClass): void; - export declare function publicAmbientFunctionWithPublicParmeterTypes(param: publicClass): void; - export interface publicInterfaceWithPrivateModuleParameterTypes { - new (param: privateModule.publicClass): publicClass; - (param: privateModule.publicClass): publicClass; - myMethod(param: privateModule.publicClass): void; - } - export declare class publicClassWithPrivateModuleParameterTypes { - private param1; - param2: privateModule.publicClass; - static myPublicStaticMethod(param: privateModule.publicClass): void; - myPublicMethod(param: privateModule.publicClass): void; - constructor(param: privateModule.publicClass, param1: privateModule.publicClass, param2: privateModule.publicClass); - } - export declare function publicFunctionWithPrivateModuleParameterTypes(param: privateModule.publicClass): void; - export declare function publicAmbientFunctionWithPrivateModuleParameterTypes(param: privateModule.publicClass): void; - export declare module publicModule { - class privateClass { - } - class publicClass { - } - interface publicInterfaceWithPrivateParmeterTypes { - new (param: privateClass): publicClass; - (param: privateClass): publicClass; - myMethod(param: privateClass): void; - } - interface publicInterfaceWithPublicParmeterTypes { - new (param: publicClass): publicClass; - (param: publicClass): publicClass; - myMethod(param: publicClass): void; - } - class publicClassWithWithPrivateParmeterTypes { - private param1; - param2: privateClass; - static myPublicStaticMethod(param: privateClass): void; - private static myPrivateStaticMethod; - myPublicMethod(param: privateClass): void; - private myPrivateMethod; - constructor(param: privateClass, param1: privateClass, param2: privateClass); - } - class publicClassWithWithPublicParmeterTypes { - private param1; - param2: publicClass; - static myPublicStaticMethod(param: publicClass): void; - private static myPrivateStaticMethod; - myPublicMethod(param: publicClass): void; - private myPrivateMethod; - constructor(param: publicClass, param1: publicClass, param2: publicClass); - } - function publicFunctionWithPrivateParmeterTypes(param: privateClass): void; - function publicFunctionWithPublicParmeterTypes(param: publicClass): void; - function publicAmbientFunctionWithPrivateParmeterTypes(param: privateClass): void; - function publicAmbientFunctionWithPublicParmeterTypes(param: publicClass): void; - interface publicInterfaceWithPrivateModuleParameterTypes { - new (param: privateModule.publicClass): publicClass; - (param: privateModule.publicClass): publicClass; - myMethod(param: privateModule.publicClass): void; - } - class publicClassWithPrivateModuleParameterTypes { - private param1; - param2: privateModule.publicClass; - static myPublicStaticMethod(param: privateModule.publicClass): void; - myPublicMethod(param: privateModule.publicClass): void; - constructor(param: privateModule.publicClass, param1: privateModule.publicClass, param2: privateModule.publicClass); - } - function publicFunctionWithPrivateModuleParameterTypes(param: privateModule.publicClass): void; - function publicAmbientFunctionWithPrivateModuleParameterTypes(param: privateModule.publicClass): void; - } - declare module privateModule { - class privateClass { - } - class publicClass { - } - interface publicInterfaceWithPrivateParmeterTypes { - new (param: privateClass): publicClass; - (param: privateClass): publicClass; - myMethod(param: privateClass): void; - } - interface publicInterfaceWithPublicParmeterTypes { - new (param: publicClass): publicClass; - (param: publicClass): publicClass; - myMethod(param: publicClass): void; - } - class publicClassWithWithPrivateParmeterTypes { - private param1; - param2: privateClass; - static myPublicStaticMethod(param: privateClass): void; - private static myPrivateStaticMethod; - myPublicMethod(param: privateClass): void; - private myPrivateMethod; - constructor(param: privateClass, param1: privateClass, param2: privateClass); - } - class publicClassWithWithPublicParmeterTypes { - private param1; - param2: publicClass; - static myPublicStaticMethod(param: publicClass): void; - private static myPrivateStaticMethod; - myPublicMethod(param: publicClass): void; - private myPrivateMethod; - constructor(param: publicClass, param1: publicClass, param2: publicClass); - } - function publicFunctionWithPrivateParmeterTypes(param: privateClass): void; - function publicFunctionWithPublicParmeterTypes(param: publicClass): void; - function publicAmbientFunctionWithPrivateParmeterTypes(param: privateClass): void; - function publicAmbientFunctionWithPublicParmeterTypes(param: publicClass): void; - interface publicInterfaceWithPrivateModuleParameterTypes { - new (param: privateModule.publicClass): publicClass; - (param: privateModule.publicClass): publicClass; - myMethod(param: privateModule.publicClass): void; - } - class publicClassWithPrivateModuleParameterTypes { - private param1; - param2: privateModule.publicClass; - static myPublicStaticMethod(param: privateModule.publicClass): void; - myPublicMethod(param: privateModule.publicClass): void; - constructor(param: privateModule.publicClass, param1: privateModule.publicClass, param2: privateModule.publicClass); - } - function publicFunctionWithPrivateModuleParameterTypes(param: privateModule.publicClass): void; - function publicAmbientFunctionWithPrivateModuleParameterTypes(param: privateModule.publicClass): void; - } - export {}; - -==== tests/cases/compiler/privacyFunctionParameterDeclFile_GlobalFile.d.ts (0 errors) ==== - declare class publicClassInGlobal { - } - interface publicInterfaceWithPublicParmeterTypesInGlobal { - new (param: publicClassInGlobal): publicClassInGlobal; - (param: publicClassInGlobal): publicClassInGlobal; - myMethod(param: publicClassInGlobal): void; - } - declare class publicClassWithWithPublicParmeterTypesInGlobal { - private param1; - param2: publicClassInGlobal; - static myPublicStaticMethod(param: publicClassInGlobal): void; - private static myPrivateStaticMethod; - myPublicMethod(param: publicClassInGlobal): void; - private myPrivateMethod; - constructor(param: publicClassInGlobal, param1: publicClassInGlobal, param2: publicClassInGlobal); - } - declare function publicFunctionWithPublicParmeterTypesInGlobal(param: publicClassInGlobal): void; - declare function publicAmbientFunctionWithPublicParmeterTypesInGlobal(param: publicClassInGlobal): void; - declare module publicModuleInGlobal { - class privateClass { - } - class publicClass { - } - module privateModule { - class privateClass { - } - class publicClass { - } - interface publicInterfaceWithPrivateParmeterTypes { - new (param: privateClass): publicClass; - (param: privateClass): publicClass; - myMethod(param: privateClass): void; - } - interface publicInterfaceWithPublicParmeterTypes { - new (param: publicClass): publicClass; - (param: publicClass): publicClass; - myMethod(param: publicClass): void; - } - class publicClassWithWithPrivateParmeterTypes { - private param1; - param2: privateClass; - static myPublicStaticMethod(param: privateClass): void; - private static myPrivateStaticMethod; - myPublicMethod(param: privateClass): void; - private myPrivateMethod; - constructor(param: privateClass, param1: privateClass, param2: privateClass); - } - class publicClassWithWithPublicParmeterTypes { - private param1; - param2: publicClass; - static myPublicStaticMethod(param: publicClass): void; - private static myPrivateStaticMethod; - myPublicMethod(param: publicClass): void; - private myPrivateMethod; - constructor(param: publicClass, param1: publicClass, param2: publicClass); - } - function publicFunctionWithPrivateParmeterTypes(param: privateClass): void; - function publicFunctionWithPublicParmeterTypes(param: publicClass): void; - function publicAmbientFunctionWithPrivateParmeterTypes(param: privateClass): void; - function publicAmbientFunctionWithPublicParmeterTypes(param: publicClass): void; - interface publicInterfaceWithPrivateModuleParameterTypes { - new (param: privateModule.publicClass): publicClass; - (param: privateModule.publicClass): publicClass; - myMethod(param: privateModule.publicClass): void; - } - class publicClassWithPrivateModuleParameterTypes { - private param1; - param2: privateModule.publicClass; - static myPublicStaticMethod(param: privateModule.publicClass): void; - myPublicMethod(param: privateModule.publicClass): void; - constructor(param: privateModule.publicClass, param1: privateModule.publicClass, param2: privateModule.publicClass); - } - function publicFunctionWithPrivateModuleParameterTypes(param: privateModule.publicClass): void; - function publicAmbientFunctionWithPrivateModuleParameterTypes(param: privateModule.publicClass): void; - } - interface publicInterfaceWithPrivateParmeterTypes { - new (param: privateClass): publicClass; - (param: privateClass): publicClass; - myMethod(param: privateClass): void; - } - interface publicInterfaceWithPublicParmeterTypes { - new (param: publicClass): publicClass; - (param: publicClass): publicClass; - myMethod(param: publicClass): void; - } - class publicClassWithWithPrivateParmeterTypes { - private param1; - param2: privateClass; - static myPublicStaticMethod(param: privateClass): void; - private static myPrivateStaticMethod; - myPublicMethod(param: privateClass): void; - private myPrivateMethod; - constructor(param: privateClass, param1: privateClass, param2: privateClass); - } - class publicClassWithWithPublicParmeterTypes { - private param1; - param2: publicClass; - static myPublicStaticMethod(param: publicClass): void; - private static myPrivateStaticMethod; - myPublicMethod(param: publicClass): void; - private myPrivateMethod; - constructor(param: publicClass, param1: publicClass, param2: publicClass); - } - function publicFunctionWithPrivateParmeterTypes(param: privateClass): void; - function publicFunctionWithPublicParmeterTypes(param: publicClass): void; - function publicAmbientFunctionWithPrivateParmeterTypes(param: privateClass): void; - function publicAmbientFunctionWithPublicParmeterTypes(param: publicClass): void; - interface publicInterfaceWithPrivateModuleParameterTypes { - new (param: privateModule.publicClass): publicClass; - (param: privateModule.publicClass): publicClass; - myMethod(param: privateModule.publicClass): void; - } - class publicClassWithPrivateModuleParameterTypes { - private param1; - param2: privateModule.publicClass; - static myPublicStaticMethod(param: privateModule.publicClass): void; - myPublicMethod(param: privateModule.publicClass): void; - constructor(param: privateModule.publicClass, param1: privateModule.publicClass, param2: privateModule.publicClass); - } - function publicFunctionWithPrivateModuleParameterTypes(param: privateModule.publicClass): void; - function publicAmbientFunctionWithPrivateModuleParameterTypes(param: privateModule.publicClass): void; - } - \ No newline at end of file diff --git a/tests/baselines/reference/privacyFunctionReturnTypeDeclFile.js b/tests/baselines/reference/privacyFunctionReturnTypeDeclFile.js index 1d10cb2083a..79b144d815e 100644 --- a/tests/baselines/reference/privacyFunctionReturnTypeDeclFile.js +++ b/tests/baselines/reference/privacyFunctionReturnTypeDeclFile.js @@ -2281,7 +2281,7 @@ var publicModuleInGlobal; //// [privacyFunctionReturnTypeDeclFile_externalModule.d.ts] -class privateClass { +declare class privateClass { } export declare class publicClass { } @@ -2597,332 +2597,3 @@ declare module publicModuleInGlobal { function publicFunctionWithPrivateModuleParameterTypes1(): privateModule.publicClass; function publicAmbientFunctionWithPrivateModuleParameterTypes(): privateModule.publicClass; } - - -//// [DtsFileErrors] - - -tests/cases/compiler/privacyFunctionReturnTypeDeclFile_externalModule.d.ts(1,1): error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. - - -==== tests/cases/compiler/privacyFunctionReturnTypeDeclFile_externalModule.d.ts (1 errors) ==== - class privateClass { - ~~~~~ -!!! error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. - } - export declare class publicClass { - } - export interface publicInterfaceWithPrivateParmeterTypes { - new (): privateClass; - (): privateClass; - [x: number]: privateClass; - myMethod(): privateClass; - } - export interface publicInterfaceWithPublicParmeterTypes { - new (): publicClass; - (): publicClass; - [x: number]: publicClass; - myMethod(): publicClass; - } - export declare class publicClassWithWithPrivateParmeterTypes { - static myPublicStaticMethod(): privateClass; - private static myPrivateStaticMethod; - myPublicMethod(): privateClass; - private myPrivateMethod; - static myPublicStaticMethod1(): privateClass; - private static myPrivateStaticMethod1; - myPublicMethod1(): privateClass; - private myPrivateMethod1; - } - export declare class publicClassWithWithPublicParmeterTypes { - static myPublicStaticMethod(): publicClass; - private static myPrivateStaticMethod; - myPublicMethod(): publicClass; - private myPrivateMethod; - static myPublicStaticMethod1(): publicClass; - private static myPrivateStaticMethod1; - myPublicMethod1(): publicClass; - private myPrivateMethod1; - } - export declare function publicFunctionWithPrivateParmeterTypes(): privateClass; - export declare function publicFunctionWithPublicParmeterTypes(): publicClass; - export declare function publicFunctionWithPrivateParmeterTypes1(): privateClass; - export declare function publicFunctionWithPublicParmeterTypes1(): publicClass; - export declare function publicAmbientFunctionWithPrivateParmeterTypes(): privateClass; - export declare function publicAmbientFunctionWithPublicParmeterTypes(): publicClass; - export interface publicInterfaceWithPrivateModuleParameterTypes { - new (): privateModule.publicClass; - (): privateModule.publicClass; - [x: number]: privateModule.publicClass; - myMethod(): privateModule.publicClass; - } - export declare class publicClassWithPrivateModuleParameterTypes { - static myPublicStaticMethod(): privateModule.publicClass; - myPublicMethod(): privateModule.publicClass; - static myPublicStaticMethod1(): privateModule.publicClass; - myPublicMethod1(): privateModule.publicClass; - } - export declare function publicFunctionWithPrivateModuleParameterTypes(): privateModule.publicClass; - export declare function publicFunctionWithPrivateModuleParameterTypes1(): privateModule.publicClass; - export declare function publicAmbientFunctionWithPrivateModuleParameterTypes(): privateModule.publicClass; - export declare module publicModule { - class privateClass { - } - class publicClass { - } - interface publicInterfaceWithPrivateParmeterTypes { - new (): privateClass; - (): privateClass; - [x: number]: privateClass; - myMethod(): privateClass; - } - interface publicInterfaceWithPublicParmeterTypes { - new (): publicClass; - (): publicClass; - [x: number]: publicClass; - myMethod(): publicClass; - } - class publicClassWithWithPrivateParmeterTypes { - static myPublicStaticMethod(): privateClass; - private static myPrivateStaticMethod; - myPublicMethod(): privateClass; - private myPrivateMethod; - static myPublicStaticMethod1(): privateClass; - private static myPrivateStaticMethod1; - myPublicMethod1(): privateClass; - private myPrivateMethod1; - } - class publicClassWithWithPublicParmeterTypes { - static myPublicStaticMethod(): publicClass; - private static myPrivateStaticMethod; - myPublicMethod(): publicClass; - private myPrivateMethod; - static myPublicStaticMethod1(): publicClass; - private static myPrivateStaticMethod1; - myPublicMethod1(): publicClass; - private myPrivateMethod1; - } - function publicFunctionWithPrivateParmeterTypes(): privateClass; - function publicFunctionWithPublicParmeterTypes(): publicClass; - function publicFunctionWithPrivateParmeterTypes1(): privateClass; - function publicFunctionWithPublicParmeterTypes1(): publicClass; - function publicAmbientFunctionWithPrivateParmeterTypes(): privateClass; - function publicAmbientFunctionWithPublicParmeterTypes(): publicClass; - interface publicInterfaceWithPrivateModuleParameterTypes { - new (): privateModule.publicClass; - (): privateModule.publicClass; - [x: number]: privateModule.publicClass; - myMethod(): privateModule.publicClass; - } - class publicClassWithPrivateModuleParameterTypes { - static myPublicStaticMethod(): privateModule.publicClass; - myPublicMethod(): privateModule.publicClass; - static myPublicStaticMethod1(): privateModule.publicClass; - myPublicMethod1(): privateModule.publicClass; - } - function publicFunctionWithPrivateModuleParameterTypes(): privateModule.publicClass; - function publicFunctionWithPrivateModuleParameterTypes1(): privateModule.publicClass; - function publicAmbientFunctionWithPrivateModuleParameterTypes(): privateModule.publicClass; - } - declare module privateModule { - class privateClass { - } - class publicClass { - } - interface publicInterfaceWithPrivateParmeterTypes { - new (): privateClass; - (): privateClass; - [x: number]: privateClass; - myMethod(): privateClass; - } - interface publicInterfaceWithPublicParmeterTypes { - new (): publicClass; - (): publicClass; - [x: number]: publicClass; - myMethod(): publicClass; - } - class publicClassWithWithPrivateParmeterTypes { - static myPublicStaticMethod(): privateClass; - private static myPrivateStaticMethod; - myPublicMethod(): privateClass; - private myPrivateMethod; - static myPublicStaticMethod1(): privateClass; - private static myPrivateStaticMethod1; - myPublicMethod1(): privateClass; - private myPrivateMethod1; - } - class publicClassWithWithPublicParmeterTypes { - static myPublicStaticMethod(): publicClass; - private static myPrivateStaticMethod; - myPublicMethod(): publicClass; - private myPrivateMethod; - static myPublicStaticMethod1(): publicClass; - private static myPrivateStaticMethod1; - myPublicMethod1(): publicClass; - private myPrivateMethod1; - } - function publicFunctionWithPrivateParmeterTypes(): privateClass; - function publicFunctionWithPublicParmeterTypes(): publicClass; - function publicFunctionWithPrivateParmeterTypes1(): privateClass; - function publicFunctionWithPublicParmeterTypes1(): publicClass; - function publicAmbientFunctionWithPrivateParmeterTypes(): privateClass; - function publicAmbientFunctionWithPublicParmeterTypes(): publicClass; - interface publicInterfaceWithPrivateModuleParameterTypes { - new (): privateModule.publicClass; - (): privateModule.publicClass; - [x: number]: privateModule.publicClass; - myMethod(): privateModule.publicClass; - } - class publicClassWithPrivateModuleParameterTypes { - static myPublicStaticMethod(): privateModule.publicClass; - myPublicMethod(): privateModule.publicClass; - static myPublicStaticMethod1(): publicClass; - myPublicMethod1(): publicClass; - } - function publicFunctionWithPrivateModuleParameterTypes(): privateModule.publicClass; - function publicFunctionWithPrivateModuleParameterTypes1(): publicClass; - function publicAmbientFunctionWithPrivateModuleParameterTypes(): privateModule.publicClass; - } - export {}; - -==== tests/cases/compiler/privacyFunctionReturnTypeDeclFile_GlobalFile.d.ts (0 errors) ==== - declare class publicClassInGlobal { - } - interface publicInterfaceWithPublicParmeterTypesInGlobal { - new (): publicClassInGlobal; - (): publicClassInGlobal; - [x: number]: publicClassInGlobal; - myMethod(): publicClassInGlobal; - } - declare class publicClassWithWithPublicParmeterTypesInGlobal { - static myPublicStaticMethod(): publicClassInGlobal; - private static myPrivateStaticMethod; - myPublicMethod(): publicClassInGlobal; - private myPrivateMethod; - static myPublicStaticMethod1(): publicClassInGlobal; - private static myPrivateStaticMethod1; - myPublicMethod1(): publicClassInGlobal; - private myPrivateMethod1; - } - declare function publicFunctionWithPublicParmeterTypesInGlobal(): publicClassInGlobal; - declare function publicFunctionWithPublicParmeterTypesInGlobal1(): publicClassInGlobal; - declare function publicAmbientFunctionWithPublicParmeterTypesInGlobal(): publicClassInGlobal; - declare module publicModuleInGlobal { - class privateClass { - } - class publicClass { - } - module privateModule { - class privateClass { - } - class publicClass { - } - interface publicInterfaceWithPrivateParmeterTypes { - new (): privateClass; - (): privateClass; - [x: number]: privateClass; - myMethod(): privateClass; - } - interface publicInterfaceWithPublicParmeterTypes { - new (): publicClass; - (): publicClass; - [x: number]: publicClass; - myMethod(): publicClass; - } - class publicClassWithWithPrivateParmeterTypes { - static myPublicStaticMethod(): privateClass; - private static myPrivateStaticMethod; - myPublicMethod(): privateClass; - private myPrivateMethod; - static myPublicStaticMethod1(): privateClass; - private static myPrivateStaticMethod1; - myPublicMethod1(): privateClass; - private myPrivateMethod1; - } - class publicClassWithWithPublicParmeterTypes { - static myPublicStaticMethod(): publicClass; - private static myPrivateStaticMethod; - myPublicMethod(): publicClass; - private myPrivateMethod; - static myPublicStaticMethod1(): publicClass; - private static myPrivateStaticMethod1; - myPublicMethod1(): publicClass; - private myPrivateMethod1; - } - function publicFunctionWithPrivateParmeterTypes(): privateClass; - function publicFunctionWithPublicParmeterTypes(): publicClass; - function publicFunctionWithPrivateParmeterTypes1(): privateClass; - function publicFunctionWithPublicParmeterTypes1(): publicClass; - function publicAmbientFunctionWithPrivateParmeterTypes(): privateClass; - function publicAmbientFunctionWithPublicParmeterTypes(): publicClass; - interface publicInterfaceWithPrivateModuleParameterTypes { - new (): privateModule.publicClass; - (): privateModule.publicClass; - [x: number]: privateModule.publicClass; - myMethod(): privateModule.publicClass; - } - class publicClassWithPrivateModuleParameterTypes { - static myPublicStaticMethod(): privateModule.publicClass; - myPublicMethod(): privateModule.publicClass; - static myPublicStaticMethod1(): publicClass; - myPublicMethod1(): publicClass; - } - function publicFunctionWithPrivateModuleParameterTypes(): privateModule.publicClass; - function publicFunctionWithPrivateModuleParameterTypes1(): publicClass; - function publicAmbientFunctionWithPrivateModuleParameterTypes(): privateModule.publicClass; - } - interface publicInterfaceWithPrivateParmeterTypes { - new (): privateClass; - (): privateClass; - [x: number]: privateClass; - myMethod(): privateClass; - } - interface publicInterfaceWithPublicParmeterTypes { - new (): publicClass; - (): publicClass; - [x: number]: publicClass; - myMethod(): publicClass; - } - class publicClassWithWithPrivateParmeterTypes { - static myPublicStaticMethod(): privateClass; - private static myPrivateStaticMethod; - myPublicMethod(): privateClass; - private myPrivateMethod; - static myPublicStaticMethod1(): privateClass; - private static myPrivateStaticMethod1; - myPublicMethod1(): privateClass; - private myPrivateMethod1; - } - class publicClassWithWithPublicParmeterTypes { - static myPublicStaticMethod(): publicClass; - private static myPrivateStaticMethod; - myPublicMethod(): publicClass; - private myPrivateMethod; - static myPublicStaticMethod1(): publicClass; - private static myPrivateStaticMethod1; - myPublicMethod1(): publicClass; - private myPrivateMethod1; - } - function publicFunctionWithPrivateParmeterTypes(): privateClass; - function publicFunctionWithPublicParmeterTypes(): publicClass; - function publicFunctionWithPrivateParmeterTypes1(): privateClass; - function publicFunctionWithPublicParmeterTypes1(): publicClass; - function publicAmbientFunctionWithPrivateParmeterTypes(): privateClass; - function publicAmbientFunctionWithPublicParmeterTypes(): publicClass; - interface publicInterfaceWithPrivateModuleParameterTypes { - new (): privateModule.publicClass; - (): privateModule.publicClass; - [x: number]: privateModule.publicClass; - myMethod(): privateModule.publicClass; - } - class publicClassWithPrivateModuleParameterTypes { - static myPublicStaticMethod(): privateModule.publicClass; - myPublicMethod(): privateModule.publicClass; - static myPublicStaticMethod1(): privateModule.publicClass; - myPublicMethod1(): privateModule.publicClass; - } - function publicFunctionWithPrivateModuleParameterTypes(): privateModule.publicClass; - function publicFunctionWithPrivateModuleParameterTypes1(): privateModule.publicClass; - function publicAmbientFunctionWithPrivateModuleParameterTypes(): privateModule.publicClass; - } - \ No newline at end of file diff --git a/tests/baselines/reference/privacyLocalInternalReferenceImportWithExport.js b/tests/baselines/reference/privacyLocalInternalReferenceImportWithExport.js index 5edf0f819b1..01841c7c44b 100644 --- a/tests/baselines/reference/privacyLocalInternalReferenceImportWithExport.js +++ b/tests/baselines/reference/privacyLocalInternalReferenceImportWithExport.js @@ -298,7 +298,7 @@ var import_private; //// [privacyLocalInternalReferenceImportWithExport.d.ts] -module m_private { +declare module m_private { class c_private { } enum e_private { @@ -369,86 +369,3 @@ export declare module import_public { var publicUse_im_public_mu_public: im_public_mu_public.i; } export {}; - - -//// [DtsFileErrors] - - -tests/cases/compiler/privacyLocalInternalReferenceImportWithExport.d.ts(1,1): error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. - - -==== tests/cases/compiler/privacyLocalInternalReferenceImportWithExport.d.ts (1 errors) ==== - module m_private { - ~~~~~~ -!!! error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. - class c_private { - } - enum e_private { - Happy = 0, - Grumpy = 1 - } - function f_private(): c_private; - var v_private: c_private; - interface i_private { - } - module mi_private { - class c { - } - } - module mu_private { - interface i { - } - } - } - export declare module m_public { - class c_public { - } - enum e_public { - Happy = 0, - Grumpy = 1 - } - function f_public(): c_public; - var v_public: number; - interface i_public { - } - module mi_public { - class c { - } - } - module mu_public { - interface i { - } - } - } - export declare module import_public { - export import im_public_c_private = m_private.c_private; - export import im_public_e_private = m_private.e_private; - export import im_public_f_private = m_private.f_private; - export import im_public_v_private = m_private.v_private; - export import im_public_i_private = m_private.i_private; - export import im_public_mi_private = m_private.mi_private; - export import im_public_mu_private = m_private.mu_private; - var publicUse_im_public_c_private: im_public_c_private; - var publicUse_im_public_e_private: im_public_e_private; - var publicUse_im_public_f_private: im_public_c_private; - var publicUse_im_public_v_private: im_public_c_private; - var publicUse_im_public_i_private: im_public_i_private; - var publicUse_im_public_mi_private: im_public_mi_private.c; - var publicUse_im_public_mu_private: im_public_mu_private.i; - export import im_public_c_public = m_public.c_public; - export import im_public_e_public = m_public.e_public; - export import im_public_f_public = m_public.f_public; - export import im_public_v_public = m_public.v_public; - export import im_public_i_public = m_public.i_public; - export import im_public_mi_public = m_public.mi_public; - export import im_public_mu_public = m_public.mu_public; - var publicUse_im_public_c_public: im_public_c_public; - var publicUse_im_public_e_public: im_public_e_public; - var publicUse_im_public_f_public: im_public_c_public; - var publicUse_im_public_v_public: number; - var publicUse_im_public_i_public: im_public_i_public; - var publicUse_im_public_mi_public: im_public_mi_public.c; - var publicUse_im_public_mu_public: im_public_mu_public.i; - } - export {}; - \ No newline at end of file diff --git a/tests/baselines/reference/privacyLocalInternalReferenceImportWithoutExport.js b/tests/baselines/reference/privacyLocalInternalReferenceImportWithoutExport.js index 73266bc1d02..35c047e0519 100644 --- a/tests/baselines/reference/privacyLocalInternalReferenceImportWithoutExport.js +++ b/tests/baselines/reference/privacyLocalInternalReferenceImportWithoutExport.js @@ -300,7 +300,7 @@ define(["require", "exports"], function (require, exports) { //// [privacyLocalInternalReferenceImportWithoutExport.d.ts] -module m_private { +declare module m_private { class c_private { } enum e_private { @@ -367,82 +367,3 @@ export declare module import_public { var publicUse_im_private_mu_public: im_private_mu_public.i; } export {}; - - -//// [DtsFileErrors] - - -tests/cases/compiler/privacyLocalInternalReferenceImportWithoutExport.d.ts(1,1): error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. - - -==== tests/cases/compiler/privacyLocalInternalReferenceImportWithoutExport.d.ts (1 errors) ==== - module m_private { - ~~~~~~ -!!! error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. - class c_private { - } - enum e_private { - Happy = 0, - Grumpy = 1 - } - function f_private(): c_private; - var v_private: c_private; - interface i_private { - } - module mi_private { - class c { - } - } - module mu_private { - interface i { - } - } - } - export declare module m_public { - class c_public { - } - enum e_public { - Happy = 0, - Grumpy = 1 - } - function f_public(): c_public; - var v_public: number; - interface i_public { - } - module mi_public { - class c { - } - } - module mu_public { - interface i { - } - } - } - export declare module import_public { - import im_private_c_private = m_private.c_private; - import im_private_e_private = m_private.e_private; - import im_private_i_private = m_private.i_private; - import im_private_mi_private = m_private.mi_private; - import im_private_mu_private = m_private.mu_private; - var publicUse_im_private_c_private: im_private_c_private; - var publicUse_im_private_e_private: im_private_e_private; - var publicUse_im_private_f_private: im_private_c_private; - var publicUse_im_private_v_private: im_private_c_private; - var publicUse_im_private_i_private: im_private_i_private; - var publicUse_im_private_mi_private: im_private_mi_private.c; - var publicUse_im_private_mu_private: im_private_mu_private.i; - import im_private_c_public = m_public.c_public; - import im_private_e_public = m_public.e_public; - import im_private_i_public = m_public.i_public; - import im_private_mi_public = m_public.mi_public; - import im_private_mu_public = m_public.mu_public; - var publicUse_im_private_c_public: im_private_c_public; - var publicUse_im_private_e_public: im_private_e_public; - var publicUse_im_private_f_public: im_private_c_public; - var publicUse_im_private_v_public: number; - var publicUse_im_private_i_public: im_private_i_public; - var publicUse_im_private_mi_public: im_private_mi_public.c; - var publicUse_im_private_mu_public: im_private_mu_public.i; - } - export {}; - \ No newline at end of file diff --git a/tests/baselines/reference/privacyTypeParameterOfFunctionDeclFile.js b/tests/baselines/reference/privacyTypeParameterOfFunctionDeclFile.js index 840255f7648..32425e9d9a4 100644 --- a/tests/baselines/reference/privacyTypeParameterOfFunctionDeclFile.js +++ b/tests/baselines/reference/privacyTypeParameterOfFunctionDeclFile.js @@ -819,7 +819,7 @@ var privateModule; //// [privacyTypeParameterOfFunctionDeclFile.d.ts] -class privateClass { +declare class privateClass { } export declare class publicClass { } @@ -964,160 +964,3 @@ declare module privateModule { function publicFunctionWithPublicTypeParametersWithoutExtends(): void; } export {}; - - -//// [DtsFileErrors] - - -tests/cases/compiler/privacyTypeParameterOfFunctionDeclFile.d.ts(1,1): error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. - - -==== tests/cases/compiler/privacyTypeParameterOfFunctionDeclFile.d.ts (1 errors) ==== - class privateClass { - ~~~~~ -!!! error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. - } - export declare class publicClass { - } - export interface publicInterfaceWithPrivateTypeParameters { - new (): privateClass; - (): privateClass; - myMethod(): privateClass; - } - export interface publicInterfaceWithPublicTypeParameters { - new (): publicClass; - (): publicClass; - myMethod(): publicClass; - } - export declare class publicClassWithWithPrivateTypeParameters { - static myPublicStaticMethod(): void; - private static myPrivateStaticMethod; - myPublicMethod(): void; - private myPrivateMethod; - } - export declare class publicClassWithWithPublicTypeParameters { - static myPublicStaticMethod(): void; - private static myPrivateStaticMethod; - myPublicMethod(): void; - private myPrivateMethod; - } - export declare function publicFunctionWithPrivateTypeParameters(): void; - export declare function publicFunctionWithPublicTypeParameters(): void; - export interface publicInterfaceWithPublicTypeParametersWithoutExtends { - new (): publicClass; - (): publicClass; - myMethod(): publicClass; - } - export declare class publicClassWithWithPublicTypeParametersWithoutExtends { - static myPublicStaticMethod(): void; - private static myPrivateStaticMethod; - myPublicMethod(): void; - private myPrivateMethod; - } - export declare function publicFunctionWithPublicTypeParametersWithoutExtends(): void; - export interface publicInterfaceWithPrivatModuleTypeParameters { - new (): privateModule.publicClass; - (): privateModule.publicClass; - myMethod(): privateModule.publicClass; - } - export declare class publicClassWithWithPrivateModuleTypeParameters { - static myPublicStaticMethod(): void; - myPublicMethod(): void; - } - export declare function publicFunctionWithPrivateMopduleTypeParameters(): void; - export declare module publicModule { - class privateClass { - } - class publicClass { - } - interface publicInterfaceWithPrivateTypeParameters { - new (): privateClass; - (): privateClass; - myMethod(): privateClass; - } - interface publicInterfaceWithPublicTypeParameters { - new (): publicClass; - (): publicClass; - myMethod(): publicClass; - } - class publicClassWithWithPrivateTypeParameters { - static myPublicStaticMethod(): void; - private static myPrivateStaticMethod; - myPublicMethod(): void; - private myPrivateMethod; - } - class publicClassWithWithPublicTypeParameters { - static myPublicStaticMethod(): void; - private static myPrivateStaticMethod; - myPublicMethod(): void; - private myPrivateMethod; - } - function publicFunctionWithPrivateTypeParameters(): void; - function publicFunctionWithPublicTypeParameters(): void; - interface publicInterfaceWithPublicTypeParametersWithoutExtends { - new (): publicClass; - (): publicClass; - myMethod(): publicClass; - } - class publicClassWithWithPublicTypeParametersWithoutExtends { - static myPublicStaticMethod(): void; - private static myPrivateStaticMethod; - myPublicMethod(): void; - private myPrivateMethod; - } - function publicFunctionWithPublicTypeParametersWithoutExtends(): void; - interface publicInterfaceWithPrivatModuleTypeParameters { - new (): privateModule.publicClass; - (): privateModule.publicClass; - myMethod(): privateModule.publicClass; - } - class publicClassWithWithPrivateModuleTypeParameters { - static myPublicStaticMethod(): void; - myPublicMethod(): void; - } - function publicFunctionWithPrivateMopduleTypeParameters(): void; - } - declare module privateModule { - class privateClass { - } - class publicClass { - } - interface publicInterfaceWithPrivateTypeParameters { - new (): privateClass; - (): privateClass; - myMethod(): privateClass; - } - interface publicInterfaceWithPublicTypeParameters { - new (): publicClass; - (): publicClass; - myMethod(): publicClass; - } - class publicClassWithWithPrivateTypeParameters { - static myPublicStaticMethod(): void; - private static myPrivateStaticMethod; - myPublicMethod(): void; - private myPrivateMethod; - } - class publicClassWithWithPublicTypeParameters { - static myPublicStaticMethod(): void; - private static myPrivateStaticMethod; - myPublicMethod(): void; - private myPrivateMethod; - } - function publicFunctionWithPrivateTypeParameters(): void; - function publicFunctionWithPublicTypeParameters(): void; - interface publicInterfaceWithPublicTypeParametersWithoutExtends { - new (): publicClass; - (): publicClass; - myMethod(): publicClass; - } - class publicClassWithWithPublicTypeParametersWithoutExtends { - static myPublicStaticMethod(): void; - private static myPrivateStaticMethod; - myPublicMethod(): void; - private myPrivateMethod; - } - function publicFunctionWithPublicTypeParametersWithoutExtends(): void; - } - export {}; - \ No newline at end of file diff --git a/tests/baselines/reference/privacyTypeParametersOfClassDeclFile.js b/tests/baselines/reference/privacyTypeParametersOfClassDeclFile.js index b0dfadfce12..bcf4c542fb7 100644 --- a/tests/baselines/reference/privacyTypeParametersOfClassDeclFile.js +++ b/tests/baselines/reference/privacyTypeParametersOfClassDeclFile.js @@ -386,7 +386,7 @@ var privateModule; //// [privacyTypeParametersOfClassDeclFile.d.ts] -class privateClass { +declare class privateClass { } export declare class publicClass { } @@ -436,65 +436,3 @@ declare module privateModule { } } export {}; - - -//// [DtsFileErrors] - - -tests/cases/compiler/privacyTypeParametersOfClassDeclFile.d.ts(1,1): error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. - - -==== tests/cases/compiler/privacyTypeParametersOfClassDeclFile.d.ts (1 errors) ==== - class privateClass { - ~~~~~ -!!! error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. - } - export declare class publicClass { - } - export declare class publicClassWithPrivateTypeParameters { - myMethod(val: T): T; - } - export declare class publicClassWithPublicTypeParameters { - myMethod(val: T): T; - } - export declare class publicClassWithPublicTypeParametersWithoutExtends { - myMethod(val: T): T; - } - export declare class publicClassWithTypeParametersFromPrivateModule { - myMethod(val: T): T; - } - export declare module publicModule { - class privateClassInPublicModule { - } - class publicClassInPublicModule { - } - class publicClassWithPrivateTypeParameters { - myMethod(val: T): T; - } - class publicClassWithPublicTypeParameters { - myMethod(val: T): T; - } - class publicClassWithPublicTypeParametersWithoutExtends { - myMethod(val: T): T; - } - class publicClassWithTypeParametersFromPrivateModule { - myMethod(val: T): T; - } - } - declare module privateModule { - class privateClassInPrivateModule { - } - class publicClassInPrivateModule { - } - class publicClassWithPrivateTypeParameters { - myMethod(val: T): T; - } - class publicClassWithPublicTypeParameters { - myMethod(val: T): T; - } - class publicClassWithPublicTypeParametersWithoutExtends { - myMethod(val: T): T; - } - } - export {}; - \ No newline at end of file diff --git a/tests/baselines/reference/privacyTypeParametersOfInterfaceDeclFile.js b/tests/baselines/reference/privacyTypeParametersOfInterfaceDeclFile.js index 25e327c42aa..2a7a83e4577 100644 --- a/tests/baselines/reference/privacyTypeParametersOfInterfaceDeclFile.js +++ b/tests/baselines/reference/privacyTypeParametersOfInterfaceDeclFile.js @@ -268,11 +268,11 @@ var privateModule; //// [privacyTypeParametersOfInterfaceDeclFile.d.ts] -class privateClass { +declare class privateClass { } export declare class publicClass { } -class privateClassT { +declare class privateClassT { } export declare class publicClassT { } @@ -361,108 +361,3 @@ declare module privateModule { } } export {}; - - -//// [DtsFileErrors] - - -tests/cases/compiler/privacyTypeParametersOfInterfaceDeclFile.d.ts(1,1): error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. - - -==== tests/cases/compiler/privacyTypeParametersOfInterfaceDeclFile.d.ts (1 errors) ==== - class privateClass { - ~~~~~ -!!! error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. - } - export declare class publicClass { - } - class privateClassT { - } - export declare class publicClassT { - } - export interface publicInterfaceWithPrivateTypeParameters { - myMethod(val: T): T; - myMethod0(): publicClassT; - myMethod1(): privateClassT; - myMethod2(): privateClassT; - myMethod3(): publicClassT; - myMethod4(): publicClassT; - } - export interface publicInterfaceWithPublicTypeParameters { - myMethod(val: T): T; - myMethod0(): publicClassT; - myMethod1(): privateClassT; - myMethod2(): privateClassT; - myMethod3(): publicClassT; - myMethod4(): publicClassT; - } - export interface publicInterfaceWithPublicTypeParametersWithoutExtends { - myMethod(val: T): T; - myMethod0(): publicClassT; - } - export interface publicInterfaceWithPrivateModuleTypeParameterConstraints { - } - export declare module publicModule { - class privateClassInPublicModule { - } - class publicClassInPublicModule { - } - class privateClassInPublicModuleT { - } - class publicClassInPublicModuleT { - } - interface publicInterfaceWithPrivateTypeParameters { - myMethod(val: T): T; - myMethod0(): publicClassInPublicModuleT; - myMethod1(): privateClassInPublicModuleT; - myMethod2(): privateClassInPublicModuleT; - myMethod3(): publicClassInPublicModuleT; - myMethod4(): publicClassInPublicModuleT; - } - interface publicInterfaceWithPublicTypeParameters { - myMethod(val: T): T; - myMethod0(): publicClassInPublicModuleT; - myMethod1(): privateClassInPublicModuleT; - myMethod2(): privateClassInPublicModuleT; - myMethod3(): publicClassInPublicModuleT; - myMethod4(): publicClassInPublicModuleT; - } - interface publicInterfaceWithPublicTypeParametersWithoutExtends { - myMethod(val: T): T; - myMethod0(): publicClassInPublicModuleT; - } - interface publicInterfaceWithPrivateModuleTypeParameterConstraints { - } - } - declare module privateModule { - class privateClassInPrivateModule { - } - class publicClassInPrivateModule { - } - class privateClassInPrivateModuleT { - } - class publicClassInPrivateModuleT { - } - interface publicInterfaceWithPrivateTypeParameters { - myMethod(val: T): T; - myMethod0(): publicClassInPrivateModuleT; - myMethod1(): privateClassInPrivateModuleT; - myMethod2(): privateClassInPrivateModuleT; - myMethod3(): publicClassInPrivateModuleT; - myMethod4(): publicClassInPrivateModuleT; - } - interface publicInterfaceWithPublicTypeParameters { - myMethod(val: T): T; - myMethod0(): publicClassInPrivateModuleT; - myMethod1(): privateClassInPrivateModuleT; - myMethod2(): privateClassInPrivateModuleT; - myMethod3(): publicClassInPrivateModuleT; - myMethod4(): publicClassInPrivateModuleT; - } - interface publicInterfaceWithPublicTypeParametersWithoutExtends { - myMethod(val: T): T; - myMethod0(): publicClassInPrivateModuleT; - } - } - export {}; - \ No newline at end of file diff --git a/tests/baselines/reference/privacyVarDeclFile.js b/tests/baselines/reference/privacyVarDeclFile.js index 016ccda1de7..f32b8707534 100644 --- a/tests/baselines/reference/privacyVarDeclFile.js +++ b/tests/baselines/reference/privacyVarDeclFile.js @@ -689,7 +689,7 @@ var publicModuleInGlobal; //// [privacyVarDeclFile_externalModule.d.ts] -class privateClass { +declare class privateClass { } export declare class publicClass { } @@ -887,214 +887,3 @@ declare module publicModuleInGlobal { var publicVarWithPrivateModulePropertyTypes: privateModule.publicClass; var publicAmbientVarWithPrivateModulePropertyTypes: privateModule.publicClass; } - - -//// [DtsFileErrors] - - -tests/cases/compiler/privacyVarDeclFile_externalModule.d.ts(1,1): error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. - - -==== tests/cases/compiler/privacyVarDeclFile_externalModule.d.ts (1 errors) ==== - class privateClass { - ~~~~~ -!!! error TS1046: A 'declare' modifier is required for a top level declaration in a .d.ts file. - } - export declare class publicClass { - } - export interface publicInterfaceWithPrivatePropertyTypes { - myProperty: privateClass; - } - export interface publicInterfaceWithPublicPropertyTypes { - myProperty: publicClass; - } - export declare class publicClassWithWithPrivatePropertyTypes { - static myPublicStaticProperty: privateClass; - private static myPrivateStaticProperty; - myPublicProperty: privateClass; - private myPrivateProperty; - } - export declare class publicClassWithWithPublicPropertyTypes { - static myPublicStaticProperty: publicClass; - private static myPrivateStaticProperty; - myPublicProperty: publicClass; - private myPrivateProperty; - } - export declare var publicVarWithPrivatePropertyTypes: privateClass; - export declare var publicVarWithPublicPropertyTypes: publicClass; - export declare var publicAmbientVarWithPrivatePropertyTypes: privateClass; - export declare var publicAmbientVarWithPublicPropertyTypes: publicClass; - export interface publicInterfaceWithPrivateModulePropertyTypes { - myProperty: privateModule.publicClass; - } - export declare class publicClassWithPrivateModulePropertyTypes { - static myPublicStaticProperty: privateModule.publicClass; - myPublicProperty: privateModule.publicClass; - } - export declare var publicVarWithPrivateModulePropertyTypes: privateModule.publicClass; - export declare var publicAmbientVarWithPrivateModulePropertyTypes: privateModule.publicClass; - export declare module publicModule { - class privateClass { - } - class publicClass { - } - interface publicInterfaceWithPrivatePropertyTypes { - myProperty: privateClass; - } - interface publicInterfaceWithPublicPropertyTypes { - myProperty: publicClass; - } - class publicClassWithWithPrivatePropertyTypes { - static myPublicStaticProperty: privateClass; - private static myPrivateStaticProperty; - myPublicProperty: privateClass; - private myPrivateProperty; - } - class publicClassWithWithPublicPropertyTypes { - static myPublicStaticProperty: publicClass; - private static myPrivateStaticProperty; - myPublicProperty: publicClass; - private myPrivateProperty; - } - var publicVarWithPrivatePropertyTypes: privateClass; - var publicVarWithPublicPropertyTypes: publicClass; - var publicAmbientVarWithPrivatePropertyTypes: privateClass; - var publicAmbientVarWithPublicPropertyTypes: publicClass; - interface publicInterfaceWithPrivateModulePropertyTypes { - myProperty: privateModule.publicClass; - } - class publicClassWithPrivateModulePropertyTypes { - static myPublicStaticProperty: privateModule.publicClass; - myPublicProperty: privateModule.publicClass; - } - var publicVarWithPrivateModulePropertyTypes: privateModule.publicClass; - var publicAmbientVarWithPrivateModulePropertyTypes: privateModule.publicClass; - } - declare module privateModule { - class privateClass { - } - class publicClass { - } - interface publicInterfaceWithPrivatePropertyTypes { - myProperty: privateClass; - } - interface publicInterfaceWithPublicPropertyTypes { - myProperty: publicClass; - } - class publicClassWithWithPrivatePropertyTypes { - static myPublicStaticProperty: privateClass; - private static myPrivateStaticProperty; - myPublicProperty: privateClass; - private myPrivateProperty; - } - class publicClassWithWithPublicPropertyTypes { - static myPublicStaticProperty: publicClass; - private static myPrivateStaticProperty; - myPublicProperty: publicClass; - private myPrivateProperty; - } - var publicVarWithPrivatePropertyTypes: privateClass; - var publicVarWithPublicPropertyTypes: publicClass; - var publicAmbientVarWithPrivatePropertyTypes: privateClass; - var publicAmbientVarWithPublicPropertyTypes: publicClass; - interface publicInterfaceWithPrivateModulePropertyTypes { - myProperty: privateModule.publicClass; - } - class publicClassWithPrivateModulePropertyTypes { - static myPublicStaticProperty: privateModule.publicClass; - myPublicProperty: privateModule.publicClass; - } - var publicVarWithPrivateModulePropertyTypes: privateModule.publicClass; - var publicAmbientVarWithPrivateModulePropertyTypes: privateModule.publicClass; - } - export {}; - -==== tests/cases/compiler/privacyVarDeclFile_GlobalFile.d.ts (0 errors) ==== - declare class publicClassInGlobal { - } - interface publicInterfaceWithPublicPropertyTypesInGlobal { - myProperty: publicClassInGlobal; - } - declare class publicClassWithWithPublicPropertyTypesInGlobal { - static myPublicStaticProperty: publicClassInGlobal; - private static myPrivateStaticProperty; - myPublicProperty: publicClassInGlobal; - private myPrivateProperty; - } - declare var publicVarWithPublicPropertyTypesInGlobal: publicClassInGlobal; - declare var publicAmbientVarWithPublicPropertyTypesInGlobal: publicClassInGlobal; - declare module publicModuleInGlobal { - class privateClass { - } - class publicClass { - } - module privateModule { - class privateClass { - } - class publicClass { - } - interface publicInterfaceWithPrivatePropertyTypes { - myProperty: privateClass; - } - interface publicInterfaceWithPublicPropertyTypes { - myProperty: publicClass; - } - class publicClassWithWithPrivatePropertyTypes { - static myPublicStaticProperty: privateClass; - private static myPrivateStaticProperty; - myPublicProperty: privateClass; - private myPrivateProperty; - } - class publicClassWithWithPublicPropertyTypes { - static myPublicStaticProperty: publicClass; - private static myPrivateStaticProperty; - myPublicProperty: publicClass; - private myPrivateProperty; - } - var publicVarWithPrivatePropertyTypes: privateClass; - var publicVarWithPublicPropertyTypes: publicClass; - var publicAmbientVarWithPrivatePropertyTypes: privateClass; - var publicAmbientVarWithPublicPropertyTypes: publicClass; - interface publicInterfaceWithPrivateModulePropertyTypes { - myProperty: privateModule.publicClass; - } - class publicClassWithPrivateModulePropertyTypes { - static myPublicStaticProperty: privateModule.publicClass; - myPublicProperty: privateModule.publicClass; - } - var publicVarWithPrivateModulePropertyTypes: privateModule.publicClass; - var publicAmbientVarWithPrivateModulePropertyTypes: privateModule.publicClass; - } - interface publicInterfaceWithPrivatePropertyTypes { - myProperty: privateClass; - } - interface publicInterfaceWithPublicPropertyTypes { - myProperty: publicClass; - } - class publicClassWithWithPrivatePropertyTypes { - static myPublicStaticProperty: privateClass; - private static myPrivateStaticProperty; - myPublicProperty: privateClass; - private myPrivateProperty; - } - class publicClassWithWithPublicPropertyTypes { - static myPublicStaticProperty: publicClass; - private static myPrivateStaticProperty; - myPublicProperty: publicClass; - private myPrivateProperty; - } - var publicVarWithPrivatePropertyTypes: privateClass; - var publicVarWithPublicPropertyTypes: publicClass; - var publicAmbientVarWithPrivatePropertyTypes: privateClass; - var publicAmbientVarWithPublicPropertyTypes: publicClass; - interface publicInterfaceWithPrivateModulePropertyTypes { - myProperty: privateModule.publicClass; - } - class publicClassWithPrivateModulePropertyTypes { - static myPublicStaticProperty: privateModule.publicClass; - myPublicProperty: privateModule.publicClass; - } - var publicVarWithPrivateModulePropertyTypes: privateModule.publicClass; - var publicAmbientVarWithPrivateModulePropertyTypes: privateModule.publicClass; - } - \ No newline at end of file diff --git a/tests/cases/compiler/declarationEmitLocalClassHasRequiredDeclare.ts b/tests/cases/compiler/declarationEmitLocalClassHasRequiredDeclare.ts new file mode 100644 index 00000000000..67bbc871545 --- /dev/null +++ b/tests/cases/compiler/declarationEmitLocalClassHasRequiredDeclare.ts @@ -0,0 +1,16 @@ +// @declaration: true +export declare namespace A { + namespace X { } +} + +class X { } + +export class A { + static X = X; +} + +export declare namespace Y { + +} + +export class Y { } \ No newline at end of file From 3d2bf6a75f87e08bb432ee03b70008bf914d4b7a Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Mon, 14 Jan 2019 13:56:27 -0800 Subject: [PATCH 88/96] Fix implement interface quickfix import types (#29410) * Pass module specifier resolution host thru types constructed by implements quickfixes * Add regression test * Fix scope node for generated methods, fix lints --- src/compiler/types.ts | 2 + src/services/codefixes/fixAddMissingMember.ts | 2 +- ...sDoesntImplementInheritedAbstractMember.ts | 11 +++-- .../fixClassIncorrectlyImplementsInterface.ts | 14 +++--- src/services/codefixes/helpers.ts | 48 +++++++++++++++---- ...ClassImplementInterface_typeInOtherFile.ts | 4 +- .../codeFixUndeclaredAcrossFiles3.ts | 2 +- ...erfaceUnreachableTypeUsesRelativeImport.ts | 26 ++++++++++ 8 files changed, 83 insertions(+), 26 deletions(-) create mode 100644 tests/cases/fourslash/quickfixImplementInterfaceUnreachableTypeUsesRelativeImport.ts diff --git a/src/compiler/types.ts b/src/compiler/types.ts index e46a3d70403..125c3297863 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3037,8 +3037,10 @@ namespace ts { /* @internal */ typeToTypeNode(type: Type, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker): TypeNode | undefined; // tslint:disable-line unified-signatures /** Note that the resulting nodes cannot be checked. */ signatureToSignatureDeclaration(signature: Signature, kind: SyntaxKind, enclosingDeclaration?: Node, flags?: NodeBuilderFlags): SignatureDeclaration & {typeArguments?: NodeArray} | undefined; + /* @internal */ signatureToSignatureDeclaration(signature: Signature, kind: SyntaxKind, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker): SignatureDeclaration & {typeArguments?: NodeArray} | undefined; // tslint:disable-line unified-signatures /** Note that the resulting nodes cannot be checked. */ indexInfoToIndexSignatureDeclaration(indexInfo: IndexInfo, kind: IndexKind, enclosingDeclaration?: Node, flags?: NodeBuilderFlags): IndexSignatureDeclaration | undefined; + /* @internal */ indexInfoToIndexSignatureDeclaration(indexInfo: IndexInfo, kind: IndexKind, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker): IndexSignatureDeclaration | undefined; // tslint:disable-line unified-signatures /** Note that the resulting nodes cannot be checked. */ symbolToEntityName(symbol: Symbol, meaning: SymbolFlags, enclosingDeclaration?: Node, flags?: NodeBuilderFlags): EntityName | undefined; /** Note that the resulting nodes cannot be checked. */ diff --git a/src/services/codefixes/fixAddMissingMember.ts b/src/services/codefixes/fixAddMissingMember.ts index bbad3e03824..98ddee61f8e 100644 --- a/src/services/codefixes/fixAddMissingMember.ts +++ b/src/services/codefixes/fixAddMissingMember.ts @@ -275,7 +275,7 @@ namespace ts.codefix { inJs: boolean, preferences: UserPreferences, ): void { - const methodDeclaration = createMethodFromCallExpression(context, callExpression, token.text, inJs, makeStatic, preferences, !isInterfaceDeclaration(typeDecl)); + const methodDeclaration = createMethodFromCallExpression(context, callExpression, token.text, inJs, makeStatic, preferences, typeDecl); const containingMethodDeclaration = getAncestor(callExpression, SyntaxKind.MethodDeclaration); if (containingMethodDeclaration && containingMethodDeclaration.parent === typeDecl) { diff --git a/src/services/codefixes/fixClassDoesntImplementInheritedAbstractMember.ts b/src/services/codefixes/fixClassDoesntImplementInheritedAbstractMember.ts index 9d9972c03e8..d18bc50639a 100644 --- a/src/services/codefixes/fixClassDoesntImplementInheritedAbstractMember.ts +++ b/src/services/codefixes/fixClassDoesntImplementInheritedAbstractMember.ts @@ -8,9 +8,9 @@ namespace ts.codefix { registerCodeFix({ errorCodes, getCodeActions(context) { - const { program, sourceFile, span } = context; + const { sourceFile, span } = context; const changes = textChanges.ChangeTracker.with(context, t => - addMissingMembers(getClass(sourceFile, span.start), sourceFile, program.getTypeChecker(), t, context.preferences)); + addMissingMembers(getClass(sourceFile, span.start), sourceFile, context, t, context.preferences)); return changes.length === 0 ? undefined : [createCodeFixAction(fixId, changes, Diagnostics.Implement_inherited_abstract_class, fixId, Diagnostics.Implement_all_inherited_abstract_classes)]; }, fixIds: [fixId], @@ -19,7 +19,7 @@ namespace ts.codefix { return codeFixAll(context, errorCodes, (changes, diag) => { const classDeclaration = getClass(diag.file, diag.start); if (addToSeen(seenClassDeclarations, getNodeId(classDeclaration))) { - addMissingMembers(classDeclaration, context.sourceFile, context.program.getTypeChecker(), changes, context.preferences); + addMissingMembers(classDeclaration, context.sourceFile, context, changes, context.preferences); } }); }, @@ -32,15 +32,16 @@ namespace ts.codefix { return cast(token.parent, isClassLike); } - function addMissingMembers(classDeclaration: ClassLikeDeclaration, sourceFile: SourceFile, checker: TypeChecker, changeTracker: textChanges.ChangeTracker, preferences: UserPreferences): void { + function addMissingMembers(classDeclaration: ClassLikeDeclaration, sourceFile: SourceFile, context: TypeConstructionContext, changeTracker: textChanges.ChangeTracker, preferences: UserPreferences): void { const extendsNode = getEffectiveBaseTypeNode(classDeclaration)!; + const checker = context.program.getTypeChecker(); const instantiatedExtendsType = checker.getTypeAtLocation(extendsNode); // Note that this is ultimately derived from a map indexed by symbol names, // so duplicates cannot occur. const abstractAndNonPrivateExtendsSymbols = checker.getPropertiesOfType(instantiatedExtendsType).filter(symbolPointsToNonPrivateAndAbstractMember); - createMissingMemberNodes(classDeclaration, abstractAndNonPrivateExtendsSymbols, checker, preferences, member => changeTracker.insertNodeAtClassStart(sourceFile, classDeclaration, member)); + createMissingMemberNodes(classDeclaration, abstractAndNonPrivateExtendsSymbols, context, preferences, member => changeTracker.insertNodeAtClassStart(sourceFile, classDeclaration, member)); } function symbolPointsToNonPrivateAndAbstractMember(symbol: Symbol): boolean { diff --git a/src/services/codefixes/fixClassIncorrectlyImplementsInterface.ts b/src/services/codefixes/fixClassIncorrectlyImplementsInterface.ts index 4401625000a..59385f2e2e9 100644 --- a/src/services/codefixes/fixClassIncorrectlyImplementsInterface.ts +++ b/src/services/codefixes/fixClassIncorrectlyImplementsInterface.ts @@ -6,11 +6,10 @@ namespace ts.codefix { registerCodeFix({ errorCodes, getCodeActions(context) { - const { program, sourceFile, span } = context; + const { sourceFile, span } = context; const classDeclaration = getClass(sourceFile, span.start); - const checker = program.getTypeChecker(); return mapDefined(getClassImplementsHeritageClauseElements(classDeclaration), implementedTypeNode => { - const changes = textChanges.ChangeTracker.with(context, t => addMissingDeclarations(checker, implementedTypeNode, sourceFile, classDeclaration, t, context.preferences)); + const changes = textChanges.ChangeTracker.with(context, t => addMissingDeclarations(context, implementedTypeNode, sourceFile, classDeclaration, t, context.preferences)); return changes.length === 0 ? undefined : createCodeFixAction(fixId, changes, [Diagnostics.Implement_interface_0, implementedTypeNode.getText(sourceFile)], fixId, Diagnostics.Implement_all_unimplemented_interfaces); }); }, @@ -21,7 +20,7 @@ namespace ts.codefix { const classDeclaration = getClass(diag.file, diag.start); if (addToSeen(seenClassDeclarations, getNodeId(classDeclaration))) { for (const implementedTypeNode of getClassImplementsHeritageClauseElements(classDeclaration)!) { - addMissingDeclarations(context.program.getTypeChecker(), implementedTypeNode, diag.file, classDeclaration, changes, context.preferences); + addMissingDeclarations(context, implementedTypeNode, diag.file, classDeclaration, changes, context.preferences); } } }); @@ -37,13 +36,14 @@ namespace ts.codefix { } function addMissingDeclarations( - checker: TypeChecker, + context: TypeConstructionContext, implementedTypeNode: ExpressionWithTypeArguments, sourceFile: SourceFile, classDeclaration: ClassLikeDeclaration, changeTracker: textChanges.ChangeTracker, preferences: UserPreferences, ): void { + const checker = context.program.getTypeChecker(); const maybeHeritageClauseSymbol = getHeritageClauseSymbolTable(classDeclaration, checker); // Note that this is ultimately derived from a map indexed by symbol names, // so duplicates cannot occur. @@ -60,12 +60,12 @@ namespace ts.codefix { createMissingIndexSignatureDeclaration(implementedType, IndexKind.String); } - createMissingMemberNodes(classDeclaration, nonPrivateAndNotExistedInHeritageClauseMembers, checker, preferences, member => changeTracker.insertNodeAtClassStart(sourceFile, classDeclaration, member)); + createMissingMemberNodes(classDeclaration, nonPrivateAndNotExistedInHeritageClauseMembers, context, preferences, member => changeTracker.insertNodeAtClassStart(sourceFile, classDeclaration, member)); function createMissingIndexSignatureDeclaration(type: InterfaceType, kind: IndexKind): void { const indexInfoOfKind = checker.getIndexInfoOfType(type, kind); if (indexInfoOfKind) { - changeTracker.insertNodeAtClassStart(sourceFile, classDeclaration, checker.indexInfoToIndexSignatureDeclaration(indexInfoOfKind, kind, classDeclaration)!); + changeTracker.insertNodeAtClassStart(sourceFile, classDeclaration, checker.indexInfoToIndexSignatureDeclaration(indexInfoOfKind, kind, classDeclaration, /*flags*/ undefined, getNoopSymbolTrackerWithResolver(context))!); } } } diff --git a/src/services/codefixes/helpers.ts b/src/services/codefixes/helpers.ts index 66488d5d697..4309e6ec35d 100644 --- a/src/services/codefixes/helpers.ts +++ b/src/services/codefixes/helpers.ts @@ -6,23 +6,48 @@ namespace ts.codefix { * @param possiblyMissingSymbols The collection of symbols to filter and then get insertions for. * @returns Empty string iff there are no member insertions. */ - export function createMissingMemberNodes(classDeclaration: ClassLikeDeclaration, possiblyMissingSymbols: ReadonlyArray, checker: TypeChecker, preferences: UserPreferences, out: (node: ClassElement) => void): void { + export function createMissingMemberNodes(classDeclaration: ClassLikeDeclaration, possiblyMissingSymbols: ReadonlyArray, context: TypeConstructionContext, preferences: UserPreferences, out: (node: ClassElement) => void): void { const classMembers = classDeclaration.symbol.members!; for (const symbol of possiblyMissingSymbols) { if (!classMembers.has(symbol.escapedName)) { - addNewNodeForMemberSymbol(symbol, classDeclaration, checker, preferences, out); + addNewNodeForMemberSymbol(symbol, classDeclaration, context, preferences, out); } } } + function getModuleSpecifierResolverHost(context: TypeConstructionContext): SymbolTracker["moduleResolverHost"] { + return { + directoryExists: context.host.directoryExists ? d => context.host.directoryExists!(d) : undefined, + fileExists: context.host.fileExists ? f => context.host.fileExists!(f) : undefined, + getCurrentDirectory: context.host.getCurrentDirectory ? () => context.host.getCurrentDirectory!() : undefined, + readFile: context.host.readFile ? f => context.host.readFile!(f) : undefined, + useCaseSensitiveFileNames: context.host.useCaseSensitiveFileNames ? () => context.host.useCaseSensitiveFileNames!() : undefined, + getSourceFiles: () => context.program.getSourceFiles(), + getCommonSourceDirectory: () => context.program.getCommonSourceDirectory(), + }; + } + + export function getNoopSymbolTrackerWithResolver(context: TypeConstructionContext): SymbolTracker { + return { + trackSymbol: noop, + moduleResolverHost: getModuleSpecifierResolverHost(context), + }; + } + + export interface TypeConstructionContext { + program: Program; + host: ModuleSpecifierResolutionHost; + } + /** * @returns Empty string iff there we can't figure out a representation for `symbol` in `enclosingDeclaration`. */ - function addNewNodeForMemberSymbol(symbol: Symbol, enclosingDeclaration: ClassLikeDeclaration, checker: TypeChecker, preferences: UserPreferences, out: (node: Node) => void): void { + function addNewNodeForMemberSymbol(symbol: Symbol, enclosingDeclaration: ClassLikeDeclaration, context: TypeConstructionContext, preferences: UserPreferences, out: (node: Node) => void): void { const declarations = symbol.getDeclarations(); if (!(declarations && declarations.length)) { return undefined; } + const checker = context.program.getTypeChecker(); const declaration = declarations[0]; const name = getSynthesizedDeepClone(getNameOfDeclaration(declaration), /*includeTrivia*/ false) as PropertyName; @@ -36,7 +61,7 @@ namespace ts.codefix { case SyntaxKind.SetAccessor: case SyntaxKind.PropertySignature: case SyntaxKind.PropertyDeclaration: - const typeNode = checker.typeToTypeNode(type, enclosingDeclaration); + const typeNode = checker.typeToTypeNode(type, enclosingDeclaration, /*flags*/ undefined, getNoopSymbolTrackerWithResolver(context)); out(createProperty( /*decorators*/undefined, modifiers, @@ -83,13 +108,13 @@ namespace ts.codefix { } function outputMethod(signature: Signature, modifiers: NodeArray | undefined, name: PropertyName, body?: Block): void { - const method = signatureToMethodDeclaration(checker, signature, enclosingDeclaration, modifiers, name, optional, body); + const method = signatureToMethodDeclaration(context, signature, enclosingDeclaration, modifiers, name, optional, body); if (method) out(method); } } function signatureToMethodDeclaration( - checker: TypeChecker, + context: TypeConstructionContext, signature: Signature, enclosingDeclaration: ClassLikeDeclaration, modifiers: NodeArray | undefined, @@ -97,7 +122,8 @@ namespace ts.codefix { optional: boolean, body: Block | undefined, ): MethodDeclaration | undefined { - const signatureDeclaration = checker.signatureToSignatureDeclaration(signature, SyntaxKind.MethodDeclaration, enclosingDeclaration, NodeBuilderFlags.NoTruncation | NodeBuilderFlags.SuppressAnyReturnType); + const program = context.program; + const signatureDeclaration = program.getTypeChecker().signatureToSignatureDeclaration(signature, SyntaxKind.MethodDeclaration, enclosingDeclaration, NodeBuilderFlags.NoTruncation | NodeBuilderFlags.SuppressAnyReturnType, getNoopSymbolTrackerWithResolver(context)); if (!signatureDeclaration) { return undefined; } @@ -117,18 +143,20 @@ namespace ts.codefix { inJs: boolean, makeStatic: boolean, preferences: UserPreferences, - body: boolean, + contextNode: Node, ): MethodDeclaration { + const body = !isInterfaceDeclaration(contextNode); const { typeArguments, arguments: args, parent } = call; const checker = context.program.getTypeChecker(); + const tracker = getNoopSymbolTrackerWithResolver(context); const types = map(args, arg => // Widen the type so we don't emit nonsense annotations like "function fn(x: 3) {" - checker.typeToTypeNode(checker.getBaseTypeOfLiteralType(checker.getTypeAtLocation(arg)))); + checker.typeToTypeNode(checker.getBaseTypeOfLiteralType(checker.getTypeAtLocation(arg)), contextNode, /*flags*/ undefined, tracker)); const names = map(args, arg => isIdentifier(arg) ? arg.text : isPropertyAccessExpression(arg) ? arg.name.text : undefined); const contextualType = checker.getContextualType(call); - const returnType = inJs ? undefined : contextualType && checker.typeToTypeNode(contextualType, call) || createKeywordTypeNode(SyntaxKind.AnyKeyword); + const returnType = inJs ? undefined : contextualType && checker.typeToTypeNode(contextualType, contextNode, /*flags*/ undefined, tracker) || createKeywordTypeNode(SyntaxKind.AnyKeyword); return createMethod( /*decorators*/ undefined, /*modifiers*/ makeStatic ? [createToken(SyntaxKind.StaticKeyword)] : undefined, diff --git a/tests/cases/fourslash/codeFixClassImplementInterface_typeInOtherFile.ts b/tests/cases/fourslash/codeFixClassImplementInterface_typeInOtherFile.ts index 712bf48e059..ed5d29cd767 100644 --- a/tests/cases/fourslash/codeFixClassImplementInterface_typeInOtherFile.ts +++ b/tests/cases/fourslash/codeFixClassImplementInterface_typeInOtherFile.ts @@ -17,8 +17,8 @@ verify.codeFix({ newFileContent: `import { I } from "./I"; export class C implements I { - x: import("/I").J; - m(): import("/I").J { + x: import("./I").J; + m(): import("./I").J { throw new Error("Method not implemented."); } }`, diff --git a/tests/cases/fourslash/codeFixUndeclaredAcrossFiles3.ts b/tests/cases/fourslash/codeFixUndeclaredAcrossFiles3.ts index 2b07493f923..dcf5c999d6a 100644 --- a/tests/cases/fourslash/codeFixUndeclaredAcrossFiles3.ts +++ b/tests/cases/fourslash/codeFixUndeclaredAcrossFiles3.ts @@ -20,7 +20,7 @@ verify.getAndApplyCodeFix(/*errorCode*/ undefined, 0); verify.rangeIs(` - m0(arg0: D): any { + m0(arg0: import("./f2").D): any { throw new Error("Method not implemented."); } `); \ No newline at end of file diff --git a/tests/cases/fourslash/quickfixImplementInterfaceUnreachableTypeUsesRelativeImport.ts b/tests/cases/fourslash/quickfixImplementInterfaceUnreachableTypeUsesRelativeImport.ts new file mode 100644 index 00000000000..ba6cd702ea0 --- /dev/null +++ b/tests/cases/fourslash/quickfixImplementInterfaceUnreachableTypeUsesRelativeImport.ts @@ -0,0 +1,26 @@ +/// + +// @Filename: class.ts +////export class Class { } +// @Filename: interface.ts +////import { Class } from './class'; +//// +////export interface Foo { +//// x: Class; +////} +// @Filename: index.ts +////import { Foo } from './interface'; +//// +////class /*1*/X implements Foo {} +goTo.marker("1"); +verify.codeFix({ + index: 0, + description: "Implement interface 'Foo'", + newFileContent: { + "/tests/cases/fourslash/index.ts": `import { Foo } from './interface'; + +class X implements Foo { + x: import("./class").Class; +}` + } +}); From 6e54cbdaff4d988a8bad6e63af8d91a1330b354b Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 14 Jan 2019 15:09:34 -0800 Subject: [PATCH 89/96] Handle generating action for export equals with anonymous symbol Fixes #28845 --- src/services/completions.ts | 4 ++- ...ompletionsImport_exportEquals_anonymous.ts | 28 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/completionsImport_exportEquals_anonymous.ts diff --git a/src/services/completions.ts b/src/services/completions.ts index 8203b66549b..f17ee862cca 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -367,7 +367,9 @@ namespace ts.Completions { } function getSymbolName(symbol: Symbol, origin: SymbolOriginInfo | undefined, target: ScriptTarget): string { - return origin && originIsExport(origin) && origin.isDefaultExport && symbol.escapedName === InternalSymbolName.Default + return origin && originIsExport(origin) && ( + (origin.isDefaultExport && symbol.escapedName === InternalSymbolName.Default) || + (symbol.escapedName === InternalSymbolName.ExportEquals)) // Name of "export default foo;" is "foo". Name of "export default 0" is the filename converted to camelCase. ? firstDefined(symbol.declarations, d => isExportAssignment(d) && isIdentifier(d.expression) ? d.expression.text : undefined) || codefix.moduleSymbolToValidIdentifier(origin.moduleSymbol, target) diff --git a/tests/cases/fourslash/completionsImport_exportEquals_anonymous.ts b/tests/cases/fourslash/completionsImport_exportEquals_anonymous.ts new file mode 100644 index 00000000000..c5e87877cfb --- /dev/null +++ b/tests/cases/fourslash/completionsImport_exportEquals_anonymous.ts @@ -0,0 +1,28 @@ +/// + +// Use `/src` to test that directory names are not included in conversion from module path to identifier. +// @noLib: true + +// @Filename: /src/foo-bar.ts +////export = 0; + +// @Filename: /src/b.ts +////exp/*0*/ +////fooB/*1*/ + +goTo.marker("0"); +const preferences: FourSlashInterface.UserPreferences = { includeCompletionsForModuleExports: true }; +const exportEntry: FourSlashInterface.ExpectedCompletionEntryObject = { name: "fooBar", source: "/src/foo-bar", sourceDisplay: "./foo-bar", text: "(property) export=: 0", kind: "property", hasAction: true }; +verify.completions( + { marker: "0", exact: ["undefined", exportEntry, ...completion.statementKeywordsWithTypes], preferences }, + { marker: "1", includes: exportEntry, preferences } +); +verify.applyCodeActionFromCompletion("0", { + name: "fooBar", + source: "/src/foo-bar", + description: `Import 'fooBar' from module "./foo-bar"`, + newFileContent: `import fooBar = require("./foo-bar"); + +exp +fooB`, +}); \ No newline at end of file From 2c50ed30890c46d2671894eda21dbf2882166e0a Mon Sep 17 00:00:00 2001 From: Benjamin Lichtman Date: Mon, 14 Jan 2019 17:05:25 -0800 Subject: [PATCH 90/96] Respond to CR --- src/harness/fourslash.ts | 9 ++++----- src/services/rename.ts | 6 +++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index fd11236501d..1276de7de44 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -1308,9 +1308,8 @@ Actual: ${stringify(fullActual)}`); } } - public verifyRenameInfoSucceeded(displayName: string | undefined, fullDisplayName: string | undefined, kind: string | undefined, kindModifiers: string | undefined, fileToRename: string | undefined, expectedRange: Range | undefined, allowRenameOfImportPath: boolean | undefined): void { - allowRenameOfImportPath = allowRenameOfImportPath === undefined ? true : allowRenameOfImportPath; - const renameInfo = this.languageService.getRenameInfo(this.activeFile.fileName, this.currentCaretPosition, { allowRenameOfImportPath }); + public verifyRenameInfoSucceeded(displayName: string | undefined, fullDisplayName: string | undefined, kind: string | undefined, kindModifiers: string | undefined, fileToRename: string | undefined, expectedRange: Range | undefined, renameInfoOptions: ts.RenameInfoOptions | undefined): void { + const renameInfo = this.languageService.getRenameInfo(this.activeFile.fileName, this.currentCaretPosition, renameInfoOptions || { allowRenameOfImportPath: true }); if (!renameInfo.canRename) { throw this.raiseError("Rename did not succeed"); } @@ -4093,8 +4092,8 @@ namespace FourSlashInterface { this.state.verifySemanticClassifications(classifications); } - public renameInfoSucceeded(displayName?: string, fullDisplayName?: string, kind?: string, kindModifiers?: string, fileToRename?: string, expectedRange?: FourSlash.Range, allowRenameOfImportPath?: boolean) { - this.state.verifyRenameInfoSucceeded(displayName, fullDisplayName, kind, kindModifiers, fileToRename, expectedRange, allowRenameOfImportPath); + public renameInfoSucceeded(displayName?: string, fullDisplayName?: string, kind?: string, kindModifiers?: string, fileToRename?: string, expectedRange?: FourSlash.Range, options?: ts.RenameInfoOptions) { + this.state.verifyRenameInfoSucceeded(displayName, fullDisplayName, kind, kindModifiers, fileToRename, expectedRange, options); } public renameInfoFailed(message?: string, allowRenameOfImportPath?: boolean) { diff --git a/src/services/rename.ts b/src/services/rename.ts index cef53d251ed..484349acc86 100644 --- a/src/services/rename.ts +++ b/src/services/rename.ts @@ -3,12 +3,12 @@ namespace ts.Rename { export function getRenameInfo(program: Program, sourceFile: SourceFile, position: number, options?: RenameInfoOptions): RenameInfo { const node = getTouchingPropertyName(sourceFile, position); const renameInfo = node && nodeIsEligibleForRename(node) - ? getRenameInfoForNode(node, program.getTypeChecker(), sourceFile, options || {}, declaration => program.isSourceFileDefaultLibrary(declaration.getSourceFile())) + ? getRenameInfoForNode(node, program.getTypeChecker(), sourceFile, declaration => program.isSourceFileDefaultLibrary(declaration.getSourceFile()), options) : undefined; return renameInfo || getRenameInfoError(Diagnostics.You_cannot_rename_this_element); } - function getRenameInfoForNode(node: Node, typeChecker: TypeChecker, sourceFile: SourceFile, options: RenameInfoOptions, isDefinedInLibraryFile: (declaration: Node) => boolean): RenameInfo | undefined { + function getRenameInfoForNode(node: Node, typeChecker: TypeChecker, sourceFile: SourceFile, isDefinedInLibraryFile: (declaration: Node) => boolean, options?: RenameInfoOptions): RenameInfo | undefined { const symbol = typeChecker.getSymbolAtLocation(node); if (!symbol) return; // Only allow a symbol to be renamed if it actually has at least one declaration. @@ -26,7 +26,7 @@ namespace ts.Rename { } if (isStringLiteralLike(node) && tryGetImportFromModuleSpecifier(node)) { - return options.allowRenameOfImportPath ? getRenameInfoForModule(node, sourceFile, symbol) : undefined; + return options && options.allowRenameOfImportPath ? getRenameInfoForModule(node, sourceFile, symbol) : undefined; } const kind = SymbolDisplay.getSymbolKind(typeChecker, symbol, node); From 5763e2c3d436d516e1e2932ed16a61705ae15a69 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Mon, 14 Jan 2019 17:08:04 -0800 Subject: [PATCH 91/96] Remove overzealous simple relationship check for unique symbols --- src/compiler/checker.ts | 1 - tests/baselines/reference/uniqueSymbols.js | 7 + .../baselines/reference/uniqueSymbols.symbols | 797 +++++++++--------- tests/baselines/reference/uniqueSymbols.types | 7 + .../types/uniqueSymbol/uniqueSymbols.ts | 4 + 5 files changed, 419 insertions(+), 397 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b48ba6bbcd6..f365af51ac6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11667,7 +11667,6 @@ namespace ts { if (s & TypeFlags.Undefined && (!strictNullChecks || t & (TypeFlags.Undefined | TypeFlags.Void))) return true; if (s & TypeFlags.Null && (!strictNullChecks || t & TypeFlags.Null)) return true; if (s & TypeFlags.Object && t & TypeFlags.NonPrimitive) return true; - if (s & TypeFlags.UniqueESSymbol || t & TypeFlags.UniqueESSymbol) return false; if (relation === assignableRelation || relation === comparableRelation) { if (s & TypeFlags.Any) return true; // Type number or any numeric literal type is assignable to any numeric enum type or any diff --git a/tests/baselines/reference/uniqueSymbols.js b/tests/baselines/reference/uniqueSymbols.js index 0e6bde4fe47..54f59e8e217 100644 --- a/tests/baselines/reference/uniqueSymbols.js +++ b/tests/baselines/reference/uniqueSymbols.js @@ -28,6 +28,10 @@ var varInitToConstDeclAmbient = constType; const constInitToConstCallWithTypeQuery: typeof constCall = constCall; const constInitToConstDeclAmbientWithTypeQuery: typeof constType = constType; +// assignment from any +// https://github.com/Microsoft/TypeScript/issues/29108 +const fromAny: unique symbol = {} as any; + // function return inference function funcReturnConstCall() { return constCall; } function funcReturnLetCall() { return letCall; } @@ -286,6 +290,9 @@ var varInitToConstDeclAmbient = constType; // declaration from initializer with type query const constInitToConstCallWithTypeQuery = constCall; const constInitToConstDeclAmbientWithTypeQuery = constType; +// assignment from any +// https://github.com/Microsoft/TypeScript/issues/29108 +const fromAny = {}; // function return inference function funcReturnConstCall() { return constCall; } function funcReturnLetCall() { return letCall; } diff --git a/tests/baselines/reference/uniqueSymbols.symbols b/tests/baselines/reference/uniqueSymbols.symbols index 6fef1873082..d7da3595a59 100644 --- a/tests/baselines/reference/uniqueSymbols.symbols +++ b/tests/baselines/reference/uniqueSymbols.symbols @@ -81,717 +81,722 @@ const constInitToConstDeclAmbientWithTypeQuery: typeof constType = constType; >constType : Symbol(constType, Decl(uniqueSymbols.ts, 6, 13)) >constType : Symbol(constType, Decl(uniqueSymbols.ts, 6, 13)) +// assignment from any +// https://github.com/Microsoft/TypeScript/issues/29108 +const fromAny: unique symbol = {} as any; +>fromAny : Symbol(fromAny, Decl(uniqueSymbols.ts, 31, 5)) + // function return inference function funcReturnConstCall() { return constCall; } ->funcReturnConstCall : Symbol(funcReturnConstCall, Decl(uniqueSymbols.ts, 27, 77)) +>funcReturnConstCall : Symbol(funcReturnConstCall, Decl(uniqueSymbols.ts, 31, 41)) >constCall : Symbol(constCall, Decl(uniqueSymbols.ts, 1, 5)) function funcReturnLetCall() { return letCall; } ->funcReturnLetCall : Symbol(funcReturnLetCall, Decl(uniqueSymbols.ts, 30, 52)) +>funcReturnLetCall : Symbol(funcReturnLetCall, Decl(uniqueSymbols.ts, 34, 52)) >letCall : Symbol(letCall, Decl(uniqueSymbols.ts, 2, 3)) function funcReturnVarCall() { return varCall; } ->funcReturnVarCall : Symbol(funcReturnVarCall, Decl(uniqueSymbols.ts, 31, 48)) +>funcReturnVarCall : Symbol(funcReturnVarCall, Decl(uniqueSymbols.ts, 35, 48)) >varCall : Symbol(varCall, Decl(uniqueSymbols.ts, 3, 3)) // function return value with type query function funcReturnConstCallWithTypeQuery(): typeof constCall { return constCall; } ->funcReturnConstCallWithTypeQuery : Symbol(funcReturnConstCallWithTypeQuery, Decl(uniqueSymbols.ts, 32, 48)) +>funcReturnConstCallWithTypeQuery : Symbol(funcReturnConstCallWithTypeQuery, Decl(uniqueSymbols.ts, 36, 48)) >constCall : Symbol(constCall, Decl(uniqueSymbols.ts, 1, 5)) >constCall : Symbol(constCall, Decl(uniqueSymbols.ts, 1, 5)) // generator function yield inference function* genFuncYieldConstCall() { yield constCall; } ->genFuncYieldConstCall : Symbol(genFuncYieldConstCall, Decl(uniqueSymbols.ts, 35, 83)) +>genFuncYieldConstCall : Symbol(genFuncYieldConstCall, Decl(uniqueSymbols.ts, 39, 83)) >constCall : Symbol(constCall, Decl(uniqueSymbols.ts, 1, 5)) function* genFuncYieldLetCall() { yield letCall; } ->genFuncYieldLetCall : Symbol(genFuncYieldLetCall, Decl(uniqueSymbols.ts, 38, 54)) +>genFuncYieldLetCall : Symbol(genFuncYieldLetCall, Decl(uniqueSymbols.ts, 42, 54)) >letCall : Symbol(letCall, Decl(uniqueSymbols.ts, 2, 3)) function* genFuncYieldVarCall() { yield varCall; } ->genFuncYieldVarCall : Symbol(genFuncYieldVarCall, Decl(uniqueSymbols.ts, 39, 50)) +>genFuncYieldVarCall : Symbol(genFuncYieldVarCall, Decl(uniqueSymbols.ts, 43, 50)) >varCall : Symbol(varCall, Decl(uniqueSymbols.ts, 3, 3)) // generator function yield with return type query function* genFuncYieldConstCallWithTypeQuery(): IterableIterator { yield constCall; } ->genFuncYieldConstCallWithTypeQuery : Symbol(genFuncYieldConstCallWithTypeQuery, Decl(uniqueSymbols.ts, 40, 50)) +>genFuncYieldConstCallWithTypeQuery : Symbol(genFuncYieldConstCallWithTypeQuery, Decl(uniqueSymbols.ts, 44, 50)) >IterableIterator : Symbol(IterableIterator, Decl(lib.es2015.iterable.d.ts, --, --)) >constCall : Symbol(constCall, Decl(uniqueSymbols.ts, 1, 5)) >constCall : Symbol(constCall, Decl(uniqueSymbols.ts, 1, 5)) // async function return inference async function asyncFuncReturnConstCall() { return constCall; } ->asyncFuncReturnConstCall : Symbol(asyncFuncReturnConstCall, Decl(uniqueSymbols.ts, 43, 103)) +>asyncFuncReturnConstCall : Symbol(asyncFuncReturnConstCall, Decl(uniqueSymbols.ts, 47, 103)) >constCall : Symbol(constCall, Decl(uniqueSymbols.ts, 1, 5)) async function asyncFuncReturnLetCall() { return letCall; } ->asyncFuncReturnLetCall : Symbol(asyncFuncReturnLetCall, Decl(uniqueSymbols.ts, 46, 63)) +>asyncFuncReturnLetCall : Symbol(asyncFuncReturnLetCall, Decl(uniqueSymbols.ts, 50, 63)) >letCall : Symbol(letCall, Decl(uniqueSymbols.ts, 2, 3)) async function asyncFuncReturnVarCall() { return varCall; } ->asyncFuncReturnVarCall : Symbol(asyncFuncReturnVarCall, Decl(uniqueSymbols.ts, 47, 59)) +>asyncFuncReturnVarCall : Symbol(asyncFuncReturnVarCall, Decl(uniqueSymbols.ts, 51, 59)) >varCall : Symbol(varCall, Decl(uniqueSymbols.ts, 3, 3)) // async generator function yield inference async function* asyncGenFuncYieldConstCall() { yield constCall; } ->asyncGenFuncYieldConstCall : Symbol(asyncGenFuncYieldConstCall, Decl(uniqueSymbols.ts, 48, 59)) +>asyncGenFuncYieldConstCall : Symbol(asyncGenFuncYieldConstCall, Decl(uniqueSymbols.ts, 52, 59)) >constCall : Symbol(constCall, Decl(uniqueSymbols.ts, 1, 5)) async function* asyncGenFuncYieldLetCall() { yield letCall; } ->asyncGenFuncYieldLetCall : Symbol(asyncGenFuncYieldLetCall, Decl(uniqueSymbols.ts, 51, 65)) +>asyncGenFuncYieldLetCall : Symbol(asyncGenFuncYieldLetCall, Decl(uniqueSymbols.ts, 55, 65)) >letCall : Symbol(letCall, Decl(uniqueSymbols.ts, 2, 3)) async function* asyncGenFuncYieldVarCall() { yield varCall; } ->asyncGenFuncYieldVarCall : Symbol(asyncGenFuncYieldVarCall, Decl(uniqueSymbols.ts, 52, 61)) +>asyncGenFuncYieldVarCall : Symbol(asyncGenFuncYieldVarCall, Decl(uniqueSymbols.ts, 56, 61)) >varCall : Symbol(varCall, Decl(uniqueSymbols.ts, 3, 3)) // classes class C { ->C : Symbol(C, Decl(uniqueSymbols.ts, 53, 61)) +>C : Symbol(C, Decl(uniqueSymbols.ts, 57, 61)) static readonly readonlyStaticCall = Symbol(); ->readonlyStaticCall : Symbol(C.readonlyStaticCall, Decl(uniqueSymbols.ts, 56, 9)) +>readonlyStaticCall : Symbol(C.readonlyStaticCall, Decl(uniqueSymbols.ts, 60, 9)) >Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.esnext.symbol.d.ts, --, --)) static readonly readonlyStaticType: unique symbol; ->readonlyStaticType : Symbol(C.readonlyStaticType, Decl(uniqueSymbols.ts, 57, 50)) +>readonlyStaticType : Symbol(C.readonlyStaticType, Decl(uniqueSymbols.ts, 61, 50)) static readonly readonlyStaticTypeAndCall: unique symbol = Symbol(); ->readonlyStaticTypeAndCall : Symbol(C.readonlyStaticTypeAndCall, Decl(uniqueSymbols.ts, 58, 54)) +>readonlyStaticTypeAndCall : Symbol(C.readonlyStaticTypeAndCall, Decl(uniqueSymbols.ts, 62, 54)) >Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.esnext.symbol.d.ts, --, --)) static readwriteStaticCall = Symbol(); ->readwriteStaticCall : Symbol(C.readwriteStaticCall, Decl(uniqueSymbols.ts, 59, 72)) +>readwriteStaticCall : Symbol(C.readwriteStaticCall, Decl(uniqueSymbols.ts, 63, 72)) >Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.esnext.symbol.d.ts, --, --)) readonly readonlyCall = Symbol(); ->readonlyCall : Symbol(C.readonlyCall, Decl(uniqueSymbols.ts, 60, 42)) +>readonlyCall : Symbol(C.readonlyCall, Decl(uniqueSymbols.ts, 64, 42)) >Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.esnext.symbol.d.ts, --, --)) readwriteCall = Symbol(); ->readwriteCall : Symbol(C.readwriteCall, Decl(uniqueSymbols.ts, 62, 37)) +>readwriteCall : Symbol(C.readwriteCall, Decl(uniqueSymbols.ts, 66, 37)) >Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.esnext.symbol.d.ts, --, --)) } declare const c: C; ->c : Symbol(c, Decl(uniqueSymbols.ts, 65, 13)) ->C : Symbol(C, Decl(uniqueSymbols.ts, 53, 61)) +>c : Symbol(c, Decl(uniqueSymbols.ts, 69, 13)) +>C : Symbol(C, Decl(uniqueSymbols.ts, 57, 61)) const constInitToCReadonlyStaticCall = C.readonlyStaticCall; ->constInitToCReadonlyStaticCall : Symbol(constInitToCReadonlyStaticCall, Decl(uniqueSymbols.ts, 67, 5)) ->C.readonlyStaticCall : Symbol(C.readonlyStaticCall, Decl(uniqueSymbols.ts, 56, 9)) ->C : Symbol(C, Decl(uniqueSymbols.ts, 53, 61)) ->readonlyStaticCall : Symbol(C.readonlyStaticCall, Decl(uniqueSymbols.ts, 56, 9)) +>constInitToCReadonlyStaticCall : Symbol(constInitToCReadonlyStaticCall, Decl(uniqueSymbols.ts, 71, 5)) +>C.readonlyStaticCall : Symbol(C.readonlyStaticCall, Decl(uniqueSymbols.ts, 60, 9)) +>C : Symbol(C, Decl(uniqueSymbols.ts, 57, 61)) +>readonlyStaticCall : Symbol(C.readonlyStaticCall, Decl(uniqueSymbols.ts, 60, 9)) const constInitToCReadonlyStaticType = C.readonlyStaticType; ->constInitToCReadonlyStaticType : Symbol(constInitToCReadonlyStaticType, Decl(uniqueSymbols.ts, 68, 5)) ->C.readonlyStaticType : Symbol(C.readonlyStaticType, Decl(uniqueSymbols.ts, 57, 50)) ->C : Symbol(C, Decl(uniqueSymbols.ts, 53, 61)) ->readonlyStaticType : Symbol(C.readonlyStaticType, Decl(uniqueSymbols.ts, 57, 50)) +>constInitToCReadonlyStaticType : Symbol(constInitToCReadonlyStaticType, Decl(uniqueSymbols.ts, 72, 5)) +>C.readonlyStaticType : Symbol(C.readonlyStaticType, Decl(uniqueSymbols.ts, 61, 50)) +>C : Symbol(C, Decl(uniqueSymbols.ts, 57, 61)) +>readonlyStaticType : Symbol(C.readonlyStaticType, Decl(uniqueSymbols.ts, 61, 50)) const constInitToCReadonlyStaticTypeAndCall = C.readonlyStaticTypeAndCall; ->constInitToCReadonlyStaticTypeAndCall : Symbol(constInitToCReadonlyStaticTypeAndCall, Decl(uniqueSymbols.ts, 69, 5)) ->C.readonlyStaticTypeAndCall : Symbol(C.readonlyStaticTypeAndCall, Decl(uniqueSymbols.ts, 58, 54)) ->C : Symbol(C, Decl(uniqueSymbols.ts, 53, 61)) ->readonlyStaticTypeAndCall : Symbol(C.readonlyStaticTypeAndCall, Decl(uniqueSymbols.ts, 58, 54)) +>constInitToCReadonlyStaticTypeAndCall : Symbol(constInitToCReadonlyStaticTypeAndCall, Decl(uniqueSymbols.ts, 73, 5)) +>C.readonlyStaticTypeAndCall : Symbol(C.readonlyStaticTypeAndCall, Decl(uniqueSymbols.ts, 62, 54)) +>C : Symbol(C, Decl(uniqueSymbols.ts, 57, 61)) +>readonlyStaticTypeAndCall : Symbol(C.readonlyStaticTypeAndCall, Decl(uniqueSymbols.ts, 62, 54)) const constInitToCReadwriteStaticCall = C.readwriteStaticCall; ->constInitToCReadwriteStaticCall : Symbol(constInitToCReadwriteStaticCall, Decl(uniqueSymbols.ts, 70, 5)) ->C.readwriteStaticCall : Symbol(C.readwriteStaticCall, Decl(uniqueSymbols.ts, 59, 72)) ->C : Symbol(C, Decl(uniqueSymbols.ts, 53, 61)) ->readwriteStaticCall : Symbol(C.readwriteStaticCall, Decl(uniqueSymbols.ts, 59, 72)) +>constInitToCReadwriteStaticCall : Symbol(constInitToCReadwriteStaticCall, Decl(uniqueSymbols.ts, 74, 5)) +>C.readwriteStaticCall : Symbol(C.readwriteStaticCall, Decl(uniqueSymbols.ts, 63, 72)) +>C : Symbol(C, Decl(uniqueSymbols.ts, 57, 61)) +>readwriteStaticCall : Symbol(C.readwriteStaticCall, Decl(uniqueSymbols.ts, 63, 72)) const constInitToCReadonlyStaticCallWithTypeQuery: typeof C.readonlyStaticCall = C.readonlyStaticCall; ->constInitToCReadonlyStaticCallWithTypeQuery : Symbol(constInitToCReadonlyStaticCallWithTypeQuery, Decl(uniqueSymbols.ts, 72, 5)) ->C.readonlyStaticCall : Symbol(C.readonlyStaticCall, Decl(uniqueSymbols.ts, 56, 9)) ->C : Symbol(C, Decl(uniqueSymbols.ts, 53, 61)) ->readonlyStaticCall : Symbol(C.readonlyStaticCall, Decl(uniqueSymbols.ts, 56, 9)) ->C.readonlyStaticCall : Symbol(C.readonlyStaticCall, Decl(uniqueSymbols.ts, 56, 9)) ->C : Symbol(C, Decl(uniqueSymbols.ts, 53, 61)) ->readonlyStaticCall : Symbol(C.readonlyStaticCall, Decl(uniqueSymbols.ts, 56, 9)) +>constInitToCReadonlyStaticCallWithTypeQuery : Symbol(constInitToCReadonlyStaticCallWithTypeQuery, Decl(uniqueSymbols.ts, 76, 5)) +>C.readonlyStaticCall : Symbol(C.readonlyStaticCall, Decl(uniqueSymbols.ts, 60, 9)) +>C : Symbol(C, Decl(uniqueSymbols.ts, 57, 61)) +>readonlyStaticCall : Symbol(C.readonlyStaticCall, Decl(uniqueSymbols.ts, 60, 9)) +>C.readonlyStaticCall : Symbol(C.readonlyStaticCall, Decl(uniqueSymbols.ts, 60, 9)) +>C : Symbol(C, Decl(uniqueSymbols.ts, 57, 61)) +>readonlyStaticCall : Symbol(C.readonlyStaticCall, Decl(uniqueSymbols.ts, 60, 9)) const constInitToCReadonlyStaticTypeWithTypeQuery: typeof C.readonlyStaticType = C.readonlyStaticType; ->constInitToCReadonlyStaticTypeWithTypeQuery : Symbol(constInitToCReadonlyStaticTypeWithTypeQuery, Decl(uniqueSymbols.ts, 73, 5)) ->C.readonlyStaticType : Symbol(C.readonlyStaticType, Decl(uniqueSymbols.ts, 57, 50)) ->C : Symbol(C, Decl(uniqueSymbols.ts, 53, 61)) ->readonlyStaticType : Symbol(C.readonlyStaticType, Decl(uniqueSymbols.ts, 57, 50)) ->C.readonlyStaticType : Symbol(C.readonlyStaticType, Decl(uniqueSymbols.ts, 57, 50)) ->C : Symbol(C, Decl(uniqueSymbols.ts, 53, 61)) ->readonlyStaticType : Symbol(C.readonlyStaticType, Decl(uniqueSymbols.ts, 57, 50)) +>constInitToCReadonlyStaticTypeWithTypeQuery : Symbol(constInitToCReadonlyStaticTypeWithTypeQuery, Decl(uniqueSymbols.ts, 77, 5)) +>C.readonlyStaticType : Symbol(C.readonlyStaticType, Decl(uniqueSymbols.ts, 61, 50)) +>C : Symbol(C, Decl(uniqueSymbols.ts, 57, 61)) +>readonlyStaticType : Symbol(C.readonlyStaticType, Decl(uniqueSymbols.ts, 61, 50)) +>C.readonlyStaticType : Symbol(C.readonlyStaticType, Decl(uniqueSymbols.ts, 61, 50)) +>C : Symbol(C, Decl(uniqueSymbols.ts, 57, 61)) +>readonlyStaticType : Symbol(C.readonlyStaticType, Decl(uniqueSymbols.ts, 61, 50)) const constInitToCReadonlyStaticTypeAndCallWithTypeQuery: typeof C.readonlyStaticTypeAndCall = C.readonlyStaticTypeAndCall; ->constInitToCReadonlyStaticTypeAndCallWithTypeQuery : Symbol(constInitToCReadonlyStaticTypeAndCallWithTypeQuery, Decl(uniqueSymbols.ts, 74, 5)) ->C.readonlyStaticTypeAndCall : Symbol(C.readonlyStaticTypeAndCall, Decl(uniqueSymbols.ts, 58, 54)) ->C : Symbol(C, Decl(uniqueSymbols.ts, 53, 61)) ->readonlyStaticTypeAndCall : Symbol(C.readonlyStaticTypeAndCall, Decl(uniqueSymbols.ts, 58, 54)) ->C.readonlyStaticTypeAndCall : Symbol(C.readonlyStaticTypeAndCall, Decl(uniqueSymbols.ts, 58, 54)) ->C : Symbol(C, Decl(uniqueSymbols.ts, 53, 61)) ->readonlyStaticTypeAndCall : Symbol(C.readonlyStaticTypeAndCall, Decl(uniqueSymbols.ts, 58, 54)) +>constInitToCReadonlyStaticTypeAndCallWithTypeQuery : Symbol(constInitToCReadonlyStaticTypeAndCallWithTypeQuery, Decl(uniqueSymbols.ts, 78, 5)) +>C.readonlyStaticTypeAndCall : Symbol(C.readonlyStaticTypeAndCall, Decl(uniqueSymbols.ts, 62, 54)) +>C : Symbol(C, Decl(uniqueSymbols.ts, 57, 61)) +>readonlyStaticTypeAndCall : Symbol(C.readonlyStaticTypeAndCall, Decl(uniqueSymbols.ts, 62, 54)) +>C.readonlyStaticTypeAndCall : Symbol(C.readonlyStaticTypeAndCall, Decl(uniqueSymbols.ts, 62, 54)) +>C : Symbol(C, Decl(uniqueSymbols.ts, 57, 61)) +>readonlyStaticTypeAndCall : Symbol(C.readonlyStaticTypeAndCall, Decl(uniqueSymbols.ts, 62, 54)) const constInitToCReadwriteStaticCallWithTypeQuery: typeof C.readwriteStaticCall = C.readwriteStaticCall; ->constInitToCReadwriteStaticCallWithTypeQuery : Symbol(constInitToCReadwriteStaticCallWithTypeQuery, Decl(uniqueSymbols.ts, 75, 5)) ->C.readwriteStaticCall : Symbol(C.readwriteStaticCall, Decl(uniqueSymbols.ts, 59, 72)) ->C : Symbol(C, Decl(uniqueSymbols.ts, 53, 61)) ->readwriteStaticCall : Symbol(C.readwriteStaticCall, Decl(uniqueSymbols.ts, 59, 72)) ->C.readwriteStaticCall : Symbol(C.readwriteStaticCall, Decl(uniqueSymbols.ts, 59, 72)) ->C : Symbol(C, Decl(uniqueSymbols.ts, 53, 61)) ->readwriteStaticCall : Symbol(C.readwriteStaticCall, Decl(uniqueSymbols.ts, 59, 72)) +>constInitToCReadwriteStaticCallWithTypeQuery : Symbol(constInitToCReadwriteStaticCallWithTypeQuery, Decl(uniqueSymbols.ts, 79, 5)) +>C.readwriteStaticCall : Symbol(C.readwriteStaticCall, Decl(uniqueSymbols.ts, 63, 72)) +>C : Symbol(C, Decl(uniqueSymbols.ts, 57, 61)) +>readwriteStaticCall : Symbol(C.readwriteStaticCall, Decl(uniqueSymbols.ts, 63, 72)) +>C.readwriteStaticCall : Symbol(C.readwriteStaticCall, Decl(uniqueSymbols.ts, 63, 72)) +>C : Symbol(C, Decl(uniqueSymbols.ts, 57, 61)) +>readwriteStaticCall : Symbol(C.readwriteStaticCall, Decl(uniqueSymbols.ts, 63, 72)) const constInitToCReadonlyCall = c.readonlyCall; ->constInitToCReadonlyCall : Symbol(constInitToCReadonlyCall, Decl(uniqueSymbols.ts, 77, 5)) ->c.readonlyCall : Symbol(C.readonlyCall, Decl(uniqueSymbols.ts, 60, 42)) ->c : Symbol(c, Decl(uniqueSymbols.ts, 65, 13)) ->readonlyCall : Symbol(C.readonlyCall, Decl(uniqueSymbols.ts, 60, 42)) +>constInitToCReadonlyCall : Symbol(constInitToCReadonlyCall, Decl(uniqueSymbols.ts, 81, 5)) +>c.readonlyCall : Symbol(C.readonlyCall, Decl(uniqueSymbols.ts, 64, 42)) +>c : Symbol(c, Decl(uniqueSymbols.ts, 69, 13)) +>readonlyCall : Symbol(C.readonlyCall, Decl(uniqueSymbols.ts, 64, 42)) const constInitToCReadwriteCall = c.readwriteCall; ->constInitToCReadwriteCall : Symbol(constInitToCReadwriteCall, Decl(uniqueSymbols.ts, 78, 5)) ->c.readwriteCall : Symbol(C.readwriteCall, Decl(uniqueSymbols.ts, 62, 37)) ->c : Symbol(c, Decl(uniqueSymbols.ts, 65, 13)) ->readwriteCall : Symbol(C.readwriteCall, Decl(uniqueSymbols.ts, 62, 37)) +>constInitToCReadwriteCall : Symbol(constInitToCReadwriteCall, Decl(uniqueSymbols.ts, 82, 5)) +>c.readwriteCall : Symbol(C.readwriteCall, Decl(uniqueSymbols.ts, 66, 37)) +>c : Symbol(c, Decl(uniqueSymbols.ts, 69, 13)) +>readwriteCall : Symbol(C.readwriteCall, Decl(uniqueSymbols.ts, 66, 37)) const constInitToCReadonlyCallWithTypeQuery: typeof c.readonlyCall = c.readonlyCall; ->constInitToCReadonlyCallWithTypeQuery : Symbol(constInitToCReadonlyCallWithTypeQuery, Decl(uniqueSymbols.ts, 79, 5)) ->c.readonlyCall : Symbol(C.readonlyCall, Decl(uniqueSymbols.ts, 60, 42)) ->c : Symbol(c, Decl(uniqueSymbols.ts, 65, 13)) ->readonlyCall : Symbol(C.readonlyCall, Decl(uniqueSymbols.ts, 60, 42)) ->c.readonlyCall : Symbol(C.readonlyCall, Decl(uniqueSymbols.ts, 60, 42)) ->c : Symbol(c, Decl(uniqueSymbols.ts, 65, 13)) ->readonlyCall : Symbol(C.readonlyCall, Decl(uniqueSymbols.ts, 60, 42)) +>constInitToCReadonlyCallWithTypeQuery : Symbol(constInitToCReadonlyCallWithTypeQuery, Decl(uniqueSymbols.ts, 83, 5)) +>c.readonlyCall : Symbol(C.readonlyCall, Decl(uniqueSymbols.ts, 64, 42)) +>c : Symbol(c, Decl(uniqueSymbols.ts, 69, 13)) +>readonlyCall : Symbol(C.readonlyCall, Decl(uniqueSymbols.ts, 64, 42)) +>c.readonlyCall : Symbol(C.readonlyCall, Decl(uniqueSymbols.ts, 64, 42)) +>c : Symbol(c, Decl(uniqueSymbols.ts, 69, 13)) +>readonlyCall : Symbol(C.readonlyCall, Decl(uniqueSymbols.ts, 64, 42)) const constInitToCReadwriteCallWithTypeQuery: typeof c.readwriteCall = c.readwriteCall; ->constInitToCReadwriteCallWithTypeQuery : Symbol(constInitToCReadwriteCallWithTypeQuery, Decl(uniqueSymbols.ts, 80, 5)) ->c.readwriteCall : Symbol(C.readwriteCall, Decl(uniqueSymbols.ts, 62, 37)) ->c : Symbol(c, Decl(uniqueSymbols.ts, 65, 13)) ->readwriteCall : Symbol(C.readwriteCall, Decl(uniqueSymbols.ts, 62, 37)) ->c.readwriteCall : Symbol(C.readwriteCall, Decl(uniqueSymbols.ts, 62, 37)) ->c : Symbol(c, Decl(uniqueSymbols.ts, 65, 13)) ->readwriteCall : Symbol(C.readwriteCall, Decl(uniqueSymbols.ts, 62, 37)) +>constInitToCReadwriteCallWithTypeQuery : Symbol(constInitToCReadwriteCallWithTypeQuery, Decl(uniqueSymbols.ts, 84, 5)) +>c.readwriteCall : Symbol(C.readwriteCall, Decl(uniqueSymbols.ts, 66, 37)) +>c : Symbol(c, Decl(uniqueSymbols.ts, 69, 13)) +>readwriteCall : Symbol(C.readwriteCall, Decl(uniqueSymbols.ts, 66, 37)) +>c.readwriteCall : Symbol(C.readwriteCall, Decl(uniqueSymbols.ts, 66, 37)) +>c : Symbol(c, Decl(uniqueSymbols.ts, 69, 13)) +>readwriteCall : Symbol(C.readwriteCall, Decl(uniqueSymbols.ts, 66, 37)) const constInitToCReadonlyCallWithIndexedAccess: C["readonlyCall"] = c.readonlyCall; ->constInitToCReadonlyCallWithIndexedAccess : Symbol(constInitToCReadonlyCallWithIndexedAccess, Decl(uniqueSymbols.ts, 81, 5)) ->C : Symbol(C, Decl(uniqueSymbols.ts, 53, 61)) ->c.readonlyCall : Symbol(C.readonlyCall, Decl(uniqueSymbols.ts, 60, 42)) ->c : Symbol(c, Decl(uniqueSymbols.ts, 65, 13)) ->readonlyCall : Symbol(C.readonlyCall, Decl(uniqueSymbols.ts, 60, 42)) +>constInitToCReadonlyCallWithIndexedAccess : Symbol(constInitToCReadonlyCallWithIndexedAccess, Decl(uniqueSymbols.ts, 85, 5)) +>C : Symbol(C, Decl(uniqueSymbols.ts, 57, 61)) +>c.readonlyCall : Symbol(C.readonlyCall, Decl(uniqueSymbols.ts, 64, 42)) +>c : Symbol(c, Decl(uniqueSymbols.ts, 69, 13)) +>readonlyCall : Symbol(C.readonlyCall, Decl(uniqueSymbols.ts, 64, 42)) const constInitToCReadwriteCallWithIndexedAccess: C["readwriteCall"] = c.readwriteCall; ->constInitToCReadwriteCallWithIndexedAccess : Symbol(constInitToCReadwriteCallWithIndexedAccess, Decl(uniqueSymbols.ts, 82, 5)) ->C : Symbol(C, Decl(uniqueSymbols.ts, 53, 61)) ->c.readwriteCall : Symbol(C.readwriteCall, Decl(uniqueSymbols.ts, 62, 37)) ->c : Symbol(c, Decl(uniqueSymbols.ts, 65, 13)) ->readwriteCall : Symbol(C.readwriteCall, Decl(uniqueSymbols.ts, 62, 37)) +>constInitToCReadwriteCallWithIndexedAccess : Symbol(constInitToCReadwriteCallWithIndexedAccess, Decl(uniqueSymbols.ts, 86, 5)) +>C : Symbol(C, Decl(uniqueSymbols.ts, 57, 61)) +>c.readwriteCall : Symbol(C.readwriteCall, Decl(uniqueSymbols.ts, 66, 37)) +>c : Symbol(c, Decl(uniqueSymbols.ts, 69, 13)) +>readwriteCall : Symbol(C.readwriteCall, Decl(uniqueSymbols.ts, 66, 37)) // interfaces interface I { ->I : Symbol(I, Decl(uniqueSymbols.ts, 82, 87)) +>I : Symbol(I, Decl(uniqueSymbols.ts, 86, 87)) readonly readonlyType: unique symbol; ->readonlyType : Symbol(I.readonlyType, Decl(uniqueSymbols.ts, 85, 13)) +>readonlyType : Symbol(I.readonlyType, Decl(uniqueSymbols.ts, 89, 13)) } declare const i: I; ->i : Symbol(i, Decl(uniqueSymbols.ts, 88, 13)) ->I : Symbol(I, Decl(uniqueSymbols.ts, 82, 87)) +>i : Symbol(i, Decl(uniqueSymbols.ts, 92, 13)) +>I : Symbol(I, Decl(uniqueSymbols.ts, 86, 87)) const constInitToIReadonlyType = i.readonlyType; ->constInitToIReadonlyType : Symbol(constInitToIReadonlyType, Decl(uniqueSymbols.ts, 90, 5)) ->i.readonlyType : Symbol(I.readonlyType, Decl(uniqueSymbols.ts, 85, 13)) ->i : Symbol(i, Decl(uniqueSymbols.ts, 88, 13)) ->readonlyType : Symbol(I.readonlyType, Decl(uniqueSymbols.ts, 85, 13)) +>constInitToIReadonlyType : Symbol(constInitToIReadonlyType, Decl(uniqueSymbols.ts, 94, 5)) +>i.readonlyType : Symbol(I.readonlyType, Decl(uniqueSymbols.ts, 89, 13)) +>i : Symbol(i, Decl(uniqueSymbols.ts, 92, 13)) +>readonlyType : Symbol(I.readonlyType, Decl(uniqueSymbols.ts, 89, 13)) const constInitToIReadonlyTypeWithTypeQuery: typeof i.readonlyType = i.readonlyType; ->constInitToIReadonlyTypeWithTypeQuery : Symbol(constInitToIReadonlyTypeWithTypeQuery, Decl(uniqueSymbols.ts, 91, 5)) ->i.readonlyType : Symbol(I.readonlyType, Decl(uniqueSymbols.ts, 85, 13)) ->i : Symbol(i, Decl(uniqueSymbols.ts, 88, 13)) ->readonlyType : Symbol(I.readonlyType, Decl(uniqueSymbols.ts, 85, 13)) ->i.readonlyType : Symbol(I.readonlyType, Decl(uniqueSymbols.ts, 85, 13)) ->i : Symbol(i, Decl(uniqueSymbols.ts, 88, 13)) ->readonlyType : Symbol(I.readonlyType, Decl(uniqueSymbols.ts, 85, 13)) +>constInitToIReadonlyTypeWithTypeQuery : Symbol(constInitToIReadonlyTypeWithTypeQuery, Decl(uniqueSymbols.ts, 95, 5)) +>i.readonlyType : Symbol(I.readonlyType, Decl(uniqueSymbols.ts, 89, 13)) +>i : Symbol(i, Decl(uniqueSymbols.ts, 92, 13)) +>readonlyType : Symbol(I.readonlyType, Decl(uniqueSymbols.ts, 89, 13)) +>i.readonlyType : Symbol(I.readonlyType, Decl(uniqueSymbols.ts, 89, 13)) +>i : Symbol(i, Decl(uniqueSymbols.ts, 92, 13)) +>readonlyType : Symbol(I.readonlyType, Decl(uniqueSymbols.ts, 89, 13)) const constInitToIReadonlyTypeWithIndexedAccess: I["readonlyType"] = i.readonlyType; ->constInitToIReadonlyTypeWithIndexedAccess : Symbol(constInitToIReadonlyTypeWithIndexedAccess, Decl(uniqueSymbols.ts, 92, 5)) ->I : Symbol(I, Decl(uniqueSymbols.ts, 82, 87)) ->i.readonlyType : Symbol(I.readonlyType, Decl(uniqueSymbols.ts, 85, 13)) ->i : Symbol(i, Decl(uniqueSymbols.ts, 88, 13)) ->readonlyType : Symbol(I.readonlyType, Decl(uniqueSymbols.ts, 85, 13)) +>constInitToIReadonlyTypeWithIndexedAccess : Symbol(constInitToIReadonlyTypeWithIndexedAccess, Decl(uniqueSymbols.ts, 96, 5)) +>I : Symbol(I, Decl(uniqueSymbols.ts, 86, 87)) +>i.readonlyType : Symbol(I.readonlyType, Decl(uniqueSymbols.ts, 89, 13)) +>i : Symbol(i, Decl(uniqueSymbols.ts, 92, 13)) +>readonlyType : Symbol(I.readonlyType, Decl(uniqueSymbols.ts, 89, 13)) // type literals type L = { ->L : Symbol(L, Decl(uniqueSymbols.ts, 92, 84)) +>L : Symbol(L, Decl(uniqueSymbols.ts, 96, 84)) readonly readonlyType: unique symbol; ->readonlyType : Symbol(readonlyType, Decl(uniqueSymbols.ts, 95, 10)) +>readonlyType : Symbol(readonlyType, Decl(uniqueSymbols.ts, 99, 10)) nested: { ->nested : Symbol(nested, Decl(uniqueSymbols.ts, 96, 41)) +>nested : Symbol(nested, Decl(uniqueSymbols.ts, 100, 41)) readonly readonlyNestedType: unique symbol; ->readonlyNestedType : Symbol(readonlyNestedType, Decl(uniqueSymbols.ts, 97, 13)) +>readonlyNestedType : Symbol(readonlyNestedType, Decl(uniqueSymbols.ts, 101, 13)) } }; declare const l: L; ->l : Symbol(l, Decl(uniqueSymbols.ts, 101, 13)) ->L : Symbol(L, Decl(uniqueSymbols.ts, 92, 84)) +>l : Symbol(l, Decl(uniqueSymbols.ts, 105, 13)) +>L : Symbol(L, Decl(uniqueSymbols.ts, 96, 84)) const constInitToLReadonlyType = l.readonlyType; ->constInitToLReadonlyType : Symbol(constInitToLReadonlyType, Decl(uniqueSymbols.ts, 103, 5)) ->l.readonlyType : Symbol(readonlyType, Decl(uniqueSymbols.ts, 95, 10)) ->l : Symbol(l, Decl(uniqueSymbols.ts, 101, 13)) ->readonlyType : Symbol(readonlyType, Decl(uniqueSymbols.ts, 95, 10)) +>constInitToLReadonlyType : Symbol(constInitToLReadonlyType, Decl(uniqueSymbols.ts, 107, 5)) +>l.readonlyType : Symbol(readonlyType, Decl(uniqueSymbols.ts, 99, 10)) +>l : Symbol(l, Decl(uniqueSymbols.ts, 105, 13)) +>readonlyType : Symbol(readonlyType, Decl(uniqueSymbols.ts, 99, 10)) const constInitToLReadonlyNestedType = l.nested.readonlyNestedType; ->constInitToLReadonlyNestedType : Symbol(constInitToLReadonlyNestedType, Decl(uniqueSymbols.ts, 104, 5)) ->l.nested.readonlyNestedType : Symbol(readonlyNestedType, Decl(uniqueSymbols.ts, 97, 13)) ->l.nested : Symbol(nested, Decl(uniqueSymbols.ts, 96, 41)) ->l : Symbol(l, Decl(uniqueSymbols.ts, 101, 13)) ->nested : Symbol(nested, Decl(uniqueSymbols.ts, 96, 41)) ->readonlyNestedType : Symbol(readonlyNestedType, Decl(uniqueSymbols.ts, 97, 13)) +>constInitToLReadonlyNestedType : Symbol(constInitToLReadonlyNestedType, Decl(uniqueSymbols.ts, 108, 5)) +>l.nested.readonlyNestedType : Symbol(readonlyNestedType, Decl(uniqueSymbols.ts, 101, 13)) +>l.nested : Symbol(nested, Decl(uniqueSymbols.ts, 100, 41)) +>l : Symbol(l, Decl(uniqueSymbols.ts, 105, 13)) +>nested : Symbol(nested, Decl(uniqueSymbols.ts, 100, 41)) +>readonlyNestedType : Symbol(readonlyNestedType, Decl(uniqueSymbols.ts, 101, 13)) const constInitToLReadonlyTypeWithTypeQuery: typeof l.readonlyType = l.readonlyType; ->constInitToLReadonlyTypeWithTypeQuery : Symbol(constInitToLReadonlyTypeWithTypeQuery, Decl(uniqueSymbols.ts, 105, 5)) ->l.readonlyType : Symbol(readonlyType, Decl(uniqueSymbols.ts, 95, 10)) ->l : Symbol(l, Decl(uniqueSymbols.ts, 101, 13)) ->readonlyType : Symbol(readonlyType, Decl(uniqueSymbols.ts, 95, 10)) ->l.readonlyType : Symbol(readonlyType, Decl(uniqueSymbols.ts, 95, 10)) ->l : Symbol(l, Decl(uniqueSymbols.ts, 101, 13)) ->readonlyType : Symbol(readonlyType, Decl(uniqueSymbols.ts, 95, 10)) +>constInitToLReadonlyTypeWithTypeQuery : Symbol(constInitToLReadonlyTypeWithTypeQuery, Decl(uniqueSymbols.ts, 109, 5)) +>l.readonlyType : Symbol(readonlyType, Decl(uniqueSymbols.ts, 99, 10)) +>l : Symbol(l, Decl(uniqueSymbols.ts, 105, 13)) +>readonlyType : Symbol(readonlyType, Decl(uniqueSymbols.ts, 99, 10)) +>l.readonlyType : Symbol(readonlyType, Decl(uniqueSymbols.ts, 99, 10)) +>l : Symbol(l, Decl(uniqueSymbols.ts, 105, 13)) +>readonlyType : Symbol(readonlyType, Decl(uniqueSymbols.ts, 99, 10)) const constInitToLReadonlyNestedTypeWithTypeQuery: typeof l.nested.readonlyNestedType = l.nested.readonlyNestedType; ->constInitToLReadonlyNestedTypeWithTypeQuery : Symbol(constInitToLReadonlyNestedTypeWithTypeQuery, Decl(uniqueSymbols.ts, 106, 5)) ->l.nested.readonlyNestedType : Symbol(readonlyNestedType, Decl(uniqueSymbols.ts, 97, 13)) ->l.nested : Symbol(nested, Decl(uniqueSymbols.ts, 96, 41)) ->l : Symbol(l, Decl(uniqueSymbols.ts, 101, 13)) ->nested : Symbol(nested, Decl(uniqueSymbols.ts, 96, 41)) ->readonlyNestedType : Symbol(readonlyNestedType, Decl(uniqueSymbols.ts, 97, 13)) ->l.nested.readonlyNestedType : Symbol(readonlyNestedType, Decl(uniqueSymbols.ts, 97, 13)) ->l.nested : Symbol(nested, Decl(uniqueSymbols.ts, 96, 41)) ->l : Symbol(l, Decl(uniqueSymbols.ts, 101, 13)) ->nested : Symbol(nested, Decl(uniqueSymbols.ts, 96, 41)) ->readonlyNestedType : Symbol(readonlyNestedType, Decl(uniqueSymbols.ts, 97, 13)) +>constInitToLReadonlyNestedTypeWithTypeQuery : Symbol(constInitToLReadonlyNestedTypeWithTypeQuery, Decl(uniqueSymbols.ts, 110, 5)) +>l.nested.readonlyNestedType : Symbol(readonlyNestedType, Decl(uniqueSymbols.ts, 101, 13)) +>l.nested : Symbol(nested, Decl(uniqueSymbols.ts, 100, 41)) +>l : Symbol(l, Decl(uniqueSymbols.ts, 105, 13)) +>nested : Symbol(nested, Decl(uniqueSymbols.ts, 100, 41)) +>readonlyNestedType : Symbol(readonlyNestedType, Decl(uniqueSymbols.ts, 101, 13)) +>l.nested.readonlyNestedType : Symbol(readonlyNestedType, Decl(uniqueSymbols.ts, 101, 13)) +>l.nested : Symbol(nested, Decl(uniqueSymbols.ts, 100, 41)) +>l : Symbol(l, Decl(uniqueSymbols.ts, 105, 13)) +>nested : Symbol(nested, Decl(uniqueSymbols.ts, 100, 41)) +>readonlyNestedType : Symbol(readonlyNestedType, Decl(uniqueSymbols.ts, 101, 13)) const constInitToLReadonlyTypeWithIndexedAccess: L["readonlyType"] = l.readonlyType; ->constInitToLReadonlyTypeWithIndexedAccess : Symbol(constInitToLReadonlyTypeWithIndexedAccess, Decl(uniqueSymbols.ts, 107, 5)) ->L : Symbol(L, Decl(uniqueSymbols.ts, 92, 84)) ->l.readonlyType : Symbol(readonlyType, Decl(uniqueSymbols.ts, 95, 10)) ->l : Symbol(l, Decl(uniqueSymbols.ts, 101, 13)) ->readonlyType : Symbol(readonlyType, Decl(uniqueSymbols.ts, 95, 10)) +>constInitToLReadonlyTypeWithIndexedAccess : Symbol(constInitToLReadonlyTypeWithIndexedAccess, Decl(uniqueSymbols.ts, 111, 5)) +>L : Symbol(L, Decl(uniqueSymbols.ts, 96, 84)) +>l.readonlyType : Symbol(readonlyType, Decl(uniqueSymbols.ts, 99, 10)) +>l : Symbol(l, Decl(uniqueSymbols.ts, 105, 13)) +>readonlyType : Symbol(readonlyType, Decl(uniqueSymbols.ts, 99, 10)) const constInitToLReadonlyNestedTypeWithIndexedAccess: L["nested"]["readonlyNestedType"] = l.nested.readonlyNestedType; ->constInitToLReadonlyNestedTypeWithIndexedAccess : Symbol(constInitToLReadonlyNestedTypeWithIndexedAccess, Decl(uniqueSymbols.ts, 108, 5)) ->L : Symbol(L, Decl(uniqueSymbols.ts, 92, 84)) ->l.nested.readonlyNestedType : Symbol(readonlyNestedType, Decl(uniqueSymbols.ts, 97, 13)) ->l.nested : Symbol(nested, Decl(uniqueSymbols.ts, 96, 41)) ->l : Symbol(l, Decl(uniqueSymbols.ts, 101, 13)) ->nested : Symbol(nested, Decl(uniqueSymbols.ts, 96, 41)) ->readonlyNestedType : Symbol(readonlyNestedType, Decl(uniqueSymbols.ts, 97, 13)) +>constInitToLReadonlyNestedTypeWithIndexedAccess : Symbol(constInitToLReadonlyNestedTypeWithIndexedAccess, Decl(uniqueSymbols.ts, 112, 5)) +>L : Symbol(L, Decl(uniqueSymbols.ts, 96, 84)) +>l.nested.readonlyNestedType : Symbol(readonlyNestedType, Decl(uniqueSymbols.ts, 101, 13)) +>l.nested : Symbol(nested, Decl(uniqueSymbols.ts, 100, 41)) +>l : Symbol(l, Decl(uniqueSymbols.ts, 105, 13)) +>nested : Symbol(nested, Decl(uniqueSymbols.ts, 100, 41)) +>readonlyNestedType : Symbol(readonlyNestedType, Decl(uniqueSymbols.ts, 101, 13)) // type argument inference const promiseForConstCall = Promise.resolve(constCall); ->promiseForConstCall : Symbol(promiseForConstCall, Decl(uniqueSymbols.ts, 111, 5)) +>promiseForConstCall : Symbol(promiseForConstCall, Decl(uniqueSymbols.ts, 115, 5)) >Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) >Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) >resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) >constCall : Symbol(constCall, Decl(uniqueSymbols.ts, 1, 5)) const arrayOfConstCall = [constCall]; ->arrayOfConstCall : Symbol(arrayOfConstCall, Decl(uniqueSymbols.ts, 112, 5)) +>arrayOfConstCall : Symbol(arrayOfConstCall, Decl(uniqueSymbols.ts, 116, 5)) >constCall : Symbol(constCall, Decl(uniqueSymbols.ts, 1, 5)) // unique symbol widening in expressions declare const s: unique symbol; ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) declare namespace N { const s: unique symbol; } ->N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 116, 27)) +>N : Symbol(N, Decl(uniqueSymbols.ts, 119, 31)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 120, 27)) declare const o: { [s]: "a", [N.s]: "b" }; ->o : Symbol(o, Decl(uniqueSymbols.ts, 117, 13)) ->[s] : Symbol([s], Decl(uniqueSymbols.ts, 117, 18)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) ->[N.s] : Symbol([N.s], Decl(uniqueSymbols.ts, 117, 28)) ->N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) ->N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) ->s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) +>o : Symbol(o, Decl(uniqueSymbols.ts, 121, 13)) +>[s] : Symbol([s], Decl(uniqueSymbols.ts, 121, 18)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) +>[N.s] : Symbol([N.s], Decl(uniqueSymbols.ts, 121, 28)) +>N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) +>N : Symbol(N, Decl(uniqueSymbols.ts, 119, 31)) +>s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) declare function f(x: T): T; ->f : Symbol(f, Decl(uniqueSymbols.ts, 117, 42)) ->T : Symbol(T, Decl(uniqueSymbols.ts, 118, 19)) ->x : Symbol(x, Decl(uniqueSymbols.ts, 118, 22)) ->T : Symbol(T, Decl(uniqueSymbols.ts, 118, 19)) ->T : Symbol(T, Decl(uniqueSymbols.ts, 118, 19)) +>f : Symbol(f, Decl(uniqueSymbols.ts, 121, 42)) +>T : Symbol(T, Decl(uniqueSymbols.ts, 122, 19)) +>x : Symbol(x, Decl(uniqueSymbols.ts, 122, 22)) +>T : Symbol(T, Decl(uniqueSymbols.ts, 122, 19)) +>T : Symbol(T, Decl(uniqueSymbols.ts, 122, 19)) declare function g(x: typeof s): void; ->g : Symbol(g, Decl(uniqueSymbols.ts, 118, 31), Decl(uniqueSymbols.ts, 119, 38)) ->x : Symbol(x, Decl(uniqueSymbols.ts, 119, 19)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>g : Symbol(g, Decl(uniqueSymbols.ts, 122, 31), Decl(uniqueSymbols.ts, 123, 38)) +>x : Symbol(x, Decl(uniqueSymbols.ts, 123, 19)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) declare function g(x: typeof N.s): void; ->g : Symbol(g, Decl(uniqueSymbols.ts, 118, 31), Decl(uniqueSymbols.ts, 119, 38)) ->x : Symbol(x, Decl(uniqueSymbols.ts, 120, 19)) ->N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) ->N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) ->s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) +>g : Symbol(g, Decl(uniqueSymbols.ts, 122, 31), Decl(uniqueSymbols.ts, 123, 38)) +>x : Symbol(x, Decl(uniqueSymbols.ts, 124, 19)) +>N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) +>N : Symbol(N, Decl(uniqueSymbols.ts, 119, 31)) +>s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) // widening positions // argument inference f(s); ->f : Symbol(f, Decl(uniqueSymbols.ts, 117, 42)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>f : Symbol(f, Decl(uniqueSymbols.ts, 121, 42)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) f(N.s); ->f : Symbol(f, Decl(uniqueSymbols.ts, 117, 42)) ->N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) ->N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) ->s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) +>f : Symbol(f, Decl(uniqueSymbols.ts, 121, 42)) +>N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) +>N : Symbol(N, Decl(uniqueSymbols.ts, 119, 31)) +>s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) f(N["s"]); ->f : Symbol(f, Decl(uniqueSymbols.ts, 117, 42)) ->N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) ->"s" : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) +>f : Symbol(f, Decl(uniqueSymbols.ts, 121, 42)) +>N : Symbol(N, Decl(uniqueSymbols.ts, 119, 31)) +>"s" : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) // array literal elements [s]; ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) [N.s]; ->N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) ->N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) ->s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) +>N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) +>N : Symbol(N, Decl(uniqueSymbols.ts, 119, 31)) +>s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) [N["s"]]; ->N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) ->"s" : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) +>N : Symbol(N, Decl(uniqueSymbols.ts, 119, 31)) +>"s" : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) // property assignments/methods const o2 = { ->o2 : Symbol(o2, Decl(uniqueSymbols.ts, 135, 5)) +>o2 : Symbol(o2, Decl(uniqueSymbols.ts, 139, 5)) a: s, ->a : Symbol(a, Decl(uniqueSymbols.ts, 135, 12)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>a : Symbol(a, Decl(uniqueSymbols.ts, 139, 12)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) b: N.s, ->b : Symbol(b, Decl(uniqueSymbols.ts, 136, 9)) ->N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) ->N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) ->s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) +>b : Symbol(b, Decl(uniqueSymbols.ts, 140, 9)) +>N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) +>N : Symbol(N, Decl(uniqueSymbols.ts, 119, 31)) +>s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) c: N["s"], ->c : Symbol(c, Decl(uniqueSymbols.ts, 137, 11)) ->N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) ->"s" : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) +>c : Symbol(c, Decl(uniqueSymbols.ts, 141, 11)) +>N : Symbol(N, Decl(uniqueSymbols.ts, 119, 31)) +>"s" : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) method1() { return s; }, ->method1 : Symbol(method1, Decl(uniqueSymbols.ts, 138, 14)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>method1 : Symbol(method1, Decl(uniqueSymbols.ts, 142, 14)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) async method2() { return s; }, ->method2 : Symbol(method2, Decl(uniqueSymbols.ts, 140, 28)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>method2 : Symbol(method2, Decl(uniqueSymbols.ts, 144, 28)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) async * method3() { yield s; }, ->method3 : Symbol(method3, Decl(uniqueSymbols.ts, 141, 34)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>method3 : Symbol(method3, Decl(uniqueSymbols.ts, 145, 34)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) * method4() { yield s; }, ->method4 : Symbol(method4, Decl(uniqueSymbols.ts, 142, 35)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>method4 : Symbol(method4, Decl(uniqueSymbols.ts, 146, 35)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) method5(p = s) { return p; }, ->method5 : Symbol(method5, Decl(uniqueSymbols.ts, 143, 29)) ->p : Symbol(p, Decl(uniqueSymbols.ts, 144, 12)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) ->p : Symbol(p, Decl(uniqueSymbols.ts, 144, 12)) +>method5 : Symbol(method5, Decl(uniqueSymbols.ts, 147, 29)) +>p : Symbol(p, Decl(uniqueSymbols.ts, 148, 12)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) +>p : Symbol(p, Decl(uniqueSymbols.ts, 148, 12)) }; // property initializers class C0 { ->C0 : Symbol(C0, Decl(uniqueSymbols.ts, 145, 2)) +>C0 : Symbol(C0, Decl(uniqueSymbols.ts, 149, 2)) static readonly a = s; ->a : Symbol(C0.a, Decl(uniqueSymbols.ts, 148, 10)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>a : Symbol(C0.a, Decl(uniqueSymbols.ts, 152, 10)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) static readonly b = N.s; ->b : Symbol(C0.b, Decl(uniqueSymbols.ts, 149, 26)) ->N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) ->N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) ->s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) +>b : Symbol(C0.b, Decl(uniqueSymbols.ts, 153, 26)) +>N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) +>N : Symbol(N, Decl(uniqueSymbols.ts, 119, 31)) +>s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) static readonly c = N["s"]; ->c : Symbol(C0.c, Decl(uniqueSymbols.ts, 150, 28)) ->N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) ->"s" : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) +>c : Symbol(C0.c, Decl(uniqueSymbols.ts, 154, 28)) +>N : Symbol(N, Decl(uniqueSymbols.ts, 119, 31)) +>"s" : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) static d = s; ->d : Symbol(C0.d, Decl(uniqueSymbols.ts, 151, 31)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>d : Symbol(C0.d, Decl(uniqueSymbols.ts, 155, 31)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) static e = N.s; ->e : Symbol(C0.e, Decl(uniqueSymbols.ts, 153, 17)) ->N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) ->N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) ->s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) +>e : Symbol(C0.e, Decl(uniqueSymbols.ts, 157, 17)) +>N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) +>N : Symbol(N, Decl(uniqueSymbols.ts, 119, 31)) +>s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) static f = N["s"]; ->f : Symbol(C0.f, Decl(uniqueSymbols.ts, 154, 19)) ->N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) ->"s" : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) +>f : Symbol(C0.f, Decl(uniqueSymbols.ts, 158, 19)) +>N : Symbol(N, Decl(uniqueSymbols.ts, 119, 31)) +>"s" : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) readonly a = s; ->a : Symbol(C0.a, Decl(uniqueSymbols.ts, 155, 22)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>a : Symbol(C0.a, Decl(uniqueSymbols.ts, 159, 22)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) readonly b = N.s; ->b : Symbol(C0.b, Decl(uniqueSymbols.ts, 157, 19)) ->N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) ->N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) ->s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) +>b : Symbol(C0.b, Decl(uniqueSymbols.ts, 161, 19)) +>N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) +>N : Symbol(N, Decl(uniqueSymbols.ts, 119, 31)) +>s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) readonly c = N["s"]; ->c : Symbol(C0.c, Decl(uniqueSymbols.ts, 158, 21)) ->N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) ->"s" : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) +>c : Symbol(C0.c, Decl(uniqueSymbols.ts, 162, 21)) +>N : Symbol(N, Decl(uniqueSymbols.ts, 119, 31)) +>"s" : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) d = s; ->d : Symbol(C0.d, Decl(uniqueSymbols.ts, 159, 24)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>d : Symbol(C0.d, Decl(uniqueSymbols.ts, 163, 24)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) e = N.s; ->e : Symbol(C0.e, Decl(uniqueSymbols.ts, 161, 10)) ->N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) ->N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) ->s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) +>e : Symbol(C0.e, Decl(uniqueSymbols.ts, 165, 10)) +>N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) +>N : Symbol(N, Decl(uniqueSymbols.ts, 119, 31)) +>s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) f = N["s"]; ->f : Symbol(C0.f, Decl(uniqueSymbols.ts, 162, 12)) ->N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) ->"s" : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) +>f : Symbol(C0.f, Decl(uniqueSymbols.ts, 166, 12)) +>N : Symbol(N, Decl(uniqueSymbols.ts, 119, 31)) +>"s" : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) method1() { return s; } ->method1 : Symbol(C0.method1, Decl(uniqueSymbols.ts, 163, 15)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>method1 : Symbol(C0.method1, Decl(uniqueSymbols.ts, 167, 15)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) async method2() { return s; } ->method2 : Symbol(C0.method2, Decl(uniqueSymbols.ts, 165, 27)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>method2 : Symbol(C0.method2, Decl(uniqueSymbols.ts, 169, 27)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) async * method3() { yield s; } ->method3 : Symbol(C0.method3, Decl(uniqueSymbols.ts, 166, 33)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>method3 : Symbol(C0.method3, Decl(uniqueSymbols.ts, 170, 33)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) * method4() { yield s; } ->method4 : Symbol(C0.method4, Decl(uniqueSymbols.ts, 167, 34)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>method4 : Symbol(C0.method4, Decl(uniqueSymbols.ts, 171, 34)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) method5(p = s) { return p; } ->method5 : Symbol(C0.method5, Decl(uniqueSymbols.ts, 168, 28)) ->p : Symbol(p, Decl(uniqueSymbols.ts, 169, 12)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) ->p : Symbol(p, Decl(uniqueSymbols.ts, 169, 12)) +>method5 : Symbol(C0.method5, Decl(uniqueSymbols.ts, 172, 28)) +>p : Symbol(p, Decl(uniqueSymbols.ts, 173, 12)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) +>p : Symbol(p, Decl(uniqueSymbols.ts, 173, 12)) } // non-widening positions // element access o[s]; ->o : Symbol(o, Decl(uniqueSymbols.ts, 117, 13)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>o : Symbol(o, Decl(uniqueSymbols.ts, 121, 13)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) o[N.s]; ->o : Symbol(o, Decl(uniqueSymbols.ts, 117, 13)) ->N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) ->N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) ->s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) +>o : Symbol(o, Decl(uniqueSymbols.ts, 121, 13)) +>N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) +>N : Symbol(N, Decl(uniqueSymbols.ts, 119, 31)) +>s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) o[N["s"]]; ->o : Symbol(o, Decl(uniqueSymbols.ts, 117, 13)) ->N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) ->"s" : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) +>o : Symbol(o, Decl(uniqueSymbols.ts, 121, 13)) +>N : Symbol(N, Decl(uniqueSymbols.ts, 119, 31)) +>"s" : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) // arguments (no-inference) f(s); ->f : Symbol(f, Decl(uniqueSymbols.ts, 117, 42)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>f : Symbol(f, Decl(uniqueSymbols.ts, 121, 42)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) f(N.s); ->f : Symbol(f, Decl(uniqueSymbols.ts, 117, 42)) ->N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) ->N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) ->s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) ->N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) ->N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) ->s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) +>f : Symbol(f, Decl(uniqueSymbols.ts, 121, 42)) +>N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) +>N : Symbol(N, Decl(uniqueSymbols.ts, 119, 31)) +>s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) +>N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) +>N : Symbol(N, Decl(uniqueSymbols.ts, 119, 31)) +>s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) f(N["s"]); ->f : Symbol(f, Decl(uniqueSymbols.ts, 117, 42)) ->N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) ->N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) ->s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) ->N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) ->"s" : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) +>f : Symbol(f, Decl(uniqueSymbols.ts, 121, 42)) +>N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) +>N : Symbol(N, Decl(uniqueSymbols.ts, 119, 31)) +>s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) +>N : Symbol(N, Decl(uniqueSymbols.ts, 119, 31)) +>"s" : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) g(s); ->g : Symbol(g, Decl(uniqueSymbols.ts, 118, 31), Decl(uniqueSymbols.ts, 119, 38)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>g : Symbol(g, Decl(uniqueSymbols.ts, 122, 31), Decl(uniqueSymbols.ts, 123, 38)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) g(N.s); ->g : Symbol(g, Decl(uniqueSymbols.ts, 118, 31), Decl(uniqueSymbols.ts, 119, 38)) ->N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) ->N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) ->s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) +>g : Symbol(g, Decl(uniqueSymbols.ts, 122, 31), Decl(uniqueSymbols.ts, 123, 38)) +>N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) +>N : Symbol(N, Decl(uniqueSymbols.ts, 119, 31)) +>s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) g(N["s"]); ->g : Symbol(g, Decl(uniqueSymbols.ts, 118, 31), Decl(uniqueSymbols.ts, 119, 38)) ->N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) ->"s" : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) +>g : Symbol(g, Decl(uniqueSymbols.ts, 122, 31), Decl(uniqueSymbols.ts, 123, 38)) +>N : Symbol(N, Decl(uniqueSymbols.ts, 119, 31)) +>"s" : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) // falsy expressions s || ""; ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) N.s || ""; ->N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) ->N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) ->s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) +>N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) +>N : Symbol(N, Decl(uniqueSymbols.ts, 119, 31)) +>s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) N["s"] || ""; ->N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) ->"s" : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) +>N : Symbol(N, Decl(uniqueSymbols.ts, 119, 31)) +>"s" : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) // conditionals Math.random() * 2 ? s : "a"; >Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) >Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) >random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) Math.random() * 2 ? N.s : "a"; >Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) >Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) >random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) ->N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) ->N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) ->s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) +>N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) +>N : Symbol(N, Decl(uniqueSymbols.ts, 119, 31)) +>s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) Math.random() * 2 ? N["s"] : "a"; >Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) >Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) >random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) ->N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) ->"s" : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) +>N : Symbol(N, Decl(uniqueSymbols.ts, 119, 31)) +>"s" : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) // computed property names ({ [s]: "a", ->[s] : Symbol([s], Decl(uniqueSymbols.ts, 198, 2)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>[s] : Symbol([s], Decl(uniqueSymbols.ts, 202, 2)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) [N.s]: "b", ->[N.s] : Symbol([N.s], Decl(uniqueSymbols.ts, 199, 13)) ->N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) ->N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) ->s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) +>[N.s] : Symbol([N.s], Decl(uniqueSymbols.ts, 203, 13)) +>N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) +>N : Symbol(N, Decl(uniqueSymbols.ts, 119, 31)) +>s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) }); class C1 { ->C1 : Symbol(C1, Decl(uniqueSymbols.ts, 201, 3)) +>C1 : Symbol(C1, Decl(uniqueSymbols.ts, 205, 3)) static [s]: "a"; ->[s] : Symbol(C1[s], Decl(uniqueSymbols.ts, 203, 10)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>[s] : Symbol(C1[s], Decl(uniqueSymbols.ts, 207, 10)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) static [N.s]: "b"; ->[N.s] : Symbol(C1[N.s], Decl(uniqueSymbols.ts, 204, 20)) ->N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) ->N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) ->s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) +>[N.s] : Symbol(C1[N.s], Decl(uniqueSymbols.ts, 208, 20)) +>N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) +>N : Symbol(N, Decl(uniqueSymbols.ts, 119, 31)) +>s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) [s]: "a"; ->[s] : Symbol(C1[s], Decl(uniqueSymbols.ts, 205, 22)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>[s] : Symbol(C1[s], Decl(uniqueSymbols.ts, 209, 22)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) [N.s]: "b"; ->[N.s] : Symbol(C1[N.s], Decl(uniqueSymbols.ts, 207, 13)) ->N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) ->N : Symbol(N, Decl(uniqueSymbols.ts, 115, 31)) ->s : Symbol(N.s, Decl(uniqueSymbols.ts, 116, 27)) +>[N.s] : Symbol(C1[N.s], Decl(uniqueSymbols.ts, 211, 13)) +>N.s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) +>N : Symbol(N, Decl(uniqueSymbols.ts, 119, 31)) +>s : Symbol(N.s, Decl(uniqueSymbols.ts, 120, 27)) } // contextual types interface Context { ->Context : Symbol(Context, Decl(uniqueSymbols.ts, 209, 1)) +>Context : Symbol(Context, Decl(uniqueSymbols.ts, 213, 1)) method1(): typeof s; ->method1 : Symbol(Context.method1, Decl(uniqueSymbols.ts, 213, 19)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>method1 : Symbol(Context.method1, Decl(uniqueSymbols.ts, 217, 19)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) method2(): Promise; ->method2 : Symbol(Context.method2, Decl(uniqueSymbols.ts, 214, 24)) +>method2 : Symbol(Context.method2, Decl(uniqueSymbols.ts, 218, 24)) >Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) method3(): AsyncIterableIterator; ->method3 : Symbol(Context.method3, Decl(uniqueSymbols.ts, 215, 33)) +>method3 : Symbol(Context.method3, Decl(uniqueSymbols.ts, 219, 33)) >AsyncIterableIterator : Symbol(AsyncIterableIterator, Decl(lib.esnext.asynciterable.d.ts, --, --)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) method4(): IterableIterator; ->method4 : Symbol(Context.method4, Decl(uniqueSymbols.ts, 216, 47)) +>method4 : Symbol(Context.method4, Decl(uniqueSymbols.ts, 220, 47)) >IterableIterator : Symbol(IterableIterator, Decl(lib.es2015.iterable.d.ts, --, --)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) method5(p?: typeof s): typeof s; ->method5 : Symbol(Context.method5, Decl(uniqueSymbols.ts, 217, 42)) ->p : Symbol(p, Decl(uniqueSymbols.ts, 218, 12)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>method5 : Symbol(Context.method5, Decl(uniqueSymbols.ts, 221, 42)) +>p : Symbol(p, Decl(uniqueSymbols.ts, 222, 12)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) } const o3: Context = { ->o3 : Symbol(o3, Decl(uniqueSymbols.ts, 221, 5)) ->Context : Symbol(Context, Decl(uniqueSymbols.ts, 209, 1)) +>o3 : Symbol(o3, Decl(uniqueSymbols.ts, 225, 5)) +>Context : Symbol(Context, Decl(uniqueSymbols.ts, 213, 1)) method1() { ->method1 : Symbol(method1, Decl(uniqueSymbols.ts, 221, 21)) +>method1 : Symbol(method1, Decl(uniqueSymbols.ts, 225, 21)) return s; // return type should not widen due to contextual type ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) }, async method2() { ->method2 : Symbol(method2, Decl(uniqueSymbols.ts, 224, 6)) +>method2 : Symbol(method2, Decl(uniqueSymbols.ts, 228, 6)) return s; // return type should not widen due to contextual type ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) }, async * method3() { ->method3 : Symbol(method3, Decl(uniqueSymbols.ts, 227, 6)) +>method3 : Symbol(method3, Decl(uniqueSymbols.ts, 231, 6)) yield s; // yield type should not widen due to contextual type ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) }, * method4() { ->method4 : Symbol(method4, Decl(uniqueSymbols.ts, 230, 6)) +>method4 : Symbol(method4, Decl(uniqueSymbols.ts, 234, 6)) yield s; // yield type should not widen due to contextual type ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) }, method5(p = s) { // parameter should not widen due to contextual type ->method5 : Symbol(method5, Decl(uniqueSymbols.ts, 233, 6)) ->p : Symbol(p, Decl(uniqueSymbols.ts, 234, 12)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>method5 : Symbol(method5, Decl(uniqueSymbols.ts, 237, 6)) +>p : Symbol(p, Decl(uniqueSymbols.ts, 238, 12)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) return p; ->p : Symbol(p, Decl(uniqueSymbols.ts, 234, 12)) +>p : Symbol(p, Decl(uniqueSymbols.ts, 238, 12)) }, }; @@ -799,60 +804,60 @@ const o3: Context = { // allowed when not emitting declarations const o4 = { ->o4 : Symbol(o4, Decl(uniqueSymbols.ts, 241, 5)) +>o4 : Symbol(o4, Decl(uniqueSymbols.ts, 245, 5)) method1(p: typeof s): typeof s { ->method1 : Symbol(method1, Decl(uniqueSymbols.ts, 241, 12)) ->p : Symbol(p, Decl(uniqueSymbols.ts, 242, 12)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>method1 : Symbol(method1, Decl(uniqueSymbols.ts, 245, 12)) +>p : Symbol(p, Decl(uniqueSymbols.ts, 246, 12)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) return p; ->p : Symbol(p, Decl(uniqueSymbols.ts, 242, 12)) +>p : Symbol(p, Decl(uniqueSymbols.ts, 246, 12)) }, method2(p: I["readonlyType"]): I["readonlyType"] { ->method2 : Symbol(method2, Decl(uniqueSymbols.ts, 244, 6)) ->p : Symbol(p, Decl(uniqueSymbols.ts, 245, 12)) ->I : Symbol(I, Decl(uniqueSymbols.ts, 82, 87)) ->I : Symbol(I, Decl(uniqueSymbols.ts, 82, 87)) +>method2 : Symbol(method2, Decl(uniqueSymbols.ts, 248, 6)) +>p : Symbol(p, Decl(uniqueSymbols.ts, 249, 12)) +>I : Symbol(I, Decl(uniqueSymbols.ts, 86, 87)) +>I : Symbol(I, Decl(uniqueSymbols.ts, 86, 87)) return p; ->p : Symbol(p, Decl(uniqueSymbols.ts, 245, 12)) +>p : Symbol(p, Decl(uniqueSymbols.ts, 249, 12)) } }; const ce0 = class { ->ce0 : Symbol(ce0, Decl(uniqueSymbols.ts, 250, 5)) +>ce0 : Symbol(ce0, Decl(uniqueSymbols.ts, 254, 5)) method1(p: typeof s): typeof s { ->method1 : Symbol(ce0.method1, Decl(uniqueSymbols.ts, 250, 19)) ->p : Symbol(p, Decl(uniqueSymbols.ts, 251, 12)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>method1 : Symbol(ce0.method1, Decl(uniqueSymbols.ts, 254, 19)) +>p : Symbol(p, Decl(uniqueSymbols.ts, 255, 12)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) return p; ->p : Symbol(p, Decl(uniqueSymbols.ts, 251, 12)) +>p : Symbol(p, Decl(uniqueSymbols.ts, 255, 12)) } method2(p: I["readonlyType"]): I["readonlyType"] { ->method2 : Symbol(ce0.method2, Decl(uniqueSymbols.ts, 253, 5)) ->p : Symbol(p, Decl(uniqueSymbols.ts, 254, 12)) ->I : Symbol(I, Decl(uniqueSymbols.ts, 82, 87)) ->I : Symbol(I, Decl(uniqueSymbols.ts, 82, 87)) +>method2 : Symbol(ce0.method2, Decl(uniqueSymbols.ts, 257, 5)) +>p : Symbol(p, Decl(uniqueSymbols.ts, 258, 12)) +>I : Symbol(I, Decl(uniqueSymbols.ts, 86, 87)) +>I : Symbol(I, Decl(uniqueSymbols.ts, 86, 87)) return p; ->p : Symbol(p, Decl(uniqueSymbols.ts, 254, 12)) +>p : Symbol(p, Decl(uniqueSymbols.ts, 258, 12)) } }; function funcInferredReturnType(obj: { method(p: typeof s): void }) { ->funcInferredReturnType : Symbol(funcInferredReturnType, Decl(uniqueSymbols.ts, 257, 2)) ->obj : Symbol(obj, Decl(uniqueSymbols.ts, 259, 32)) ->method : Symbol(method, Decl(uniqueSymbols.ts, 259, 38)) ->p : Symbol(p, Decl(uniqueSymbols.ts, 259, 46)) ->s : Symbol(s, Decl(uniqueSymbols.ts, 115, 13)) +>funcInferredReturnType : Symbol(funcInferredReturnType, Decl(uniqueSymbols.ts, 261, 2)) +>obj : Symbol(obj, Decl(uniqueSymbols.ts, 263, 32)) +>method : Symbol(method, Decl(uniqueSymbols.ts, 263, 38)) +>p : Symbol(p, Decl(uniqueSymbols.ts, 263, 46)) +>s : Symbol(s, Decl(uniqueSymbols.ts, 119, 13)) return obj; ->obj : Symbol(obj, Decl(uniqueSymbols.ts, 259, 32)) +>obj : Symbol(obj, Decl(uniqueSymbols.ts, 263, 32)) } diff --git a/tests/baselines/reference/uniqueSymbols.types b/tests/baselines/reference/uniqueSymbols.types index 7bf4b7fdf4a..9ee3be1cb28 100644 --- a/tests/baselines/reference/uniqueSymbols.types +++ b/tests/baselines/reference/uniqueSymbols.types @@ -85,6 +85,13 @@ const constInitToConstDeclAmbientWithTypeQuery: typeof constType = constType; >constType : unique symbol >constType : unique symbol +// assignment from any +// https://github.com/Microsoft/TypeScript/issues/29108 +const fromAny: unique symbol = {} as any; +>fromAny : unique symbol +>{} as any : any +>{} : {} + // function return inference function funcReturnConstCall() { return constCall; } >funcReturnConstCall : () => symbol diff --git a/tests/cases/conformance/types/uniqueSymbol/uniqueSymbols.ts b/tests/cases/conformance/types/uniqueSymbol/uniqueSymbols.ts index 498a1c2904d..59d00a55ed9 100644 --- a/tests/cases/conformance/types/uniqueSymbol/uniqueSymbols.ts +++ b/tests/cases/conformance/types/uniqueSymbol/uniqueSymbols.ts @@ -31,6 +31,10 @@ var varInitToConstDeclAmbient = constType; const constInitToConstCallWithTypeQuery: typeof constCall = constCall; const constInitToConstDeclAmbientWithTypeQuery: typeof constType = constType; +// assignment from any +// https://github.com/Microsoft/TypeScript/issues/29108 +const fromAny: unique symbol = {} as any; + // function return inference function funcReturnConstCall() { return constCall; } function funcReturnLetCall() { return letCall; } From 104434182b6bf0922920b935ad8a083201fd8ed7 Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Mon, 14 Jan 2019 17:01:46 -0800 Subject: [PATCH 92/96] Harden telemetryOnOpenFile against disabled projects As for syntax-only servers, we can't meaningfully report open-file telemetry for projects with disabled language services. Hopefully, a deeper fix will follow, but this solves the immediate problem that VS disables the LS for all projects when it sees a failure in applyChangedToOpenFiles (because it assumes the server state is corrupt). --- src/server/editorServices.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index cd1c69a2d67..3e062efc272 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -2777,7 +2777,12 @@ namespace ts.server { return; } - const info: OpenFileInfo = { checkJs: !!scriptInfo.getDefaultProject().getSourceFile(scriptInfo.path)!.checkJsDirective }; + const project = scriptInfo.getDefaultProject(); + if (!project.languageServiceEnabled) { + return; + } + + const info: OpenFileInfo = { checkJs: !!project.getSourceFile(scriptInfo.path)!.checkJsDirective }; this.eventHandler({ eventName: OpenFileInfoTelemetryEvent, data: { info } }); } From b86cb27d0b222f1cadb00e391928923c26244257 Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Mon, 14 Jan 2019 18:13:13 -0800 Subject: [PATCH 93/96] Fix trailing whitespace --- src/server/editorServices.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 3e062efc272..bc8197f9354 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -2780,7 +2780,7 @@ namespace ts.server { const project = scriptInfo.getDefaultProject(); if (!project.languageServiceEnabled) { return; - } + } const info: OpenFileInfo = { checkJs: !!project.getSourceFile(scriptInfo.path)!.checkJsDirective }; this.eventHandler({ eventName: OpenFileInfoTelemetryEvent, data: { info } }); From 3fb09630a82c3f94e47ec37515cb0733b6cfcdb5 Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Tue, 15 Jan 2019 10:55:15 -0800 Subject: [PATCH 94/96] Add regression test --- src/testRunner/unittests/tsserver/projects.ts | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/testRunner/unittests/tsserver/projects.ts b/src/testRunner/unittests/tsserver/projects.ts index 00941a1d3c9..3a648c9189e 100644 --- a/src/testRunner/unittests/tsserver/projects.ts +++ b/src/testRunner/unittests/tsserver/projects.ts @@ -103,6 +103,30 @@ namespace ts.projectSystem { assert.isFalse(proj3.languageServiceEnabled); }); + it("should not crash when opening a file in a project with a disabled language service", () => { + const file1 = { + path: "/a/b/f1.js", + content: "let x =1;", + fileSize: 50 * 1024 * 1024 + }; + const file2 = { + path: "/a/b/f2.js", + content: "let x =1;", + fileSize: 100 + }; + + const projName = "proj1"; + + const host = createServerHost([file1, file2]); + const projectService = createProjectService(host, { useSingleInferredProject: true }, { eventHandler: noop }); + + projectService.openExternalProject({ rootFiles: toExternalFiles([file1.path, file2.path]), options: {}, projectFileName: projName }); + const proj1 = projectService.findProject(projName)!; + assert.isFalse(proj1.languageServiceEnabled); + + assert.doesNotThrow(() => projectService.openClientFile(file2.path)); + }); + describe("ignoreConfigFiles", () => { it("external project including config file", () => { const file1 = { From 49689894d747714d6b2b8461b9033020efec9625 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 15 Jan 2019 11:32:36 -0800 Subject: [PATCH 95/96] Elaborate jsx children elementwise (#29264) * Heavy WIP, but has good contextual typing fix * Add arity error, refine messages and spans * Small error message change * Better error messages, text-specific message --- src/compiler/checker.ts | 133 ++++++++++++- src/compiler/diagnosticMessages.json | 12 ++ src/compiler/utilities.ts | 3 +- .../checkJsxChildrenProperty14.errors.txt | 8 +- .../checkJsxChildrenProperty2.errors.txt | 40 +--- .../checkJsxChildrenProperty4.errors.txt | 27 ++- .../checkJsxChildrenProperty5.errors.txt | 22 +-- .../checkJsxChildrenProperty7.errors.txt | 40 +--- ...sxFactoryDeclarationsLocalTypes.errors.txt | 32 ++- ...xChildrenGenericContextualTypes.errors.txt | 30 +-- ...drenIndividualErrorElaborations.errors.txt | 128 ++++++++++++ .../jsxChildrenIndividualErrorElaborations.js | 119 ++++++++++++ ...hildrenIndividualErrorElaborations.symbols | 169 ++++++++++++++++ ...xChildrenIndividualErrorElaborations.types | 183 ++++++++++++++++++ ...jsxChildrenIndividualErrorElaborations.tsx | 78 ++++++++ 15 files changed, 883 insertions(+), 141 deletions(-) create mode 100644 tests/baselines/reference/jsxChildrenIndividualErrorElaborations.errors.txt create mode 100644 tests/baselines/reference/jsxChildrenIndividualErrorElaborations.js create mode 100644 tests/baselines/reference/jsxChildrenIndividualErrorElaborations.symbols create mode 100644 tests/baselines/reference/jsxChildrenIndividualErrorElaborations.types create mode 100644 tests/cases/compiler/jsxChildrenIndividualErrorElaborations.tsx diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f365af51ac6..ab460212d53 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11196,7 +11196,7 @@ namespace ts { case SyntaxKind.ArrayLiteralExpression: return elaborateArrayLiteral(node as ArrayLiteralExpression, source, target, relation); case SyntaxKind.JsxAttributes: - return elaborateJsxAttributes(node as JsxAttributes, source, target, relation); + return elaborateJsxComponents(node as JsxAttributes, source, target, relation); case SyntaxKind.ArrowFunction: return elaborateArrowFunction(node as ArrowFunction, source, target, relation); } @@ -11336,8 +11336,113 @@ namespace ts { } } - function elaborateJsxAttributes(node: JsxAttributes, source: Type, target: Type, relation: Map) { - return elaborateElementwise(generateJsxAttributes(node), source, target, relation); + function *generateJsxChildren(node: JsxElement, getInvalidTextDiagnostic: () => DiagnosticMessage): ElaborationIterator { + if (!length(node.children)) return; + let memberOffset = 0; + for (let i = 0; i < node.children.length; i++) { + const child = node.children[i]; + const nameType = getLiteralType(i - memberOffset); + const elem = getElaborationElementForJsxChild(child, nameType, getInvalidTextDiagnostic); + if (elem) { + yield elem; + } + else { + memberOffset++; + } + } + } + + function getElaborationElementForJsxChild(child: JsxChild, nameType: LiteralType, getInvalidTextDiagnostic: () => DiagnosticMessage) { + switch (child.kind) { + case SyntaxKind.JsxExpression: + // child is of the type of the expression + return { errorNode: child, innerExpression: child.expression, nameType }; + case SyntaxKind.JsxText: + if (child.containsOnlyWhiteSpaces) { + break; // Whitespace only jsx text isn't real jsx text + } + // child is a string + return { errorNode: child, innerExpression: undefined, nameType, errorMessage: getInvalidTextDiagnostic() }; + case SyntaxKind.JsxElement: + case SyntaxKind.JsxSelfClosingElement: + case SyntaxKind.JsxFragment: + // child is of type JSX.Element + return { errorNode: child, innerExpression: child, nameType }; + default: + return Debug.assertNever(child, "Found invalid jsx child"); + } + } + + function elaborateJsxComponents(node: JsxAttributes, source: Type, target: Type, relation: Map) { + let result = elaborateElementwise(generateJsxAttributes(node), source, target, relation); + let invalidTextDiagnostic: DiagnosticMessage | undefined; + if (isJsxOpeningElement(node.parent) && isJsxElement(node.parent.parent)) { + const containingElement = node.parent.parent; + const childPropName = getJsxElementChildrenPropertyName(getJsxNamespaceAt(node)); + const childrenPropName = childPropName === undefined ? "children" : unescapeLeadingUnderscores(childPropName); + const childrenNameType = getLiteralType(childrenPropName); + const childrenTargetType = getIndexedAccessType(target, childrenNameType); + const validChildren = filter(containingElement.children, i => !isJsxText(i) || !i.containsOnlyWhiteSpaces); + if (!length(validChildren)) { + return result; + } + const moreThanOneRealChildren = length(validChildren) > 1; + const arrayLikeTargetParts = filterType(childrenTargetType, isArrayOrTupleLikeType); + const nonArrayLikeTargetParts = filterType(childrenTargetType, t => !isArrayOrTupleLikeType(t)); + if (moreThanOneRealChildren) { + if (arrayLikeTargetParts !== neverType) { + const realSource = createTupleType(checkJsxChildren(containingElement, CheckMode.Normal)); + result = elaborateElementwise(generateJsxChildren(containingElement, getInvalidTextualChildDiagnostic), realSource, arrayLikeTargetParts, relation) || result; + } + else if (!isTypeRelatedTo(getIndexedAccessType(source, childrenNameType), childrenTargetType, relation)) { + // arity mismatch + result = true; + error( + containingElement.openingElement.tagName, + Diagnostics.This_JSX_tag_s_0_prop_expects_a_single_child_of_type_1_but_multiple_children_were_provided, + childrenPropName, + typeToString(childrenTargetType) + ); + } + } + else { + if (nonArrayLikeTargetParts !== neverType) { + const child = validChildren[0]; + const elem = getElaborationElementForJsxChild(child, childrenNameType, getInvalidTextualChildDiagnostic); + if (elem) { + result = elaborateElementwise( + (function*() { yield elem; })(), + source, + target, + relation + ) || result; + } + } + else if (!isTypeRelatedTo(getIndexedAccessType(source, childrenNameType), childrenTargetType, relation)) { + // arity mismatch + result = true; + error( + containingElement.openingElement.tagName, + Diagnostics.This_JSX_tag_s_0_prop_expects_type_1_which_requires_multiple_children_but_only_a_single_child_was_provided, + childrenPropName, + typeToString(childrenTargetType) + ); + } + } + } + return result; + + function getInvalidTextualChildDiagnostic() { + if (!invalidTextDiagnostic) { + const tagNameText = getTextOfNode(node.parent.tagName); + const childPropName = getJsxElementChildrenPropertyName(getJsxNamespaceAt(node)); + const childrenPropName = childPropName === undefined ? "children" : unescapeLeadingUnderscores(childPropName); + const childrenTargetType = getIndexedAccessType(target, getLiteralType(childrenPropName)); + const diagnostic = Diagnostics._0_components_don_t_accept_text_as_child_elements_Text_in_JSX_has_the_type_string_but_the_expected_type_of_1_is_2; + invalidTextDiagnostic = { ...diagnostic, key: "!!ALREADY FORMATTED!!", message: formatMessage(/*_dummy*/ undefined, diagnostic, tagNameText, childrenPropName, typeToString(childrenTargetType)) }; + } + return invalidTextDiagnostic; + } } function *generateLimitedTupleElements(node: ArrayLiteralExpression, target: Type): ElaborationIterator { @@ -13477,6 +13582,10 @@ namespace ts { return isTupleType(type) || !!getPropertyOfType(type, "0" as __String); } + function isArrayOrTupleLikeType(type: Type): boolean { + return isArrayLikeType(type) || isTupleLikeType(type); + } + function getTupleElementType(type: Type, index: number) { const propType = getTypeOfPropertyOfType(type, "" + index as __String); if (propType) { @@ -17492,11 +17601,23 @@ namespace ts { return node === conditional.whenTrue || node === conditional.whenFalse ? getContextualType(conditional) : undefined; } - function getContextualTypeForChildJsxExpression(node: JsxElement) { + function getContextualTypeForChildJsxExpression(node: JsxElement, child: JsxChild) { const attributesType = getApparentTypeOfContextualType(node.openingElement.tagName); // JSX expression is in children of JSX Element, we will look for an "children" atttribute (we get the name from JSX.ElementAttributesProperty) const jsxChildrenPropertyName = getJsxElementChildrenPropertyName(getJsxNamespaceAt(node)); - return attributesType && !isTypeAny(attributesType) && jsxChildrenPropertyName && jsxChildrenPropertyName !== "" ? getTypeOfPropertyOfContextualType(attributesType, jsxChildrenPropertyName) : undefined; + if (!(attributesType && !isTypeAny(attributesType) && jsxChildrenPropertyName && jsxChildrenPropertyName !== "")) { + return undefined; + } + const childIndex = node.children.indexOf(child); + const childFieldType = getTypeOfPropertyOfContextualType(attributesType, jsxChildrenPropertyName); + return childFieldType && mapType(childFieldType, t => { + if (isArrayLikeType(t)) { + return getIndexedAccessType(t, getLiteralType(childIndex)); + } + else { + return t; + } + }, /*noReductions*/ true); } function getContextualTypeForJsxExpression(node: JsxExpression): Type | undefined { @@ -17504,7 +17625,7 @@ namespace ts { return isJsxAttributeLike(exprParent) ? getContextualType(node) : isJsxElement(exprParent) - ? getContextualTypeForChildJsxExpression(exprParent) + ? getContextualTypeForChildJsxExpression(exprParent, node) : undefined; } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 4e99c001d80..a4bd48e8562 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2541,6 +2541,18 @@ "category": "Error", "code": 2744 }, + "This JSX tag's '{0}' prop expects type '{1}' which requires multiple children, but only a single child was provided.": { + "category": "Error", + "code": 2745 + }, + "This JSX tag's '{0}' prop expects a single child of type '{1}', but multiple children were provided.": { + "category": "Error", + "code": 2746 + }, + "'{0}' components don't accept text as child elements. Text in JSX has the type 'string', but the expected type of '{1}' is '{2}'.": { + "category": "Error", + "code": 2747 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 9c6b27de13c..33a902b8035 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -888,7 +888,7 @@ namespace ts { } const isMissing = nodeIsMissing(errorNode); - const pos = isMissing + const pos = isMissing || isJsxText(node) ? errorNode.pos : skipTrivia(sourceFile.text, errorNode.pos); @@ -7024,6 +7024,7 @@ namespace ts { }; } + export function formatMessage(_dummy: any, message: DiagnosticMessage, ...args: (string | number | undefined)[]): string; export function formatMessage(_dummy: any, message: DiagnosticMessage): string { let text = getLocaleSpecificMessage(message); diff --git a/tests/baselines/reference/checkJsxChildrenProperty14.errors.txt b/tests/baselines/reference/checkJsxChildrenProperty14.errors.txt index b401345a5e1..0f44d023a76 100644 --- a/tests/baselines/reference/checkJsxChildrenProperty14.errors.txt +++ b/tests/baselines/reference/checkJsxChildrenProperty14.errors.txt @@ -1,6 +1,4 @@ -tests/cases/conformance/jsx/file.tsx(42,11): error TS2322: Type '{ children: Element[]; a: number; b: string; }' is not assignable to type 'SingleChildProp'. - Types of property 'children' are incompatible. - Type 'Element[]' is missing the following properties from type 'Element': type, props +tests/cases/conformance/jsx/file.tsx(42,11): error TS2746: This JSX tag's 'children' prop expects a single child of type 'Element', but multiple children were provided. ==== tests/cases/conformance/jsx/file.tsx (1 errors) ==== @@ -47,6 +45,4 @@ tests/cases/conformance/jsx/file.tsx(42,11): error TS2322: Type '{ children: Ele // Error let k5 = <>