-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scope.js
48 lines (48 loc) · 1.25 KB
/
Scope.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class Scope {
constructor(local, $this) {
this.local = local;
this.this = $this;
}
resolve(name) {
if (name in this.local)
return [this.local[name], 'local'];
if ('this' in this) {
if (name == 'this')
return [this.this, 'local'];
if (typeof this.this == 'object' && !(this.this instanceof Array))
if (name in this.this)
return [this.this[name], 'this'];
}
}
*[Symbol.iterator]({ key, name } = {}) {
if (key != 'this')
if (name !== undefined) {
if (name in this.local)
yield [this.local[name], name, 'local'];
} else
for (let name in this.local)
yield [this.local[name], name, 'local'];
if ('this' in this) {
if (key != 'this')
if (name !== undefined) {
if (name == 'this')
yield [this.this, 'this', 'local'];
} else
yield [this.this, 'this', 'local'];
if (key != 'local')
if (typeof this.this == 'object' && !(this.this instanceof Array))
if (name !== undefined) {
if (name in this.this)
yield [this.this[name], name, 'this'];
} else
for (let name in this.this)
yield [this.this[name], name, 'this'];
}
}
find(f, filter) {
for (var entry of this[Symbol.iterator](filter))
if (f(...entry))
return entry;
}
}
module.exports = Scope;