Skip to content

Commit

Permalink
+ init code
Browse files Browse the repository at this point in the history
  • Loading branch information
chpio committed Jul 4, 2016
1 parent 23f97ad commit 9d68457
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["es2015"],
}
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{.eslintrc,package.json}]
indent_style = space
indent_size = 2
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
extends: sudeti
rules:
no-console: 0
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules/
/main.es5.js
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!/main.es5.js
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# babel-plugin-transform-promise-to-bluebird

This plugin transforms `Promise` to `bluebird`.

## Usage

1. Install: `npm install --save-dev babel-plugin-transform-promise-to-bluebird`
2. Add *transform-promise-to-bluebird* to your *.babelrc* file:
```json
{
"plugins": ["transform-promise-to-bluebird"]
}
```
If you'r using the *transform-runtime* plugin add *transform-promise-to-bluebird* before
*transform-runtime*:
```json
{
"plugins": [
"transform-promise-to-bluebird",
"transform-runtime"
]
}
```
32 changes: 32 additions & 0 deletions main.es2015.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export default function promiseToBluebird({types: t}) {
return {
visitor: {
ReferencedIdentifier(path, state) {
const {node, parent, scope} = path;

if (node.name !== 'Promise') return;
if (t.isMemberExpression(parent)) return;
if (scope.getBindingIdentifier(node.name)) return;

path.replaceWith(state.addImport('bluebird', 'default', node.name));
},

MemberExpression: {
exit(path, state) {
const {node} = path;
const obj = node.object;

if (obj.name !== 'Promise') return;
if (!path.isReferenced()) return;
if (path.scope.getBindingIdentifier(obj.name)) return;

path.replaceWith(t.memberExpression(
state.addImport('bluebird', 'default', obj.name),
node.property,
node.computed
));
},
},
},
};
}
22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "babel-plugin-transform-promise-to-bluebird",
"version": "0.0.0",
"description": "Transforms *Promise* to *bluebird*",
"main": "main.es5.js",
"devDependencies": {
"babel-cli": "^6.10.1",
"babel-preset-es2015": "^6.9.0"
},
"scripts": {
"prepublish": "babel main.es2015.js > main.es5.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/chpio/babel-plugin-transform-promise-to-bluebird.git"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/chpio/babel-plugin-transform-promise-to-bluebird/issues"
},
"homepage": "https://github.com/chpio/babel-plugin-transform-promise-to-bluebird#readme"
}

0 comments on commit 9d68457

Please sign in to comment.