- Open https://astexplorer.net/
- Set it to JavaScript if it's not
- Set it to babylon6
- Paste the
source.js
code in the top left pane - In the "Transform" menu on the top select
babel6
- Copy the
transform.js
code in the bottom left page
Last active
February 5, 2017 23:43
-
-
Save xaviervia/6cf7937b5a20d66203706a02f5379a14 to your computer and use it in GitHub Desktop.
babel transform to trace function calls, try 1
This file contains hidden or 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
function hola (a, b) { | |
console.log("called: hola", arguments); | |
return `${a} ${b}` | |
} | |
hola('hello', 'world') |
This file contains hidden or 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
function hola (a, b) { | |
return `${a} ${b}` | |
} | |
hola('hello', 'world') |
This file contains hidden or 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
export default function (babel) { | |
const { types: t } = babel; | |
return { | |
visitor: { | |
FunctionDeclaration(path) { | |
const memberExpression = t.memberExpression(t.identifier('console'), t.identifier('log')) | |
const theArguments = [t.stringLiteral(`called: ${path.node.id.name}`), t.identifier('arguments')] | |
const expressionStatement = t.expressionStatement(t.callExpression(memberExpression, theArguments)) | |
path.node.body.body.unshift(expressionStatement) | |
} | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
try with: