Skip to content

Commit 8b4cf5c

Browse files
Willem Wyndhamdependabot-preview[bot]
Willem Wyndham
andauthored
Make consts and former static fields lazy (near#78)
* Bump assemblyscript from 0.13.8 to 0.14.9 Bumps [assemblyscript](https://github.com/AssemblyScript/assemblyscript) from 0.13.8 to 0.14.9. - [Release notes](https://github.com/AssemblyScript/assemblyscript/releases) - [Commits](AssemblyScript/assemblyscript@v0.13.8...v0.14.9) Signed-off-by: dependabot-preview[bot] <[email protected]> * fix: change _JSON to a namespace and lazily instantiate Handlers * fix: add lazy to more consts Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
1 parent 3424505 commit 8b4cf5c

File tree

5 files changed

+29
-23
lines changed

5 files changed

+29
-23
lines changed

assembly/JSON.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Buffer } from "./util";
22
import { JSONDecoder } from "./decoder";
33

4-
54
class Handler {
65
stack: JSON.Value[] = new Array<JSON.Value>();
76

@@ -79,12 +78,12 @@ class Handler {
7978
}
8079
}
8180

82-
class _JSON {
83-
private static handler: Handler = new Handler();
84-
private static decoder: JSONDecoder<Handler> = new JSONDecoder<Handler>(_JSON.handler);
81+
namespace _JSON {
82+
@lazy export const handler: Handler = new Handler();
83+
@lazy export const decoder: JSONDecoder<Handler> = new JSONDecoder<Handler>(_JSON.handler);
8584

8685
/** Parses a string or Uint8Array and returns a Json Value. */
87-
static parse<T = Uint8Array>(str: T): JSON.Value {
86+
export function parse<T = Uint8Array>(str: T): JSON.Value {
8887
var arr: Uint8Array;
8988
if (isString<T>(str)){
9089
arr = Buffer.fromString(<string>str);

assembly/decoder.ts

+14-7
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,20 @@ export class ThrowingJSONHandler extends JSONHandler {
6060
}
6161
}
6262

63-
const TRUE_STR = "true";
64-
const FALSE_STR = "false";
65-
const NULL_STR = "null";
66-
const CHAR_0: i32 = 48; //"0".charCodeAt(0);
67-
const CHAR_9: i32 = 57; //"9".charCodeAt(0);
68-
const CHAR_A: i32 = 65; //"A".charCodeAt(0);
69-
const CHAR_A_LOWER: i32 = 97; //"a".charCodeAt(0);
63+
//@ts-ignore: decorator
64+
@lazy const TRUE_STR = "true";
65+
//@ts-ignore: decorator
66+
@lazy const FALSE_STR = "false";
67+
//@ts-ignore: decorator
68+
@lazy const NULL_STR = "null";
69+
//@ts-ignore: decorator
70+
@lazy const CHAR_0: i32 = 48; //"0".charCodeAt(0);
71+
//@ts-ignore: decorator
72+
@lazy const CHAR_9: i32 = 57; //"9".charCodeAt(0);
73+
//@ts-ignore: decorator
74+
@lazy const CHAR_A: i32 = 65; //"A".charCodeAt(0);
75+
//@ts-ignore: decorator
76+
@lazy const CHAR_A_LOWER: i32 = 97; //"a".charCodeAt(0);
7077

7178
export class DecoderState {
7279
lastKey: string = "";

assembly/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "../node_modules/assemblyscript/std/assembly.json",
2+
"extends": "assemblyscript/std/assembly.json",
33
"include": [
44
"./**/*.ts"
55
]

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
},
1111
"devDependencies": {
1212
"@as-pect/cli": "^4.0.0",
13-
"assemblyscript": "^0.13.3"
13+
"assemblyscript": "^0.14.9"
1414
}
1515
}

yarn.lock

+9-9
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,23 @@ ansi-styles@^4.1.0:
6565
"@types/color-name" "^1.1.1"
6666
color-convert "^2.0.1"
6767

68-
assemblyscript@^0.13.3:
69-
version "0.13.8"
70-
resolved "https://registry.yarnpkg.com/assemblyscript/-/assemblyscript-0.13.8.tgz#be86486c4c178169be069b6265d70dfbab127756"
71-
integrity sha512-HOwnJd/Fs88jPuQVA1Waz/njGJfu1tPQCL4hGas3XDvap6xVQUFGxx4hCxn8kFC8kSmVC3MBgFkWz+VPTes7Bw==
68+
assemblyscript@^0.14.9:
69+
version "0.14.9"
70+
resolved "https://registry.yarnpkg.com/assemblyscript/-/assemblyscript-0.14.9.tgz#f738c228e68d52c9b5f2ca40d1614c0118b7eea2"
71+
integrity sha512-4e67IC2hQ1XOwOp+Sz9w84y7uAMCiU4GHw0J9+A5aWeEDM0lYp8knYCRw1DCJTj1mZVLdpsD5mIIrXcmcVb+FA==
7272
dependencies:
73-
binaryen "93.0.0-nightly.20200609"
73+
binaryen "95.0.0-nightly.20200813"
7474
long "^4.0.0"
7575

7676
balanced-match@^1.0.0:
7777
version "1.0.0"
7878
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
7979
integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c=
8080

81-
binaryen@93.0.0-nightly.20200609:
82-
version "93.0.0-nightly.20200609"
83-
resolved "https://registry.yarnpkg.com/binaryen/-/binaryen-93.0.0-nightly.20200609.tgz#e7c9211911c0cff94b8682e895e4de630f110cd5"
84-
integrity sha512-CIaeav05u+fWRN2h1ecwIoSaOF/Mk6U85M/G6eg1nOHAXYYmOuh9TztF9Fu8krRWnl98J3W+VfDClApMV5zCtw==
81+
binaryen@95.0.0-nightly.20200813:
82+
version "95.0.0-nightly.20200813"
83+
resolved "https://registry.yarnpkg.com/binaryen/-/binaryen-95.0.0-nightly.20200813.tgz#c84b332a7b06d4a9a2096c57b29c3e889130bcfb"
84+
integrity sha512-xY+fhSAkVxptBoQAn9X4o21zTFycOjc+PeqbWSwcDqrSmXBXUMeq7qHhz4EWSWlFDKobHeUaiIbzLzlmciDWHw==
8585

8686
brace-expansion@^1.1.7:
8787
version "1.1.11"

0 commit comments

Comments
 (0)