diff --git a/README b/README deleted file mode 100644 index 585a6d0..0000000 --- a/README +++ /dev/null @@ -1 +0,0 @@ -#babel-transform-react-es6-class-displayname diff --git a/README.md b/README.md new file mode 100644 index 0000000..5385c51 --- /dev/null +++ b/README.md @@ -0,0 +1,35 @@ +# babel-plugin-transform-react-es6-displayname + +Automatically add `displayName` to React components instantiated in ES6 style inheriting from React.Component (ex: `class ComponentName extends React.Component`) + +## Installation + +```sh +$ npm install babel-plugin-transform-react-es6-displayname +``` + +## Usage + +### Via `.babelrc` (Recommended) + +**.babelrc** + +```js +{ + "plugins": ["transform-react-es6-displayname"] +} +``` + +### Via CLI + +```sh +$ babel --plugins transform-react-es6-displayname script.js +``` + +### Via Node API + +```javascript +require("babel-core").transform("code", { + plugins: ["transform-react-es6-displayname"] +}); +``` diff --git a/index.js b/index.js index 9e690d0..1d0fd6b 100644 --- a/index.js +++ b/index.js @@ -22,7 +22,7 @@ function addDisplayName (t) { ) ) ) { - this.insertAfter([ + (t.isExportNamedDeclaration(this.parentPath.node) ? this.parentPath : this).insertAfter([ t.expressionStatement(t.assignmentExpression( '=', t.memberExpression(this.node.id, t.identifier('displayName')), diff --git a/package.json b/package.json index 37712fe..c3a274b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-react-es6-displayname", - "version": "1.0.0-beta1.3", + "version": "1.0.0-beta1.4", "description": "Babel transform to add the displayName property to component classes", "main": "index.js", "scripts": { @@ -18,7 +18,10 @@ "react", "displayName" ], - "author": "Nathan Marks (http://nathanmarks.io)", + "authors": [ + "Nathan Marks (http://nathanmarks.io)", + "Dmitri Farkov (http://github.com/dmitrif)" + ], "license": "MIT", "bugs": { "url": "https://github.com/nathanmarks/babel-plugin-transform-react-es6-displayname/issues"