@abaplint/runtime 2.7.113 → 2.7.115

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.
@@ -15,6 +15,7 @@ import { ClassicError } from "./classic_error";
15
15
  import { Console } from "./console/console";
16
16
  import { MemoryConsole } from "./console/memory_console";
17
17
  import { buildDbTableName } from "./prefix";
18
+ import { IntegerFactory } from "./integer_factory";
18
19
  export { UnitTestResult, RFC, types, DB, MemoryConsole };
19
20
  export type RuntimeDatabaseOptions = {
20
21
  schemaPrefix?: string;
@@ -61,6 +62,7 @@ export declare class ABAP {
61
62
  expandDynamic: typeof expandDynamic;
62
63
  buildDbTableName: typeof buildDbTableName;
63
64
  ClassicError: typeof ClassicError;
65
+ IntegerFactory: typeof IntegerFactory;
64
66
  readonly context: Context;
65
67
  readonly dbo: RuntimeDatabaseOptions;
66
68
  constructor(input?: RuntimeOptions);
@@ -23,6 +23,7 @@ const standard_out_console_1 = require("./console/standard_out_console");
23
23
  const memory_console_1 = require("./console/memory_console");
24
24
  Object.defineProperty(exports, "MemoryConsole", { enumerable: true, get: function () { return memory_console_1.MemoryConsole; } });
25
25
  const prefix_1 = require("./prefix");
26
+ const integer_factory_1 = require("./integer_factory");
26
27
  class ABAP {
27
28
  constructor(input) {
28
29
  // global objects
@@ -44,6 +45,7 @@ class ABAP {
44
45
  this.expandDynamic = expand_dynamic_1.expandDynamic;
45
46
  this.buildDbTableName = prefix_1.buildDbTableName;
46
47
  this.ClassicError = classic_error_1.ClassicError;
48
+ this.IntegerFactory = integer_factory_1.IntegerFactory;
47
49
  this.context = new context_1.Context();
48
50
  this.console = (input === null || input === void 0 ? void 0 : input.console) ? input === null || input === void 0 ? void 0 : input.console : new standard_out_console_1.StandardOutConsole();
49
51
  this.context.console = this.console;
@@ -0,0 +1,5 @@
1
+ import { Integer } from "./types";
2
+ export declare class IntegerFactory {
3
+ private static readonly map;
4
+ static get(num: number): Integer;
5
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IntegerFactory = void 0;
4
+ const types_1 = require("./types");
5
+ class IntegerFactory {
6
+ static get(num) {
7
+ if (IntegerFactory.map[num] === undefined) {
8
+ IntegerFactory.map[num] = new types_1.Integer().set(num).setConstant();
9
+ }
10
+ return IntegerFactory.map[num];
11
+ }
12
+ }
13
+ exports.IntegerFactory = IntegerFactory;
14
+ IntegerFactory.map = {};
15
+ //# sourceMappingURL=integer_factory.js.map
@@ -5,18 +5,6 @@ const types_1 = require("../types");
5
5
  const string_1 = require("../types/string");
6
6
  const _parse_1 = require("./_parse");
7
7
  function add(left, right) {
8
- if (left instanceof types_1.FieldSymbol) {
9
- if (left.getPointer() === undefined) {
10
- throw new Error("GETWA_NOT_ASSIGNED");
11
- }
12
- return add(left.getPointer(), right);
13
- }
14
- if (right instanceof types_1.FieldSymbol) {
15
- if (right.getPointer() === undefined) {
16
- throw new Error("GETWA_NOT_ASSIGNED");
17
- }
18
- return add(left, right.getPointer());
19
- }
20
8
  if (left instanceof types_1.Integer && right instanceof types_1.Integer) {
21
9
  return new types_1.Integer().set(left.get() + right.get());
22
10
  }
@@ -36,6 +24,18 @@ function add(left, right) {
36
24
  else if ((right instanceof string_1.String || right instanceof types_1.Character) && Number.isInteger(Number(right)) && left instanceof types_1.Integer) {
37
25
  return new types_1.Integer().set(left.get() + Number.parseInt(right.get(), 10));
38
26
  }
27
+ if (left instanceof types_1.FieldSymbol) {
28
+ if (left.getPointer() === undefined) {
29
+ throw new Error("GETWA_NOT_ASSIGNED");
30
+ }
31
+ return add(left.getPointer(), right);
32
+ }
33
+ if (right instanceof types_1.FieldSymbol) {
34
+ if (right.getPointer() === undefined) {
35
+ throw new Error("GETWA_NOT_ASSIGNED");
36
+ }
37
+ return add(left, right.getPointer());
38
+ }
39
39
  const ret = new types_1.Float().set((0, _parse_1.parse)(left) + (0, _parse_1.parse)(right));
40
40
  return ret;
41
41
  }
@@ -80,11 +80,9 @@ class Hex {
80
80
  }
81
81
  let ret = this.value;
82
82
  if (offset) {
83
- // @ts-ignore
84
83
  ret = ret.substr(offset * 2);
85
84
  }
86
85
  if (length !== undefined) {
87
- // @ts-ignore
88
86
  ret = ret.substr(0, length * 2);
89
87
  }
90
88
  const r = new xstring_1.XString();
@@ -4,11 +4,13 @@ import { ICharacter } from "./_character";
4
4
  import { INumeric } from "./_numeric";
5
5
  export declare class Integer implements INumeric {
6
6
  private value;
7
+ private constant;
7
8
  private readonly qualifiedName;
8
9
  constructor(input?: {
9
10
  qualifiedName?: string;
10
11
  });
11
12
  getQualifiedName(): string | undefined;
13
+ setConstant(): this;
12
14
  set(value: INumeric | ICharacter | Hex | string | number | Integer | Float): this;
13
15
  clear(): void;
14
16
  get(): number;
@@ -8,13 +8,21 @@ const xstring_1 = require("./xstring");
8
8
  const digits = new RegExp(/^\s*-?\+?\d+\.?\d* *$/i);
9
9
  class Integer {
10
10
  constructor(input) {
11
+ this.constant = false;
11
12
  this.value = 0;
12
13
  this.qualifiedName = input === null || input === void 0 ? void 0 : input.qualifiedName;
13
14
  }
14
15
  getQualifiedName() {
15
16
  return this.qualifiedName;
16
17
  }
18
+ setConstant() {
19
+ this.constant = true;
20
+ return this;
21
+ }
17
22
  set(value) {
23
+ if (this.constant === true) {
24
+ throw new Error("Changing constant");
25
+ }
18
26
  if (typeof value === "number") {
19
27
  this.value = Math.round(value);
20
28
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/runtime",
3
- "version": "2.7.113",
3
+ "version": "2.7.115",
4
4
  "description": "Transpiler - Runtime",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",