@abapify/abap-ast 0.4.33 → 0.4.36
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/README.md +17 -184
- package/dist/index.d.mts +57 -62
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +100 -78
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -630,7 +630,7 @@ function printExpression(expr, writer) {
|
|
|
630
630
|
}
|
|
631
631
|
function printLiteral(kind, value) {
|
|
632
632
|
switch (kind) {
|
|
633
|
-
case "string": return `'${String(value).replaceAll("'",
|
|
633
|
+
case "string": return `'${String(value).replaceAll("'", "''")}'`;
|
|
634
634
|
case "int": return String(value);
|
|
635
635
|
case "bool": return value ? "abap_true" : "abap_false";
|
|
636
636
|
case "hex": return `'${String(value)}'`;
|
|
@@ -657,6 +657,94 @@ function printStringTemplate(node, writer) {
|
|
|
657
657
|
function printStatements(stmts, writer) {
|
|
658
658
|
for (const s of stmts) printStatement(s, writer);
|
|
659
659
|
}
|
|
660
|
+
function printCall(stmt, writer) {
|
|
661
|
+
const col = writer.prefix().length;
|
|
662
|
+
if (stmt.callKind === "static") {
|
|
663
|
+
const recv = stmt.receiver !== void 0 ? printExpression(stmt.receiver, writer) : "";
|
|
664
|
+
const head = recv.length > 0 ? `${recv}=>${stmt.method}` : stmt.method;
|
|
665
|
+
const args = printArgs(stmt.args, writer, col + head.length + 1);
|
|
666
|
+
writer.writeLine(`${head}(${args}).`);
|
|
667
|
+
} else {
|
|
668
|
+
if (stmt.receiver === void 0) throw new Error("Call: instance call has no receiver");
|
|
669
|
+
const head = `${printExpression(stmt.receiver, writer)}->${stmt.method}`;
|
|
670
|
+
const args = printArgs(stmt.args, writer, col + head.length + 1);
|
|
671
|
+
writer.writeLine(`${head}(${args}).`);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
function printIf(stmt, writer) {
|
|
675
|
+
const K = (s) => writer.kw(s);
|
|
676
|
+
writer.writeLine(`${K("IF")} ${printExpression(stmt.condition, writer)}.`);
|
|
677
|
+
writer.indent();
|
|
678
|
+
printStatements(stmt.thenBody, writer);
|
|
679
|
+
writer.dedent();
|
|
680
|
+
for (const b of stmt.elseIfs) {
|
|
681
|
+
writer.writeLine(`${K("ELSEIF")} ${printExpression(b.condition, writer)}.`);
|
|
682
|
+
writer.indent();
|
|
683
|
+
printStatements(b.body, writer);
|
|
684
|
+
writer.dedent();
|
|
685
|
+
}
|
|
686
|
+
if (stmt.else) {
|
|
687
|
+
writer.writeLine(`${K("ELSE")}.`);
|
|
688
|
+
writer.indent();
|
|
689
|
+
printStatements(stmt.else, writer);
|
|
690
|
+
writer.dedent();
|
|
691
|
+
}
|
|
692
|
+
writer.writeLine(`${K("ENDIF")}.`);
|
|
693
|
+
}
|
|
694
|
+
function printLoop(stmt, writer) {
|
|
695
|
+
const K = (s) => writer.kw(s);
|
|
696
|
+
const table = printExpression(stmt.table, writer);
|
|
697
|
+
const bind = stmt.binding.bindKind === "into" ? `${K("INTO")} ${stmt.binding.target}` : `${K("ASSIGNING")} ${stmt.binding.fieldSymbol}`;
|
|
698
|
+
writer.writeLine(`${K("LOOP AT")} ${table} ${bind}.`);
|
|
699
|
+
writer.indent();
|
|
700
|
+
printStatements(stmt.body, writer);
|
|
701
|
+
writer.dedent();
|
|
702
|
+
writer.writeLine(`${K("ENDLOOP")}.`);
|
|
703
|
+
}
|
|
704
|
+
function printReturn(stmt, writer) {
|
|
705
|
+
const K = (s) => writer.kw(s);
|
|
706
|
+
if (stmt.value !== void 0) writer.writeLine(`${stmt.target} = ${printExpression(stmt.value, writer)}.`);
|
|
707
|
+
writer.writeLine(`${K("RETURN")}.`);
|
|
708
|
+
}
|
|
709
|
+
function printTry(stmt, writer) {
|
|
710
|
+
const K = (s) => writer.kw(s);
|
|
711
|
+
writer.writeLine(`${K("TRY")}.`);
|
|
712
|
+
writer.indent();
|
|
713
|
+
printStatements(stmt.body, writer);
|
|
714
|
+
writer.dedent();
|
|
715
|
+
for (const c of stmt.catches) {
|
|
716
|
+
const types = c.exceptionTypes.map((t) => printInlineType(t, writer)).join(" ");
|
|
717
|
+
const into = c.into ? ` ${K("INTO")} ${c.into}` : "";
|
|
718
|
+
writer.writeLine(`${K("CATCH")} ${types}${into}.`);
|
|
719
|
+
writer.indent();
|
|
720
|
+
printStatements(c.body, writer);
|
|
721
|
+
writer.dedent();
|
|
722
|
+
}
|
|
723
|
+
if (stmt.cleanup) {
|
|
724
|
+
writer.writeLine(`${K("CLEANUP")}.`);
|
|
725
|
+
writer.indent();
|
|
726
|
+
printStatements(stmt.cleanup, writer);
|
|
727
|
+
writer.dedent();
|
|
728
|
+
}
|
|
729
|
+
writer.writeLine(`${K("ENDTRY")}.`);
|
|
730
|
+
}
|
|
731
|
+
function printRead(stmt, writer) {
|
|
732
|
+
const K = (s) => writer.kw(s);
|
|
733
|
+
const t = printExpression(stmt.table, writer);
|
|
734
|
+
const bind = stmt.binding.bindKind === "into" ? `${K("INTO")} ${stmt.binding.target}` : `${K("ASSIGNING")} ${stmt.binding.fieldSymbol}`;
|
|
735
|
+
const parts = [`${K("READ TABLE")} ${t}`];
|
|
736
|
+
if (stmt.index !== void 0) parts.push(`${K("INDEX")} ${printExpression(stmt.index, writer)}`);
|
|
737
|
+
parts.push(bind);
|
|
738
|
+
if (stmt.withKey && stmt.withKey.length > 0) {
|
|
739
|
+
const kv = stmt.withKey.map((a) => `${a.name} = ${printExpression(a.value, writer)}`).join(" ");
|
|
740
|
+
parts.push(`${K("WITH KEY")} ${kv}`);
|
|
741
|
+
}
|
|
742
|
+
writer.writeLine(parts.join(" ") + ".");
|
|
743
|
+
}
|
|
744
|
+
function printRaw(stmt, writer) {
|
|
745
|
+
const lines = stmt.source.split(/\r?\n/);
|
|
746
|
+
for (const line of lines) writer.writeLine(line);
|
|
747
|
+
}
|
|
660
748
|
function printStatement(stmt, writer) {
|
|
661
749
|
const K = (s) => writer.kw(s);
|
|
662
750
|
switch (stmt.kind) {
|
|
@@ -675,21 +763,9 @@ function printStatement(stmt, writer) {
|
|
|
675
763
|
writer.writeLine(`${target} = ${value}.`);
|
|
676
764
|
return;
|
|
677
765
|
}
|
|
678
|
-
case "Call":
|
|
679
|
-
|
|
680
|
-
if (stmt.callKind === "static") {
|
|
681
|
-
const recv = stmt.receiver !== void 0 ? printExpression(stmt.receiver, writer) : "";
|
|
682
|
-
const head = recv.length > 0 ? `${recv}=>${stmt.method}` : stmt.method;
|
|
683
|
-
const args = printArgs(stmt.args, writer, col + head.length + 1);
|
|
684
|
-
writer.writeLine(`${head}(${args}).`);
|
|
685
|
-
} else {
|
|
686
|
-
if (stmt.receiver === void 0) throw new Error("Call: instance call has no receiver");
|
|
687
|
-
const head = `${printExpression(stmt.receiver, writer)}->${stmt.method}`;
|
|
688
|
-
const args = printArgs(stmt.args, writer, col + head.length + 1);
|
|
689
|
-
writer.writeLine(`${head}(${args}).`);
|
|
690
|
-
}
|
|
766
|
+
case "Call":
|
|
767
|
+
printCall(stmt, writer);
|
|
691
768
|
return;
|
|
692
|
-
}
|
|
693
769
|
case "Raise": {
|
|
694
770
|
const col = writer.prefix().length;
|
|
695
771
|
const type = printInlineType(stmt.exceptionType, writer);
|
|
@@ -699,58 +775,16 @@ function printStatement(stmt, writer) {
|
|
|
699
775
|
return;
|
|
700
776
|
}
|
|
701
777
|
case "If":
|
|
702
|
-
|
|
703
|
-
writer.indent();
|
|
704
|
-
printStatements(stmt.thenBody, writer);
|
|
705
|
-
writer.dedent();
|
|
706
|
-
for (const b of stmt.elseIfs) {
|
|
707
|
-
writer.writeLine(`${K("ELSEIF")} ${printExpression(b.condition, writer)}.`);
|
|
708
|
-
writer.indent();
|
|
709
|
-
printStatements(b.body, writer);
|
|
710
|
-
writer.dedent();
|
|
711
|
-
}
|
|
712
|
-
if (stmt.else) {
|
|
713
|
-
writer.writeLine(`${K("ELSE")}.`);
|
|
714
|
-
writer.indent();
|
|
715
|
-
printStatements(stmt.else, writer);
|
|
716
|
-
writer.dedent();
|
|
717
|
-
}
|
|
718
|
-
writer.writeLine(`${K("ENDIF")}.`);
|
|
778
|
+
printIf(stmt, writer);
|
|
719
779
|
return;
|
|
720
|
-
case "Loop":
|
|
721
|
-
|
|
722
|
-
const bind = stmt.binding.bindKind === "into" ? `${K("INTO")} ${stmt.binding.target}` : `${K("ASSIGNING")} ${stmt.binding.fieldSymbol}`;
|
|
723
|
-
writer.writeLine(`${K("LOOP AT")} ${table} ${bind}.`);
|
|
724
|
-
writer.indent();
|
|
725
|
-
printStatements(stmt.body, writer);
|
|
726
|
-
writer.dedent();
|
|
727
|
-
writer.writeLine(`${K("ENDLOOP")}.`);
|
|
780
|
+
case "Loop":
|
|
781
|
+
printLoop(stmt, writer);
|
|
728
782
|
return;
|
|
729
|
-
}
|
|
730
783
|
case "Return":
|
|
731
|
-
|
|
732
|
-
writer.writeLine(`${K("RETURN")}.`);
|
|
784
|
+
printReturn(stmt, writer);
|
|
733
785
|
return;
|
|
734
786
|
case "Try":
|
|
735
|
-
writer
|
|
736
|
-
writer.indent();
|
|
737
|
-
printStatements(stmt.body, writer);
|
|
738
|
-
writer.dedent();
|
|
739
|
-
for (const c of stmt.catches) {
|
|
740
|
-
const types = c.exceptionTypes.map((t) => printInlineType(t, writer)).join(" ");
|
|
741
|
-
const into = c.into ? ` ${K("INTO")} ${c.into}` : "";
|
|
742
|
-
writer.writeLine(`${K("CATCH")} ${types}${into}.`);
|
|
743
|
-
writer.indent();
|
|
744
|
-
printStatements(c.body, writer);
|
|
745
|
-
writer.dedent();
|
|
746
|
-
}
|
|
747
|
-
if (stmt.cleanup) {
|
|
748
|
-
writer.writeLine(`${K("CLEANUP")}.`);
|
|
749
|
-
writer.indent();
|
|
750
|
-
printStatements(stmt.cleanup, writer);
|
|
751
|
-
writer.dedent();
|
|
752
|
-
}
|
|
753
|
-
writer.writeLine(`${K("ENDTRY")}.`);
|
|
787
|
+
printTry(stmt, writer);
|
|
754
788
|
return;
|
|
755
789
|
case "Append": {
|
|
756
790
|
const v = printExpression(stmt.value, writer);
|
|
@@ -764,19 +798,9 @@ function printStatement(stmt, writer) {
|
|
|
764
798
|
writer.writeLine(`${K("INSERT")} ${v} ${K("INTO TABLE")} ${t}.`);
|
|
765
799
|
return;
|
|
766
800
|
}
|
|
767
|
-
case "Read":
|
|
768
|
-
|
|
769
|
-
const bind = stmt.binding.bindKind === "into" ? `${K("INTO")} ${stmt.binding.target}` : `${K("ASSIGNING")} ${stmt.binding.fieldSymbol}`;
|
|
770
|
-
const parts = [`${K("READ TABLE")} ${t}`];
|
|
771
|
-
if (stmt.index !== void 0) parts.push(`${K("INDEX")} ${printExpression(stmt.index, writer)}`);
|
|
772
|
-
parts.push(bind);
|
|
773
|
-
if (stmt.withKey && stmt.withKey.length > 0) {
|
|
774
|
-
const kv = stmt.withKey.map((a) => `${a.name} = ${printExpression(a.value, writer)}`).join(" ");
|
|
775
|
-
parts.push(`${K("WITH KEY")} ${kv}`);
|
|
776
|
-
}
|
|
777
|
-
writer.writeLine(parts.join(" ") + ".");
|
|
801
|
+
case "Read":
|
|
802
|
+
printRead(stmt, writer);
|
|
778
803
|
return;
|
|
779
|
-
}
|
|
780
804
|
case "Clear":
|
|
781
805
|
writer.writeLine(`${K("CLEAR")} ${printExpression(stmt.target, writer)}.`);
|
|
782
806
|
return;
|
|
@@ -786,11 +810,9 @@ function printStatement(stmt, writer) {
|
|
|
786
810
|
case "Continue":
|
|
787
811
|
writer.writeLine(`${K("CONTINUE")}.`);
|
|
788
812
|
return;
|
|
789
|
-
case "Raw":
|
|
790
|
-
|
|
791
|
-
for (const line of lines) writer.writeLine(line);
|
|
813
|
+
case "Raw":
|
|
814
|
+
printRaw(stmt, writer);
|
|
792
815
|
return;
|
|
793
|
-
}
|
|
794
816
|
}
|
|
795
817
|
}
|
|
796
818
|
function printComment(node, writer) {
|