Skip to content

Commit 4b77a86

Browse files
authored
Merge pull request #3 from Fimba-Code/fix/pluging-module-export
Fixed parser
2 parents b3f3ee2 + ade8734 commit 4b77a86

File tree

10 files changed

+1370
-739
lines changed

10 files changed

+1370
-739
lines changed

.DS_Store

0 Bytes
Binary file not shown.

.babelrc

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

example/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function add(a, b) {
2+
$log;
3+
const result = a + b;
4+
return result;
5+
}
6+
add(2, 3);

index.js

Lines changed: 29 additions & 0 deletions
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+
}

index.ts

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)