astronomical 1.0.0-beta.14 → 1.0.0-beta.15
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/cjs/index.js +15 -18
- package/lib/cjs/nodeutils.js +9 -1
- package/lib/cjs/traverse.js +46 -8
- package/lib/cjs/types/index.d.ts +2 -1
- package/lib/cjs/types/index.d.ts.map +1 -1
- package/lib/cjs/types/nodeutils.d.ts +5 -2
- package/lib/cjs/types/nodeutils.d.ts.map +1 -1
- package/lib/cjs/types/traverse.d.ts +3 -0
- package/lib/cjs/types/traverse.d.ts.map +1 -1
- package/lib/esm/index.mjs +15 -18
- package/lib/esm/nodeutils.js +9 -1
- package/lib/esm/traverse.js +46 -8
- package/lib/esm/types/index.d.ts +2 -1
- package/lib/esm/types/index.d.ts.map +1 -1
- package/lib/esm/types/nodeutils.d.ts +5 -2
- package/lib/esm/types/nodeutils.d.ts.map +1 -1
- package/lib/esm/types/traverse.d.ts +3 -0
- package/lib/esm/types/traverse.d.ts.map +1 -1
- package/package.json +1 -1
package/lib/cjs/index.js
CHANGED
|
@@ -75,7 +75,7 @@ function breadCrumb(path) {
|
|
|
75
75
|
}
|
|
76
76
|
function createQuerier() {
|
|
77
77
|
const traverser = (0, traverse_1.default)();
|
|
78
|
-
const { getChildren, getBinding, createNodePath, traverse } = traverser;
|
|
78
|
+
const { getChildren, getPrimitiveChildren, getPrimitiveChildrenOrNodePaths, getBinding, createNodePath, traverse } = traverser;
|
|
79
79
|
function createFilter(filter, filterResult) {
|
|
80
80
|
if (filter.type == "and" || filter.type == "or" || filter.type == "equals") {
|
|
81
81
|
return {
|
|
@@ -190,20 +190,17 @@ function createQuerier() {
|
|
|
190
190
|
return functionNode;
|
|
191
191
|
}
|
|
192
192
|
function addPrimitiveAttributeIfMatch(fnode, path) {
|
|
193
|
-
if (!fnode.node.attribute ||
|
|
193
|
+
if (!fnode.node.attribute || fnode.node.value == undefined)
|
|
194
194
|
return;
|
|
195
195
|
if (fnode.node.child || fnode.node.filter)
|
|
196
196
|
return;
|
|
197
197
|
if (!Object.hasOwn(path.node, fnode.node.value))
|
|
198
198
|
return;
|
|
199
|
-
const
|
|
200
|
-
const nodes = toArray(lookup)
|
|
201
|
-
.filter(n => n.node != undefined)
|
|
202
|
-
.filter(n => (0, nodeutils_1.isPrimitive)(n.node));
|
|
199
|
+
const nodes = getPrimitiveChildren(fnode.node.value, path);
|
|
203
200
|
if (nodes.length == 0)
|
|
204
201
|
return;
|
|
205
|
-
log.debug("PRIMITIVE", fnode.node.value, nodes
|
|
206
|
-
fnode.result.push(...nodes
|
|
202
|
+
log.debug("PRIMITIVE", fnode.node.value, nodes);
|
|
203
|
+
fnode.result.push(...nodes);
|
|
207
204
|
}
|
|
208
205
|
function evaluateFilter(filter, path) {
|
|
209
206
|
log.debug("EVALUATING FILTER", filter, breadCrumb(path));
|
|
@@ -260,7 +257,6 @@ function createQuerier() {
|
|
|
260
257
|
}
|
|
261
258
|
return resolveDirectly(startNode, startPath);
|
|
262
259
|
}
|
|
263
|
-
const toArray = (value) => Array.isArray(value) ? value : [value];
|
|
264
260
|
function isDefined(value) {
|
|
265
261
|
return value != undefined && value != null;
|
|
266
262
|
}
|
|
@@ -273,31 +269,32 @@ function createQuerier() {
|
|
|
273
269
|
const lookup = startNode.value;
|
|
274
270
|
if (!lookup)
|
|
275
271
|
throw new Error("Selector must have a value");
|
|
276
|
-
log.debug("STEP IN ", lookup, paths.map(p => breadCrumb(p)));
|
|
277
|
-
const nodes = paths.map(n =>
|
|
278
|
-
log.debug("LOOKUP", lookup, path.node.type, nodes.map(n => n.node)
|
|
272
|
+
//log.debug("STEP IN ", lookup, paths.map(p => breadCrumb(p)));
|
|
273
|
+
const nodes = paths.filter(nodeutils_1.isNodePath).map(n => getPrimitiveChildrenOrNodePaths(lookup, n)).flat();
|
|
274
|
+
//log.debug("LOOKUP", lookup, path.node.type, nodes.map(n => n.node));
|
|
275
|
+
//console.log(nodes);
|
|
279
276
|
if (nodes.length == 0)
|
|
280
277
|
return [];
|
|
281
278
|
paths = nodes;
|
|
282
279
|
if (startNode.resolve) {
|
|
283
|
-
const resolved = paths.map(p => resolveBinding(p)).filter(isDefined).map(p => getChildren("init", p)).
|
|
280
|
+
const resolved = paths.filter(nodeutils_1.isNodePath).map(p => resolveBinding(p)).filter(isDefined).map(p => getChildren("init", p)).flat();
|
|
284
281
|
if (resolved.length > 0)
|
|
285
282
|
paths = resolved;
|
|
286
283
|
}
|
|
287
284
|
else if (startNode.binding) {
|
|
288
|
-
paths = paths.map(p => resolveBinding(p)).filter(isDefined);
|
|
285
|
+
paths = paths.filter(nodeutils_1.isNodePath).map(p => resolveBinding(p)).filter(isDefined);
|
|
289
286
|
}
|
|
290
287
|
const filter = startNode.filter;
|
|
291
288
|
if (filter) {
|
|
292
|
-
paths = paths.filter(p => travHandle({ subquery: filter }, p).subquery.length > 0);
|
|
289
|
+
paths = paths.filter(nodeutils_1.isNodePath).filter(p => travHandle({ subquery: filter }, p).subquery.length > 0);
|
|
293
290
|
}
|
|
294
291
|
if (!startNode.child) {
|
|
295
|
-
return paths.map(p => p.node);
|
|
292
|
+
return paths.map(p => (0, nodeutils_1.isPrimitive)(p) ? p : p.node);
|
|
296
293
|
}
|
|
297
294
|
startNode = startNode.child;
|
|
298
295
|
}
|
|
299
|
-
log.debug("DIRECT TRAV RESOLVE", startNode, paths.map(p => breadCrumb(p)));
|
|
300
|
-
const result = paths.flatMap(path => {
|
|
296
|
+
//log.debug("DIRECT TRAV RESOLVE", startNode, paths.map(p => breadCrumb(p)));
|
|
297
|
+
const result = paths.filter(nodeutils_1.isNodePath).flatMap(path => {
|
|
301
298
|
const subQueryKey = "subquery-" + subQueryCounter++;
|
|
302
299
|
return travHandle({ [subQueryKey]: startNode }, path)[subQueryKey];
|
|
303
300
|
});
|
package/lib/cjs/nodeutils.js
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isExportSpecifier = exports.isScopable = exports.isScope = exports.VISITOR_KEYS = exports.isBinding = exports.isVariableDeclarator = exports.isFunctionExpression = exports.isFunctionDeclaration = exports.isIdentifier = exports.isMemberExpression = exports.isAssignmentExpression = exports.isPrimitive = exports.isNode = void 0;
|
|
3
|
+
exports.isExportSpecifier = exports.isScopable = exports.isScope = exports.VISITOR_KEYS = exports.isBinding = exports.isVariableDeclarator = exports.isFunctionExpression = exports.isFunctionDeclaration = exports.isIdentifier = exports.isMemberExpression = exports.isAssignmentExpression = exports.isPrimitive = exports.isLiteral = exports.isNodePath = exports.isNode = void 0;
|
|
4
4
|
function isNode(candidate) {
|
|
5
5
|
return typeof candidate === "object" && candidate != null && "type" in candidate;
|
|
6
6
|
}
|
|
7
7
|
exports.isNode = isNode;
|
|
8
|
+
function isNodePath(candidate) {
|
|
9
|
+
return typeof candidate === "object" && candidate != null && "node" in candidate;
|
|
10
|
+
}
|
|
11
|
+
exports.isNodePath = isNodePath;
|
|
12
|
+
function isLiteral(candidate) {
|
|
13
|
+
return isNode(candidate) && candidate.type === "Literal";
|
|
14
|
+
}
|
|
15
|
+
exports.isLiteral = isLiteral;
|
|
8
16
|
function isPrimitive(value) {
|
|
9
17
|
return typeof value == "string" || typeof value == "number" || typeof value == "boolean";
|
|
10
18
|
}
|
package/lib/cjs/traverse.js
CHANGED
|
@@ -13,6 +13,7 @@ const scopes = new Array(100000);
|
|
|
13
13
|
function createTraverser() {
|
|
14
14
|
let scopeIdCounter = 0;
|
|
15
15
|
let removedScopes = 0;
|
|
16
|
+
//const nodePathsCreated: Record<string, number> = {}
|
|
16
17
|
function createScope(parentScopeId) {
|
|
17
18
|
const id = scopeIdCounter++;
|
|
18
19
|
scopes[id] = parentScopeId ?? -1;
|
|
@@ -26,7 +27,7 @@ function createTraverser() {
|
|
|
26
27
|
return getBinding(scope, name);
|
|
27
28
|
}
|
|
28
29
|
const s = scope.bindings[name];
|
|
29
|
-
if (s)
|
|
30
|
+
if (s != undefined)
|
|
30
31
|
return s;
|
|
31
32
|
if (scope.parentScopeId != undefined && scope.parentScopeId >= 0) {
|
|
32
33
|
return getBinding(scope.parentScopeId, name);
|
|
@@ -62,6 +63,31 @@ function createTraverser() {
|
|
|
62
63
|
}
|
|
63
64
|
return [];
|
|
64
65
|
}
|
|
66
|
+
function getPrimitiveChildren(key, path) {
|
|
67
|
+
if (key in path.node) {
|
|
68
|
+
const r = path.node[key];
|
|
69
|
+
return (0, utils_1.toArray)(r).filter(utils_1.isDefined).filter(nodeutils_1.isPrimitive);
|
|
70
|
+
}
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
73
|
+
function getPrimitiveChildrenOrNodePaths(key, path) {
|
|
74
|
+
if (key in path.node) {
|
|
75
|
+
const r = path.node[key];
|
|
76
|
+
if (Array.isArray(r)) {
|
|
77
|
+
return r.map((n, i) => (0, nodeutils_1.isPrimitive)(n) ? n :
|
|
78
|
+
// isLiteral(n) ? n.value as PrimitiveValue :
|
|
79
|
+
createNodePath(n, i.toString(), key, path.scopeId, path));
|
|
80
|
+
}
|
|
81
|
+
else if (r != undefined) {
|
|
82
|
+
return [
|
|
83
|
+
(0, nodeutils_1.isPrimitive)(r) ? r :
|
|
84
|
+
// isLiteral(r) ? r.value as PrimitiveValue :
|
|
85
|
+
createNodePath(r, key, key, path.scopeId, path)
|
|
86
|
+
];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
65
91
|
function createNodePath(node, key, parentKey, scopeId, nodePath) {
|
|
66
92
|
if (node.extra?.nodePath) {
|
|
67
93
|
const path = node.extra.nodePath;
|
|
@@ -83,6 +109,11 @@ function createTraverser() {
|
|
|
83
109
|
node.extra.nodePath = path;
|
|
84
110
|
Object.defineProperty(node.extra, "nodePath", { enumerable: false });
|
|
85
111
|
}
|
|
112
|
+
/*const x: string| undefined = node.type;
|
|
113
|
+
if (x == undefined) {
|
|
114
|
+
console.log("x", node, key, parentKey, nodePath?.node?.type);
|
|
115
|
+
}*/
|
|
116
|
+
//nodePathsCreated[node.type] = (nodePathsCreated[node.type] ?? 0) + 1;
|
|
86
117
|
pathsCreated++;
|
|
87
118
|
return path;
|
|
88
119
|
}
|
|
@@ -101,13 +132,16 @@ function createTraverser() {
|
|
|
101
132
|
}
|
|
102
133
|
}
|
|
103
134
|
}
|
|
135
|
+
let bindingNodesVisited = 0;
|
|
104
136
|
function registerBindings(node, parentNode, grandParentNode, scopeId) {
|
|
105
|
-
if (
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
137
|
+
if (!(0, nodeutils_1.isNode)(node))
|
|
138
|
+
return;
|
|
139
|
+
node.extra = node.extra ?? {};
|
|
140
|
+
if (node.extra["scopeId"] != undefined)
|
|
141
|
+
return;
|
|
142
|
+
node.extra["scopeId"] = scopeId;
|
|
143
|
+
bindingNodesVisited++;
|
|
144
|
+
;
|
|
111
145
|
const keys = nodeutils_1.VISITOR_KEYS[node.type];
|
|
112
146
|
//console.log(keys, node);
|
|
113
147
|
if (keys.length == 0)
|
|
@@ -160,14 +194,18 @@ function createTraverser() {
|
|
|
160
194
|
function traverse(node, visitor, scopeId, state, path) {
|
|
161
195
|
traverseInner(node, visitor, scopeId, state, path);
|
|
162
196
|
if (!sOut.includes(scopeIdCounter)) {
|
|
163
|
-
log.debug("Scopes created", scopeIdCounter, " Scopes removed", removedScopes, "Paths created", pathsCreated);
|
|
197
|
+
log.debug("Scopes created", scopeIdCounter, " Scopes removed", removedScopes, "Paths created", pathsCreated, bindingNodesVisited);
|
|
164
198
|
sOut.push(scopeIdCounter);
|
|
199
|
+
//const k = Object.fromEntries(Object.entries(nodePathsCreated).sort((a, b) => b[1] - a[1]));
|
|
200
|
+
//console.log("Node paths created", k);
|
|
165
201
|
}
|
|
166
202
|
}
|
|
167
203
|
return {
|
|
168
204
|
traverse,
|
|
169
205
|
createNodePath,
|
|
170
206
|
getChildren,
|
|
207
|
+
getPrimitiveChildren,
|
|
208
|
+
getPrimitiveChildrenOrNodePaths,
|
|
171
209
|
getBinding
|
|
172
210
|
};
|
|
173
211
|
}
|
package/lib/cjs/types/index.d.ts
CHANGED
|
@@ -15,7 +15,8 @@ export declare const functions: {
|
|
|
15
15
|
};
|
|
16
16
|
export type AvailableFunction = keyof typeof functions;
|
|
17
17
|
export declare function isAvailableFunction(name: string): name is AvailableFunction;
|
|
18
|
-
type
|
|
18
|
+
export type PrimitiveValue = string | number | boolean;
|
|
19
|
+
type Result = ASTNode | PrimitiveValue;
|
|
19
20
|
export declare function query(code: string | ASTNode, query: string, returnAST?: boolean): Result[] & {
|
|
20
21
|
__AST?: ASTNode;
|
|
21
22
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAwB,EAAG,OAAO,EAAY,MAAM,YAAY,CAAC;AAajE,eAAO,MAAM,SAAS;;qBAEL,MAAM,EAAE,EAAE,KAAG,MAAM,EAAE;;;qBAWrB,MAAM,EAAE,EAAE,KAAG,MAAM,EAAE;;;qBAMrB,MAAM,EAAE,EAAE,KAAG,MAAM,EAAE;;;qBAOrB,MAAM,EAAE,EAAE,KAAG,MAAM,EAAE;;CASrC,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG,MAAM,OAAO,SAAS,CAAC;AACvD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAI,IAAI,IAAI,iBAAiB,CAE5E;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAwB,EAAG,OAAO,EAAY,MAAM,YAAY,CAAC;AAajE,eAAO,MAAM,SAAS;;qBAEL,MAAM,EAAE,EAAE,KAAG,MAAM,EAAE;;;qBAWrB,MAAM,EAAE,EAAE,KAAG,MAAM,EAAE;;;qBAMrB,MAAM,EAAE,EAAE,KAAG,MAAM,EAAE;;;qBAOrB,MAAM,EAAE,EAAE,KAAG,MAAM,EAAE;;CASrC,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG,MAAM,OAAO,SAAS,CAAC;AACvD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAI,IAAI,IAAI,iBAAiB,CAE5E;AAGD,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAEvD,KAAK,MAAM,GAAG,OAAO,GAAG,cAAc,CAAC;AA4XvC,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,OAAO,GAAI,MAAM,EAAE,GAAG;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,CAQjH;AAED,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,EAAE,YAAY,EAAE,CAAC,EAAE,SAAS,CAAC,EAAE,OAAO,GAAI,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,CAY3K;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAI,OAAO,CAMpD"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { ESTree } from "meriyah";
|
|
2
|
-
import { ASTNode } from "./traverse";
|
|
2
|
+
import { ASTNode, NodePath } from "./traverse";
|
|
3
|
+
import { PrimitiveValue } from ".";
|
|
3
4
|
export declare function isNode(candidate: unknown): candidate is ASTNode;
|
|
4
|
-
export declare function
|
|
5
|
+
export declare function isNodePath(candidate: unknown): candidate is NodePath;
|
|
6
|
+
export declare function isLiteral(candidate: unknown): candidate is ESTree.Literal;
|
|
7
|
+
export declare function isPrimitive(value: unknown): value is PrimitiveValue;
|
|
5
8
|
export declare function isAssignmentExpression(node: ESTree.Node): node is ESTree.AssignmentExpression;
|
|
6
9
|
export declare function isMemberExpression(node: ESTree.Node): node is ESTree.MemberExpression;
|
|
7
10
|
export declare function isIdentifier(node: ESTree.Node): node is ESTree.Identifier;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodeutils.d.ts","sourceRoot":"","sources":["../../../src/nodeutils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"nodeutils.d.ts","sourceRoot":"","sources":["../../../src/nodeutils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,GAAG,CAAC;AAEnC,wBAAgB,MAAM,CAAC,SAAS,EAAE,OAAO,GAAI,SAAS,IAAI,OAAO,CAEhE;AAED,wBAAgB,UAAU,CAAC,SAAS,EAAE,OAAO,GAAI,SAAS,IAAI,QAAQ,CAErE;AAED,wBAAgB,SAAS,CAAC,SAAS,EAAE,OAAO,GAAI,SAAS,IAAI,MAAM,CAAC,OAAO,CAE1E;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAI,KAAK,IAAI,cAAc,CAEpE;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,GAAG,IAAI,IAAI,MAAM,CAAC,oBAAoB,CAE7F;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,GAAG,IAAI,IAAI,MAAM,CAAC,gBAAgB,CAErF;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,GAAG,IAAI,IAAI,MAAM,CAAC,UAAU,CAEzE;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,GAAG,IAAI,IAAI,MAAM,CAAC,mBAAmB,CAE3F;AACD,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,GAAG,IAAI,IAAI,MAAM,CAAC,kBAAkB,CAEzF;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,GAAG,IAAI,IAAI,MAAM,CAAC,kBAAkB,CAEzF;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,IAAI,EAAE,eAAe,EAAE,MAAM,CAAC,IAAI,GAAG,SAAS,GAAG,OAAO,CA0BvH;AAuDD,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CA0F9D,CAAC;AAqBF,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,IAAI,GAAG,OAAO,CAS3E;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,GAAG,OAAO,CAqBrD;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,GAAG,IAAI,IAAI,MAAM,CAAC,eAAe,CAEnF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ESTree } from "meriyah";
|
|
2
|
+
import { PrimitiveValue } from ".";
|
|
2
3
|
export type Binding = {
|
|
3
4
|
path: NodePath;
|
|
4
5
|
};
|
|
@@ -28,6 +29,8 @@ export default function createTraverser(): {
|
|
|
28
29
|
traverse: <T>(node: ASTNode, visitor: Visitor<T>, scopeId: number | undefined, state: T, path?: NodePath) => void;
|
|
29
30
|
createNodePath: (node: ASTNode, key: string | undefined, parentKey: string | undefined, scopeId: number | undefined, nodePath?: NodePath) => NodePath;
|
|
30
31
|
getChildren: (key: string, path: NodePath) => NodePath[];
|
|
32
|
+
getPrimitiveChildren: (key: string, path: NodePath) => PrimitiveValue[];
|
|
33
|
+
getPrimitiveChildrenOrNodePaths: (key: string, path: NodePath) => Array<PrimitiveValue | NodePath>;
|
|
31
34
|
getBinding: (scopeId: number, name: string) => Binding | undefined;
|
|
32
35
|
};
|
|
33
36
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"traverse.d.ts","sourceRoot":"","sources":["../../../src/traverse.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"traverse.d.ts","sourceRoot":"","sources":["../../../src/traverse.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC,OAAO,EAAE,cAAc,EAAE,MAAM,GAAG,CAAC;AASnC,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,QAAQ,CAAC;CAChB,CAAA;AAED,MAAM,MAAM,KAAK,GAAG;IAClB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAIF,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,GAAG;IAClC,KAAK,CAAC,EAAE;QACN,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,QAAQ,CAAC,EAAE,QAAQ,CAAC;KACrB,CAAA;CACF,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,OAAO,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,QAAQ,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,KAAK,OAAO,CAAC,CAAC,IAAI;IAChB,KAAK,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAC1C,IAAI,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;CAC1C,CAAA;AAED,MAAM,CAAC,OAAO,UAAU,eAAe;wBAuMR,OAAO,gCAEzB,MAAM,GAAG,SAAS,mBAEpB,QAAQ;2BAzHa,OAAO,OAAO,MAAM,GAAG,SAAS,aAAa,MAAM,GAAG,SAAS,WAAW,MAAM,GAAG,SAAS,aAAa,QAAQ,KAAI,QAAQ;uBAtCjI,MAAM,QAAQ,QAAQ,KAAI,QAAQ,EAAE;gCAW3B,MAAM,QAAQ,QAAQ,KAAI,cAAc,EAAE;2CAO/B,MAAM,QAAQ,QAAQ,KAAI,MAAM,cAAc,GAAG,QAAQ,CAAC;0BAnD3E,MAAM,QAAQ,MAAM;EAmNlD"}
|
package/lib/esm/index.mjs
CHANGED
|
@@ -75,7 +75,7 @@ function breadCrumb(path) {
|
|
|
75
75
|
}
|
|
76
76
|
function createQuerier() {
|
|
77
77
|
const traverser = (0, traverse_1.default)();
|
|
78
|
-
const { getChildren, getBinding, createNodePath, traverse } = traverser;
|
|
78
|
+
const { getChildren, getPrimitiveChildren, getPrimitiveChildrenOrNodePaths, getBinding, createNodePath, traverse } = traverser;
|
|
79
79
|
function createFilter(filter, filterResult) {
|
|
80
80
|
if (filter.type == "and" || filter.type == "or" || filter.type == "equals") {
|
|
81
81
|
return {
|
|
@@ -190,20 +190,17 @@ function createQuerier() {
|
|
|
190
190
|
return functionNode;
|
|
191
191
|
}
|
|
192
192
|
function addPrimitiveAttributeIfMatch(fnode, path) {
|
|
193
|
-
if (!fnode.node.attribute ||
|
|
193
|
+
if (!fnode.node.attribute || fnode.node.value == undefined)
|
|
194
194
|
return;
|
|
195
195
|
if (fnode.node.child || fnode.node.filter)
|
|
196
196
|
return;
|
|
197
197
|
if (!Object.hasOwn(path.node, fnode.node.value))
|
|
198
198
|
return;
|
|
199
|
-
const
|
|
200
|
-
const nodes = toArray(lookup)
|
|
201
|
-
.filter(n => n.node != undefined)
|
|
202
|
-
.filter(n => (0, nodeutils_1.isPrimitive)(n.node));
|
|
199
|
+
const nodes = getPrimitiveChildren(fnode.node.value, path);
|
|
203
200
|
if (nodes.length == 0)
|
|
204
201
|
return;
|
|
205
|
-
log.debug("PRIMITIVE", fnode.node.value, nodes
|
|
206
|
-
fnode.result.push(...nodes
|
|
202
|
+
log.debug("PRIMITIVE", fnode.node.value, nodes);
|
|
203
|
+
fnode.result.push(...nodes);
|
|
207
204
|
}
|
|
208
205
|
function evaluateFilter(filter, path) {
|
|
209
206
|
log.debug("EVALUATING FILTER", filter, breadCrumb(path));
|
|
@@ -260,7 +257,6 @@ function createQuerier() {
|
|
|
260
257
|
}
|
|
261
258
|
return resolveDirectly(startNode, startPath);
|
|
262
259
|
}
|
|
263
|
-
const toArray = (value) => Array.isArray(value) ? value : [value];
|
|
264
260
|
function isDefined(value) {
|
|
265
261
|
return value != undefined && value != null;
|
|
266
262
|
}
|
|
@@ -273,31 +269,32 @@ function createQuerier() {
|
|
|
273
269
|
const lookup = startNode.value;
|
|
274
270
|
if (!lookup)
|
|
275
271
|
throw new Error("Selector must have a value");
|
|
276
|
-
log.debug("STEP IN ", lookup, paths.map(p => breadCrumb(p)));
|
|
277
|
-
const nodes = paths.map(n =>
|
|
278
|
-
log.debug("LOOKUP", lookup, path.node.type, nodes.map(n => n.node)
|
|
272
|
+
//log.debug("STEP IN ", lookup, paths.map(p => breadCrumb(p)));
|
|
273
|
+
const nodes = paths.filter(nodeutils_1.isNodePath).map(n => getPrimitiveChildrenOrNodePaths(lookup, n)).flat();
|
|
274
|
+
//log.debug("LOOKUP", lookup, path.node.type, nodes.map(n => n.node));
|
|
275
|
+
//console.log(nodes);
|
|
279
276
|
if (nodes.length == 0)
|
|
280
277
|
return [];
|
|
281
278
|
paths = nodes;
|
|
282
279
|
if (startNode.resolve) {
|
|
283
|
-
const resolved = paths.map(p => resolveBinding(p)).filter(isDefined).map(p => getChildren("init", p)).
|
|
280
|
+
const resolved = paths.filter(nodeutils_1.isNodePath).map(p => resolveBinding(p)).filter(isDefined).map(p => getChildren("init", p)).flat();
|
|
284
281
|
if (resolved.length > 0)
|
|
285
282
|
paths = resolved;
|
|
286
283
|
}
|
|
287
284
|
else if (startNode.binding) {
|
|
288
|
-
paths = paths.map(p => resolveBinding(p)).filter(isDefined);
|
|
285
|
+
paths = paths.filter(nodeutils_1.isNodePath).map(p => resolveBinding(p)).filter(isDefined);
|
|
289
286
|
}
|
|
290
287
|
const filter = startNode.filter;
|
|
291
288
|
if (filter) {
|
|
292
|
-
paths = paths.filter(p => travHandle({ subquery: filter }, p).subquery.length > 0);
|
|
289
|
+
paths = paths.filter(nodeutils_1.isNodePath).filter(p => travHandle({ subquery: filter }, p).subquery.length > 0);
|
|
293
290
|
}
|
|
294
291
|
if (!startNode.child) {
|
|
295
|
-
return paths.map(p => p.node);
|
|
292
|
+
return paths.map(p => (0, nodeutils_1.isPrimitive)(p) ? p : p.node);
|
|
296
293
|
}
|
|
297
294
|
startNode = startNode.child;
|
|
298
295
|
}
|
|
299
|
-
log.debug("DIRECT TRAV RESOLVE", startNode, paths.map(p => breadCrumb(p)));
|
|
300
|
-
const result = paths.flatMap(path => {
|
|
296
|
+
//log.debug("DIRECT TRAV RESOLVE", startNode, paths.map(p => breadCrumb(p)));
|
|
297
|
+
const result = paths.filter(nodeutils_1.isNodePath).flatMap(path => {
|
|
301
298
|
const subQueryKey = "subquery-" + subQueryCounter++;
|
|
302
299
|
return travHandle({ [subQueryKey]: startNode }, path)[subQueryKey];
|
|
303
300
|
});
|
package/lib/esm/nodeutils.js
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isExportSpecifier = exports.isScopable = exports.isScope = exports.VISITOR_KEYS = exports.isBinding = exports.isVariableDeclarator = exports.isFunctionExpression = exports.isFunctionDeclaration = exports.isIdentifier = exports.isMemberExpression = exports.isAssignmentExpression = exports.isPrimitive = exports.isNode = void 0;
|
|
3
|
+
exports.isExportSpecifier = exports.isScopable = exports.isScope = exports.VISITOR_KEYS = exports.isBinding = exports.isVariableDeclarator = exports.isFunctionExpression = exports.isFunctionDeclaration = exports.isIdentifier = exports.isMemberExpression = exports.isAssignmentExpression = exports.isPrimitive = exports.isLiteral = exports.isNodePath = exports.isNode = void 0;
|
|
4
4
|
function isNode(candidate) {
|
|
5
5
|
return typeof candidate === "object" && candidate != null && "type" in candidate;
|
|
6
6
|
}
|
|
7
7
|
exports.isNode = isNode;
|
|
8
|
+
function isNodePath(candidate) {
|
|
9
|
+
return typeof candidate === "object" && candidate != null && "node" in candidate;
|
|
10
|
+
}
|
|
11
|
+
exports.isNodePath = isNodePath;
|
|
12
|
+
function isLiteral(candidate) {
|
|
13
|
+
return isNode(candidate) && candidate.type === "Literal";
|
|
14
|
+
}
|
|
15
|
+
exports.isLiteral = isLiteral;
|
|
8
16
|
function isPrimitive(value) {
|
|
9
17
|
return typeof value == "string" || typeof value == "number" || typeof value == "boolean";
|
|
10
18
|
}
|
package/lib/esm/traverse.js
CHANGED
|
@@ -13,6 +13,7 @@ const scopes = new Array(100000);
|
|
|
13
13
|
function createTraverser() {
|
|
14
14
|
let scopeIdCounter = 0;
|
|
15
15
|
let removedScopes = 0;
|
|
16
|
+
//const nodePathsCreated: Record<string, number> = {}
|
|
16
17
|
function createScope(parentScopeId) {
|
|
17
18
|
const id = scopeIdCounter++;
|
|
18
19
|
scopes[id] = parentScopeId ?? -1;
|
|
@@ -26,7 +27,7 @@ function createTraverser() {
|
|
|
26
27
|
return getBinding(scope, name);
|
|
27
28
|
}
|
|
28
29
|
const s = scope.bindings[name];
|
|
29
|
-
if (s)
|
|
30
|
+
if (s != undefined)
|
|
30
31
|
return s;
|
|
31
32
|
if (scope.parentScopeId != undefined && scope.parentScopeId >= 0) {
|
|
32
33
|
return getBinding(scope.parentScopeId, name);
|
|
@@ -62,6 +63,31 @@ function createTraverser() {
|
|
|
62
63
|
}
|
|
63
64
|
return [];
|
|
64
65
|
}
|
|
66
|
+
function getPrimitiveChildren(key, path) {
|
|
67
|
+
if (key in path.node) {
|
|
68
|
+
const r = path.node[key];
|
|
69
|
+
return (0, utils_1.toArray)(r).filter(utils_1.isDefined).filter(nodeutils_1.isPrimitive);
|
|
70
|
+
}
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
73
|
+
function getPrimitiveChildrenOrNodePaths(key, path) {
|
|
74
|
+
if (key in path.node) {
|
|
75
|
+
const r = path.node[key];
|
|
76
|
+
if (Array.isArray(r)) {
|
|
77
|
+
return r.map((n, i) => (0, nodeutils_1.isPrimitive)(n) ? n :
|
|
78
|
+
// isLiteral(n) ? n.value as PrimitiveValue :
|
|
79
|
+
createNodePath(n, i.toString(), key, path.scopeId, path));
|
|
80
|
+
}
|
|
81
|
+
else if (r != undefined) {
|
|
82
|
+
return [
|
|
83
|
+
(0, nodeutils_1.isPrimitive)(r) ? r :
|
|
84
|
+
// isLiteral(r) ? r.value as PrimitiveValue :
|
|
85
|
+
createNodePath(r, key, key, path.scopeId, path)
|
|
86
|
+
];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
65
91
|
function createNodePath(node, key, parentKey, scopeId, nodePath) {
|
|
66
92
|
if (node.extra?.nodePath) {
|
|
67
93
|
const path = node.extra.nodePath;
|
|
@@ -83,6 +109,11 @@ function createTraverser() {
|
|
|
83
109
|
node.extra.nodePath = path;
|
|
84
110
|
Object.defineProperty(node.extra, "nodePath", { enumerable: false });
|
|
85
111
|
}
|
|
112
|
+
/*const x: string| undefined = node.type;
|
|
113
|
+
if (x == undefined) {
|
|
114
|
+
console.log("x", node, key, parentKey, nodePath?.node?.type);
|
|
115
|
+
}*/
|
|
116
|
+
//nodePathsCreated[node.type] = (nodePathsCreated[node.type] ?? 0) + 1;
|
|
86
117
|
pathsCreated++;
|
|
87
118
|
return path;
|
|
88
119
|
}
|
|
@@ -101,13 +132,16 @@ function createTraverser() {
|
|
|
101
132
|
}
|
|
102
133
|
}
|
|
103
134
|
}
|
|
135
|
+
let bindingNodesVisited = 0;
|
|
104
136
|
function registerBindings(node, parentNode, grandParentNode, scopeId) {
|
|
105
|
-
if (
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
137
|
+
if (!(0, nodeutils_1.isNode)(node))
|
|
138
|
+
return;
|
|
139
|
+
node.extra = node.extra ?? {};
|
|
140
|
+
if (node.extra["scopeId"] != undefined)
|
|
141
|
+
return;
|
|
142
|
+
node.extra["scopeId"] = scopeId;
|
|
143
|
+
bindingNodesVisited++;
|
|
144
|
+
;
|
|
111
145
|
const keys = nodeutils_1.VISITOR_KEYS[node.type];
|
|
112
146
|
//console.log(keys, node);
|
|
113
147
|
if (keys.length == 0)
|
|
@@ -160,14 +194,18 @@ function createTraverser() {
|
|
|
160
194
|
function traverse(node, visitor, scopeId, state, path) {
|
|
161
195
|
traverseInner(node, visitor, scopeId, state, path);
|
|
162
196
|
if (!sOut.includes(scopeIdCounter)) {
|
|
163
|
-
log.debug("Scopes created", scopeIdCounter, " Scopes removed", removedScopes, "Paths created", pathsCreated);
|
|
197
|
+
log.debug("Scopes created", scopeIdCounter, " Scopes removed", removedScopes, "Paths created", pathsCreated, bindingNodesVisited);
|
|
164
198
|
sOut.push(scopeIdCounter);
|
|
199
|
+
//const k = Object.fromEntries(Object.entries(nodePathsCreated).sort((a, b) => b[1] - a[1]));
|
|
200
|
+
//console.log("Node paths created", k);
|
|
165
201
|
}
|
|
166
202
|
}
|
|
167
203
|
return {
|
|
168
204
|
traverse,
|
|
169
205
|
createNodePath,
|
|
170
206
|
getChildren,
|
|
207
|
+
getPrimitiveChildren,
|
|
208
|
+
getPrimitiveChildrenOrNodePaths,
|
|
171
209
|
getBinding
|
|
172
210
|
};
|
|
173
211
|
}
|
package/lib/esm/types/index.d.ts
CHANGED
|
@@ -15,7 +15,8 @@ export declare const functions: {
|
|
|
15
15
|
};
|
|
16
16
|
export type AvailableFunction = keyof typeof functions;
|
|
17
17
|
export declare function isAvailableFunction(name: string): name is AvailableFunction;
|
|
18
|
-
type
|
|
18
|
+
export type PrimitiveValue = string | number | boolean;
|
|
19
|
+
type Result = ASTNode | PrimitiveValue;
|
|
19
20
|
export declare function query(code: string | ASTNode, query: string, returnAST?: boolean): Result[] & {
|
|
20
21
|
__AST?: ASTNode;
|
|
21
22
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAwB,EAAG,OAAO,EAAY,MAAM,YAAY,CAAC;AAajE,eAAO,MAAM,SAAS;;qBAEL,MAAM,EAAE,EAAE,KAAG,MAAM,EAAE;;;qBAWrB,MAAM,EAAE,EAAE,KAAG,MAAM,EAAE;;;qBAMrB,MAAM,EAAE,EAAE,KAAG,MAAM,EAAE;;;qBAOrB,MAAM,EAAE,EAAE,KAAG,MAAM,EAAE;;CASrC,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG,MAAM,OAAO,SAAS,CAAC;AACvD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAI,IAAI,IAAI,iBAAiB,CAE5E;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAwB,EAAG,OAAO,EAAY,MAAM,YAAY,CAAC;AAajE,eAAO,MAAM,SAAS;;qBAEL,MAAM,EAAE,EAAE,KAAG,MAAM,EAAE;;;qBAWrB,MAAM,EAAE,EAAE,KAAG,MAAM,EAAE;;;qBAMrB,MAAM,EAAE,EAAE,KAAG,MAAM,EAAE;;;qBAOrB,MAAM,EAAE,EAAE,KAAG,MAAM,EAAE;;CASrC,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG,MAAM,OAAO,SAAS,CAAC;AACvD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAI,IAAI,IAAI,iBAAiB,CAE5E;AAGD,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAEvD,KAAK,MAAM,GAAG,OAAO,GAAG,cAAc,CAAC;AA4XvC,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,OAAO,GAAI,MAAM,EAAE,GAAG;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,CAQjH;AAED,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,EAAE,YAAY,EAAE,CAAC,EAAE,SAAS,CAAC,EAAE,OAAO,GAAI,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,CAY3K;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAI,OAAO,CAMpD"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { ESTree } from "meriyah";
|
|
2
|
-
import { ASTNode } from "./traverse";
|
|
2
|
+
import { ASTNode, NodePath } from "./traverse";
|
|
3
|
+
import { PrimitiveValue } from ".";
|
|
3
4
|
export declare function isNode(candidate: unknown): candidate is ASTNode;
|
|
4
|
-
export declare function
|
|
5
|
+
export declare function isNodePath(candidate: unknown): candidate is NodePath;
|
|
6
|
+
export declare function isLiteral(candidate: unknown): candidate is ESTree.Literal;
|
|
7
|
+
export declare function isPrimitive(value: unknown): value is PrimitiveValue;
|
|
5
8
|
export declare function isAssignmentExpression(node: ESTree.Node): node is ESTree.AssignmentExpression;
|
|
6
9
|
export declare function isMemberExpression(node: ESTree.Node): node is ESTree.MemberExpression;
|
|
7
10
|
export declare function isIdentifier(node: ESTree.Node): node is ESTree.Identifier;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodeutils.d.ts","sourceRoot":"","sources":["../../../src/nodeutils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"nodeutils.d.ts","sourceRoot":"","sources":["../../../src/nodeutils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,GAAG,CAAC;AAEnC,wBAAgB,MAAM,CAAC,SAAS,EAAE,OAAO,GAAI,SAAS,IAAI,OAAO,CAEhE;AAED,wBAAgB,UAAU,CAAC,SAAS,EAAE,OAAO,GAAI,SAAS,IAAI,QAAQ,CAErE;AAED,wBAAgB,SAAS,CAAC,SAAS,EAAE,OAAO,GAAI,SAAS,IAAI,MAAM,CAAC,OAAO,CAE1E;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAI,KAAK,IAAI,cAAc,CAEpE;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,GAAG,IAAI,IAAI,MAAM,CAAC,oBAAoB,CAE7F;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,GAAG,IAAI,IAAI,MAAM,CAAC,gBAAgB,CAErF;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,GAAG,IAAI,IAAI,MAAM,CAAC,UAAU,CAEzE;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,GAAG,IAAI,IAAI,MAAM,CAAC,mBAAmB,CAE3F;AACD,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,GAAG,IAAI,IAAI,MAAM,CAAC,kBAAkB,CAEzF;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,GAAG,IAAI,IAAI,MAAM,CAAC,kBAAkB,CAEzF;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,IAAI,EAAE,eAAe,EAAE,MAAM,CAAC,IAAI,GAAG,SAAS,GAAG,OAAO,CA0BvH;AAuDD,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CA0F9D,CAAC;AAqBF,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,IAAI,GAAG,OAAO,CAS3E;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,GAAG,OAAO,CAqBrD;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,GAAG,IAAI,IAAI,MAAM,CAAC,eAAe,CAEnF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ESTree } from "meriyah";
|
|
2
|
+
import { PrimitiveValue } from ".";
|
|
2
3
|
export type Binding = {
|
|
3
4
|
path: NodePath;
|
|
4
5
|
};
|
|
@@ -28,6 +29,8 @@ export default function createTraverser(): {
|
|
|
28
29
|
traverse: <T>(node: ASTNode, visitor: Visitor<T>, scopeId: number | undefined, state: T, path?: NodePath) => void;
|
|
29
30
|
createNodePath: (node: ASTNode, key: string | undefined, parentKey: string | undefined, scopeId: number | undefined, nodePath?: NodePath) => NodePath;
|
|
30
31
|
getChildren: (key: string, path: NodePath) => NodePath[];
|
|
32
|
+
getPrimitiveChildren: (key: string, path: NodePath) => PrimitiveValue[];
|
|
33
|
+
getPrimitiveChildrenOrNodePaths: (key: string, path: NodePath) => Array<PrimitiveValue | NodePath>;
|
|
31
34
|
getBinding: (scopeId: number, name: string) => Binding | undefined;
|
|
32
35
|
};
|
|
33
36
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"traverse.d.ts","sourceRoot":"","sources":["../../../src/traverse.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"traverse.d.ts","sourceRoot":"","sources":["../../../src/traverse.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC,OAAO,EAAE,cAAc,EAAE,MAAM,GAAG,CAAC;AASnC,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,QAAQ,CAAC;CAChB,CAAA;AAED,MAAM,MAAM,KAAK,GAAG;IAClB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAIF,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,GAAG;IAClC,KAAK,CAAC,EAAE;QACN,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,QAAQ,CAAC,EAAE,QAAQ,CAAC;KACrB,CAAA;CACF,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,OAAO,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,QAAQ,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,KAAK,OAAO,CAAC,CAAC,IAAI;IAChB,KAAK,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAC1C,IAAI,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;CAC1C,CAAA;AAED,MAAM,CAAC,OAAO,UAAU,eAAe;wBAuMR,OAAO,gCAEzB,MAAM,GAAG,SAAS,mBAEpB,QAAQ;2BAzHa,OAAO,OAAO,MAAM,GAAG,SAAS,aAAa,MAAM,GAAG,SAAS,WAAW,MAAM,GAAG,SAAS,aAAa,QAAQ,KAAI,QAAQ;uBAtCjI,MAAM,QAAQ,QAAQ,KAAI,QAAQ,EAAE;gCAW3B,MAAM,QAAQ,QAAQ,KAAI,cAAc,EAAE;2CAO/B,MAAM,QAAQ,QAAQ,KAAI,MAAM,cAAc,GAAG,QAAQ,CAAC;0BAnD3E,MAAM,QAAQ,MAAM;EAmNlD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astronomical",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.15",
|
|
4
4
|
"description": "offers a way to query a Javascript AST to find specific patterns using a syntax somewhat similar to XPath.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"lint": "eslint . --ext .ts --fix --ignore-path .gitignore",
|