mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 01:39:28 -06:00
feat(37092): improve error message about missing default export (#37212)
This commit is contained in:
parent
7f5994958b
commit
3c130d1317
@ -2388,18 +2388,7 @@ namespace ts {
|
||||
));
|
||||
}
|
||||
else {
|
||||
if (moduleSymbol.exports && moduleSymbol.exports.has(node.symbol.escapedName)) {
|
||||
error(
|
||||
node.name,
|
||||
Diagnostics.Module_0_has_no_default_export_Did_you_mean_to_use_import_1_from_0_instead,
|
||||
symbolToString(moduleSymbol),
|
||||
symbolToString(node.symbol),
|
||||
);
|
||||
}
|
||||
else {
|
||||
error(node.name, Diagnostics.Module_0_has_no_default_export, symbolToString(moduleSymbol));
|
||||
}
|
||||
|
||||
reportNonDefaultExport(moduleSymbol, node);
|
||||
}
|
||||
}
|
||||
else if (hasSyntheticDefault) {
|
||||
@ -2413,6 +2402,30 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function reportNonDefaultExport(moduleSymbol: Symbol, node: ImportClause) {
|
||||
if (moduleSymbol.exports?.has(node.symbol.escapedName)) {
|
||||
error(
|
||||
node.name,
|
||||
Diagnostics.Module_0_has_no_default_export_Did_you_mean_to_use_import_1_from_0_instead,
|
||||
symbolToString(moduleSymbol),
|
||||
symbolToString(node.symbol),
|
||||
);
|
||||
}
|
||||
else {
|
||||
const diagnostic = error(node.name, Diagnostics.Module_0_has_no_default_export, symbolToString(moduleSymbol));
|
||||
const exportStar = moduleSymbol.exports?.get(InternalSymbolName.ExportStar);
|
||||
if (exportStar) {
|
||||
const defaultExport = find(exportStar.declarations, decl => !!(
|
||||
isExportDeclaration(decl) && decl.moduleSpecifier &&
|
||||
resolveExternalModuleName(decl, decl.moduleSpecifier)?.exports?.has(InternalSymbolName.Default)
|
||||
));
|
||||
if (defaultExport) {
|
||||
addRelatedInfo(diagnostic, createDiagnosticForNode(defaultExport, Diagnostics.export_Asterisk_does_not_re_export_a_default));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getTargetOfNamespaceImport(node: NamespaceImport, dontResolveAlias: boolean): Symbol | undefined {
|
||||
const moduleSpecifier = node.parent.parent.moduleSpecifier;
|
||||
const immediate = resolveExternalModuleName(node, moduleSpecifier);
|
||||
|
||||
@ -611,6 +611,10 @@
|
||||
"category": "Error",
|
||||
"code": 1194
|
||||
},
|
||||
"'export *' does not re-export a default.": {
|
||||
"category": "Error",
|
||||
"code": 1195
|
||||
},
|
||||
"Catch clause variable cannot have a type annotation.": {
|
||||
"category": "Error",
|
||||
"code": 1196
|
||||
|
||||
@ -30,6 +30,7 @@ tests/cases/conformance/es6/modules/t4.ts(3,1): error TS2308: Module "./t1" has
|
||||
import hello, { x, y, z, foo } from "./t4";
|
||||
~~~~~
|
||||
!!! error TS1192: Module '"tests/cases/conformance/es6/modules/t4"' has no default export.
|
||||
!!! related TS1195 tests/cases/conformance/es6/modules/t4.ts:2:1: 'export *' does not re-export a default.
|
||||
hello;
|
||||
x;
|
||||
y;
|
||||
|
||||
@ -30,6 +30,7 @@ tests/cases/conformance/es6/modules/t4.ts(3,1): error TS2308: Module "./t1" has
|
||||
import hello, { x, y, z, foo } from "./t4";
|
||||
~~~~~
|
||||
!!! error TS1192: Module '"tests/cases/conformance/es6/modules/t4"' has no default export.
|
||||
!!! related TS1195 tests/cases/conformance/es6/modules/t4.ts:2:1: 'export *' does not re-export a default.
|
||||
hello;
|
||||
x;
|
||||
y;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user