astronomical 1.0.0-beta.12 → 1.0.0-beta.13

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 CHANGED
@@ -219,7 +219,7 @@ function addPrimitiveAttributeIfMatch(fnode, path) {
219
219
  return;
220
220
  if (!Object.hasOwn(path.node, fnode.node.value))
221
221
  return;
222
- const lookup = path.get(fnode.node.value);
222
+ const lookup = (0, traverse_1.getChildren)(fnode.node.value, path);
223
223
  const nodes = (Array.isArray(lookup) ? lookup : [lookup])
224
224
  .filter(n => n.node != undefined)
225
225
  .filter(n => isPrimitive(n.node));
@@ -229,7 +229,7 @@ function addPrimitiveAttributeIfMatch(fnode, path) {
229
229
  fnode.result.push(...nodes.map(n => n.node));
230
230
  }
231
231
  function evaluateFilter(filter, path) {
232
- log.debug("EVALUATING FILTER", filter);
232
+ log.debug("EVALUATING FILTER", filter, breadCrumb(path));
233
233
  if ("type" in filter) {
234
234
  if (filter.type == "and") {
235
235
  const left = evaluateFilter(filter.left, path);
@@ -295,24 +295,28 @@ function resolveDirectly(node, path) {
295
295
  let startNode = node;
296
296
  const startPath = path;
297
297
  let paths = [startPath];
298
- while (startNode.attribute) {
298
+ while (startNode.attribute && startNode.type == "child") {
299
299
  const lookup = startNode.value;
300
300
  if (!lookup)
301
301
  throw new Error("Selector must have a value");
302
302
  log.debug("STEP IN ", lookup, paths.map(p => breadCrumb(p)));
303
- const nodes = paths.map(n => n.get(lookup)).map(toArray).flat().filter(n => n.node != undefined);
304
- log.debug("LOOKUP", lookup, nodes.map(n => n.node), nodes.filter(n => n.node == undefined));
303
+ const nodes = paths.map(n => (0, traverse_1.getChildren)(lookup, n)).map(toArray).flat().filter(n => n.node != undefined);
304
+ log.debug("LOOKUP", lookup, path.node.type, nodes.map(n => n.node), nodes.filter(n => n.node == undefined));
305
305
  if (nodes.length == 0)
306
306
  return [];
307
307
  paths = nodes;
308
308
  if (startNode.resolve) {
309
- const resolved = paths.map(p => resolveBinding(p)).filter(isDefined).map(p => p.get("init")).flatMap(toArray).filter(p => p.node != undefined).filter(isDefined);
309
+ const resolved = paths.map(p => resolveBinding(p)).filter(isDefined).map(p => (0, traverse_1.getChildren)("init", p)).flatMap(toArray).filter(p => p.node != undefined).filter(isDefined);
310
310
  if (resolved.length > 0)
311
311
  paths = resolved;
312
312
  }
313
313
  else if (startNode.binding) {
314
314
  paths = paths.map(p => resolveBinding(p)).filter(isDefined);
315
315
  }
316
+ const filter = startNode.filter;
317
+ if (filter) {
318
+ paths = paths.filter(p => travHandle({ subquery: filter }, p).subquery.length > 0);
319
+ }
316
320
  if (!startNode.child) {
317
321
  return paths.map(p => p.node);
318
322
  }
@@ -333,7 +337,8 @@ function addResultIfTokenMatch(fnode, path, state) {
333
337
  if (filters.length > 0 && matchingFilters.length == 0)
334
338
  return;
335
339
  if (fnode.node.resolve) {
336
- const [resolved] = toArray(resolveBinding(path)?.get("init")).filter(isDefined).filter(p => p.node != undefined);
340
+ const binding = resolveBinding(path);
341
+ const resolved = binding ? (0, traverse_1.getChildren)("init", binding)[0] : undefined;
337
342
  if (fnode.node.child) {
338
343
  const result = resolveDirectly(fnode.node.child, resolved ?? path);
339
344
  fnode.result.push(...result);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createNodePath = exports.getBinding = void 0;
3
+ exports.createNodePath = exports.getChildren = exports.getBinding = void 0;
4
4
  const nodeutils_1 = require("./nodeutils");
5
5
  const debugLogEnabled = false;
6
6
  const log = {
@@ -10,18 +10,10 @@ const log = {
10
10
  }
11
11
  };
12
12
  const scopes = new Array(100000);
13
- const voidFn = () => { };
14
13
  let scopeIdCounter = 0;
15
14
  let removedScopes = 0;
16
15
  function createScope(parentScopeId) {
17
16
  const id = scopeIdCounter++;
18
- /*const bindings: Record<string, Binding> = {};
19
- const s: Scope = {
20
- bindings,
21
- id,
22
- parentScopeId,
23
- hasEntries: false
24
- }*/
25
17
  scopes[id] = parentScopeId ?? -1;
26
18
  return id;
27
19
  }
@@ -49,7 +41,6 @@ function setBinding(scopeId, name, binding) {
49
41
  bindings: {},
50
42
  id: scopeId,
51
43
  parentScopeId: s == -1 ? undefined : s,
52
- hasEntries: false
53
44
  };
54
45
  scopes[scopeId] = scope;
55
46
  }
@@ -57,13 +48,24 @@ function setBinding(scopeId, name, binding) {
57
48
  scope = s;
58
49
  }
59
50
  scope.bindings[name] = binding;
60
- scope.hasEntries = true;
61
51
  }
62
52
  let pathsCreated = 0;
63
- const nodeKey = "ASTronomical-path";
53
+ function getChildren(key, path) {
54
+ if (key in path.node) {
55
+ const r = path.node[key];
56
+ if (Array.isArray(r)) {
57
+ return r.map((n, i) => createNodePath(n, i.toString(), key, path.scopeId, path));
58
+ }
59
+ else if (r != undefined) {
60
+ return [createNodePath(r, key, key, path.scopeId, path)];
61
+ }
62
+ }
63
+ return [];
64
+ }
65
+ exports.getChildren = getChildren;
64
66
  function createNodePath(node, key, parentKey, scopeId, nodePath) {
65
- if (node.extra && node.extra[nodeKey]) {
66
- const path = node.extra[nodeKey];
67
+ if (node.extra?.nodePath) {
68
+ const path = node.extra.nodePath;
67
69
  path.key = key;
68
70
  path.parentKey = parentKey;
69
71
  path.parentPath = nodePath;
@@ -73,29 +75,14 @@ function createNodePath(node, key, parentKey, scopeId, nodePath) {
73
75
  const path = {
74
76
  node,
75
77
  scopeId: finalScope,
76
- shouldStop: false,
77
- stop: voidFn,
78
- get: (key) => {
79
- if (key in node) {
80
- const r = node[key];
81
- if (Array.isArray(r)) {
82
- return r.map((n, i) => createNodePath(n, i.toString(), key, scopeId, nodePath));
83
- }
84
- else if (r != undefined) {
85
- return [createNodePath(r, key, key, scopeId, nodePath)];
86
- }
87
- }
88
- return [];
89
- },
90
78
  parentPath: nodePath,
91
79
  key,
92
80
  parentKey
93
81
  };
94
- path.stop = () => { path.shouldStop = true; };
95
82
  if ((0, nodeutils_1.isNode)(node)) {
96
83
  node.extra = node.extra ?? {};
97
- node.extra[nodeKey] = path;
98
- Object.defineProperty(node.extra, nodeKey, { enumerable: false });
84
+ node.extra.nodePath = path;
85
+ Object.defineProperty(node.extra, "nodePath", { enumerable: false });
99
86
  }
100
87
  pathsCreated++;
101
88
  return path;
@@ -125,9 +112,8 @@ function registerBindings(node, parentNode, grandParentNode, scopeId) {
125
112
  }
126
113
  const keys = nodeutils_1.VISITOR_KEYS[node.type];
127
114
  //console.log(keys, node);
128
- if (!keys) {
115
+ if (keys.length == 0)
129
116
  return;
130
- }
131
117
  let childScopeId = scopeId;
132
118
  // This is also buggy. Need to investigate what creates a new scope
133
119
  if ((0, nodeutils_1.isScopable)(node)) {
@@ -153,12 +139,9 @@ function registerBindings(node, parentNode, grandParentNode, scopeId) {
153
139
  }
154
140
  function traverseInner(node, visitor, scopeId, state, path) {
155
141
  const nodePath = path ?? createNodePath(node, undefined, undefined, scopeId);
156
- const keys = nodeutils_1.VISITOR_KEYS[node.type];
142
+ const keys = nodeutils_1.VISITOR_KEYS[node.type] ?? [];
157
143
  if (nodePath.parentPath)
158
144
  registerBindings(nodePath.node, nodePath.parentPath.node, nodePath.parentPath.parentPath?.node, nodePath.scopeId);
159
- if (!keys) {
160
- return;
161
- }
162
145
  for (const key of keys) {
163
146
  const childNodes = node[key];
164
147
  const children = Array.isArray(childNodes) ? childNodes : childNodes ? [childNodes] : [];
@@ -170,19 +153,8 @@ function traverseInner(node, visitor, scopeId, state, path) {
170
153
  }).filter(x => x != undefined);
171
154
  nodePaths.forEach((childPath) => {
172
155
  visitor.enter(childPath, state);
173
- if (childPath.shouldStop) {
174
- childPath.shouldStop = false;
175
- nodePath.shouldStop = true;
176
- return;
177
- }
178
156
  traverseInner(childPath.node, visitor, nodePath.scopeId, state, childPath);
179
- if (visitor.exit)
180
- visitor.exit(childPath, state);
181
- if (childPath.shouldStop) {
182
- childPath.shouldStop = false;
183
- nodePath.shouldStop = true;
184
- return;
185
- }
157
+ visitor.exit(childPath, state);
186
158
  });
187
159
  }
188
160
  }
@@ -1,4 +1,4 @@
1
- import { ASTNode } from "./nodeutils";
1
+ import { ASTNode } from "./traverse";
2
2
  export declare const functions: {
3
3
  join: {
4
4
  fn: (result: Result[][]) => Result[];
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAUtC,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;AAOD,KAAK,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAiXlD,wBAAgB,KAAK,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,EAAE,KAAK,EAAE,MAAM,GAAI,MAAM,EAAE,CAEtE;AAED,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM,EAAE,YAAY,EAAE,CAAC,GAAI,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CAQhI;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAI,OAAO,CAMpD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAiB,EAAG,OAAO,EAAqD,MAAM,YAAY,CAAC;AAYnG,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;AAOD,KAAK,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAuXlD,wBAAgB,KAAK,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,EAAE,KAAK,EAAE,MAAM,GAAI,MAAM,EAAE,CAEtE;AAED,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM,EAAE,YAAY,EAAE,CAAC,GAAI,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CAQhI;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAI,OAAO,CAMpD"}
@@ -1,4 +1,5 @@
1
1
  import { ESTree } from "meriyah";
2
+ import { ASTNode } from "./traverse";
2
3
  export declare function isNode(candidate: unknown): candidate is ASTNode;
3
4
  export declare function isAssignmentExpression(node: ESTree.Node): node is ESTree.AssignmentExpression;
4
5
  export declare function isMemberExpression(node: ESTree.Node): node is ESTree.MemberExpression;
@@ -11,7 +12,4 @@ export declare const VISITOR_KEYS: Record<ESTree.Node["type"], string[]>;
11
12
  export declare function isScope(node: ESTree.Node, parentNode: ESTree.Node): boolean;
12
13
  export declare function isScopable(node: ESTree.Node): boolean;
13
14
  export declare function isExportSpecifier(node: ESTree.Node): node is ESTree.ExportSpecifier;
14
- export type ASTNode = ESTree.Node & {
15
- extra?: Record<string, unknown>;
16
- };
17
15
  //# s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,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,29 +1,32 @@
1
- import { ASTNode } from "./nodeutils";
1
+ import { ESTree } from "meriyah";
2
2
  export type Binding = {
3
- path: NodePath<ASTNode>;
3
+ path: NodePath;
4
4
  };
5
5
  export type Scope = {
6
6
  bindings: Record<string, Binding>;
7
7
  parentScopeId?: number;
8
8
  id: number;
9
- hasEntries: boolean;
10
9
  };
11
- export type NodePath<T> = {
12
- node: T;
10
+ export type ASTNode = ESTree.Node & {
11
+ extra?: {
12
+ scopeId?: number;
13
+ nodePath?: NodePath;
14
+ };
15
+ };
16
+ export type NodePath = {
17
+ node: ASTNode;
13
18
  key?: string;
14
- parentPath?: NodePath<T>;
19
+ parentPath?: NodePath;
15
20
  parentKey?: string;
16
- stop: () => void;
17
- get(key: string): NodePath<ASTNode>[];
18
21
  scopeId: number;
19
- shouldStop: boolean;
20
22
  };
21
23
  type Visitor<T> = {
22
- enter: (path: NodePath<ASTNode>, state: T) => void;
23
- exit?: (path: NodePath<ASTNode>, state: T) => void;
24
+ enter: (path: NodePath, state: T) => void;
25
+ exit: (path: NodePath, state: T) => void;
24
26
  };
25
27
  export declare function getBinding(scopeId: number, name: string): Binding | undefined;
26
- export declare function createNodePath(node: ASTNode, key: string | undefined, parentKey: string | undefined, scopeId: number | undefined, nodePath?: NodePath<ASTNode>): NodePath<ASTNode>;
27
- export default function traverse<T>(node: ASTNode, visitor: Visitor<T>, scopeId: number | undefined, state: T, path?: NodePath<ASTNode>): void;
28
+ export declare function getChildren(key: string, path: NodePath): NodePath[];
29
+ export declare function createNodePath(node: ASTNode, key: string | undefined, parentKey: string | undefined, scopeId: number | undefined, nodePath?: NodePath): NodePath;
30
+ export default function traverse<T>(node: ASTNode, visitor: Visitor<T>, scopeId: number | undefined, state: T, path?: NodePath): void;
28
31
  export {};
29
32
  //# sourceMappingURL=traverse.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"traverse.d.ts","sourceRoot":"","sources":["../../../src/traverse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAkH,MAAM,aAAa,CAAC;AAStJ,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;CACzB,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;IACX,UAAU,EAAE,OAAO,CAAC;CACrB,CAAC;AAMF,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;IACxB,IAAI,EAAE,CAAC,CAAC;IACR,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF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220
220
  if (!Object.hasOwn(path.node, fnode.node.value))
221
221
  return;
222
- const lookup = path.get(fnode.node.value);
222
+ const lookup = (0, traverse_1.getChildren)(fnode.node.value, path);
223
223
  const nodes = (Array.isArray(lookup) ? lookup : [lookup])
224
224
  .filter(n => n.node != undefined)
225
225
  .filter(n => isPrimitive(n.node));
@@ -229,7 +229,7 @@ function addPrimitiveAttributeIfMatch(fnode, path) {
229
229
  fnode.result.push(...nodes.map(n => n.node));
230
230
  }
231
231
  function evaluateFilter(filter, path) {
232
- log.debug("EVALUATING FILTER", filter);
232
+ log.debug("EVALUATING FILTER", filter, breadCrumb(path));
233
233
  if ("type" in filter) {
234
234
  if (filter.type == "and") {
235
235
  const left = evaluateFilter(filter.left, path);
@@ -295,24 +295,28 @@ function resolveDirectly(node, path) {
295
295
  let startNode = node;
296
296
  const startPath = path;
297
297
  let paths = [startPath];
298
- while (startNode.attribute) {
298
+ while (startNode.attribute && startNode.type == "child") {
299
299
  const lookup = startNode.value;
300
300
  if (!lookup)
301
301
  throw new Error("Selector must have a value");
302
302
  log.debug("STEP IN ", lookup, paths.map(p => breadCrumb(p)));
303
- const nodes = paths.map(n => n.get(lookup)).map(toArray).flat().filter(n => n.node != undefined);
304
- log.debug("LOOKUP", lookup, nodes.map(n => n.node), nodes.filter(n => n.node == undefined));
303
+ const nodes = paths.map(n => (0, traverse_1.getChildren)(lookup, n)).map(toArray).flat().filter(n => n.node != undefined);
304
+ log.debug("LOOKUP", lookup, path.node.type, nodes.map(n => n.node), nodes.filter(n => n.node == undefined));
305
305
  if (nodes.length == 0)
306
306
  return [];
307
307
  paths = nodes;
308
308
  if (startNode.resolve) {
309
- const resolved = paths.map(p => resolveBinding(p)).filter(isDefined).map(p => p.get("init")).flatMap(toArray).filter(p => p.node != undefined).filter(isDefined);
309
+ const resolved = paths.map(p => resolveBinding(p)).filter(isDefined).map(p => (0, traverse_1.getChildren)("init", p)).flatMap(toArray).filter(p => p.node != undefined).filter(isDefined);
310
310
  if (resolved.length > 0)
311
311
  paths = resolved;
312
312
  }
313
313
  else if (startNode.binding) {
314
314
  paths = paths.map(p => resolveBinding(p)).filter(isDefined);
315
315
  }
316
+ const filter = startNode.filter;
317
+ if (filter) {
318
+ paths = paths.filter(p => travHandle({ subquery: filter }, p).subquery.length > 0);
319
+ }
316
320
  if (!startNode.child) {
317
321
  return paths.map(p => p.node);
318
322
  }
@@ -333,7 +337,8 @@ function addResultIfTokenMatch(fnode, path, state) {
333
337
  if (filters.length > 0 && matchingFilters.length == 0)
334
338
  return;
335
339
  if (fnode.node.resolve) {
336
- const [resolved] = toArray(resolveBinding(path)?.get("init")).filter(isDefined).filter(p => p.node != undefined);
340
+ const binding = resolveBinding(path);
341
+ const resolved = binding ? (0, traverse_1.getChildren)("init", binding)[0] : undefined;
337
342
  if (fnode.node.child) {
338
343
  const result = resolveDirectly(fnode.node.child, resolved ?? path);
339
344
  fnode.result.push(...result);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createNodePath = exports.getBinding = void 0;
3
+ exports.createNodePath = exports.getChildren = exports.getBinding = void 0;
4
4
  const nodeutils_1 = require("./nodeutils");
5
5
  const debugLogEnabled = false;
6
6
  const log = {
@@ -10,18 +10,10 @@ const log = {
10
10
  }
11
11
  };
12
12
  const scopes = new Array(100000);
13
- const voidFn = () => { };
14
13
  let scopeIdCounter = 0;
15
14
  let removedScopes = 0;
16
15
  function createScope(parentScopeId) {
17
16
  const id = scopeIdCounter++;
18
- /*const bindings: Record<string, Binding> = {};
19
- const s: Scope = {
20
- bindings,
21
- id,
22
- parentScopeId,
23
- hasEntries: false
24
- }*/
25
17
  scopes[id] = parentScopeId ?? -1;
26
18
  return id;
27
19
  }
@@ -49,7 +41,6 @@ function setBinding(scopeId, name, binding) {
49
41
  bindings: {},
50
42
  id: scopeId,
51
43
  parentScopeId: s == -1 ? undefined : s,
52
- hasEntries: false
53
44
  };
54
45
  scopes[scopeId] = scope;
55
46
  }
@@ -57,13 +48,24 @@ function setBinding(scopeId, name, binding) {
57
48
  scope = s;
58
49
  }
59
50
  scope.bindings[name] = binding;
60
- scope.hasEntries = true;
61
51
  }
62
52
  let pathsCreated = 0;
63
- const nodeKey = "ASTronomical-path";
53
+ function getChildren(key, path) {
54
+ if (key in path.node) {
55
+ const r = path.node[key];
56
+ if (Array.isArray(r)) {
57
+ return r.map((n, i) => createNodePath(n, i.toString(), key, path.scopeId, path));
58
+ }
59
+ else if (r != undefined) {
60
+ return [createNodePath(r, key, key, path.scopeId, path)];
61
+ }
62
+ }
63
+ return [];
64
+ }
65
+ exports.getChildren = getChildren;
64
66
  function createNodePath(node, key, parentKey, scopeId, nodePath) {
65
- if (node.extra && node.extra[nodeKey]) {
66
- const path = node.extra[nodeKey];
67
+ if (node.extra?.nodePath) {
68
+ const path = node.extra.nodePath;
67
69
  path.key = key;
68
70
  path.parentKey = parentKey;
69
71
  path.parentPath = nodePath;
@@ -73,29 +75,14 @@ function createNodePath(node, key, parentKey, scopeId, nodePath) {
73
75
  const path = {
74
76
  node,
75
77
  scopeId: finalScope,
76
- shouldStop: false,
77
- stop: voidFn,
78
- get: (key) => {
79
- if (key in node) {
80
- const r = node[key];
81
- if (Array.isArray(r)) {
82
- return r.map((n, i) => createNodePath(n, i.toString(), key, scopeId, nodePath));
83
- }
84
- else if (r != undefined) {
85
- return [createNodePath(r, key, key, scopeId, nodePath)];
86
- }
87
- }
88
- return [];
89
- },
90
78
  parentPath: nodePath,
91
79
  key,
92
80
  parentKey
93
81
  };
94
- path.stop = () => { path.shouldStop = true; };
95
82
  if ((0, nodeutils_1.isNode)(node)) {
96
83
  node.extra = node.extra ?? {};
97
- node.extra[nodeKey] = path;
98
- Object.defineProperty(node.extra, nodeKey, { enumerable: false });
84
+ node.extra.nodePath = path;
85
+ Object.defineProperty(node.extra, "nodePath", { enumerable: false });
99
86
  }
100
87
  pathsCreated++;
101
88
  return path;
@@ -125,9 +112,8 @@ function registerBindings(node, parentNode, grandParentNode, scopeId) {
125
112
  }
126
113
  const keys = nodeutils_1.VISITOR_KEYS[node.type];
127
114
  //console.log(keys, node);
128
- if (!keys) {
115
+ if (keys.length == 0)
129
116
  return;
130
- }
131
117
  let childScopeId = scopeId;
132
118
  // This is also buggy. Need to investigate what creates a new scope
133
119
  if ((0, nodeutils_1.isScopable)(node)) {
@@ -153,12 +139,9 @@ function registerBindings(node, parentNode, grandParentNode, scopeId) {
153
139
  }
154
140
  function traverseInner(node, visitor, scopeId, state, path) {
155
141
  const nodePath = path ?? createNodePath(node, undefined, undefined, scopeId);
156
- const keys = nodeutils_1.VISITOR_KEYS[node.type];
142
+ const keys = nodeutils_1.VISITOR_KEYS[node.type] ?? [];
157
143
  if (nodePath.parentPath)
158
144
  registerBindings(nodePath.node, nodePath.parentPath.node, nodePath.parentPath.parentPath?.node, nodePath.scopeId);
159
- if (!keys) {
160
- return;
161
- }
162
145
  for (const key of keys) {
163
146
  const childNodes = node[key];
164
147
  const children = Array.isArray(childNodes) ? childNodes : childNodes ? [childNodes] : [];
@@ -170,19 +153,8 @@ function traverseInner(node, visitor, scopeId, state, path) {
170
153
  }).filter(x => x != undefined);
171
154
  nodePaths.forEach((childPath) => {
172
155
  visitor.enter(childPath, state);
173
- if (childPath.shouldStop) {
174
- childPath.shouldStop = false;
175
- nodePath.shouldStop = true;
176
- return;
177
- }
178
156
  traverseInner(childPath.node, visitor, nodePath.scopeId, state, childPath);
179
- if (visitor.exit)
180
- visitor.exit(childPath, state);
181
- if (childPath.shouldStop) {
182
- childPath.shouldStop = false;
183
- nodePath.shouldStop = true;
184
- return;
185
- }
157
+ visitor.exit(childPath, state);
186
158
  });
187
159
  }
188
160
  }
@@ -1,4 +1,4 @@
1
- import { ASTNode } from "./nodeutils";
1
+ import { ASTNode } from "./traverse";
2
2
  export declare const functions: {
3
3
  join: {
4
4
  fn: (result: Result[][]) => Result[];
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../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BAAiB,GAAG,MAAM,OAAO,SAAS,CAAC;AACvD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAI,IAAI,IAAI,iBAAiB,CAE5E;AAOD,KAAK,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAuXlD,wBAAgB,KAAK,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,EAAE,KAAK,EAAE,MAAM,GAAI,MAAM,EAAE,CAEtE;AAED,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM,EAAE,YAAY,EAAE,CAAC,GAAI,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CAQhI;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAI,OAAO,CAMpD"}
@@ -1,4 +1,5 @@
1
1
  import { ESTree } from "meriyah";
2
+ import { ASTNode } from "./traverse";
2
3
  export declare function isNode(candidate: unknown): candidate is ASTNode;
3
4
  export declare function isAssignmentExpression(node: ESTree.Node): node is ESTree.AssignmentExpression;
4
5
  export declare function isMemberExpression(node: ESTree.Node): node is ESTree.MemberExpression;
@@ -11,7 +12,4 @@ export declare const VISITOR_KEYS: Record<ESTree.Node["type"], string[]>;
11
12
  export declare function isScope(node: ESTree.Node, parentNode: ESTree.Node): boolean;
12
13
  export declare function isScopable(node: ESTree.Node): boolean;
13
14
  export declare function isExportSpecifier(node: ESTree.Node): node is ESTree.ExportSpecifier;
14
- export type ASTNode = ESTree.Node & {
15
- extra?: Record<string, unknown>;
16
- };
17
15
  //# sourceMappingURL=nodeutils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"nodeutils.d.ts","sourceRoot":"","sources":["../../../src/nodeutils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC,wBAAgB,MAAM,CAAC,SAAS,EA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AM,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,29 +1,32 @@
1
- import { ASTNode } from "./nodeutils";
1
+ import { ESTree } from "meriyah";
2
2
  export type Binding = {
3
- path: NodePath<ASTNode>;
3
+ path: NodePath;
4
4
  };
5
5
  export type Scope = {
6
6
  bindings: Record<string, Binding>;
7
7
  parentScopeId?: number;
8
8
  id: number;
9
- hasEntries: boolean;
10
9
  };
11
- export type NodePath<T> = {
12
- node: T;
10
+ export type ASTNode = ESTree.Node & {
11
+ extra?: {
12
+ scopeId?: number;
13
+ nodePath?: NodePath;
14
+ };
15
+ };
16
+ export type NodePath = {
17
+ node: ASTNode;
13
18
  key?: string;
14
- parentPath?: NodePath<T>;
19
+ parentPath?: NodePath;
15
20
  parentKey?: string;
16
- stop: () => void;
17
- get(key: string): NodePath<ASTNode>[];
18
21
  scopeId: number;
19
- shouldStop: boolean;
20
22
  };
21
23
  type Visitor<T> = {
22
- enter: (path: NodePath<ASTNode>, state: T) => void;
23
- exit?: (path: NodePath<ASTNode>, state: T) => void;
24
+ enter: (path: NodePath, state: T) => void;
25
+ exit: (path: NodePath, state: T) => void;
24
26
  };
25
27
  export declare function getBinding(scopeId: number, name: string): Binding | undefined;
26
- export declare function createNodePath(node: ASTNode, key: string | undefined, parentKey: string | undefined, scopeId: number | undefined, nodePath?: NodePath<ASTNode>): NodePath<ASTNode>;
27
- export default function traverse<T>(node: ASTNode, visitor: Visitor<T>, scopeId: number | undefined, state: T, path?: NodePath<ASTNode>): void;
28
+ export declare function getChildren(key: string, path: NodePath): NodePath[];
29
+ export declare function createNodePath(node: ASTNode, key: string | undefined, parentKey: string | undefined, scopeId: number | undefined, nodePath?: NodePath): NodePath;
30
+ export default function traverse<T>(node: ASTNode, visitor: Visitor<T>, scopeId: number | undefined, state: T, path?: NodePath): void;
28
31
  export {};
29
32
  //# sourceMappingURL=traverse.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"traverse.d.ts","sourceRoot":"","sources":["../../../src/traverse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAkH,MAAM,aAAa,CAAC;AAStJ,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;CACzB,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;IACX,UAAU,EAAE,OAAO,CAAC;CACrB,CAAC;AAMF,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;IACxB,IAAI,EAAE,CAAC,CAAC;IACR,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,KAAK,OAAO,CAAC,CAAC,IAAI;IAChB,KAAK,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IACnD,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,OAAO,CAA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E,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;AAYD,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,uBAYvD;AAqBD,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAI,QAAQ,EAAE,CAUpE;AAGD,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,EAAE,SAAS,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAI,QAAQ,CAwBjK;AAuFD,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,CAAC,EAAI,IAAI,EAAE,OAAO,EACjD,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,KAAK,EAAE,CAAC,EACR,IAAI,CAAC,EAAE,QAAQ,QAMhB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astronomical",
3
- "version": "1.0.0-beta.12",
3
+ "version": "1.0.0-beta.13",
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",
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",
21
- "url": "https://github.com/RetireJS/babel-q.git"
21
+ "url": "https://github.com/RetireJS/ASTronomical.git"
22
22
  },
23
23
  "author": "Erlend Oftedal <erlend@oftedal.no>",
24
24
  "license": "Apache-2.0",