From 6ef00bbe8b2ecbbf4a1fed37728eca1108b5e931 Mon Sep 17 00:00:00 2001 From: Lars Hvam Date: Mon, 5 Aug 2024 19:07:36 +0200 Subject: [PATCH] 2.10.7: fix REPLACEMENT COUNT + bugfix DELETE internal (#1454) --- package-lock.json | 44 ++++++------- package.json | 4 +- packages/cli/package-lock.json | 66 +++++++++---------- packages/cli/package.json | 8 +-- packages/runtime/package-lock.json | 4 +- packages/runtime/package.json | 2 +- .../runtime/src/statements/delete_internal.ts | 4 +- packages/runtime/src/statements/replace.ts | 9 ++- packages/transpiler/package-lock.json | 18 ++--- packages/transpiler/package.json | 4 +- .../src/statements/delete_internal.ts | 5 +- packages/transpiler/src/statements/replace.ts | 5 ++ packages/transpiler/test/single_statements.ts | 8 +-- test/statements/delete_internal.ts | 31 +++++++++ test/statements/replace.ts | 60 +++++++++++++++++ 15 files changed, 187 insertions(+), 85 deletions(-) diff --git a/package-lock.json b/package-lock.json index d31725e2f..d2837f914 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,10 +10,10 @@ "hasInstallScript": true, "license": "MIT", "devDependencies": { - "@abaplint/core": "^2.112.9", + "@abaplint/core": "^2.112.10", "@types/chai": "^4.3.17", "@types/mocha": "^10.0.7", - "@types/node": "^22.0.2", + "@types/node": "^22.1.0", "@types/sql.js": "^1.4.9", "@typescript-eslint/eslint-plugin": "^7.18.0", "@typescript-eslint/parser": "^7.18.0", @@ -43,9 +43,9 @@ } }, "node_modules/@abaplint/core": { - "version": "2.112.9", - "resolved": "https://registry.npmjs.org/@abaplint/core/-/core-2.112.9.tgz", - "integrity": "sha512-4k4oSUX5xjpmJvsjrXdgfqN3NiYDKu8apAfHruNXPjoEezTjXrJi/AyQyGIpEiLWiDxzYIdgubcb7ilhmtlWig==", + "version": "2.112.10", + "resolved": "https://registry.npmjs.org/@abaplint/core/-/core-2.112.10.tgz", + "integrity": "sha512-o1tO8ZcYPW4Rn+DS2W+CYzFHgczqRH2G4asgNZaRKDqdNb4uXYJxuXiiGX2ki2rmOEB5JYm/qnJ035sbB75wHA==", "dev": true, "dependencies": { "fast-xml-parser": "^4.4.1", @@ -2134,12 +2134,12 @@ "dev": true }, "node_modules/@types/node": { - "version": "22.0.2", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.0.2.tgz", - "integrity": "sha512-yPL6DyFwY5PiMVEwymNeqUTKsDczQBJ/5T7W/46RwLU/VH+AA8aT5TZkvBviLKLbbm0hlfftEkGrNzfRk/fofQ==", + "version": "22.1.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.1.0.tgz", + "integrity": "sha512-AOmuRF0R2/5j1knA3c6G3HOk523Ga+l+ZXltX8SF1+5oqcXijjfTd8fY3XRZqSihEu9XhtQnKYLmkFaoxgsJHw==", "dev": true, "dependencies": { - "undici-types": "~6.11.1" + "undici-types": "~6.13.0" } }, "node_modules/@types/node-fetch": { @@ -6775,9 +6775,9 @@ } }, "node_modules/undici-types": { - "version": "6.11.1", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.11.1.tgz", - "integrity": "sha512-mIDEX2ek50x0OlRgxryxsenE5XaQD4on5U2inY7RApK3SOJpofyw7uW2AyfMKkhAxXIceo2DeWGVGwyvng1GNQ==", + "version": "6.13.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.13.0.tgz", + "integrity": "sha512-xtFJHudx8S2DSoujjMd1WeWvn7KKWFRESZTMeL1RptAYERu29D6jphMjjY+vn96jvN3kVPDNxU/E13VTaXj6jg==", "dev": true }, "node_modules/uri-js": { @@ -7068,9 +7068,9 @@ "dev": true }, "@abaplint/core": { - "version": "2.112.9", - "resolved": "https://registry.npmjs.org/@abaplint/core/-/core-2.112.9.tgz", - "integrity": "sha512-4k4oSUX5xjpmJvsjrXdgfqN3NiYDKu8apAfHruNXPjoEezTjXrJi/AyQyGIpEiLWiDxzYIdgubcb7ilhmtlWig==", + "version": "2.112.10", + "resolved": "https://registry.npmjs.org/@abaplint/core/-/core-2.112.10.tgz", + "integrity": "sha512-o1tO8ZcYPW4Rn+DS2W+CYzFHgczqRH2G4asgNZaRKDqdNb4uXYJxuXiiGX2ki2rmOEB5JYm/qnJ035sbB75wHA==", "dev": true, "requires": { "fast-xml-parser": "^4.4.1", @@ -8793,12 +8793,12 @@ "dev": true }, "@types/node": { - "version": "22.0.2", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.0.2.tgz", - "integrity": "sha512-yPL6DyFwY5PiMVEwymNeqUTKsDczQBJ/5T7W/46RwLU/VH+AA8aT5TZkvBviLKLbbm0hlfftEkGrNzfRk/fofQ==", + "version": "22.1.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.1.0.tgz", + "integrity": "sha512-AOmuRF0R2/5j1knA3c6G3HOk523Ga+l+ZXltX8SF1+5oqcXijjfTd8fY3XRZqSihEu9XhtQnKYLmkFaoxgsJHw==", "dev": true, "requires": { - "undici-types": "~6.11.1" + "undici-types": "~6.13.0" } }, "@types/node-fetch": { @@ -12220,9 +12220,9 @@ } }, "undici-types": { - "version": "6.11.1", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.11.1.tgz", - "integrity": "sha512-mIDEX2ek50x0OlRgxryxsenE5XaQD4on5U2inY7RApK3SOJpofyw7uW2AyfMKkhAxXIceo2DeWGVGwyvng1GNQ==", + "version": "6.13.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.13.0.tgz", + "integrity": "sha512-xtFJHudx8S2DSoujjMd1WeWvn7KKWFRESZTMeL1RptAYERu29D6jphMjjY+vn96jvN3kVPDNxU/E13VTaXj6jg==", "dev": true }, "uri-js": { diff --git a/package.json b/package.json index 4a1eac92d..7594ab0bc 100644 --- a/package.json +++ b/package.json @@ -186,10 +186,10 @@ }, "homepage": "https://github.com/abaplint/transpiler_poc#readme", "devDependencies": { - "@abaplint/core": "^2.112.9", + "@abaplint/core": "^2.112.10", "@types/chai": "^4.3.17", "@types/mocha": "^10.0.7", - "@types/node": "^22.0.2", + "@types/node": "^22.1.0", "@types/sql.js": "^1.4.9", "@typescript-eslint/eslint-plugin": "^7.18.0", "@typescript-eslint/parser": "^7.18.0", diff --git a/packages/cli/package-lock.json b/packages/cli/package-lock.json index bfb4c30ca..3b501a6a5 100644 --- a/packages/cli/package-lock.json +++ b/packages/cli/package-lock.json @@ -1,21 +1,21 @@ { "name": "@abaplint/transpiler-cli", - "version": "2.10.6", + "version": "2.10.7", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@abaplint/transpiler-cli", - "version": "2.10.6", + "version": "2.10.7", "license": "MIT", "bin": { "abap_transpile": "abap_transpile" }, "devDependencies": { - "@abaplint/core": "^2.112.9", - "@abaplint/transpiler": "^2.10.6", + "@abaplint/core": "^2.112.10", + "@abaplint/transpiler": "^2.10.7", "@types/glob": "^8.1.0", - "@types/node": "^22.0.2", + "@types/node": "^22.1.0", "@types/progress": "^2.0.7", "glob": "=7.2.0", "progress": "^2.0.3", @@ -28,9 +28,9 @@ } }, "node_modules/@abaplint/core": { - "version": "2.112.9", - "resolved": "https://registry.npmjs.org/@abaplint/core/-/core-2.112.9.tgz", - "integrity": "sha512-4k4oSUX5xjpmJvsjrXdgfqN3NiYDKu8apAfHruNXPjoEezTjXrJi/AyQyGIpEiLWiDxzYIdgubcb7ilhmtlWig==", + "version": "2.112.10", + "resolved": "https://registry.npmjs.org/@abaplint/core/-/core-2.112.10.tgz", + "integrity": "sha512-o1tO8ZcYPW4Rn+DS2W+CYzFHgczqRH2G4asgNZaRKDqdNb4uXYJxuXiiGX2ki2rmOEB5JYm/qnJ035sbB75wHA==", "dev": true, "dependencies": { "fast-xml-parser": "^4.4.1", @@ -45,12 +45,12 @@ } }, "node_modules/@abaplint/transpiler": { - "version": "2.10.6", - "resolved": "https://registry.npmjs.org/@abaplint/transpiler/-/transpiler-2.10.6.tgz", - "integrity": "sha512-IkwuopJfkJVmPaXE0fob4DVxoO9IF+etp2dJsqJNGkTF6+R+nRhsMeLZkf0M7zHmsiAf2wGb7o6Ypx+G6sSZKA==", + "version": "2.10.7", + "resolved": "https://registry.npmjs.org/@abaplint/transpiler/-/transpiler-2.10.7.tgz", + "integrity": "sha512-sj+rxkJFzxxvhpp69yY/DwisMIgySChMUQuFHHEYGjjV9EKwR2+BnCjPPZmDL+q4/vwfcLW2K8uM7laI+TP+3A==", "dev": true, "dependencies": { - "@abaplint/core": "^2.112.9", + "@abaplint/core": "^2.112.10", "source-map": "^0.7.4" }, "funding": { @@ -173,12 +173,12 @@ "dev": true }, "node_modules/@types/node": { - "version": "22.0.2", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.0.2.tgz", - "integrity": "sha512-yPL6DyFwY5PiMVEwymNeqUTKsDczQBJ/5T7W/46RwLU/VH+AA8aT5TZkvBviLKLbbm0hlfftEkGrNzfRk/fofQ==", + "version": "22.1.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.1.0.tgz", + "integrity": "sha512-AOmuRF0R2/5j1knA3c6G3HOk523Ga+l+ZXltX8SF1+5oqcXijjfTd8fY3XRZqSihEu9XhtQnKYLmkFaoxgsJHw==", "dev": true, "dependencies": { - "undici-types": "~6.11.1" + "undici-types": "~6.13.0" } }, "node_modules/@types/progress": { @@ -1371,9 +1371,9 @@ } }, "node_modules/undici-types": { - "version": "6.11.1", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.11.1.tgz", - "integrity": "sha512-mIDEX2ek50x0OlRgxryxsenE5XaQD4on5U2inY7RApK3SOJpofyw7uW2AyfMKkhAxXIceo2DeWGVGwyvng1GNQ==", + "version": "6.13.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.13.0.tgz", + "integrity": "sha512-xtFJHudx8S2DSoujjMd1WeWvn7KKWFRESZTMeL1RptAYERu29D6jphMjjY+vn96jvN3kVPDNxU/E13VTaXj6jg==", "dev": true }, "node_modules/update-browserslist-db": { @@ -1587,9 +1587,9 @@ }, "dependencies": { "@abaplint/core": { - "version": "2.112.9", - "resolved": "https://registry.npmjs.org/@abaplint/core/-/core-2.112.9.tgz", - "integrity": "sha512-4k4oSUX5xjpmJvsjrXdgfqN3NiYDKu8apAfHruNXPjoEezTjXrJi/AyQyGIpEiLWiDxzYIdgubcb7ilhmtlWig==", + "version": "2.112.10", + "resolved": "https://registry.npmjs.org/@abaplint/core/-/core-2.112.10.tgz", + "integrity": "sha512-o1tO8ZcYPW4Rn+DS2W+CYzFHgczqRH2G4asgNZaRKDqdNb4uXYJxuXiiGX2ki2rmOEB5JYm/qnJ035sbB75wHA==", "dev": true, "requires": { "fast-xml-parser": "^4.4.1", @@ -1598,12 +1598,12 @@ } }, "@abaplint/transpiler": { - "version": "2.10.6", - "resolved": "https://registry.npmjs.org/@abaplint/transpiler/-/transpiler-2.10.6.tgz", - "integrity": "sha512-IkwuopJfkJVmPaXE0fob4DVxoO9IF+etp2dJsqJNGkTF6+R+nRhsMeLZkf0M7zHmsiAf2wGb7o6Ypx+G6sSZKA==", + "version": "2.10.7", + "resolved": "https://registry.npmjs.org/@abaplint/transpiler/-/transpiler-2.10.7.tgz", + "integrity": "sha512-sj+rxkJFzxxvhpp69yY/DwisMIgySChMUQuFHHEYGjjV9EKwR2+BnCjPPZmDL+q4/vwfcLW2K8uM7laI+TP+3A==", "dev": true, "requires": { - "@abaplint/core": "^2.112.9", + "@abaplint/core": "^2.112.10", "source-map": "^0.7.4" } }, @@ -1711,12 +1711,12 @@ "dev": true }, "@types/node": { - "version": "22.0.2", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.0.2.tgz", - "integrity": "sha512-yPL6DyFwY5PiMVEwymNeqUTKsDczQBJ/5T7W/46RwLU/VH+AA8aT5TZkvBviLKLbbm0hlfftEkGrNzfRk/fofQ==", + "version": "22.1.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.1.0.tgz", + "integrity": "sha512-AOmuRF0R2/5j1knA3c6G3HOk523Ga+l+ZXltX8SF1+5oqcXijjfTd8fY3XRZqSihEu9XhtQnKYLmkFaoxgsJHw==", "dev": true, "requires": { - "undici-types": "~6.11.1" + "undici-types": "~6.13.0" } }, "@types/progress": { @@ -2605,9 +2605,9 @@ "dev": true }, "undici-types": { - "version": "6.11.1", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.11.1.tgz", - "integrity": "sha512-mIDEX2ek50x0OlRgxryxsenE5XaQD4on5U2inY7RApK3SOJpofyw7uW2AyfMKkhAxXIceo2DeWGVGwyvng1GNQ==", + "version": "6.13.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.13.0.tgz", + "integrity": "sha512-xtFJHudx8S2DSoujjMd1WeWvn7KKWFRESZTMeL1RptAYERu29D6jphMjjY+vn96jvN3kVPDNxU/E13VTaXj6jg==", "dev": true }, "update-browserslist-db": { diff --git a/packages/cli/package.json b/packages/cli/package.json index 5032368bb..81c87d1af 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@abaplint/transpiler-cli", - "version": "2.10.6", + "version": "2.10.7", "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.6", + "@abaplint/transpiler": "^2.10.7", "@types/glob": "^8.1.0", "glob": "=7.2.0", "@types/progress": "^2.0.7", - "@types/node": "^22.0.2", - "@abaplint/core": "^2.112.9", + "@types/node": "^22.1.0", + "@abaplint/core": "^2.112.10", "progress": "^2.0.3", "webpack": "^5.93.0", "webpack-cli": "^5.1.4", diff --git a/packages/runtime/package-lock.json b/packages/runtime/package-lock.json index 86e00a87f..7f385de14 100644 --- a/packages/runtime/package-lock.json +++ b/packages/runtime/package-lock.json @@ -1,12 +1,12 @@ { "name": "@abaplint/runtime", - "version": "2.10.6", + "version": "2.10.7", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@abaplint/runtime", - "version": "2.10.6", + "version": "2.10.7", "license": "MIT", "dependencies": { "temporal-polyfill": "^0.2.5" diff --git a/packages/runtime/package.json b/packages/runtime/package.json index f4e4496c9..fbe41c9e3 100644 --- a/packages/runtime/package.json +++ b/packages/runtime/package.json @@ -1,6 +1,6 @@ { "name": "@abaplint/runtime", - "version": "2.10.6", + "version": "2.10.7", "description": "Transpiler - Runtime", "main": "build/src/index.js", "typings": "build/src/index.d.ts", diff --git a/packages/runtime/src/statements/delete_internal.ts b/packages/runtime/src/statements/delete_internal.ts index 4f5fde85d..358aa1b8b 100644 --- a/packages/runtime/src/statements/delete_internal.ts +++ b/packages/runtime/src/statements/delete_internal.ts @@ -4,7 +4,7 @@ import {INumeric} from "../types/_numeric"; import {loop} from "./loop"; export interface IDeleteInternalOptions { - where?: (i: any) => boolean, + where?: (i: any) => Promise, index?: INumeric, adjacent?: boolean, comparing?: string[], @@ -98,7 +98,7 @@ export async function deleteInternal(target: Table | HashedTable | FieldSymbol, if (options?.where) { const row = i instanceof Structure ? i.get() : {table_line: i}; - if (options.where(row) === true) { + if (await options.where(row) === true) { if (target instanceof HashedTable) { target.deleteFrom(i); } else { diff --git a/packages/runtime/src/statements/replace.ts b/packages/runtime/src/statements/replace.ts index a890d0bf8..4b13c406d 100644 --- a/packages/runtime/src/statements/replace.ts +++ b/packages/runtime/src/statements/replace.ts @@ -9,6 +9,7 @@ export type replaceInput = { sectionLength?: INumeric, sectionOffset?: INumeric, replacementLength?: INumeric, + replacementCount?: INumeric, regex?: ICharacter, pcre?: ICharacter, all: boolean, @@ -53,7 +54,8 @@ export function replace(input: replaceInput): void { search = new RegExp(regex, ignoreCase + allOccurrences); found = temp.match(search) !== null; } else if (input.pcre) { - const regex = ABAPRegExp.convert(input.pcre.get()); + const str = input.pcre.get(); + const regex = ABAPRegExp.convert(str); if (regex.length === 0 && input.all === true) { throw "REPLACE, zero length input"; } @@ -96,6 +98,11 @@ export function replace(input: replaceInput): void { input.replacementLength.set(replacement.length); } + if (input.replacementCount) { + const match = temp.match(search); + input.replacementCount.set(match?.length || 0); + } + temp = temp.replace(search, rr); const subrc = found ? 0 : 4; diff --git a/packages/transpiler/package-lock.json b/packages/transpiler/package-lock.json index 1e931d6d3..3a6683b27 100644 --- a/packages/transpiler/package-lock.json +++ b/packages/transpiler/package-lock.json @@ -1,15 +1,15 @@ { "name": "@abaplint/transpiler", - "version": "2.10.6", + "version": "2.10.7", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@abaplint/transpiler", - "version": "2.10.6", + "version": "2.10.7", "license": "MIT", "dependencies": { - "@abaplint/core": "^2.112.9", + "@abaplint/core": "^2.112.10", "source-map": "^0.7.4" }, "devDependencies": { @@ -25,9 +25,9 @@ } }, "node_modules/@abaplint/core": { - "version": "2.112.9", - "resolved": "https://registry.npmjs.org/@abaplint/core/-/core-2.112.9.tgz", - "integrity": "sha512-4k4oSUX5xjpmJvsjrXdgfqN3NiYDKu8apAfHruNXPjoEezTjXrJi/AyQyGIpEiLWiDxzYIdgubcb7ilhmtlWig==", + "version": "2.112.10", + "resolved": "https://registry.npmjs.org/@abaplint/core/-/core-2.112.10.tgz", + "integrity": "sha512-o1tO8ZcYPW4Rn+DS2W+CYzFHgczqRH2G4asgNZaRKDqdNb4uXYJxuXiiGX2ki2rmOEB5JYm/qnJ035sbB75wHA==", "dependencies": { "fast-xml-parser": "^4.4.1", "json5": "^2.2.3", @@ -1075,9 +1075,9 @@ }, "dependencies": { "@abaplint/core": { - "version": "2.112.9", - "resolved": "https://registry.npmjs.org/@abaplint/core/-/core-2.112.9.tgz", - "integrity": "sha512-4k4oSUX5xjpmJvsjrXdgfqN3NiYDKu8apAfHruNXPjoEezTjXrJi/AyQyGIpEiLWiDxzYIdgubcb7ilhmtlWig==", + "version": "2.112.10", + "resolved": "https://registry.npmjs.org/@abaplint/core/-/core-2.112.10.tgz", + "integrity": "sha512-o1tO8ZcYPW4Rn+DS2W+CYzFHgczqRH2G4asgNZaRKDqdNb4uXYJxuXiiGX2ki2rmOEB5JYm/qnJ035sbB75wHA==", "requires": { "fast-xml-parser": "^4.4.1", "json5": "^2.2.3", diff --git a/packages/transpiler/package.json b/packages/transpiler/package.json index 19f7b81db..2620eb147 100644 --- a/packages/transpiler/package.json +++ b/packages/transpiler/package.json @@ -1,6 +1,6 @@ { "name": "@abaplint/transpiler", - "version": "2.10.6", + "version": "2.10.7", "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.112.9", + "@abaplint/core": "^2.112.10", "source-map": "^0.7.4" }, "devDependencies": { diff --git a/packages/transpiler/src/statements/delete_internal.ts b/packages/transpiler/src/statements/delete_internal.ts index 5b68f726b..49c9dd682 100644 --- a/packages/transpiler/src/statements/delete_internal.ts +++ b/packages/transpiler/src/statements/delete_internal.ts @@ -13,14 +13,13 @@ export class DeleteInternalTranspiler implements IStatementTranspiler { const componentCond = node.findDirectExpression(abaplint.Expressions.ComponentCond); if (componentCond) { - // todo, replacing "await" is a hack - extra.push("where: " + traversal.traverse(componentCond).getCode().replace("await ", "")); + extra.push("where: async " + traversal.traverse(componentCond).getCode()); } const componentCompare = node.findDirectExpression(abaplint.Expressions.ComponentCompare); if (componentCompare) { // todo: this can be optimized, WITH TABLE KEY - extra.push("where: " + traversal.traverse(componentCompare).getCode()); + extra.push("where: async " + traversal.traverse(componentCompare).getCode()); } // todo, this is not completely correct, fields might have the name ADJACENT diff --git a/packages/transpiler/src/statements/replace.ts b/packages/transpiler/src/statements/replace.ts index 70fa4e464..2e262fa90 100644 --- a/packages/transpiler/src/statements/replace.ts +++ b/packages/transpiler/src/statements/replace.ts @@ -26,6 +26,11 @@ export class ReplaceTranspiler implements IStatementTranspiler { extra.push("of: " + new SourceTranspiler().transpile(o, traversal).getCode()); } + const cnt = node.findExpressionAfterToken("COUNT"); + if (cnt) { + extra.push("replacementCount: " + new TargetTranspiler().transpile(cnt, traversal).getCode()); + } + const length = node.findExpressionAfterToken("LENGTH"); if (length) { if (length.get() instanceof abaplint.Expressions.Source) { diff --git a/packages/transpiler/test/single_statements.ts b/packages/transpiler/test/single_statements.ts index 43fe0afa4..914f89765 100644 --- a/packages/transpiler/test/single_statements.ts +++ b/packages/transpiler/test/single_statements.ts @@ -68,7 +68,7 @@ describe("Single statements", () => { {abap: "SPLIT foo AT bar INTO TABLE moo.", js: "abap.statements.split({source: foo, at: bar, table: moo});", skip: false}, {abap: "SPLIT |blah| AT '.' INTO lv_major lv_minor.", js: "abap.statements.split({source: new abap.types.String().set(`blah`), at: new abap.types.Character(1).set('.'), targets: [lv_major,lv_minor]});", skip: false}, {abap: "WRITE |moo|.", js: "abap.statements.write(new abap.types.String().set(`moo`));", skip: false}, - {abap: "DELETE foo WHERE bar = 2.", js: "await abap.statements.deleteInternal(foo,{where: (I) => {return abap.compare.eq(I.bar, abap.IntegerFactory.get(2));}});", skip: false}, + {abap: "DELETE foo WHERE bar = 2.", js: "await abap.statements.deleteInternal(foo,{where: async (I) => {return abap.compare.eq(I.bar, abap.IntegerFactory.get(2));}});", skip: false}, {abap: "DELETE ADJACENT DUPLICATES FROM foo.", js: "await abap.statements.deleteInternal(foo,{adjacent: true});", skip: false}, {abap: "DELETE foo INDEX 2.", js: "await abap.statements.deleteInternal(foo,{index: abap.IntegerFactory.get(2)});", skip: false}, {abap: "DELETE TABLE tab FROM .", js: "await abap.statements.deleteInternal(tab,{fromValue: fs_bar_});", skip: false}, @@ -220,7 +220,7 @@ describe("Single statements", () => { {abap: "MOVE-CORRESPONDING foo TO bar.", js: `abap.statements.moveCorresponding(foo, bar);`, skip: false}, {abap: "ASSERT 5 IN bar.", js: `abap.statements.assert(abap.compare.in(abap.IntegerFactory.get(5), bar));`, skip: false}, {abap: "INSERT INITIAL LINE INTO tab ASSIGNING INDEX 1.", js: `abap.statements.insertInternal({initial: true, index: abap.IntegerFactory.get(1), assigning: fs_row_, table: tab});`, skip: false}, - {abap: "DELETE lt_log_temp WHERE msg-level < iv_min_level.", js: `await abap.statements.deleteInternal(lt_log_temp,{where: (I) => {return abap.compare.lt(I.msg.get().level, iv_min_level);}});`, skip: false}, + {abap: "DELETE lt_log_temp WHERE msg-level < iv_min_level.", js: `await abap.statements.deleteInternal(lt_log_temp,{where: async (I) => {return abap.compare.lt(I.msg.get().level, iv_min_level);}});`, skip: false}, {abap: "ASSIGN lv_x TO CASTING.", js: `abap.statements.assign({target: fs_lv_y_, source: lv_x, casting: true});`, skip: false}, {abap: `CALL TRANSFORMATION id @@ -353,14 +353,14 @@ await abap.Classes['KERNEL_AUTHORITY_CHECK'].call({});`}, // todo WHERE item IS INITIAL AND NOT ( file-path = zif=>c_dir AND file-filename = zif=>c_dot ).`, - js: `await abap.statements.deleteInternal(ct_files,{where: (I) => {return abap.compare.initial(I.item) && !(abap.compare.eq(I.file.get().path, abap.Classes['ZIF'].c_dir) && abap.compare.eq(I.file.get().filename, abap.Classes['ZIF'].c_dot));}});`}, + js: `await abap.statements.deleteInternal(ct_files,{where: async (I) => {return abap.compare.initial(I.item) && !(abap.compare.eq(I.file.get().path, abap.Classes['ZIF'].c_dir) && abap.compare.eq(I.file.get().filename, abap.Classes['ZIF'].c_dot));}});`}, {abap: "lo_foo ?= lo_bar.", js: "await abap.statements.cast(lo_foo, lo_bar);", skip: false}, {abap: "RETRY.", js: `throw new Error("Retry, not supported, transpiler");`, skip: false}, {abap: "delete foo where instance->field_type not in types.", - js: `await abap.statements.deleteInternal(foo,{where: (I) => {return !abap.compare.in(I.instance.get().field_type, types);}});`, skip: false}, + js: `await abap.statements.deleteInternal(foo,{where: async (I) => {return !abap.compare.in(I.instance.get().field_type, types);}});`, skip: false}, {abap: "READ REPORT name INTO text STATE 'A'.", js: `abap.statements.readReport(name, {into: text,state: new abap.types.Character(1).set('A')});`, skip: false}, diff --git a/test/statements/delete_internal.ts b/test/statements/delete_internal.ts index 7895f1b7f..3fd9e3dee 100644 --- a/test/statements/delete_internal.ts +++ b/test/statements/delete_internal.ts @@ -498,4 +498,35 @@ ENDLOOP.`; expect(abap.console.get()).to.equal("1\n3"); }); + it("DELETE, with awaited statement", async () => { + const code = ` +CLASS lcl DEFINITION. + PUBLIC SECTION. + METHODS get_column_index RETURNING VALUE(index) TYPE i. + METHODS foo. +ENDCLASS. + +CLASS lcl IMPLEMENTATION. + METHOD get_column_index. + ENDMETHOD. + + METHOD foo. + TYPES: + BEGIN OF mty_s_hashed_column, + column_index TYPE i, + column TYPE REF TO object, + END OF mty_s_hashed_column, + mty_ts_hashed_column TYPE HASHED TABLE OF mty_s_hashed_column WITH UNIQUE KEY column_index. + + DATA columns_hashed TYPE mty_ts_hashed_column. + + DELETE TABLE columns_hashed WITH TABLE KEY column_index = get_column_index( ). + ENDMETHOD. +ENDCLASS.`; + const js = await run(code); + const f = new AsyncFunction("abap", js); + await f(abap); + // just test its valid syntax + }); + }); \ No newline at end of file diff --git a/test/statements/replace.ts b/test/statements/replace.ts index 64caba571..2ab57e19a 100644 --- a/test/statements/replace.ts +++ b/test/statements/replace.ts @@ -382,4 +382,64 @@ WRITE / sdummy.`; expect(abap.console.getTrimmed()).to.equal("32\n0894ef4577a91ed8a495bd69397619c0"); }); + it("REPLACE, PCRE and escaping", async () => { + const code = ` +DATA rcnt TYPE i. +DATA string_to_parse TYPE string. +string_to_parse = \`\\"\`. +REPLACE ALL OCCURRENCES OF PCRE \`\\\\\` IN string_to_parse WITH \`\\\\\` REPLACEMENT COUNT rcnt. +WRITE / rcnt.`; + + const js = await run(code); + const f = new AsyncFunction("abap", js); + await f(abap); + expect(abap.console.getTrimmed()).to.equal("1"); + }); + + /* + it.only("REPLACE, PCRE and escaping, more", async () => { + const code = ` +DATA rcnt TYPE i. +DATA string_to_parse TYPE string. +string_to_parse = \`\\"\`. +REPLACE ALL OCCURRENCES OF PCRE \`\\"\` IN string_to_parse WITH \`\\\\"\` REPLACEMENT COUNT rcnt. +ASSERT rcnt = 1. +WRITE / string_to_parse.`; + + const js = await run(code); + console.log(js); + const f = new AsyncFunction("abap", js); + await f(abap); + expect(abap.console.getTrimmed()).to.equal(`\\\\"`); + }); + */ + + it("REPLACE, PCRE and escaping, a", async () => { + const code = ` +DATA rcnt TYPE i. +DATA string_to_parse TYPE string. +string_to_parse = \`"\`. +REPLACE ALL OCCURRENCES OF PCRE \`"\` IN string_to_parse WITH \`a\` REPLACEMENT COUNT rcnt. +ASSERT rcnt = 1. +WRITE / string_to_parse.`; + + const js = await run(code); + const f = new AsyncFunction("abap", js); + await f(abap); + expect(abap.console.getTrimmed()).to.equal("a"); + }); + + it("REPLACE, basic PCRE", async () => { + const code = +`DATA link_for_testing TYPE string. +link_for_testing = 'foo bar'. +REPLACE ALL OCCURRENCES OF PCRE \`\\s\` IN link_for_testing WITH \`\`. +WRITE / link_for_testing.`; + + const js = await run(code); + const f = new AsyncFunction("abap", js); + await f(abap); + expect(abap.console.getTrimmed()).to.equal("foobar"); + }); + }); \ No newline at end of file