@abaplint/transpiler 2.1.86 → 2.1.88

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.
@@ -40,6 +40,12 @@ class CompareOperatorTranspiler {
40
40
  return new chunk_1.Chunk().append("na", node, traversal);
41
41
  case "NP":
42
42
  return new chunk_1.Chunk().append("np", node, traversal);
43
+ case "O":
44
+ return new chunk_1.Chunk().append("o", node, traversal);
45
+ case "Z":
46
+ return new chunk_1.Chunk().append("z", node, traversal);
47
+ case "M":
48
+ return new chunk_1.Chunk().append("m", node, traversal);
43
49
  default:
44
50
  return new chunk_1.Chunk().append("compareoperatortodo" + op, node, traversal);
45
51
  }
@@ -6,4 +6,6 @@ export declare class SQLCondTranspiler implements IExpressionTranspiler {
6
6
  transpile(node: Nodes.ExpressionNode, traversal: Traversal): Chunk;
7
7
  private sqlIn;
8
8
  private basicCondition;
9
+ private sqlSource;
10
+ private basicConditionNew;
9
11
  }
@@ -55,15 +55,29 @@ class SQLCondTranspiler {
55
55
  basicCondition(c, traversal) {
56
56
  let ret = "";
57
57
  if (c.getChildren().length !== 3) {
58
- throw new Error("SQL Condition, transpiler todo, " + c.concatTokens() + ", " + c.getChildren().length);
58
+ return this.basicConditionNew(c, traversal);
59
+ // throw new Error("SQL Condition, transpiler todo1, " + c.concatTokens() + ", " + c.getChildren().length);
59
60
  }
60
61
  const fieldName = c.findDirectExpression(abaplint.Expressions.SQLFieldName);
61
62
  const operator = c.findDirectExpression(abaplint.Expressions.SQLCompareOperator);
62
63
  const source = c.findDirectExpression(abaplint.Expressions.SQLSource);
63
64
  if (fieldName === undefined || operator === undefined || source === undefined) {
64
- throw new Error("SQL Condition, transpiler todo, " + c.concatTokens());
65
+ throw new Error("SQL Condition, transpiler todo2, " + c.concatTokens());
65
66
  }
66
67
  ret += fieldName.concatTokens() + " " + operator.concatTokens() + " ";
68
+ ret += this.sqlSource(source, traversal);
69
+ /*
70
+ const simple = source.findDirectExpression(abaplint.Expressions.SimpleSource3);
71
+ if (simple && simple.findDirectExpression(abaplint.Expressions.Constant) === undefined) {
72
+ ret += "'\" + " + new SimpleSource3Transpiler(true).transpile(simple, traversal).getCode() + " + \"'";
73
+ } else {
74
+ ret += source.concatTokens();
75
+ }
76
+ */
77
+ return ret;
78
+ }
79
+ sqlSource(source, traversal) {
80
+ let ret = "";
67
81
  const simple = source.findDirectExpression(abaplint.Expressions.SimpleSource3);
68
82
  if (simple && simple.findDirectExpression(abaplint.Expressions.Constant) === undefined) {
69
83
  ret += "'\" + " + new simple_source3_1.SimpleSource3Transpiler(true).transpile(simple, traversal).getCode() + " + \"'";
@@ -73,6 +87,25 @@ class SQLCondTranspiler {
73
87
  }
74
88
  return ret;
75
89
  }
90
+ basicConditionNew(node, traversal) {
91
+ let ret = "";
92
+ for (const child of node.getChildren()) {
93
+ if (ret !== "") {
94
+ ret += " ";
95
+ }
96
+ if (child.get() instanceof abaplint.Expressions.SQLFieldName) {
97
+ ret += child.concatTokens();
98
+ }
99
+ else if (child.get() instanceof abaplint.Expressions.SQLSource
100
+ && child instanceof abaplint.Nodes.ExpressionNode) {
101
+ ret += this.sqlSource(child, traversal);
102
+ }
103
+ else {
104
+ ret += child.concatTokens();
105
+ }
106
+ }
107
+ return ret;
108
+ }
76
109
  }
77
110
  exports.SQLCondTranspiler = SQLCondTranspiler;
78
111
  //# sourceMappingURL=sql_cond.js.map
@@ -4,5 +4,4 @@ import { Traversal } from "../traversal";
4
4
  import { Chunk } from "../chunk";
5
5
  export declare class CheckTranspiler implements IStatementTranspiler {
6
6
  transpile(node: abaplint.Nodes.StatementNode, traversal: Traversal): Chunk;
7
- private isInsideLoop;
8
7
  }
@@ -11,7 +11,7 @@ class CheckTranspiler {
11
11
  ret.append("if (!(", node, traversal);
12
12
  ret.appendChunk(cond);
13
13
  ret.appendString(")) {\n");
14
- if (this.isInsideLoop(node, traversal)) {
14
+ if (traversal.isInsideLoop(node)) {
15
15
  ret.appendString("continue;");
16
16
  }
17
17
  else {
@@ -20,28 +20,6 @@ class CheckTranspiler {
20
20
  ret.append("\n}", node.getLastToken(), traversal);
21
21
  return ret;
22
22
  }
23
- isInsideLoop(node, traversal) {
24
- const stack = [];
25
- for (const statement of traversal.getFile().getStatements()) {
26
- const get = statement.get();
27
- if (get instanceof abaplint.Statements.Loop
28
- || get instanceof abaplint.Statements.While
29
- || get instanceof abaplint.Statements.SelectLoop
30
- || get instanceof abaplint.Statements.Do) {
31
- stack.push(statement);
32
- }
33
- else if (get instanceof abaplint.Statements.EndLoop
34
- || get instanceof abaplint.Statements.EndWhile
35
- || get instanceof abaplint.Statements.EndSelect
36
- || get instanceof abaplint.Statements.EndDo) {
37
- stack.pop();
38
- }
39
- if (statement === node) {
40
- break;
41
- }
42
- }
43
- return stack.length > 0;
44
- }
45
23
  }
46
24
  exports.CheckTranspiler = CheckTranspiler;
47
25
  //# sourceMappingURL=check.js.map
@@ -2,9 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ExitTranspiler = void 0;
4
4
  const chunk_1 = require("../chunk");
5
+ const return_1 = require("./return");
5
6
  class ExitTranspiler {
6
7
  transpile(node, traversal) {
7
- return new chunk_1.Chunk().append("break;", node, traversal);
8
+ if (traversal.isInsideLoop(node)) {
9
+ return new chunk_1.Chunk().append("break;", node, traversal);
10
+ }
11
+ else {
12
+ return new return_1.ReturnTranspiler().transpile(node, traversal);
13
+ }
8
14
  }
9
15
  }
10
16
  exports.ExitTranspiler = ExitTranspiler;
@@ -37,6 +37,7 @@ export declare class Traversal {
37
37
  findClassDefinition(name: string, scope: abaplint.ISpaghettiScopeNode | undefined): abaplint.IClassDefinition | undefined;
38
38
  private dataFromInterfaces;
39
39
  determineType(node: abaplint.Nodes.ExpressionNode | abaplint.Nodes.StatementNode, scope: abaplint.ISpaghettiScopeNode | undefined): abaplint.AbstractType | undefined;
40
+ isInsideLoop(node: abaplint.Nodes.StatementNode): boolean;
40
41
  registerClassOrInterface(def: abaplint.IClassDefinition | abaplint.IInterfaceDefinition | undefined): string;
41
42
  lookupClassOrInterface(name: string | undefined, token: abaplint.Token | undefined, directGlobal?: boolean): string;
42
43
  private buildPrefix;
@@ -271,7 +271,7 @@ class Traversal {
271
271
  }
272
272
  // handle aliases after initialization of carrier variables
273
273
  for (const a of def.getAliases().getAll()) {
274
- ret += "this." + a.getName().toLowerCase() + " = this." + a.getComponent().replace("~", "$").toLowerCase() + ";\n";
274
+ ret += "this." + a.getName().toLowerCase() + " = this." + Traversal.escapeClassName(a.getComponent().replace("~", "$").toLowerCase()) + ";\n";
275
275
  }
276
276
  // constants can be accessed both statically and via reference
277
277
  for (const c of def.getAttributes().getConstants()) {
@@ -350,7 +350,28 @@ class Traversal {
350
350
  }
351
351
  return context;
352
352
  }
353
- ////////////////////////////
353
+ isInsideLoop(node) {
354
+ const stack = [];
355
+ for (const statement of this.getFile().getStatements()) {
356
+ const get = statement.get();
357
+ if (get instanceof abaplint.Statements.Loop
358
+ || get instanceof abaplint.Statements.While
359
+ || get instanceof abaplint.Statements.SelectLoop
360
+ || get instanceof abaplint.Statements.Do) {
361
+ stack.push(statement);
362
+ }
363
+ else if (get instanceof abaplint.Statements.EndLoop
364
+ || get instanceof abaplint.Statements.EndWhile
365
+ || get instanceof abaplint.Statements.EndSelect
366
+ || get instanceof abaplint.Statements.EndDo) {
367
+ stack.pop();
368
+ }
369
+ if (statement === node) {
370
+ break;
371
+ }
372
+ }
373
+ return stack.length > 0;
374
+ }
354
375
  registerClassOrInterface(def) {
355
376
  if (def === undefined) {
356
377
  return "";
@@ -30,10 +30,12 @@ exports.config = {
30
30
  "allowed_object_types": {
31
31
  "allowed": ["INTF", "CLAS", "PROG", "DEVC", "TABL", "SHLP", "XSLT", "SHMA", "SICF", "NROB", "TYPE", "DTEL", "DOMA", "TTYP", "MSAG", "FUGR"],
32
32
  },
33
- "exit_or_check": {
34
- "allowCheck": true,
35
- "allowExit": false,
36
- },
33
+ /*
34
+ "exit_or_check": {
35
+ "allowCheck": true,
36
+ "allowExit": false,
37
+ },
38
+ */
37
39
  "unknown_types": true,
38
40
  "ambiguous_statement": true,
39
41
  "implement_methods": true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler",
3
- "version": "2.1.86",
3
+ "version": "2.1.88",
4
4
  "description": "Transpiler",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",