-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
25 lines (22 loc) · 877 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function (_ref) {
var t = _ref.types;
return {
visitor: {
Program: function Program(path, file) {
// Inject `var CatchPromise = require('catch-promise');`
var catchPromiseDeclaration = t.variableDeclaration('var', [t.variableDeclarator(t.identifier('CatchPromise'), t.callExpression(t.identifier('require'), [t.stringLiteral('catch-promise')]))]);
path.unshiftContainer('body', catchPromiseDeclaration);
},
Identifier: function Identifier(path) {
// Replace `Promise` with `CatchPromise`
if (path.node.name === 'Promise') {
path.replaceWith(t.identifier('CatchPromise'));
}
}
}
};
};