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:
Andrew Casey
2018-01-04 15:34:19 -08:00
parent 0477f91dba
commit ff58f1f2f9
+22 -2
View File
@@ -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();