@abaplint/runtime 2.2.17 → 2.2.19

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 } from "./types";
1
+ import { Character, 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: Character, options: IOffsetLengthOptions);
13
+ constructor(obj: Character | Hex | XString | Structure, options: IOffsetLengthOptions);
14
14
  get(): string;
15
15
  set(value: ICharacter | string): void;
16
16
  }
@@ -49,7 +49,7 @@ class OffsetLength {
49
49
  else {
50
50
  val = value.get() + "";
51
51
  }
52
- let old = this.obj.get();
52
+ let old = this.obj instanceof types_1.Structure ? this.obj.getCharacter() : this.obj.get();
53
53
  if (this.obj instanceof types_1.Character) {
54
54
  old = old.padEnd(this.obj.getLength(), " ");
55
55
  }
@@ -14,15 +14,23 @@ function concatenate(input) {
14
14
  }
15
15
  else {
16
16
  for (const source of input.source) {
17
- if (typeof source === "string" || typeof source === "number") {
18
- list.push(source.toString());
19
- }
20
- else if (source instanceof types_1.Table) {
17
+ let val = "";
18
+ if (source instanceof types_1.Table) {
21
19
  throw new Error("concatenate, error input is table");
22
20
  }
21
+ else if (typeof source === "string" || typeof source === "number") {
22
+ val = source.toString();
23
+ }
24
+ else if (source instanceof types_1.Character) {
25
+ val = source.get().toString();
26
+ if (input.respectingBlanks !== true) {
27
+ val = val.replace(/ +$/, "");
28
+ }
29
+ }
23
30
  else {
24
- list.push(source.get().toString());
31
+ val = source.get().toString();
25
32
  }
33
+ list.push(val);
26
34
  }
27
35
  }
28
36
  let sep = "";
@@ -10,6 +10,7 @@ import { createData } from "./create_data";
10
10
  import { deleteInternal } from "./delete_internal";
11
11
  import { describe } from "./describe";
12
12
  import { find } from "./find";
13
+ import { overlay } from "./overlay";
13
14
  import { cast } from "./cast";
14
15
  import { getBit } from "./get_bit";
15
16
  import { getLocale } from "./get_locale";
@@ -55,6 +56,7 @@ export declare class Statements {
55
56
  deleteInternal: typeof deleteInternal;
56
57
  describe: typeof describe;
57
58
  find: typeof find;
59
+ overlay: typeof overlay;
58
60
  getParameter: typeof getParameter;
59
61
  getBit: typeof getBit;
60
62
  getLocale: typeof getLocale;
@@ -13,6 +13,7 @@ const create_data_1 = require("./create_data");
13
13
  const delete_internal_1 = require("./delete_internal");
14
14
  const describe_1 = require("./describe");
15
15
  const find_1 = require("./find");
16
+ const overlay_1 = require("./overlay");
16
17
  const cast_1 = require("./cast");
17
18
  const get_bit_1 = require("./get_bit");
18
19
  const get_locale_1 = require("./get_locale");
@@ -57,6 +58,7 @@ class Statements {
57
58
  this.deleteInternal = delete_internal_1.deleteInternal;
58
59
  this.describe = describe_1.describe;
59
60
  this.find = find_1.find;
61
+ this.overlay = overlay_1.overlay;
60
62
  this.getParameter = get_parameter_1.getParameter;
61
63
  this.getBit = get_bit_1.getBit;
62
64
  this.getLocale = get_locale_1.getLocale;
@@ -40,7 +40,7 @@ async function findText(context, arbgb, msgnr, msgty) {
40
40
  }
41
41
  if (text === undefined) {
42
42
  // fallback
43
- text = msgty + ":" + arbgb + ":" + msgnr + " &1 &2 &3 &4";
43
+ text = msgty + ":" + (arbgb === null || arbgb === void 0 ? void 0 : arbgb.trim()) + ":" + msgnr + " &1 &2 &3 &4";
44
44
  }
45
45
  return text;
46
46
  }
@@ -0,0 +1,3 @@
1
+ import { Character, Structure } from "../types";
2
+ import { ICharacter } from "../types/_character";
3
+ export declare function overlay(value: Character | Structure, withh: ICharacter, _only?: ICharacter): void;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.overlay = void 0;
4
+ const offset_length_1 = require("../offset_length");
5
+ const types_1 = require("../types");
6
+ function overlay(value, withh, _only) {
7
+ const set = value instanceof types_1.Structure ? value.getCharacter() : value.get();
8
+ const w = withh.get();
9
+ const len = set.length;
10
+ for (let i = 0; i < len; i++) {
11
+ if (set.substring(i, i + 1) === " ") {
12
+ new offset_length_1.OffsetLength(value, { offset: i, length: 1 }).set(w.substring(i, i + 1));
13
+ }
14
+ }
15
+ }
16
+ exports.overlay = overlay;
17
+ //# sourceMappingURL=overlay.js.map
@@ -20,10 +20,8 @@ class WriteStatement {
20
20
  result = source.toString();
21
21
  }
22
22
  else if (source instanceof types_1.Structure) {
23
- const obj = source.get();
24
- for (const f in obj) {
25
- this.write(obj[f], Object.assign({}, options));
26
- }
23
+ const obj = source.getCharacter();
24
+ this.write(obj, Object.assign({}, options));
27
25
  }
28
26
  else if (source instanceof types_1.Float) {
29
27
  if (((_a = options === null || options === void 0 ? void 0 : options.exponent) === null || _a === void 0 ? void 0 : _a.get()) === 0) {
@@ -43,11 +43,23 @@ function templateFormatting(source, options) {
43
43
  text = text.trimEnd().padEnd(options.width, " ");
44
44
  }
45
45
  else if ((options === null || options === void 0 ? void 0 : options.decimals) && source instanceof types_1.Integer) {
46
- text = source.get() + "." + "".padEnd(options.decimals, "0");
46
+ text = source.get().toFixed(options.decimals);
47
47
  }
48
48
  else if ((options === null || options === void 0 ? void 0 : options.decimals) && source instanceof types_1.Packed) {
49
49
  text = source.get().toFixed(options.decimals);
50
50
  }
51
+ else if ((options === null || options === void 0 ? void 0 : options.decimals) && source instanceof types_1.Float) {
52
+ text = source.getRaw().toFixed(options.decimals);
53
+ }
54
+ else if (source instanceof types_1.Float) {
55
+ const raw = source.getRaw();
56
+ if (Number.isInteger(raw)) {
57
+ text = raw.toFixed(0);
58
+ }
59
+ else {
60
+ text = raw.toFixed(16);
61
+ }
62
+ }
51
63
  return text;
52
64
  }
53
65
  exports.templateFormatting = templateFormatting;
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Character = void 0;
4
4
  const _parse_1 = require("../operators/_parse");
5
+ // eslint-disable-next-line prefer-const
6
+ let featureFixLength = true;
5
7
  class Character {
6
8
  constructor(input) {
7
9
  this.length = (input === null || input === void 0 ? void 0 : input.length) ? input === null || input === void 0 ? void 0 : input.length : 1;
@@ -20,9 +22,9 @@ class Character {
20
22
  }
21
23
  if (this.value.length > this.length) {
22
24
  this.value = this.value.substr(0, this.length);
23
- // todo, maintain consistent length
24
- // } else if (this.value.length < this.length) {
25
- // this.value.padEnd(this.length, " ");
25
+ }
26
+ else if (featureFixLength && this.value.length < this.length) {
27
+ this.value.padEnd(this.length, " ");
26
28
  }
27
29
  return this;
28
30
  }
@@ -33,9 +35,12 @@ class Character {
33
35
  return this.length;
34
36
  }
35
37
  clear() {
36
- // todo, maintain consistent length
37
- // this.value = " ".repeat(this.length);
38
- this.value = "";
38
+ if (featureFixLength) {
39
+ this.value = " ".repeat(this.length);
40
+ }
41
+ else {
42
+ this.value = "";
43
+ }
39
44
  }
40
45
  get() {
41
46
  return this.value;
@@ -2,6 +2,8 @@ import { FieldSymbol } from "./field_symbol";
2
2
  import { Table } from "./table";
3
3
  import { ICharacter } from "./_character";
4
4
  import { INumeric } from "./_numeric";
5
+ import { Hex } from "./hex";
6
+ import { Character } from "./character";
5
7
  export declare class Structure {
6
8
  private readonly value;
7
9
  private readonly qualifiedName;
@@ -11,4 +13,9 @@ export declare class Structure {
11
13
  set(input: Structure | string | INumeric | Table | ICharacter | FieldSymbol | undefined): this | undefined;
12
14
  private setCharacter;
13
15
  get(): any;
16
+ getCharacter(): string;
17
+ getOffset(input: {
18
+ offset?: number | INumeric | Hex;
19
+ length?: number | INumeric | Hex;
20
+ }): Character;
14
21
  }
@@ -4,6 +4,8 @@ exports.Structure = void 0;
4
4
  const clone_1 = require("../clone");
5
5
  const field_symbol_1 = require("./field_symbol");
6
6
  const table_1 = require("./table");
7
+ const _parse_1 = require("../operators/_parse");
8
+ const character_1 = require("./character");
7
9
  class Structure {
8
10
  constructor(fields, qualifiedName) {
9
11
  this.value = fields;
@@ -69,6 +71,46 @@ class Structure {
69
71
  get() {
70
72
  return this.value;
71
73
  }
74
+ getCharacter() {
75
+ let val = "";
76
+ for (const v in this.value) {
77
+ val += this.value[v].get();
78
+ }
79
+ return val;
80
+ }
81
+ getOffset(input) {
82
+ if (input === null || input === void 0 ? void 0 : input.offset) {
83
+ input.offset = (0, _parse_1.parse)(input.offset);
84
+ }
85
+ if (input === null || input === void 0 ? void 0 : input.length) {
86
+ input.length = (0, _parse_1.parse)(input.length);
87
+ }
88
+ const val = this.getCharacter();
89
+ if ((input.offset && input.offset >= val.length)
90
+ || (input.offset && input.offset < 0)
91
+ || (input.length && input.length < 0)) {
92
+ // @ts-ignore
93
+ if (abap.Classes["CX_SY_RANGE_OUT_OF_BOUNDS"] !== undefined) {
94
+ // @ts-ignore
95
+ throw new abap.Classes["CX_SY_RANGE_OUT_OF_BOUNDS"]();
96
+ }
97
+ else {
98
+ throw "Global class CX_SY_RANGE_OUT_OF_BOUNDS not found";
99
+ }
100
+ }
101
+ let ret = val;
102
+ if (input === null || input === void 0 ? void 0 : input.offset) {
103
+ // @ts-ignore
104
+ ret = ret.substr(input.offset);
105
+ }
106
+ if ((input === null || input === void 0 ? void 0 : input.length) !== undefined) {
107
+ // @ts-ignore
108
+ ret = ret.substr(0, input.length);
109
+ }
110
+ const r = new character_1.Character({ length: ret.length });
111
+ r.set(ret);
112
+ return r;
113
+ }
72
114
  }
73
115
  exports.Structure = Structure;
74
116
  //# sourceMappingURL=structure.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/runtime",
3
- "version": "2.2.17",
3
+ "version": "2.2.19",
4
4
  "description": "Transpiler - Runtime",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",