Skip to content

Commit

Permalink
fix(extract-component): incorrect handling of nested member expressio…
Browse files Browse the repository at this point in the history
…ns. Fixes #62
  • Loading branch information
Boris Litvinsky committed Mar 26, 2019
1 parent 63911e7 commit 1840c64
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/modules/extract-to-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ export function wrapWithComponent(componentName, jsx): ProcessedSelection {
}
},
MemberExpression(path) {
if (!path.node.wasVisited && t.isThisExpression(path.node.object.object)) {
if (!path.node.wasVisited) {
if (
t.isThisExpression(path.node.object.object) &&
(path.node.object.property.name === "props" ||
path.node.object.property.name === "state")
) {
Expand All @@ -61,7 +62,10 @@ export function wrapWithComponent(componentName, jsx): ProcessedSelection {
path.replaceWith(t.identifier(path.node.property.name));

} else {
if(t.isThisExpression(path.node.object)){
componentProperties.componentMembers.add(path.node.property.name);
path.replaceWith(t.identifier(path.node.property.name));
}
}
path.node.wasVisited = true;
path.skip();
Expand Down

0 comments on commit 1840c64

Please sign in to comment.