Bad error message when default 'import'-ing an 'export =' without 'esModuleInterop'

This commit is contained in:
Alexander T
2019-04-10 17:35:47 +03:00
parent ef4acc8841
commit f5d4e66451
10 changed files with 116 additions and 25 deletions

View File

@@ -1953,7 +1953,21 @@ namespace ts {
const file = find(moduleSymbol.declarations, isSourceFile);
const hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias);
if (!exportDefaultSymbol && !hasSyntheticDefault) {
error(node.name, Diagnostics.Module_0_has_no_default_export, symbolToString(moduleSymbol));
if (hasExportAssignmentSymbol(moduleSymbol)) {
const compilerOptionName = moduleKind >= ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop";
const exportEqualsSymbol = moduleSymbol.exports!.get(InternalSymbolName.ExportEquals);
const exportAssignment = exportEqualsSymbol!.valueDeclaration;
const err = error(node.name, Diagnostics.Module_0_can_only_be_default_imported_using_the_1_flag, symbolToString(moduleSymbol), compilerOptionName);
addRelatedInfo(err, createDiagnosticForNode(
exportAssignment,
Diagnostics.This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag,
compilerOptionName
));
}
else {
error(node.name, Diagnostics.Module_0_has_no_default_export, symbolToString(moduleSymbol));
}
}
else if (hasSyntheticDefault) {
// per emit behavior, a synthetic default overrides a "real" .default member if `__esModule` is not present

View File

@@ -851,6 +851,10 @@
"category": "Error",
"code": 1258
},
"Module '{0}' can only be default-imported using the '{1}' flag": {
"category": "Error",
"code": 1259
},
"'with' statements are not allowed in an async function block.": {
"category": "Error",
"code": 1300
@@ -2156,6 +2160,10 @@
"category": "Error",
"code": 2593
},
"This module is declared with using 'export =', and can only be used with a default import when using the '{0}' flag.": {
"category": "Error",
"code": 2594
},
"JSX element attributes type '{0}' may not be a union type.": {
"category": "Error",
"code": 2600