@bablr/agast-helpers 0.8.0 → 0.10.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/builders.js +159 -88
- package/lib/path.js +1571 -419
- package/lib/print.js +78 -41
- package/lib/shorthand.js +17 -13
- package/lib/stream.js +437 -164
- package/lib/symbols.js +5 -2
- package/lib/tags.js +285 -0
- package/lib/template.js +52 -46
- package/lib/tree.js +165 -687
- package/package.json +6 -4
- package/lib/children.js +0 -120
- package/lib/path-facade.js +0 -39
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.
|
|
4
|
+
"version": "0.10.0",
|
|
5
5
|
"author": "Conrad Buck<conartist6@gmail.com>",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
"exports": {
|
|
11
11
|
"./btree": "./lib/btree.js",
|
|
12
12
|
"./builders": "./lib/builders.js",
|
|
13
|
-
"./children": "./lib/children.js",
|
|
14
13
|
"./object": "./lib/object.js",
|
|
15
14
|
"./path-facade": "./lib/path-facade.js",
|
|
16
15
|
"./path": "./lib/path.js",
|
|
@@ -18,6 +17,7 @@
|
|
|
18
17
|
"./shorthand": "./lib/shorthand.js",
|
|
19
18
|
"./stream": "./lib/stream.js",
|
|
20
19
|
"./symbols": "./lib/symbols.js",
|
|
20
|
+
"./tags": "./lib/tags.js",
|
|
21
21
|
"./template": "./lib/template.js",
|
|
22
22
|
"./tree": "./lib/tree.js"
|
|
23
23
|
},
|
|
@@ -26,13 +26,15 @@
|
|
|
26
26
|
"test": "mocha test/*.test.js"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@bablr/btree": "0.4.
|
|
29
|
+
"@bablr/btree": "0.4.2",
|
|
30
30
|
"@bablr/coroutine": "0.1.0",
|
|
31
|
+
"@bablr/stream-iterator": "2.0.0",
|
|
31
32
|
"@bablr/weak-stack": "1.0.1",
|
|
32
|
-
"@iter-tools/imm-stack": "1.
|
|
33
|
+
"@iter-tools/imm-stack": "1.2.0"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
36
|
"@bablr/eslint-config-base": "github:bablr-lang/eslint-config-base#c97bfa4b3663f8378e9b3e42bb5a41e685406cf9",
|
|
37
|
+
"@qnighy/dedent": "0.1.1",
|
|
36
38
|
"enhanced-resolve": "^5.12.0",
|
|
37
39
|
"eslint": "^8.32.0",
|
|
38
40
|
"eslint-import-resolver-enhanced-resolve": "^1.0.5",
|
package/lib/children.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { buildModule, defaultNodeSize } from '@bablr/btree/enhanceable';
|
|
2
|
-
import {
|
|
3
|
-
BindingTag,
|
|
4
|
-
InitializerTag,
|
|
5
|
-
LiteralTag,
|
|
6
|
-
OpenNodeTag,
|
|
7
|
-
Property,
|
|
8
|
-
ReferenceTag,
|
|
9
|
-
} from './symbols.js';
|
|
10
|
-
|
|
11
|
-
const { isArray } = Array;
|
|
12
|
-
const { freeze } = Object;
|
|
13
|
-
|
|
14
|
-
export { defaultNodeSize };
|
|
15
|
-
|
|
16
|
-
const {
|
|
17
|
-
btreeFrom: sumTreeFrom,
|
|
18
|
-
from,
|
|
19
|
-
btreeFromValues: sumTreeFromValues,
|
|
20
|
-
fromValues,
|
|
21
|
-
findBalancePoint,
|
|
22
|
-
splitValues,
|
|
23
|
-
collapses,
|
|
24
|
-
nodeCollapses,
|
|
25
|
-
nodeCanDonate,
|
|
26
|
-
pop,
|
|
27
|
-
push: push_,
|
|
28
|
-
addAt,
|
|
29
|
-
isValidNode,
|
|
30
|
-
assertValidNode,
|
|
31
|
-
getValues,
|
|
32
|
-
getSums,
|
|
33
|
-
setValues,
|
|
34
|
-
isLeafNode,
|
|
35
|
-
traverse,
|
|
36
|
-
getSize,
|
|
37
|
-
findPath,
|
|
38
|
-
getAt,
|
|
39
|
-
replaceAt,
|
|
40
|
-
} = buildModule(
|
|
41
|
-
defaultNodeSize,
|
|
42
|
-
(acc, val) => {
|
|
43
|
-
const { references, specialTypes } = acc;
|
|
44
|
-
if (isArray(val)) {
|
|
45
|
-
acc.lineBreaks += val[2].lineBreaks;
|
|
46
|
-
for (const { 0: key, 1: value } of Object.entries(val[2].references)) {
|
|
47
|
-
references[key] = (references[key] ?? 0) + value;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
for (const { 0: key, 1: value } of Object.entries(val[2].specialTypes)) {
|
|
51
|
-
specialTypes[key] = (specialTypes[key] ?? 0) + value;
|
|
52
|
-
}
|
|
53
|
-
} else {
|
|
54
|
-
if (val.type === LiteralTag) {
|
|
55
|
-
let text = val.value;
|
|
56
|
-
let idx = 0;
|
|
57
|
-
while ((idx = text.indexOf('\n', idx + 1)) >= 0) {
|
|
58
|
-
acc.lineBreaks++;
|
|
59
|
-
}
|
|
60
|
-
} else if (val.type === ReferenceTag) {
|
|
61
|
-
const { type, name } = val.value;
|
|
62
|
-
if (type) {
|
|
63
|
-
specialTypes[type] = (specialTypes[type] ?? 0) + 1;
|
|
64
|
-
} else {
|
|
65
|
-
references[name] = (references[name] ?? 0) + 1;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return acc;
|
|
70
|
-
},
|
|
71
|
-
() => ({
|
|
72
|
-
lineBreaks: 0,
|
|
73
|
-
references: {},
|
|
74
|
-
specialTypes: {},
|
|
75
|
-
}),
|
|
76
|
-
(stats) => {
|
|
77
|
-
freeze(stats);
|
|
78
|
-
freeze(stats.references);
|
|
79
|
-
},
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
const push = (children, tag) => {
|
|
83
|
-
let lastTag = getAt(-1, children);
|
|
84
|
-
|
|
85
|
-
if (tag.type === Property && lastTag.type !== BindingTag) {
|
|
86
|
-
throw new Error();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (lastTag?.type === ReferenceTag && ![BindingTag, InitializerTag].includes(tag.type)) {
|
|
90
|
-
throw new Error();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return push_(children, tag);
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
export {
|
|
97
|
-
sumTreeFrom as btreeFrom,
|
|
98
|
-
from,
|
|
99
|
-
sumTreeFromValues as btreeFromValues,
|
|
100
|
-
fromValues,
|
|
101
|
-
findBalancePoint,
|
|
102
|
-
splitValues,
|
|
103
|
-
collapses,
|
|
104
|
-
nodeCollapses,
|
|
105
|
-
nodeCanDonate,
|
|
106
|
-
pop,
|
|
107
|
-
push,
|
|
108
|
-
addAt,
|
|
109
|
-
isValidNode,
|
|
110
|
-
assertValidNode,
|
|
111
|
-
getValues,
|
|
112
|
-
getSums,
|
|
113
|
-
setValues,
|
|
114
|
-
isLeafNode,
|
|
115
|
-
traverse,
|
|
116
|
-
getSize,
|
|
117
|
-
findPath,
|
|
118
|
-
getAt,
|
|
119
|
-
replaceAt,
|
|
120
|
-
};
|
package/lib/path-facade.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { CloseNodeTag, ReferenceTag } from './symbols.js';
|
|
2
|
-
|
|
3
|
-
export function* allTagPathsFor(range, options = {}) {
|
|
4
|
-
if (range == null) return;
|
|
5
|
-
|
|
6
|
-
const { unshift = false } = options;
|
|
7
|
-
let startPath = range[0];
|
|
8
|
-
let endPath = range[1];
|
|
9
|
-
let path = startPath;
|
|
10
|
-
|
|
11
|
-
while (path) {
|
|
12
|
-
if (path.inner && path.previousSibling.tag.type === ReferenceTag) {
|
|
13
|
-
path = path.inner.tagPathAt(0);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (path.path.depth < startPath.path.depth) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
yield path;
|
|
21
|
-
|
|
22
|
-
if (endPath && endPath.equalTo(path)) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
let propPath = path.path.parent && path.path.parent.tagPathAt(path.path.referenceIndex + 2);
|
|
27
|
-
|
|
28
|
-
if (endPath && path.tag.type === CloseNodeTag && propPath && endPath.equalTo(propPath)) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
path = unshift ? path.nextUnshifted : path.next;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function* allTagsFor(range, options = {}) {
|
|
36
|
-
for (let path of allTagPathsFor(range, options)) {
|
|
37
|
-
yield path.tag;
|
|
38
|
-
}
|
|
39
|
-
}
|