Skip to content

Commit

Permalink
Fix renameTo renaming React component prop name unexpectedly
Browse files Browse the repository at this point in the history
  • Loading branch information
baopham committed Aug 20, 2017
1 parent 2bed715 commit 794b2cd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/collections/VariableDeclarator.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ const transformMethods = {
return false;
}

if (
types.JSXAttribute.check(parent) &&
parent.name === path.node &&
!parent.computed
) {
// <Foo oldName={oldName} />
return false;
}

return true;
})
.forEach(function(path) {
Expand Down
12 changes: 12 additions & 0 deletions src/collections/__tests__/VariableDeclarator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ describe('VariableDeclarators', function() {
' blah() {}',
' }',
'}',
'<Component foo={foo} />',
].join('\n'), {parser: babel}).program];
});

Expand Down Expand Up @@ -127,6 +128,17 @@ describe('VariableDeclarators', function() {

expect(identifiers.length).toBe(1);
});

it('does not rename React component prop name', function () {
const declarators = Collection.fromNodes(nodes)
.findVariableDeclarators('foo')
.renameTo('xyz');

const identifiers = Collection.fromNodes(nodes)
.find(types.JSXIdentifier, { name: 'foo' });

expect(identifiers.length).toBe(1);
});
});

});

0 comments on commit 794b2cd

Please sign in to comment.