@graffiticode/basis 1.5.0 → 1.5.1

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 +14 -14
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@graffiticode/basis",
3
3
  "type": "module",
4
- "version": "1.5.0",
4
+ "version": "1.5.1",
5
5
  "description": "The basis library for creating Graffiticode languages",
6
6
  "main": "index.js",
7
7
  "scripts": {
package/src/compiler.js CHANGED
@@ -541,17 +541,21 @@ export class Transformer extends Visitor {
541
541
  }
542
542
  RECORD(node, options, resume) {
543
543
  let err = [];
544
- let val = {};
545
544
  let len = 0;
546
545
  if (node.elts.length === 0) {
547
546
  resume(err, val);
548
547
  } else {
548
+ const ndx = [];
549
549
  for (let elt of node.elts.reverse()) {
550
550
  // For historical reasons, the bindings are reversed in the AST.
551
551
  this.visit(elt, options, (e0, v0) => {
552
552
  err = err.concat(e0);
553
- val[v0.key] = v0.val;
553
+ ndx[elt] = v0;
554
554
  if (++len === node.elts.length) {
555
+ // This is a little trickery to restore the original order of the,
556
+ // given that they may have been reordered do to the node being
557
+ // visited asynchronously.
558
+ const val = index.reduce((acc, v0) => ({...acc, [v0.key]: v0.val}), {});
555
559
  resume(err, val);
556
560
  }
557
561
  });
@@ -613,19 +617,15 @@ export class Transformer extends Visitor {
613
617
  resume(err, val);
614
618
  }
615
619
  DATA(node, options, resume) {
616
- if (options.data && Object.keys(options.data).length !== 0) {
617
- // Got external data, so use it.
618
- const err = [];
619
- const val = options.data;
620
- resume(err, val);
621
- } else {
622
- // Otherwise, use the default data.
623
- this.visit(node.elts[0], options, (e0, v0) => {
624
- const err = e0;
625
- const val = v0;
626
- resume(err, val);
620
+ this.visit(node.elts[0], options, (e0, v0) => {
621
+ const data = options.data || {};
622
+ const err = e0;
623
+ const val = v0;
624
+ resume(err, {
625
+ ...val,
626
+ ...data, // External data overrides internal data.
627
627
  });
628
- }
628
+ });
629
629
  }
630
630
  PAREN(node, options, resume) {
631
631
  this.visit(node.elts[0], options, (e0, v0) => {