@abaplint/transpiler 2.11.8 → 2.11.10
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/build/src/expressions/index.d.ts +1 -0
- package/build/src/expressions/index.js +1 -0
- package/build/src/expressions/source.js +14 -3
- package/build/src/expressions/type_name_or_infer.d.ts +7 -0
- package/build/src/expressions/type_name_or_infer.js +25 -0
- package/build/src/statements/loop.js +2 -1
- package/build/src/statements/message.js +5 -6
- package/build/src/statements/move.js +55 -13
- package/build/src/transpile_types.js +0 -16
- package/build/src/traversal.d.ts +4 -0
- package/build/src/traversal.js +74 -0
- package/build/src/types.d.ts +2 -0
- package/build/src/validation.js +7 -0
- package/package.json +2 -2
|
@@ -20,6 +20,7 @@ export * from "./field_offset";
|
|
|
20
20
|
export * from "./field_symbol";
|
|
21
21
|
export * from "./function_exporting";
|
|
22
22
|
export * from "./source_field_symbol_chain";
|
|
23
|
+
export * from "./type_name_or_infer";
|
|
23
24
|
export * from "./function_parameters";
|
|
24
25
|
export * from "./message_number";
|
|
25
26
|
export * from "./method_call_body";
|
|
@@ -36,6 +36,7 @@ __exportStar(require("./field_offset"), exports);
|
|
|
36
36
|
__exportStar(require("./field_symbol"), exports);
|
|
37
37
|
__exportStar(require("./function_exporting"), exports);
|
|
38
38
|
__exportStar(require("./source_field_symbol_chain"), exports);
|
|
39
|
+
__exportStar(require("./type_name_or_infer"), exports);
|
|
39
40
|
__exportStar(require("./function_parameters"), exports);
|
|
40
41
|
__exportStar(require("./message_number"), exports);
|
|
41
42
|
__exportStar(require("./method_call_body"), exports);
|
|
@@ -16,7 +16,7 @@ class SourceTranspiler {
|
|
|
16
16
|
const children = node.getChildren();
|
|
17
17
|
for (let i = 0; i < children.length; i++) {
|
|
18
18
|
const c = children[i];
|
|
19
|
-
const
|
|
19
|
+
const isLast = i === children.length - 1;
|
|
20
20
|
if (c instanceof core_1.Nodes.ExpressionNode) {
|
|
21
21
|
if (c.get() instanceof core_1.Expressions.FieldChain) {
|
|
22
22
|
ret.appendChunk(new _1.FieldChainTranspiler(this.addGet).transpile(c, traversal));
|
|
@@ -43,7 +43,7 @@ class SourceTranspiler {
|
|
|
43
43
|
if (code.includes("await")) {
|
|
44
44
|
ret = new chunk_1.Chunk().appendString("(").appendChunk(ret).appendString(")");
|
|
45
45
|
}
|
|
46
|
-
if (this.addGet &&
|
|
46
|
+
if (this.addGet && isLast === true) {
|
|
47
47
|
ret.append(".get()", c, traversal);
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -59,7 +59,7 @@ class SourceTranspiler {
|
|
|
59
59
|
else if (c.get() instanceof core_1.Expressions.ComponentChain) {
|
|
60
60
|
ret = new chunk_1.Chunk().appendString("(").appendChunk(ret).appendString(").get().");
|
|
61
61
|
ret.appendChunk(new _1.ComponentChainTranspiler().transpile(c, traversal));
|
|
62
|
-
if (this.addGet &&
|
|
62
|
+
if (this.addGet && isLast === true) {
|
|
63
63
|
ret.append(".get()", c, traversal);
|
|
64
64
|
}
|
|
65
65
|
}
|
|
@@ -69,6 +69,17 @@ class SourceTranspiler {
|
|
|
69
69
|
else if (c.get() instanceof core_1.Expressions.TextElement) {
|
|
70
70
|
ret = new chunk_1.Chunk().appendString(`new abap.types.String().set("${c.concatTokens()}")`);
|
|
71
71
|
}
|
|
72
|
+
else if (c.get() instanceof core_1.Expressions.ConvBody) {
|
|
73
|
+
const typ = node.findFirstExpression(core_1.Expressions.TypeNameOrInfer);
|
|
74
|
+
if (typ === undefined) {
|
|
75
|
+
throw new Error("TypeNameOrInfer not found in ConvBody");
|
|
76
|
+
}
|
|
77
|
+
ret = new chunk_1.Chunk().appendString(new _1.TypeNameOrInfer().transpile(typ, traversal).getCode());
|
|
78
|
+
ret.appendString(".set(");
|
|
79
|
+
// todo: handle LET
|
|
80
|
+
ret.appendString(traversal.traverse(c.getFirstChild()).getCode());
|
|
81
|
+
ret.appendString(")");
|
|
82
|
+
}
|
|
72
83
|
else {
|
|
73
84
|
ret.appendString("SourceUnknown-" + c.get().constructor.name);
|
|
74
85
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Nodes } from "@abaplint/core";
|
|
2
|
+
import { IExpressionTranspiler } from "./_expression_transpiler";
|
|
3
|
+
import { Traversal } from "../traversal";
|
|
4
|
+
import { Chunk } from "../chunk";
|
|
5
|
+
export declare class TypeNameOrInfer implements IExpressionTranspiler {
|
|
6
|
+
transpile(node: Nodes.ExpressionNode, traversal: Traversal): Chunk;
|
|
7
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypeNameOrInfer = void 0;
|
|
4
|
+
const chunk_1 = require("../chunk");
|
|
5
|
+
const transpile_types_1 = require("../transpile_types");
|
|
6
|
+
class TypeNameOrInfer {
|
|
7
|
+
transpile(node, traversal) {
|
|
8
|
+
let type;
|
|
9
|
+
const scope = traversal.findCurrentScopeByToken(node.getFirstToken());
|
|
10
|
+
if (node.concatTokens() === "#") {
|
|
11
|
+
type = traversal.lookupInferred(node, scope);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
type = traversal.lookupType(node.getFirstChild(), scope);
|
|
15
|
+
}
|
|
16
|
+
if (type === undefined) {
|
|
17
|
+
throw new Error("TypeNameOrInfer, type not found: " + node.concatTokens());
|
|
18
|
+
}
|
|
19
|
+
const ret = new chunk_1.Chunk();
|
|
20
|
+
ret.appendString(new transpile_types_1.TranspileTypes().toType(type));
|
|
21
|
+
return ret;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.TypeNameOrInfer = TypeNameOrInfer;
|
|
25
|
+
//# sourceMappingURL=type_name_or_infer.js.map
|
|
@@ -20,7 +20,8 @@ class LoopTranspiler {
|
|
|
20
20
|
if (!(node.get() instanceof abaplint.Statements.Loop)) {
|
|
21
21
|
throw new Error("LoopTranspiler, unexpected node");
|
|
22
22
|
}
|
|
23
|
-
const
|
|
23
|
+
const loopSource = node.findDirectExpression(abaplint.Expressions.LoopSource)?.getFirstChild();
|
|
24
|
+
const source = traversal.traverse(loopSource).getCode();
|
|
24
25
|
this.unique = unique_identifier_1.UniqueIdentifier.get();
|
|
25
26
|
let target = "";
|
|
26
27
|
const into = node.findDirectExpression(abaplint.Expressions.LoopTarget)?.findDirectExpression(abaplint.Expressions.Target);
|
|
@@ -41,7 +41,7 @@ class MessageTranspiler {
|
|
|
41
41
|
}
|
|
42
42
|
else {
|
|
43
43
|
// exception or constant based
|
|
44
|
-
const exception = node.findDirectExpression(abaplint.Expressions.
|
|
44
|
+
const exception = node.findDirectExpression(abaplint.Expressions.MessageSourceSource)?.findDirectExpression(abaplint.Expressions.Source);
|
|
45
45
|
const str = exception?.findFirstExpression(abaplint.Expressions.Constant);
|
|
46
46
|
if (str) {
|
|
47
47
|
options.push("text: " + traversal.traverse(str).getCode());
|
|
@@ -64,11 +64,10 @@ class MessageTranspiler {
|
|
|
64
64
|
if (c.getFirstToken().getStr().toUpperCase() === "WITH") {
|
|
65
65
|
withs = true;
|
|
66
66
|
}
|
|
67
|
-
else if (withs === true
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
w.push(traversal.traverse(c).getCode());
|
|
67
|
+
else if (withs === true
|
|
68
|
+
&& c.get() instanceof abaplint.Expressions.MessageSourceSource
|
|
69
|
+
&& c instanceof abaplint.Nodes.ExpressionNode) {
|
|
70
|
+
w.push(traversal.traverse(c.getFirstChild()).getCode());
|
|
72
71
|
}
|
|
73
72
|
else if (withs === true) {
|
|
74
73
|
break;
|
|
@@ -12,21 +12,63 @@ class MoveTranspiler {
|
|
|
12
12
|
}
|
|
13
13
|
const ret = new chunk_1.Chunk();
|
|
14
14
|
const second = node.getChildren()[1]?.concatTokens();
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
.append(");", node.getLastToken(), traversal);
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
for (const target of targets.reverse()) {
|
|
24
|
-
ret.appendChunk(target)
|
|
25
|
-
.appendString(".set(")
|
|
15
|
+
switch (second) {
|
|
16
|
+
case "?=":
|
|
17
|
+
ret.appendString("await abap.statements.cast(")
|
|
18
|
+
.appendChunk(targets[0])
|
|
19
|
+
.appendString(", ")
|
|
26
20
|
.appendChunk(source)
|
|
27
21
|
.append(");", node.getLastToken(), traversal);
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
break;
|
|
23
|
+
case "+":
|
|
24
|
+
ret.appendChunk(targets[0])
|
|
25
|
+
.appendString(".set(abap.operators.add(")
|
|
26
|
+
.appendChunk(targets[0])
|
|
27
|
+
.appendString(", ")
|
|
28
|
+
.appendChunk(source)
|
|
29
|
+
.append("));", node.getLastToken(), traversal);
|
|
30
|
+
break;
|
|
31
|
+
case "-":
|
|
32
|
+
ret.appendChunk(targets[0])
|
|
33
|
+
.appendString(".set(abap.operators.minus(")
|
|
34
|
+
.appendChunk(targets[0])
|
|
35
|
+
.appendString(", ")
|
|
36
|
+
.appendChunk(source)
|
|
37
|
+
.append("));", node.getLastToken(), traversal);
|
|
38
|
+
break;
|
|
39
|
+
case "/=":
|
|
40
|
+
ret.appendChunk(targets[0])
|
|
41
|
+
.appendString(".set(abap.operators.divide(")
|
|
42
|
+
.appendChunk(targets[0])
|
|
43
|
+
.appendString(", ")
|
|
44
|
+
.appendChunk(source)
|
|
45
|
+
.append("));", node.getLastToken(), traversal);
|
|
46
|
+
break;
|
|
47
|
+
case "*=":
|
|
48
|
+
ret.appendChunk(targets[0])
|
|
49
|
+
.appendString(".set(abap.operators.multiply(")
|
|
50
|
+
.appendChunk(targets[0])
|
|
51
|
+
.appendString(", ")
|
|
52
|
+
.appendChunk(source)
|
|
53
|
+
.append("));", node.getLastToken(), traversal);
|
|
54
|
+
break;
|
|
55
|
+
case "&&=":
|
|
56
|
+
ret.appendChunk(targets[0])
|
|
57
|
+
.appendString(".set(abap.operators.concat(")
|
|
58
|
+
.appendChunk(targets[0])
|
|
59
|
+
.appendString(", ")
|
|
60
|
+
.appendChunk(source)
|
|
61
|
+
.append("));", node.getLastToken(), traversal);
|
|
62
|
+
break;
|
|
63
|
+
default:
|
|
64
|
+
for (const target of targets.reverse()) {
|
|
65
|
+
ret.appendChunk(target)
|
|
66
|
+
.appendString(".set(")
|
|
67
|
+
.appendChunk(source)
|
|
68
|
+
.append(");", node.getLastToken(), traversal);
|
|
69
|
+
source = target;
|
|
70
|
+
}
|
|
71
|
+
break;
|
|
30
72
|
}
|
|
31
73
|
return ret;
|
|
32
74
|
}
|
|
@@ -82,24 +82,8 @@ class TranspileTypes {
|
|
|
82
82
|
const list = [];
|
|
83
83
|
const suffix = {};
|
|
84
84
|
const asInclude = {};
|
|
85
|
-
/*
|
|
86
|
-
const skipFields: Set<string> = new Set();
|
|
87
|
-
|
|
88
|
-
for (const c of type.getComponents()) {
|
|
89
|
-
if (c.type instanceof abaplint.BasicTypes.StructureType) {
|
|
90
|
-
for (const f of c.type.getComponents()) {
|
|
91
|
-
skipFields.add(f.name.toLowerCase());
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
*/
|
|
96
85
|
for (const c of type.getComponents()) {
|
|
97
86
|
const lower = c.name.toLowerCase();
|
|
98
|
-
/*
|
|
99
|
-
if (skipFields.has(lower)) {
|
|
100
|
-
continue; // skip fields from nested structures
|
|
101
|
-
}
|
|
102
|
-
*/
|
|
103
87
|
list.push(`"` + lower + `": ` + this.toType(c.type));
|
|
104
88
|
if (c.suffix) {
|
|
105
89
|
suffix[lower] = c.suffix;
|
package/build/src/traversal.d.ts
CHANGED
|
@@ -39,6 +39,8 @@ export declare class Traversal {
|
|
|
39
39
|
isTypePool(token: abaplint.Token): string | undefined;
|
|
40
40
|
isInterfaceAttribute(token: abaplint.Token): string | undefined;
|
|
41
41
|
private findReadOrWriteReference;
|
|
42
|
+
private findInferredTypeReference;
|
|
43
|
+
private findTypeReference;
|
|
42
44
|
private buildThisAttributes;
|
|
43
45
|
private buildFriendsAccess;
|
|
44
46
|
buildConstructorContents(scope: abaplint.ISpaghettiScopeNode | undefined, def: abaplint.IClassDefinition): string;
|
|
@@ -48,6 +50,8 @@ export declare class Traversal {
|
|
|
48
50
|
findClassDefinition(name: string | undefined, scope: abaplint.ISpaghettiScopeNode | undefined): abaplint.IClassDefinition | undefined;
|
|
49
51
|
private dataFromInterfaces;
|
|
50
52
|
private aliasesFromInterfaces;
|
|
53
|
+
lookupType(node: abaplint.Nodes.ExpressionNode, scope: abaplint.ISpaghettiScopeNode | undefined): abaplint.AbstractType | undefined;
|
|
54
|
+
lookupInferred(node: abaplint.Nodes.ExpressionNode, scope: abaplint.ISpaghettiScopeNode | undefined): abaplint.AbstractType | undefined;
|
|
51
55
|
determineType(node: abaplint.Nodes.ExpressionNode | abaplint.Nodes.StatementNode, scope: abaplint.ISpaghettiScopeNode | undefined): abaplint.AbstractType | undefined;
|
|
52
56
|
isInsideLoop(node: abaplint.Nodes.StatementNode): boolean;
|
|
53
57
|
isInsideDoOrWhile(node: abaplint.Nodes.StatementNode): boolean;
|
package/build/src/traversal.js
CHANGED
|
@@ -402,6 +402,36 @@ class Traversal {
|
|
|
402
402
|
}
|
|
403
403
|
return undefined;
|
|
404
404
|
}
|
|
405
|
+
findInferredTypeReference(token) {
|
|
406
|
+
const scope = this.findCurrentScopeByToken(token);
|
|
407
|
+
if (scope === undefined) {
|
|
408
|
+
return undefined;
|
|
409
|
+
}
|
|
410
|
+
for (const r of scope.getData().references) {
|
|
411
|
+
if (r.referenceType === abaplint.ReferenceType.InferredType
|
|
412
|
+
&& r.position.getStart().equals(token.getStart())) {
|
|
413
|
+
if (r.resolved instanceof abaplint.TypedIdentifier) {
|
|
414
|
+
return r.resolved.getType();
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return undefined;
|
|
419
|
+
}
|
|
420
|
+
findTypeReference(token) {
|
|
421
|
+
const scope = this.findCurrentScopeByToken(token);
|
|
422
|
+
if (scope === undefined) {
|
|
423
|
+
return undefined;
|
|
424
|
+
}
|
|
425
|
+
for (const r of scope.getData().references) {
|
|
426
|
+
if (r.referenceType === abaplint.ReferenceType.TypeReference
|
|
427
|
+
&& r.position.getStart().equals(token.getStart())) {
|
|
428
|
+
if (r.resolved instanceof abaplint.TypedIdentifier) {
|
|
429
|
+
return r.resolved.getType();
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
return undefined;
|
|
434
|
+
}
|
|
405
435
|
buildThisAttributes(def, cName) {
|
|
406
436
|
let ret = "";
|
|
407
437
|
for (const a of def.getAttributes()?.getAll() || []) {
|
|
@@ -574,6 +604,50 @@ this.INTERNAL_ID = abap.internalIdCounter++;\n`;
|
|
|
574
604
|
}
|
|
575
605
|
return ret;
|
|
576
606
|
}
|
|
607
|
+
lookupType(node, scope) {
|
|
608
|
+
if (scope === undefined) {
|
|
609
|
+
return undefined;
|
|
610
|
+
}
|
|
611
|
+
else if (!(node.get() instanceof abaplint.Expressions.TypeName)) {
|
|
612
|
+
throw new Error("lookupType, node is not a TypeName, " + node.get());
|
|
613
|
+
}
|
|
614
|
+
const name = node.concatTokens().toLowerCase();
|
|
615
|
+
switch (name) {
|
|
616
|
+
case "i":
|
|
617
|
+
return abaplint.BasicTypes.IntegerType.get();
|
|
618
|
+
case "f":
|
|
619
|
+
return new abaplint.BasicTypes.FloatType();
|
|
620
|
+
case "string":
|
|
621
|
+
return abaplint.BasicTypes.StringType.get();
|
|
622
|
+
case "xstring":
|
|
623
|
+
return abaplint.BasicTypes.XStringType.get();
|
|
624
|
+
case "d":
|
|
625
|
+
return new abaplint.BasicTypes.DateType();
|
|
626
|
+
case "t":
|
|
627
|
+
return new abaplint.BasicTypes.TimeType();
|
|
628
|
+
default:
|
|
629
|
+
break;
|
|
630
|
+
}
|
|
631
|
+
const found = this.findTypeReference(node.getFirstToken());
|
|
632
|
+
if (found !== undefined) {
|
|
633
|
+
return found;
|
|
634
|
+
}
|
|
635
|
+
const dtel = this.reg.getObject("DTEL", name);
|
|
636
|
+
if (dtel) {
|
|
637
|
+
return dtel.parseType(this.reg);
|
|
638
|
+
}
|
|
639
|
+
// todo: yea, well, yea
|
|
640
|
+
throw new Error("lookupType, type not found, " + node.concatTokens());
|
|
641
|
+
}
|
|
642
|
+
lookupInferred(node, scope) {
|
|
643
|
+
if (scope === undefined) {
|
|
644
|
+
return undefined;
|
|
645
|
+
}
|
|
646
|
+
else if (node.concatTokens() !== "#") {
|
|
647
|
+
throw new Error("lookupInferred, unexpected, " + node.get());
|
|
648
|
+
}
|
|
649
|
+
return this.findInferredTypeReference(node.getFirstToken());
|
|
650
|
+
}
|
|
577
651
|
determineType(node, scope) {
|
|
578
652
|
if (scope === undefined) {
|
|
579
653
|
return undefined;
|
package/build/src/types.d.ts
CHANGED
package/build/src/validation.js
CHANGED
|
@@ -121,6 +121,13 @@ class Validation {
|
|
|
121
121
|
// this is not a constant, just a regex that happens to not match anything
|
|
122
122
|
exports.config.syntax.errorNamespace = "VOID_EVERYTHING";
|
|
123
123
|
}
|
|
124
|
+
if (this.options?.skipVersionCheck === true) {
|
|
125
|
+
// todo, set it to abaplint default version
|
|
126
|
+
exports.config.syntax.version = core_1.Version.v758;
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
exports.config.syntax.version = core_1.Version.OpenABAP;
|
|
130
|
+
}
|
|
124
131
|
const conf = new core_1.Config(JSON.stringify(exports.config));
|
|
125
132
|
reg.setConfig(conf);
|
|
126
133
|
const issues = reg.findIssues();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abaplint/transpiler",
|
|
3
|
-
"version": "2.11.
|
|
3
|
+
"version": "2.11.10",
|
|
4
4
|
"description": "Transpiler",
|
|
5
5
|
"main": "build/src/index.js",
|
|
6
6
|
"typings": "build/src/index.d.ts",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"author": "abaplint",
|
|
30
30
|
"license": "MIT",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@abaplint/core": "^2.113.
|
|
32
|
+
"@abaplint/core": "^2.113.155",
|
|
33
33
|
"source-map": "^0.7.6"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|