forked from chpio/babel-plugin-transform-promise-to-bluebird
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["es2015"], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
extends: sudeti | ||
rules: | ||
no-console: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/node_modules/ | ||
/main.es5.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!/main.es5.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
)); | ||
}, | ||
}, | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |