@abaplint/runtime 2.8.11 → 2.8.13

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.
@@ -1,4 +1,4 @@
1
- import { Character, Hex, Structure, XString } from "./types";
1
+ import { Character, FieldSymbol, Hex, Structure, XString } from "./types";
2
2
  import { ICharacter } from "./types/_character";
3
3
  import { INumeric } from "./types/_numeric";
4
4
  export interface IOffsetLengthOptions {
@@ -10,7 +10,7 @@ export declare class OffsetLength {
10
10
  private readonly offset?;
11
11
  private readonly length?;
12
12
  private readonly isHex;
13
- constructor(obj: ICharacter | Character | Hex | XString | Structure, options: IOffsetLengthOptions);
13
+ constructor(obj: ICharacter | Character | Hex | XString | Structure | FieldSymbol, options: IOffsetLengthOptions);
14
14
  get(): string;
15
- set(value: ICharacter | string): void;
15
+ set(value: ICharacter | string | Hex | XString): void;
16
16
  }
@@ -5,7 +5,13 @@ const types_1 = require("./types");
5
5
  class OffsetLength {
6
6
  constructor(obj, options) {
7
7
  this.obj = obj;
8
- this.isHex = obj instanceof types_1.Hex || obj instanceof types_1.XString;
8
+ if (this.obj instanceof types_1.FieldSymbol) {
9
+ this.obj = this.obj.getPointer();
10
+ if (this.obj === undefined) {
11
+ throw new Error("GETWA_NOT_ASSIGNED");
12
+ }
13
+ }
14
+ this.isHex = this.obj instanceof types_1.Hex || this.obj instanceof types_1.XString;
9
15
  if (options.offset) {
10
16
  if (typeof options.offset === "number") {
11
17
  this.offset = options.offset;
@@ -56,16 +62,12 @@ class OffsetLength {
56
62
  else if (value instanceof types_1.Integer) {
57
63
  val = value.get() + "";
58
64
  if (this.isHex) {
59
- val = Number(val).toString(16);
65
+ val = Number(val).toString(16).toUpperCase();
60
66
  }
61
67
  }
62
68
  else {
63
69
  val = value.get() + "";
64
70
  }
65
- let old = this.obj instanceof types_1.Structure ? this.obj.getCharacter() : this.obj.get();
66
- if (this.obj instanceof types_1.Character) {
67
- old = old.padEnd(this.obj.getLength(), " ");
68
- }
69
71
  if (this.length) {
70
72
  val = val.substr(0, this.length);
71
73
  if (this.isHex || this.obj instanceof types_1.Time) {
@@ -75,6 +77,7 @@ class OffsetLength {
75
77
  val = val.padEnd(this.length, " ");
76
78
  }
77
79
  }
80
+ let old = this.obj instanceof types_1.Structure ? this.obj.getCharacter() : this.obj.get();
78
81
  if (this.length && this.offset) {
79
82
  old = old.substr(0, this.offset) + val + old.substr(this.offset + this.length);
80
83
  }
@@ -84,10 +87,6 @@ class OffsetLength {
84
87
  else if (this.offset) {
85
88
  old = old.substr(0, this.offset) + val;
86
89
  }
87
- old = old.trimEnd();
88
- if (this.obj instanceof types_1.Character) {
89
- old = old.padEnd(this.obj.getLength(), " ");
90
- }
91
90
  this.obj.set(old);
92
91
  }
93
92
  }
@@ -5,12 +5,8 @@ function setBit(number, hex, val) {
5
5
  if (number.get() <= 0) {
6
6
  throw new Error("BIT_OFFSET_NOT_POSITIVE");
7
7
  }
8
- let hexFull = hex.get();
9
- if (hexFull === "") {
10
- hexFull = "00";
11
- }
8
+ const hexFull = hex.get();
12
9
  const fullByteLength = Math.ceil(hexFull.length / 2);
13
- hexFull = hexFull.padEnd(fullByteLength * 2, "0");
14
10
  const byteNum = Math.ceil(number.get() / 8);
15
11
  if (byteNum > fullByteLength) {
16
12
  return;
@@ -13,7 +13,7 @@ export declare class Hex implements ICharacter {
13
13
  qualifiedName?: string;
14
14
  });
15
15
  getQualifiedName(): string | undefined;
16
- set(value: ICharacter | INumeric | string | number | Integer | Integer8 | Float): Hex;
16
+ set(value: ICharacter | INumeric | string | number | Integer | Integer8 | Float | Hex | XString): Hex;
17
17
  getLength(): number;
18
18
  clear(): void;
19
19
  get(): string;
@@ -6,6 +6,7 @@ const float_1 = require("./float");
6
6
  const xstring_1 = require("./xstring");
7
7
  const throw_error_1 = require("../throw_error");
8
8
  const integer8_1 = require("./integer8");
9
+ const REGEXP = /^(?![A-F0-9])/;
9
10
  class Hex {
10
11
  constructor(input) {
11
12
  this.length = input?.length ? input?.length : 1;
@@ -16,6 +17,7 @@ class Hex {
16
17
  return this.qualifiedName;
17
18
  }
18
19
  set(value) {
20
+ const doubleLength = this.length * 2;
19
21
  if (typeof value === "string") {
20
22
  this.value = value;
21
23
  }
@@ -23,57 +25,56 @@ class Hex {
23
25
  const maxVal = Math.pow(2, this.length * 8);
24
26
  if (value < 0) {
25
27
  let hex = Math.round(value + 0x100000000).toString(16).toUpperCase();
26
- if (hex.length > this.length * 2) {
27
- hex = hex.substring(hex.length - this.length * 2);
28
+ if (hex.length > doubleLength) {
29
+ hex = hex.substring(hex.length - doubleLength);
28
30
  }
29
31
  this.value = hex;
30
32
  }
31
33
  else if (value >= maxVal) {
32
34
  const sub = value % maxVal;
33
- this.value = Math.round(sub).toString(16);
35
+ this.value = Math.round(sub).toString(16).toUpperCase();
34
36
  }
35
37
  else {
36
- this.value = Math.round(value).toString(16);
38
+ this.value = Math.round(value).toString(16).toUpperCase();
37
39
  }
38
- this.value = this.value.padStart(this.length * 2, "0");
40
+ this.value = this.value.padStart(doubleLength, "0");
39
41
  }
40
42
  else if (value instanceof integer8_1.Integer8) {
41
43
  let hex = "";
42
44
  if (value.get() < 0) {
43
45
  hex = (value.get() + 0x10000000000000000n).toString(16).toUpperCase();
44
- if (hex.length > this.length * 2) {
45
- hex = hex.substring(hex.length - this.length * 2);
46
+ if (hex.length > doubleLength) {
47
+ hex = hex.substring(hex.length - doubleLength);
46
48
  }
47
49
  }
48
50
  else {
49
51
  hex = value.get().toString(16).toUpperCase();
50
- hex = hex.padStart(this.length * 2, "0");
52
+ hex = hex.padStart(doubleLength, "0");
51
53
  }
52
- this.set(hex);
54
+ return this.set(hex);
53
55
  }
54
56
  else {
55
- let v = value.get();
57
+ const v = value.get();
56
58
  if (value instanceof float_1.Float) {
57
- v = value.getRaw();
58
- this.set(v);
59
+ return this.set(value.getRaw());
59
60
  }
60
61
  else if (typeof v === "number") {
61
- this.set(v);
62
+ return this.set(v);
62
63
  }
63
64
  else {
64
65
  this.value = v;
65
- if (this.value.match(/^(?![A-F0-9])/)) {
66
+ if (this.value.match(REGEXP)) {
66
67
  this.value = "";
67
68
  }
68
69
  }
69
70
  }
70
- if (this.value.length > this.length * 2) {
71
- this.value = this.value.substr(0, this.length * 2);
71
+ if (this.value.length > doubleLength) {
72
+ this.value = this.value.substr(0, doubleLength);
72
73
  }
73
- if (this.value.length < this.length * 2) {
74
- this.value = this.value.padEnd(this.length * 2, "0");
74
+ else if (this.value.length < doubleLength) {
75
+ this.value = this.value.padEnd(doubleLength, "0");
75
76
  }
76
- this.value = this.value.toUpperCase();
77
+ // this.value = this.value.toUpperCase(); // todo, for some reason abapNTLM needs this? investigate
77
78
  return this;
78
79
  }
79
80
  getLength() {
@@ -21,7 +21,7 @@ class XString {
21
21
  this.value = this.value.padEnd(finalLength, "0");
22
22
  }
23
23
  else if (typeof value === "number") {
24
- this.value = Math.round(value).toString(16);
24
+ this.value = Math.round(value).toString(16).toUpperCase();
25
25
  if (this.value.length % 2 === 1) {
26
26
  this.value = "0" + this.value;
27
27
  }
@@ -36,7 +36,7 @@ class XString {
36
36
  this.set(value.getTrimEnd());
37
37
  }
38
38
  else if (typeof v === "number") {
39
- this.value = v.toString(16);
39
+ this.value = v.toString(16).toUpperCase();
40
40
  const finalLength = Math.ceil(this.value.length / 2) * 2;
41
41
  this.value = this.value.padStart(finalLength, "0");
42
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/runtime",
3
- "version": "2.8.11",
3
+ "version": "2.8.13",
4
4
  "description": "Transpiler - Runtime",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",