Skip to content

Commit 543cd37

Browse files
committed
Fixed a couple map bugs
1 parent 2b0271b commit 543cd37

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/lualib/Map.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,31 @@ class Map<TKey, TValue> {
99

1010
if (other) {
1111
this.size = other.size;
12-
other.forEach((value, key) => {this.items[key] = value; });
12+
for (const [key, value] of other.entries()) {
13+
this.items[key] = value;
14+
}
1315
}
1416
}
1517

1618
public clear(): void {
1719
this.items = {};
1820
this.size = 0;
21+
return;
1922
}
2023

2124
public delete(key: TKey): boolean {
2225
const contains = this.has(key);
26+
if (contains) {
27+
this.size = this.size - 1;
28+
}
2329
this.items[key as any] = undefined;
24-
this.size = this.size - 1;
2530
return contains;
2631
}
2732

2833
public entries(): Array<[TKey, TValue]> {
2934
const out = [];
3035
for (const key in this.items) {
31-
out[out.length + 1] = [key, this.items[key]];
36+
out[out.length] = [key, this.items[key]];
3237
}
3338
return out;
3439
}
@@ -37,20 +42,21 @@ class Map<TKey, TValue> {
3742
for (const key in this.items) {
3843
callback(this.items[key], key as any, this);
3944
}
45+
return;
4046
}
4147

4248
public get(key: TKey): TValue {
4349
return this.items[key as any];
4450
}
4551

4652
public has(key: TKey): boolean {
47-
return this.items[key as any] != undefined;
53+
return this.items[key as any] !== undefined;
4854
}
4955

5056
public keys(): TKey[] {
5157
const out = [];
5258
for (const key in this.items) {
53-
out[out.length + 1] = key;
59+
out[out.length] = key;
5460
}
5561
return out;
5662
}
@@ -66,7 +72,7 @@ class Map<TKey, TValue> {
6672
public values(): TValue[] {
6773
const out = [];
6874
for (const key in this.items) {
69-
out[out.length + 1] = this.items[key];
75+
out[out.length] = this.items[key];
7076
}
7177
return out;
7278
}

tslint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"align": [true, "parameters", "statements", "arguments", "members", "elements"],
1010
"arrow-parens": [true, "ban-single-arg-parens"],
1111
"class-name": true,
12+
"forin": false,
1213
"no-bitwise": false,
1314
"indent": [true, "spaces", 4],
1415
"max-classes-per-file": 1,

0 commit comments

Comments
 (0)