correct this handling

This commit is contained in:
2026-02-18 11:00:51 -06:00
parent bd7f9f34ec
commit 187d7e9832
3 changed files with 29 additions and 12 deletions

View File

@@ -4,15 +4,21 @@
var query = {}
// Top-level this: references where name=="this" and enclosing==null.
query.top_level_this = function(idx) {
// Find this references. scope: "top" (top-level only), "fn" (in functions), null (all).
query.find_this = function(idx, scope) {
var hits = []
var i = 0
var ref = null
while (i < length(idx.references)) {
ref = idx.references[i]
if (ref.name == "this" && ref.enclosing == null) {
hits[] = ref
if (ref.name == "this") {
if (scope == null) {
hits[] = ref
} else if (scope == "top" && ref.enclosing == null) {
hits[] = ref
} else if (scope == "fn" && ref.enclosing != null) {
hits[] = ref
}
}
i = i + 1
}