mirror of
https://github.com/fluencelabs/assemblyscript-json
synced 2025-03-15 03:00:50 +00:00
add null checks
This commit is contained in:
parent
64675e7e53
commit
a177d4b61f
@ -54,7 +54,7 @@ export class JSONEncoder {
|
|||||||
this.isFirstKey.pop();
|
this.isFirstKey.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
pushObject(name: string): bool {
|
pushObject(name: string | null): bool {
|
||||||
this.writeKey(name);
|
this.writeKey(name);
|
||||||
this.write("{");
|
this.write("{");
|
||||||
this.isFirstKey.push(true);
|
this.isFirstKey.push(true);
|
||||||
@ -66,14 +66,14 @@ export class JSONEncoder {
|
|||||||
this.isFirstKey.pop();
|
this.isFirstKey.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
private writeKey(str: string): void {
|
private writeKey(str: string | null): void {
|
||||||
if (!this.isFirstKey[this.isFirstKey.length - 1]) {
|
if (!this.isFirstKey[this.isFirstKey.length - 1]) {
|
||||||
this.write(",");
|
this.write(",");
|
||||||
} else {
|
} else {
|
||||||
this.isFirstKey[this.isFirstKey.length - 1] = false;
|
this.isFirstKey[this.isFirstKey.length - 1] = false;
|
||||||
}
|
}
|
||||||
if (str != null) {
|
if (str != null) {
|
||||||
this.writeString(str);
|
this.writeString(str as string);
|
||||||
this.write(":");
|
this.write(":");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user