forked from christina-de-martinez/babel-plugin-glowup-vibes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (29 loc) · 909 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
26
27
28
29
30
31
32
33
module.exports = function () {
const identifierMappings = require("./identifierMappings.js")
const handleIdentifier = (path) => {
const newName = identifierMappings[path.node.name];
if (newName) {
path.node.name = newName;
}
};
const handleExpressionStatement = (path) => {
const { node } = path;
if (
node.expression.type === "CallExpression" &&
node.expression.callee.name === "yeet"
) {
const errorArgument = node.expression.arguments[0];
const throwStatement = {
type: "ThrowStatement",
argument: errorArgument,
};
path.replaceWith(throwStatement);
}
};
return {
visitor: {
Identifier: handleIdentifier,
ExpressionStatement: handleExpressionStatement,
},
};
};