@abaplint/transpiler 2.1.85 → 2.1.87

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.
@@ -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 "";
@@ -11,4 +11,5 @@ export declare class UnitTest {
11
11
  unitTestScriptOpen(reg: abaplint.IRegistry, _skip?: TestMethodList, _only?: TestMethodList): string;
12
12
  unitTestScript(reg: abaplint.IRegistry, skip?: TestMethodList, _only?: TestMethodList): string;
13
13
  private buildImports;
14
+ private hasClassConstructor;
14
15
  }
@@ -181,7 +181,6 @@ run().then(() => {
181
181
  buildImports(reg, useImport) {
182
182
  // note: ES modules are hoised, so use the dynamic import(), due to setting of globalThis.abap
183
183
  // some sorting required: eg. a class constructor using constant from interface
184
- var _a;
185
184
  const list = [];
186
185
  const late = [];
187
186
  const imp = (filename) => {
@@ -207,7 +206,7 @@ run().then(() => {
207
206
  }
208
207
  else if (obj instanceof abaplint.Objects.Class) {
209
208
  if (obj.getName().toUpperCase() !== "CL_ABAP_CHAR_UTILITIES"
210
- && ((_a = obj.getDefinition()) === null || _a === void 0 ? void 0 : _a.getMethodDefinitions().getByName("CLASS_CONSTRUCTOR")) !== undefined) {
209
+ && this.hasClassConstructor(reg, obj)) {
211
210
  // this will not solve all problems with class constors 100%, but probably good enough
212
211
  late.push(imp(`${this.escapeNamespace(obj.getName().toLowerCase())}.${obj.getType().toLowerCase()}`));
213
212
  }
@@ -221,6 +220,22 @@ run().then(() => {
221
220
  }
222
221
  return [...list.sort(), ...late].join("\n");
223
222
  }
223
+ // class constructors might make early use of eg. constants from interfaces
224
+ // sub classes will import() super classes and trigger a class constructor of the super
225
+ hasClassConstructor(reg, clas) {
226
+ var _a, _b;
227
+ if (((_a = clas.getDefinition()) === null || _a === void 0 ? void 0 : _a.getMethodDefinitions().getByName("CLASS_CONSTRUCTOR")) !== undefined) {
228
+ return true;
229
+ }
230
+ const sup = (_b = clas.getDefinition()) === null || _b === void 0 ? void 0 : _b.getSuperClass();
231
+ if (sup !== undefined) {
232
+ const superClass = reg.getObject("CLAS", sup);
233
+ if (superClass) {
234
+ return this.hasClassConstructor(reg, superClass);
235
+ }
236
+ }
237
+ return false;
238
+ }
224
239
  }
225
240
  exports.UnitTest = UnitTest;
226
241
  //# sourceMappingURL=unit_test.js.map
@@ -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.85",
3
+ "version": "2.1.87",
4
4
  "description": "Transpiler",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",