@oddo/lang 0.0.2 → 0.0.3
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/dist/index.js +95 -71
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +95 -71
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2633,8 +2633,10 @@ function convertPostfix(cst) {
|
|
|
2633
2633
|
return operand;
|
|
2634
2634
|
}
|
|
2635
2635
|
function convertFunctionCall(cst) {
|
|
2636
|
+
var _a;
|
|
2636
2637
|
let callee = convertExpression(getFirstChild(cst, "memberAccess"));
|
|
2637
2638
|
const leftParens = cst.children.LeftParen || [];
|
|
2639
|
+
const rightParens = cst.children.RightParen || [];
|
|
2638
2640
|
const questionDots = cst.children.QuestionDot || [];
|
|
2639
2641
|
const templateLiterals = cst.children.TemplateLiteral || [];
|
|
2640
2642
|
if (templateLiterals.length > 0 && leftParens.length === 0) {
|
|
@@ -2652,11 +2654,16 @@ function convertFunctionCall(cst) {
|
|
|
2652
2654
|
const argLists = getAllChildren(cst, "argumentList");
|
|
2653
2655
|
const allExprs = getAllChildren(cst, "expression");
|
|
2654
2656
|
const ops = [
|
|
2655
|
-
...leftParens.map((t2, i) => ({
|
|
2657
|
+
...leftParens.map((t2, i) => ({
|
|
2658
|
+
k: "c",
|
|
2659
|
+
off: t2.startOffset,
|
|
2660
|
+
token: t2,
|
|
2661
|
+
rightParen: rightParens[i]
|
|
2662
|
+
})),
|
|
2656
2663
|
...dots.map((t2, i) => ({ k: "d", off: t2.startOffset, i })),
|
|
2657
2664
|
...brackets.map((t2, i) => {
|
|
2658
|
-
var
|
|
2659
|
-
return { k: "b", off: t2.startOffset, i, end: (
|
|
2665
|
+
var _a2;
|
|
2666
|
+
return { k: "b", off: t2.startOffset, i, end: (_a2 = rightBrackets[i]) == null ? void 0 : _a2.endOffset };
|
|
2660
2667
|
}),
|
|
2661
2668
|
...questionDots.filter((q) => !leftParens.some((p) => Math.abs(p.startOffset - q.endOffset) <= 1)).map((t2, i) => ({ k: "q", off: t2.startOffset, i }))
|
|
2662
2669
|
].sort((a, b) => a.off - b.off);
|
|
@@ -2664,7 +2671,12 @@ function convertFunctionCall(cst) {
|
|
|
2664
2671
|
for (const op of ops) {
|
|
2665
2672
|
if (op.k === "c") {
|
|
2666
2673
|
const isOptional = questionDots.some((q) => q.endOffset < op.token.startOffset && op.token.startOffset - q.endOffset <= 1);
|
|
2667
|
-
const
|
|
2674
|
+
const leftOff = op.token.startOffset;
|
|
2675
|
+
const rightOff = (_a = op.rightParen) == null ? void 0 : _a.endOffset;
|
|
2676
|
+
const argsCST = argLists.find((al) => {
|
|
2677
|
+
const alStart = getFirstTokenOffset(al);
|
|
2678
|
+
return alStart !== void 0 && alStart > leftOff && (rightOff === void 0 || alStart < rightOff);
|
|
2679
|
+
});
|
|
2668
2680
|
const args = [];
|
|
2669
2681
|
if (argsCST) {
|
|
2670
2682
|
const exprs = getAllChildren(argsCST, "expression");
|
|
@@ -2684,9 +2696,9 @@ function convertFunctionCall(cst) {
|
|
|
2684
2696
|
if (nextBracket) {
|
|
2685
2697
|
const bIdx = brackets.indexOf(nextBracket);
|
|
2686
2698
|
const expr = allExprs.find((e) => {
|
|
2687
|
-
var
|
|
2699
|
+
var _a2;
|
|
2688
2700
|
const o = getFirstTokenOffset(e);
|
|
2689
|
-
return o > nextBracket.startOffset && o < ((
|
|
2701
|
+
return o > nextBracket.startOffset && o < ((_a2 = rightBrackets[bIdx]) == null ? void 0 : _a2.endOffset);
|
|
2690
2702
|
});
|
|
2691
2703
|
if (expr) callee = { type: "memberAccess", object: callee, property: convertExpression(expr), computed: true, optional: true };
|
|
2692
2704
|
ops.splice(ops.findIndex((o) => o.k === "b" && o.i === bIdx), 1);
|
|
@@ -2709,6 +2721,7 @@ function convertMemberAccess(cst) {
|
|
|
2709
2721
|
const dots = cst.children.Dot || [];
|
|
2710
2722
|
const questionDots = cst.children.QuestionDot || [];
|
|
2711
2723
|
const brackets = cst.children.LeftBracket || [];
|
|
2724
|
+
const rightBrackets = cst.children.RightBracket || [];
|
|
2712
2725
|
const dotDotDots = cst.children.DotDotDot || [];
|
|
2713
2726
|
if (dots.length === 0 && questionDots.length === 0 && brackets.length === 0) {
|
|
2714
2727
|
return object;
|
|
@@ -2718,85 +2731,96 @@ function convertMemberAccess(cst) {
|
|
|
2718
2731
|
allOps.push({ type: "dot", token: dot, optional: false });
|
|
2719
2732
|
}
|
|
2720
2733
|
for (const qDot of questionDots) {
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
const identifiers = cst.children.Identifier || [];
|
|
2725
|
-
let identifierIndex = 0;
|
|
2726
|
-
for (let i = 0; i < allOps.length; i++) {
|
|
2727
|
-
const op = allOps[i];
|
|
2728
|
-
const identifier2 = identifiers[identifierIndex];
|
|
2729
|
-
if (identifier2) {
|
|
2730
|
-
identifierIndex++;
|
|
2731
|
-
object = {
|
|
2732
|
-
type: "memberAccess",
|
|
2733
|
-
object,
|
|
2734
|
-
property: identifier2.image,
|
|
2735
|
-
computed: false,
|
|
2736
|
-
optional: op.optional
|
|
2737
|
-
};
|
|
2734
|
+
const isFollowedByBracket = brackets.some((b) => b.startOffset > qDot.endOffset && b.startOffset - qDot.endOffset <= 1);
|
|
2735
|
+
if (!isFollowedByBracket) {
|
|
2736
|
+
allOps.push({ type: "dot", token: qDot, optional: true });
|
|
2738
2737
|
}
|
|
2739
2738
|
}
|
|
2740
|
-
const expressions = getAllChildren(cst, "expression");
|
|
2741
|
-
let expressionIndex = 0;
|
|
2742
2739
|
for (let i = 0; i < brackets.length; i++) {
|
|
2743
2740
|
const bracket = brackets[i];
|
|
2744
|
-
const bracketStart = bracket.startOffset;
|
|
2745
|
-
const isOptional = questionDots.some((qDot) => {
|
|
2746
|
-
return qDot.endOffset < bracketStart && bracketStart - qDot.endOffset <= 1;
|
|
2747
|
-
});
|
|
2748
|
-
const rightBrackets = cst.children.RightBracket || [];
|
|
2749
2741
|
const rightBracket = rightBrackets[i];
|
|
2750
2742
|
if (!rightBracket) continue;
|
|
2743
|
+
const isOptional = questionDots.some(
|
|
2744
|
+
(qDot) => qDot.endOffset < bracket.startOffset && bracket.startOffset - qDot.endOffset <= 1
|
|
2745
|
+
);
|
|
2751
2746
|
const dotDotDotsInRange = dotDotDots.filter(
|
|
2752
|
-
(ddd) => ddd.startOffset >
|
|
2747
|
+
(ddd) => ddd.startOffset > bracket.startOffset && ddd.startOffset < rightBracket.startOffset
|
|
2753
2748
|
);
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2749
|
+
allOps.push({
|
|
2750
|
+
type: "bracket",
|
|
2751
|
+
token: bracket,
|
|
2752
|
+
rightBracket,
|
|
2753
|
+
optional: isOptional,
|
|
2754
|
+
isSlice: dotDotDotsInRange.length > 0
|
|
2755
|
+
});
|
|
2756
|
+
}
|
|
2757
|
+
allOps.sort((a, b) => a.token.startOffset - b.token.startOffset);
|
|
2758
|
+
const identifiers = cst.children.Identifier || [];
|
|
2759
|
+
const expressions = getAllChildren(cst, "expression");
|
|
2760
|
+
let identifierIndex = 0;
|
|
2761
|
+
let expressionIndex = 0;
|
|
2762
|
+
for (const op of allOps) {
|
|
2763
|
+
if (op.type === "dot") {
|
|
2764
|
+
const identifier2 = identifiers[identifierIndex];
|
|
2765
|
+
if (identifier2) {
|
|
2766
|
+
identifierIndex++;
|
|
2768
2767
|
object = {
|
|
2769
|
-
type: "
|
|
2768
|
+
type: "memberAccess",
|
|
2770
2769
|
object,
|
|
2771
|
-
|
|
2772
|
-
|
|
2770
|
+
property: identifier2.image,
|
|
2771
|
+
computed: false,
|
|
2772
|
+
optional: op.optional
|
|
2773
2773
|
};
|
|
2774
|
-
continue;
|
|
2775
2774
|
}
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2775
|
+
} else if (op.type === "bracket") {
|
|
2776
|
+
if (op.isSlice) {
|
|
2777
|
+
const exprsInBracket = expressions.filter((e, idx) => {
|
|
2778
|
+
if (idx < expressionIndex) return false;
|
|
2779
|
+
const exprStart = getFirstTokenOffset(e);
|
|
2780
|
+
return exprStart > op.token.startOffset && exprStart < op.rightBracket.startOffset;
|
|
2781
|
+
});
|
|
2782
|
+
if (exprsInBracket.length === 0) {
|
|
2783
|
+
object = {
|
|
2784
|
+
type: "arraySlice",
|
|
2785
|
+
object,
|
|
2786
|
+
start: null,
|
|
2787
|
+
end: null
|
|
2788
|
+
};
|
|
2789
|
+
} else if (exprsInBracket.length >= 2) {
|
|
2790
|
+
const startExpr = expressions[expressionIndex];
|
|
2791
|
+
const endExpr = expressions[expressionIndex + 1];
|
|
2792
|
+
expressionIndex += 2;
|
|
2793
|
+
object = {
|
|
2794
|
+
type: "arraySlice",
|
|
2795
|
+
object,
|
|
2796
|
+
start: convertExpression(startExpr),
|
|
2797
|
+
end: convertExpression(endExpr)
|
|
2798
|
+
};
|
|
2799
|
+
} else {
|
|
2800
|
+
const startExpr = expressions[expressionIndex];
|
|
2801
|
+
expressionIndex++;
|
|
2802
|
+
object = {
|
|
2803
|
+
type: "arraySlice",
|
|
2804
|
+
object,
|
|
2805
|
+
start: convertExpression(startExpr),
|
|
2806
|
+
end: null
|
|
2807
|
+
};
|
|
2808
|
+
}
|
|
2809
|
+
} else {
|
|
2810
|
+
if (expressions.length > expressionIndex) {
|
|
2811
|
+
const exprCst = expressions[expressionIndex];
|
|
2812
|
+
expressionIndex++;
|
|
2813
|
+
const property = convertExpression(exprCst);
|
|
2814
|
+
object = {
|
|
2815
|
+
type: "memberAccess",
|
|
2816
|
+
object,
|
|
2817
|
+
property,
|
|
2818
|
+
computed: true,
|
|
2819
|
+
optional: op.optional
|
|
2820
|
+
};
|
|
2821
|
+
}
|
|
2786
2822
|
}
|
|
2787
2823
|
}
|
|
2788
|
-
if (expressions.length > expressionIndex) {
|
|
2789
|
-
const exprCst = expressions[expressionIndex];
|
|
2790
|
-
expressionIndex++;
|
|
2791
|
-
const property = convertExpression(exprCst);
|
|
2792
|
-
object = {
|
|
2793
|
-
type: "memberAccess",
|
|
2794
|
-
object,
|
|
2795
|
-
property,
|
|
2796
|
-
computed: true,
|
|
2797
|
-
optional: isOptional
|
|
2798
|
-
};
|
|
2799
|
-
}
|
|
2800
2824
|
}
|
|
2801
2825
|
return object;
|
|
2802
2826
|
}
|