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?? } } }; }
You can you this
or use the 2nd parameter in a visitor (state
)
Identifier(path, state) { console.log(state.file.opts.filename); }
For any future viewers, you can use this.file.opts.filename in a visitor function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With