Created
December 10, 2017 04:17
-
-
Save kinka/fd2b8d598168b9a707ce75673df5b43c to your computer and use it in GitHub Desktop.
This file contains 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
module.exports = function ({types: t}) { | |
return { | |
// name: "ast-transform", // not required | |
visitor: { | |
Identifier(path, state) { | |
//path.node.name = path.node.name.split('').reverse().join(''); | |
//console.log('test', path.node) | |
//path.node.name = path.node.name + '_' + loc.start.line + '_' + loc.start.column | |
}, | |
FunctionDeclaration: { | |
exit(path, state) { | |
const filename = state.file.opts.filename; | |
const loc = path.node.loc | |
const body = path.get('body') | |
body.unshiftContainer('body', | |
t.expressionStatement( | |
t.callExpression( | |
t.memberExpression(t.identifier('console'), t.identifier('log')), | |
[t.stringLiteral(filename), t.stringLiteral(path.node.id.name), t.identifier('loc')] | |
) | |
) | |
); | |
body.unshiftContainer('body', | |
t.variableDeclaration('const', [ | |
t.variableDeclarator(t.identifier('loc'), t.identifier(JSON.stringify(loc))) | |
]) | |
); | |
} | |
} | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment