astronomical 3.0.4 → 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 +102 -37
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +103 -38
- package/lib/index.mjs.map +1 -1
- package/package.json +7 -6
package/lib/index.mjs
CHANGED
|
@@ -537,7 +537,7 @@ function parse(input) {
|
|
|
537
537
|
}
|
|
538
538
|
|
|
539
539
|
// src/index.ts
|
|
540
|
-
import {
|
|
540
|
+
import { parse as parseJS } from "meriyah";
|
|
541
541
|
|
|
542
542
|
// src/utils.ts
|
|
543
543
|
function toArray(value) {
|
|
@@ -634,6 +634,42 @@ function createQuerier() {
|
|
|
634
634
|
result
|
|
635
635
|
};
|
|
636
636
|
}
|
|
637
|
+
function activateDescendant(fnode, state) {
|
|
638
|
+
state.descendant[state.depth + 1].push(fnode);
|
|
639
|
+
fnode.seq = state.seqCounter++;
|
|
640
|
+
const value = fnode.node.value;
|
|
641
|
+
if (fnode.node.attribute) {
|
|
642
|
+
state.descendantOther.push(fnode);
|
|
643
|
+
state.descendantAttr.push(fnode);
|
|
644
|
+
} else if (value == "*") {
|
|
645
|
+
state.descendantOther.push(fnode);
|
|
646
|
+
} else if (value != void 0) {
|
|
647
|
+
let bucket = state.descendantByType.get(value);
|
|
648
|
+
if (!bucket) {
|
|
649
|
+
bucket = [];
|
|
650
|
+
state.descendantByType.set(value, bucket);
|
|
651
|
+
}
|
|
652
|
+
bucket.push(fnode);
|
|
653
|
+
}
|
|
654
|
+
state.descendantActiveCount++;
|
|
655
|
+
}
|
|
656
|
+
function removeFromBucket(arr, fnode) {
|
|
657
|
+
const i = arr.lastIndexOf(fnode);
|
|
658
|
+
if (i >= 0) arr.splice(i, 1);
|
|
659
|
+
}
|
|
660
|
+
function deactivateDescendant(fnode, state) {
|
|
661
|
+
const value = fnode.node.value;
|
|
662
|
+
if (fnode.node.attribute) {
|
|
663
|
+
removeFromBucket(state.descendantOther, fnode);
|
|
664
|
+
removeFromBucket(state.descendantAttr, fnode);
|
|
665
|
+
} else if (value == "*") {
|
|
666
|
+
removeFromBucket(state.descendantOther, fnode);
|
|
667
|
+
} else if (value != void 0) {
|
|
668
|
+
const bucket = state.descendantByType.get(value);
|
|
669
|
+
if (bucket) removeFromBucket(bucket, fnode);
|
|
670
|
+
}
|
|
671
|
+
state.descendantActiveCount--;
|
|
672
|
+
}
|
|
637
673
|
function addFilterChildrenToState(filter, state) {
|
|
638
674
|
if ("type" in filter && (filter.type == NodeType.AND || filter.type == NodeType.OR || filter.type == NodeType.EQUALS)) {
|
|
639
675
|
addFilterChildrenToState(filter.left, state);
|
|
@@ -645,7 +681,7 @@ function createQuerier() {
|
|
|
645
681
|
}
|
|
646
682
|
if (filter.node.type == NodeType.DESCENDANT) {
|
|
647
683
|
log2?.debug("ADDING FILTER DESCENDANT", filter.node);
|
|
648
|
-
|
|
684
|
+
activateDescendant(filter, state);
|
|
649
685
|
}
|
|
650
686
|
}
|
|
651
687
|
}
|
|
@@ -655,7 +691,7 @@ function createQuerier() {
|
|
|
655
691
|
if (token.type == NodeType.CHILD) {
|
|
656
692
|
state.child[state.depth + 1].push(fnode);
|
|
657
693
|
} else if (token.type == NodeType.DESCENDANT) {
|
|
658
|
-
|
|
694
|
+
activateDescendant(fnode, state);
|
|
659
695
|
}
|
|
660
696
|
return fnode;
|
|
661
697
|
}
|
|
@@ -674,16 +710,24 @@ function createQuerier() {
|
|
|
674
710
|
}
|
|
675
711
|
function addIfTokenMatch(fnode, path, state) {
|
|
676
712
|
if (!isMatch(fnode, path)) return;
|
|
713
|
+
addMatch(fnode, path, state);
|
|
714
|
+
}
|
|
715
|
+
function addMatch(fnode, path, state) {
|
|
677
716
|
state.matches[state.depth].push([fnode, path]);
|
|
678
717
|
if (fnode.node.filter) {
|
|
679
718
|
const filter = createFilter(fnode.node.filter, []);
|
|
680
719
|
const filteredResult = [];
|
|
681
720
|
const f = { filter, qNode: fnode.node, node: path.node, result: filteredResult };
|
|
682
721
|
state.filters[state.depth].push(f);
|
|
683
|
-
let
|
|
722
|
+
let fmapContainer = state.filtersMap[state.depth];
|
|
723
|
+
if (!fmapContainer) {
|
|
724
|
+
fmapContainer = /* @__PURE__ */ new Map();
|
|
725
|
+
state.filtersMap[state.depth] = fmapContainer;
|
|
726
|
+
}
|
|
727
|
+
let fmap = fmapContainer.get(fnode.node);
|
|
684
728
|
if (!fmap) {
|
|
685
729
|
fmap = [];
|
|
686
|
-
|
|
730
|
+
fmapContainer.set(fnode.node, fmap);
|
|
687
731
|
}
|
|
688
732
|
fmap.push(f);
|
|
689
733
|
addFilterChildrenToState(filter, state);
|
|
@@ -889,7 +933,8 @@ function createQuerier() {
|
|
|
889
933
|
function addResultIfTokenMatch(fnode, path, state) {
|
|
890
934
|
const matchingFilters = [];
|
|
891
935
|
const filters = [];
|
|
892
|
-
const
|
|
936
|
+
const fmapContainer = state.filtersMap[state.depth];
|
|
937
|
+
const nodeFilters = fmapContainer ? fmapContainer.get(fnode.node) : void 0;
|
|
893
938
|
if (nodeFilters) {
|
|
894
939
|
for (let i = 0; i < nodeFilters.length; i++) {
|
|
895
940
|
const f = nodeFilters[i];
|
|
@@ -987,9 +1032,14 @@ function createQuerier() {
|
|
|
987
1032
|
child: [[], []],
|
|
988
1033
|
descendant: [[], []],
|
|
989
1034
|
filters: [[], []],
|
|
990
|
-
filtersMap: [
|
|
1035
|
+
filtersMap: [void 0, void 0],
|
|
991
1036
|
matches: [[]],
|
|
992
|
-
functionCalls: [[]]
|
|
1037
|
+
functionCalls: [[]],
|
|
1038
|
+
descendantByType: /* @__PURE__ */ new Map(),
|
|
1039
|
+
descendantOther: [],
|
|
1040
|
+
descendantAttr: [],
|
|
1041
|
+
descendantActiveCount: 0,
|
|
1042
|
+
seqCounter: 0
|
|
993
1043
|
};
|
|
994
1044
|
for (const [name, node] of Object.entries(queries)) {
|
|
995
1045
|
createFNodeAndAddToState(node, results[name], state);
|
|
@@ -998,12 +1048,8 @@ function createQuerier() {
|
|
|
998
1048
|
for (let i = 0; i < childAtDepth.length; i++) {
|
|
999
1049
|
addPrimitiveAttributeIfMatch(childAtDepth[i], root);
|
|
1000
1050
|
}
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
const fnodes = descendantSlice[i];
|
|
1004
|
-
for (let j = 0; j < fnodes.length; j++) {
|
|
1005
|
-
addPrimitiveAttributeIfMatch(fnodes[j], root);
|
|
1006
|
-
}
|
|
1051
|
+
for (let i = 0; i < state.descendantAttr.length; i++) {
|
|
1052
|
+
addPrimitiveAttributeIfMatch(state.descendantAttr[i], root);
|
|
1007
1053
|
}
|
|
1008
1054
|
traverse(root.node, {
|
|
1009
1055
|
enter(path, state2) {
|
|
@@ -1011,15 +1057,31 @@ function createQuerier() {
|
|
|
1011
1057
|
state2.child.push([]);
|
|
1012
1058
|
state2.descendant.push([]);
|
|
1013
1059
|
state2.filters.push([]);
|
|
1014
|
-
state2.filtersMap.push(
|
|
1060
|
+
state2.filtersMap.push(void 0);
|
|
1015
1061
|
state2.matches.push([]);
|
|
1016
1062
|
state2.functionCalls.push([]);
|
|
1017
1063
|
for (const fnode of state2.child[state2.depth]) {
|
|
1018
1064
|
addIfTokenMatch(fnode, path, state2);
|
|
1019
1065
|
}
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1066
|
+
const bucket = state2.descendantByType.get(path.node.type);
|
|
1067
|
+
const other = state2.descendantOther;
|
|
1068
|
+
const bucketLen = bucket ? bucket.length : 0;
|
|
1069
|
+
const otherLen = other.length;
|
|
1070
|
+
if (otherLen == 0) {
|
|
1071
|
+
for (let i = 0; i < bucketLen; i++) {
|
|
1072
|
+
addMatch(bucket[i], path, state2);
|
|
1073
|
+
}
|
|
1074
|
+
} else if (bucketLen == 0) {
|
|
1075
|
+
for (let i = 0; i < otherLen; i++) {
|
|
1076
|
+
addIfTokenMatch(other[i], path, state2);
|
|
1077
|
+
}
|
|
1078
|
+
} else {
|
|
1079
|
+
const cands = [];
|
|
1080
|
+
for (let i = 0; i < bucketLen; i++) cands.push(bucket[i]);
|
|
1081
|
+
for (let i = 0; i < otherLen; i++) cands.push(other[i]);
|
|
1082
|
+
cands.sort((a, b) => a.seq - b.seq);
|
|
1083
|
+
for (let i = 0; i < cands.length; i++) {
|
|
1084
|
+
addIfTokenMatch(cands[i], path, state2);
|
|
1023
1085
|
}
|
|
1024
1086
|
}
|
|
1025
1087
|
},
|
|
@@ -1029,16 +1091,17 @@ function createQuerier() {
|
|
|
1029
1091
|
for (let i = 0; i < childAtDepthPlusOne.length; i++) {
|
|
1030
1092
|
addPrimitiveAttributeIfMatch(childAtDepthPlusOne[i], path);
|
|
1031
1093
|
}
|
|
1032
|
-
for (let i = 0; i < state2.
|
|
1033
|
-
|
|
1034
|
-
for (let j = 0; j < fnodes.length; j++) {
|
|
1035
|
-
addPrimitiveAttributeIfMatch(fnodes[j], path);
|
|
1036
|
-
}
|
|
1094
|
+
for (let i = 0; i < state2.descendantAttr.length; i++) {
|
|
1095
|
+
addPrimitiveAttributeIfMatch(state2.descendantAttr[i], path);
|
|
1037
1096
|
}
|
|
1038
1097
|
const matchesAtDepth = state2.matches[state2.depth];
|
|
1039
1098
|
for (let i = 0; i < matchesAtDepth.length; i++) {
|
|
1040
1099
|
addResultIfTokenMatch(matchesAtDepth[i][0], matchesAtDepth[i][1], state2);
|
|
1041
1100
|
}
|
|
1101
|
+
const leavingDescendants = state2.descendant[state2.descendant.length - 1];
|
|
1102
|
+
for (let i = 0; i < leavingDescendants.length; i++) {
|
|
1103
|
+
deactivateDescendant(leavingDescendants[i], state2);
|
|
1104
|
+
}
|
|
1042
1105
|
state2.depth--;
|
|
1043
1106
|
state2.child.pop();
|
|
1044
1107
|
state2.descendant.pop();
|
|
@@ -1090,16 +1153,17 @@ function multiQuery(code, namedQueries, returnAST) {
|
|
|
1090
1153
|
}
|
|
1091
1154
|
function parseSource(source, optimize = true) {
|
|
1092
1155
|
const parsingOptions = optimize ? { loc: false, ranges: false } : { loc: true, ranges: true };
|
|
1156
|
+
const base = { next: true, validateRegex: false, ...parsingOptions };
|
|
1093
1157
|
try {
|
|
1094
|
-
return
|
|
1158
|
+
return parseJS(source, { ...base, sourceType: "module" });
|
|
1095
1159
|
} catch {
|
|
1096
1160
|
try {
|
|
1097
|
-
return
|
|
1161
|
+
return parseJS(source, { ...base, sourceType: "script", webcompat: true });
|
|
1098
1162
|
} catch {
|
|
1099
1163
|
try {
|
|
1100
|
-
return
|
|
1164
|
+
return parseJS(source, { ...base, sourceType: "module", jsx: true });
|
|
1101
1165
|
} catch {
|
|
1102
|
-
return
|
|
1166
|
+
return parseJS(source, { ...base, sourceType: "script", webcompat: true, jsx: true });
|
|
1103
1167
|
}
|
|
1104
1168
|
}
|
|
1105
1169
|
}
|
|
@@ -1295,7 +1359,7 @@ function createTraverser() {
|
|
|
1295
1359
|
registerBindings(stack, nodePath.scopeId, nodePath.functionScopeId);
|
|
1296
1360
|
}
|
|
1297
1361
|
const stateTyped = state;
|
|
1298
|
-
const hasDescendantQueries = stateTyped.
|
|
1362
|
+
const hasDescendantQueries = stateTyped.descendantActiveCount > 0;
|
|
1299
1363
|
const hasChildQueriesAtNextDepth = stateTyped.child && stateTyped.child[stateTyped.depth + 1] && stateTyped.child[stateTyped.depth + 1].length > 0;
|
|
1300
1364
|
if (!hasDescendantQueries && !hasChildQueriesAtNextDepth) {
|
|
1301
1365
|
return;
|
|
@@ -1303,17 +1367,18 @@ function createTraverser() {
|
|
|
1303
1367
|
for (let keyIdx = 0; keyIdx < keys.length; keyIdx++) {
|
|
1304
1368
|
const key = keys[keyIdx];
|
|
1305
1369
|
const childNodes = node[key];
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
const childPath = createNodePath(child,
|
|
1312
|
-
|
|
1370
|
+
if (childNodes == void 0) continue;
|
|
1371
|
+
if (Array.isArray(childNodes)) {
|
|
1372
|
+
for (let i = 0; i < childNodes.length; i++) {
|
|
1373
|
+
const child = childNodes[i];
|
|
1374
|
+
if (!isNode(child)) continue;
|
|
1375
|
+
const childPath = createNodePath(child, i, key, nodePath.scopeId, nodePath.functionScopeId, nodePath);
|
|
1376
|
+
visitor.enter(childPath, state);
|
|
1377
|
+
traverseInner(childPath.node, visitor, nodePath.scopeId, nodePath.functionScopeId, state, childPath);
|
|
1378
|
+
visitor.exit(childPath, state);
|
|
1313
1379
|
}
|
|
1314
|
-
}
|
|
1315
|
-
|
|
1316
|
-
const childPath = nodePaths[i];
|
|
1380
|
+
} else if (isNode(childNodes)) {
|
|
1381
|
+
const childPath = createNodePath(childNodes, key, key, nodePath.scopeId, nodePath.functionScopeId, nodePath);
|
|
1317
1382
|
visitor.enter(childPath, state);
|
|
1318
1383
|
traverseInner(childPath.node, visitor, nodePath.scopeId, nodePath.functionScopeId, state, childPath);
|
|
1319
1384
|
visitor.exit(childPath, state);
|