Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,11 @@ describe('renameDefaultExportedIdentifiers', () => {

test('should rename local class name which is default-exported', async () => {
const code = `
class ExportedClass {};
class ExportedClass {}
export default ExportedClass;`;
const result = await translate(code);
expect(result).toMatchInlineSnapshot(`
"class ExportedClass_default {}
;
export default ExportedClass_default;"
`);
});
Expand All @@ -70,13 +69,27 @@ describe('renameDefaultExportedIdentifiers', () => {

test('should rename local function name which is default-exported', async () => {
const code = `
function exportedFunction() {};
function exportedFunction() {}
export default exportedFunction;`;
const result = await translate(code);
expect(result).toMatchInlineSnapshot(`
"function exportedFunction_default() {}
;
export default exportedFunction_default;"
`);
});

test('should not rename identifiers with the same name in member expressions', async () => {
const code = `
import Other from 'Other';
type Type = typeof Other.Exported;
class Exported {}
export default Exported;`;
const result = await translate(code);
expect(result).toMatchInlineSnapshot(`
"import Other from 'Other';
type Type = typeof Other.Exported;
class Exported_default {}
export default Exported_default;"
`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ const visitor: PluginObj<mixed> = {
const newName = `${localSymbol}_default`;
nodePath.traverse({
Identifier(innerPath) {
if (innerPath.node.name === localSymbol) {
if (
innerPath.node.name === localSymbol &&
!innerPath.findParent(
path => t.isMemberExpression(path) || t.isTSQualifiedName(path),
)
) {
innerPath.node.name = newName;
}
},
Expand Down
Loading