diff --git a/package-lock.json b/package-lock.json index 3903d0aa9..708ad6833 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "hasInstallScript": true, "license": "MIT", "devDependencies": { - "@abaplint/core": "^2.113.7", + "@abaplint/core": "^2.113.8", "@types/chai": "^4.3.19", "@types/mocha": "^10.0.7", "@types/node": "^22.5.4", @@ -30,7 +30,7 @@ "source-map-support": "^0.5.21", "sql.js": "^1.11.0", "temporal-polyfill": "^0.2.5", - "typescript": "^5.5.4" + "typescript": "^5.6.2" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -43,9 +43,9 @@ } }, "node_modules/@abaplint/core": { - "version": "2.113.7", - "resolved": "https://registry.npmjs.org/@abaplint/core/-/core-2.113.7.tgz", - "integrity": "sha512-vyHV/A9DJOi+/9TUknMg94BR9ivHVpiQZ2ox5FiVlj4rJ5eaTZqHvZ+rvFFjI66ADt158gGIvu1+tiIIsUXqzA==", + "version": "2.113.8", + "resolved": "https://registry.npmjs.org/@abaplint/core/-/core-2.113.8.tgz", + "integrity": "sha512-0byfQc4NZ+BsvquP/aNcMmwp9AvujSIIEsrQqA6+BuTQAcL/KM9Lrgw7dsUkI8LUPPtgG6QSgfvhmRpBna4ivA==", "dev": true, "dependencies": { "fast-xml-parser": "^4.5.0", @@ -6777,9 +6777,9 @@ } }, "node_modules/typescript": { - "version": "5.5.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz", - "integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==", + "version": "5.6.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.2.tgz", + "integrity": "sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -7098,9 +7098,9 @@ "dev": true }, "@abaplint/core": { - "version": "2.113.7", - "resolved": "https://registry.npmjs.org/@abaplint/core/-/core-2.113.7.tgz", - "integrity": "sha512-vyHV/A9DJOi+/9TUknMg94BR9ivHVpiQZ2ox5FiVlj4rJ5eaTZqHvZ+rvFFjI66ADt158gGIvu1+tiIIsUXqzA==", + "version": "2.113.8", + "resolved": "https://registry.npmjs.org/@abaplint/core/-/core-2.113.8.tgz", + "integrity": "sha512-0byfQc4NZ+BsvquP/aNcMmwp9AvujSIIEsrQqA6+BuTQAcL/KM9Lrgw7dsUkI8LUPPtgG6QSgfvhmRpBna4ivA==", "dev": true, "requires": { "fast-xml-parser": "^4.5.0", @@ -12259,9 +12259,9 @@ } }, "typescript": { - "version": "5.5.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz", - "integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==", + "version": "5.6.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.2.tgz", + "integrity": "sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==", "dev": true }, "unbox-primitive": { diff --git a/package.json b/package.json index 0359aa266..5e6b69b9d 100644 --- a/package.json +++ b/package.json @@ -17,8 +17,8 @@ "link:database-pg": "cd packages/database-pg && npm link @abaplint/runtime", "link:database-snowflake": "cd packages/database-snowflake && npm link @abaplint/runtime", "link:cli": "cd packages/cli && npm link --force && npm link @abaplint/transpiler", - "docker:start": "docker compose -f test/stack.yml up -d", - "docker:stop": "docker compose -f test/stack.yml down", + "docker:start": "docker compose -p transpiler -f test/stack.yml up -d", + "docker:stop": "docker compose -p transpiler -f test/stack.yml down -v", "lint": "eslint packages/**/*.ts --format unix" }, "repository": { @@ -186,7 +186,7 @@ }, "homepage": "https://github.com/abaplint/transpiler_poc#readme", "devDependencies": { - "@abaplint/core": "^2.113.7", + "@abaplint/core": "^2.113.8", "@types/chai": "^4.3.19", "@types/mocha": "^10.0.7", "@types/node": "^22.5.4", @@ -206,6 +206,6 @@ "source-map-support": "^0.5.21", "sql.js": "^1.11.0", "temporal-polyfill": "^0.2.5", - "typescript": "^5.5.4" + "typescript": "^5.6.2" } } diff --git a/packages/cli/package-lock.json b/packages/cli/package-lock.json index 3ff909fb9..ce74ad068 100644 --- a/packages/cli/package-lock.json +++ b/packages/cli/package-lock.json @@ -1,19 +1,19 @@ { "name": "@abaplint/transpiler-cli", - "version": "2.10.18", + "version": "2.10.19", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@abaplint/transpiler-cli", - "version": "2.10.18", + "version": "2.10.19", "license": "MIT", "bin": { "abap_transpile": "abap_transpile" }, "devDependencies": { - "@abaplint/core": "^2.113.7", - "@abaplint/transpiler": "^2.10.18", + "@abaplint/core": "^2.113.8", + "@abaplint/transpiler": "^2.10.19", "@types/glob": "^8.1.0", "@types/node": "^22.5.4", "@types/progress": "^2.0.7", @@ -28,9 +28,9 @@ } }, "node_modules/@abaplint/core": { - "version": "2.113.7", - "resolved": "https://registry.npmjs.org/@abaplint/core/-/core-2.113.7.tgz", - "integrity": "sha512-vyHV/A9DJOi+/9TUknMg94BR9ivHVpiQZ2ox5FiVlj4rJ5eaTZqHvZ+rvFFjI66ADt158gGIvu1+tiIIsUXqzA==", + "version": "2.113.8", + "resolved": "https://registry.npmjs.org/@abaplint/core/-/core-2.113.8.tgz", + "integrity": "sha512-0byfQc4NZ+BsvquP/aNcMmwp9AvujSIIEsrQqA6+BuTQAcL/KM9Lrgw7dsUkI8LUPPtgG6QSgfvhmRpBna4ivA==", "dev": true, "dependencies": { "fast-xml-parser": "^4.5.0", @@ -45,12 +45,12 @@ } }, "node_modules/@abaplint/transpiler": { - "version": "2.10.18", - "resolved": "https://registry.npmjs.org/@abaplint/transpiler/-/transpiler-2.10.18.tgz", - "integrity": "sha512-5X0669N/QGDjhg+VoE3xs29p0nIaOnXf2vt14bPzT0+3cFKuZSCnGLwRDY2zGDACbvLVm08JYVmz9CyUEyYKlA==", + "version": "2.10.19", + "resolved": "https://registry.npmjs.org/@abaplint/transpiler/-/transpiler-2.10.19.tgz", + "integrity": "sha512-rHYGq2wlLWElHfjWdDPSrP5GIj/nNxudFVlhZ+WxPR06cXmK8wMGrWomPQHXecYl1Dwoly6QU2M4KeEqRVdnPQ==", "dev": true, "dependencies": { - "@abaplint/core": "^2.113.7", + "@abaplint/core": "^2.113.8", "source-map": "^0.7.4" }, "funding": { @@ -1566,9 +1566,9 @@ }, "dependencies": { "@abaplint/core": { - "version": "2.113.7", - "resolved": "https://registry.npmjs.org/@abaplint/core/-/core-2.113.7.tgz", - "integrity": "sha512-vyHV/A9DJOi+/9TUknMg94BR9ivHVpiQZ2ox5FiVlj4rJ5eaTZqHvZ+rvFFjI66ADt158gGIvu1+tiIIsUXqzA==", + "version": "2.113.8", + "resolved": "https://registry.npmjs.org/@abaplint/core/-/core-2.113.8.tgz", + "integrity": "sha512-0byfQc4NZ+BsvquP/aNcMmwp9AvujSIIEsrQqA6+BuTQAcL/KM9Lrgw7dsUkI8LUPPtgG6QSgfvhmRpBna4ivA==", "dev": true, "requires": { "fast-xml-parser": "^4.5.0", @@ -1577,12 +1577,12 @@ } }, "@abaplint/transpiler": { - "version": "2.10.18", - "resolved": "https://registry.npmjs.org/@abaplint/transpiler/-/transpiler-2.10.18.tgz", - "integrity": "sha512-5X0669N/QGDjhg+VoE3xs29p0nIaOnXf2vt14bPzT0+3cFKuZSCnGLwRDY2zGDACbvLVm08JYVmz9CyUEyYKlA==", + "version": "2.10.19", + "resolved": "https://registry.npmjs.org/@abaplint/transpiler/-/transpiler-2.10.19.tgz", + "integrity": "sha512-rHYGq2wlLWElHfjWdDPSrP5GIj/nNxudFVlhZ+WxPR06cXmK8wMGrWomPQHXecYl1Dwoly6QU2M4KeEqRVdnPQ==", "dev": true, "requires": { - "@abaplint/core": "^2.113.7", + "@abaplint/core": "^2.113.8", "source-map": "^0.7.4" } }, diff --git a/packages/cli/package.json b/packages/cli/package.json index 6f39d150f..66f61d525 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@abaplint/transpiler-cli", - "version": "2.10.18", + "version": "2.10.19", "description": "Transpiler - Command Line Interface", "funding": "https://github.com/sponsors/larshp", "bin": { @@ -26,12 +26,12 @@ "author": "abaplint", "license": "MIT", "devDependencies": { - "@abaplint/transpiler": "^2.10.18", + "@abaplint/transpiler": "^2.10.19", "@types/glob": "^8.1.0", "glob": "=7.2.0", "@types/progress": "^2.0.7", "@types/node": "^22.5.4", - "@abaplint/core": "^2.113.7", + "@abaplint/core": "^2.113.8", "progress": "^2.0.3", "webpack": "^5.94.0", "webpack-cli": "^5.1.4", diff --git a/packages/runtime/package-lock.json b/packages/runtime/package-lock.json index 158e0827e..b20b1ad56 100644 --- a/packages/runtime/package-lock.json +++ b/packages/runtime/package-lock.json @@ -1,12 +1,12 @@ { "name": "@abaplint/runtime", - "version": "2.10.18", + "version": "2.10.19", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@abaplint/runtime", - "version": "2.10.18", + "version": "2.10.19", "license": "MIT", "dependencies": { "temporal-polyfill": "^0.2.5" @@ -17,7 +17,7 @@ "chai": "^4.5.0", "mocha": "^10.7.3", "source-map-support": "^0.5.21", - "typescript": "^5.5.4" + "typescript": "^5.6.2" }, "funding": { "url": "https://github.com/sponsors/larshp" @@ -914,9 +914,9 @@ } }, "node_modules/typescript": { - "version": "5.5.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz", - "integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==", + "version": "5.6.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.2.tgz", + "integrity": "sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -1664,9 +1664,9 @@ "dev": true }, "typescript": { - "version": "5.5.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz", - "integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==", + "version": "5.6.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.2.tgz", + "integrity": "sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==", "dev": true }, "workerpool": { diff --git a/packages/runtime/package.json b/packages/runtime/package.json index daecd4cad..99b183907 100644 --- a/packages/runtime/package.json +++ b/packages/runtime/package.json @@ -1,6 +1,6 @@ { "name": "@abaplint/runtime", - "version": "2.10.18", + "version": "2.10.19", "description": "Transpiler - Runtime", "main": "build/src/index.js", "typings": "build/src/index.d.ts", @@ -34,7 +34,7 @@ "chai": "^4.5.0", "mocha": "^10.7.3", "source-map-support": "^0.5.21", - "typescript": "^5.5.4" + "typescript": "^5.6.2" }, "dependencies": { "temporal-polyfill": "^0.2.5" diff --git a/packages/runtime/src/builtin/from_mixed.ts b/packages/runtime/src/builtin/from_mixed.ts new file mode 100644 index 000000000..be722cad7 --- /dev/null +++ b/packages/runtime/src/builtin/from_mixed.ts @@ -0,0 +1,40 @@ +/* eslint-disable @typescript-eslint/ban-types */ +import {throwError} from "../throw_error"; +import {String} from "../types"; +import {ICharacter} from "../types/_character"; +import {INumeric} from "../types/_numeric"; + +export function from_mixed(input: { + val: ICharacter | string, + sep?: ICharacter | string, + case?: ICharacter | string, + min?: INumeric | number }): String { + + let sep = input.sep; + if (sep === undefined) { + sep = "_"; + } + if (typeof sep !== "string") { + sep = sep.get(); + } + if (sep.length === 0) { + throwError("CX_SY_STRG_PAR_VAL"); + } + + const min = 1; + if (min < 0) { + throwError("CX_SY_STRG_PAR_VAL"); + } + + let val = input.val; + if (typeof val !== "string") { + val = val.get(); + } + +// todo: handle "case" and "min" ? + + const regex = new RegExp(/([A-Z])/, "g"); + val = val.substring(0, 1) + val.substring(1).replace(regex, "_$1"); + + return new String().set(val.toUpperCase()); +} diff --git a/packages/runtime/src/builtin/index.ts b/packages/runtime/src/builtin/index.ts index d72320630..20d460cba 100644 --- a/packages/runtime/src/builtin/index.ts +++ b/packages/runtime/src/builtin/index.ts @@ -13,6 +13,7 @@ export * from "./escape"; export * from "./find"; export * from "./floor"; export * from "./frac"; +export * from "./from_mixed"; export * from "./insert"; export * from "./ipow"; export * from "./lines"; @@ -26,8 +27,8 @@ export * from "./replace"; export * from "./reverse"; export * from "./round"; export * from "./segment"; -export * from "./shift_right"; export * from "./shift_left"; +export * from "./shift_right"; export * from "./sign"; export * from "./sin"; export * from "./sqrt"; diff --git a/packages/transpiler/package-lock.json b/packages/transpiler/package-lock.json index b0b36dccf..dcdf60e40 100644 --- a/packages/transpiler/package-lock.json +++ b/packages/transpiler/package-lock.json @@ -1,15 +1,15 @@ { "name": "@abaplint/transpiler", - "version": "2.10.18", + "version": "2.10.19", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@abaplint/transpiler", - "version": "2.10.18", + "version": "2.10.19", "license": "MIT", "dependencies": { - "@abaplint/core": "^2.113.7", + "@abaplint/core": "^2.113.8", "source-map": "^0.7.4" }, "devDependencies": { @@ -18,16 +18,16 @@ "chai": "^4.5.0", "mocha": "^10.7.3", "source-map-support": "^0.5.21", - "typescript": "^5.5.4" + "typescript": "^5.6.2" }, "funding": { "url": "https://github.com/sponsors/larshp" } }, "node_modules/@abaplint/core": { - "version": "2.113.7", - "resolved": "https://registry.npmjs.org/@abaplint/core/-/core-2.113.7.tgz", - "integrity": "sha512-vyHV/A9DJOi+/9TUknMg94BR9ivHVpiQZ2ox5FiVlj4rJ5eaTZqHvZ+rvFFjI66ADt158gGIvu1+tiIIsUXqzA==", + "version": "2.113.8", + "resolved": "https://registry.npmjs.org/@abaplint/core/-/core-2.113.8.tgz", + "integrity": "sha512-0byfQc4NZ+BsvquP/aNcMmwp9AvujSIIEsrQqA6+BuTQAcL/KM9Lrgw7dsUkI8LUPPtgG6QSgfvhmRpBna4ivA==", "dependencies": { "fast-xml-parser": "^4.5.0", "json5": "^2.2.3", @@ -963,9 +963,9 @@ } }, "node_modules/typescript": { - "version": "5.5.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz", - "integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==", + "version": "5.6.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.2.tgz", + "integrity": "sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -1075,9 +1075,9 @@ }, "dependencies": { "@abaplint/core": { - "version": "2.113.7", - "resolved": "https://registry.npmjs.org/@abaplint/core/-/core-2.113.7.tgz", - "integrity": "sha512-vyHV/A9DJOi+/9TUknMg94BR9ivHVpiQZ2ox5FiVlj4rJ5eaTZqHvZ+rvFFjI66ADt158gGIvu1+tiIIsUXqzA==", + "version": "2.113.8", + "resolved": "https://registry.npmjs.org/@abaplint/core/-/core-2.113.8.tgz", + "integrity": "sha512-0byfQc4NZ+BsvquP/aNcMmwp9AvujSIIEsrQqA6+BuTQAcL/KM9Lrgw7dsUkI8LUPPtgG6QSgfvhmRpBna4ivA==", "requires": { "fast-xml-parser": "^4.5.0", "json5": "^2.2.3", @@ -1740,9 +1740,9 @@ "dev": true }, "typescript": { - "version": "5.5.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz", - "integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==", + "version": "5.6.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.2.tgz", + "integrity": "sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==", "dev": true }, "vscode-languageserver-types": { diff --git a/packages/transpiler/package.json b/packages/transpiler/package.json index d4ff8112f..c0c67466b 100644 --- a/packages/transpiler/package.json +++ b/packages/transpiler/package.json @@ -1,6 +1,6 @@ { "name": "@abaplint/transpiler", - "version": "2.10.18", + "version": "2.10.19", "description": "Transpiler", "main": "build/src/index.js", "typings": "build/src/index.d.ts", @@ -29,7 +29,7 @@ "author": "abaplint", "license": "MIT", "dependencies": { - "@abaplint/core": "^2.113.7", + "@abaplint/core": "^2.113.8", "source-map": "^0.7.4" }, "devDependencies": { @@ -38,6 +38,6 @@ "chai": "^4.5.0", "mocha": "^10.7.3", "source-map-support": "^0.5.21", - "typescript": "^5.5.4" + "typescript": "^5.6.2" } } diff --git a/test/builtin/from_mixed.ts b/test/builtin/from_mixed.ts new file mode 100644 index 000000000..8a84c7909 --- /dev/null +++ b/test/builtin/from_mixed.ts @@ -0,0 +1,47 @@ +import {expect} from "chai"; +import {ABAP, MemoryConsole} from "../../packages/runtime/src"; +import {AsyncFunction, runFiles} from "../_utils"; + +let abap: ABAP; + +async function run(contents: string) { + return runFiles(abap, [{filename: "zfoobar.prog.abap", contents}]); +} + +describe("Builtin functions - from_mixed", () => { + + beforeEach(async () => { + abap = new ABAP({console: new MemoryConsole()}); + }); + + it("test1", async () => { + const code = ` +WRITE / from_mixed( 'putData' ). +`; + const js = await run(code); + const f = new AsyncFunction("abap", js); + await f(abap); + expect(abap.console.get()).to.equal(`PUT_DATA`); + }); + + it("more testing", async () => { + const code = ` +WRITE / from_mixed( 'PutData' ). +WRITE / from_mixed( 'PUTDATA' ). +WRITE / from_mixed( 'putdata' ). +WRITE / from_mixed( 'put data' ). +WRITE / from_mixed( 'put Data' ). +WRITE / from_mixed( '_PutData' ). +`; + const js = await run(code); + const f = new AsyncFunction("abap", js); + await f(abap); + expect(abap.console.get()).to.equal(`PUT_DATA +P_U_T_D_A_T_A +PUTDATA +PUT DATA +PUT _DATA +__PUT_DATA`); + }); + +}); diff --git a/test/stack.yml b/test/stack.yml index 120c7924f..00804143d 100644 --- a/test/stack.yml +++ b/test/stack.yml @@ -1,5 +1,4 @@ # Use postgres/example user/password credentials -version: '3.1' services: postgresql: