@bablr/agast-vm-helpers 0.5.0 → 0.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.
- package/lib/index.js +62 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -5,6 +5,8 @@ import { buildNodeCloseTag, buildLiteralTag, buildDoctypeTag } from '@bablr/agas
|
|
|
5
5
|
import {
|
|
6
6
|
DoctypeTag,
|
|
7
7
|
OpenNodeTag,
|
|
8
|
+
OpenFragmentTag,
|
|
9
|
+
CloseFragmentTag,
|
|
8
10
|
CloseNodeTag,
|
|
9
11
|
ReferenceTag,
|
|
10
12
|
ShiftTag,
|
|
@@ -84,6 +86,31 @@ export const reifyProperties = (properties = []) => {
|
|
|
84
86
|
return built;
|
|
85
87
|
};
|
|
86
88
|
|
|
89
|
+
export const buildFragmentChildren = (node) => {
|
|
90
|
+
let { open, children = [], close } = node.properties;
|
|
91
|
+
|
|
92
|
+
let built = [];
|
|
93
|
+
|
|
94
|
+
open = reifyExpression(open);
|
|
95
|
+
close = reifyExpression(close);
|
|
96
|
+
|
|
97
|
+
built = btree.push(built, open);
|
|
98
|
+
|
|
99
|
+
for (const child of btree.traverse(children)) {
|
|
100
|
+
if (child.type !== 'Property') throw new Error('umimplemented');
|
|
101
|
+
|
|
102
|
+
let { reference } = child.properties;
|
|
103
|
+
|
|
104
|
+
reference = reifyExpression(reference);
|
|
105
|
+
|
|
106
|
+
built = btree.push(built, reference);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
built = btree.push(built, close);
|
|
110
|
+
|
|
111
|
+
return built;
|
|
112
|
+
};
|
|
113
|
+
|
|
87
114
|
export const buildChildren = (node) => {
|
|
88
115
|
let { open, children = [], close } = node.properties;
|
|
89
116
|
|
|
@@ -144,7 +171,7 @@ export const reifyExpression = (node) => {
|
|
|
144
171
|
type: null,
|
|
145
172
|
children: btree.addAt(
|
|
146
173
|
0,
|
|
147
|
-
|
|
174
|
+
buildFragmentChildren(node.properties.tree),
|
|
148
175
|
buildDoctypeTag(attributes),
|
|
149
176
|
),
|
|
150
177
|
properties,
|
|
@@ -171,6 +198,25 @@ export const reifyExpression = (node) => {
|
|
|
171
198
|
};
|
|
172
199
|
}
|
|
173
200
|
|
|
201
|
+
case 'Fragment': {
|
|
202
|
+
let { open, children } = node.properties;
|
|
203
|
+
|
|
204
|
+
open = reifyExpression(open);
|
|
205
|
+
|
|
206
|
+
let { flags } = open.value;
|
|
207
|
+
|
|
208
|
+
const properties = reifyProperties(children);
|
|
209
|
+
|
|
210
|
+
return {
|
|
211
|
+
flags,
|
|
212
|
+
language: null,
|
|
213
|
+
type: null,
|
|
214
|
+
children: buildChildren(node),
|
|
215
|
+
properties,
|
|
216
|
+
attributes: {},
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
174
220
|
case 'DoctypeTag': {
|
|
175
221
|
let { doctype, version, attributes } = node.properties;
|
|
176
222
|
return {
|
|
@@ -229,6 +275,21 @@ export const reifyExpression = (node) => {
|
|
|
229
275
|
return { type: CloseNodeTag, value: { language, type } };
|
|
230
276
|
}
|
|
231
277
|
|
|
278
|
+
case 'OpenFragmentTag': {
|
|
279
|
+
let { flags } = node.properties;
|
|
280
|
+
|
|
281
|
+
flags = reifyFlags(flags);
|
|
282
|
+
|
|
283
|
+
return {
|
|
284
|
+
type: OpenFragmentTag,
|
|
285
|
+
value: { flags },
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
case 'CloseFragmentTag': {
|
|
290
|
+
return { type: CloseFragmentTag, value: undefined };
|
|
291
|
+
}
|
|
292
|
+
|
|
232
293
|
case 'Integer': {
|
|
233
294
|
let { digits } = node.properties;
|
|
234
295
|
return parseInt(digits.map((digit) => getCooked(digit)).join(''), 10);
|