Created
June 18, 2018 11:49
-
-
Save misablaha/d284fb5615f1a94f932fd8edd3cbc26f to your computer and use it in GitHub Desktop.
Babel plugin that checks access to global window variable
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
const { resolve: resolvePath } = require('path'); | |
module.exports = (babel) => ({ | |
visitor: { | |
Identifier(path, state) { | |
if (path.node.name === 'window') { | |
if (!path.scope.hasBinding('window')) { | |
const fileName = resolvePath(state.file.opts.filenameRelative); | |
const { start } = path.node.loc; | |
console.warn(`Global window is touched at ${fileName}:${start.line}:${start.column}`); | |
} | |
} | |
}, | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment