Skip to content

Commit a76cb20

Browse files
committed
add clarifying comments to isGlobalReference() code
1 parent 0279002 commit a76cb20

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

apps/oxlint/src-js/plugins/scope.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,15 @@ export function isGlobalReference(node: ESTree.Node): boolean {
165165
return false;
166166
}
167167

168+
// If the identifier is a reference to a global variable, the global scope should have a variable with the name.
168169
const variable = SOURCE_CODE.scopeManager.globalScope.set.get(name);
170+
171+
// Global variables are not defined by any node, so they should have no definitions.
169172
if (!variable || variable.defs.length > 0) {
170173
return false;
171174
}
172175

176+
// If there is a variable by the same name exists in the global scope, we need to check our node is one of its references.
173177
const { references } = variable;
174178

175179
for (let i = 0; i < references.length; i++) {

0 commit comments

Comments
 (0)