@graffiticode/basis 1.4.0 → 1.5.0

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/compiler.js +20 -15
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@graffiticode/basis",
3
3
  "type": "module",
4
- "version": "1.4.0",
4
+ "version": "1.5.0",
5
5
  "description": "The basis library for creating Graffiticode languages",
6
6
  "main": "index.js",
7
7
  "scripts": {
package/src/compiler.js CHANGED
@@ -25,20 +25,25 @@ class Visitor {
25
25
  this.root = code.root;
26
26
  }
27
27
  visit(nid, options, resume) {
28
- assert(nid);
29
- let node;
30
- if (typeof nid === "object") {
31
- node = nid;
32
- } else {
33
- node = this.nodePool[nid];
34
- }
35
- assert(node && node.tag && node.elts, "2000: Visitor.visit() tag=" + node.tag + " elts= " + JSON.stringify(node.elts));
36
- assert(this[node.tag], "2000: Visitor function not defined for: " + node.tag);
37
- assert(typeof resume === "function", message(1003));
38
- if (!options.SYNC && ASYNC) {
39
- setTimeout(() => this[node.tag](node, options, resume), 0);
40
- } else {
41
- this[node.tag](node, options, resume);
28
+ try {
29
+ assert(nid);
30
+ let node;
31
+ if (typeof nid === "object") {
32
+ node = nid;
33
+ } else {
34
+ node = this.nodePool[nid];
35
+ }
36
+ assert(node && node.tag && node.elts, "2000: Visitor.visit() tag=" + node.tag + " elts= " + JSON.stringify(node.elts));
37
+ assert(this[node.tag], "2000: Visitor function not defined for: " + node.tag);
38
+ assert(typeof resume === "function", message(1003));
39
+ if (!options.SYNC && ASYNC) {
40
+ // This is used to keep from blowing the call stack.
41
+ setTimeout(() => this[node.tag](node, options, resume), 0);
42
+ } else {
43
+ this[node.tag](node, options, resume);
44
+ }
45
+ } catch (x) {
46
+ resume(error(x.stack));
42
47
  }
43
48
  }
44
49
  node(nid) {
@@ -139,7 +144,7 @@ export class Checker extends Visitor {
139
144
  }
140
145
  JSON(node, options, resume) {
141
146
  this.visit(node.elts[0], options, (e0, v0) => {
142
- assert(v0.tag === "STR");
147
+ assert(v0.tag === "STR", JSON.stringify(v0, null, 2));
143
148
  const err = [];
144
149
  const val = node;
145
150
  resume(err, val);