toilscript 0.1.60 → 0.1.62

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "imports": {
3
- "toilscript": "https://cdn.jsdelivr.net/npm/toilscript@0.1.60/dist/toilscript.js",
4
- "toilscript/cli": "https://cdn.jsdelivr.net/npm/toilscript@0.1.60/dist/cli.js",
3
+ "toilscript": "https://cdn.jsdelivr.net/npm/toilscript@0.1.62/dist/toilscript.js",
4
+ "toilscript/cli": "https://cdn.jsdelivr.net/npm/toilscript@0.1.62/dist/cli.js",
5
5
  "binaryen": "https://cdn.jsdelivr.net/npm/binaryen@130.0.0/index.js",
6
6
  "long": "https://cdn.jsdelivr.net/npm/long@5.3.2/index.js"
7
7
  }
package/dist/web.js CHANGED
@@ -1,8 +1,8 @@
1
- var ASSEMBLYSCRIPT_VERSION = "0.1.60";
1
+ var ASSEMBLYSCRIPT_VERSION = "0.1.62";
2
2
  var ASSEMBLYSCRIPT_IMPORTMAP = {
3
3
  "imports": {
4
- "toilscript": "https://cdn.jsdelivr.net/npm/toilscript@0.1.60/dist/toilscript.js",
5
- "toilscript/cli": "https://cdn.jsdelivr.net/npm/toilscript@0.1.60/dist/cli.js",
4
+ "toilscript": "https://cdn.jsdelivr.net/npm/toilscript@0.1.62/dist/toilscript.js",
5
+ "toilscript/cli": "https://cdn.jsdelivr.net/npm/toilscript@0.1.62/dist/cli.js",
6
6
  "binaryen": "https://cdn.jsdelivr.net/npm/binaryen@130.0.0/index.js",
7
7
  "long": "https://cdn.jsdelivr.net/npm/long@5.3.2/index.js"
8
8
  }
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "toilscript",
9
9
  "wasm"
10
10
  ],
11
- "version": "0.1.60",
11
+ "version": "0.1.62",
12
12
  "author": "Daniel Wirtz <dcode+assemblyscript@dcode.io>",
13
13
  "license": "Apache-2.0",
14
14
  "homepage": "https://github.com/dacely-cloud/toilscript",
@@ -300,20 +300,26 @@ export class JSON {
300
300
  // ---- shared string escaping ----
301
301
 
302
302
  private static quote(s: string): string {
303
- let out = "\"";
303
+ const out: i32[] = [0x22];
304
+ const digits = "0123456789abcdef";
304
305
  for (let i = 0, len = s.length; i < len; i++) {
305
306
  const c = s.charCodeAt(i);
306
- if (c == 0x22) out += "\\\"";
307
- else if (c == 0x5c) out += "\\\\";
308
- else if (c == 0x08) out += "\\b";
309
- else if (c == 0x0c) out += "\\f";
310
- else if (c == 0x0a) out += "\\n";
311
- else if (c == 0x0d) out += "\\r";
312
- else if (c == 0x09) out += "\\t";
313
- else if (c < 0x20) out += "\\u" + JSON.hex4(c);
314
- else out += String.fromCharCode(c);
307
+ if (c == 0x22 || c == 0x5c) { out.push(0x5c); out.push(c); }
308
+ else if (c < 0x20) {
309
+ out.push(0x5c);
310
+ if (c == 0x08) out.push(0x62);
311
+ else if (c == 0x0c) out.push(0x66);
312
+ else if (c == 0x0a) out.push(0x6e);
313
+ else if (c == 0x0d) out.push(0x72);
314
+ else if (c == 0x09) out.push(0x74);
315
+ else {
316
+ out.push(0x75);
317
+ for (let shift = 12; shift >= 0; shift -= 4) out.push(digits.charCodeAt((c >> shift) & 0xf));
318
+ }
319
+ } else out.push(c);
315
320
  }
316
- return out + "\"";
321
+ out.push(0x22);
322
+ return String.fromCharCodes(out);
317
323
  }
318
324
 
319
325
  private static hex4(c: i32): string {
@@ -394,7 +400,7 @@ class Parser {
394
400
  /** Read a quoted string starting at the current `"`. Sets err on failure. */
395
401
  private readString(): string {
396
402
  this.pos++; // opening "
397
- let out = "";
403
+ const out: i32[] = [];
398
404
  while (true) {
399
405
  if (this.atEnd()) {
400
406
  this.fail("unterminated string");
@@ -408,14 +414,14 @@ class Parser {
408
414
  return "";
409
415
  }
410
416
  const e = this.take();
411
- if (e == 0x22) out += "\"";
412
- else if (e == 0x5c) out += "\\";
413
- else if (e == 0x2f) out += "/";
414
- else if (e == 0x62) out += String.fromCharCode(0x08);
415
- else if (e == 0x66) out += String.fromCharCode(0x0c);
416
- else if (e == 0x6e) out += "\n";
417
- else if (e == 0x72) out += "\r";
418
- else if (e == 0x74) out += "\t";
417
+ if (e == 0x22) out.push(0x22);
418
+ else if (e == 0x5c) out.push(0x5c);
419
+ else if (e == 0x2f) out.push(0x2f);
420
+ else if (e == 0x62) out.push(0x08);
421
+ else if (e == 0x66) out.push(0x0c);
422
+ else if (e == 0x6e) out.push(0x0a);
423
+ else if (e == 0x72) out.push(0x0d);
424
+ else if (e == 0x74) out.push(0x09);
419
425
  else if (e == 0x75) {
420
426
  let code = 0;
421
427
  for (let k = 0; k < 4; k++) {
@@ -426,16 +432,17 @@ class Parser {
426
432
  }
427
433
  code = (code << 4) | d;
428
434
  }
429
- out += String.fromCharCode(code);
435
+ out.push(code);
430
436
  } else {
431
437
  this.fail("invalid escape");
432
438
  return "";
433
439
  }
434
440
  } else {
435
- out += String.fromCharCode(c);
441
+ if (c < 0x20) { this.fail("unescaped control character"); return ""; }
442
+ out.push(c);
436
443
  }
437
444
  }
438
- return out;
445
+ return String.fromCharCodes(out);
439
446
  }
440
447
 
441
448
  private parseNumber(): JSON {