astronomical 3.0.5 → 3.0.6
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 +97 -33
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +97 -33
- package/lib/index.mjs.map +1 -1
- package/package.json +2 -1
package/lib/index.js
CHANGED
|
@@ -664,6 +664,42 @@ function createQuerier() {
|
|
|
664
664
|
result
|
|
665
665
|
};
|
|
666
666
|
}
|
|
667
|
+
function activateDescendant(fnode, state) {
|
|
668
|
+
state.descendant[state.depth + 1].push(fnode);
|
|
669
|
+
fnode.seq = state.seqCounter++;
|
|
670
|
+
const value = fnode.node.value;
|
|
671
|
+
if (fnode.node.attribute) {
|
|
672
|
+
state.descendantOther.push(fnode);
|
|
673
|
+
state.descendantAttr.push(fnode);
|
|
674
|
+
} else if (value == "*") {
|
|
675
|
+
state.descendantOther.push(fnode);
|
|
676
|
+
} else if (value != void 0) {
|
|
677
|
+
let bucket = state.descendantByType.get(value);
|
|
678
|
+
if (!bucket) {
|
|
679
|
+
bucket = [];
|
|
680
|
+
state.descendantByType.set(value, bucket);
|
|
681
|
+
}
|
|
682
|
+
bucket.push(fnode);
|
|
683
|
+
}
|
|
684
|
+
state.descendantActiveCount++;
|
|
685
|
+
}
|
|
686
|
+
function removeFromBucket(arr, fnode) {
|
|
687
|
+
const i = arr.lastIndexOf(fnode);
|
|
688
|
+
if (i >= 0) arr.splice(i, 1);
|
|
689
|
+
}
|
|
690
|
+
function deactivateDescendant(fnode, state) {
|
|
691
|
+
const value = fnode.node.value;
|
|
692
|
+
if (fnode.node.attribute) {
|
|
693
|
+
removeFromBucket(state.descendantOther, fnode);
|
|
694
|
+
removeFromBucket(state.descendantAttr, fnode);
|
|
695
|
+
} else if (value == "*") {
|
|
696
|
+
removeFromBucket(state.descendantOther, fnode);
|
|
697
|
+
} else if (value != void 0) {
|
|
698
|
+
const bucket = state.descendantByType.get(value);
|
|
699
|
+
if (bucket) removeFromBucket(bucket, fnode);
|
|
700
|
+
}
|
|
701
|
+
state.descendantActiveCount--;
|
|
702
|
+
}
|
|
667
703
|
function addFilterChildrenToState(filter, state) {
|
|
668
704
|
if ("type" in filter && (filter.type == NodeType.AND || filter.type == NodeType.OR || filter.type == NodeType.EQUALS)) {
|
|
669
705
|
addFilterChildrenToState(filter.left, state);
|
|
@@ -675,7 +711,7 @@ function createQuerier() {
|
|
|
675
711
|
}
|
|
676
712
|
if (filter.node.type == NodeType.DESCENDANT) {
|
|
677
713
|
log2?.debug("ADDING FILTER DESCENDANT", filter.node);
|
|
678
|
-
|
|
714
|
+
activateDescendant(filter, state);
|
|
679
715
|
}
|
|
680
716
|
}
|
|
681
717
|
}
|
|
@@ -685,7 +721,7 @@ function createQuerier() {
|
|
|
685
721
|
if (token.type == NodeType.CHILD) {
|
|
686
722
|
state.child[state.depth + 1].push(fnode);
|
|
687
723
|
} else if (token.type == NodeType.DESCENDANT) {
|
|
688
|
-
|
|
724
|
+
activateDescendant(fnode, state);
|
|
689
725
|
}
|
|
690
726
|
return fnode;
|
|
691
727
|
}
|
|
@@ -704,16 +740,24 @@ function createQuerier() {
|
|
|
704
740
|
}
|
|
705
741
|
function addIfTokenMatch(fnode, path, state) {
|
|
706
742
|
if (!isMatch(fnode, path)) return;
|
|
743
|
+
addMatch(fnode, path, state);
|
|
744
|
+
}
|
|
745
|
+
function addMatch(fnode, path, state) {
|
|
707
746
|
state.matches[state.depth].push([fnode, path]);
|
|
708
747
|
if (fnode.node.filter) {
|
|
709
748
|
const filter = createFilter(fnode.node.filter, []);
|
|
710
749
|
const filteredResult = [];
|
|
711
750
|
const f = { filter, qNode: fnode.node, node: path.node, result: filteredResult };
|
|
712
751
|
state.filters[state.depth].push(f);
|
|
713
|
-
let
|
|
752
|
+
let fmapContainer = state.filtersMap[state.depth];
|
|
753
|
+
if (!fmapContainer) {
|
|
754
|
+
fmapContainer = /* @__PURE__ */ new Map();
|
|
755
|
+
state.filtersMap[state.depth] = fmapContainer;
|
|
756
|
+
}
|
|
757
|
+
let fmap = fmapContainer.get(fnode.node);
|
|
714
758
|
if (!fmap) {
|
|
715
759
|
fmap = [];
|
|
716
|
-
|
|
760
|
+
fmapContainer.set(fnode.node, fmap);
|
|
717
761
|
}
|
|
718
762
|
fmap.push(f);
|
|
719
763
|
addFilterChildrenToState(filter, state);
|
|
@@ -919,7 +963,8 @@ function createQuerier() {
|
|
|
919
963
|
function addResultIfTokenMatch(fnode, path, state) {
|
|
920
964
|
const matchingFilters = [];
|
|
921
965
|
const filters = [];
|
|
922
|
-
const
|
|
966
|
+
const fmapContainer = state.filtersMap[state.depth];
|
|
967
|
+
const nodeFilters = fmapContainer ? fmapContainer.get(fnode.node) : void 0;
|
|
923
968
|
if (nodeFilters) {
|
|
924
969
|
for (let i = 0; i < nodeFilters.length; i++) {
|
|
925
970
|
const f = nodeFilters[i];
|
|
@@ -1017,9 +1062,14 @@ function createQuerier() {
|
|
|
1017
1062
|
child: [[], []],
|
|
1018
1063
|
descendant: [[], []],
|
|
1019
1064
|
filters: [[], []],
|
|
1020
|
-
filtersMap: [
|
|
1065
|
+
filtersMap: [void 0, void 0],
|
|
1021
1066
|
matches: [[]],
|
|
1022
|
-
functionCalls: [[]]
|
|
1067
|
+
functionCalls: [[]],
|
|
1068
|
+
descendantByType: /* @__PURE__ */ new Map(),
|
|
1069
|
+
descendantOther: [],
|
|
1070
|
+
descendantAttr: [],
|
|
1071
|
+
descendantActiveCount: 0,
|
|
1072
|
+
seqCounter: 0
|
|
1023
1073
|
};
|
|
1024
1074
|
for (const [name, node] of Object.entries(queries)) {
|
|
1025
1075
|
createFNodeAndAddToState(node, results[name], state);
|
|
@@ -1028,12 +1078,8 @@ function createQuerier() {
|
|
|
1028
1078
|
for (let i = 0; i < childAtDepth.length; i++) {
|
|
1029
1079
|
addPrimitiveAttributeIfMatch(childAtDepth[i], root);
|
|
1030
1080
|
}
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
const fnodes = descendantSlice[i];
|
|
1034
|
-
for (let j = 0; j < fnodes.length; j++) {
|
|
1035
|
-
addPrimitiveAttributeIfMatch(fnodes[j], root);
|
|
1036
|
-
}
|
|
1081
|
+
for (let i = 0; i < state.descendantAttr.length; i++) {
|
|
1082
|
+
addPrimitiveAttributeIfMatch(state.descendantAttr[i], root);
|
|
1037
1083
|
}
|
|
1038
1084
|
traverse(root.node, {
|
|
1039
1085
|
enter(path, state2) {
|
|
@@ -1041,15 +1087,31 @@ function createQuerier() {
|
|
|
1041
1087
|
state2.child.push([]);
|
|
1042
1088
|
state2.descendant.push([]);
|
|
1043
1089
|
state2.filters.push([]);
|
|
1044
|
-
state2.filtersMap.push(
|
|
1090
|
+
state2.filtersMap.push(void 0);
|
|
1045
1091
|
state2.matches.push([]);
|
|
1046
1092
|
state2.functionCalls.push([]);
|
|
1047
1093
|
for (const fnode of state2.child[state2.depth]) {
|
|
1048
1094
|
addIfTokenMatch(fnode, path, state2);
|
|
1049
1095
|
}
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1096
|
+
const bucket = state2.descendantByType.get(path.node.type);
|
|
1097
|
+
const other = state2.descendantOther;
|
|
1098
|
+
const bucketLen = bucket ? bucket.length : 0;
|
|
1099
|
+
const otherLen = other.length;
|
|
1100
|
+
if (otherLen == 0) {
|
|
1101
|
+
for (let i = 0; i < bucketLen; i++) {
|
|
1102
|
+
addMatch(bucket[i], path, state2);
|
|
1103
|
+
}
|
|
1104
|
+
} else if (bucketLen == 0) {
|
|
1105
|
+
for (let i = 0; i < otherLen; i++) {
|
|
1106
|
+
addIfTokenMatch(other[i], path, state2);
|
|
1107
|
+
}
|
|
1108
|
+
} else {
|
|
1109
|
+
const cands = [];
|
|
1110
|
+
for (let i = 0; i < bucketLen; i++) cands.push(bucket[i]);
|
|
1111
|
+
for (let i = 0; i < otherLen; i++) cands.push(other[i]);
|
|
1112
|
+
cands.sort((a, b) => a.seq - b.seq);
|
|
1113
|
+
for (let i = 0; i < cands.length; i++) {
|
|
1114
|
+
addIfTokenMatch(cands[i], path, state2);
|
|
1053
1115
|
}
|
|
1054
1116
|
}
|
|
1055
1117
|
},
|
|
@@ -1059,16 +1121,17 @@ function createQuerier() {
|
|
|
1059
1121
|
for (let i = 0; i < childAtDepthPlusOne.length; i++) {
|
|
1060
1122
|
addPrimitiveAttributeIfMatch(childAtDepthPlusOne[i], path);
|
|
1061
1123
|
}
|
|
1062
|
-
for (let i = 0; i < state2.
|
|
1063
|
-
|
|
1064
|
-
for (let j = 0; j < fnodes.length; j++) {
|
|
1065
|
-
addPrimitiveAttributeIfMatch(fnodes[j], path);
|
|
1066
|
-
}
|
|
1124
|
+
for (let i = 0; i < state2.descendantAttr.length; i++) {
|
|
1125
|
+
addPrimitiveAttributeIfMatch(state2.descendantAttr[i], path);
|
|
1067
1126
|
}
|
|
1068
1127
|
const matchesAtDepth = state2.matches[state2.depth];
|
|
1069
1128
|
for (let i = 0; i < matchesAtDepth.length; i++) {
|
|
1070
1129
|
addResultIfTokenMatch(matchesAtDepth[i][0], matchesAtDepth[i][1], state2);
|
|
1071
1130
|
}
|
|
1131
|
+
const leavingDescendants = state2.descendant[state2.descendant.length - 1];
|
|
1132
|
+
for (let i = 0; i < leavingDescendants.length; i++) {
|
|
1133
|
+
deactivateDescendant(leavingDescendants[i], state2);
|
|
1134
|
+
}
|
|
1072
1135
|
state2.depth--;
|
|
1073
1136
|
state2.child.pop();
|
|
1074
1137
|
state2.descendant.pop();
|
|
@@ -1326,7 +1389,7 @@ function createTraverser() {
|
|
|
1326
1389
|
registerBindings(stack, nodePath.scopeId, nodePath.functionScopeId);
|
|
1327
1390
|
}
|
|
1328
1391
|
const stateTyped = state;
|
|
1329
|
-
const hasDescendantQueries = stateTyped.
|
|
1392
|
+
const hasDescendantQueries = stateTyped.descendantActiveCount > 0;
|
|
1330
1393
|
const hasChildQueriesAtNextDepth = stateTyped.child && stateTyped.child[stateTyped.depth + 1] && stateTyped.child[stateTyped.depth + 1].length > 0;
|
|
1331
1394
|
if (!hasDescendantQueries && !hasChildQueriesAtNextDepth) {
|
|
1332
1395
|
return;
|
|
@@ -1334,17 +1397,18 @@ function createTraverser() {
|
|
|
1334
1397
|
for (let keyIdx = 0; keyIdx < keys.length; keyIdx++) {
|
|
1335
1398
|
const key = keys[keyIdx];
|
|
1336
1399
|
const childNodes = node[key];
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
const childPath = createNodePath(child,
|
|
1343
|
-
|
|
1400
|
+
if (childNodes == void 0) continue;
|
|
1401
|
+
if (Array.isArray(childNodes)) {
|
|
1402
|
+
for (let i = 0; i < childNodes.length; i++) {
|
|
1403
|
+
const child = childNodes[i];
|
|
1404
|
+
if (!isNode(child)) continue;
|
|
1405
|
+
const childPath = createNodePath(child, i, key, nodePath.scopeId, nodePath.functionScopeId, nodePath);
|
|
1406
|
+
visitor.enter(childPath, state);
|
|
1407
|
+
traverseInner(childPath.node, visitor, nodePath.scopeId, nodePath.functionScopeId, state, childPath);
|
|
1408
|
+
visitor.exit(childPath, state);
|
|
1344
1409
|
}
|
|
1345
|
-
}
|
|
1346
|
-
|
|
1347
|
-
const childPath = nodePaths[i];
|
|
1410
|
+
} else if (isNode(childNodes)) {
|
|
1411
|
+
const childPath = createNodePath(childNodes, key, key, nodePath.scopeId, nodePath.functionScopeId, nodePath);
|
|
1348
1412
|
visitor.enter(childPath, state);
|
|
1349
1413
|
traverseInner(childPath.node, visitor, nodePath.scopeId, nodePath.functionScopeId, state, childPath);
|
|
1350
1414
|
visitor.exit(childPath, state);
|