Skip to content

Instantly share code, notes, and snippets.

@misablaha
Created June 18, 2018 11:49
Show Gist options
  • Save misablaha/d284fb5615f1a94f932fd8edd3cbc26f to your computer and use it in GitHub Desktop.
Save misablaha/d284fb5615f1a94f932fd8edd3cbc26f to your computer and use it in GitHub Desktop.
Babel plugin that checks access to global window variable
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