Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current filename in Babel Plugin?

Tags:

I'm attempting to write a plugin for babel, and am needing the filename of the current file that is being parsed. I know the lines of the code are passed in, but I haven't managed to find a reference to the filename. Any help??

For instance given this code what could I do

export default function({ types: t }) {   return {     visitor: {       Identifier(path) {        // something here??       }     }   }; } 
like image 806
gfunk Avatar asked Mar 08 '16 01:03

gfunk


2 Answers

You can you this or use the 2nd parameter in a visitor (state)

Identifier(path, state) {     console.log(state.file.opts.filename); } 
like image 141
hzoo Avatar answered Sep 20 '22 18:09

hzoo


For any future viewers, you can use this.file.opts.filename in a visitor function

like image 30
gfunk Avatar answered Sep 19 '22 18:09

gfunk