diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e0672300f1cd4..c78879af04e23 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2538,7 +2538,7 @@ namespace ts { ); } else { - reportNonExportedMember(name, declarationName, moduleSymbol, moduleName); + reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName); } } } @@ -2547,27 +2547,50 @@ namespace ts { } } - function reportNonExportedMember(name: Identifier, declarationName: string, moduleSymbol: Symbol, moduleName: string): void { + function reportNonExportedMember(node: ImportDeclaration | ExportDeclaration, name: Identifier, declarationName: string, moduleSymbol: Symbol, moduleName: string): void { const localSymbol = moduleSymbol.valueDeclaration.locals?.get(name.escapedText); const exports = moduleSymbol.exports; - if (localSymbol) { - const exportedSymbol = exports && !exports.has(InternalSymbolName.ExportEquals) - ? find(symbolsToArray(exports), symbol => !!getSymbolIfSameReference(symbol, localSymbol)) - : undefined; - const diagnostic = exportedSymbol - ? error(name, Diagnostics.Module_0_declares_1_locally_but_it_is_exported_as_2, moduleName, declarationName, symbolToString(exportedSymbol)) - : error(name, Diagnostics.Module_0_declares_1_locally_but_it_is_not_exported, moduleName, declarationName); + const exportedEqualsSymbol = exports?.get(InternalSymbolName.ExportEquals); + if (exportedEqualsSymbol) { + getSymbolIfSameReference(exportedEqualsSymbol, localSymbol) ? reportInvalidImportEqualsExportMember(node, name, declarationName, moduleName) : + error(name, Diagnostics.Module_0_has_no_exported_member_1, moduleName, declarationName); + } + else { + const exportedSymbol = exports ? find(symbolsToArray(exports), symbol => !!getSymbolIfSameReference(symbol, localSymbol)) : undefined; + const diagnostic = exportedSymbol ? error(name, Diagnostics.Module_0_declares_1_locally_but_it_is_exported_as_2, moduleName, declarationName, symbolToString(exportedSymbol)) : + error(name, Diagnostics.Module_0_declares_1_locally_but_it_is_not_exported, moduleName, declarationName); - addRelatedInfo(diagnostic, - ...map(localSymbol.declarations, (decl, index) => - createDiagnosticForNode(decl, index === 0 ? Diagnostics._0_is_declared_here : Diagnostics.and_here, declarationName))); + addRelatedInfo(diagnostic, + ...map(localSymbol.declarations, (decl, index) => + createDiagnosticForNode(decl, index === 0 ? Diagnostics._0_is_declared_here : Diagnostics.and_here, declarationName))); + } } else { error(name, Diagnostics.Module_0_has_no_exported_member_1, moduleName, declarationName); } } + function reportInvalidImportEqualsExportMember(node: ImportDeclaration | ExportDeclaration, name: Identifier, declarationName: string, moduleName: string) { + if (moduleKind >= ModuleKind.ES2015) { + const message = compilerOptions.esModuleInterop ? Diagnostics._0_can_only_be_imported_by_using_a_default_import : + Diagnostics._0_can_only_be_imported_by_turning_on_the_esModuleInterop_flag_and_using_a_default_import; + error(name, message, declarationName); + } + else { + if (isInJSFile(node)) { + const message = compilerOptions.esModuleInterop ? Diagnostics._0_can_only_be_imported_by_using_a_require_call_or_by_using_a_default_import : + Diagnostics._0_can_only_be_imported_by_using_a_require_call_or_by_turning_on_the_esModuleInterop_flag_and_using_a_default_import; + error(name, message, declarationName); + } + else { + const message = compilerOptions.esModuleInterop ? Diagnostics._0_can_only_be_imported_by_using_import_1_require_2_or_a_default_import : + Diagnostics._0_can_only_be_imported_by_using_import_1_require_2_or_by_turning_on_the_esModuleInterop_flag_and_using_a_default_import; + error(name, message, declarationName, declarationName, moduleName); + } + } + } + function getTargetOfImportSpecifier(node: ImportSpecifier, dontResolveAlias: boolean): Symbol | undefined { const resolved = getExternalModuleMember(node.parent.parent.parent, node, dontResolveAlias); markSymbolOfAliasDeclarationIfTypeOnly(node, /*immediateTarget*/ undefined, resolved, /*overwriteEmpty*/ false); diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 195fc43dbb12d..4ef85296ef69a 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2317,6 +2317,22 @@ "category": "Error", "code": 2594 }, + "'{0}' can only be imported by using a default import.": { + "category": "Error", + "code": 2595 + }, + "'{0}' can only be imported by turning on the 'esModuleInterop' flag and using a default import.": { + "category": "Error", + "code": 2596 + }, + "'{0}' can only be imported by using a 'require' call or by using a default import.": { + "category": "Error", + "code": 2597 + }, + "'{0}' can only be imported by using a 'require' call or by turning on the 'esModuleInterop' flag and using a default import.": { + "category": "Error", + "code": 2598 + }, "JSX element attributes type '{0}' may not be a union type.": { "category": "Error", "code": 2600 @@ -2381,6 +2397,14 @@ "category": "Error", "code": 2615 }, + "'{0}' can only be imported by using 'import {1} = require({2})' or a default import.": { + "category": "Error", + "code": 2616 + }, + "'{0}' can only be imported by using 'import {1} = require({2})' or by turning on the 'esModuleInterop' flag and using a default import.": { + "category": "Error", + "code": 2617 + }, "Cannot augment module '{0}' with value exports because it resolves to a non-module entity.": { "category": "Error", diff --git a/tests/baselines/reference/es6ImportNamedImportNoNamedExports.errors.txt b/tests/baselines/reference/es6ImportNamedImportNoNamedExports.errors.txt index 1219ff6255186..63ea04644c60a 100644 --- a/tests/baselines/reference/es6ImportNamedImportNoNamedExports.errors.txt +++ b/tests/baselines/reference/es6ImportNamedImportNoNamedExports.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/es6ImportNamedImportNoNamedExports_1.ts(1,10): error TS2459: Module '"./es6ImportNamedImportNoNamedExports_0"' declares 'a' locally, but it is not exported. -tests/cases/compiler/es6ImportNamedImportNoNamedExports_1.ts(2,10): error TS2459: Module '"./es6ImportNamedImportNoNamedExports_0"' declares 'a' locally, but it is not exported. +tests/cases/compiler/es6ImportNamedImportNoNamedExports_1.ts(1,10): error TS2617: 'a' can only be imported by using 'import a = require("./es6ImportNamedImportNoNamedExports_0")' or by turning on the 'esModuleInterop' flag and using a default import. +tests/cases/compiler/es6ImportNamedImportNoNamedExports_1.ts(2,10): error TS2617: 'a' can only be imported by using 'import a = require("./es6ImportNamedImportNoNamedExports_0")' or by turning on the 'esModuleInterop' flag and using a default import. ==== tests/cases/compiler/es6ImportNamedImportNoNamedExports_0.ts (0 errors) ==== @@ -9,9 +9,7 @@ tests/cases/compiler/es6ImportNamedImportNoNamedExports_1.ts(2,10): error TS2459 ==== tests/cases/compiler/es6ImportNamedImportNoNamedExports_1.ts (2 errors) ==== import { a } from "./es6ImportNamedImportNoNamedExports_0"; ~ -!!! error TS2459: Module '"./es6ImportNamedImportNoNamedExports_0"' declares 'a' locally, but it is not exported. -!!! related TS2728 tests/cases/compiler/es6ImportNamedImportNoNamedExports_0.ts:1:5: 'a' is declared here. +!!! error TS2617: 'a' can only be imported by using 'import a = require("./es6ImportNamedImportNoNamedExports_0")' or by turning on the 'esModuleInterop' flag and using a default import. import { a as x } from "./es6ImportNamedImportNoNamedExports_0"; ~ -!!! error TS2459: Module '"./es6ImportNamedImportNoNamedExports_0"' declares 'a' locally, but it is not exported. -!!! related TS2728 tests/cases/compiler/es6ImportNamedImportNoNamedExports_0.ts:1:5: 'a' is declared here. \ No newline at end of file +!!! error TS2617: 'a' can only be imported by using 'import a = require("./es6ImportNamedImportNoNamedExports_0")' or by turning on the 'esModuleInterop' flag and using a default import. \ No newline at end of file diff --git a/tests/baselines/reference/importNonExportedMember10.errors.txt b/tests/baselines/reference/importNonExportedMember10.errors.txt new file mode 100644 index 0000000000000..72cb0c6a99e5b --- /dev/null +++ b/tests/baselines/reference/importNonExportedMember10.errors.txt @@ -0,0 +1,17 @@ +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/b.js(1,10): error TS2596: 'Foo' can only be imported by turning on the 'esModuleInterop' flag and using a default import. +tests/cases/compiler/b.js(1,21): 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) ==== + class Foo {} + export = Foo; + ~~~~~~~~~~~~~ +!!! error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead. + +==== tests/cases/compiler/b.js (2 errors) ==== + import { Foo } from './a'; + ~~~ +!!! error TS2596: 'Foo' can only be imported 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 'allowSyntheticDefaultImports' flag and referencing its default export. \ No newline at end of file diff --git a/tests/baselines/reference/importNonExportedMember10.symbols b/tests/baselines/reference/importNonExportedMember10.symbols new file mode 100644 index 0000000000000..54ef501ecdce5 --- /dev/null +++ b/tests/baselines/reference/importNonExportedMember10.symbols @@ -0,0 +1,11 @@ +=== tests/cases/compiler/a.ts === +class Foo {} +>Foo : Symbol(Foo, Decl(a.ts, 0, 0)) + +export = Foo; +>Foo : Symbol(Foo, Decl(a.ts, 0, 0)) + +=== tests/cases/compiler/b.js === +import { Foo } from './a'; +>Foo : Symbol(Foo, Decl(b.js, 0, 8)) + diff --git a/tests/baselines/reference/importNonExportedMember10.types b/tests/baselines/reference/importNonExportedMember10.types new file mode 100644 index 0000000000000..ca9cc044c2d16 --- /dev/null +++ b/tests/baselines/reference/importNonExportedMember10.types @@ -0,0 +1,11 @@ +=== tests/cases/compiler/a.ts === +class Foo {} +>Foo : Foo + +export = Foo; +>Foo : Foo + +=== tests/cases/compiler/b.js === +import { Foo } from './a'; +>Foo : any + diff --git a/tests/baselines/reference/importNonExportedMember11.errors.txt b/tests/baselines/reference/importNonExportedMember11.errors.txt new file mode 100644 index 0000000000000..d1b77038a8314 --- /dev/null +++ b/tests/baselines/reference/importNonExportedMember11.errors.txt @@ -0,0 +1,17 @@ +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/b.js(1,10): error TS2595: 'Foo' can only be imported by using a default import. +tests/cases/compiler/b.js(1,21): 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) ==== + class Foo {} + export = Foo; + ~~~~~~~~~~~~~ +!!! error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead. + +==== tests/cases/compiler/b.js (2 errors) ==== + import { Foo } from './a'; + ~~~ +!!! error TS2595: 'Foo' can only be imported by 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. \ No newline at end of file diff --git a/tests/baselines/reference/importNonExportedMember11.symbols b/tests/baselines/reference/importNonExportedMember11.symbols new file mode 100644 index 0000000000000..54ef501ecdce5 --- /dev/null +++ b/tests/baselines/reference/importNonExportedMember11.symbols @@ -0,0 +1,11 @@ +=== tests/cases/compiler/a.ts === +class Foo {} +>Foo : Symbol(Foo, Decl(a.ts, 0, 0)) + +export = Foo; +>Foo : Symbol(Foo, Decl(a.ts, 0, 0)) + +=== tests/cases/compiler/b.js === +import { Foo } from './a'; +>Foo : Symbol(Foo, Decl(b.js, 0, 8)) + diff --git a/tests/baselines/reference/importNonExportedMember11.types b/tests/baselines/reference/importNonExportedMember11.types new file mode 100644 index 0000000000000..ca9cc044c2d16 --- /dev/null +++ b/tests/baselines/reference/importNonExportedMember11.types @@ -0,0 +1,11 @@ +=== tests/cases/compiler/a.ts === +class Foo {} +>Foo : Foo + +export = Foo; +>Foo : Foo + +=== tests/cases/compiler/b.js === +import { Foo } from './a'; +>Foo : any + diff --git a/tests/baselines/reference/importNonExportedMember4.errors.txt b/tests/baselines/reference/importNonExportedMember4.errors.txt new file mode 100644 index 0000000000000..96623c4fba96c --- /dev/null +++ b/tests/baselines/reference/importNonExportedMember4.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/b.ts(1,10): error TS2617: 'Foo' can only be imported by using 'import Foo = require("./a")' or by turning on the 'esModuleInterop' flag and using a default import. +tests/cases/compiler/b.ts(1,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/a.ts (0 errors) ==== + class Foo {} + export = Foo; + +==== tests/cases/compiler/b.ts (2 errors) ==== + import { Foo } from './a'; + ~~~ +!!! error TS2617: 'Foo' can only be imported by using 'import Foo = require("./a")' or 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. \ No newline at end of file diff --git a/tests/baselines/reference/importNonExportedMember4.js b/tests/baselines/reference/importNonExportedMember4.js new file mode 100644 index 0000000000000..3ea1c65f35c38 --- /dev/null +++ b/tests/baselines/reference/importNonExportedMember4.js @@ -0,0 +1,20 @@ +//// [tests/cases/compiler/importNonExportedMember4.ts] //// + +//// [a.ts] +class Foo {} +export = Foo; + +//// [b.ts] +import { Foo } from './a'; + +//// [a.js] +"use strict"; +var Foo = /** @class */ (function () { + function Foo() { + } + return Foo; +}()); +module.exports = Foo; +//// [b.js] +"use strict"; +exports.__esModule = true; diff --git a/tests/baselines/reference/importNonExportedMember4.symbols b/tests/baselines/reference/importNonExportedMember4.symbols new file mode 100644 index 0000000000000..ebe40a13da5f7 --- /dev/null +++ b/tests/baselines/reference/importNonExportedMember4.symbols @@ -0,0 +1,11 @@ +=== tests/cases/compiler/a.ts === +class Foo {} +>Foo : Symbol(Foo, Decl(a.ts, 0, 0)) + +export = Foo; +>Foo : Symbol(Foo, Decl(a.ts, 0, 0)) + +=== tests/cases/compiler/b.ts === +import { Foo } from './a'; +>Foo : Symbol(Foo, Decl(b.ts, 0, 8)) + diff --git a/tests/baselines/reference/importNonExportedMember4.types b/tests/baselines/reference/importNonExportedMember4.types new file mode 100644 index 0000000000000..7668201a247f5 --- /dev/null +++ b/tests/baselines/reference/importNonExportedMember4.types @@ -0,0 +1,11 @@ +=== tests/cases/compiler/a.ts === +class Foo {} +>Foo : Foo + +export = Foo; +>Foo : Foo + +=== tests/cases/compiler/b.ts === +import { Foo } from './a'; +>Foo : any + diff --git a/tests/baselines/reference/importNonExportedMember5.errors.txt b/tests/baselines/reference/importNonExportedMember5.errors.txt new file mode 100644 index 0000000000000..b5754d1b84f00 --- /dev/null +++ b/tests/baselines/reference/importNonExportedMember5.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/b.ts(1,10): error TS2616: 'Foo' can only be imported by using 'import Foo = require("./a")' or a default import. +tests/cases/compiler/b.ts(1,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/a.ts (0 errors) ==== + class Foo {} + export = Foo; + +==== tests/cases/compiler/b.ts (2 errors) ==== + import { Foo } from './a'; + ~~~ +!!! error TS2616: 'Foo' can only be imported by using 'import Foo = require("./a")' or 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. \ No newline at end of file diff --git a/tests/baselines/reference/importNonExportedMember5.js b/tests/baselines/reference/importNonExportedMember5.js new file mode 100644 index 0000000000000..4ed4eb74948c5 --- /dev/null +++ b/tests/baselines/reference/importNonExportedMember5.js @@ -0,0 +1,20 @@ +//// [tests/cases/compiler/importNonExportedMember5.ts] //// + +//// [a.ts] +class Foo {} +export = Foo; + +//// [b.ts] +import { Foo } from './a'; + +//// [a.js] +"use strict"; +var Foo = /** @class */ (function () { + function Foo() { + } + return Foo; +}()); +module.exports = Foo; +//// [b.js] +"use strict"; +exports.__esModule = true; diff --git a/tests/baselines/reference/importNonExportedMember5.symbols b/tests/baselines/reference/importNonExportedMember5.symbols new file mode 100644 index 0000000000000..ebe40a13da5f7 --- /dev/null +++ b/tests/baselines/reference/importNonExportedMember5.symbols @@ -0,0 +1,11 @@ +=== tests/cases/compiler/a.ts === +class Foo {} +>Foo : Symbol(Foo, Decl(a.ts, 0, 0)) + +export = Foo; +>Foo : Symbol(Foo, Decl(a.ts, 0, 0)) + +=== tests/cases/compiler/b.ts === +import { Foo } from './a'; +>Foo : Symbol(Foo, Decl(b.ts, 0, 8)) + diff --git a/tests/baselines/reference/importNonExportedMember5.types b/tests/baselines/reference/importNonExportedMember5.types new file mode 100644 index 0000000000000..7668201a247f5 --- /dev/null +++ b/tests/baselines/reference/importNonExportedMember5.types @@ -0,0 +1,11 @@ +=== tests/cases/compiler/a.ts === +class Foo {} +>Foo : Foo + +export = Foo; +>Foo : Foo + +=== tests/cases/compiler/b.ts === +import { Foo } from './a'; +>Foo : any + diff --git a/tests/baselines/reference/importNonExportedMember6.errors.txt b/tests/baselines/reference/importNonExportedMember6.errors.txt new file mode 100644 index 0000000000000..0685e3c0e99d5 --- /dev/null +++ b/tests/baselines/reference/importNonExportedMember6.errors.txt @@ -0,0 +1,17 @@ +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/b.ts(1,10): error TS2596: 'Foo' can only be imported by turning on the 'esModuleInterop' flag and using a default import. +tests/cases/compiler/b.ts(1,21): 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) ==== + class Foo {} + export = Foo; + ~~~~~~~~~~~~~ +!!! error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead. + +==== tests/cases/compiler/b.ts (2 errors) ==== + import { Foo } from './a'; + ~~~ +!!! error TS2596: 'Foo' can only be imported 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 'allowSyntheticDefaultImports' flag and referencing its default export. \ No newline at end of file diff --git a/tests/baselines/reference/importNonExportedMember6.js b/tests/baselines/reference/importNonExportedMember6.js new file mode 100644 index 0000000000000..9866fbd54b00e --- /dev/null +++ b/tests/baselines/reference/importNonExportedMember6.js @@ -0,0 +1,16 @@ +//// [tests/cases/compiler/importNonExportedMember6.ts] //// + +//// [a.ts] +class Foo {} +export = Foo; + +//// [b.ts] +import { Foo } from './a'; + +//// [a.js] +var Foo = /** @class */ (function () { + function Foo() { + } + return Foo; +}()); +//// [b.js] diff --git a/tests/baselines/reference/importNonExportedMember6.symbols b/tests/baselines/reference/importNonExportedMember6.symbols new file mode 100644 index 0000000000000..ebe40a13da5f7 --- /dev/null +++ b/tests/baselines/reference/importNonExportedMember6.symbols @@ -0,0 +1,11 @@ +=== tests/cases/compiler/a.ts === +class Foo {} +>Foo : Symbol(Foo, Decl(a.ts, 0, 0)) + +export = Foo; +>Foo : Symbol(Foo, Decl(a.ts, 0, 0)) + +=== tests/cases/compiler/b.ts === +import { Foo } from './a'; +>Foo : Symbol(Foo, Decl(b.ts, 0, 8)) + diff --git a/tests/baselines/reference/importNonExportedMember6.types b/tests/baselines/reference/importNonExportedMember6.types new file mode 100644 index 0000000000000..7668201a247f5 --- /dev/null +++ b/tests/baselines/reference/importNonExportedMember6.types @@ -0,0 +1,11 @@ +=== tests/cases/compiler/a.ts === +class Foo {} +>Foo : Foo + +export = Foo; +>Foo : Foo + +=== tests/cases/compiler/b.ts === +import { Foo } from './a'; +>Foo : any + diff --git a/tests/baselines/reference/importNonExportedMember7.errors.txt b/tests/baselines/reference/importNonExportedMember7.errors.txt new file mode 100644 index 0000000000000..bcc8c481b4ec8 --- /dev/null +++ b/tests/baselines/reference/importNonExportedMember7.errors.txt @@ -0,0 +1,17 @@ +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/b.ts(1,10): error TS2595: 'Foo' can only be imported by using a default import. +tests/cases/compiler/b.ts(1,21): 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) ==== + class Foo {} + export = Foo; + ~~~~~~~~~~~~~ +!!! error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead. + +==== tests/cases/compiler/b.ts (2 errors) ==== + import { Foo } from './a'; + ~~~ +!!! error TS2595: 'Foo' can only be imported by 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. \ No newline at end of file diff --git a/tests/baselines/reference/importNonExportedMember7.js b/tests/baselines/reference/importNonExportedMember7.js new file mode 100644 index 0000000000000..24beab599900c --- /dev/null +++ b/tests/baselines/reference/importNonExportedMember7.js @@ -0,0 +1,16 @@ +//// [tests/cases/compiler/importNonExportedMember7.ts] //// + +//// [a.ts] +class Foo {} +export = Foo; + +//// [b.ts] +import { Foo } from './a'; + +//// [a.js] +var Foo = /** @class */ (function () { + function Foo() { + } + return Foo; +}()); +//// [b.js] diff --git a/tests/baselines/reference/importNonExportedMember7.symbols b/tests/baselines/reference/importNonExportedMember7.symbols new file mode 100644 index 0000000000000..ebe40a13da5f7 --- /dev/null +++ b/tests/baselines/reference/importNonExportedMember7.symbols @@ -0,0 +1,11 @@ +=== tests/cases/compiler/a.ts === +class Foo {} +>Foo : Symbol(Foo, Decl(a.ts, 0, 0)) + +export = Foo; +>Foo : Symbol(Foo, Decl(a.ts, 0, 0)) + +=== tests/cases/compiler/b.ts === +import { Foo } from './a'; +>Foo : Symbol(Foo, Decl(b.ts, 0, 8)) + diff --git a/tests/baselines/reference/importNonExportedMember7.types b/tests/baselines/reference/importNonExportedMember7.types new file mode 100644 index 0000000000000..7668201a247f5 --- /dev/null +++ b/tests/baselines/reference/importNonExportedMember7.types @@ -0,0 +1,11 @@ +=== tests/cases/compiler/a.ts === +class Foo {} +>Foo : Foo + +export = Foo; +>Foo : Foo + +=== tests/cases/compiler/b.ts === +import { Foo } from './a'; +>Foo : any + diff --git a/tests/baselines/reference/importNonExportedMember8.errors.txt b/tests/baselines/reference/importNonExportedMember8.errors.txt new file mode 100644 index 0000000000000..489c7ef66a762 --- /dev/null +++ b/tests/baselines/reference/importNonExportedMember8.errors.txt @@ -0,0 +1,15 @@ +tests/cases/compiler/b.js(1,10): error TS2598: 'Foo' can only be imported by using a 'require' call or by turning on the 'esModuleInterop' flag and using a default import. +tests/cases/compiler/b.js(1,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/a.ts (0 errors) ==== + class Foo {} + export = Foo; + +==== tests/cases/compiler/b.js (2 errors) ==== + import { Foo } from './a'; + ~~~ +!!! error TS2598: 'Foo' can only be imported by using a 'require' call or 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. + \ No newline at end of file diff --git a/tests/baselines/reference/importNonExportedMember8.symbols b/tests/baselines/reference/importNonExportedMember8.symbols new file mode 100644 index 0000000000000..54ef501ecdce5 --- /dev/null +++ b/tests/baselines/reference/importNonExportedMember8.symbols @@ -0,0 +1,11 @@ +=== tests/cases/compiler/a.ts === +class Foo {} +>Foo : Symbol(Foo, Decl(a.ts, 0, 0)) + +export = Foo; +>Foo : Symbol(Foo, Decl(a.ts, 0, 0)) + +=== tests/cases/compiler/b.js === +import { Foo } from './a'; +>Foo : Symbol(Foo, Decl(b.js, 0, 8)) + diff --git a/tests/baselines/reference/importNonExportedMember8.types b/tests/baselines/reference/importNonExportedMember8.types new file mode 100644 index 0000000000000..ca9cc044c2d16 --- /dev/null +++ b/tests/baselines/reference/importNonExportedMember8.types @@ -0,0 +1,11 @@ +=== tests/cases/compiler/a.ts === +class Foo {} +>Foo : Foo + +export = Foo; +>Foo : Foo + +=== tests/cases/compiler/b.js === +import { Foo } from './a'; +>Foo : any + diff --git a/tests/baselines/reference/importNonExportedMember9.errors.txt b/tests/baselines/reference/importNonExportedMember9.errors.txt new file mode 100644 index 0000000000000..4f86dfb05da7a --- /dev/null +++ b/tests/baselines/reference/importNonExportedMember9.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/b.js(1,10): error TS2597: 'Foo' can only be imported by using a 'require' call or by using a default import. +tests/cases/compiler/b.js(1,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/a.ts (0 errors) ==== + class Foo {} + export = Foo; + +==== tests/cases/compiler/b.js (2 errors) ==== + import { Foo } from './a'; + ~~~ +!!! error TS2597: 'Foo' can only be imported by using a 'require' call or by 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. \ No newline at end of file diff --git a/tests/baselines/reference/importNonExportedMember9.symbols b/tests/baselines/reference/importNonExportedMember9.symbols new file mode 100644 index 0000000000000..54ef501ecdce5 --- /dev/null +++ b/tests/baselines/reference/importNonExportedMember9.symbols @@ -0,0 +1,11 @@ +=== tests/cases/compiler/a.ts === +class Foo {} +>Foo : Symbol(Foo, Decl(a.ts, 0, 0)) + +export = Foo; +>Foo : Symbol(Foo, Decl(a.ts, 0, 0)) + +=== tests/cases/compiler/b.js === +import { Foo } from './a'; +>Foo : Symbol(Foo, Decl(b.js, 0, 8)) + diff --git a/tests/baselines/reference/importNonExportedMember9.types b/tests/baselines/reference/importNonExportedMember9.types new file mode 100644 index 0000000000000..ca9cc044c2d16 --- /dev/null +++ b/tests/baselines/reference/importNonExportedMember9.types @@ -0,0 +1,11 @@ +=== tests/cases/compiler/a.ts === +class Foo {} +>Foo : Foo + +export = Foo; +>Foo : Foo + +=== tests/cases/compiler/b.js === +import { Foo } from './a'; +>Foo : any + diff --git a/tests/cases/compiler/importNonExportedMember10.ts b/tests/cases/compiler/importNonExportedMember10.ts new file mode 100644 index 0000000000000..b38c14e231e7a --- /dev/null +++ b/tests/cases/compiler/importNonExportedMember10.ts @@ -0,0 +1,12 @@ +// @esModuleInterop: false +// @module: es2015 +// @checkJs: true +// @allowJs: true +// @noEmit: true + +// @Filename: a.ts +class Foo {} +export = Foo; + +// @Filename: b.js +import { Foo } from './a'; \ No newline at end of file diff --git a/tests/cases/compiler/importNonExportedMember11.ts b/tests/cases/compiler/importNonExportedMember11.ts new file mode 100644 index 0000000000000..33c8128e01d07 --- /dev/null +++ b/tests/cases/compiler/importNonExportedMember11.ts @@ -0,0 +1,12 @@ +// @esModuleInterop: true +// @module: es2015 +// @checkJs: true +// @allowJs: true +// @noEmit: true + +// @Filename: a.ts +class Foo {} +export = Foo; + +// @Filename: b.js +import { Foo } from './a'; \ No newline at end of file diff --git a/tests/cases/compiler/importNonExportedMember4.ts b/tests/cases/compiler/importNonExportedMember4.ts new file mode 100644 index 0000000000000..21f4dc5612290 --- /dev/null +++ b/tests/cases/compiler/importNonExportedMember4.ts @@ -0,0 +1,9 @@ +// @esModuleInterop: false +// @module: commonjs + +// @Filename: a.ts +class Foo {} +export = Foo; + +// @Filename: b.ts +import { Foo } from './a'; \ No newline at end of file diff --git a/tests/cases/compiler/importNonExportedMember5.ts b/tests/cases/compiler/importNonExportedMember5.ts new file mode 100644 index 0000000000000..4a9f560e40aa9 --- /dev/null +++ b/tests/cases/compiler/importNonExportedMember5.ts @@ -0,0 +1,9 @@ +// @esModuleInterop: true +// @module: commonjs + +// @Filename: a.ts +class Foo {} +export = Foo; + +// @Filename: b.ts +import { Foo } from './a'; \ No newline at end of file diff --git a/tests/cases/compiler/importNonExportedMember6.ts b/tests/cases/compiler/importNonExportedMember6.ts new file mode 100644 index 0000000000000..ca1c39b230f21 --- /dev/null +++ b/tests/cases/compiler/importNonExportedMember6.ts @@ -0,0 +1,9 @@ +// @module: es2015 +// @esModuleInterop: false + +// @Filename: a.ts +class Foo {} +export = Foo; + +// @Filename: b.ts +import { Foo } from './a'; \ No newline at end of file diff --git a/tests/cases/compiler/importNonExportedMember7.ts b/tests/cases/compiler/importNonExportedMember7.ts new file mode 100644 index 0000000000000..4c6da92a563eb --- /dev/null +++ b/tests/cases/compiler/importNonExportedMember7.ts @@ -0,0 +1,9 @@ +// @module: es2015 +// @esModuleInterop: true + +// @Filename: a.ts +class Foo {} +export = Foo; + +// @Filename: b.ts +import { Foo } from './a'; \ No newline at end of file diff --git a/tests/cases/compiler/importNonExportedMember8.ts b/tests/cases/compiler/importNonExportedMember8.ts new file mode 100644 index 0000000000000..f1b01dc51159e --- /dev/null +++ b/tests/cases/compiler/importNonExportedMember8.ts @@ -0,0 +1,12 @@ +// @esModuleInterop: false +// @module: commonjs +// @checkJs: true +// @allowJs: true +// @noEmit: true + +// @Filename: a.ts +class Foo {} +export = Foo; + +// @Filename: b.js +import { Foo } from './a'; diff --git a/tests/cases/compiler/importNonExportedMember9.ts b/tests/cases/compiler/importNonExportedMember9.ts new file mode 100644 index 0000000000000..5a18a8649c16a --- /dev/null +++ b/tests/cases/compiler/importNonExportedMember9.ts @@ -0,0 +1,12 @@ +// @esModuleInterop: true +// @module: commonjs +// @checkJs: true +// @allowJs: true +// @noEmit: true + +// @Filename: a.ts +class Foo {} +export = Foo; + +// @Filename: b.js +import { Foo } from './a'; \ No newline at end of file