Skip to content

Commit e60662b

Browse files
baophamfkling
authored andcommittedMar 7, 2018
Fix renameTo renaming React component prop name unexpectedly (#220)
See: #219
1 parent 32cc779 commit e60662b

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed
 

‎src/collections/VariableDeclarator.js

+9
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@ const transformMethods = {
114114
return false;
115115
}
116116

117+
if (
118+
types.JSXAttribute.check(parent) &&
119+
parent.name === path.node &&
120+
!parent.computed
121+
) {
122+
// <Foo oldName={oldName} />
123+
return false;
124+
}
125+
117126
return true;
118127
})
119128
.forEach(function(path) {

‎src/collections/__tests__/VariableDeclarator-test.js

+12
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ describe('VariableDeclarators', function() {
5353
' blah() {}',
5454
' }',
5555
'}',
56+
'<Component foo={foo} />',
5657
].join('\n'), {parser: getParser()}).program];
5758
});
5859

@@ -127,6 +128,17 @@ describe('VariableDeclarators', function() {
127128

128129
expect(identifiers.length).toBe(1);
129130
});
131+
132+
it('does not rename React component prop name', function () {
133+
const declarators = Collection.fromNodes(nodes)
134+
.findVariableDeclarators('foo')
135+
.renameTo('xyz');
136+
137+
const identifiers = Collection.fromNodes(nodes)
138+
.find(types.JSXIdentifier, { name: 'foo' });
139+
140+
expect(identifiers.length).toBe(1);
141+
});
130142
});
131143

132144
});

0 commit comments

Comments
 (0)
Please sign in to comment.