@graffiticode/basis 1.5.0 → 1.5.2

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.
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.2",
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) => {
package/src/share.js CHANGED
@@ -1,5 +1,3 @@
1
- /* -*- Mode: js; js-indent-level: 2; indent-tabs-mode: nil; tab-width: 2 -*- */
2
- /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
3
1
  /*
4
2
  * Copyright 2013 Art Compiler LLC
5
3
  *
@@ -77,7 +75,6 @@
77
75
 
78
76
  */
79
77
 
80
- import Hashids from 'hashids';
81
78
  import https from 'https';
82
79
 
83
80
  export const messages = {};
@@ -116,76 +113,6 @@ export const reserveCodeRange = function (first, last, moduleName) {
116
113
  reservedCodes.push({first: first, last: last, name: moduleName});
117
114
  }
118
115
 
119
- const hashids = new Hashids("Art Compiler LLC"); // This string shall never change!
120
- export const decodeID = (id) => {
121
- // console.log("[1] decodeID() >> " + id);
122
- // 123456, 123+534653+0, Px4xO423c, 123+123456+0+Px4xO423c, Px4xO423c+Px4xO423c
123
- if (id === undefined) {
124
- id = "0";
125
- }
126
- if (Number.isInteger(id)) {
127
- id = "" + id;
128
- }
129
- if (Array.isArray(id)) {
130
- // Looks like it is already decoded.
131
- assert(Number.isInteger(id[0]) && Number.isInteger(id[1]));
132
- return id;
133
- }
134
- assert(typeof id === "string", "Invalid id " + id);
135
- id = id.replace(/\+/g, " ");
136
- let parts = id.split(" ");
137
- let ids = [];
138
- // Concatenate the first two integer ids and the last hash id. Everything
139
- // else gets erased.
140
- for (let i = 0; i < parts.length; i++) {
141
- let n;
142
- if (ids.length > 2) {
143
- // Found the head, now skip to the last part to get the tail.
144
- ids = ids.slice(0, 2);
145
- i = parts.length - 1;
146
- }
147
- if (Number.isInteger(n = +parts[i])) {
148
- ids.push(n);
149
- } else {
150
- ids = ids.concat(hashids.decode(parts[i]));
151
- }
152
- }
153
- // Fix short ids.
154
- if (ids.length === 1) {
155
- ids = [0, ids[0], 0];
156
- } else if (ids.length === 2) {
157
- ids = [0, ids[0], 113, ids[1], 0];
158
- } else if (ids.length === 3 && ids[2] !== 0) {
159
- ids = [ids[0], ids[1], 113, ids[2], 0];
160
- }
161
- // console.log("[2] decodeID() << " + JSON.stringify(ids));
162
- return ids;
163
- };
164
-
165
- export const encodeID = (ids) => {
166
- // console.log("[1] encodeID() >> " + JSON.stringify(ids));
167
- let length = ids.length;
168
- if (length >= 3 &&
169
- // [0,0,0] --> "0"
170
- +ids[length - 3] === 0 &&
171
- +ids[length - 2] === 0 &&
172
- +ids[length - 1] === 0) {
173
- ids = ids.slice(0, length - 2);
174
- length = ids.length;
175
- }
176
- if (length === 1) {
177
- if (+ids[0] === 0) {
178
- return "0";
179
- }
180
- ids = [0, +ids[0], 0];
181
- } else if (length === 2) {
182
- ids = [0, +ids[0], 113, +ids[1], 0];
183
- }
184
- let id = hashids.encode(ids);
185
- // console.log("[2] encodeID() << " + id);
186
- return id;
187
- };
188
-
189
116
  function postAuth(path, data, resume) {
190
117
  let encodedData = JSON.stringify(data);
191
118
  var options = {