@bablr/agast-helpers 0.1.6 → 0.2.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.
- package/lib/print.js +1 -0
- package/lib/stream.js +9 -2
- package/lib/tree.js +1 -8
- package/package.json +1 -1
package/lib/print.js
CHANGED
|
@@ -15,6 +15,7 @@ export const printExpression = (expr) => {
|
|
|
15
15
|
return String(expr);
|
|
16
16
|
} else if (isNumber(expr)) {
|
|
17
17
|
if (!isFinite(expr)) {
|
|
18
|
+
if (isNaN(expr)) throw new Error();
|
|
18
19
|
return expr === -Infinity ? '-Infinity' : '+Infinity';
|
|
19
20
|
} else if (isInteger(expr)) {
|
|
20
21
|
return String(expr);
|
package/lib/stream.js
CHANGED
|
@@ -204,6 +204,8 @@ export const generateStandardOutput = (terminals) =>
|
|
|
204
204
|
function* __generateAllOutput(terminals) {
|
|
205
205
|
const co = new Coroutine(getStreamIterator(terminals));
|
|
206
206
|
|
|
207
|
+
let currentStream = null;
|
|
208
|
+
|
|
207
209
|
for (;;) {
|
|
208
210
|
co.advance();
|
|
209
211
|
|
|
@@ -217,6 +219,11 @@ function* __generateAllOutput(terminals) {
|
|
|
217
219
|
if (terminal.type === 'Effect') {
|
|
218
220
|
const effect = terminal.value;
|
|
219
221
|
if (effect.verb === 'write') {
|
|
222
|
+
const prevStream = currentStream;
|
|
223
|
+
currentStream = effect.value.options.stream || 1;
|
|
224
|
+
if (prevStream && prevStream !== currentStream && !effect.value.text.startsWith('\n')) {
|
|
225
|
+
yield* '\n';
|
|
226
|
+
}
|
|
220
227
|
yield* effect.value.text;
|
|
221
228
|
}
|
|
222
229
|
}
|
|
@@ -272,7 +279,7 @@ export const stringFromStream = (stream) => {
|
|
|
272
279
|
};
|
|
273
280
|
|
|
274
281
|
function* __generatePrettyCSTMLStrategy(terminals, options) {
|
|
275
|
-
const { indent = ' ',
|
|
282
|
+
const { indent = ' ', emitEffects = false, inline: inlineOption = true } = options;
|
|
276
283
|
|
|
277
284
|
if (!terminals) {
|
|
278
285
|
yield buildWriteEffect('<//>');
|
|
@@ -296,7 +303,7 @@ function* __generatePrettyCSTMLStrategy(terminals, options) {
|
|
|
296
303
|
|
|
297
304
|
if (terminal.type === 'Effect') {
|
|
298
305
|
const effect = terminal.value;
|
|
299
|
-
if (
|
|
306
|
+
if (emitEffects && effect.verb === 'write') {
|
|
300
307
|
yield buildWriteEffect((first ? '' : '\n') + effect.value.text, effect.value.options);
|
|
301
308
|
|
|
302
309
|
first = false;
|
package/lib/tree.js
CHANGED
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
buildEmbedded,
|
|
8
8
|
nodeFlags,
|
|
9
9
|
buildDoctypeTag,
|
|
10
|
-
buildReference,
|
|
11
10
|
} from './builders.js';
|
|
12
11
|
import {
|
|
13
12
|
printPrettyCSTML as printPrettyCSTMLFromStream,
|
|
@@ -140,10 +139,6 @@ function* __treeFromStream(tokens) {
|
|
|
140
139
|
break;
|
|
141
140
|
}
|
|
142
141
|
|
|
143
|
-
if (nodes.size === 1 && !flags.trivia) {
|
|
144
|
-
node.children.push(buildReference('root', false));
|
|
145
|
-
}
|
|
146
|
-
|
|
147
142
|
const newNode = freeze({
|
|
148
143
|
flags,
|
|
149
144
|
language,
|
|
@@ -158,9 +153,7 @@ function* __treeFromStream(tokens) {
|
|
|
158
153
|
throw new Error('Nodes must follow references');
|
|
159
154
|
}
|
|
160
155
|
|
|
161
|
-
const { name, isArray } = node.
|
|
162
|
-
? arrayLast(node.children).value
|
|
163
|
-
: { name: 'root', isArray: false };
|
|
156
|
+
const { name, isArray } = arrayLast(node.children).value;
|
|
164
157
|
|
|
165
158
|
if (isArray) {
|
|
166
159
|
if (!hasOwn(node.properties, name)) {
|