@graffiticode/basis 1.5.4 → 1.5.6

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 +11 -7
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@graffiticode/basis",
3
3
  "type": "module",
4
- "version": "1.5.4",
4
+ "version": "1.5.6",
5
5
  "description": "The basis library for creating Graffiticode languages",
6
6
  "main": "index.js",
7
7
  "scripts": {
package/src/compiler.js CHANGED
@@ -33,14 +33,19 @@ class Visitor {
33
33
  } else {
34
34
  node = this.nodePool[nid];
35
35
  }
36
+ console.log(
37
+ "Visitor/visit()",
38
+ "node.tag=" + node.tag,
39
+ );
40
+ const fn = (this[node.tag] || this["CATCH_ALL"]).bind(this);
36
41
  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);
42
+ assert(fn, "2000: Visitor function not defined for: " + node.tag);
38
43
  assert(typeof resume === "function", message(1003));
39
44
  if (!options.SYNC && ASYNC) {
40
45
  // This is used to keep from blowing the call stack.
41
- setTimeout(() => this[node.tag](node, options, resume), 0);
46
+ setTimeout(() => fn(node, options, resume), 0);
42
47
  } else {
43
- this[node.tag](node, options, resume);
48
+ fn(node, options, resume);
44
49
  }
45
50
  } catch (x) {
46
51
  resume(error(x.stack));
@@ -366,7 +371,7 @@ export class Transformer extends Visitor {
366
371
  if (pattern.tag === undefined || node.tag === undefined) {
367
372
  return false;
368
373
  }
369
- const patternNid = this.internPattern(pattern);
374
+ const patternNid = this.internPattern(pattern);
370
375
  if (patternNid === this.internPattern(node) ||
371
376
  patternNid === this.internPattern(newNode('IDENT', ['_']))) {
372
377
  return true;
@@ -407,7 +412,6 @@ export class Transformer extends Visitor {
407
412
  return matches;
408
413
  }
409
414
 
410
-
411
415
  PROG(node, options, resume) {
412
416
  if (!options) {
413
417
  options = {};
@@ -485,7 +489,7 @@ export class Transformer extends Visitor {
485
489
  // elements, given that they may have been reordered due to the
486
490
  // nodes being visited asynchronously. The node ids are reversed,
487
491
  // so we need to add prepend the current v0 to the list.
488
- const val = ndx.reduce((acc, v0) => [v0, ...acc], []);
492
+ const val = node.elts.reduce((acc, elt) => [...acc, ndx[elt]], []);
489
493
  resume(err, val);
490
494
  }
491
495
  });
@@ -560,7 +564,7 @@ export class Transformer extends Visitor {
560
564
  // This is a little trickery to restore the original order of the
561
565
  // fields, given that they may have been reordered due to the nodes
562
566
  // being visited asynchronously.
563
- const val = ndx.reduce((acc, v0) => ({...acc, [v0.key]: v0.val}), {});
567
+ const val = node.elts.reduce((acc, elt) => ({...acc, [ndx[elt].key]: ndx[elt].val}), {});
564
568
  resume(err, val);
565
569
  }
566
570
  });