GlobalBinding is like Binding but for globals. It tracks usage of a variable
that is not declared, but is being used.
const { traverse } = require('estree-toolkit');
const { parseModule } = require('meriyah');
const ast = parseModule(`
document.querySelector('.class')
window.location.reload();
x = 7;
`);
traverse(ast, {
$: { scope: true },
Program(path) {
path.scope.globalBindings
/* =>
{
document: GlobalBinding { ... },
window: GlobalBinding { ... },
x: GlobalBinding { ... }
}
*/
}
});kind'global'For GlobalBindings, the kind is constant and it's 'global'.
namestringThe name of the global binding.
referencesNodePath[]All paths that references this global binding.
constantViolationsNodePaths[]All paths that reassigns the value of this global binding.
constantfalseFor global bindings we can't know for sure if the binding is constant,
because other modules/files can change value of global bindings anytime.
So any global binding's constant would be always false.