@bablr/agast-helpers 0.1.2 → 0.1.4

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/lib/print.js CHANGED
@@ -2,6 +2,7 @@ const { isInteger, isFinite } = Number;
2
2
  const { isArray } = Array;
3
3
  const isString = (val) => typeof val === 'string';
4
4
  const isNumber = (val) => typeof val === 'number';
5
+ const isObject = (val) => val && typeof val === 'object' && !isArray(val);
5
6
 
6
7
  export const printExpression = (expr) => {
7
8
  if (isString(expr)) {
@@ -87,7 +88,9 @@ export const printReference = (terminal) => {
87
88
  };
88
89
 
89
90
  export const printNull = (terminal) => {
90
- if (terminal?.type !== 'Null') throw new Error();
91
+ if (terminal && terminal.type !== 'Null') {
92
+ throw new Error();
93
+ }
91
94
 
92
95
  return 'null';
93
96
  };
@@ -166,6 +169,8 @@ export const printCloseFragmentTag = (terminal) => {
166
169
  };
167
170
 
168
171
  export const printTerminal = (terminal) => {
172
+ if (!isObject(terminal)) throw new Error();
173
+
169
174
  switch (terminal?.type || 'Null') {
170
175
  case 'Null':
171
176
  return printNull(terminal);
package/lib/stream.js CHANGED
@@ -159,6 +159,8 @@ function* __generateCSTML(terminals) {
159
159
 
160
160
  yield* printTerminal(terminal);
161
161
  }
162
+
163
+ yield* '\n';
162
164
  }
163
165
 
164
166
  export const generateCSTML = (terminals) => new StreamIterable(__generateCSTML(terminals));
@@ -197,9 +199,9 @@ export const stringFromStream = (stream) => {
197
199
 
198
200
  if (co.done) break;
199
201
 
200
- const terminal = co.value;
202
+ const chr = co.value;
201
203
 
202
- str += printTerminal(terminal);
204
+ str += chr;
203
205
  }
204
206
 
205
207
  return str;
@@ -255,6 +257,8 @@ function* __generatePrettyCSTML(terminals, indent) {
255
257
 
256
258
  first = false;
257
259
  }
260
+
261
+ yield* '\n';
258
262
  }
259
263
 
260
264
  export const generatePrettyCSTML = (terminals, indent = ' ') => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bablr/agast-helpers",
3
3
  "description": "Helper functions for working with agAST trees",
4
- "version": "0.1.2",
4
+ "version": "0.1.4",
5
5
  "author": "Conrad Buck<conartist6@gmail.com>",
6
6
  "type": "module",
7
7
  "files": [