Merge pull request #25445 from a-tarasyuk/bug/24542-bad-error-message-for-import-ing-an-export

24542 - bad error message for `import *`-ing an `export=`
This commit is contained in:
Daniel Rosenwasser
2019-01-09 11:02:14 -08:00
committed by GitHub
13 changed files with 194 additions and 20 deletions

View File

@@ -2408,11 +2408,18 @@ 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.Module_0_resolves_to_a_non_module_entity_and_cannot_be_imported_using_this_construct, symbolToString(moduleSymbol!));
const compilerOptionName = moduleKind >= ModuleKind.ES2015
? "allowSyntheticDefaultImports"
: "esModuleInterop";
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;
}
if (compilerOptions.esModuleInterop) {
const referenceParent = referencingLocation.parent;
if (

View File

@@ -1776,7 +1776,7 @@
"category": "Error",
"code": 2496
},
"Module '{0}' resolves to a non-module entity and cannot be imported using this construct.": {
"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
},