@abaplint/runtime 2.0.1 → 2.0.4

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.
package/README.md CHANGED
@@ -1,3 +1,3 @@
1
- # @abaplint/runtime
2
-
1
+ # @abaplint/runtime
2
+
3
3
  Runtime
@@ -10,6 +10,7 @@ export * from "./escape";
10
10
  export * from "./find";
11
11
  export * from "./floor";
12
12
  export * from "./frac";
13
+ export * from "./insert";
13
14
  export * from "./lines";
14
15
  export * from "./nmax";
15
16
  export * from "./nmin";
@@ -27,6 +27,7 @@ __exportStar(require("./escape"), exports);
27
27
  __exportStar(require("./find"), exports);
28
28
  __exportStar(require("./floor"), exports);
29
29
  __exportStar(require("./frac"), exports);
30
+ __exportStar(require("./insert"), exports);
30
31
  __exportStar(require("./lines"), exports);
31
32
  __exportStar(require("./nmax"), exports);
32
33
  __exportStar(require("./nmin"), exports);
@@ -0,0 +1,9 @@
1
+ import { String } from "../types";
2
+ import { ICharacter } from "../types/_character";
3
+ import { INumeric } from "../types/_numeric";
4
+ export interface IInsertInput {
5
+ val: ICharacter;
6
+ sub: ICharacter;
7
+ off?: INumeric;
8
+ }
9
+ export declare function insert(input: IInsertInput): String;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.insert = void 0;
4
+ const types_1 = require("../types");
5
+ function insert(input) {
6
+ let offset = 0;
7
+ if (input.off) {
8
+ offset = input.off.get();
9
+ }
10
+ const value = input.val.getOffset({ offset: 0, length: offset }).get() +
11
+ input.sub.get() +
12
+ input.val.getOffset({ offset: offset }).get();
13
+ return new types_1.String().set(value);
14
+ }
15
+ exports.insert = insert;
16
+ //# sourceMappingURL=insert.js.map
@@ -34,11 +34,18 @@ function replace(input) {
34
34
  else if (input.regex) {
35
35
  sub = input.regex.get();
36
36
  }
37
- if (input.off && input.len) {
37
+ if (input.off && input.len && typeof input.val === "string") {
38
38
  const offset = input.off.get();
39
39
  const length = input.len.get();
40
40
  val = val.substring(0, offset) + wi + val.substring(offset + length);
41
41
  }
42
+ else if (input.off && input.len && !(typeof input.val === "string")) {
43
+ const offset = input.off.get();
44
+ const length = input.len.get();
45
+ val = input.val.getOffset({ offset: 0, length: offset }).get() +
46
+ wi +
47
+ input.val.getOffset({ offset: offset + length }).get();
48
+ }
42
49
  else if (input.occ === undefined && sub && wi) {
43
50
  val = val.replace(sub, wi);
44
51
  }
@@ -4,13 +4,18 @@ exports.substring = void 0;
4
4
  const string_1 = require("../types/string");
5
5
  function substring(input) {
6
6
  var _a, _b;
7
- const val = typeof input.val === "string" ? input.val : input.val.get();
8
7
  let off = (_a = input === null || input === void 0 ? void 0 : input.off) === null || _a === void 0 ? void 0 : _a.get();
9
8
  if (off === undefined) {
10
9
  off = 0;
11
10
  }
12
11
  const len = (_b = input === null || input === void 0 ? void 0 : input.len) === null || _b === void 0 ? void 0 : _b.get();
13
- const sub = val.substr(off, len);
12
+ let sub = "";
13
+ if (typeof input.val === "string") {
14
+ sub = input.val.substr(off, len);
15
+ }
16
+ else {
17
+ sub = input.val.getOffset({ offset: off, length: len }).get();
18
+ }
14
19
  return new string_1.String().set(sub);
15
20
  }
16
21
  exports.substring = substring;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.initial = void 0;
4
4
  const types_1 = require("../types");
5
5
  function initial(val) {
6
+ // todo, refactor? add as method in each type instead?
6
7
  if (val instanceof types_1.Table) {
7
8
  return val.array().length === 0;
8
9
  }
@@ -1,3 +1,4 @@
1
+ import { Float, Integer } from "../types";
1
2
  import { ICharacter } from "../types/_character";
2
3
  import { INumeric } from "../types/_numeric";
3
- export declare function parse(val: INumeric | ICharacter | string | number): number;
4
+ export declare function parse(val: INumeric | ICharacter | string | number | Float | Integer): number;
@@ -1,4 +1,4 @@
1
- import { Float, Integer } from "../types";
1
+ import { Float, Hex, Integer } from "../types";
2
2
  import { ICharacter } from "../types/_character";
3
3
  import { INumeric } from "../types/_numeric";
4
- export declare function add(left: INumeric | ICharacter | string | number, right: INumeric | ICharacter | string | number): Float | Integer;
4
+ export declare function add(left: INumeric | ICharacter | string | number | Float | Integer | Hex, right: INumeric | ICharacter | string | number | Float | Integer | Hex): Float | Integer;
@@ -1,4 +1,4 @@
1
1
  import { Float, Integer } from "../types";
2
2
  import { ICharacter } from "../types/_character";
3
3
  import { INumeric } from "../types/_numeric";
4
- export declare function minus(left: INumeric | ICharacter | string | number, right: INumeric | ICharacter | string | number): Float | Integer;
4
+ export declare function minus(left: INumeric | ICharacter | string | number | Integer | Float, right: INumeric | ICharacter | string | number | Integer | Float): Float | Integer;
@@ -47,13 +47,11 @@ function shift_character_mode(target, options) {
47
47
  value = value.substr(index);
48
48
  }
49
49
  }
50
+ else if (options === null || options === void 0 ? void 0 : options.circular) {
51
+ value = value.substr(1) + value.substr(0, 1);
52
+ }
50
53
  else {
51
- if (options === null || options === void 0 ? void 0 : options.circular) {
52
- value = value.substr(1) + value.substr(0, 1);
53
- }
54
- else {
55
- value = value.substr(1);
56
- }
54
+ value = value.substr(1);
57
55
  }
58
56
  target.set(value);
59
57
  }
@@ -91,6 +89,12 @@ function shift_byte_mode(target, options) {
91
89
  value = value.substr(index);
92
90
  }
93
91
  }
92
+ else if (options === null || options === void 0 ? void 0 : options.circular) {
93
+ value = value.substr(2) + value.substr(0, 2);
94
+ }
95
+ else {
96
+ value = value.substr(2);
97
+ }
94
98
  target.set(value);
95
99
  }
96
100
  //# sourceMappingURL=shift.js.map
@@ -2,4 +2,8 @@ export interface ICharacter {
2
2
  set(value: ICharacter | string): void;
3
3
  get(): string;
4
4
  clear(): void;
5
+ getOffset(input: {
6
+ offset?: number;
7
+ length?: number;
8
+ }): ICharacter;
5
9
  }
@@ -3,9 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Character = void 0;
4
4
  class Character {
5
5
  constructor(input) {
6
- this.value = "";
7
6
  this.length = (input === null || input === void 0 ? void 0 : input.length) ? input === null || input === void 0 ? void 0 : input.length : 1;
7
+ if (this.length <= 0) {
8
+ throw "Character, invalid length";
9
+ }
8
10
  this.qualifiedName = input === null || input === void 0 ? void 0 : input.qualifiedName;
11
+ this.clear();
9
12
  }
10
13
  set(value) {
11
14
  if (typeof value === "string" || typeof value === "number") {
@@ -16,6 +19,9 @@ class Character {
16
19
  }
17
20
  if (this.value.length > this.length) {
18
21
  this.value = this.value.substr(0, this.length);
22
+ // todo, maintain consistent length
23
+ // } else if (this.value.length < this.length) {
24
+ // this.value.padEnd(this.length, " ");
19
25
  }
20
26
  return this;
21
27
  }
@@ -26,12 +32,26 @@ class Character {
26
32
  return this.length;
27
33
  }
28
34
  clear() {
35
+ // todo, maintain consistent length
36
+ // this.value = " ".repeat(this.length);
29
37
  this.value = "";
30
38
  }
31
39
  get() {
32
40
  return this.value;
33
41
  }
34
42
  getOffset(input) {
43
+ if ((input.offset && input.offset >= this.length)
44
+ || (input.offset && input.offset < 0)
45
+ || (input.length && input.length < 0)) {
46
+ // @ts-ignore
47
+ if (abap.Classes["CX_SY_RANGE_OUT_OF_BOUNDS"] !== undefined) {
48
+ // @ts-ignore
49
+ throw new abap.Classes["CX_SY_RANGE_OUT_OF_BOUNDS"]();
50
+ }
51
+ else {
52
+ throw "Global class CX_SY_RANGE_OUT_OF_BOUNDS not found";
53
+ }
54
+ }
35
55
  let ret = this.value;
36
56
  if (input === null || input === void 0 ? void 0 : input.offset) {
37
57
  ret = ret.substr(input.offset);
@@ -1,3 +1,5 @@
1
+ import { Float } from "./float";
2
+ import { Integer } from "./integer";
1
3
  import { XString } from "./xstring";
2
4
  import { ICharacter } from "./_character";
3
5
  import { INumeric } from "./_numeric";
@@ -7,7 +9,7 @@ export declare class Hex implements ICharacter {
7
9
  constructor(input?: {
8
10
  length?: number;
9
11
  });
10
- set(value: ICharacter | INumeric | string | number): void;
12
+ set(value: ICharacter | INumeric | string | number | Integer | Float): void;
11
13
  getLength(): number;
12
14
  clear(): void;
13
15
  get(): string;
@@ -1,10 +1,11 @@
1
+ import { Float } from "./float";
1
2
  import { Hex } from "./hex";
2
3
  import { ICharacter } from "./_character";
3
4
  import { INumeric } from "./_numeric";
4
5
  export declare class Integer implements INumeric {
5
6
  private value;
6
7
  constructor();
7
- set(value: INumeric | ICharacter | Hex | string | number): this;
8
+ set(value: INumeric | ICharacter | Hex | string | number | Integer | Float): this;
8
9
  clear(): void;
9
10
  get(): number;
10
11
  }
@@ -11,4 +11,8 @@ export declare class Numc implements ICharacter {
11
11
  getLength(): number;
12
12
  clear(): void;
13
13
  get(): string;
14
+ getOffset(_input: {
15
+ offset?: number;
16
+ length?: number;
17
+ }): Numc;
14
18
  }
@@ -37,6 +37,9 @@ class Numc {
37
37
  get() {
38
38
  return this.value;
39
39
  }
40
+ getOffset(_input) {
41
+ throw "todo, runtime, numc getOffset()";
42
+ }
40
43
  }
41
44
  exports.Numc = Numc;
42
45
  //# sourceMappingURL=numc.js.map
@@ -34,6 +34,18 @@ class String {
34
34
  return this.value;
35
35
  }
36
36
  getOffset(input) {
37
+ if ((input.offset && input.offset > this.value.length)
38
+ || (input.offset && input.offset < 0)
39
+ || (input.length && input.length < 0)) {
40
+ // @ts-ignore
41
+ if (abap.Classes["CX_SY_RANGE_OUT_OF_BOUNDS"] !== undefined) {
42
+ // @ts-ignore
43
+ throw new abap.Classes["CX_SY_RANGE_OUT_OF_BOUNDS"]();
44
+ }
45
+ else {
46
+ throw "Global class CX_SY_RANGE_OUT_OF_BOUNDS not found";
47
+ }
48
+ }
37
49
  let ret = this.value;
38
50
  if (input === null || input === void 0 ? void 0 : input.offset) {
39
51
  ret = ret.substr(input.offset);
package/package.json CHANGED
@@ -1,39 +1,39 @@
1
- {
2
- "name": "@abaplint/runtime",
3
- "version": "2.0.1",
4
- "description": "Transpiler - Runtime",
5
- "main": "build/src/index.js",
6
- "typings": "build/src/index.d.ts",
7
- "repository": {
8
- "type": "git",
9
- "url": "git+https://github.com/abaplint/transpiler.git"
10
- },
11
- "scripts": {
12
- "compile": "tsc",
13
- "publish:major": "npm --no-git-tag-version version major && rm -rf build && npm install && npm run test && npm publish --access public",
14
- "publish:minor": "npm --no-git-tag-version version minor && rm -rf build && npm install && npm run test && npm publish --access public",
15
- "publish:patch": "npm --no-git-tag-version version patch && rm -rf build && npm install && npm run test && npm publish --access public",
16
- "test": "npm run compile && mocha"
17
- },
18
- "mocha": {
19
- "recursive": true,
20
- "reporter": "progress",
21
- "spec": "build/test/**/*.js",
22
- "require": "source-map-support/register"
23
- },
24
- "keywords": [
25
- "ABAP",
26
- "abaplint"
27
- ],
28
- "author": "abaplint",
29
- "license": "MIT",
30
- "devDependencies": {
31
- "@types/chai": "^4.3.0",
32
- "@types/mocha": "^9.1.0",
33
- "@types/sql.js": "^1.4.3",
34
- "chai": "^4.3.6",
35
- "mocha": "^9.2.2",
36
- "source-map-support": "^0.5.21",
37
- "typescript": "^4.6.3"
38
- }
39
- }
1
+ {
2
+ "name": "@abaplint/runtime",
3
+ "version": "2.0.4",
4
+ "description": "Transpiler - Runtime",
5
+ "main": "build/src/index.js",
6
+ "typings": "build/src/index.d.ts",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/abaplint/transpiler.git"
10
+ },
11
+ "scripts": {
12
+ "compile": "tsc",
13
+ "publish:major": "npm --no-git-tag-version version major && rm -rf build && npm install && npm run test && npm publish --access public",
14
+ "publish:minor": "npm --no-git-tag-version version minor && rm -rf build && npm install && npm run test && npm publish --access public",
15
+ "publish:patch": "npm --no-git-tag-version version patch && rm -rf build && npm install && npm run test && npm publish --access public",
16
+ "test": "npm run compile && mocha"
17
+ },
18
+ "mocha": {
19
+ "recursive": true,
20
+ "reporter": "progress",
21
+ "spec": "build/test/**/*.js",
22
+ "require": "source-map-support/register"
23
+ },
24
+ "keywords": [
25
+ "ABAP",
26
+ "abaplint"
27
+ ],
28
+ "author": "abaplint",
29
+ "license": "MIT",
30
+ "devDependencies": {
31
+ "@types/chai": "^4.3.0",
32
+ "@types/mocha": "^9.1.0",
33
+ "@types/sql.js": "^1.4.3",
34
+ "chai": "^4.3.6",
35
+ "mocha": "^9.2.2",
36
+ "source-map-support": "^0.5.21",
37
+ "typescript": "^4.6.3"
38
+ }
39
+ }