Skip to content

Commit

Permalink
Implemented new treatment for old export declaration (module.exports)…
Browse files Browse the repository at this point in the history
… in ReactForwardedRefOrMemo components. (#1)

* Implemented new treatment for old export declaration (module.exports) in ReactForwardedRefOrMemo components

* fix test of moduleExportsInMemoOrForwardRefComponent

* removed displayName of module.exports and fix version of babel

* fix to remove displayName in module.exports case

* changed fix to ignore MemberExpression node type

Co-authored-by: Lucas Victor <[email protected]>
  • Loading branch information
lucasvictor3 and Lucas Victor committed Aug 20, 2021
1 parent aa2914f commit d7d9abf
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ function transform (babel) {
}

var id = path.node.arguments[0].id || findCandidateNameForExpression(path);
if (id) {

if (id && id.type !== 'MemberExpression') {
setDisplayNameUsingClosure(path.get('arguments.0'), id, babel.types);
}
}
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@geekie/babel-plugin-add-react-displayname",
"version": "0.0.5",
"version": "0.1.1",
"description": "Automatically add displayName to all your components",
"main": "index.js",
"dependencies": {},
Expand All @@ -22,7 +22,8 @@
},
"author": "Ron Cohen",
"contributors": [
"Rodrigo Almeida"
"Rodrigo Almeida",
"Lucas Victor"
],
"license": "MIT",
"bugs": {
Expand Down
15 changes: 15 additions & 0 deletions test/fixtures/reactModuleExportsInMemoForwardRef/expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from "react";

let TestComponent = class TestComponent extends React.Component {
constructor(props) {
super(props);
}

render() {
return React.createElement("div", null);
}
};
TestComponent.displayName = "TestComponent";


module.exports = React.forwardRef((props, state) => React.createElement(TestComponent, null));
15 changes: 15 additions & 0 deletions test/fixtures/reactModuleExportsInMemoForwardRef/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from "react";

class TestComponent extends React.Component {
constructor(props) {
super(props);
}

render() {
return (
<div></div>
)
}
}

module.exports = React.forwardRef((props, state) => <TestComponent />);

0 comments on commit d7d9abf

Please sign in to comment.