Skip to content

Commit ade8734

Browse files
committed
✨ fixed parser
1 parent 02300ad commit ade8734

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

.DS_Store

0 Bytes
Binary file not shown.

.babelrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"plugins": ["./index.js"]
3+
}

index.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
module.exports = function (babel) {
3+
const { types: t } = babel;
4+
5+
let hasLogID = false;
6+
7+
return {
8+
name: "log-transform",
9+
visitor: {
10+
ReturnStatement: (path) => {
11+
const identifierName = path.node.argument.name;
12+
if (path.node.argument.type === "Identifier" && hasLogID) {
13+
path.replaceWithMultiple([
14+
t.identifier(
15+
`console.log('Final Result 😛 ==> ', ${identifierName})`
16+
),
17+
t.identifier(`return ${identifierName}`),
18+
]);
19+
}
20+
},
21+
Identifier: (path) => {
22+
if (path.isIdentifier({ name: "$log" })) {
23+
hasLogID = true;
24+
path.remove();
25+
}
26+
},
27+
},
28+
};
29+
}

0 commit comments

Comments
 (0)