Skip to content

Commit cb5390c

Browse files
committed
Fixed map/set constructors
1 parent e049a86 commit cb5390c

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

src/lualib/Map.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@ class Map<TKey, TValue> {
33

44
private items: {[key: string]: TValue}; // Type of key is actually TKey
55

6-
constructor(other: any) {
6+
constructor(other: Map<TKey, TValue> | Array<[TKey, TValue]>) {
77
this.items = {};
88
this.size = 0;
99

10-
if (other) {
10+
if (other instanceof Map) {
1111
this.size = other.size;
1212
for (const [key, value] of other.entries()) {
13-
this.items[key] = value;
13+
this.items[key as any] = value;
14+
}
15+
} else if (other !== undefined) {
16+
this.size = other.length;
17+
for (const [key, value] of other) {
18+
this.items[key as any] = value;
1419
}
1520
}
1621
}

src/lualib/Set.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@ class Set<TValue> {
33

44
private items: {[key: string]: boolean}; // Key type is actually TValue
55

6-
constructor(other: any) {
6+
constructor(other: Set<TValue> | TValue[]) {
77
this.items = {};
88
this.size = 0;
99

10-
if (other) {
10+
if (other instanceof Set) {
1111
this.size = other.size;
1212
for (const value of other.values()) {
13-
this.items[value] = true;
13+
this.items[value as any] = true as any;
14+
}
15+
} else if (other !== undefined) {
16+
this.size = other.length;
17+
for (const value of other) {
18+
this.items[value as any] = true as any;
1419
}
1520
}
1621
}

test/unit/lualib/set.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { Expect, Test, TestCase, FocusTests } from "alsatian";
1+
import { Expect, Test, TestCase } from "alsatian";
22
import * as util from "../../src/util";
33

4-
@FocusTests
54
export class SetTests {
65
@Test("set constructor")
76
public setConstructor() {

0 commit comments

Comments
 (0)