mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Handle different default export forms the same way in import code fixes
`export default C` and `export { C as default }` should be handled the
same as `export default class C { }`.
Fixes #19115
This commit is contained in:
@@ -770,8 +770,11 @@ namespace ts.codefix {
|
||||
const defaultExport = checker.tryGetMemberInModuleExports(InternalSymbolName.Default, moduleSymbol);
|
||||
if (defaultExport) {
|
||||
const localSymbol = getLocalSymbolForExportDefault(defaultExport);
|
||||
if ((localSymbol && localSymbol.escapedName === symbolName || moduleSymbolToValidIdentifier(moduleSymbol, context.compilerOptions.target) === symbolName)
|
||||
&& checkSymbolHasMeaning(localSymbol || defaultExport, currentTokenMeaning)) {
|
||||
if ((
|
||||
localSymbol && localSymbol.escapedName === symbolName ||
|
||||
getEscapedNameForExportDefault(defaultExport) === symbolName ||
|
||||
moduleSymbolToValidIdentifier(moduleSymbol, context.compilerOptions.target) === symbolName
|
||||
) && checkSymbolHasMeaning(localSymbol || defaultExport, currentTokenMeaning)) {
|
||||
// check if this symbol is already used
|
||||
const symbolId = getUniqueSymbolId(localSymbol || defaultExport, checker);
|
||||
symbolIdActionMap.addActions(symbolId, getCodeActionForImport(moduleSymbol, { ...context, kind: ImportKind.Default }));
|
||||
@@ -784,6 +787,23 @@ namespace ts.codefix {
|
||||
const symbolId = getUniqueSymbolId(exportSymbolWithIdenticalName, checker);
|
||||
symbolIdActionMap.addActions(symbolId, getCodeActionForImport(moduleSymbol, { ...context, kind: ImportKind.Named }));
|
||||
}
|
||||
|
||||
function getEscapedNameForExportDefault(symbol: Symbol): __String | undefined {
|
||||
const declarations = symbol.declarations;
|
||||
if (length(declarations) > 0) {
|
||||
const declaration = declarations[0];
|
||||
if (isExportAssignment(declaration)) {
|
||||
if (isIdentifier(declaration.expression)) {
|
||||
return declaration.expression.escapedText;
|
||||
}
|
||||
}
|
||||
else if (isExportSpecifier(declaration)) {
|
||||
if (declaration.propertyName) {
|
||||
return declaration.propertyName.escapedText;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return symbolIdActionMap.getAllActions();
|
||||
|
||||
Reference in New Issue
Block a user