From 2c7b39aa4467eaeaa28d5650d286ff7e49e3f9f8 Mon Sep 17 00:00:00 2001 From: Alexander T Date: Thu, 5 Jul 2018 11:04:04 +0300 Subject: [PATCH 1/5] 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 207d731707878..669938b597dcb 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 40a4c4d09d402..75e2d35c47172 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 99452b93d4763..a251e4d936116 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 4675136d0817f..2d29884065ca8 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 2/5] 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 7561255c25b28..02efec7ba1377 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 da81894887026..365014ab3189c 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 2d29884065ca8..bebe3f45940e4 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 0000000000000..96d2f55ed274d --- /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 0000000000000..37f127721cef6 --- /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 0000000000000..071f2fb5725e7 --- /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 0000000000000..652d7d6241b64 --- /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 0000000000000..ee3e9cfff172d --- /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 0000000000000..603f158946e94 --- /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 0000000000000..071f2fb5725e7 --- /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 0000000000000..652d7d6241b64 --- /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 0000000000000..577e606c249f9 --- /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 0000000000000..a5505b0e90e57 --- /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 332c88e57db6a5450b2aae3ef0465d134daffdbc Mon Sep 17 00:00:00 2001 From: Alexander T Date: Tue, 18 Dec 2018 10:39:32 +0200 Subject: [PATCH 3/5] 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 f451c91046b53..b70d5cf876b62 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 907940c4f6a62..a27aa17efb929 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 4/5] 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 bebe3f45940e4..986aae2245fcb 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 96d2f55ed274d..1c19b4c31044b 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 ee3e9cfff172d..4aa467f8b6ada 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 945eed8d9bfd8fd5c2c218c6cb92720bef61e971 Mon Sep 17 00:00:00 2001 From: Alexander T Date: Tue, 8 Jan 2019 10:54:08 +0200 Subject: [PATCH 5/5] 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 d213e4e01bf74..061a6110afc39 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 cccb3dcb98333..136e601dbe81f 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 986aae2245fcb..5b8e83b3cca54 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 1c19b4c31044b..3d8301d3ca1b7 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 4aa467f8b6ada..94c05e068f5f8 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;