mirror of
https://github.com/fluencelabs/assemblyscript-json
synced 2025-03-15 11:10:49 +00:00
fix compilation
This commit is contained in:
parent
63a4f35b3f
commit
a22567e8c8
@ -1,6 +1,3 @@
|
||||
declare function logStr(str: string): void;
|
||||
declare function logF64(val: f64): void;
|
||||
|
||||
/**
|
||||
* Extend from this class to handle events from parser.
|
||||
* Default implementation traverses whole object tree and does nothing.
|
||||
@ -76,8 +73,8 @@ let CHAR_A_LOWER = "a".charCodeAt(0);
|
||||
|
||||
export class DecoderState {
|
||||
readIndex: i32 = 0;
|
||||
buffer: Uint8Array = null;
|
||||
lastKey: string = null;
|
||||
buffer: Uint8Array = new Uint8Array(0);
|
||||
lastKey: string | null = null;
|
||||
}
|
||||
|
||||
export class JSONDecoder<JSONHandlerT extends JSONHandler> {
|
||||
@ -89,7 +86,7 @@ export class JSONDecoder<JSONHandlerT extends JSONHandler> {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
deserialize(buffer: Uint8Array, decoderState: DecoderState = null): void {
|
||||
deserialize(buffer: Uint8Array, decoderState: DecoderState = null as DecoderState): void {
|
||||
if (decoderState) {
|
||||
this.state = decoderState;
|
||||
} else {
|
||||
@ -123,7 +120,7 @@ export class JSONDecoder<JSONHandlerT extends JSONHandler> {
|
||||
|| this.parseString()
|
||||
|| this.parseBoolean()
|
||||
|| this.parseNumber()
|
||||
|| this.parseNull()
|
||||
|| this.parseNull();
|
||||
this.skipWhitespace();
|
||||
return result;
|
||||
}
|
||||
@ -132,7 +129,7 @@ export class JSONDecoder<JSONHandlerT extends JSONHandler> {
|
||||
if (this.peekChar() != "{".charCodeAt(0)) {
|
||||
return false;
|
||||
}
|
||||
let key = this.state.lastKey;
|
||||
let key = this.state.lastKey as string;
|
||||
this.state.lastKey = null;
|
||||
if (this.handler.pushObject(key)) {
|
||||
this.readChar();
|
||||
@ -165,7 +162,7 @@ export class JSONDecoder<JSONHandlerT extends JSONHandler> {
|
||||
if (this.peekChar() != "[".charCodeAt(0)) {
|
||||
return false;
|
||||
}
|
||||
let key = this.state.lastKey;
|
||||
let key = this.state.lastKey as string;
|
||||
this.state.lastKey = null;
|
||||
if (this.handler.pushArray(key)) {
|
||||
this.readChar();
|
||||
@ -183,21 +180,21 @@ export class JSONDecoder<JSONHandlerT extends JSONHandler> {
|
||||
assert(this.readChar() == "]".charCodeAt(0), "Unexpected end of array");
|
||||
}
|
||||
this.handler.popArray();
|
||||
return true;;
|
||||
return true;
|
||||
}
|
||||
|
||||
private parseString(): bool {
|
||||
if (this.peekChar() != '"'.charCodeAt(0)) {
|
||||
return false;
|
||||
}
|
||||
this.handler.setString(this.state.lastKey, this.readString());
|
||||
this.handler.setString(this.state.lastKey as string, this.readString());
|
||||
return true;
|
||||
}
|
||||
|
||||
private readString(): string {
|
||||
assert(this.readChar() == '"'.charCodeAt(0), "Expected double-quoted string");
|
||||
let savedIndex = this.state.readIndex;
|
||||
let stringParts: Array<string> = null;
|
||||
let stringParts: Array<string> = null as Array<string>;
|
||||
for (;;) {
|
||||
let byte = this.readChar();
|
||||
assert(byte >= 0x20, "Unexpected control character");
|
||||
@ -231,8 +228,6 @@ export class JSONDecoder<JSONHandlerT extends JSONHandler> {
|
||||
savedIndex = this.state.readIndex;
|
||||
}
|
||||
}
|
||||
// Should never happen
|
||||
return "";
|
||||
}
|
||||
|
||||
private readEscapedChar(): string {
|
||||
@ -301,7 +296,7 @@ export class JSONDecoder<JSONHandlerT extends JSONHandler> {
|
||||
digits++;
|
||||
}
|
||||
if (digits > 0) {
|
||||
this.handler.setInteger(this.state.lastKey, number * sign);
|
||||
this.handler.setInteger(this.state.lastKey as string, number * sign);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -310,12 +305,12 @@ export class JSONDecoder<JSONHandlerT extends JSONHandler> {
|
||||
private parseBoolean(): bool {
|
||||
if (this.peekChar() == FALSE_STR.charCodeAt(0)) {
|
||||
this.readAndAssert(FALSE_STR);
|
||||
this.handler.setBoolean(this.state.lastKey, false);
|
||||
this.handler.setBoolean(this.state.lastKey as string, false);
|
||||
return true;
|
||||
}
|
||||
if (this.peekChar() == TRUE_STR.charCodeAt(0)) {
|
||||
this.readAndAssert(TRUE_STR);
|
||||
this.handler.setBoolean(this.state.lastKey, true);
|
||||
this.handler.setBoolean(this.state.lastKey as string, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -325,7 +320,7 @@ export class JSONDecoder<JSONHandlerT extends JSONHandler> {
|
||||
private parseNull(): bool {
|
||||
if (this.peekChar() == NULL_STR.charCodeAt(0)) {
|
||||
this.readAndAssert(NULL_STR);
|
||||
this.handler.setNull(this.state.lastKey);
|
||||
this.handler.setNull(this.state.lastKey as string);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
44
package-lock.json
generated
44
package-lock.json
generated
@ -4,6 +4,36 @@
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"@as-pect/assembly": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@as-pect/assembly/-/assembly-2.3.1.tgz",
|
||||
"integrity": "sha512-KYBhyTEnaVcJjN/1EpzLhpbUHKT3pJjCPxm+Mdc7obnZ9EdVz6vN/lw+BQjeL4cUi1YLsnvgl8ftXcup5jVbQA==",
|
||||
"dev": true
|
||||
},
|
||||
"@as-pect/cli": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@as-pect/cli/-/cli-2.3.1.tgz",
|
||||
"integrity": "sha512-ipcxrXnK9Xj1Foy92nSRsganapB+yxFe4HJ/RuwnjRQ9s8bqu0UwH12XbiHktcK7bJMs1H77/sqbQVxqoYHQcA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@as-pect/assembly": "^2.3.1",
|
||||
"@as-pect/core": "^2.3.1",
|
||||
"chalk": "^2.4.2",
|
||||
"glob": "^7.1.4"
|
||||
}
|
||||
},
|
||||
"@as-pect/core": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@as-pect/core/-/core-2.3.1.tgz",
|
||||
"integrity": "sha512-iwd4MkGuO1wZqo9/sPlT567XYK0PkMLzBvwfkXOM2zq1wwuc5GZQrKoofgYorA40KI0edJW39djtOmPwIhx2vA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@as-pect/assembly": "^2.3.1",
|
||||
"chalk": "^2.4.2",
|
||||
"csv-stringify": "^5.3.0",
|
||||
"long": "^4.0.0"
|
||||
}
|
||||
},
|
||||
"@protobufjs/utf8": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.0.tgz",
|
||||
@ -22,21 +52,15 @@
|
||||
"as-pect": {
|
||||
"version": "github:jtenner/as-pect#38025ef6ff7bf5a1727bbf685f98147d11598a71",
|
||||
"from": "github:jtenner/as-pect",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"chalk": "^2.4.2",
|
||||
"csv-stringify": "^5.3.0",
|
||||
"glob": "^7.1.4",
|
||||
"long": "^4.0.0"
|
||||
}
|
||||
"dev": true
|
||||
},
|
||||
"assemblyscript": {
|
||||
"version": "github:assemblyscript/assemblyscript#5a8eee0befabf7bdef20960bc5d0d4c5246e7603",
|
||||
"version": "github:assemblyscript/assemblyscript#addb99eff250af2af0241442d45ff3d23434e6f1",
|
||||
"from": "github:assemblyscript/assemblyscript",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@protobufjs/utf8": "^1.1.0",
|
||||
"binaryen": "84.0.0-nightly.20190522",
|
||||
"binaryen": "87.0.0-nightly.20190716",
|
||||
"glob": "^7.1.4",
|
||||
"long": "^4.0.0",
|
||||
"opencollective-postinstall": "^2.0.0",
|
||||
@ -200,7 +224,7 @@
|
||||
},
|
||||
"path-is-absolute": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
|
||||
"resolved": "http://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
|
||||
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
|
||||
"dev": true
|
||||
},
|
||||
|
@ -11,7 +11,8 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"assemblyscript": "github:assemblyscript/assemblyscript",
|
||||
"as-pect": "github:jtenner/as-pect"
|
||||
"as-pect": "github:jtenner/as-pect",
|
||||
"@as-pect/cli": "^2.2.0"
|
||||
},
|
||||
"dependencies": {}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user