From c11972a3e2387f0a75415da4e962a1b8db784a07 Mon Sep 17 00:00:00 2001 From: Erik Hetzner Date: Thu, 4 Jun 2026 13:27:43 -0700 Subject: [PATCH 01/10] wip: make compilation work in the browser --- package-lock.json | 400 +++++++++++++++++++++++++++++++++++++++++++- package.json | 4 +- src/cli.ts | 2 +- src/compile.ts | 83 +-------- src/compilex.ts | 142 ++++++++++++++++ src/compilex.web.ts | 0 src/index.ts | 3 + test/suite.spec.ts | 2 +- test/xjslt.spec.ts | 2 +- webpack.config.ts | 34 ++++ 10 files changed, 585 insertions(+), 87 deletions(-) create mode 100644 src/compilex.ts create mode 100644 src/compilex.web.ts create mode 100644 src/index.ts create mode 100644 webpack.config.ts diff --git a/package-lock.json b/package-lock.json index c8a5c72..e8f7d6e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,8 +27,10 @@ "jest-simple-dot-reporter": "*", "prettier": "*", "ts-jest": "*", + "ts-loader": "^9.6.0", "ts-node": "*", - "typescript": "*" + "typescript": "*", + "webpack-cli": "*" }, "engines": { "node": ">=18" @@ -554,6 +556,16 @@ "@jridgewell/sourcemap-codec": "^1.4.10" } }, + "node_modules/@discoveryjs/json-ext": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@discoveryjs/json-ext/-/json-ext-1.1.0.tgz", + "integrity": "sha512-Xc3VhU02wqZ1HvHRJUwL09HkZSTvidqY5Ya0NXBSYOxAp+Ln9dcJr9fySI+CkONzP3PekQo9WdzCv0PGER/mOA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=14.17.0" + } + }, "node_modules/@emnapi/core": { "version": "1.10.0", "resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.10.0.tgz", @@ -2062,6 +2074,19 @@ "balanced-match": "^1.0.0" } }, + "node_modules/braces": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", + "dev": true, + "license": "MIT", + "dependencies": { + "fill-range": "^7.1.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/browserslist": { "version": "4.28.1", "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.28.1.tgz", @@ -2301,6 +2326,21 @@ "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, + "node_modules/clone-deep": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/clone-deep/-/clone-deep-4.0.1.tgz", + "integrity": "sha512-neHB9xuzh/wk0dIHweyAXv2aPGZIVk3pLMe+/RNzINf17fe0OG96QroktYAUm7SM1PBnzTabaLboqqxDyMU+SQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "is-plain-object": "^2.0.4", + "kind-of": "^6.0.2", + "shallow-clone": "^3.0.0" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/co": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", @@ -2493,6 +2533,19 @@ "node": ">=10.13.0" } }, + "node_modules/envinfo": { + "version": "7.21.0", + "resolved": "https://registry.npmjs.org/envinfo/-/envinfo-7.21.0.tgz", + "integrity": "sha512-Lw7I8Zp5YKHFCXL7+Dz95g4CcbMEpgvqZNNq3AmlT5XAV6CgAAk6gyAMqn2zjw08K9BHfcNuKrMiCPLByGafow==", + "dev": true, + "license": "MIT", + "bin": { + "envinfo": "dist/cli.js" + }, + "engines": { + "node": ">=4" + } + }, "node_modules/error-ex": { "version": "1.3.4", "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.4.tgz", @@ -2503,6 +2556,16 @@ "is-arrayish": "^0.2.1" } }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, "node_modules/es-module-lexer": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-2.1.0.tgz", @@ -2692,6 +2755,19 @@ "bser": "2.1.1" } }, + "node_modules/fill-range": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", + "dev": true, + "license": "MIT", + "dependencies": { + "to-regex-range": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/find-up": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", @@ -2706,6 +2782,16 @@ "node": ">=8" } }, + "node_modules/flat": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/flat/-/flat-5.0.2.tgz", + "integrity": "sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==", + "dev": true, + "license": "BSD-3-Clause", + "bin": { + "flat": "cli.js" + } + }, "node_modules/fontoxpath": { "version": "3.34.0", "resolved": "https://registry.npmjs.org/fontoxpath/-/fontoxpath-3.34.0.tgz", @@ -2755,6 +2841,16 @@ "node": "^8.16.0 || ^10.6.0 || >=11.0.0" } }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/gensync": { "version": "1.0.0-beta.2", "resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz", @@ -2863,6 +2959,19 @@ "node": ">=8" } }, + "node_modules/hasown": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz", + "integrity": "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==", + "dev": true, + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/html-escaper": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz", @@ -2929,6 +3038,16 @@ "dev": true, "license": "ISC" }, + "node_modules/interpret": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/interpret/-/interpret-3.1.1.tgz", + "integrity": "sha512-6xwYfHbajpoF0xLW+iwLkhwgvLoZDfjYfoFNu8ftMoXINzwuymNLd9u/KmwtdT2GbR+/Cz66otEGEVVUHX9QLQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=10.13.0" + } + }, "node_modules/is-arrayish": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", @@ -2936,6 +3055,22 @@ "dev": true, "license": "MIT" }, + "node_modules/is-core-module": { + "version": "2.16.2", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.16.2.tgz", + "integrity": "sha512-evOr8xfXKxE6qSR0hSXL2r3sd7ALj8+7jQEUvPYcm5sgZFdJ+AYzT6yNmJenvIYQBgIGwfwz08sL8zoL7yq2BA==", + "dev": true, + "license": "MIT", + "dependencies": { + "hasown": "^2.0.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/is-fullwidth-code-point": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", @@ -2956,6 +3091,29 @@ "node": ">=6" } }, + "node_modules/is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.12.0" + } + }, + "node_modules/is-plain-object": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz", + "integrity": "sha512-h5PpgXkWitc38BBMYawTYMWJHFZJVnBquFE57xFpjB8pJFiF6gZ+bU+WyI/yqXiFR5mdLsgYNaPe8uao6Uv9Og==", + "dev": true, + "license": "MIT", + "dependencies": { + "isobject": "^3.0.1" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/is-stream": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", @@ -2976,6 +3134,16 @@ "dev": true, "license": "ISC" }, + "node_modules/isobject": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz", + "integrity": "sha512-WhB9zCku7EGTj/HQQRz5aUQEUeoQZH2bWcltRErOpymJ4boYE6wL9Tbr23krRPSZ+C5zqNSrSw+Cc7sZZ4b7vg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/istanbul-lib-coverage": { "version": "3.2.2", "resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-3.2.2.tgz", @@ -3736,6 +3904,16 @@ "node": ">=6" } }, + "node_modules/kind-of": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz", + "integrity": "sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/leven": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/leven/-/leven-3.1.0.tgz", @@ -3848,6 +4026,33 @@ "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==", "license": "MIT" }, + "node_modules/micromatch": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", + "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", + "dev": true, + "license": "MIT", + "dependencies": { + "braces": "^3.0.3", + "picomatch": "^2.3.1" + }, + "engines": { + "node": ">=8.6" + } + }, + "node_modules/micromatch/node_modules/picomatch": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.2.tgz", + "integrity": "sha512-V7+vQEJ06Z+c5tSye8S+nHUfI51xoXIXjHQ99cQtKUkQqqO1kO/KCJUfZXuB47h/YBlDhah2H3hdUGXn8ie0oA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, "node_modules/mime-db": { "version": "1.54.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.54.0.tgz", @@ -4112,6 +4317,13 @@ "node": ">=8" } }, + "node_modules/path-parse": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", + "dev": true, + "license": "MIT" + }, "node_modules/path-scurry": { "version": "1.11.1", "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.11.1.tgz", @@ -4262,6 +4474,19 @@ "dev": true, "license": "MIT" }, + "node_modules/rechoir": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.8.0.tgz", + "integrity": "sha512-/vxpCXddiX8NGfGO/mTafwjq4aFa/71pvamip0++IQk3zG8cbCj0fifNPrjjF1XMXUne91jL9OoxmdykoEtifQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "resolve": "^1.20.0" + }, + "engines": { + "node": ">= 10.13.0" + } + }, "node_modules/require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -4281,6 +4506,28 @@ "node": ">=0.10.0" } }, + "node_modules/resolve": { + "version": "1.22.12", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.12.tgz", + "integrity": "sha512-TyeJ1zif53BPfHootBGwPRYT1RUt6oGWsaQr8UyZW/eAm9bKoijtvruSDEmZHm92CwS9nj7/fWttqPCgzep8CA==", + "dev": true, + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "is-core-module": "^2.16.1", + "path-parse": "^1.0.7", + "supports-preserve-symlinks-flag": "^1.0.0" + }, + "bin": { + "resolve": "bin/resolve" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/resolve-cwd": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/resolve-cwd/-/resolve-cwd-3.0.0.tgz", @@ -4333,6 +4580,19 @@ "semver": "bin/semver.js" } }, + "node_modules/shallow-clone": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/shallow-clone/-/shallow-clone-3.0.1.tgz", + "integrity": "sha512-/6KqX+GVUdqPuPPd2LxDDxzX6CAbjJehAAOKlNpqqUpAqPM6HeL8f+o3a+JsyGjn2lv0WY8UsTgUJjU9Ok55NA==", + "dev": true, + "license": "MIT", + "dependencies": { + "kind-of": "^6.0.2" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/shebang-command": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", @@ -4612,6 +4872,19 @@ "node": ">=8" } }, + "node_modules/supports-preserve-symlinks-flag": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", + "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/synckit": { "version": "0.11.12", "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.11.12.tgz", @@ -4832,6 +5105,19 @@ "dev": true, "license": "BSD-3-Clause" }, + "node_modules/to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "is-number": "^7.0.0" + }, + "engines": { + "node": ">=8.0" + } + }, "node_modules/ts-jest": { "version": "29.4.10", "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-29.4.10.tgz", @@ -4911,6 +5197,56 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/ts-loader": { + "version": "9.6.0", + "resolved": "https://registry.npmjs.org/ts-loader/-/ts-loader-9.6.0.tgz", + "integrity": "sha512-dsJO0S+T7grTDWTc4a0nTygXGjKncVUpx8Y+af8EvI/D5WgTJby5UEk5eoMCB9EcLQmnvitqh99MqtjtHgAwFQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "chalk": "^4.1.0", + "enhanced-resolve": "^5.0.0", + "micromatch": "^4.0.0", + "semver": "^7.3.4", + "source-map": "^0.7.4" + }, + "engines": { + "node": ">=12.0.0" + }, + "peerDependencies": { + "loader-utils": "*", + "typescript": "*", + "webpack": "^4.0.0 || ^5.0.0" + }, + "peerDependenciesMeta": { + "loader-utils": { + "optional": true + } + } + }, + "node_modules/ts-loader/node_modules/semver": { + "version": "7.8.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.2.tgz", + "integrity": "sha512-c8jsqUZm3omBOI66G90z1Dyw5z622G8oLG+omfsHBJf3CWQTlOcwOjvOG6wtiNfW6anKm/eA39LMwMtMez2TiQ==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/ts-loader/node_modules/source-map": { + "version": "0.7.6", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.6.tgz", + "integrity": "sha512-i5uvt8C3ikiWeNZSVZNWcfZPItFQOsYTUAOkcUPGd8DqDy1uOUikjt5dG+uRlwyvR108Fb9DOd4GvXfT0N2/uQ==", + "dev": true, + "license": "BSD-3-Clause", + "engines": { + "node": ">= 12" + } + }, "node_modules/ts-node": { "version": "10.9.2", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", @@ -5179,6 +5515,61 @@ } } }, + "node_modules/webpack-cli": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/webpack-cli/-/webpack-cli-7.0.3.tgz", + "integrity": "sha512-2E2C6A1e2El7791zQgTH7LPIuwLjRliow9OHS/qlJc9pwhZlCoL/uiwqd/1WSlXT83wJfmfDbkcqHXuXoPJZ3g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@discoveryjs/json-ext": "^1.1.0", + "commander": "^14.0.3", + "cross-spawn": "^7.0.6", + "envinfo": "^7.14.0", + "import-local": "^3.0.2", + "interpret": "^3.1.1", + "rechoir": "^0.8.0", + "webpack-merge": "^6.0.1" + }, + "bin": { + "webpack-cli": "bin/cli.js" + }, + "engines": { + "node": ">=20.9.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/webpack" + }, + "peerDependencies": { + "webpack": "^5.101.0", + "webpack-bundle-analyzer": "^4.0.0 || ^5.0.0", + "webpack-dev-server": "^5.0.0" + }, + "peerDependenciesMeta": { + "webpack-bundle-analyzer": { + "optional": true + }, + "webpack-dev-server": { + "optional": true + } + } + }, + "node_modules/webpack-merge": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/webpack-merge/-/webpack-merge-6.0.1.tgz", + "integrity": "sha512-hXXvrjtx2PLYx4qruKl+kyRSLc52V+cCvMxRjmKwoA+CBbbF5GfIBtR6kCvl0fYGqTUPKB+1ktVmTHqMOzgCBg==", + "dev": true, + "license": "MIT", + "dependencies": { + "clone-deep": "^4.0.1", + "flat": "^5.0.2", + "wildcard": "^2.0.1" + }, + "engines": { + "node": ">=18.0.0" + } + }, "node_modules/webpack-sources": { "version": "3.4.1", "resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-3.4.1.tgz", @@ -5210,6 +5601,13 @@ "integrity": "sha512-cGGfDPYYqoHoMWqXVc3G+N74u1FhFhrBa+pOO906b9ktRc/JFUdwroTkfPqjKzyoCLVcKr6yy6bYIcWT7jTg2A==", "license": "MIT" }, + "node_modules/wildcard": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/wildcard/-/wildcard-2.0.1.tgz", + "integrity": "sha512-CC1bOL87PIWSBhDcTrdeLo6eGT7mCFtrg0uIJtqJUFyK+eJnzl8A1niH56uu7KMa5XFrtiV+AQuHO3n7DsHnLQ==", + "dev": true, + "license": "MIT" + }, "node_modules/wordwrap": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", diff --git a/package.json b/package.json index bf5cd1c..9731430 100644 --- a/package.json +++ b/package.json @@ -51,8 +51,10 @@ "jest-simple-dot-reporter": "*", "prettier": "*", "ts-jest": "*", + "ts-loader": "^9.6.0", "ts-node": "*", - "typescript": "*" + "typescript": "*", + "webpack-cli": "*" }, "dependencies": { "@types/estree": "^1.0.8", diff --git a/src/cli.ts b/src/cli.ts index c7f09fe..ccdc4c8 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -21,7 +21,7 @@ import * as slimdom from "slimdom"; import { Command, Option } from "commander"; -import { compileFromPath, compileToFile } from "./compile"; +import { compileFromPath, compileToFile } from "./compilex"; import { serialize } from "./xjslt"; import { readFile, writeFile } from "fs/promises"; import { pathToFileURL } from "url"; diff --git a/src/compile.ts b/src/compile.ts index d342b33..466c9a2 100644 --- a/src/compile.ts +++ b/src/compile.ts @@ -50,12 +50,6 @@ import { evaluateXPathToBoolean, evaluateXPathToNodes, } from "fontoxpath"; -import { readFileSync, writeFileSync, symlinkSync } from "fs"; -import { readFile, symlink, writeFile } from "fs/promises"; -import { pathToFileURL, fileURLToPath } from "url"; -import * as path from "path"; -import { tmpdir } from "os"; -import { mkdtempSync } from "fs"; import preprocessSimplified from "./preprocess/simplified"; import preprocessInclude from "./preprocess/include"; import preprocessImport from "./preprocess/import"; @@ -74,7 +68,6 @@ import { DecimalFormat, DEFAULT_DECIMAL_FORMAT, xpathstring, - Rule, TemplateForCompilation, TemplateIndex, StylesheetTransform, @@ -1456,7 +1449,7 @@ function compileAvt(avt: string | null) { } } -function preprocess( +export function preprocess( doc: slimdom.Document, inputURL: URL, readDocument: (uri: string) => slimdom.Document, @@ -1555,77 +1548,3 @@ export function compile( new Function("xjslt", "module", code)(xjslt, m); return m.exports.transform; } - -function mkFsReadDocument(): (uri: string) => slimdom.Document { - return (uri: string) => { - if (uri.startsWith("file:")) { - return slimdom.parseXmlDocument( - readFileSync(fileURLToPath(new URL(uri))).toString(), - ); - } - throw new Error(`FODC0005: document ${uri} not found`); - }; -} - -async function readAndParseXml(path: string): Promise { - const str = (await readFile(path)).toString(); - return slimdom.parseXmlDocument(str); -} - -function readAndParseXmlSync(path: string): slimdom.Document { - const str = readFileSync(path).toString(); - return slimdom.parseXmlDocument(str); -} - -export async function compileToFile(xsltPath: string) { - let slimdom_path = require.resolve("slimdom").split(path.sep); - let root_dir = path.join( - "/", - ...slimdom_path.slice(0, slimdom_path.indexOf("node_modules")), - ); - var tempdir = mkdtempSync(path.join(tmpdir(), "xjslt-")); - symlinkSync( - path.join(root_dir, "node_modules"), - path.join(tempdir, "node_modules"), - ); - symlinkSync( - path.join(root_dir, "package.json"), - path.join(tempdir, "package.json"), - ); - symlinkSync(path.join(root_dir, "dist"), path.join(tempdir, "dist")); - var tempfile = path.join(tempdir, "transform.js"); - const xsltURL = pathToFileURL(xsltPath); - const xsltDoc = await preprocess( - await readAndParseXml(xsltPath), - xsltURL, - mkFsReadDocument(), - ); - await writeFile( - tempfile, - generate(compileStylesheetNode(xsltDoc.documentElement)), - ); - return tempfile; - // rmSync(tempdir, { recursive: true }); -} - -/** - * Build a stylesheet. Returns a function that will take an input DOM - * document and return an output DOM document. - */ -export async function compileFromPath( - xsltPath: string, -): Promise { - return compile( - await readAndParseXml(xsltPath), - mkFsReadDocument(), - pathToFileURL(xsltPath), - ); -} - -export function compileFromPathSync(xsltPath: string): StylesheetTransform { - return compile( - readAndParseXmlSync(xsltPath), - mkFsReadDocument(), - pathToFileURL(xsltPath), - ); -} diff --git a/src/compilex.ts b/src/compilex.ts new file mode 100644 index 0000000..cb74327 --- /dev/null +++ b/src/compilex.ts @@ -0,0 +1,142 @@ +/* + * Copyright (C) 2021-2026 Erik Hetzner + * + * This file is part of XJSLT. + * + * XJSLT is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * XJSLT is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with XJSLT. If not, see + * . + */ + +import { generate } from "astring"; +import { + mkArray, + mkArrowFun, + mkBlock, + mkCall, + mkCallWithContext, + mkFun, + mkIdentifier, + mkImportsNode, + mkLet, + mkLiteral, + mkMember, + mkNew, + mkReturn, + toEstree, +} from "./estree-util"; +import { + Expression, + ExpressionStatement, + ObjectExpression, + Program, + Statement, +} from "estree"; +import * as slimdom from "slimdom"; +import * as xjslt from "./xjslt"; +import { + compileXPathToJavaScript, + evaluateXPath, + evaluateXPathToBoolean, + evaluateXPathToNodes, +} from "fontoxpath"; +import { readFileSync, symlinkSync } from "fs"; +import { readFile, writeFile } from "fs/promises"; +import { pathToFileURL, fileURLToPath } from "url"; +import * as path from "path"; +import { tmpdir } from "os"; +import { mkdtempSync } from "fs"; +import { StylesheetTransform } from "./definitions"; +import { + compareSortable, + computeDefaultPriority, + isAlphanumeric, + mkOutputDefinition, + mkResolver, + sortSortable, +} from "./shared"; +import { compile, compileStylesheetNode, preprocess } from "./compile"; + +async function readAndParseXml(path: string): Promise { + const str = (await readFile(path)).toString(); + return slimdom.parseXmlDocument(str); +} + +function readAndParseXmlSync(path: string): slimdom.Document { + const str = readFileSync(path).toString(); + return slimdom.parseXmlDocument(str); +} + +/** + * Build a stylesheet. Returns a function that will take an input DOM + * document and return an output DOM document. + */ +export async function compileFromPath( + xsltPath: string, +): Promise { + return compile( + await readAndParseXml(xsltPath), + mkFsReadDocument(), + pathToFileURL(xsltPath), + ); +} + +export function compileFromPathSync(xsltPath: string): StylesheetTransform { + return compile( + readAndParseXmlSync(xsltPath), + mkFsReadDocument(), + pathToFileURL(xsltPath), + ); +} + +export async function compileToFile(xsltPath: string) { + let slimdom_path = require.resolve("slimdom").split(path.sep); + let root_dir = path.join( + "/", + ...slimdom_path.slice(0, slimdom_path.indexOf("node_modules")), + ); + var tempdir = mkdtempSync(path.join(tmpdir(), "xjslt-")); + symlinkSync( + path.join(root_dir, "node_modules"), + path.join(tempdir, "node_modules"), + ); + symlinkSync( + path.join(root_dir, "package.json"), + path.join(tempdir, "package.json"), + ); + symlinkSync(path.join(root_dir, "dist"), path.join(tempdir, "dist")); + var tempfile = path.join(tempdir, "transform.js"); + const xsltURL = pathToFileURL(xsltPath); + const xsltDoc = await preprocess( + await readAndParseXml(xsltPath), + xsltURL, + mkFsReadDocument(), + ); + await writeFile( + tempfile, + generate(compileStylesheetNode(xsltDoc.documentElement)), + ); + return tempfile; + // rmSync(tempdir, { recursive: true }); +} + +function mkFsReadDocument(): (uri: string) => slimdom.Document { + return (uri: string) => { + if (uri.startsWith("file:")) { + return slimdom.parseXmlDocument( + readFileSync(fileURLToPath(new URL(uri))).toString(), + ); + } + throw new Error(`FODC0005: document ${uri} not found`); + }; +} diff --git a/src/compilex.web.ts b/src/compilex.web.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..23102b8 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,3 @@ +import { compile } from "./compile"; + +export { compile }; diff --git a/test/suite.spec.ts b/test/suite.spec.ts index 7f90849..b8b5273 100644 --- a/test/suite.spec.ts +++ b/test/suite.spec.ts @@ -19,7 +19,7 @@ */ import { log } from "console"; -import { compileFromPathSync } from "../src/compile"; +import { compileFromPathSync } from "../src/compilex"; import * as slimdom from "slimdom"; import * as path from "path"; import { diff --git a/test/xjslt.spec.ts b/test/xjslt.spec.ts index 1b5d4b7..e7c33e8 100644 --- a/test/xjslt.spec.ts +++ b/test/xjslt.spec.ts @@ -32,13 +32,13 @@ import { dedupGenerator, } from "../src/xjslt"; import { - compileFromPath, compile, compileAvtRaw, compileSequenceConstructorNode, compileTopLevelNode, getNodeNS, } from "../src/compile"; +import { compileFromPath } from "../src/compilex"; import { DynamicContext, Template, diff --git a/webpack.config.ts b/webpack.config.ts new file mode 100644 index 0000000..0cf36d4 --- /dev/null +++ b/webpack.config.ts @@ -0,0 +1,34 @@ +import path from "node:path"; +import { fileURLToPath } from "url"; +import webpack from "webpack"; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +const config: webpack.Configuration = { + entry: "./src/index.ts", + "mode": "production", + module: { + rules: [ + { + test: /\.ts$/, + use: "ts-loader", + exclude: /node_modules/, + }, + ], + }, + resolve: { + extensions: [".web.ts", ".web.js", ".ts", ".js"], + }, + output: { + library: { + name: "xjslt", + type: "umd", + export: "xjslt.compile", + }, + filename: "xjslt-web.js", + path: path.resolve(__dirname, "dist"), + }, +}; + +export default config; From 7ee65de57c983cf85c9c86e38144bd04d2eabd21 Mon Sep 17 00:00:00 2001 From: Erik Hetzner Date: Mon, 8 Jun 2026 13:09:25 -0700 Subject: [PATCH 02/10] run tests in jsdom as well --- jest.config.ts | 16 +- package-lock.json | 576 +++++++++++++++++++++++++++++++++++++++++++++ package.json | 4 + test/xjslt.spec.ts | 13 +- 4 files changed, 597 insertions(+), 12 deletions(-) diff --git a/jest.config.ts b/jest.config.ts index 1ad2cb8..87c7234 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -1,7 +1,17 @@ export default { coveragePathIgnorePatterns: ["src/preprocess"], - preset: "ts-jest", - testEnvironment: "node", reporters: [["jest-simple-dot-reporter", { color: true }]], - testPathIgnorePatterns: ["examples"], + projects: [ + { + displayName: "node", + preset: "ts-jest", + testEnvironment: "node", + // testPathIgnorePatterns: ["examples"], + }, + { + displayName: "jsdom", + preset: "ts-jest", + testEnvironment: "jsdom", + }, + ], }; diff --git a/package-lock.json b/package-lock.json index e8f7d6e..9d2ea32 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,6 +24,7 @@ "devDependencies": { "@types/jest": "*", "jest": "*", + "jest-environment-jsdom": "^30.4.1", "jest-simple-dot-reporter": "*", "prettier": "*", "ts-jest": "*", @@ -36,6 +37,27 @@ "node": ">=18" } }, + "node_modules/@asamuzakjp/css-color": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/@asamuzakjp/css-color/-/css-color-3.2.0.tgz", + "integrity": "sha512-K1A6z8tS3XsmCMM86xoWdn7Fkdn9m6RSVtocUrJYIwZnFVkng/PvkEoWtOWmP+Scc6saYWHWZYbndEEXxl24jw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@csstools/css-calc": "^2.1.3", + "@csstools/css-color-parser": "^3.0.9", + "@csstools/css-parser-algorithms": "^3.0.4", + "@csstools/css-tokenizer": "^3.0.3", + "lru-cache": "^10.4.3" + } + }, + "node_modules/@asamuzakjp/css-color/node_modules/lru-cache": { + "version": "10.4.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.3.tgz", + "integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==", + "dev": true, + "license": "ISC" + }, "node_modules/@babel/code-frame": { "version": "7.29.0", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.29.0.tgz", @@ -556,6 +578,121 @@ "@jridgewell/sourcemap-codec": "^1.4.10" } }, + "node_modules/@csstools/color-helpers": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@csstools/color-helpers/-/color-helpers-5.1.0.tgz", + "integrity": "sha512-S11EXWJyy0Mz5SYvRmY8nJYTFFd1LCNV+7cXyAgQtOOuzb4EsgfqDufL+9esx72/eLhsRdGZwaldu/h+E4t4BA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/csstools" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/csstools" + } + ], + "license": "MIT-0", + "engines": { + "node": ">=18" + } + }, + "node_modules/@csstools/css-calc": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/@csstools/css-calc/-/css-calc-2.1.4.tgz", + "integrity": "sha512-3N8oaj+0juUw/1H3YwmDDJXCgTB1gKU6Hc/bB502u9zR0q2vd786XJH9QfrKIEgFlZmhZiq6epXl4rHqhzsIgQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/csstools" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/csstools" + } + ], + "license": "MIT", + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "@csstools/css-parser-algorithms": "^3.0.5", + "@csstools/css-tokenizer": "^3.0.4" + } + }, + "node_modules/@csstools/css-color-parser": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@csstools/css-color-parser/-/css-color-parser-3.1.0.tgz", + "integrity": "sha512-nbtKwh3a6xNVIp/VRuXV64yTKnb1IjTAEEh3irzS+HkKjAOYLTGNb9pmVNntZ8iVBHcWDA2Dof0QtPgFI1BaTA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/csstools" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/csstools" + } + ], + "license": "MIT", + "dependencies": { + "@csstools/color-helpers": "^5.1.0", + "@csstools/css-calc": "^2.1.4" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "@csstools/css-parser-algorithms": "^3.0.5", + "@csstools/css-tokenizer": "^3.0.4" + } + }, + "node_modules/@csstools/css-parser-algorithms": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/@csstools/css-parser-algorithms/-/css-parser-algorithms-3.0.5.tgz", + "integrity": "sha512-DaDeUkXZKjdGhgYaHNJTV9pV7Y9B3b644jCLs9Upc3VeNGg6LWARAT6O+Q+/COo+2gg/bM5rhpMAtf70WqfBdQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/csstools" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/csstools" + } + ], + "license": "MIT", + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "@csstools/css-tokenizer": "^3.0.4" + } + }, + "node_modules/@csstools/css-tokenizer": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/@csstools/css-tokenizer/-/css-tokenizer-3.0.4.tgz", + "integrity": "sha512-Vd/9EVDiu6PPJt9yAh6roZP6El1xHrdvIVGjyBsHR0RYwNHgL7FJPyIIW4fANJNG6FtyZfvlRPpFI4ZM/lubvw==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/csstools" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/csstools" + } + ], + "license": "MIT", + "engines": { + "node": ">=18" + } + }, "node_modules/@discoveryjs/json-ext": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@discoveryjs/json-ext/-/json-ext-1.1.0.tgz", @@ -737,6 +874,34 @@ "node": "^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0" } }, + "node_modules/@jest/environment-jsdom-abstract": { + "version": "30.4.1", + "resolved": "https://registry.npmjs.org/@jest/environment-jsdom-abstract/-/environment-jsdom-abstract-30.4.1.tgz", + "integrity": "sha512-dSlKrqug3siYNHVnjwIldShY12wAH3spwRltO/+8VOjg0X+xEq7vOs3DbBs4LRKsu7OH+NUb9kuZUNBF9Ho3TA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jest/environment": "30.4.1", + "@jest/fake-timers": "30.4.1", + "@jest/types": "30.4.1", + "@types/jsdom": "^21.1.7", + "@types/node": "*", + "jest-mock": "30.4.1", + "jest-util": "30.4.1" + }, + "engines": { + "node": "^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0" + }, + "peerDependencies": { + "canvas": "^3.0.0", + "jsdom": "*" + }, + "peerDependenciesMeta": { + "canvas": { + "optional": true + } + } + }, "node_modules/@jest/expect": { "version": "30.4.1", "resolved": "https://registry.npmjs.org/@jest/expect/-/expect-30.4.1.tgz", @@ -1240,6 +1405,18 @@ "pretty-format": "^30.0.0" } }, + "node_modules/@types/jsdom": { + "version": "21.1.7", + "resolved": "https://registry.npmjs.org/@types/jsdom/-/jsdom-21.1.7.tgz", + "integrity": "sha512-yOriVnggzrnQ3a9OKOCxaVuSug3w3/SbOj5i7VwXWZEyUNl3bLF9V3MfxGbZKuwqJOQyRfqXyROBB1CoZLFWzA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*", + "@types/tough-cookie": "*", + "parse5": "^7.0.0" + } + }, "node_modules/@types/json-schema": { "version": "7.0.15", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", @@ -1262,6 +1439,13 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/tough-cookie": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-4.0.5.tgz", + "integrity": "sha512-/Ad8+nIOV7Rl++6f1BdKxFSMgmoqEoYbHRpPcx3JEfv8VRsQe9Z4mCXeJBzxs7mbHY/XOZZuXlRNfhpVPbs6ZA==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/yargs": { "version": "17.0.35", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.35.tgz", @@ -1803,6 +1987,16 @@ "node": ">=0.4.0" } }, + "node_modules/agent-base": { + "version": "7.1.4", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.4.tgz", + "integrity": "sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 14" + } + }, "node_modules/ajv": { "version": "8.20.0", "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.20.0.tgz", @@ -2424,6 +2618,34 @@ "node": ">= 8" } }, + "node_modules/cssstyle": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/cssstyle/-/cssstyle-4.6.0.tgz", + "integrity": "sha512-2z+rWdzbbSZv6/rhtvzvqeZQHrBaqgogqt85sqFNbabZOuFbCVFb8kPeEtZjiKkbrm395irpNKiYeFeLiQnFPg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@asamuzakjp/css-color": "^3.2.0", + "rrweb-cssom": "^0.8.0" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/data-urls": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/data-urls/-/data-urls-5.0.0.tgz", + "integrity": "sha512-ZYP5VBHshaDAiVZxjbRVcFJpc+4xGgT0bK3vzy1HLN8jTO975HEbuYzZJcHoQEY5K1a0z8YayJkyVETa08eNTg==", + "dev": true, + "license": "MIT", + "dependencies": { + "whatwg-mimetype": "^4.0.0", + "whatwg-url": "^14.0.0" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/debug": { "version": "4.4.3", "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", @@ -2442,6 +2664,13 @@ } } }, + "node_modules/decimal.js": { + "version": "10.6.0", + "resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-10.6.0.tgz", + "integrity": "sha512-YpgQiITW3JXGntzdUmyUR1V812Hn8T1YVXhCu+wO3OpS4eU9l4YdD3qjyiKdV6mvV29zapkMeD390UVEf2lkUg==", + "dev": true, + "license": "MIT" + }, "node_modules/dedent": { "version": "1.7.2", "resolved": "https://registry.npmjs.org/dedent/-/dedent-1.7.2.tgz", @@ -2533,6 +2762,19 @@ "node": ">=10.13.0" } }, + "node_modules/entities": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/entities/-/entities-6.0.1.tgz", + "integrity": "sha512-aN97NXWF6AWBTahfVOIrB/NShkzi5H7F9r1s9mD3cDj4Ko5f2qhhVoYMibXF7GlLveb/D2ioWay8lxI97Ven3g==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=0.12" + }, + "funding": { + "url": "https://github.com/fb55/entities?sponsor=1" + } + }, "node_modules/envinfo": { "version": "7.21.0", "resolved": "https://registry.npmjs.org/envinfo/-/envinfo-7.21.0.tgz", @@ -2972,6 +3214,19 @@ "node": ">= 0.4" } }, + "node_modules/html-encoding-sniffer": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-4.0.0.tgz", + "integrity": "sha512-Y22oTqIU4uuPgEemfz7NDJz6OeKf12Lsu+QC+s3BVpda64lTiMYCyGwg5ki4vFxkMwQdeZDl2adZoqUgdFuTgQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "whatwg-encoding": "^3.1.1" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/html-escaper": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz", @@ -2979,6 +3234,34 @@ "dev": true, "license": "MIT" }, + "node_modules/http-proxy-agent": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-7.0.2.tgz", + "integrity": "sha512-T1gkAiYYDWYx3V5Bmyu7HcfcvL7mUrTWiM6yOfa3PIphViJ/gFPbvidQ+veqSOHci/PxBcDabeUNCzpOODJZig==", + "dev": true, + "license": "MIT", + "dependencies": { + "agent-base": "^7.1.0", + "debug": "^4.3.4" + }, + "engines": { + "node": ">= 14" + } + }, + "node_modules/https-proxy-agent": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.6.tgz", + "integrity": "sha512-vK9P5/iUfdl95AI+JVyUuIcVtd4ofvtrOr3HNtM2yxC9bnMbEdp3x01OhQNnjb8IJYi38VlTE3mBXwcfvywuSw==", + "dev": true, + "license": "MIT", + "dependencies": { + "agent-base": "^7.1.2", + "debug": "4" + }, + "engines": { + "node": ">= 14" + } + }, "node_modules/human-signals": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", @@ -2989,6 +3272,19 @@ "node": ">=10.17.0" } }, + "node_modules/iconv-lite": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", + "dev": true, + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/import-local": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/import-local/-/import-local-3.2.0.tgz", @@ -3114,6 +3410,13 @@ "node": ">=0.10.0" } }, + "node_modules/is-potential-custom-element-name": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-potential-custom-element-name/-/is-potential-custom-element-name-1.0.1.tgz", + "integrity": "sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==", + "dev": true, + "license": "MIT" + }, "node_modules/is-stream": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", @@ -3448,6 +3751,29 @@ "node": "^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0" } }, + "node_modules/jest-environment-jsdom": { + "version": "30.4.1", + "resolved": "https://registry.npmjs.org/jest-environment-jsdom/-/jest-environment-jsdom-30.4.1.tgz", + "integrity": "sha512-o3nfaN4zej7qgk2X0j8Jhq/S9nAVKs2xK3QeQxeHVvpkEPxaA1yxDGydR+iVI7zPy7Cp62Aq2h3Ja46QvfWHGA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jest/environment": "30.4.1", + "@jest/environment-jsdom-abstract": "30.4.1", + "jsdom": "^26.1.0" + }, + "engines": { + "node": "^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0" + }, + "peerDependencies": { + "canvas": "^3.0.0" + }, + "peerDependenciesMeta": { + "canvas": { + "optional": true + } + } + }, "node_modules/jest-environment-node": { "version": "30.4.1", "resolved": "https://registry.npmjs.org/jest-environment-node/-/jest-environment-node-30.4.1.tgz", @@ -3865,6 +4191,46 @@ "js-yaml": "bin/js-yaml.js" } }, + "node_modules/jsdom": { + "version": "26.1.0", + "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-26.1.0.tgz", + "integrity": "sha512-Cvc9WUhxSMEo4McES3P7oK3QaXldCfNWp7pl2NNeiIFlCoLr3kfq9kb1fxftiwk1FLV7CvpvDfonxtzUDeSOPg==", + "dev": true, + "license": "MIT", + "dependencies": { + "cssstyle": "^4.2.1", + "data-urls": "^5.0.0", + "decimal.js": "^10.5.0", + "html-encoding-sniffer": "^4.0.0", + "http-proxy-agent": "^7.0.2", + "https-proxy-agent": "^7.0.6", + "is-potential-custom-element-name": "^1.0.1", + "nwsapi": "^2.2.16", + "parse5": "^7.2.1", + "rrweb-cssom": "^0.8.0", + "saxes": "^6.0.0", + "symbol-tree": "^3.2.4", + "tough-cookie": "^5.1.1", + "w3c-xmlserializer": "^5.0.0", + "webidl-conversions": "^7.0.0", + "whatwg-encoding": "^3.1.1", + "whatwg-mimetype": "^4.0.0", + "whatwg-url": "^14.1.1", + "ws": "^8.18.0", + "xml-name-validator": "^5.0.0" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "canvas": "^3.0.0" + }, + "peerDependenciesMeta": { + "canvas": { + "optional": true + } + } + }, "node_modules/jsesc": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-3.1.0.tgz", @@ -4180,6 +4546,13 @@ "node": ">=8" } }, + "node_modules/nwsapi": { + "version": "2.2.24", + "resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.2.24.tgz", + "integrity": "sha512-7YRhZ3jS45LwmSCT4b2sVFHt/WuovaktDU07QrtOBY2PXskss5a9jfmR9jptyumwXST+rFjrmppMY1KT/yn35A==", + "dev": true, + "license": "MIT" + }, "node_modules/once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -4287,6 +4660,19 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/parse5": { + "version": "7.3.0", + "resolved": "https://registry.npmjs.org/parse5/-/parse5-7.3.0.tgz", + "integrity": "sha512-IInvU7fabl34qmi9gY8XOVxhYyMyuH2xUNpb2q8/Y+7552KlejkRvqvD19nMoUW/uQGGbqNpA6Tufu5FL5BZgw==", + "dev": true, + "license": "MIT", + "dependencies": { + "entities": "^6.0.0" + }, + "funding": { + "url": "https://github.com/inikulin/parse5?sponsor=1" + } + }, "node_modules/path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", @@ -4441,6 +4827,16 @@ "integrity": "sha512-OmXQ2v76RlXNx/gqv7+oB6jyKnudJ/rsMfAIVexhbDFxXAJPoWKMxJkZU2ohlu4miCiSQCG+horf2DV4/kNc1Q==", "license": "MIT" }, + "node_modules/punycode": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", + "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/pure-rand": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/pure-rand/-/pure-rand-7.0.1.tgz", @@ -4551,6 +4947,33 @@ "node": ">=8" } }, + "node_modules/rrweb-cssom": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/rrweb-cssom/-/rrweb-cssom-0.8.0.tgz", + "integrity": "sha512-guoltQEx+9aMf2gDZ0s62EcV8lsXR+0w8915TC3ITdn2YueuNjdAYh/levpU9nFaoChh9RUS5ZdQMrKfVEN9tw==", + "dev": true, + "license": "MIT" + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "dev": true, + "license": "MIT" + }, + "node_modules/saxes": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/saxes/-/saxes-6.0.0.tgz", + "integrity": "sha512-xAg7SOnEhrm5zI3puOOKyy1OMcMlIJZYNJY7xLBwSze0UjhPLnWfj2GF2EpT0jmzaJKIWKHLsaSSajf35bcYnA==", + "dev": true, + "license": "ISC", + "dependencies": { + "xmlchars": "^2.2.0" + }, + "engines": { + "node": ">=v12.22.7" + } + }, "node_modules/schema-utils": { "version": "4.3.3", "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-4.3.3.tgz", @@ -4885,6 +5308,13 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/symbol-tree": { + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz", + "integrity": "sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==", + "dev": true, + "license": "MIT" + }, "node_modules/synckit": { "version": "0.11.12", "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.11.12.tgz", @@ -5098,6 +5528,26 @@ "node": "*" } }, + "node_modules/tldts": { + "version": "6.1.86", + "resolved": "https://registry.npmjs.org/tldts/-/tldts-6.1.86.tgz", + "integrity": "sha512-WMi/OQ2axVTf/ykqCQgXiIct+mSQDFdH2fkwhPwgEwvJ1kSzZRiinb0zF2Xb8u4+OqPChmyI6MEu4EezNJz+FQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "tldts-core": "^6.1.86" + }, + "bin": { + "tldts": "bin/cli.js" + } + }, + "node_modules/tldts-core": { + "version": "6.1.86", + "resolved": "https://registry.npmjs.org/tldts-core/-/tldts-core-6.1.86.tgz", + "integrity": "sha512-Je6p7pkk+KMzMv2XXKmAE3McmolOQFdxkKw0R8EYNr7sELW46JqnNeTX8ybPiQgvg1ymCoF8LXs5fzFaZvJPTA==", + "dev": true, + "license": "MIT" + }, "node_modules/tmpl": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz", @@ -5118,6 +5568,32 @@ "node": ">=8.0" } }, + "node_modules/tough-cookie": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-5.1.2.tgz", + "integrity": "sha512-FVDYdxtnj0G6Qm/DhNPSb8Ju59ULcup3tuJxkFb5K8Bv2pUXILbf0xZWU8PX8Ov19OXljbUyveOFwRMwkXzO+A==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "tldts": "^6.1.32" + }, + "engines": { + "node": ">=16" + } + }, + "node_modules/tr46": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-5.1.1.tgz", + "integrity": "sha512-hdF5ZgjTqgAntKkklYw0R03MG2x/bSzTtkxmIRw/sTNV8YXsCJ1tfLAX23lhxhHJlEf3CRCOCGGWw3vI3GaSPw==", + "dev": true, + "license": "MIT", + "dependencies": { + "punycode": "^2.3.1" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/ts-jest": { "version": "29.4.10", "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-29.4.10.tgz", @@ -5446,6 +5922,19 @@ "node": ">=10.12.0" } }, + "node_modules/w3c-xmlserializer": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/w3c-xmlserializer/-/w3c-xmlserializer-5.0.0.tgz", + "integrity": "sha512-o8qghlI8NZHU1lLPrpi2+Uq7abh4GGPpYANlalzWxyWteJOCsr/P+oPBA49TOLu5FTZO4d3F9MnWJfiMo4BkmA==", + "dev": true, + "license": "MIT", + "dependencies": { + "xml-name-validator": "^5.0.0" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/walker": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/walker/-/walker-1.0.8.tgz", @@ -5469,6 +5958,16 @@ "node": ">=10.13.0" } }, + "node_modules/webidl-conversions": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + } + }, "node_modules/webpack": { "version": "5.107.0", "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.107.0.tgz", @@ -5579,6 +6078,44 @@ "node": ">=10.13.0" } }, + "node_modules/whatwg-encoding": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-3.1.1.tgz", + "integrity": "sha512-6qN4hJdMwfYBtE3YBTTHhoeuUrDBPZmbQaxWAqSALV/MeEnR5z1xd8UKud2RAkFoPkmB+hli1TZSnyi84xz1vQ==", + "deprecated": "Use @exodus/bytes instead for a more spec-conformant and faster implementation", + "dev": true, + "license": "MIT", + "dependencies": { + "iconv-lite": "0.6.3" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/whatwg-mimetype": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-4.0.0.tgz", + "integrity": "sha512-QaKxh0eNIi2mE9p2vEdzfagOKHCcj1pJ56EEHGQOVxp8r9/iszLUUV7v89x9O1p/T+NlTM5W7jW6+cz4Fq1YVg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/whatwg-url": { + "version": "14.2.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-14.2.0.tgz", + "integrity": "sha512-De72GdQZzNTUBBChsXueQUnPKDkg/5A5zp7pFDuQAj5UFoENpiACU0wlCvzpAGnTkj++ihpKwKyYewn/XNUbKw==", + "dev": true, + "license": "MIT", + "dependencies": { + "tr46": "^5.1.0", + "webidl-conversions": "^7.0.0" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -5731,6 +6268,45 @@ "node": "^14.17.0 || ^16.13.0 || >=18.0.0" } }, + "node_modules/ws": { + "version": "8.21.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.21.0.tgz", + "integrity": "sha512-Vsp28b7DRcimFQvrqu2Wek3z1iYxDCWqHYB8Qsnk/S4RfaCQzPGPyBNuVjJV3cd6UiKtUtp6sNM77gWvzcCH+g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + }, + "node_modules/xml-name-validator": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-5.0.0.tgz", + "integrity": "sha512-EvGK8EJ3DhaHfbRlETOWAS5pO9MZITeauHKJyb8wyajUfQUenkIg2MvLDTZ4T/TgIcm3HU0TFBgWWboAZ30UHg==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=18" + } + }, + "node_modules/xmlchars": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz", + "integrity": "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==", + "dev": true, + "license": "MIT" + }, "node_modules/xspattern": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/xspattern/-/xspattern-3.1.0.tgz", diff --git a/package.json b/package.json index 9731430..b906110 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "devDependencies": { "@types/jest": "*", "jest": "*", + "jest-environment-jsdom": "^30.4.1", "jest-simple-dot-reporter": "*", "prettier": "*", "ts-jest": "*", @@ -65,5 +66,8 @@ "fontoxpath": "^3.34.0", "slimdom": "^4.3.5", "webpack": "^5.107.0" + }, + "allowScripts": { + "jest-environment-jsdom@30.4.1": true } } diff --git a/test/xjslt.spec.ts b/test/xjslt.spec.ts index e7c33e8..f4f2d08 100644 --- a/test/xjslt.spec.ts +++ b/test/xjslt.spec.ts @@ -53,7 +53,7 @@ import { generate } from "astring"; import { Parser } from "acorn"; import { tmpdir } from "os"; import { readFileSync } from "fs"; -import { readFile, writeFile, unlink } from "fs/promises"; +import { readFile } from "fs/promises"; import { expect } from "@jest/globals"; import { toBeEquivalentDom } from "./matchers"; import { OutputDefinition } from "../src/definitions"; @@ -80,21 +80,16 @@ ${template} } async function makeTransform(body: string) { - const tempfile = path.join(tmpdir(), "temp.xsl"); - await writeFile( - tempfile, - ` ${body} -`, +`), ); - const transform = await compileFromPath(tempfile); - await unlink(tempfile); - return transform; } test("slimdon", () => { From 3288343ffe80704a344ed63add74111856e14547 Mon Sep 17 00:00:00 2001 From: Erik Hetzner Date: Mon, 8 Jun 2026 13:09:39 -0700 Subject: [PATCH 03/10] lint --- src/xjslt.ts | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/xjslt.ts b/src/xjslt.ts index 579b71e..5cde5e0 100644 --- a/src/xjslt.ts +++ b/src/xjslt.ts @@ -417,11 +417,7 @@ export function nextMatch( const next = nextMatches.next(); if (!next.done) { context.nextMatches = nextMatches; - evaluateTemplate( - next.value, - context, - data.params, - ); + evaluateTemplate(next.value, context, data.params); } } } @@ -443,11 +439,7 @@ export function applyImports( } if (!next.done) { context.nextMatches = nextMatches; - evaluateTemplate( - next.value, - context, - data.params, - ); + evaluateTemplate(next.value, context, data.params); } } } @@ -658,13 +650,9 @@ export function applyTemplates( data.sortKeyComponents, namespaceResolver, ); - iterateNodes(sorted, {...context, mode }, (context) => { + iterateNodes(sorted, { ...context, mode }, (context) => { context.variableScopes = extendScope(context.variableScopes); - processNode( - context, - data.params, - data.namespaces, - ); + processNode(context, data.params, data.namespaces); context.variableScopes.pop(); }); } From b764530e96cc29ed67516869be2d32cb20cafc1a Mon Sep 17 00:00:00 2001 From: Erik Hetzner Date: Mon, 8 Jun 2026 15:06:47 -0700 Subject: [PATCH 04/10] trying to make web compilation work --- jest.config.ts | 1 - src/compile.ts | 8 +- src/compilex.ts | 35 +- src/compilex.web.ts | 22 + src/functions.ts | 8 +- src/index.ts | 2 +- src/preprocess/attribute-set.js | 2420 ++++++++++++++-------------- src/preprocess/error-analysis.js | 434 ++--- src/preprocess/import.js | 488 +++--- src/preprocess/include.js | 446 ++--- src/preprocess/simplified.js | 566 +++---- src/preprocess/stripWhitespace1.js | 672 ++++---- src/preprocess/stripWhitespace2.js | 518 +++--- src/preprocess/use-when.js | 520 +++--- src/util.ts | 28 - src/util.web.ts | 25 - test/attribute-namespace.spec.ts | 4 +- test/xjslt.spec.ts | 21 +- webpack.config.ts | 6 +- 19 files changed, 3127 insertions(+), 3097 deletions(-) delete mode 100644 src/util.ts delete mode 100644 src/util.web.ts diff --git a/jest.config.ts b/jest.config.ts index 87c7234..96b7887 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -6,7 +6,6 @@ export default { displayName: "node", preset: "ts-jest", testEnvironment: "node", - // testPathIgnorePatterns: ["examples"], }, { displayName: "jsdom", diff --git a/src/compile.ts b/src/compile.ts index 466c9a2..5acada0 100644 --- a/src/compile.ts +++ b/src/compile.ts @@ -1530,17 +1530,17 @@ export function preprocess( * * `); * - * const transform = await compile(xslt); + * const transform = compile(xslt); * * const input = slimdom.parseXmlDocument("Hello"); * const output = transform(input).get("#default"); * console.log(serialize(output)); // Hello * ``` */ -export function compile( +export function rawCompile( xslt: slimdom.Document, - readDocument?: (uri: string) => slimdom.Document, - inputURL?: URL, + readDocument: (uri: string) => slimdom.Document, + inputURL: URL, ): StylesheetTransform { const xsltDoc = preprocess(xslt, inputURL, readDocument); const code = generate(compileStylesheetNode(xsltDoc.documentElement, true)); diff --git a/src/compilex.ts b/src/compilex.ts index cb74327..f4aa60b 100644 --- a/src/compilex.ts +++ b/src/compilex.ts @@ -65,7 +65,7 @@ import { mkResolver, sortSortable, } from "./shared"; -import { compile, compileStylesheetNode, preprocess } from "./compile"; +import { rawCompile, compileStylesheetNode, preprocess } from "./compile"; async function readAndParseXml(path: string): Promise { const str = (await readFile(path)).toString(); @@ -84,17 +84,17 @@ function readAndParseXmlSync(path: string): slimdom.Document { export async function compileFromPath( xsltPath: string, ): Promise { - return compile( + return rawCompile( await readAndParseXml(xsltPath), - mkFsReadDocument(), + readDocument, pathToFileURL(xsltPath), ); } export function compileFromPathSync(xsltPath: string): StylesheetTransform { - return compile( + return rawCompile( readAndParseXmlSync(xsltPath), - mkFsReadDocument(), + readDocument, pathToFileURL(xsltPath), ); } @@ -120,7 +120,7 @@ export async function compileToFile(xsltPath: string) { const xsltDoc = await preprocess( await readAndParseXml(xsltPath), xsltURL, - mkFsReadDocument(), + readDocument, ); await writeFile( tempfile, @@ -130,13 +130,18 @@ export async function compileToFile(xsltPath: string) { // rmSync(tempdir, { recursive: true }); } -function mkFsReadDocument(): (uri: string) => slimdom.Document { - return (uri: string) => { - if (uri.startsWith("file:")) { - return slimdom.parseXmlDocument( - readFileSync(fileURLToPath(new URL(uri))).toString(), - ); - } - throw new Error(`FODC0005: document ${uri} not found`); - }; +function readDocument(uri: string): slimdom.Document { + if (uri.startsWith("file:")) { + return slimdom.parseXmlDocument( + readFileSync(fileURLToPath(new URL(uri))).toString(), + ); + } + throw new Error(`FODC0005: document ${uri} not found`); +} + +export function compile( + xslt: slimdom.Document, + inputURL: URL, +): StylesheetTransform { + return rawCompile(xslt, readDocument, inputURL); } diff --git a/src/compilex.web.ts b/src/compilex.web.ts index e69de29..9f109ad 100644 --- a/src/compilex.web.ts +++ b/src/compilex.web.ts @@ -0,0 +1,22 @@ +import * as slimdom from "slimdom"; + +import { rawCompile } from "./compile"; +import { StylesheetTransform } from "./definitions"; + +function readDocument(uri: string): slimdom.Document { + // This should be async, but fontoxpath can't handle async custom + // functions, and this is used by those, so it has to be synchronous + // for now. + console.log(uri); + const xhr = new XMLHttpRequest(); + xhr.open("GET", uri, false); + xhr.send(null); // blocks + return xhr.responseXML as unknown as slimdom.Document; // force convert to slimdom.Document, should be fine +} + +export function compile( + xslt: slimdom.Document, + inputURL: URL, +): StylesheetTransform { + return rawCompile(xslt, readDocument, inputURL); +} diff --git a/src/functions.ts b/src/functions.ts index 39d1ec1..ca824fa 100644 --- a/src/functions.ts +++ b/src/functions.ts @@ -30,14 +30,16 @@ import { XSLT1_NSURI, } from "./definitions"; import { formatNumberWithPicture } from "./numbering"; -import { urlToDom } from "./util"; function fnCurrent({ currentContext }) { return currentContext.contextItem; } function fnDoc({ currentContext }, url: string) { - return urlToDom(currentContext, url); + const absoluteURL = currentContext.inputURL + ? new URL(url, currentContext.inputURL.toString()).toString() + : url; + return currentContext.readDocument(absoluteURL); } function fnCurrentGroupingKey({ currentContext }) { @@ -264,7 +266,7 @@ export function registerFunctions() { { namespaceURI: XJSLT_NSURI, localName: "doc" }, ["xs:string"], "document-node()", - fnDoc as (context: any, url: string) => any, + fnDoc as (context: any, url: string) => Promise, ); registerCustomXPathFunction( diff --git a/src/index.ts b/src/index.ts index 23102b8..55d6760 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,3 @@ -import { compile } from "./compile"; +import { compile } from "./compilex"; export { compile }; diff --git a/src/preprocess/attribute-set.js b/src/preprocess/attribute-set.js index 5e2d167..1558099 100644 --- a/src/preprocess/attribute-set.js +++ b/src/preprocess/attribute-set.js @@ -1,26 +1,26 @@ (() => { - var t = { - 144(t, e, n) { + var e = { + 396(e, t, n) { (n(898), n(594)); let o = n(821); - function r(t, e) { - e = o.setParamDefaults(t, e); + function r(e, t) { + t = o.setParamDefaults(e, t); let n = new Map(); - n.set("#default", { document: e.outputDocument }); + n.set("#default", { document: t.outputDocument }); let r = new Map(), a = new Map(), s = new Map(), i = { - outputDocument: e.outputDocument, - append: o.mkNodeAppender(e.outputNode), + outputDocument: t.outputDocument, + append: o.mkNodeAppender(t.outputNode), resultDocuments: n, - contextItem: t, - contextList: [t], + contextItem: e, + contextList: [e], position: 1, - mode: e.initialMode, + mode: t.initialMode, templates: [ { - apply: (t) => {}, + apply: (e) => {}, allowedParams: [], modes: ["#all"], namespaces: { @@ -31,8 +31,8 @@ declarationOrder: 5e-324, }, { - apply: (t) => { - o.valueOf(t, { + apply: (e) => { + o.valueOf(e, { select: ".", separator: void 0, namespaces: { @@ -51,8 +51,8 @@ declarationOrder: 5e-324, }, { - apply: (t) => { - o.applyTemplates(t, { + apply: (e) => { + o.applyTemplates(e, { select: "child::node()", params: [], mode: "#current", @@ -75,17 +75,17 @@ { modes: ["#default"], allowedParams: [], - apply: (t) => { + apply: (e) => { o.copy( - t, + e, { namespaces: { xsl: "http://www.w3.org/1999/XSL/Transform", xjslt: "https://www.e6h.org/xjslt", }, }, - (t) => { - o.applyTemplates(t, { + (e) => { + o.applyTemplates(e, { select: "@* | node()", mode: "#default", params: [], @@ -116,8 +116,8 @@ as: void 0, }, ], - apply: (t) => { - (o.variable(t, { + apply: (e) => { + (o.variable(e, { name: "root", content: "/", namespaces: { @@ -127,7 +127,7 @@ as: void 0, }), o.forEach( - t, + e, { select: "tokenize($attribute-sets, '\\s+')", sortKeyComponents: [], @@ -136,8 +136,8 @@ xjslt: "https://www.e6h.org/xjslt", }, }, - (t) => { - (o.variable(t, { + (e) => { + (o.variable(e, { name: "name", content: ".", namespaces: { @@ -146,7 +146,7 @@ }, as: void 0, }), - o.variable(t, { + o.variable(e, { name: "attribute-set", content: "$root//xsl:attribute-set[@name=$name]", namespaces: { @@ -156,7 +156,7 @@ as: void 0, }), o.ifX( - t, + e, { test: "not(boolean($attribute-set))", namespaces: { @@ -164,9 +164,9 @@ xjslt: "https://www.e6h.org/xjslt", }, }, - (t) => { + (e) => { o.message( - t, + e, { select: void 0, terminate: "yes", @@ -175,16 +175,16 @@ xjslt: "https://www.e6h.org/xjslt", }, }, - (t) => { + (e) => { o.literalText( - t, + e, "XTSE0710 Attribute set not found", ); }, ); }, ), - o.copyOf(t, { + o.copyOf(e, { select: "$root//xsl:attribute-set[@name=$name]/node()", namespaces: { @@ -206,17 +206,17 @@ { modes: ["#default"], allowedParams: [], - apply: (t) => { + apply: (e) => { o.copy( - t, + e, { namespaces: { xsl: "http://www.w3.org/1999/XSL/Transform", xjslt: "https://www.e6h.org/xjslt", }, }, - (t) => { - (o.applyTemplates(t, { + (e) => { + (o.applyTemplates(e, { select: "@*", mode: "#default", params: [], @@ -226,7 +226,7 @@ xjslt: "https://www.e6h.org/xjslt", }, }), - o.callTemplate(t, { + o.callTemplate(e, { name: "use-attribute-sets", params: [ { @@ -240,7 +240,7 @@ }, ], }), - o.applyTemplates(t, { + o.applyTemplates(e, { select: "node()", mode: "#default", params: [], @@ -264,17 +264,17 @@ { modes: ["#default"], allowedParams: [], - apply: (t) => { + apply: (e) => { o.copy( - t, + e, { namespaces: { xsl: "http://www.w3.org/1999/XSL/Transform", xjslt: "https://www.e6h.org/xjslt", }, }, - (t) => { - (o.applyTemplates(t, { + (e) => { + (o.applyTemplates(e, { select: "@*", mode: "#default", params: [], @@ -284,7 +284,7 @@ xjslt: "https://www.e6h.org/xjslt", }, }), - o.callTemplate(t, { + o.callTemplate(e, { name: "use-attribute-sets", params: [ { @@ -298,7 +298,7 @@ }, ], }), - o.applyTemplates(t, { + o.applyTemplates(e, { select: "node()", mode: "#default", params: [], @@ -322,7 +322,7 @@ { modes: ["#default"], allowedParams: [], - apply: (t) => {}, + apply: (e) => {}, namespaces: { xsl: "http://www.w3.org/1999/XSL/Transform", xjslt: "https://www.e6h.org/xjslt", @@ -380,7 +380,7 @@ ], namedTemplates: new Map([["use-attribute-sets", 4]]), variableScopes: [new Map()], - inputURL: e.inputURL, + inputURL: t.inputURL, ruleTree: { feature: new o.NodeTypeFeature(o.selfNode, 7), results: [], @@ -418,19 +418,19 @@ }, }, }, - readDocument: e.readDocument, + readDocument: t.readDocument, keys: r, outputDefinitions: a, decimalFormats: s, patternMatchCache: new Map(), - stylesheetParams: e.stylesheetParams, + stylesheetParams: t.stylesheetParams, }; return ( o.initialize(i, { xsl: "http://www.w3.org/1999/XSL/Transform", xjslt: "https://www.e6h.org/xjslt", }), - o.stripSpace(t, []), + o.stripSpace(e, []), o.processNode(i, [], { xsl: "http://www.w3.org/1999/XSL/Transform", xjslt: "https://www.e6h.org/xjslt", @@ -438,42 +438,42 @@ n ); } - ((t.exports.transform = r), (global.transform = r)); + ((e.exports.transform = r), (global.transform = r)); }, - 712(t, e, n) { + 712(e, t, n) { "use strict"; - (Object.defineProperty(e, "__esModule", { value: !0 }), - (e.Feature = - e.DEFAULT_DECIMAL_FORMAT = - e.NodeType = - e.DEFAULT_PRIORITIES = - e.XJSLT_NSURI = - e.XPATH_NSURI = - e.XMLNS_NSURI = - e.XSLT1_NSURI = + (Object.defineProperty(t, "__esModule", { value: !0 }), + (t.Feature = + t.DEFAULT_DECIMAL_FORMAT = + t.NodeType = + t.DEFAULT_PRIORITIES = + t.XJSLT_NSURI = + t.XPATH_NSURI = + t.XMLNS_NSURI = + t.XSLT1_NSURI = void 0), - (e.isNodeGroup = c), - (e.isNodeGroupArray = function (t) { - return Array.isArray(t) && (0 === t.length || c(t[0])); + (t.isNodeGroup = c), + (t.isNodeGroupArray = function (e) { + return Array.isArray(e) && (0 === e.length || c(e[0])); })); const o = n(953), r = String.raw`[^,:\(\)\*\[\]/]`, a = String.raw`(child::|attribute::|@)?`, s = String.raw`(document-node\()?`; var i; - function c(t) { + function c(e) { return ( - "object" == typeof t && - null !== t && - "string" == typeof t.key && - Array.isArray(t.nodes) + "object" == typeof e && + null !== e && + "string" == typeof e.key && + Array.isArray(e.nodes) ); } - ((e.XSLT1_NSURI = "http://www.w3.org/1999/XSL/Transform"), - (e.XMLNS_NSURI = "http://www.w3.org/2000/xmlns/"), - (e.XPATH_NSURI = "http://www.w3.org/2005/xpath-functions"), - (e.XJSLT_NSURI = "https://www.e6h.org/xjslt"), - (e.DEFAULT_PRIORITIES = new Map([ + ((t.XSLT1_NSURI = "http://www.w3.org/1999/XSL/Transform"), + (t.XMLNS_NSURI = "http://www.w3.org/2000/xmlns/"), + (t.XPATH_NSURI = "http://www.w3.org/2005/xpath-functions"), + (t.XJSLT_NSURI = "https://www.e6h.org/xjslt"), + (t.DEFAULT_PRIORITIES = new Map([ [new RegExp(String.raw`^\s*/\s*$`), -0.5], [new RegExp(String.raw`^\s*\*\s*$`), -0.5], [new RegExp(String.raw`^\s*${s}${a}processing-instruction`), 0], @@ -526,21 +526,21 @@ [new RegExp(String.raw`^\s*${a}\*:${r}+\s*$`), -0.25], [new RegExp(String.raw`^\s*${a}${r}+\s*$`), 0], ])), - (function (t) { - ((t[(t.ELEMENT = 1)] = "ELEMENT"), - (t[(t.ATTRIBUTE = 2)] = "ATTRIBUTE"), - (t[(t.TEXT = 3)] = "TEXT"), - (t[(t.CDATA_SECTION = 4)] = "CDATA_SECTION"), - (t[(t.ENTITY_REFERENCE = 5)] = "ENTITY_REFERENCE"), - (t[(t.ENTITY = 6)] = "ENTITY"), - (t[(t.PROCESSING_INSTRUCTION = 7)] = "PROCESSING_INSTRUCTION"), - (t[(t.COMMENT = 8)] = "COMMENT"), - (t[(t.DOCUMENT = 9)] = "DOCUMENT"), - (t[(t.DOCUMENT_TYPE = 10)] = "DOCUMENT_TYPE"), - (t[(t.DOCUMENT_FRAGMENT = 11)] = "DOCUMENT_FRAGMENT"), - (t[(t.NOTATION = 12)] = "NOTATION")); - })(i || (e.NodeType = i = {})), - (e.DEFAULT_DECIMAL_FORMAT = { + (function (e) { + ((e[(e.ELEMENT = 1)] = "ELEMENT"), + (e[(e.ATTRIBUTE = 2)] = "ATTRIBUTE"), + (e[(e.TEXT = 3)] = "TEXT"), + (e[(e.CDATA_SECTION = 4)] = "CDATA_SECTION"), + (e[(e.ENTITY_REFERENCE = 5)] = "ENTITY_REFERENCE"), + (e[(e.ENTITY = 6)] = "ENTITY"), + (e[(e.PROCESSING_INSTRUCTION = 7)] = "PROCESSING_INSTRUCTION"), + (e[(e.COMMENT = 8)] = "COMMENT"), + (e[(e.DOCUMENT = 9)] = "DOCUMENT"), + (e[(e.DOCUMENT_TYPE = 10)] = "DOCUMENT_TYPE"), + (e[(e.DOCUMENT_FRAGMENT = 11)] = "DOCUMENT_FRAGMENT"), + (e[(e.NOTATION = 12)] = "NOTATION")); + })(i || (t.NodeType = i = {})), + (t.DEFAULT_DECIMAL_FORMAT = { decimalSeparator: ".", digit: "#", groupingSeparator: ",", @@ -552,9 +552,9 @@ perMille: "‰", zeroDigit: "0", }), - (e.Feature = class { - constructor(t) { - this.value = t; + (t.Feature = class { + constructor(e) { + this.value = e; } serialize() { return (0, o.mkNew)( @@ -562,100 +562,102 @@ [(0, o.toEstree)(this.value)], ); } - equals(t) { + equals(e) { return ( - this.constructor === t.constructor && this.value === t.value + this.constructor === e.constructor && this.value === e.value ); } })); }, - 320(t, e, n) { + 320(e, t, n) { "use strict"; var o, r = (this && this.__createBinding) || (Object.create - ? function (t, e, n, o) { + ? function (e, t, n, o) { void 0 === o && (o = n); - var r = Object.getOwnPropertyDescriptor(e, n); + var r = Object.getOwnPropertyDescriptor(t, n); ((r && !("get" in r - ? !e.__esModule + ? !t.__esModule : r.writable || r.configurable)) || (r = { enumerable: !0, get: function () { - return e[n]; + return t[n]; }, }), - Object.defineProperty(t, o, r)); + Object.defineProperty(e, o, r)); } - : function (t, e, n, o) { - (void 0 === o && (o = n), (t[o] = e[n])); + : function (e, t, n, o) { + (void 0 === o && (o = n), (e[o] = t[n])); }), a = (this && this.__setModuleDefault) || (Object.create - ? function (t, e) { - Object.defineProperty(t, "default", { + ? function (e, t) { + Object.defineProperty(e, "default", { enumerable: !0, - value: e, + value: t, }); } - : function (t, e) { - t.default = e; + : function (e, t) { + e.default = t; }), s = (this && this.__importStar) || - ((o = function (t) { + ((o = function (e) { return ( (o = Object.getOwnPropertyNames || - function (t) { - var e = []; - for (var n in t) - Object.prototype.hasOwnProperty.call(t, n) && - (e[e.length] = n); - return e; + function (e) { + var t = []; + for (var n in e) + Object.prototype.hasOwnProperty.call(e, n) && + (t[t.length] = n); + return t; }), - o(t) + o(e) ); }), - function (t) { - if (t && t.__esModule) return t; - var e = {}; - if (null != t) - for (var n = o(t), s = 0; s < n.length; s++) - "default" !== n[s] && r(e, t, n[s]); - return (a(e, t), e); + function (e) { + if (e && e.__esModule) return e; + var t = {}; + if (null != e) + for (var n = o(e), s = 0; s < n.length; s++) + "default" !== n[s] && r(t, e, n[s]); + return (a(t, e), t); }); - (Object.defineProperty(e, "__esModule", { value: !0 }), - (e.NodeAttributeFeature = - e.NodeTextFeature = - e.NodeNameFeature = - e.NodeTypeFeature = - e.NodeNamespaceFeature = + (Object.defineProperty(t, "__esModule", { value: !0 }), + (t.NodeAttributeFeature = + t.NodeTextFeature = + t.NodeNameFeature = + t.NodeTypeFeature = + t.NodeNamespaceFeature = void 0), - (e.selfNode = m), - (e.parentNode = d), - (e.grandParentNode = f), - (e.greatGrandParentNode = x), - (e.xpathToFeatures = function (t, e) { - if (t) - return (function (t, e) { + (t.selfNode = m), + (t.parentNode = d), + (t.grandParentNode = f), + (t.greatGrandParentNode = x), + (t.greatGreatGrandParentNode = h), + (t.ancestorNodes = g), + (t.xpathToFeatures = function (e, t) { + if (e) + return (function (e, t) { const n = []; try { - return (I(t, n, e), n); - } catch (t) { + return (C(e, n, t), n); + } catch (e) { return; } })( (0, u.parseScript)( - t, + e, { language: u.evaluateXPath.XPATH_3_1_LANGUAGE }, new l.Document(), ), - e, + t, ); })); const i = n(953), @@ -663,35 +665,53 @@ u = n(594), l = s(n(898)), p = "http://www.w3.org/2005/XQueryX"; - function m(t) { - return t; - } - function d(t) { - return t.parentNode || void 0; - } - function f(t) { - var e; - return ( - (null === (e = t.parentNode) || void 0 === e - ? void 0 - : e.parentNode) || void 0 - ); - } - function x(t) { - var e, n; - return ( - (null === + function* m(e) { + yield e; + } + function* d(e) { + e.parentNode && (yield e.parentNode); + } + function* f(e) { + var t; + const n = + null === (t = e.parentNode) || void 0 === t ? void 0 : t.parentNode; + n && (yield n); + } + function* x(e) { + var t, n; + const o = + null === (n = - null === (e = t.parentNode) || void 0 === e + null === (t = e.parentNode) || void 0 === t ? void 0 - : e.parentNode) || void 0 === n + : t.parentNode) || void 0 === n ? void 0 - : n.parentNode) || void 0 - ); + : n.parentNode; + o && (yield o); + } + function* h(e) { + var t, n, o; + const r = + null === + (o = + null === + (n = + null === (t = e.parentNode) || void 0 === t + ? void 0 + : t.parentNode) || void 0 === n + ? void 0 + : n.parentNode) || void 0 === o + ? void 0 + : o.parentNode; + r && (yield r); } - class h extends c.Feature { - constructor(t, e) { - (super(e), (this.nodeExtractor = t)); + function* g(e) { + let t = e.parentNode; + for (; t; ) (yield t, (t = t.parentNode)); + } + class w extends c.Feature { + constructor(e, t) { + (super(t), (this.nodeExtractor = e)); } serialize() { return (0, i.mkNew)( @@ -702,304 +722,305 @@ ], ); } - equals(t) { - return this.nodeExtractor === t.nodeExtractor && super.equals(t); + equals(e) { + return this.nodeExtractor === e.nodeExtractor && super.equals(e); } } - class g extends h { - matches(t) { - var e; - return ( - (null === (e = this.nodeExtractor(t)) || void 0 === e - ? void 0 - : e.nodeType) === l.Node.ELEMENT_NODE && - t.namespaceURI === this.value + function N(e, t) { + for (const n of e) if (t(n)) return !0; + return !1; + } + class v extends w { + matches(e) { + return N( + this.nodeExtractor(e), + (e) => + e.nodeType == l.Node.ELEMENT_NODE && + e.namespaceURI === this.value, ); } } - e.NodeNamespaceFeature = g; - class w extends h { - matches(t) { - var e; - return ( - (null === (e = this.nodeExtractor(t)) || void 0 === e - ? void 0 - : e.nodeType) === this.value - ); + t.NodeNamespaceFeature = v; + class T extends w { + matches(e) { + return N(this.nodeExtractor(e), (e) => e.nodeType === this.value); } } - e.NodeTypeFeature = w; - class N extends h { - matches(t) { - var e; - return ( - (null === (e = this.nodeExtractor(t)) || void 0 === e - ? void 0 - : e.nodeName) === this.value - ); + t.NodeTypeFeature = T; + class y extends w { + matches(e) { + return N(this.nodeExtractor(e), (e) => e.nodeName === this.value); } } - e.NodeNameFeature = N; - class v extends h { - matches(t) { - var e; - return ( - (null === (e = this.nodeExtractor(t)) || void 0 === e - ? void 0 - : e.textContent) === this.value + t.NodeNameFeature = y; + class b extends w { + matches(e) { + return N( + this.nodeExtractor(e), + (e) => e.textContent === this.value, ); } } - e.NodeTextFeature = v; - class T extends h { - matches(t) { - const e = this.nodeExtractor(t); - return ( - e.nodeType === l.Node.ELEMENT_NODE && - e.getAttribute(this.value.name) === this.value.value + t.NodeTextFeature = b; + class S extends w { + matches(e) { + return N( + this.nodeExtractor(e), + (e) => + e.nodeType == l.Node.ELEMENT_NODE && + e.getAttribute(this.value.name) === this.value.value, ); } } - function y(t) { + function E(e) { return ( - (function (t) { - return 1 === t.nodeType; - })(t) && t.namespaceURI === p + (function (e) { + return 1 === e.nodeType; + })(e) && e.namespaceURI === p ); } - function b(t, e) { - return y(t) && t.localName === e; + function R(e, t) { + return E(e) && e.localName === t; } - function S(t, e) { - for (const n of t.childNodes) if (b(n, e)) return n; + function I(e, t) { + for (const n of e.childNodes) if (R(n, t)) return n; } - function E(t, e, n) { - for (const o of t.childNodes) { - if (!y(o)) continue; - if (b(o, e) && (!n || n(o))) return o; - const t = E(o, e, n); - if (t) return t; + function P(e, t, n) { + for (const o of e.childNodes) { + if (!E(o)) continue; + if (R(o, t) && (!n || n(o))) return o; + const e = P(o, t, n); + if (e) return e; } } - e.NodeAttributeFeature = T; - class R extends Error {} - function I(t, e, n) { - if (!y(t)) return; - const o = t.localName; + function j(e) { + var t; + return ( + "descendant-or-self" === + (null === (t = I(e, "xpathAxis")) || void 0 === t + ? void 0 + : t.textContent) && !!I(e, "anyKindTest") + ); + } + t.NodeAttributeFeature = S; + class O extends Error {} + function C(e, t, n) { + if (!E(e)) return; + const o = e.localName; if ("module" === o || "mainModule" === o || "queryBody" === o) - for (const o of t.childNodes) I(o, e, n); + for (const o of e.childNodes) C(o, t, n); else { - if ("pathExpr" !== o) throw new R(); + if ("pathExpr" !== o) throw new O(); { - const o = t.childNodes.filter((t) => b(t, "stepExpr")); - if (b(t.firstChild, "rootExpr")) { + const o = e.childNodes.filter((e) => R(e, "stepExpr")); + if (R(e.firstChild, "rootExpr")) { if (0 === o.length) - return void e.push(new w(m, l.Node.DOCUMENT_NODE)); - if ( - "descendant-or-self" !== - (null === (a = S((r = o[0]), "xpathAxis")) || void 0 === a - ? void 0 - : a.textContent) || - !S(r, "anyKindTest") - ) - throw new R(); + return void t.push(new T(m, l.Node.DOCUMENT_NODE)); + if (!j(o[0])) throw new O(); o.shift(); } - if (0 === o.length) throw new R(); - const s = o.reverse(); - if (0 == s.length || s.length > 4) throw new R(); - (O(m, s[0], e, n), - s[1] && O(d, s[1], e, n), - s[2] && O(f, s[2], e, n), - s[3] && O(x, s[3], e, n)); + if (0 === o.length) throw new O(); + const r = o.reverse(); + if (0 == r.length) throw new O(); + const a = [m, d, f, x, h]; + let s = 0, + i = !1; + for (const e of r) { + if (j(e)) { + i = !0; + continue; + } + const o = i ? g : a[s++]; + if (!o) throw new O(); + D(o, e, t, n); + } } } - var r, a; } - function j(t, e, n) { - "attribute" === e - ? n.push(new w(t, l.Node.ATTRIBUTE_NODE)) - : n.push(new w(t, l.Node.ELEMENT_NODE)); + function $(e, t, n) { + "attribute" === t + ? n.push(new T(e, l.Node.ATTRIBUTE_NODE)) + : n.push(new T(e, l.Node.ELEMENT_NODE)); } - function O(t, e, n, o) { + function D(e, t, n, o) { var r, a; const s = - null === (r = S(e, "xpathAxis")) || void 0 === r + null === (r = I(t, "xpathAxis")) || void 0 === r ? void 0 : r.textContent; if ("child" !== s && "attribute" !== s) - throw new R(`unsupported axis: ${s}`); - for (const r of e.childNodes.slice(1)) { - if (!y(r)) continue; + throw new O(`unsupported axis: ${s}`); + for (const r of t.childNodes.slice(1)) { + if (!E(r)) continue; const i = r.localName; - if ("nameTest" === i) (P(t, e, n, o), j(t, s, n)); + if ("nameTest" === i) (X(e, t, n, o), $(e, s, n)); else if ("Wildcard" === i) { - const e = S(r, "NCName"); - if (e) { + const t = I(r, "NCName"); + if (t) { const r = null == o ? void 0 - : o(null !== (a = e.textContent) && void 0 !== a ? a : ""); - if (!r) throw new R(`unresolved ns prefix: ${r}`); - n.push(new g(t, r)); + : o(null !== (a = t.textContent) && void 0 !== a ? a : ""); + if (!r) throw new O(`unresolved ns prefix: ${r}`); + n.push(new v(e, r)); } - j(t, s, n); + $(e, s, n); } else if ("piTest" === i) { - n.push(new w(t, l.Node.PROCESSING_INSTRUCTION_NODE)); - const e = S(r, "piTarget"); - (null == e ? void 0 : e.textContent) && - n.push(new N(t, e.textContent)); + n.push(new T(e, l.Node.PROCESSING_INSTRUCTION_NODE)); + const t = I(r, "piTarget"); + (null == t ? void 0 : t.textContent) && + n.push(new y(e, t.textContent)); } else if ("commentTest" === i) - n.push(new w(t, l.Node.COMMENT_NODE)); - else if ("textTest" === i) n.push(new w(t, l.Node.TEXT_NODE)); + n.push(new T(e, l.Node.COMMENT_NODE)); + else if ("textTest" === i) n.push(new T(e, l.Node.TEXT_NODE)); else { - if ("predicates" !== i) throw new R(); - C(t, r, n, o); + if ("predicates" !== i) throw new O(); + L(e, r, n, o); } } } - function P(t, e, n, o) { - const r = S(e, "nameTest"); - if (!r) throw new R(); + function X(e, t, n, o) { + const r = I(t, "nameTest"); + if (!r) throw new O(); const a = r.textContent; - a && n.push(new N(t, a)); + a && n.push(new y(e, a)); const s = r.getAttributeNS(p, "prefix"); if (s) { - const e = null == o ? void 0 : o(s); - if (!e) throw new R(`unresolved ns prefix: ${e}`); - n.push(new g(t, e)); + const t = null == o ? void 0 : o(s); + if (!t) throw new O(`unresolved ns prefix: ${t}`); + n.push(new v(e, t)); } const i = r.getAttributeNS(p, "URI"); - i && n.push(new g(t, i)); - } - function C(t, e, n, o) { - for (const r of e.childNodes) { - if (!y(r)) throw new R(); - const e = r.localName; - if ("equalOp" === e) { - const e = S(r, "firstOperand"), - o = S(r, "secondOperand"); - if (!e || !o) throw new R(); - const a = $(t, e, o) || $(t, o, e); - if (!a) throw new R(); + i && n.push(new v(e, i)); + } + function L(e, t, n, o) { + for (const r of t.childNodes) { + if (!E(r)) throw new O(); + const t = r.localName; + if ("equalOp" === t) { + const t = I(r, "firstOperand"), + o = I(r, "secondOperand"); + if (!t || !o) throw new O(); + const a = M(e, t, o) || M(e, o, t); + if (!a) throw new O(); n.push(a); } else { - if ("andOp" !== e) throw new R(); - (C(t, S(r, "firstOperand"), n, o), - C(t, S(r, "secondOperand"), n, o)); + if ("andOp" !== t) throw new O(); + (L(e, I(r, "firstOperand"), n, o), + L(e, I(r, "secondOperand"), n, o)); } } } - function $(t, e, n) { + function M(e, t, n) { var o, r; - const a = E(n, "value"); + const a = P(n, "value"); if (!a) return; const s = null !== (o = a.textContent) && void 0 !== o ? o : "", - i = E(e, "stepExpr", (t) => { - var e; + i = P(t, "stepExpr", (e) => { + var t; return ( "attribute" === - (null === (e = S(t, "xpathAxis")) || void 0 === e + (null === (t = I(e, "xpathAxis")) || void 0 === t ? void 0 - : e.textContent) + : t.textContent) ); }); if (i) { - const e = - null === (r = S(i, "nameTest")) || void 0 === r + const t = + null === (r = I(i, "nameTest")) || void 0 === r ? void 0 : r.textContent; - if (!e) return; - return new T(t, { name: e, value: s }); + if (!t) return; + return new S(e, { name: t, value: s }); } - return S(e, "contextItemExpr") || E(e, "textTest") - ? new v(t, s) + return I(t, "contextItemExpr") || P(t, "textTest") + ? new b(e, s) : void 0; } }, - 324(t, e) { + 324(e, t) { "use strict"; - (Object.defineProperty(e, "__esModule", { value: !0 }), - (e.buildRuleTree = function t(e) { - if (0 === e.length) return { results: [] }; + (Object.defineProperty(t, "__esModule", { value: !0 }), + (t.buildRuleTree = function e(t) { + if (0 === t.length) return { results: [] }; const n = new Set(); - for (const t of e) for (const e of t.features) n.add(e); - if (0 === n.size) return { results: e.map((t) => t.result) }; + for (const e of t) for (const t of e.features) n.add(t); + if (0 === n.size) return { results: t.map((e) => e.result) }; const o = Array.from(n)[0], r = [], a = []; - for (const t of e) - t.features.some((t) => t.equals(o)) ? r.push(t) : a.push(t); + for (const e of t) + e.features.some((e) => e.equals(o)) ? r.push(e) : a.push(e); let s = { feature: o, results: [] }; if (r.length > 0) { - const e = r.map((t) => - Object.assign(Object.assign({}, t), { - features: t.features.filter((t) => !t.equals(o)), + const t = r.map((e) => + Object.assign(Object.assign({}, e), { + features: e.features.filter((e) => !e.equals(o)), }), ); - s.left = t(e.filter((t) => t.features.length > 0)); - const n = r.filter((t, n) => 0 === e[n].features.length); + s.left = e(t.filter((e) => e.features.length > 0)); + const n = r.filter((e, n) => 0 === t[n].features.length); n.length > 0 && (s.left || (s.left = { results: [] }), - (s.left.results = n.map((t) => t.result))); + (s.left.results = n.map((e) => e.result))); } - return (a.length > 0 && (s.right = t(a)), s); + return (a.length > 0 && (s.right = e(a)), s); }), - (e.findMatchingRules = function (t, e) { + (t.findMatchingRules = function (e, t) { const n = [], - o = [t]; + o = [e]; for (; o.length > 0; ) { - const t = o.pop(); - t && - (n.push(...t.results), - t.feature && - (t.right && o.push(t.right), - t.feature.matches(e) && t.left && o.push(t.left))); + const e = o.pop(); + e && + (n.push(...e.results), + e.feature && + (e.right && o.push(e.right), + e.feature.matches(t) && e.left && o.push(e.left))); } return n; })); }, - 953(t, e) { + 953(e, t) { "use strict"; - function n(t, e) { + function n(e, t) { return { type: "ExpressionStatement", expression: { type: "CallExpression", - callee: t, - arguments: e, + callee: e, + arguments: t, optional: !1, }, }; } - function o(t) { - return { type: "Identifier", name: t }; + function o(e) { + return { type: "Identifier", name: e }; } - function r(t) { - return { type: "Literal", value: (t = t ?? void 0) }; + function r(e) { + return { type: "Literal", value: (e = e ?? void 0) }; } - function a(t, e) { + function a(e, t) { return { type: "MemberExpression", - object: o(t), - property: o(e), + object: o(e), + property: o(t), computed: !1, optional: !1, }; } - function s(t, e) { + function s(e, t) { return ( - e || (e = t), + t || (t = e), { type: "VariableDeclaration", declarations: [ { type: "VariableDeclarator", - id: o(t), + id: o(e), init: { type: "CallExpression", callee: o("require"), - arguments: [r(e)], + arguments: [r(t)], optional: !1, }, }, @@ -1008,46 +1029,46 @@ } ); } - function i(t) { - return { type: "ArrayExpression", elements: t }; + function i(e) { + return { type: "ArrayExpression", elements: e }; } - function c(t, e, n) { + function c(e, t, n) { return { type: "VariableDeclaration", - declarations: [{ type: "VariableDeclarator", id: t, init: e }], + declarations: [{ type: "VariableDeclarator", id: e, init: t }], kind: n, }; } - function u(t, e) { - return { type: "NewExpression", callee: t, arguments: e }; + function u(e, t) { + return { type: "NewExpression", callee: e, arguments: t }; } - (Object.defineProperty(e, "__esModule", { value: !0 }), - (e.mkArrowFun = function (t) { + (Object.defineProperty(t, "__esModule", { value: !0 }), + (t.mkArrowFun = function (e) { return { type: "ArrowFunctionExpression", expression: !1, generator: !1, async: !1, params: [o("context")], - body: { type: "BlockStatement", body: t }, + body: { type: "BlockStatement", body: e }, }; }), - (e.mkFun = function (t, e, n) { + (t.mkFun = function (e, t, n) { return { type: "FunctionDeclaration", - id: t, + id: e, generator: !1, async: !1, - params: e, + params: t, body: n, }; }), - (e.mkCall = n), - (e.mkCallWithContext = function (t, e) { - return n(t, [o("context"), ...e]); + (t.mkCall = n), + (t.mkCallWithContext = function (e, t) { + return n(e, [o("context"), ...t]); }), - (e.mkIdentifier = o), - (e.mkImports = function () { + (t.mkIdentifier = o), + (t.mkImports = function () { return [ { type: "ImportDeclaration", @@ -1071,84 +1092,84 @@ }, ]; }), - (e.mkImportsNode = function () { + (t.mkImportsNode = function () { return [s("slimdom"), s("fontoxpath"), s("xjslt", "xjslt")]; }), - (e.mkLiteral = r), - (e.mkMember = a), - (e.mkObject = function (t) { - let e = []; - for (let n in t) - e.push({ + (t.mkLiteral = r), + (t.mkMember = a), + (t.mkObject = function (e) { + let t = []; + for (let n in e) + t.push({ type: "Property", method: !1, shorthand: !1, computed: !1, key: r(n), - value: t[n], + value: e[n], kind: "init", }); - return { type: "ObjectExpression", properties: e }; + return { type: "ObjectExpression", properties: t }; }), - (e.mkRequire = s), - (e.mkArray = i), - (e.mkReturn = function (t) { - return { type: "ReturnStatement", argument: t }; + (t.mkRequire = s), + (t.mkArray = i), + (t.mkReturn = function (e) { + return { type: "ReturnStatement", argument: e }; }), - (e.mkBlock = function (t) { - return { type: "BlockStatement", body: t }; + (t.mkBlock = function (e) { + return { type: "BlockStatement", body: e }; }), - (e.mkLet = function (t, e) { - return c(t, e, "let"); + (t.mkLet = function (e, t) { + return c(e, t, "let"); }), - (e.mkConst = function (t, e) { - return c(t, e, "const"); + (t.mkConst = function (e, t) { + return c(e, t, "const"); }), - (e.mkVariableDeclaration = c), - (e.mkNew = u), - (e.toEstree = function t(e) { - const n = typeof e; - return null == e || + (t.mkVariableDeclaration = c), + (t.mkNew = u), + (t.toEstree = function e(t) { + const n = typeof t; + return null == t || "string" === n || "number" === n || "boolean" === n - ? r(e) - : Array.isArray(e) - ? i(e.map((e) => t(e))) - : "function" == typeof e.serialize - ? e.serialize() + ? r(t) + : Array.isArray(t) + ? i(t.map((t) => e(t))) + : "function" == typeof t.serialize + ? t.serialize() : "function" === n - ? a("xjslt", e.name) + ? a("xjslt", t.name) : "object" === n - ? e instanceof Map - ? u(o("Map"), [t(Array.from(e.entries()))]) - : "type" in e - ? e - : (function (e) { + ? t instanceof Map + ? u(o("Map"), [e(Array.from(t.entries()))]) + : "type" in t + ? t + : (function (t) { let n = []; - for (let o in e) + for (let o in t) n.push({ type: "Property", method: !1, shorthand: !1, computed: !1, - key: t(o), - value: t(e[o]), + key: e(o), + value: e(t[o]), kind: "init", }); return { type: "ObjectExpression", properties: n, }; - })(e) + })(t) : void 0; })); }, - 379(t, e, n) { + 379(e, t, n) { "use strict"; - (Object.defineProperty(e, "__esModule", { value: !0 }), - (e.functionNameResolver = y), - (e.registerFunctions = function () { + (Object.defineProperty(t, "__esModule", { value: !0 }), + (t.functionNameResolver = y), + (t.registerFunctions = function () { ((0, o.registerCustomXPathFunction)( { namespaceURI: r.XJSLT_NSURI, localName: "current" }, [], @@ -1225,27 +1246,27 @@ { namespaceURI: r.XJSLT_NSURI, localName: "evaluate" }, ["xs:string"], "item()", - (t, e) => - (function ({ currentContext: t }, e) { + (e, t) => + (function ({ currentContext: e }, t) { const n = (0, o.evaluateXPath)( - e, + t, void 0, void 0, void 0, o.evaluateXPath.ALL_RESULTS_TYPE, { - currentContext: { currentContext: t }, + currentContext: { currentContext: e }, functionNameResolver: y, }, ); return 1 === n.length ? n[0] : n; - })(t, e), + })(e, t), ), (0, o.registerCustomXPathFunction)( { namespaceURI: r.XJSLT_NSURI, localName: "normalize-unicode" }, ["xs:string?"], "xs:string", - (t, e) => N(0, e, "NFC"), + (e, t) => N(0, t, "NFC"), ), (0, o.registerCustomXPathFunction)( { namespaceURI: r.XJSLT_NSURI, localName: "normalize-unicode" }, @@ -1276,38 +1297,38 @@ r = n(712), a = n(845), s = n(472); - function i({ currentContext: t }) { - return t.contextItem; + function i({ currentContext: e }) { + return e.contextItem; } - function c({ currentContext: t }, e) { - return (0, s.urlToDom)(t, e); + function c({ currentContext: e }, t) { + return (0, s.urlToDom)(e, t); } - function u({ currentContext: t }) { - return t.currentGroup.key; + function u({ currentContext: e }) { + return e.currentGroup.key; } - function l({ currentContext: t }) { - return t.currentGroup.nodes; + function l({ currentContext: e }) { + return e.currentGroup.nodes; } - function p({ currentContext: t }) { - return t.position; + function p({ currentContext: e }) { + return e.position; } - function m({ currentContext: t }) { - return t.contextList.length; + function m({ currentContext: e }) { + return e.contextList.length; } - function d({ currentContext: t }) { - for (const [e, n] of t.resultDocuments) - if (n === t.outputDocument) return e; + function d({ currentContext: e }) { + for (const [t, n] of e.resultDocuments) + if (n === e.outputDocument) return t; return "#default"; } - function f({ currentContext: t }, e, n) { + function f({ currentContext: e }, t, n) { const { keys: o, contextItem: r, variableScopes: a, patternMatchCache: s, - } = t; - if (!o.has(e)) throw new Error("XTDE1260"); - return o.get(e).lookup(s, r.ownerDocument, a, n) || []; + } = e; + if (!o.has(t)) throw new Error("XTDE1260"); + return o.get(t).lookup(s, r.ownerDocument, a, n) || []; } const x = new Set([ "apply-imports", @@ -1336,66 +1357,66 @@ "value-of", "variable", ]); - function h(t, e) { - const [n, o] = e.split(":"); + function h(e, t) { + const [n, o] = t.split(":"); return !(!n || !o) && x.has(o); } - function g(t, e) { - return "version" === e.split(":")[1] + function g(e, t) { + return "version" === t.split(":")[1] ? "2.0" - : "vendor" === e.split(":")[1] + : "vendor" === t.split(":")[1] ? "xjslt" - : "vendor-url" === e.split(":")[1] + : "vendor-url" === t.split(":")[1] ? "https://github.com/egh/xjslt" - : "product-name" === e.split(":")[1] + : "product-name" === t.split(":")[1] ? "xjslt" - : "product-version" === e.split(":")[1] + : "product-version" === t.split(":")[1] ? "0.1" - : "supports-backwards-compatibility" === e.split(":")[1] || - "is-schema-aware" === e.split(":")[1] || - "supports-serialization" === e.split(":")[1] || - "supports-backwards-compatibility" === e.split(":")[1] + : "supports-backwards-compatibility" === t.split(":")[1] || + "is-schema-aware" === t.split(":")[1] || + "supports-serialization" === t.split(":")[1] || + "supports-backwards-compatibility" === t.split(":")[1] ? "no" : ""; } - function w({ currentContext: t }, e) { - const n = void 0 !== e ? e : t.contextItem; + function w({ currentContext: e }, t) { + const n = void 0 !== t ? t : e.contextItem; if (!n) return null; let o = n; const r = []; for (; o; ) { - const t = + const e = 1 === o.nodeType ? o.getAttributeNS( "http://www.w3.org/XML/1998/namespace", "base", ) : null; - (t && r.unshift(t), (o = o.parentNode)); + (e && r.unshift(e), (o = o.parentNode)); } - let a = t.inputURL || void 0; - for (const t of r) a = new URL(t, a) || t; + let a = e.inputURL || void 0; + for (const e of r) a = new URL(e, a) || e; return a; } - function N(t, e, n) { - if (null == e) return ""; + function N(e, t, n) { + if (null == t) return ""; const o = n.toUpperCase().replace("-", ""); if (!["NFC", "NFD", "NFKC", "NFKD"].includes(o)) throw new Error("FOCH0003: Normalization form not supported."); - return e.normalize(o); + return t.normalize(o); } - function v({ currentContext: t }, e, n, o) { + function v({ currentContext: e }, t, n, o) { var s, i; const c = o || "#default", u = null !== (i = - null === (s = t.decimalFormats) || void 0 === s + null === (s = e.decimalFormats) || void 0 === s ? void 0 : s.get(c)) && void 0 !== i ? i : r.DEFAULT_DECIMAL_FORMAT; - return (0, a.formatNumberWithPicture)(e, n, u); + return (0, a.formatNumberWithPicture)(t, n, u); } const T = [ "base-uri", @@ -1412,77 +1433,77 @@ "positionx", "system-property", ]; - function y({ prefix: t, localName: e }, n) { - return (t && "fn" !== t) || !T.includes(e) + function y({ prefix: e, localName: t }, n) { + return (e && "fn" !== e) || !T.includes(t) ? null - : { namespaceURI: r.XJSLT_NSURI, localName: e }; + : { namespaceURI: r.XJSLT_NSURI, localName: t }; } }, - 845(t, e, n) { + 845(e, t, n) { "use strict"; - (Object.defineProperty(e, "__esModule", { value: !0 }), - (e.toAlphabeticUpper = e.toAlphabetic = void 0), - (e.groupNumeric = s), - (e.toNumeric = i), - (e.mkToAlphabetic = c), - (e.toRoman = u), - (e.formatWithToken = l), - (e.formatNumber = function (t, e, n, o) { + (Object.defineProperty(t, "__esModule", { value: !0 }), + (t.toAlphabeticUpper = t.toAlphabetic = void 0), + (t.groupNumeric = s), + (t.toNumeric = i), + (t.mkToAlphabetic = c), + (t.toRoman = u), + (t.formatWithToken = l), + (t.formatNumber = function (e, t, n, o) { const r = []; - e.prefix && r.push(e.prefix); - for (let a = 0; a < t.length; a++) { - const s = Math.min(a, e.formats.length - 1), - i = e.formats[s]; + t.prefix && r.push(t.prefix); + for (let a = 0; a < e.length; a++) { + const s = Math.min(a, t.formats.length - 1), + i = t.formats[s]; if (!i) throw new Error("No number format found"); (i.separator && 0 !== a && r.push(i.separator), - r.push(l(t[a], i.format, n, o))); + r.push(l(e[a], i.format, n, o))); } - return (e.suffix && r.push(e.suffix), r.join("")); + return (t.suffix && r.push(t.suffix), r.join("")); }), - (e.remapDigits = m), - (e.formatNumberWithPicture = function (t, e, n) { - if (isNaN(t)) return n.nan; - if (!isFinite(t)) return (t < 0 ? n.minusSign : "") + n.infinity; - const a = e.split(n.patternSeparator); + (t.remapDigits = m), + (t.formatNumberWithPicture = function (e, t, n) { + if (isNaN(e)) return n.nan; + if (!isFinite(e)) return (e < 0 ? n.minusSign : "") + n.infinity; + const a = t.split(n.patternSeparator); let c; - if (t < 0) + if (e < 0) if (a.length > 1) c = p(a[1], n); else { - const t = p(a[0], n); - c = Object.assign(Object.assign({}, t), { - prefix: `${n.minusSign}${t.prefix || ""}`, + const e = p(a[0], n); + c = Object.assign(Object.assign({}, e), { + prefix: `${n.minusSign}${e.prefix || ""}`, }); } else c = p(a[0], n); - return (function (t, e, n) { + return (function (e, t, n) { var a; - e.isPercent ? (t *= 100) : e.isPerMille && (t *= 1e3); + t.isPercent ? (e *= 100) : t.isPerMille && (e *= 1e3); const c = (0, o.evaluateXPathToNumber)( "round-half-to-even($number, $precision)", void 0, void 0, { - number: (0, r.wrapValue)(t, "xs:double"), - precision: (0, r.wrapValue)(e.decimalMaxDigits, "xs:integer"), + number: (0, r.wrapValue)(e, "xs:double"), + precision: (0, r.wrapValue)(t.decimalMaxDigits, "xs:integer"), }, ); let u = s( - i(Math.trunc(c), e.integerMinDigits), + i(Math.trunc(c), t.integerMinDigits), n.groupingSeparator, - e.integerGroupSize, + t.integerGroupSize, ), l = null !== (a = c.toString().split(".")[1]) && void 0 !== a ? a : ""; - for (; l.length < e.decimalMinDigits; ) l += "0"; + for (; l.length < t.decimalMinDigits; ) l += "0"; const p = l.length > 0 ? n.decimalSeparator : "", d = n.zeroDigit.codePointAt(0); return ( 48 !== d && ((u = m(u, d)), (l = m(l, d))), - `${e.prefix}${u}${p}${l}${e.suffix}` + `${t.prefix}${u}${p}${l}${t.suffix}` ); - })(Math.abs(t), c, n); + })(Math.abs(e), c, n); })); const o = n(594), r = n(821), @@ -1495,29 +1516,29 @@ 73041, 73121, 92769, 93009, 120783, 120793, 120803, 120813, 120823, 125265, ]; - function s(t, e, n) { - if (!e || !n || t.length <= n) return t; + function s(e, t, n) { + if (!t || !n || e.length <= n) return e; const o = []; - let r = t; + let r = e; for (; r.length > n; ) (o.unshift(r.slice(-n)), (r = r.slice(0, -n))); - return (r && o.unshift(r), o.join(e)); + return (r && o.unshift(r), o.join(t)); } - function i(t, e) { - return t.toString().padStart(e, "0"); + function i(e, t) { + return e.toString().padStart(t, "0"); } - function c(t, e) { - const n = e - t + 1, - o = [...Array(n)].map((e, n) => String.fromCodePoint(t + n)); - return function (t) { - if (0 === t) return "0"; - let e = "", - r = t; - for (; r > 0; ) (r--, (e = o[r % n] + e), (r = Math.floor(r / n))); - return e; + function c(e, t) { + const n = t - e + 1, + o = [...Array(n)].map((t, n) => String.fromCodePoint(e + n)); + return function (e) { + if (0 === e) return "0"; + let t = "", + r = e; + for (; r > 0; ) (r--, (t = o[r % n] + t), (r = Math.floor(r / n))); + return t; }; } - function u(t) { - const e = new Map([ + function u(e) { + const t = new Map([ [1e3, "m"], [900, "cm"], [500, "d"], @@ -1532,36 +1553,36 @@ [4, "iv"], [1, "i"], ]); - if (0 === t) return "0"; + if (0 === e) return "0"; let n = "", - o = t; - for (const [t, r] of e) for (; o >= t; ) ((n += r), (o -= t)); + o = e; + for (const [e, r] of t) for (; o >= e; ) ((n += r), (o -= e)); return n; } - function l(t, n, o, r) { - if (isNaN(t) || !isFinite(t)) return ""; - if (/0*1/.test(n)) return s(i(t, n.length), o, r); - if ("A" === n) return (0, e.toAlphabeticUpper)(t) || ""; - if ("a" === n) return (0, e.toAlphabetic)(t) || ""; - if ("I" === n) return u(t).toUpperCase(); - if ("i" === n) return u(t); - for (const e of a) { - if (49 === e) continue; - const a = e - 1; + function l(e, n, o, r) { + if (isNaN(e) || !isFinite(e)) return ""; + if (/0*1/.test(n)) return s(i(e, n.length), o, r); + if ("A" === n) return (0, t.toAlphabeticUpper)(e) || ""; + if ("a" === n) return (0, t.toAlphabetic)(e) || ""; + if ("I" === n) return u(e).toUpperCase(); + if ("i" === n) return u(e); + for (const t of a) { + if (49 === t) continue; + const a = t - 1; if ( new RegExp( - `${String.fromCharCode(a)}*${String.fromCharCode(e)}`, + `${String.fromCharCode(a)}*${String.fromCharCode(t)}`, ).test(n) ) - return s(m(i(t, n.length), a), o, r); + return s(m(i(e, n.length), a), o, r); } - return s(i(t, n.length), o, r); + return s(i(e, n.length), o, r); } - function p(t, e) { - const n = e.zeroDigit, - o = e.digit, - r = e.decimalSeparator, - a = e.groupingSeparator; + function p(e, t) { + const n = t.zeroDigit, + o = t.digit, + r = t.decimalSeparator, + a = t.groupingSeparator; let s = 0, i = !1, c = !1; @@ -1573,10 +1594,10 @@ } function l() { let a = ""; - for (; s < t.length && t[s] !== n && t[s] !== o && t[s] !== r; ) - (t[s] === e.percent && (u(), (i = !0)), - t[s] === e.perMille && (u(), (c = !0)), - (a += t[s++])); + for (; s < e.length && e[s] !== n && e[s] !== o && e[s] !== r; ) + (e[s] === t.percent && (u(), (i = !0)), + e[s] === t.perMille && (u(), (c = !0)), + (a += e[s++])); return a; } const p = l(); @@ -1584,12 +1605,12 @@ d = 0, f = 0, x = -1; - for (; s < t.length && t[s] !== r; ) { - const e = t[s]; - if (e === n) (d++, f++); - else if (e === o) f++; + for (; s < e.length && e[s] !== r; ) { + const t = e[s]; + if (t === n) (d++, f++); + else if (t === o) f++; else { - if (e !== a) break; + if (t !== a) break; x = f; } s++; @@ -1597,20 +1618,20 @@ x >= 0 && (m = f - x); let h = 0, g = 0; - if (s < t.length && t[s] === r) - for (s++; s < t.length; ) { - const e = t[s]; - if (e === n) (h++, g++); + if (s < e.length && e[s] === r) + for (s++; s < e.length; ) { + const t = e[s]; + if (t === n) (h++, g++); else { - if (e !== o) break; + if (t !== o) break; g++; } s++; } const w = l(); - if (s < t.length) + if (s < e.length) throw new Error( - `XTDE1310: Active characters after picture string suffix: ${t.slice(s)}`, + `XTDE1310: Active characters after picture string suffix: ${e.slice(s)}`, ); return { prefix: p, @@ -1623,75 +1644,75 @@ isPerMille: c, }; } - function m(t, e) { - return [...t] - .map((t) => { - const n = t.codePointAt(0); - return n >= 48 && n <= 57 ? String.fromCodePoint(e + n - 48) : t; + function m(e, t) { + return [...e] + .map((e) => { + const n = e.codePointAt(0); + return n >= 48 && n <= 57 ? String.fromCodePoint(t + n - 48) : e; }) .join(""); } - ((e.toAlphabetic = c(97, 122)), (e.toAlphabeticUpper = c(65, 90))); + ((t.toAlphabetic = c(97, 122)), (t.toAlphabeticUpper = c(65, 90))); }, - 777(t, e) { + 777(e, t) { "use strict"; - function n(t) { - return "yes" === t; + function n(e) { + return "yes" === e; } - function o(t) { - return "omit" === t ? void 0 : "yes" === t; + function o(e) { + return "omit" === e ? void 0 : "yes" === e; } - (Object.defineProperty(e, "__esModule", { value: !0 }), - (e.parseYesNo = n), - (e.parseYesNoOmit = o), - (e.isAlphanumeric = function (t) { + (Object.defineProperty(t, "__esModule", { value: !0 }), + (t.parseYesNo = n), + (t.parseYesNoOmit = o), + (t.isAlphanumeric = function (e) { return /^[\p{Nd}\p{Nl}\p{No}\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Lo}]$/u.test( - t, + e, ); }), - (e.mkOutputDefinition = function (t) { + (t.mkOutputDefinition = function (e) { return { - omitXmlDeclaration: n(t.omitXmlDeclaration), - standalone: o(t.standalone), - doctypeSystem: t.doctypeSystem, - doctypePublic: t.doctypePublic, + omitXmlDeclaration: n(e.omitXmlDeclaration), + standalone: o(e.standalone), + doctypeSystem: e.doctypeSystem, + doctypePublic: e.doctypePublic, }; }), - (e.mkResolver = function (t) { - return (e) => - "" === e && "#xpath-default" in t - ? t["#xpath-default"] || null - : t[e]; + (t.mkResolver = function (e) { + return (t) => + "" === t && "#xpath-default" in e + ? e["#xpath-default"] || null + : e[t]; }), - (e.determineNamespace = function (t, e, n) { + (t.determineNamespace = function (e, t, n) { let o = n; - if (void 0 !== o) return [o, t]; + if (void 0 !== o) return [o, e]; let r = ""; return ( - t.includes(":") && ([r, t] = t.split(":")), - (o = e(r)), - [o, t] + e.includes(":") && ([r, e] = e.split(":")), + (o = t(r)), + [o, e] ); }), - (e.computeDefaultPriority = function t(e) { - if (e && e.includes("|")) + (t.computeDefaultPriority = function e(t) { + if (t && t.includes("|")) return Math.max( - ...e + ...t .split("|") - .filter((t) => "" !== t) - .map((e) => t(e)), + .filter((e) => "" !== e) + .map((t) => e(t)), ); - for (let [t, n] of i) if (t.test(e)) return n; + for (let [e, n] of i) if (e.test(t)) return n; return 0.5; }), - (e.compareSortable = c), - (e.sortSortable = function (t) { - return t.sort(c); + (t.compareSortable = c), + (t.sortSortable = function (e) { + return e.sort(c); }), - (e.zip = function (t, e) { - if (void 0 === t || void 0 === e) return []; - const n = Math.min(t.length, e.length); - return t.slice(0, n).map((t, n) => [t, e[n]]); + (t.zip = function (e, t) { + if (void 0 === e || void 0 === t) return []; + const n = Math.min(e.length, t.length); + return e.slice(0, n).map((e, n) => [e, t[n]]); })); const r = String.raw`[^,:\(\)\*\[\]/]`, a = String.raw`(child::|attribute::|@)?`, @@ -1749,194 +1770,185 @@ [new RegExp(String.raw`^\s*${a}\*:${r}+\s*$`), -0.25], [new RegExp(String.raw`^\s*${a}${r}+\s*$`), 0], ]); - function c(t, e) { - const n = t.importPrecedence - e.importPrecedence; + function c(e, t) { + const n = e.importPrecedence - t.importPrecedence; if (0 !== n) return n; { - const n = e.priority - t.priority; - return 0 !== n ? n : e.declarationOrder - t.declarationOrder; + const n = t.priority - e.priority; + return 0 !== n ? n : t.declarationOrder - e.declarationOrder; } } }, - 472(t, e, n) { + 472(e, t) { "use strict"; - (Object.defineProperty(e, "__esModule", { value: !0 }), - (e.urlToDom = function (t, e) { - if (!t.readDocument) return; - const n = t.inputURL ? (0, o.resolve)(t.inputURL.toString(), e) : e; - return t.readDocument(n); + (Object.defineProperty(t, "__esModule", { value: !0 }), + (t.urlToDom = function (e, t) { + const n = e.inputURL + ? new URL(t, e.inputURL.toString()).toString() + : t; + return e.readDocument(n); })); - const o = n(16); }, - 821(t, e, n) { + 821(e, t, n) { "use strict"; var o, r = (this && this.__createBinding) || (Object.create - ? function (t, e, n, o) { + ? function (e, t, n, o) { void 0 === o && (o = n); - var r = Object.getOwnPropertyDescriptor(e, n); + var r = Object.getOwnPropertyDescriptor(t, n); ((r && !("get" in r - ? !e.__esModule + ? !t.__esModule : r.writable || r.configurable)) || (r = { enumerable: !0, get: function () { - return e[n]; + return t[n]; }, }), - Object.defineProperty(t, o, r)); + Object.defineProperty(e, o, r)); } - : function (t, e, n, o) { - (void 0 === o && (o = n), (t[o] = e[n])); + : function (e, t, n, o) { + (void 0 === o && (o = n), (e[o] = t[n])); }), a = (this && this.__setModuleDefault) || (Object.create - ? function (t, e) { - Object.defineProperty(t, "default", { + ? function (e, t) { + Object.defineProperty(e, "default", { enumerable: !0, - value: e, + value: t, }); } - : function (t, e) { - t.default = e; + : function (e, t) { + e.default = t; }), s = (this && this.__importStar) || - ((o = function (t) { + ((o = function (e) { return ( (o = Object.getOwnPropertyNames || - function (t) { - var e = []; - for (var n in t) - Object.prototype.hasOwnProperty.call(t, n) && - (e[e.length] = n); - return e; + function (e) { + var t = []; + for (var n in e) + Object.prototype.hasOwnProperty.call(e, n) && + (t[t.length] = n); + return t; }), - o(t) + o(e) ); }), - function (t) { - if (t && t.__esModule) return t; - var e = {}; - if (null != t) - for (var n = o(t), s = 0; s < n.length; s++) - "default" !== n[s] && r(e, t, n[s]); - return (a(e, t), e); + function (e) { + if (e && e.__esModule) return e; + var t = {}; + if (null != e) + for (var n = o(e), s = 0; s < n.length; s++) + "default" !== n[s] && r(t, e, n[s]); + return (a(t, e), t); }); - (Object.defineProperty(e, "__esModule", { value: !0 }), - (e.NodeTypeFeature = - e.NodeTextFeature = - e.NodeNameFeature = - e.NodeNamespaceFeature = - e.NodeAttributeFeature = - e.selfNode = - e.greatGrandParentNode = - e.grandParentNode = - e.parentNode = - e.KeyImpl = + (Object.defineProperty(t, "__esModule", { value: !0 }), + (t.NodeTypeFeature = + t.NodeTextFeature = + t.NodeNameFeature = + t.NodeNamespaceFeature = + t.NodeAttributeFeature = + t.selfNode = + t.greatGreatGrandParentNode = + t.greatGrandParentNode = + t.grandParentNode = + t.parentNode = + t.ancestorNodes = + t.KeyImpl = void 0), - (e.visitNodes = x), - (e.dedupGenerator = y), - (e.mergeTemplateGenerators = b), - (e.processNode = S), - (e.nextMatch = function (t, e) { - const n = t.nextMatches; + (t.visitNodes = x), + (t.dedupGenerator = y), + (t.mergeTemplateGenerators = b), + (t.processNode = S), + (t.nextMatch = function (e, t) { + const n = e.nextMatches; if (n) { const o = n.next(); - o.done || - C( - o.value, - Object.assign(Object.assign({}, t), { nextMatches: n }), - e.params, - ); + o.done || ((e.nextMatches = n), C(o.value, e, t.params)); } }), - (e.applyImports = function (t, e) { - const n = t.nextMatches; + (t.applyImports = function (e, t) { + const n = e.nextMatches; if (n) { let o = n.next(); for (; !o.done && 1 === o.value.importPrecedence; ) o = n.next(); - o.done || - C( - o.value, - Object.assign(Object.assign({}, t), { nextMatches: n }), - e.params, - ); + o.done || ((e.nextMatches = n), C(o.value, e, t.params)); } }), - (e.sort = O), - (e.applyTemplates = function (t, e) { - const n = (0, p.mkResolver)(e.namespaces), + (t.sort = j), + (t.applyTemplates = function (e, t) { + const n = (0, p.mkResolver)(t.namespaces), o = (0, i.evaluateXPathToNodes)( - e.select, - t.contextItem, + t.select, + e.contextItem, void 0, - _(t.variableScopes), + _(e.variableScopes), { - currentContext: t, + currentContext: e, namespaceResolver: n, functionNameResolver: u.functionNameResolver, }, ); - let r = e.mode || "#default"; - ("#current" === r && (r = t.mode), - I(O(t, o, e.sortKeyComponents, n), t, (t) => { - S( - Object.assign(Object.assign({}, t), { - mode: r, - variableScopes: $(t.variableScopes), - }), - e.params, - e.namespaces, - ); - })); + let r = t.mode || "#default"; + ("#current" === r && (r = e.mode), + I( + j(e, o, t.sortKeyComponents, n), + Object.assign(Object.assign({}, e), { mode: r }), + (e) => { + ((e.variableScopes = $(e.variableScopes)), + S(e, t.params, t.namespaces), + e.variableScopes.pop()); + }, + )); }), - (e.callTemplate = function (t, e) { - const n = t.namedTemplates.get(e.name); - if (void 0 !== n) return C(t.templates[n], t, e.params); - throw new Error(`Cannot find a template named ${e.name}`); + (t.callTemplate = function (e, t) { + const n = e.namedTemplates.get(t.name); + if (void 0 !== n) return C(e.templates[n], e, t.params); + throw new Error(`Cannot find a template named ${t.name}`); }), - (e.functionX = function (t, e) { - const n = t.params.map((t) => "item()"), - o = t.params.map((t) => t.name); + (t.functionX = function (e, t) { + const n = e.params.map((e) => "item()"), + o = e.params.map((e) => e.name); (0, i.registerCustomXPathFunction)( - { namespaceURI: t.namespace, localName: t.name }, + { namespaceURI: e.namespace, localName: e.name }, n, - t.as || "item()", - ({ currentContext: t }, ...n) => { + e.as || "item()", + ({ currentContext: e }, ...n) => { let r = new Map(); return ( - o.forEach((t, e) => r.set(t, n[e])), + o.forEach((e, t) => r.set(e, n[t])), J( - Object.assign(Object.assign({}, t), { - variableScopes: [r].concat(t.variableScopes), + Object.assign(Object.assign({}, e), { + variableScopes: [r].concat(e.variableScopes), }), - e, + t, ) ); }, ); }), - (e.copy = function (t, e, n) { - const o = t.contextItem; + (t.copy = function (e, t, n) { + const o = e.contextItem; let r, a; if (o.nodeType === l.NodeType.ELEMENT) { - const e = o; - r = t.outputDocument.createElementNS( - e.namespaceURI, - e.prefix ? `${e.prefix}:${e.localName}` : e.localName, + const t = o; + r = e.outputDocument.createElementNS( + t.namespaceURI, + t.prefix ? `${t.prefix}:${t.localName}` : t.localName, ); - for (let n of e.attributes) + for (let n of t.attributes) if (n.namespaceURI === l.XMLNS_NSURI) { const o = n.localName; r.setAttributeNode( - t.outputDocument.importNode( - e.getAttributeNodeNS(l.XMLNS_NSURI, o), + e.outputDocument.importNode( + t.getAttributeNodeNS(l.XMLNS_NSURI, o), ), ); } @@ -1944,505 +1956,503 @@ r = o.nodeType === l.NodeType.DOCUMENT ? void 0 - : t.outputDocument.importNode(o); - (r && (a = t.append(r)), + : e.outputDocument.importNode(o); + (r && (a = e.append(r)), n && n( - Object.assign(Object.assign({}, t), { - append: a || t.append, + Object.assign(Object.assign({}, e), { + append: a || e.append, }), )); }), - (e.copyOf = function (t, e) { + (t.copyOf = function (e, t) { let n = (0, i.evaluateXPath)( - e.select, - t.contextItem, + t.select, + e.contextItem, void 0, - _(t.variableScopes), + _(e.variableScopes), i.evaluateXPath.ALL_RESULTS_TYPE, { - currentContext: t, - namespaceResolver: (0, p.mkResolver)(e.namespaces), + currentContext: e, + namespaceResolver: (0, p.mkResolver)(t.namespaces), functionNameResolver: u.functionNameResolver, }, ); - for (let e of n) t.append(e); + for (let t of n) e.append(t); }), - (e.valueOf = function (t, e, n) { - t.append( - Y(t, e.select || n, (0, p.mkResolver)(e.namespaces), e.separator), + (t.valueOf = function (e, t, n) { + e.append( + Y(e, t.select || n, (0, p.mkResolver)(t.namespaces), t.separator), ); }), - (e.message = function (t, e, n) { - const o = Y(t, e.select || n, (0, p.mkResolver)(e.namespaces)); - if ("yes" === e.terminate) throw new Error(o); + (t.message = function (e, t, n) { + const o = Y(e, t.select || n, (0, p.mkResolver)(t.namespaces)); + if ("yes" === t.terminate) throw new Error(o); console.log(o); }), - (e.text = function (t, e, n) { - t.append(Y(t, n, (0, p.mkResolver)(e.namespaces), [""])); + (t.text = function (e, t, n) { + e.append(Y(e, n, (0, p.mkResolver)(t.namespaces), [""])); }), - (e.variable = function (t, e) { - M(t.variableScopes, e.name, B(t, e)); + (t.variable = function (e, t) { + M(e.variableScopes, t.name, B(e, t)); }), - (e.param = function (t, e) { - M(t.variableScopes, e.name, t.stylesheetParams[e.name] || B(t, e)); + (t.param = function (e, t) { + M(e.variableScopes, t.name, e.stylesheetParams[t.name] || B(e, t)); }), - (e.extendScope = $), - (e.wrapValue = L), - (e.setVariable = M), - (e.mergeVariableScopes = _), - (e.literalText = function (t, e) { - t.append(e); + (t.extendScope = $), + (t.wrapValue = L), + (t.setVariable = M), + (t.mergeVariableScopes = _), + (t.literalText = function (e, t) { + e.append(t); }), - (e.sequence = function (t, e) { + (t.sequence = function (e, t) { const n = (0, i.evaluateXPath)( - e.select, - t.contextItem, + t.select, + e.contextItem, void 0, - _(t.variableScopes), + _(e.variableScopes), i.evaluateXPath.ALL_RESULTS_TYPE, { - currentContext: t, - namespaceResolver: (0, p.mkResolver)(e.namespaces), + currentContext: e, + namespaceResolver: (0, p.mkResolver)(t.namespaces), functionNameResolver: u.functionNameResolver, }, ); - t.append(n); + e.append(n); }), - (e.buildNode = A), - (e.buildAttributeNode = U), - (e.literalElement = function (t, e, n) { - let o = A(t, { name: e.name, namespace: e.namespace }); - const r = (0, p.mkResolver)(e.namespaces); - for (let n of e.attributes) { - const e = G(t, n.value, r), - a = U(t, { name: n.name, namespace: n.namespace, value: e }); + (t.buildNode = A), + (t.buildAttributeNode = U), + (t.literalElement = function (e, t, n) { + let o = A(e, { name: t.name, namespace: t.namespace }); + const r = (0, p.mkResolver)(t.namespaces); + for (let n of t.attributes) { + const t = z(e, n.value, r), + a = U(e, { name: n.name, namespace: n.namespace, value: t }); o.setAttributeNode(a); } - const a = t.append(o); + const a = e.append(o); n( - Object.assign(Object.assign({}, t), { - variableScopes: $(t.variableScopes), - append: a || t.append, + Object.assign(Object.assign({}, e), { + variableScopes: $(e.variableScopes), + append: a || e.append, }), ); }), - (e.attribute = function (t, e, n) { - const o = (0, p.mkResolver)(e.namespaces), - r = G(t, e.name, o), - a = G(t, e.namespace, o), + (t.attribute = function (e, t, n) { + const o = (0, p.mkResolver)(t.namespaces), + r = z(e, t.name, o), + a = z(e, t.namespace, o), [s, i] = r.includes(":") ? (0, p.determineNamespace)(r, o, a) : [a, r], - c = U(t, { + c = U(e, { name: r, namespace: s, - value: Y(t, e.select || n, o, e.separator), + value: Y(e, t.select || n, o, t.separator), }); - t.append(c); + e.append(c); }), - (e.processingInstruction = function (t, e, n) { - const o = G(t, e.name, (0, p.mkResolver)(e.namespaces)), - r = Y(t, e.select || n, (0, p.mkResolver)(e.namespaces), [ + (t.processingInstruction = function (e, t, n) { + const o = z(e, t.name, (0, p.mkResolver)(t.namespaces)), + r = Y(e, t.select || n, (0, p.mkResolver)(t.namespaces), [ "", ]).trimStart(); - t.append(t.outputDocument.createProcessingInstruction(o, r)); + e.append(e.outputDocument.createProcessingInstruction(o, r)); }), - (e.comment = function (t, e, n) { - const o = Y(t, e.select || n, (0, p.mkResolver)(e.namespaces), [ + (t.comment = function (e, t, n) { + const o = Y(e, t.select || n, (0, p.mkResolver)(t.namespaces), [ "", ]); - t.append(t.outputDocument.createComment(o)); + e.append(e.outputDocument.createComment(o)); }), - (e.namespace = function (t, e, n) { - const o = (0, p.mkResolver)(e.namespaces), - r = G(t, e.name, o), - a = Y(t, e.select || n, o, [""]), - s = U(t, { + (t.namespace = function (e, t, n) { + const o = (0, p.mkResolver)(t.namespaces), + r = z(e, t.name, o), + a = Y(e, t.select || n, o, [""]), + s = U(e, { name: `xmlns:${r}`, namespace: l.XMLNS_NSURI, value: a, }); - t.append(s); + e.append(s); }), - (e.element = function (t, e, n) { - const o = (0, p.mkResolver)(e.namespaces); - let r = G(t, e.name, o), - a = G(t, e.namespace, o), - s = A(t, { + (t.element = function (e, t, n) { + const o = (0, p.mkResolver)(t.namespaces); + let r = z(e, t.name, o), + a = z(e, t.namespace, o), + s = A(e, { name: r, namespace: (0, p.determineNamespace)( r, - (0, p.mkResolver)(e.namespaces), + (0, p.mkResolver)(t.namespaces), a, )[0], }); - const i = t.append(s); + const i = e.append(s); n( - Object.assign(Object.assign({}, t), { - variableScopes: $(t.variableScopes), - append: i || t.append, + Object.assign(Object.assign({}, e), { + variableScopes: $(e.variableScopes), + append: i || e.append, }), ); }), - (e.ifX = function (t, e, n) { + (t.ifX = function (e, t, n) { (0, i.evaluateXPathToBoolean)( - e.test, - t.contextItem, + t.test, + e.contextItem, void 0, - _(t.variableScopes), + _(e.variableScopes), { - currentContext: t, - namespaceResolver: (0, p.mkResolver)(e.namespaces), + currentContext: e, + namespaceResolver: (0, p.mkResolver)(t.namespaces), functionNameResolver: u.functionNameResolver, }, - ) && n(t); + ) && n(e); }), - (e.choose = function (t, e) { - for (let n of e) { - if (!n.test) return n.apply(t); + (t.choose = function (e, t) { + for (let n of t) { + if (!n.test) return n.apply(e); if ( (0, i.evaluateXPathToBoolean)( n.test, - t.contextItem, + e.contextItem, void 0, - _(t.variableScopes), + _(e.variableScopes), { - currentContext: t, + currentContext: e, functionNameResolver: u.functionNameResolver, }, ) ) - return n.apply(t); + return n.apply(e); } }), - (e.document = function (t, e, n) { - const o = t.outputDocument.implementation.createDocument( + (t.document = function (e, t, n) { + const o = e.outputDocument.implementation.createDocument( null, null, null, ), - r = t.append(o); + r = e.append(o); n( - Object.assign(Object.assign({}, t), { + Object.assign(Object.assign({}, e), { outputDocument: o, append: r, mode: "#default", - variableScopes: $(t.variableScopes), + variableScopes: $(e.variableScopes), }), ); }), - (e.performSort = function (t, e) { - const n = (0, p.mkResolver)(e.namespaces), + (t.performSort = function (e, t) { + const n = (0, p.mkResolver)(t.namespaces), o = (0, i.evaluateXPath)( - e.select, - t.contextItem, + t.select, + e.contextItem, void 0, - _(t.variableScopes), + _(e.variableScopes), i.evaluateXPath.ALL_RESULTS_TYPE, { - currentContext: t, + currentContext: e, namespaceResolver: n, functionNameResolver: u.functionNameResolver, }, ); if (o && Symbol.iterator in Object(o)) { - const r = O(t, o, e.sortKeyComponents, n); - for (let e of r) t.append(e); + const r = j(e, o, t.sortKeyComponents, n); + for (let t of r) e.append(t); } }), - (e.forEach = function (t, e, n) { - const o = (0, p.mkResolver)(e.namespaces); + (t.forEach = function (e, t, n) { + const o = (0, p.mkResolver)(t.namespaces); let r = (0, i.evaluateXPath)( - e.select, - t.contextItem, + t.select, + e.contextItem, void 0, - _(t.variableScopes), + _(e.variableScopes), i.evaluateXPath.ALL_RESULTS_TYPE, { - currentContext: t, + currentContext: e, namespaceResolver: o, functionNameResolver: u.functionNameResolver, }, ); r && Symbol.iterator in Object(r) && - ((r = O(t, r, e.sortKeyComponents, o)), - I(r, t, (t) => { - n( - Object.assign(Object.assign({}, t), { - variableScopes: $(t.variableScopes), - }), - ); + ((r = j(e, r, t.sortKeyComponents, o)), + I(r, e, (e) => { + ((e.variableScopes = $(e.variableScopes)), + n(e), + e.variableScopes.pop()); })); }), - (e.forEachGroup = function (t, e, n) { - const o = (0, p.mkResolver)(e.namespaces), - r = _(t.variableScopes), + (t.forEachGroup = function (e, t, n) { + const o = (0, p.mkResolver)(t.namespaces), + r = _(e.variableScopes), a = (0, i.evaluateXPathToNodes)( - e.select, - t.contextItem, + t.select, + e.contextItem, void 0, r, { - currentContext: t, + currentContext: e, namespaceResolver: o, functionNameResolver: u.functionNameResolver, }, ); if (a && Symbol.iterator in Object(a)) { let r = []; - (e.groupBy - ? (r = (function (t, e, n, o) { - const r = _(t.variableScopes); + (t.groupBy + ? (r = (function (e, t, n, o) { + const r = _(e.variableScopes); let a = []; return ( - I(e, t, (t) => { - const e = (0, i.evaluateXPathToString)( + I(t, e, (e) => { + const t = (0, i.evaluateXPathToString)( n, - t.contextItem, + e.contextItem, void 0, r, { - currentContext: t, + currentContext: e, namespaceResolver: o, functionNameResolver: u.functionNameResolver, }, ); - let s = a.find((t) => t.key === e); - (s || ((s = { key: e, nodes: [] }), a.push(s)), - s.nodes.push(t.contextItem)); + let s = a.find((e) => e.key === t); + (s || ((s = { key: t, nodes: [] }), a.push(s)), + s.nodes.push(e.contextItem)); }), a ); - })(t, a, e.groupBy, o)) - : e.groupAdjacent - ? (r = (function (t, e, n, o) { - const r = _(t.variableScopes); + })(e, a, t.groupBy, o)) + : t.groupAdjacent + ? (r = (function (e, t, n, o) { + const r = _(e.variableScopes); let a = [], s = null, c = []; return ( - I(e, t, (t) => { - const e = t.contextItem, - l = (0, i.evaluateXPathToString)(n, e, void 0, r, { - currentContext: t, + I(t, e, (e) => { + const t = e.contextItem, + l = (0, i.evaluateXPathToString)(n, t, void 0, r, { + currentContext: e, namespaceResolver: o, functionNameResolver: u.functionNameResolver, }); l !== s - ? (F(a, c, s), (s = l), (c = [e])) - : c.push(e); + ? (F(a, c, s), (s = l), (c = [t])) + : c.push(t); }), F(a, c, s), a ); - })(t, a, e.groupAdjacent, o)) - : e.groupEndingWith - ? (r = (function (t, e, n, o) { + })(e, a, t.groupAdjacent, o)) + : t.groupEndingWith + ? (r = (function (e, t, n, o) { let r = [], a = []; return ( - I(e, t, (t) => { - const e = t.contextItem; - (a.push(e), + I(t, e, (e) => { + const t = e.contextItem; + (a.push(t), T( - t.patternMatchCache, + e.patternMatchCache, n, - e, - t.variableScopes, + t, + _(e.variableScopes), o, ) && (F(r, a), (a = []))); }), F(r, a), r ); - })(t, a, e.groupEndingWith, o)) - : e.groupStartingWith && - (r = (function (t, e, n, o) { + })(e, a, t.groupEndingWith, o)) + : t.groupStartingWith && + (r = (function (e, t, n, o) { let r = [], a = []; return ( - I(e, t, (t) => { - const e = t.contextItem; + I(t, e, (e) => { + const t = e.contextItem; (T( - t.patternMatchCache, + e.patternMatchCache, n, - e, - t.variableScopes, + t, + _(e.variableScopes), o, ) && (F(r, a), (a = [])), - a.push(e)); + a.push(t)); }), F(r, a), r ); - })(t, a, e.groupStartingWith, o)), - (r = O(t, r, e.sortKeyComponents, o)), - j(r, t, n)); + })(e, a, t.groupStartingWith, o)), + (r = j(e, r, t.sortKeyComponents, o)), + P(r, e, n)); } }), - (e.number = function (t, e) { - const n = (0, p.mkResolver)(e.namespaces), - o = _(t.variableScopes); + (t.number = function (e, t) { + const n = (0, p.mkResolver)(t.namespaces), + o = _(e.variableScopes); let r; - (e.value + (t.value ? (r = (0, i.evaluateXPathToNumber)( - e.value, - t.contextItem, + t.value, + e.contextItem, void 0, o, { - currentContext: t, + currentContext: e, namespaceResolver: n, functionNameResolver: u.functionNameResolver, }, )) - : "single" === e.level && - void 0 === e.value && - void 0 === e.select && - void 0 === e.count && - (r = t.position), - t.append( + : "single" === t.level && + void 0 === t.value && + void 0 === t.select && + void 0 === t.count && + (r = e.position), + e.append( (0, m.formatNumber)( [r], - e.format, - e.groupingSeparator, - e.groupingSize, + t.format, + t.groupingSeparator, + t.groupingSize, ), )); }), - (e.mkNodeAppender = k), - (e.mkArrayAppender = z), - (e.resultDocument = function (t, e, n) { - const o = (0, p.mkResolver)(e.namespaces); - function r(e) { - return G(t, e, o); + (t.mkNodeAppender = k), + (t.mkArrayAppender = G), + (t.resultDocument = function (e, t, n) { + const o = (0, p.mkResolver)(t.namespaces); + function r(t) { + return z(e, t, o); } - const a = r(e.format); + const a = r(t.format); let s = (0, p.mkOutputDefinition)({ - omitXmlDeclaration: r(e.omitXmlDeclaration), - doctypePublic: r(e.doctypePublic), - doctypeSystem: r(e.doctypeSystem), - standalone: r(e.standalone), + omitXmlDeclaration: r(t.omitXmlDeclaration), + doctypePublic: r(t.doctypePublic), + doctypeSystem: r(t.doctypeSystem), + standalone: r(t.standalone), }); - Object.keys(s).forEach((t) => { - s[t] || delete s[t]; + Object.keys(s).forEach((e) => { + s[e] || delete s[e]; }); const i = Object.assign( - Object.assign({}, a ? t.outputDefinitions.get(a) : {}), + Object.assign({}, a ? e.outputDefinitions.get(a) : {}), s, ), - c = r(e.href); + c = r(t.href); let u = null; if ( ((i.doctypePublic || i.doctypeSystem) && - (u = t.outputDocument.implementation.createDocumentType( + (u = e.outputDocument.implementation.createDocumentType( "out", i.doctypePublic || "", i.doctypeSystem || "", )), c) ) { - const e = t.outputDocument.implementation.createDocument( + const t = e.outputDocument.implementation.createDocument( null, null, u, ); - if (t.resultDocuments.has(c)) + if (e.resultDocuments.has(c)) throw new Error(`XTDE1490: ${c} is a duplicate`); - (t.resultDocuments.set( + (e.resultDocuments.set( c, - Object.assign(Object.assign({}, i), { document: e }), + Object.assign(Object.assign({}, i), { document: t }), ), n( - Object.assign(Object.assign({}, t), { - outputDocument: e, - append: k(e), + Object.assign(Object.assign({}, e), { + outputDocument: t, + append: k(t), }), )); } else { - if (t.outputDocument.documentElement) throw new Error("XTDE1490"); - let e = t.outputDocument; + if (e.outputDocument.documentElement) throw new Error("XTDE1490"); + let t = e.outputDocument; (u && - ((e = t.outputDocument.implementation.createDocument( + ((t = e.outputDocument.implementation.createDocument( null, null, u, )), - (t.outputDocument = e), - (t.append = k(e))), - t.resultDocuments.set( + (e.outputDocument = t), + (e.append = k(t))), + e.resultDocuments.set( "#default", - Object.assign(Object.assign({}, i), { document: e }), + Object.assign(Object.assign({}, i), { document: t }), ), - n(t)); + n(e)); } }), - (e.stripSpace = function (t, e) { + (t.stripSpace = function (e, t) { const n = RegExp("^[ \n\r\t]+$"); let o = []; - !(function t(r) { + !(function e(r) { if (r.nodeType === l.NodeType.TEXT) n.test(r.textContent) && - (function (t, e) { + (function (e, t) { let n = new Map(); - for (const o of e) { - const e = (0, p.mkResolver)(o.namespaces); - if (T(n, o.match, t, [], e)) return !o.preserve; + for (const o of t) { + const t = (0, p.mkResolver)(o.namespaces); + if (T(n, o.match, e, [], t)) return !o.preserve; } return !1; - })(r.parentNode, e) && + })(r.parentNode, t) && o.push(r); else if (r.hasChildNodes && r.hasChildNodes()) - for (let e of r.childNodes) t(e); - })(t); - for (let t of o) t.remove(); - return t; + for (let t of r.childNodes) e(t); + })(e); + for (let e of o) e.remove(); + return e; }), - (e.evaluateAttributeValueTemplate = G), - (e.serialize = function (t) { - const e = new c.XMLSerializer(); - if (!0 !== t.omitXmlDeclaration) { - let e = new Map([ + (t.evaluateAttributeValueTemplate = z), + (t.serialize = function (e) { + const t = new c.XMLSerializer(); + if (!0 !== e.omitXmlDeclaration) { + let t = new Map([ ["version", "1.0"], ["encoding", "UTF-8"], ["standalone", void 0], ]); - void 0 !== t.standalone && - e.set("standalone", t.standalone ? "yes" : "no"); - const n = Array.from(e) - .map(([t, e]) => (e ? `${t}="${e}"` : "")) + void 0 !== e.standalone && + t.set("standalone", e.standalone ? "yes" : "no"); + const n = Array.from(t) + .map(([e, t]) => (t ? `${e}="${t}"` : "")) .join(" "); - t.document.insertBefore( - t.document.createProcessingInstruction("xml", n), - t.document.firstChild, + e.document.insertBefore( + e.document.createProcessingInstruction("xml", n), + e.document.firstChild, ); } - return e.serializeToString(t.document); + return t.serializeToString(e.document); }), - (e.setParamDefaults = function (t, e) { + (t.setParamDefaults = function (e, t) { return ( - e || (e = {}), - e.outputDocument || - (e.outputDocument = t.implementation.createDocument( + t || (t = {}), + t.outputDocument || + (t.outputDocument = e.implementation.createDocument( null, null, )), - e.outputNode || (e.outputNode = e.outputDocument), - e.initialMode || (e.initialMode = "#default"), - e.stylesheetParams || (e.stylesheetParams = {}), - e + t.outputNode || (t.outputNode = t.outputDocument), + t.initialMode || (t.initialMode = "#default"), + t.stylesheetParams || (t.stylesheetParams = {}), + t ); }), - (e.compileMatchFunction = function (t) { + (t.compileMatchFunction = function (e) { try { - return new Function(t); - } catch (t) { + return new Function(e); + } catch (e) { return; } }), - (e.initialize = function (t, e) {})); + (t.initialize = function (e, t) {})); const i = n(594), c = s(n(898)), u = n(379), @@ -2451,103 +2461,116 @@ m = n(845), d = n(324), f = n(320); - function x(t, e) { - if ((e(t), t.childNodes)) for (let n of t.childNodes) x(n, e); + function x(e, t) { + if ((t(e), e.childNodes)) for (let n of e.childNodes) x(n, t); } - function h(t) { - return Array.isArray(t) - ? t.map((t) => h(t)).join("") - : t.nodeType - ? t.textContent - : t.toString(); + function h(e) { + return Array.isArray(e) + ? e.map((e) => h(e)).join("") + : e.nodeType + ? e.textContent + : e.toString(); } - (Object.defineProperty(e, "greatGrandParentNode", { + (Object.defineProperty(t, "ancestorNodes", { enumerable: !0, get: function () { - return f.greatGrandParentNode; + return f.ancestorNodes; }, }), - Object.defineProperty(e, "grandParentNode", { + Object.defineProperty(t, "greatGrandParentNode", { + enumerable: !0, + get: function () { + return f.greatGrandParentNode; + }, + }), + Object.defineProperty(t, "greatGreatGrandParentNode", { + enumerable: !0, + get: function () { + return f.greatGreatGrandParentNode; + }, + }), + Object.defineProperty(t, "grandParentNode", { enumerable: !0, get: function () { return f.grandParentNode; }, }), - Object.defineProperty(e, "parentNode", { + Object.defineProperty(t, "parentNode", { enumerable: !0, get: function () { return f.parentNode; }, }), - Object.defineProperty(e, "selfNode", { + Object.defineProperty(t, "selfNode", { enumerable: !0, get: function () { return f.selfNode; }, }), - Object.defineProperty(e, "NodeAttributeFeature", { + Object.defineProperty(t, "NodeAttributeFeature", { enumerable: !0, get: function () { return f.NodeAttributeFeature; }, }), - Object.defineProperty(e, "NodeNamespaceFeature", { + Object.defineProperty(t, "NodeNamespaceFeature", { enumerable: !0, get: function () { return f.NodeNamespaceFeature; }, }), - Object.defineProperty(e, "NodeNameFeature", { + Object.defineProperty(t, "NodeNameFeature", { enumerable: !0, get: function () { return f.NodeNameFeature; }, }), - Object.defineProperty(e, "NodeTextFeature", { + Object.defineProperty(t, "NodeTextFeature", { enumerable: !0, get: function () { return f.NodeTextFeature; }, }), - Object.defineProperty(e, "NodeTypeFeature", { + Object.defineProperty(t, "NodeTypeFeature", { enumerable: !0, get: function () { return f.NodeTypeFeature; }, }), - (e.KeyImpl = class { - constructor(t, e, n) { - ((this.match = t), - (this.use = e), + (t.KeyImpl = class { + constructor(e, t, n) { + ((this.match = e), + (this.use = t), (this.namespaces = n), (this.cache = new Map())); } - buildDocumentCache(t, e, n) { + buildDocumentCache(e, t, n) { let o = new Map(); + const r = _(n); return ( - x(e, (e) => { + x(t, (t) => { if ( "string" == typeof this.use && T( - t, - { xpath: this.match }, e, - n, + { xpath: this.match }, + t, + r, (0, p.mkResolver)(this.namespaces), ) ) { - let t = (0, i.evaluateXPathToString)(this.use, e); - (o.has(t) || o.set(t, []), o.set(t, o.get(t).concat(e))); + let e = (0, i.evaluateXPathToString)(this.use, t); + (o.has(e) || o.set(e, []), o.set(e, o.get(e).concat(t))); } }), o ); } - lookup(t, e, n, o) { + lookup(e, t, n, o) { return ( - this.cache.has(e) || - this.cache.set(e, this.buildDocumentCache(t, e, n)), - this.cache.get(e).get(h(o)) + this.cache.has(t) || + this.cache.set(t, this.buildDocumentCache(e, t, n)), + this.cache.get(t).get(h(o)) ); } })); @@ -2555,186 +2578,173 @@ w = new RegExp(/^@[a-z]+$/), N = new RegExp(/text\(\)|node\(\)/), v = new RegExp(/@|attribute|node/); - function T(t, e, n, o, r) { + function T(e, t, n, o, r) { return !( (n && - (function (t, e) { + (function (e, t) { return ( - (e.nodeType === l.NodeType.ATTRIBUTE && !v.exec(t)) || - (e.nodeType === l.NodeType.TEXT && !N.exec(t)) || - !(!g.exec(t) || e.nodeType === l.NodeType.ELEMENT) || - !(!w.exec(t) || e.nodeType === l.NodeType.ATTRIBUTE) + (t.nodeType === l.NodeType.ATTRIBUTE && !v.exec(e)) || + (t.nodeType === l.NodeType.TEXT && !N.exec(e)) || + !(!g.exec(e) || t.nodeType === l.NodeType.ELEMENT) || + !(!w.exec(e) || t.nodeType === l.NodeType.ATTRIBUTE) ); - })(e.xpath, n)) || + })(t.xpath, n)) || void 0 === - (function (t, e, n, o, r) { - let a = t.get(e.xpath); - a || ((a = new Map()), t.set(e.xpath, a)); + (function (e, t, n, o, r) { + let a = e.get(t.xpath); + a || ((a = new Map()), e.set(t.xpath, a)); let s = n; - const c = _(o); for (; s; ) { - let t = a.get(s); + let e = a.get(s); if ( - (void 0 === t && - ((t = e.compiled - ? (0, i.executeJavaScriptCompiledXPath)(e.compiled, s) - : (0, i.evaluateXPathToNodes)(e.xpath, s, void 0, c, { + (void 0 === e && + ((e = t.compiled + ? (0, i.executeJavaScriptCompiledXPath)(t.compiled, s) + : (0, i.evaluateXPathToNodes)(t.xpath, s, void 0, o, { namespaceResolver: r, functionNameResolver: u.functionNameResolver, })), - a.set(s, t)), - -1 !== t.indexOf(n)) + a.set(s, e)), + -1 !== e.indexOf(n)) ) - return t; + return e; s = s.parentNode || (s.nodeType === l.NodeType.ATTRIBUTE && s.ownerElement); } - })(t, e, n, o, r) + })(e, t, n, o, r) ); } - function* y(t) { - let e = new Set(), - n = t.next(); + function* y(e) { + let t = new Set(), + n = e.next(); for (; !n.done; ) - (e.has(n.value) || (yield n.value, e.add(n.value)), (n = t.next())); + (t.has(n.value) || (yield n.value, t.add(n.value)), (n = e.next())); } - function* b(t, e) { - let n = [t.next(), e.next()]; + function* b(e, t) { + let n = [e.next(), t.next()]; for (; !n[0].done || !n[1].done; ) n[0].done - ? (yield n[1].value, (n[1] = e.next())) + ? (yield n[1].value, (n[1] = t.next())) : n[1].done || (0, p.compareSortable)(n[0].value, n[1].value) < 0 - ? (yield n[0].value, (n[0] = t.next())) - : (yield n[1].value, (n[1] = e.next())); - } - function S(t, e, n) { - let o = (function* (t, e, n, o) { - const r = (0, d.findMatchingRules)(e, t).map((t) => n[t]); - for (let t of (0, p.sortSortable)(r)) - ("#all" === t.modes[0] || t.modes.includes(o)) && (yield t); - })(t.contextItem, t.ruleTree, t.templates, t.mode), - r = (function* (t, e, n, o, r, a, s) { - for (let [i, c] of n) { + ? (yield n[0].value, (n[0] = e.next())) + : (yield n[1].value, (n[1] = t.next())); + } + function S(e, t, n) { + let o = (function* (e, t, n, o) { + const r = (0, d.findMatchingRules)(t, e).map((e) => n[e]); + for (let e of (0, p.sortSortable)(r)) + ("#all" === e.modes[0] || e.modes.includes(o)) && (yield e); + })(e.contextItem, e.ruleTree, e.templates, e.mode), + r = (function* (e, t, n, o, r, a, s) { + const i = _(r); + for (let [r, c] of n) { const n = o[c]; - i && + r && ("#all" === n.modes[0] || n.modes.includes(a)) && - T(t, i, e, r, (0, p.mkResolver)(s)) && + T(e, r, t, i, (0, p.mkResolver)(s)) && (yield n); } })( - t.patternMatchCache, - t.contextItem, - t.nonRuleTemplateIndexes, - t.templates, - t.variableScopes, - t.mode, + e.patternMatchCache, + e.contextItem, + e.nonRuleTemplateIndexes, + e.templates, + e.variableScopes, + e.mode, n, ), a = y(b(o, r)); const s = a.next(); - s.done || - C( - s.value, - Object.assign(Object.assign({}, t), { nextMatches: a }), - e, - ); + ((e.nextMatches = a), s.done || C(s.value, e, t)); } - function E(t, e, n, o) { - const r = "descending" === G(t, n.order, o); + function E(e, t, n, o) { + const r = "descending" === z(e, n.order, o); return "number" === n.dataType - ? (function (t, e, n, o, r) { - const a = R(e, t, (t) => { - let e; - const r = Y(t, n.sortKey, o); + ? (function (e, t, n, o, r) { + const a = R(t, e, (e) => { + let t; + const r = Y(e, n.sortKey, o); return ( - (e = Number(r)), - isNaN(e) && (e = Number.MIN_SAFE_INTEGER), - e + (t = Number(r)), + isNaN(t) && (t = Number.MIN_SAFE_INTEGER), + t ); }); - return (0, p.zip)(a, e) - .sort(r ? (t, e) => e[0] - t[0] : (t, e) => t[0] - e[0]) - .map((t) => t[1]); - })(t, e, n, o, r) - : (function (t, e, n, o, r) { - const a = R(e, t, (t) => Y(t, n.sortKey, o)), - s = n.lang && G(t, n.lang, o); + return (0, p.zip)(a, t) + .sort(r ? (e, t) => t[0] - e[0] : (e, t) => e[0] - t[0]) + .map((e) => e[1]); + })(e, t, n, o, r) + : (function (e, t, n, o, r) { + const a = R(t, e, (e) => Y(e, n.sortKey, o)), + s = n.lang && z(e, n.lang, o); let i = new Intl.Collator(s).compare; - return (0, p.zip)(a, e) - .sort(r ? (t, e) => i(e[0], t[0]) : (t, e) => i(t[0], e[0])) - .map((t) => t[1]); - })(t, e, n, o, r); + return (0, p.zip)(a, t) + .sort(r ? (e, t) => i(t[0], e[0]) : (e, t) => i(e[0], t[0])) + .map((e) => e[1]); + })(e, t, n, o, r); } - function R(t, e, n) { - if (t.length > 0) - return (0, l.isNodeGroupArray)(t) ? j(t, e, n) : I(t, e, n); + function R(e, t, n) { + if (e.length > 0) + return (0, l.isNodeGroupArray)(e) ? P(e, t, n) : I(e, t, n); } - function I(t, e, n) { + function I(e, t, n) { let o = 0; - return t.map( - (r) => ( - o++, - n( - Object.assign(Object.assign({}, e), { - contextItem: r, - contextList: t, - position: o, - }), - ) - ), + const r = Object.assign(Object.assign({}, t), { contextList: e }); + return e.map( + (e) => (o++, (r.contextItem = e), (r.position = o), n(r)), ); } - function j(t, e, n) { + function P(e, t, n) { let o = 0; - return t.map((t) => { + return e.map((e) => { o++; - const r = Object.assign(Object.assign({}, e), { - contextItem: t.nodes[0], - contextList: t.nodes, - currentGroup: t, + const r = Object.assign(Object.assign({}, t), { + contextItem: e.nodes[0], + contextList: e.nodes, + currentGroup: e, position: o, - variableScopes: $(e.variableScopes), + variableScopes: $(t.variableScopes), }); return n(r); }); } - function O(t, e, n, o) { - if (n) for (let r of [...n].reverse()) e = E(t, e, r, o); - return e; + function j(e, t, n, o) { + if (n) for (let r of [...n].reverse()) t = E(e, t, r, o); + return t; } - function P(t, e) { - for (let n of e) if (n.name === t) return n; + function O(e, t) { + for (let n of t) if (n.name === e) return n; } - function C(t, e, n) { - let o = $(e.variableScopes); - for (let r of t.allowedParams) { - let t = P(r.name, n); - void 0 !== t ? M(o, t.name, B(e, t)) : M(o, r.name, B(e, r)); + function C(e, t, n) { + let o = $(t.variableScopes); + for (let r of e.allowedParams) { + let e = O(r.name, n); + void 0 !== e ? M(o, e.name, B(t, e)) : M(o, r.name, B(t, r)); } - return t.apply( - Object.assign(Object.assign({}, e), { variableScopes: o }), + return e.apply( + Object.assign(Object.assign({}, t), { variableScopes: o }), ); } - function $(t) { - return t.concat([new Map()]); + function $(e) { + return e.concat([new Map()]); } new RegExp(/(^\/$|document-node\(|node\()/); let D = new Map(); - function X(t) { + function X(e) { return ( - D.has(t) || D.set(t, (0, i.createTypedValueFactory)(t)), - D.get(t) + D.has(e) || D.set(e, (0, i.createTypedValueFactory)(e)), + D.get(e) ); } - function L(t, e) { - if (Array.isArray(t) && 0 === t.length) return X("item()*")([], null); - if (e) + function L(e, t) { + if (Array.isArray(e) && 0 === e.length) return X("item()*")([], null); + if (t) try { - return X(e)(t, null); - } catch (t) {} - const n = Array.isArray(t), - o = n ? t[0] : t; + return X(t)(e, null); + } catch (e) {} + const n = Array.isArray(e), + o = n ? e[0] : e; let r = "item()"; const a = n ? "*" : ""; return ( @@ -2742,102 +2752,102 @@ ? (r = "xs:string") : "number" == typeof o && (r = Number.isInteger(o) ? "xs:integer" : "xs:numeric"), - X(`${r}${a}`)(t, null) + X(`${r}${a}`)(e, null) ); } - function M(t, e, n) { - t[t.length - 1].set(e, n); + function M(e, t, n) { + e[e.length - 1].set(t, n); } - function _(t) { - let e = {}; - for (let n of t) for (let [t, o] of n) e[t] = o; - return e; + function _(e) { + let t = {}; + for (let n of e) for (let [e, o] of n) t[e] = o; + return t; } - function A(t, e) { + function A(e, t) { let n; return ( (n = - void 0 !== e.namespace && null !== e.namespace - ? t.outputDocument.createElementNS(e.namespace, e.name) - : t.outputDocument.createElement(e.name)), + void 0 !== t.namespace && null !== t.namespace + ? e.outputDocument.createElementNS(t.namespace, t.name) + : e.outputDocument.createElement(t.name)), n ); } - function U(t, e) { + function U(e, t) { let n; return ( - (n = e.namespace - ? t.outputDocument.createAttributeNS(e.namespace, e.name) - : t.outputDocument.createAttribute(e.name)), - (n.value = e.value), + (n = t.namespace + ? e.outputDocument.createAttributeNS(t.namespace, t.name) + : e.outputDocument.createAttribute(t.name)), + (n.value = t.value), n ); } - function F(t, e, n) { - e.length > 0 && - (null === n && (n = `group-${t.length + 1}`), - t.push({ key: n, nodes: e })); + function F(e, t, n) { + t.length > 0 && + (null === n && (n = `group-${e.length + 1}`), + e.push({ key: n, nodes: t })); } - function k(t) { - const e = t.ownerDocument || t; + function k(e) { + const t = e.ownerDocument || e; return function n(o) { if (o.length && o.values) { - let t = !0; - const e = o.length > 0 && !o[0].nodeType; - for (let r of o) (t ? (t = !1) : e && n(" "), n(r)); + let e = !0; + const t = o.length > 0 && !o[0].nodeType; + for (let r of o) (e ? (e = !1) : t && n(" "), n(r)); } else if ("string" == typeof o) { - if (t.nodeType !== l.NodeType.DOCUMENT) - if (t.lastChild && t.lastChild.nodeType === l.NodeType.TEXT) - t.lastChild.appendData(o); + if (e.nodeType !== l.NodeType.DOCUMENT) + if (e.lastChild && e.lastChild.nodeType === l.NodeType.TEXT) + e.lastChild.appendData(o); else if ("" !== o) { - const n = e.createTextNode(o); - n && t.append(n); + const n = t.createTextNode(o); + n && e.append(n); } } else if (o.nodeType === l.NodeType.ATTRIBUTE) { - let n = e.importNode(o, !0); - t.setAttributeNode(n); + let n = t.importNode(o, !0); + e.setAttributeNode(n); } else { if (o.nodeType === l.NodeType.DOCUMENT) { - const t = o; - return (o = o.documentElement) ? (n(o), k(o)) : k(t); + const e = o; + return (o = o.documentElement) ? (n(o), k(o)) : k(e); } if (o.nodeType === l.NodeType.DOCUMENT_FRAGMENT) n(o.childNodes); else if (o.nodeType === l.NodeType.TEXT) n(o.data); else { if (o.nodeType) { - let n = e.importNode(o, !0); - return (t.append(n), k(n)); + let n = t.importNode(o, !0); + return (e.append(n), k(n)); } n(`${o}`); } } }; } - function z(t) { - return function (e) { + function G(e) { + return function (t) { if ( - (t.push(e), - e.nodeType && - (e.nodeType === l.NodeType.DOCUMENT || - e.nodeType === l.NodeType.ELEMENT)) + (e.push(t), + t.nodeType && + (t.nodeType === l.NodeType.DOCUMENT || + t.nodeType === l.NodeType.ELEMENT)) ) - return k(e); + return k(t); }; } - function G(t, e, n) { - if (!e) return; - const o = _(t.variableScopes); - return e - .map((e) => - "string" == typeof e - ? e + function z(e, t, n) { + if (!t) return; + const o = _(e.variableScopes); + return t + .map((t) => + "string" == typeof t + ? t : (0, i.evaluateXPathToString)( - e.xpath, - t.contextItem, + t.xpath, + e.contextItem, void 0, o, { - currentContext: t, + currentContext: e, namespaceResolver: n, functionNameResolver: u.functionNameResolver, }, @@ -2845,120 +2855,116 @@ ) .join(""); } - function Y(t, e, n, o) { - o || (o = "string" == typeof e ? [" "] : []); - const r = G(t, o, n); - if ("string" == typeof e) { - const o = _(t.variableScopes); + function Y(e, t, n, o) { + o || (o = "string" == typeof t ? [" "] : []); + const r = z(e, o, n); + if ("string" == typeof t) { + const o = _(e.variableScopes); return (0, i.evaluateXPath)( - e, - t.contextItem, + t, + e.contextItem, void 0, o, i.evaluateXPath.STRINGS_TYPE, { - currentContext: t, + currentContext: e, namespaceResolver: n, functionNameResolver: u.functionNameResolver, }, ).join(r); } - return (function (t) { - let e = []; + return (function (e) { + let t = []; return ( - x(t, (t) => { - t.nodeType === l.NodeType.TEXT && - "" !== t.data && - (e = e.concat(t.data)); + x(e, (e) => { + e.nodeType === l.NodeType.TEXT && + "" !== e.data && + (t = t.concat(e.data)); }), - e + t ); - })(J(t, e)).join(r); + })(J(e, t)).join(r); } - function B(t, e) { - if ("string" == typeof e.content) { - const n = e.as && e.as.match(/[\+\*]$/); + function B(e, t) { + if ("string" == typeof t.content) { + const n = t.as && t.as.match(/[\+\*]$/); let o = (0, i.evaluateXPath)( - e.content, - t.contextItem, + t.content, + e.contextItem, void 0, - _(t.variableScopes), + _(e.variableScopes), i.evaluateXPath.ALL_RESULTS_TYPE, { - currentContext: t, - namespaceResolver: (0, p.mkResolver)(e.namespaces), + currentContext: e, + namespaceResolver: (0, p.mkResolver)(t.namespaces), functionNameResolver: u.functionNameResolver, }, ); - return (1 !== o.length || n || (o = o[0]), L(o, e.as)); + return (1 !== o.length || n || (o = o[0]), L(o, t.as)); } - return null == e.content + return null == t.content ? "" - : e.as + : t.as ? L( - (function (t, e) { + (function (e, t) { let n = []; return ( - e( - Object.assign(Object.assign({}, t), { - append: z(n), + t( + Object.assign(Object.assign({}, e), { + append: G(n), mode: "#default", - variableScopes: $(t.variableScopes), + variableScopes: $(e.variableScopes), }), ), 1 === n.length ? n[0] : n ); - })(t, e.content), - e.as, + })(e, t.content), + t.as, ) - : J(t, e.content); + : J(e, t.content); } - function J(t, e) { - return (function (t, e) { - const n = t.outputDocument.createDocumentFragment(); + function J(e, t) { + return (function (e, t) { + const n = e.outputDocument.createDocumentFragment(); if ( - (e(k(n)), 1 === n.childNodes.length && 1 === n.childElementCount) + (t(k(n)), 1 === n.childNodes.length && 1 === n.childElementCount) ) { - const e = t.outputDocument.implementation.createDocument( + const t = e.outputDocument.implementation.createDocument( null, null, null, ); - return (e.appendChild(n.firstChild), e); + return (t.appendChild(n.firstChild), t); } return n; - })(t, (n) => { - e( - Object.assign(Object.assign({}, t), { + })(e, (n) => { + t( + Object.assign(Object.assign({}, e), { append: n, - outputDocument: t.outputDocument, + outputDocument: e.outputDocument, mode: "#default", - variableScopes: $(t.variableScopes), + variableScopes: $(e.variableScopes), }), ); }); } (0, u.registerFunctions)(); }, - 594(t) { - "use strict"; - t.exports = require("fontoxpath"); - }, - 898(t) { + 594(e) { "use strict"; - t.exports = require("slimdom"); + e.exports = require("fontoxpath"); }, - 16(t) { + 898(e) { "use strict"; - t.exports = require("url"); + e.exports = require("slimdom"); }, }, - e = {}, + t = {}, n = (function n(o) { - var r = e[o]; + var r = t[o]; if (void 0 !== r) return r.exports; - var a = (e[o] = { exports: {} }); - return (t[o].call(a.exports, a, a.exports, n), a.exports); - })(144); + var a = (t[o] = { exports: {} }); + return (e[o].call(a.exports, a, a.exports, n), a.exports); + })(396); module.exports = n.transform; })(); diff --git a/src/preprocess/error-analysis.js b/src/preprocess/error-analysis.js index 3e6a136..f073fcf 100644 --- a/src/preprocess/error-analysis.js +++ b/src/preprocess/error-analysis.js @@ -1,6 +1,6 @@ (() => { var t = { - 763(t, e, n) { + 926(t, e, n) { (n(898), n(594)); let o = n(821); function r(t, e) { @@ -2318,12 +2318,14 @@ (e.parentNode = d), (e.grandParentNode = x), (e.greatGrandParentNode = f), + (e.greatGreatGrandParentNode = I), + (e.ancestorNodes = w), (e.xpathToFeatures = function (t, e) { if (t) return (function (t, e) { const n = []; try { - return (L(t, n, e), n); + return (O(t, n, e), n); } catch (t) { return; } @@ -2341,33 +2343,51 @@ m = n(594), l = s(n(898)), p = "http://www.w3.org/2005/XQueryX"; - function u(t) { - return t; + function* u(t) { + yield t; } - function d(t) { - return t.parentNode || void 0; + function* d(t) { + t.parentNode && (yield t.parentNode); } - function x(t) { + function* x(t) { var e; - return ( - (null === (e = t.parentNode) || void 0 === e - ? void 0 - : e.parentNode) || void 0 - ); + const n = + null === (e = t.parentNode) || void 0 === e ? void 0 : e.parentNode; + n && (yield n); } - function f(t) { + function* f(t) { var e, n; - return ( - (null === + const o = + null === (n = null === (e = t.parentNode) || void 0 === e ? void 0 : e.parentNode) || void 0 === n ? void 0 - : n.parentNode) || void 0 - ); + : n.parentNode; + o && (yield o); + } + function* I(t) { + var e, n, o; + const r = + null === + (o = + null === + (n = + null === (e = t.parentNode) || void 0 === e + ? void 0 + : e.parentNode) || void 0 === n + ? void 0 + : n.parentNode) || void 0 === o + ? void 0 + : o.parentNode; + r && (yield r); } - class I extends i.Feature { + function* w(t) { + let e = t.parentNode; + for (; e; ) (yield e, (e = e.parentNode)); + } + class T extends i.Feature { constructor(t, e) { (super(e), (this.nodeExtractor = t)); } @@ -2384,214 +2404,215 @@ return this.nodeExtractor === t.nodeExtractor && super.equals(t); } } - class w extends I { + function h(t, e) { + for (const n of t) if (e(n)) return !0; + return !1; + } + class y extends T { matches(t) { - var e; - return ( - (null === (e = this.nodeExtractor(t)) || void 0 === e - ? void 0 - : e.nodeType) === l.Node.ELEMENT_NODE && - t.namespaceURI === this.value + return h( + this.nodeExtractor(t), + (t) => + t.nodeType == l.Node.ELEMENT_NODE && + t.namespaceURI === this.value, ); } } - e.NodeNamespaceFeature = w; - class T extends I { + e.NodeNamespaceFeature = y; + class g extends T { matches(t) { - var e; - return ( - (null === (e = this.nodeExtractor(t)) || void 0 === e - ? void 0 - : e.nodeType) === this.value - ); + return h(this.nodeExtractor(t), (t) => t.nodeType === this.value); } } - e.NodeTypeFeature = T; - class h extends I { + e.NodeTypeFeature = g; + class E extends T { matches(t) { - var e; - return ( - (null === (e = this.nodeExtractor(t)) || void 0 === e - ? void 0 - : e.nodeName) === this.value - ); + return h(this.nodeExtractor(t), (t) => t.nodeName === this.value); } } - e.NodeNameFeature = h; - class y extends I { + e.NodeNameFeature = E; + class N extends T { matches(t) { - var e; - return ( - (null === (e = this.nodeExtractor(t)) || void 0 === e - ? void 0 - : e.textContent) === this.value + return h( + this.nodeExtractor(t), + (t) => t.textContent === this.value, ); } } - e.NodeTextFeature = y; - class g extends I { + e.NodeTextFeature = N; + class v extends T { matches(t) { - const e = this.nodeExtractor(t); - return ( - e.nodeType === l.Node.ELEMENT_NODE && - e.getAttribute(this.value.name) === this.value.value + return h( + this.nodeExtractor(t), + (t) => + t.nodeType == l.Node.ELEMENT_NODE && + t.getAttribute(this.value.name) === this.value.value, ); } } - function E(t) { + function b(t) { return ( (function (t) { return 1 === t.nodeType; })(t) && t.namespaceURI === p ); } - function N(t, e) { - return E(t) && t.localName === e; + function S(t, e) { + return b(t) && t.localName === e; } - function v(t, e) { - for (const n of t.childNodes) if (N(n, e)) return n; + function L(t, e) { + for (const n of t.childNodes) if (S(n, e)) return n; } - function b(t, e, n) { + function X(t, e, n) { for (const o of t.childNodes) { - if (!E(o)) continue; - if (N(o, e) && (!n || n(o))) return o; - const t = b(o, e, n); + if (!b(o)) continue; + if (S(o, e) && (!n || n(o))) return o; + const t = X(o, e, n); if (t) return t; } } - e.NodeAttributeFeature = g; - class S extends Error {} - function L(t, e, n) { - if (!E(t)) return; + function R(t) { + var e; + return ( + "descendant-or-self" === + (null === (e = L(t, "xpathAxis")) || void 0 === e + ? void 0 + : e.textContent) && !!L(t, "anyKindTest") + ); + } + e.NodeAttributeFeature = v; + class D extends Error {} + function O(t, e, n) { + if (!b(t)) return; const o = t.localName; if ("module" === o || "mainModule" === o || "queryBody" === o) - for (const o of t.childNodes) L(o, e, n); + for (const o of t.childNodes) O(o, e, n); else { - if ("pathExpr" !== o) throw new S(); + if ("pathExpr" !== o) throw new D(); { - const o = t.childNodes.filter((t) => N(t, "stepExpr")); - if (N(t.firstChild, "rootExpr")) { + const o = t.childNodes.filter((t) => S(t, "stepExpr")); + if (S(t.firstChild, "rootExpr")) { if (0 === o.length) - return void e.push(new T(u, l.Node.DOCUMENT_NODE)); - if ( - "descendant-or-self" !== - (null === (a = v((r = o[0]), "xpathAxis")) || void 0 === a - ? void 0 - : a.textContent) || - !v(r, "anyKindTest") - ) - throw new S(); + return void e.push(new g(u, l.Node.DOCUMENT_NODE)); + if (!R(o[0])) throw new D(); o.shift(); } - if (0 === o.length) throw new S(); - const s = o.reverse(); - if (0 == s.length || s.length > 4) throw new S(); - (R(u, s[0], e, n), - s[1] && R(d, s[1], e, n), - s[2] && R(x, s[2], e, n), - s[3] && R(f, s[3], e, n)); + if (0 === o.length) throw new D(); + const r = o.reverse(); + if (0 == r.length) throw new D(); + const a = [u, d, x, f, I]; + let s = 0, + c = !1; + for (const t of r) { + if (R(t)) { + c = !0; + continue; + } + const o = c ? w : a[s++]; + if (!o) throw new D(); + F(o, t, e, n); + } } } - var r, a; } - function X(t, e, n) { + function P(t, e, n) { "attribute" === e - ? n.push(new T(t, l.Node.ATTRIBUTE_NODE)) - : n.push(new T(t, l.Node.ELEMENT_NODE)); + ? n.push(new g(t, l.Node.ATTRIBUTE_NODE)) + : n.push(new g(t, l.Node.ELEMENT_NODE)); } - function R(t, e, n, o) { + function F(t, e, n, o) { var r, a; const s = - null === (r = v(e, "xpathAxis")) || void 0 === r + null === (r = L(e, "xpathAxis")) || void 0 === r ? void 0 : r.textContent; if ("child" !== s && "attribute" !== s) - throw new S(`unsupported axis: ${s}`); + throw new D(`unsupported axis: ${s}`); for (const r of e.childNodes.slice(1)) { - if (!E(r)) continue; + if (!b(r)) continue; const c = r.localName; - if ("nameTest" === c) (D(t, e, n, o), X(t, s, n)); + if ("nameTest" === c) (M(t, e, n, o), P(t, s, n)); else if ("Wildcard" === c) { - const e = v(r, "NCName"); + const e = L(r, "NCName"); if (e) { const r = null == o ? void 0 : o(null !== (a = e.textContent) && void 0 !== a ? a : ""); - if (!r) throw new S(`unresolved ns prefix: ${r}`); - n.push(new w(t, r)); + if (!r) throw new D(`unresolved ns prefix: ${r}`); + n.push(new y(t, r)); } - X(t, s, n); + P(t, s, n); } else if ("piTest" === c) { - n.push(new T(t, l.Node.PROCESSING_INSTRUCTION_NODE)); - const e = v(r, "piTarget"); + n.push(new g(t, l.Node.PROCESSING_INSTRUCTION_NODE)); + const e = L(r, "piTarget"); (null == e ? void 0 : e.textContent) && - n.push(new h(t, e.textContent)); + n.push(new E(t, e.textContent)); } else if ("commentTest" === c) - n.push(new T(t, l.Node.COMMENT_NODE)); - else if ("textTest" === c) n.push(new T(t, l.Node.TEXT_NODE)); + n.push(new g(t, l.Node.COMMENT_NODE)); + else if ("textTest" === c) n.push(new g(t, l.Node.TEXT_NODE)); else { - if ("predicates" !== c) throw new S(); - O(t, r, n, o); + if ("predicates" !== c) throw new D(); + _(t, r, n, o); } } } - function D(t, e, n, o) { - const r = v(e, "nameTest"); - if (!r) throw new S(); + function M(t, e, n, o) { + const r = L(e, "nameTest"); + if (!r) throw new D(); const a = r.textContent; - a && n.push(new h(t, a)); + a && n.push(new E(t, a)); const s = r.getAttributeNS(p, "prefix"); if (s) { const e = null == o ? void 0 : o(s); - if (!e) throw new S(`unresolved ns prefix: ${e}`); - n.push(new w(t, e)); + if (!e) throw new D(`unresolved ns prefix: ${e}`); + n.push(new y(t, e)); } const c = r.getAttributeNS(p, "URI"); - c && n.push(new w(t, c)); + c && n.push(new y(t, c)); } - function O(t, e, n, o) { + function _(t, e, n, o) { for (const r of e.childNodes) { - if (!E(r)) throw new S(); + if (!b(r)) throw new D(); const e = r.localName; if ("equalOp" === e) { - const e = v(r, "firstOperand"), - o = v(r, "secondOperand"); - if (!e || !o) throw new S(); - const a = F(t, e, o) || F(t, o, e); - if (!a) throw new S(); + const e = L(r, "firstOperand"), + o = L(r, "secondOperand"); + if (!e || !o) throw new D(); + const a = C(t, e, o) || C(t, o, e); + if (!a) throw new D(); n.push(a); } else { - if ("andOp" !== e) throw new S(); - (O(t, v(r, "firstOperand"), n, o), - O(t, v(r, "secondOperand"), n, o)); + if ("andOp" !== e) throw new D(); + (_(t, L(r, "firstOperand"), n, o), + _(t, L(r, "secondOperand"), n, o)); } } } - function F(t, e, n) { + function C(t, e, n) { var o, r; - const a = b(n, "value"); + const a = X(n, "value"); if (!a) return; const s = null !== (o = a.textContent) && void 0 !== o ? o : "", - c = b(e, "stepExpr", (t) => { + c = X(e, "stepExpr", (t) => { var e; return ( "attribute" === - (null === (e = v(t, "xpathAxis")) || void 0 === e + (null === (e = L(t, "xpathAxis")) || void 0 === e ? void 0 : e.textContent) ); }); if (c) { const e = - null === (r = v(c, "nameTest")) || void 0 === r + null === (r = L(c, "nameTest")) || void 0 === r ? void 0 : r.textContent; if (!e) return; - return new g(t, { name: e, value: s }); + return new v(t, { name: e, value: s }); } - return v(e, "contextItemExpr") || b(e, "textTest") - ? new y(t, s) + return L(e, "contextItemExpr") || X(e, "textTest") + ? new N(t, s) : void 0; } }, @@ -3436,15 +3457,15 @@ } } }, - 472(t, e, n) { + 472(t, e) { "use strict"; (Object.defineProperty(e, "__esModule", { value: !0 }), (e.urlToDom = function (t, e) { - if (!t.readDocument) return; - const n = t.inputURL ? (0, o.resolve)(t.inputURL.toString(), e) : e; + const n = t.inputURL + ? new URL(e, t.inputURL.toString()).toString() + : e; return t.readDocument(n); })); - const o = n(16); }, 821(t, e, n) { "use strict"; @@ -3513,9 +3534,11 @@ e.NodeNamespaceFeature = e.NodeAttributeFeature = e.selfNode = + e.greatGreatGrandParentNode = e.greatGrandParentNode = e.grandParentNode = e.parentNode = + e.ancestorNodes = e.KeyImpl = void 0), (e.visitNodes = f), @@ -3526,12 +3549,7 @@ const n = t.nextMatches; if (n) { const o = n.next(); - o.done || - O( - o.value, - Object.assign(Object.assign({}, t), { nextMatches: n }), - e.params, - ); + o.done || ((t.nextMatches = n), O(o.value, t, e.params)); } }), (e.applyImports = function (t, e) { @@ -3539,12 +3557,7 @@ if (n) { let o = n.next(); for (; !o.done && 1 === o.value.importPrecedence; ) o = n.next(); - o.done || - O( - o.value, - Object.assign(Object.assign({}, t), { nextMatches: n }), - e.params, - ); + o.done || ((t.nextMatches = n), O(o.value, t, e.params)); } }), (e.sort = R), @@ -3563,16 +3576,15 @@ ); let r = e.mode || "#default"; ("#current" === r && (r = t.mode), - L(R(t, o, e.sortKeyComponents, n), t, (t) => { - v( - Object.assign(Object.assign({}, t), { - mode: r, - variableScopes: F(t.variableScopes), - }), - e.params, - e.namespaces, - ); - })); + L( + R(t, o, e.sortKeyComponents, n), + Object.assign(Object.assign({}, t), { mode: r }), + (t) => { + ((t.variableScopes = P(t.variableScopes)), + v(t, e.params, e.namespaces), + t.variableScopes.pop()); + }, + )); }), (e.callTemplate = function (t, e) { const n = t.namedTemplates.get(e.name); @@ -3590,7 +3602,7 @@ let r = new Map(); return ( o.forEach((t, e) => r.set(t, n[e])), - G( + q( Object.assign(Object.assign({}, t), { variableScopes: [r].concat(t.variableScopes), }), @@ -3660,12 +3672,12 @@ t.append(z(t, n, (0, p.mkResolver)(e.namespaces), [""])); }), (e.variable = function (t, e) { - C(t.variableScopes, e.name, q(t, e)); + C(t.variableScopes, e.name, G(t, e)); }), (e.param = function (t, e) { - C(t.variableScopes, e.name, t.stylesheetParams[e.name] || q(t, e)); + C(t.variableScopes, e.name, t.stylesheetParams[e.name] || G(t, e)); }), - (e.extendScope = F), + (e.extendScope = P), (e.wrapValue = _), (e.setVariable = C), (e.mergeVariableScopes = U), @@ -3700,7 +3712,7 @@ const a = t.append(o); n( Object.assign(Object.assign({}, t), { - variableScopes: F(t.variableScopes), + variableScopes: P(t.variableScopes), append: a || t.append, }), ); @@ -3758,7 +3770,7 @@ const c = t.append(s); n( Object.assign(Object.assign({}, t), { - variableScopes: F(t.variableScopes), + variableScopes: P(t.variableScopes), append: c || t.append, }), ); @@ -3806,7 +3818,7 @@ outputDocument: o, append: r, mode: "#default", - variableScopes: F(t.variableScopes), + variableScopes: P(t.variableScopes), }), ); }), @@ -3847,11 +3859,9 @@ Symbol.iterator in Object(r) && ((r = R(t, r, e.sortKeyComponents, o)), L(r, t, (t) => { - n( - Object.assign(Object.assign({}, t), { - variableScopes: F(t.variableScopes), - }), - ); + ((t.variableScopes = P(t.variableScopes)), + n(t), + t.variableScopes.pop()); })); }), (e.forEachGroup = function (t, e, n) { @@ -3928,7 +3938,7 @@ t.patternMatchCache, n, e, - t.variableScopes, + U(t.variableScopes), o, ) && (j(r, a), (a = []))); }), @@ -3947,7 +3957,7 @@ t.patternMatchCache, n, e, - t.variableScopes, + U(t.variableScopes), o, ) && (j(r, a), (a = [])), a.push(e)); @@ -4139,12 +4149,24 @@ ? t.textContent : t.toString(); } - (Object.defineProperty(e, "greatGrandParentNode", { + (Object.defineProperty(e, "ancestorNodes", { enumerable: !0, get: function () { - return x.greatGrandParentNode; + return x.ancestorNodes; }, }), + Object.defineProperty(e, "greatGrandParentNode", { + enumerable: !0, + get: function () { + return x.greatGrandParentNode; + }, + }), + Object.defineProperty(e, "greatGreatGrandParentNode", { + enumerable: !0, + get: function () { + return x.greatGreatGrandParentNode; + }, + }), Object.defineProperty(e, "grandParentNode", { enumerable: !0, get: function () { @@ -4202,6 +4224,7 @@ } buildDocumentCache(t, e, n) { let o = new Map(); + const r = U(n); return ( f(e, (e) => { if ( @@ -4210,7 +4233,7 @@ t, { xpath: this.match }, e, - n, + r, (0, p.mkResolver)(this.namespaces), ) ) { @@ -4249,14 +4272,13 @@ let a = t.get(e.xpath); a || ((a = new Map()), t.set(e.xpath, a)); let s = n; - const i = U(o); for (; s; ) { let t = a.get(s); if ( (void 0 === t && ((t = e.compiled ? (0, c.executeJavaScriptCompiledXPath)(e.compiled, s) - : (0, c.evaluateXPathToNodes)(e.xpath, s, void 0, i, { + : (0, c.evaluateXPathToNodes)(e.xpath, s, void 0, o, { namespaceResolver: r, functionNameResolver: m.functionNameResolver, })), @@ -4293,11 +4315,12 @@ ("#all" === t.modes[0] || t.modes.includes(o)) && (yield t); })(t.contextItem, t.ruleTree, t.templates, t.mode), r = (function* (t, e, n, o, r, a, s) { - for (let [c, i] of n) { + const c = U(r); + for (let [r, i] of n) { const n = o[i]; - c && + r && ("#all" === n.modes[0] || n.modes.includes(a)) && - g(t, c, e, r, (0, p.mkResolver)(s)) && + g(t, r, e, c, (0, p.mkResolver)(s)) && (yield n); } })( @@ -4311,12 +4334,7 @@ ), a = E(N(o, r)); const s = a.next(); - s.done || - O( - s.value, - Object.assign(Object.assign({}, t), { nextMatches: a }), - e, - ); + ((t.nextMatches = a), s.done || O(s.value, t, e)); } function b(t, e, n, o) { const r = "descending" === B(t, n.order, o); @@ -4350,17 +4368,9 @@ } function L(t, e, n) { let o = 0; + const r = Object.assign(Object.assign({}, e), { contextList: t }); return t.map( - (r) => ( - o++, - n( - Object.assign(Object.assign({}, e), { - contextItem: r, - contextList: t, - position: o, - }), - ) - ), + (t) => (o++, (r.contextItem = t), (r.position = o), n(r)), ); } function X(t, e, n) { @@ -4372,7 +4382,7 @@ contextList: t.nodes, currentGroup: t, position: o, - variableScopes: F(e.variableScopes), + variableScopes: P(e.variableScopes), }); return n(r); }); @@ -4385,24 +4395,24 @@ for (let n of e) if (n.name === t) return n; } function O(t, e, n) { - let o = F(e.variableScopes); + let o = P(e.variableScopes); for (let r of t.allowedParams) { let t = D(r.name, n); - void 0 !== t ? C(o, t.name, q(e, t)) : C(o, r.name, q(e, r)); + void 0 !== t ? C(o, t.name, G(e, t)) : C(o, r.name, G(e, r)); } return t.apply( Object.assign(Object.assign({}, e), { variableScopes: o }), ); } - function F(t) { + function P(t) { return t.concat([new Map()]); } new RegExp(/(^\/$|document-node\(|node\()/); - let P = new Map(); + let F = new Map(); function M(t) { return ( - P.has(t) || P.set(t, (0, c.createTypedValueFactory)(t)), - P.get(t) + F.has(t) || F.set(t, (0, c.createTypedValueFactory)(t)), + F.get(t) ); } function _(t, e) { @@ -4551,9 +4561,9 @@ }), e ); - })(G(t, e)).join(r); + })(q(t, e)).join(r); } - function q(t, e) { + function G(t, e) { if ("string" == typeof e.content) { const n = e.as && e.as.match(/[\+\*]$/); let o = (0, c.evaluateXPath)( @@ -4581,7 +4591,7 @@ Object.assign(Object.assign({}, t), { append: Y(n), mode: "#default", - variableScopes: F(t.variableScopes), + variableScopes: P(t.variableScopes), }), ), 1 === n.length ? n[0] : n @@ -4589,9 +4599,9 @@ })(t, e.content), e.as, ) - : G(t, e.content); + : q(t, e.content); } - function G(t, e) { + function q(t, e) { return (function (t, e) { const n = t.outputDocument.createDocumentFragment(); if ( @@ -4611,7 +4621,7 @@ append: n, outputDocument: t.outputDocument, mode: "#default", - variableScopes: F(t.variableScopes), + variableScopes: P(t.variableScopes), }), ); }); @@ -4626,10 +4636,6 @@ "use strict"; t.exports = require("slimdom"); }, - 16(t) { - "use strict"; - t.exports = require("url"); - }, }, e = {}, n = (function n(o) { @@ -4637,6 +4643,6 @@ if (void 0 !== r) return r.exports; var a = (e[o] = { exports: {} }); return (t[o].call(a.exports, a, a.exports, n), a.exports); - })(763); + })(926); module.exports = n.transform; })(); diff --git a/src/preprocess/import.js b/src/preprocess/import.js index fdf620e..b96caf0 100644 --- a/src/preprocess/import.js +++ b/src/preprocess/import.js @@ -1,6 +1,6 @@ (() => { var e = { - 868(e, t, n) { + 813(e, t, n) { (n(898), n(594)); let o = n(821); function r(e, t) { @@ -590,12 +590,14 @@ (t.parentNode = d), (t.grandParentNode = f), (t.greatGrandParentNode = h), + (t.greatGreatGrandParentNode = x), + (t.ancestorNodes = g), (t.xpathToFeatures = function (e, t) { if (e) return (function (e, t) { const n = []; try { - return (I(e, n, t), n); + return (C(e, n, t), n); } catch (e) { return; } @@ -613,33 +615,51 @@ u = n(594), l = s(n(898)), p = "http://www.w3.org/2005/XQueryX"; - function m(e) { - return e; + function* m(e) { + yield e; } - function d(e) { - return e.parentNode || void 0; + function* d(e) { + e.parentNode && (yield e.parentNode); } - function f(e) { + function* f(e) { var t; - return ( - (null === (t = e.parentNode) || void 0 === t - ? void 0 - : t.parentNode) || void 0 - ); + const n = + null === (t = e.parentNode) || void 0 === t ? void 0 : t.parentNode; + n && (yield n); } - function h(e) { + function* h(e) { var t, n; - return ( - (null === + const o = + null === (n = null === (t = e.parentNode) || void 0 === t ? void 0 : t.parentNode) || void 0 === n ? void 0 - : n.parentNode) || void 0 - ); + : n.parentNode; + o && (yield o); + } + function* x(e) { + var t, n, o; + const r = + null === + (o = + null === + (n = + null === (t = e.parentNode) || void 0 === t + ? void 0 + : t.parentNode) || void 0 === n + ? void 0 + : n.parentNode) || void 0 === o + ? void 0 + : o.parentNode; + r && (yield r); + } + function* g(e) { + let t = e.parentNode; + for (; t; ) (yield t, (t = t.parentNode)); } - class x extends c.Feature { + class w extends c.Feature { constructor(e, t) { (super(t), (this.nodeExtractor = e)); } @@ -656,214 +676,215 @@ return this.nodeExtractor === e.nodeExtractor && super.equals(e); } } - class g extends x { + function N(e, t) { + for (const n of e) if (t(n)) return !0; + return !1; + } + class v extends w { matches(e) { - var t; - return ( - (null === (t = this.nodeExtractor(e)) || void 0 === t - ? void 0 - : t.nodeType) === l.Node.ELEMENT_NODE && - e.namespaceURI === this.value + return N( + this.nodeExtractor(e), + (e) => + e.nodeType == l.Node.ELEMENT_NODE && + e.namespaceURI === this.value, ); } } - t.NodeNamespaceFeature = g; - class w extends x { + t.NodeNamespaceFeature = v; + class y extends w { matches(e) { - var t; - return ( - (null === (t = this.nodeExtractor(e)) || void 0 === t - ? void 0 - : t.nodeType) === this.value - ); + return N(this.nodeExtractor(e), (e) => e.nodeType === this.value); } } - t.NodeTypeFeature = w; - class v extends x { + t.NodeTypeFeature = y; + class T extends w { matches(e) { - var t; - return ( - (null === (t = this.nodeExtractor(e)) || void 0 === t - ? void 0 - : t.nodeName) === this.value - ); + return N(this.nodeExtractor(e), (e) => e.nodeName === this.value); } } - t.NodeNameFeature = v; - class N extends x { + t.NodeNameFeature = T; + class b extends w { matches(e) { - var t; - return ( - (null === (t = this.nodeExtractor(e)) || void 0 === t - ? void 0 - : t.textContent) === this.value + return N( + this.nodeExtractor(e), + (e) => e.textContent === this.value, ); } } - t.NodeTextFeature = N; - class y extends x { + t.NodeTextFeature = b; + class S extends w { matches(e) { - const t = this.nodeExtractor(e); - return ( - t.nodeType === l.Node.ELEMENT_NODE && - t.getAttribute(this.value.name) === this.value.value + return N( + this.nodeExtractor(e), + (e) => + e.nodeType == l.Node.ELEMENT_NODE && + e.getAttribute(this.value.name) === this.value.value, ); } } - function T(e) { + function E(e) { return ( (function (e) { return 1 === e.nodeType; })(e) && e.namespaceURI === p ); } - function b(e, t) { - return T(e) && e.localName === t; + function R(e, t) { + return E(e) && e.localName === t; } - function S(e, t) { - for (const n of e.childNodes) if (b(n, t)) return n; + function I(e, t) { + for (const n of e.childNodes) if (R(n, t)) return n; } - function E(e, t, n) { + function P(e, t, n) { for (const o of e.childNodes) { - if (!T(o)) continue; - if (b(o, t) && (!n || n(o))) return o; - const e = E(o, t, n); + if (!E(o)) continue; + if (R(o, t) && (!n || n(o))) return o; + const e = P(o, t, n); if (e) return e; } } - t.NodeAttributeFeature = y; - class R extends Error {} - function I(e, t, n) { - if (!T(e)) return; + function j(e) { + var t; + return ( + "descendant-or-self" === + (null === (t = I(e, "xpathAxis")) || void 0 === t + ? void 0 + : t.textContent) && !!I(e, "anyKindTest") + ); + } + t.NodeAttributeFeature = S; + class $ extends Error {} + function C(e, t, n) { + if (!E(e)) return; const o = e.localName; if ("module" === o || "mainModule" === o || "queryBody" === o) - for (const o of e.childNodes) I(o, t, n); + for (const o of e.childNodes) C(o, t, n); else { - if ("pathExpr" !== o) throw new R(); + if ("pathExpr" !== o) throw new $(); { - const o = e.childNodes.filter((e) => b(e, "stepExpr")); - if (b(e.firstChild, "rootExpr")) { + const o = e.childNodes.filter((e) => R(e, "stepExpr")); + if (R(e.firstChild, "rootExpr")) { if (0 === o.length) - return void t.push(new w(m, l.Node.DOCUMENT_NODE)); - if ( - "descendant-or-self" !== - (null === (a = S((r = o[0]), "xpathAxis")) || void 0 === a - ? void 0 - : a.textContent) || - !S(r, "anyKindTest") - ) - throw new R(); + return void t.push(new y(m, l.Node.DOCUMENT_NODE)); + if (!j(o[0])) throw new $(); o.shift(); } - if (0 === o.length) throw new R(); - const s = o.reverse(); - if (0 == s.length || s.length > 4) throw new R(); - (P(m, s[0], t, n), - s[1] && P(d, s[1], t, n), - s[2] && P(f, s[2], t, n), - s[3] && P(h, s[3], t, n)); + if (0 === o.length) throw new $(); + const r = o.reverse(); + if (0 == r.length) throw new $(); + const a = [m, d, f, h, x]; + let s = 0, + i = !1; + for (const e of r) { + if (j(e)) { + i = !0; + continue; + } + const o = i ? g : a[s++]; + if (!o) throw new $(); + X(o, e, t, n); + } } } - var r, a; } - function j(e, t, n) { + function O(e, t, n) { "attribute" === t - ? n.push(new w(e, l.Node.ATTRIBUTE_NODE)) - : n.push(new w(e, l.Node.ELEMENT_NODE)); + ? n.push(new y(e, l.Node.ATTRIBUTE_NODE)) + : n.push(new y(e, l.Node.ELEMENT_NODE)); } - function P(e, t, n, o) { + function X(e, t, n, o) { var r, a; const s = - null === (r = S(t, "xpathAxis")) || void 0 === r + null === (r = I(t, "xpathAxis")) || void 0 === r ? void 0 : r.textContent; if ("child" !== s && "attribute" !== s) - throw new R(`unsupported axis: ${s}`); + throw new $(`unsupported axis: ${s}`); for (const r of t.childNodes.slice(1)) { - if (!T(r)) continue; + if (!E(r)) continue; const i = r.localName; - if ("nameTest" === i) (O(e, t, n, o), j(e, s, n)); + if ("nameTest" === i) (D(e, t, n, o), O(e, s, n)); else if ("Wildcard" === i) { - const t = S(r, "NCName"); + const t = I(r, "NCName"); if (t) { const r = null == o ? void 0 : o(null !== (a = t.textContent) && void 0 !== a ? a : ""); - if (!r) throw new R(`unresolved ns prefix: ${r}`); - n.push(new g(e, r)); + if (!r) throw new $(`unresolved ns prefix: ${r}`); + n.push(new v(e, r)); } - j(e, s, n); + O(e, s, n); } else if ("piTest" === i) { - n.push(new w(e, l.Node.PROCESSING_INSTRUCTION_NODE)); - const t = S(r, "piTarget"); + n.push(new y(e, l.Node.PROCESSING_INSTRUCTION_NODE)); + const t = I(r, "piTarget"); (null == t ? void 0 : t.textContent) && - n.push(new v(e, t.textContent)); + n.push(new T(e, t.textContent)); } else if ("commentTest" === i) - n.push(new w(e, l.Node.COMMENT_NODE)); - else if ("textTest" === i) n.push(new w(e, l.Node.TEXT_NODE)); + n.push(new y(e, l.Node.COMMENT_NODE)); + else if ("textTest" === i) n.push(new y(e, l.Node.TEXT_NODE)); else { - if ("predicates" !== i) throw new R(); - $(e, r, n, o); + if ("predicates" !== i) throw new $(); + L(e, r, n, o); } } } - function O(e, t, n, o) { - const r = S(t, "nameTest"); - if (!r) throw new R(); + function D(e, t, n, o) { + const r = I(t, "nameTest"); + if (!r) throw new $(); const a = r.textContent; - a && n.push(new v(e, a)); + a && n.push(new T(e, a)); const s = r.getAttributeNS(p, "prefix"); if (s) { const t = null == o ? void 0 : o(s); - if (!t) throw new R(`unresolved ns prefix: ${t}`); - n.push(new g(e, t)); + if (!t) throw new $(`unresolved ns prefix: ${t}`); + n.push(new v(e, t)); } const i = r.getAttributeNS(p, "URI"); - i && n.push(new g(e, i)); + i && n.push(new v(e, i)); } - function $(e, t, n, o) { + function L(e, t, n, o) { for (const r of t.childNodes) { - if (!T(r)) throw new R(); + if (!E(r)) throw new $(); const t = r.localName; if ("equalOp" === t) { - const t = S(r, "firstOperand"), - o = S(r, "secondOperand"); - if (!t || !o) throw new R(); - const a = C(e, t, o) || C(e, o, t); - if (!a) throw new R(); + const t = I(r, "firstOperand"), + o = I(r, "secondOperand"); + if (!t || !o) throw new $(); + const a = M(e, t, o) || M(e, o, t); + if (!a) throw new $(); n.push(a); } else { - if ("andOp" !== t) throw new R(); - ($(e, S(r, "firstOperand"), n, o), - $(e, S(r, "secondOperand"), n, o)); + if ("andOp" !== t) throw new $(); + (L(e, I(r, "firstOperand"), n, o), + L(e, I(r, "secondOperand"), n, o)); } } } - function C(e, t, n) { + function M(e, t, n) { var o, r; - const a = E(n, "value"); + const a = P(n, "value"); if (!a) return; const s = null !== (o = a.textContent) && void 0 !== o ? o : "", - i = E(t, "stepExpr", (e) => { + i = P(t, "stepExpr", (e) => { var t; return ( "attribute" === - (null === (t = S(e, "xpathAxis")) || void 0 === t + (null === (t = I(e, "xpathAxis")) || void 0 === t ? void 0 : t.textContent) ); }); if (i) { const t = - null === (r = S(i, "nameTest")) || void 0 === r + null === (r = I(i, "nameTest")) || void 0 === r ? void 0 : r.textContent; if (!t) return; - return new y(e, { name: t, value: s }); + return new S(e, { name: t, value: s }); } - return S(t, "contextItemExpr") || E(t, "textTest") - ? new N(e, s) + return I(t, "contextItemExpr") || P(t, "textTest") + ? new b(e, s) : void 0; } }, @@ -1195,13 +1216,13 @@ { namespaceURI: r.XJSLT_NSURI, localName: "normalize-unicode" }, ["xs:string?"], "xs:string", - (e, t) => v(0, t, "NFC"), + (e, t) => N(0, t, "NFC"), ), (0, o.registerCustomXPathFunction)( { namespaceURI: r.XJSLT_NSURI, localName: "normalize-unicode" }, ["xs:string?", "xs:string"], "xs:string", - v, + N, ), (0, o.registerCustomXPathFunction)( { namespaceURI: r.XJSLT_NSURI, localName: "element-available" }, @@ -1213,13 +1234,13 @@ { namespaceURI: r.XJSLT_NSURI, localName: "format-number" }, ["xs:numeric", "xs:string"], "xs:string", - N, + v, ), (0, o.registerCustomXPathFunction)( { namespaceURI: r.XJSLT_NSURI, localName: "format-number" }, ["xs:numeric", "xs:string", "xs:string"], "xs:string", - N, + v, )); })); const o = n(594), @@ -1327,14 +1348,14 @@ for (const e of r) a = new URL(e, a) || e; return a; } - function v(e, t, n) { + function N(e, t, n) { if (null == t) return ""; const o = n.toUpperCase().replace("-", ""); if (!["NFC", "NFD", "NFKC", "NFKD"].includes(o)) throw new Error("FOCH0003: Normalization form not supported."); return t.normalize(o); } - function N({ currentContext: e }, t, n, o) { + function v({ currentContext: e }, t, n, o) { var s, i; const c = o || "#default", u = @@ -1708,15 +1729,15 @@ } } }, - 472(e, t, n) { + 472(e, t) { "use strict"; (Object.defineProperty(t, "__esModule", { value: !0 }), (t.urlToDom = function (e, t) { - if (!e.readDocument) return; - const n = e.inputURL ? (0, o.resolve)(e.inputURL.toString(), t) : t; + const n = e.inputURL + ? new URL(t, e.inputURL.toString()).toString() + : t; return e.readDocument(n); })); - const o = n(16); }, 821(e, t, n) { "use strict"; @@ -1785,9 +1806,11 @@ t.NodeNamespaceFeature = t.NodeAttributeFeature = t.selfNode = + t.greatGreatGrandParentNode = t.greatGrandParentNode = t.grandParentNode = t.parentNode = + t.ancestorNodes = t.KeyImpl = void 0), (t.visitNodes = h), @@ -1798,12 +1821,7 @@ const n = e.nextMatches; if (n) { const o = n.next(); - o.done || - $( - o.value, - Object.assign(Object.assign({}, e), { nextMatches: n }), - t.params, - ); + o.done || ((e.nextMatches = n), C(o.value, e, t.params)); } }), (t.applyImports = function (e, t) { @@ -1811,15 +1829,10 @@ if (n) { let o = n.next(); for (; !o.done && 1 === o.value.importPrecedence; ) o = n.next(); - o.done || - $( - o.value, - Object.assign(Object.assign({}, e), { nextMatches: n }), - t.params, - ); + o.done || ((e.nextMatches = n), C(o.value, e, t.params)); } }), - (t.sort = P), + (t.sort = j), (t.applyTemplates = function (e, t) { const n = (0, p.mkResolver)(t.namespaces), o = (0, i.evaluateXPathToNodes)( @@ -1835,20 +1848,19 @@ ); let r = t.mode || "#default"; ("#current" === r && (r = e.mode), - I(P(e, o, t.sortKeyComponents, n), e, (e) => { - S( - Object.assign(Object.assign({}, e), { - mode: r, - variableScopes: C(e.variableScopes), - }), - t.params, - t.namespaces, - ); - })); + I( + j(e, o, t.sortKeyComponents, n), + Object.assign(Object.assign({}, e), { mode: r }), + (e) => { + ((e.variableScopes = O(e.variableScopes)), + S(e, t.params, t.namespaces), + e.variableScopes.pop()); + }, + )); }), (t.callTemplate = function (e, t) { const n = e.namedTemplates.get(t.name); - if (void 0 !== n) return $(e.templates[n], e, t.params); + if (void 0 !== n) return C(e.templates[n], e, t.params); throw new Error(`Cannot find a template named ${t.name}`); }), (t.functionX = function (e, t) { @@ -1937,7 +1949,7 @@ (t.param = function (e, t) { M(e.variableScopes, t.name, e.stylesheetParams[t.name] || J(e, t)); }), - (t.extendScope = C), + (t.extendScope = O), (t.wrapValue = L), (t.setVariable = M), (t.mergeVariableScopes = _), @@ -1965,22 +1977,22 @@ let o = F(e, { name: t.name, namespace: t.namespace }); const r = (0, p.mkResolver)(t.namespaces); for (let n of t.attributes) { - const t = G(e, n.value, r), + const t = z(e, n.value, r), a = U(e, { name: n.name, namespace: n.namespace, value: t }); o.setAttributeNode(a); } const a = e.append(o); n( Object.assign(Object.assign({}, e), { - variableScopes: C(e.variableScopes), + variableScopes: O(e.variableScopes), append: a || e.append, }), ); }), (t.attribute = function (e, t, n) { const o = (0, p.mkResolver)(t.namespaces), - r = G(e, t.name, o), - a = G(e, t.namespace, o), + r = z(e, t.name, o), + a = z(e, t.namespace, o), [s, i] = r.includes(":") ? (0, p.determineNamespace)(r, o, a) : [a, r], @@ -1992,7 +2004,7 @@ e.append(c); }), (t.processingInstruction = function (e, t, n) { - const o = G(e, t.name, (0, p.mkResolver)(t.namespaces)), + const o = z(e, t.name, (0, p.mkResolver)(t.namespaces)), r = Y(e, t.select || n, (0, p.mkResolver)(t.namespaces), [ "", ]).trimStart(); @@ -2006,7 +2018,7 @@ }), (t.namespace = function (e, t, n) { const o = (0, p.mkResolver)(t.namespaces), - r = G(e, t.name, o), + r = z(e, t.name, o), a = Y(e, t.select || n, o, [""]), s = U(e, { name: `xmlns:${r}`, @@ -2017,8 +2029,8 @@ }), (t.element = function (e, t, n) { const o = (0, p.mkResolver)(t.namespaces); - let r = G(e, t.name, o), - a = G(e, t.namespace, o), + let r = z(e, t.name, o), + a = z(e, t.namespace, o), s = F(e, { name: r, namespace: (0, p.determineNamespace)( @@ -2030,7 +2042,7 @@ const i = e.append(s); n( Object.assign(Object.assign({}, e), { - variableScopes: C(e.variableScopes), + variableScopes: O(e.variableScopes), append: i || e.append, }), ); @@ -2078,7 +2090,7 @@ outputDocument: o, append: r, mode: "#default", - variableScopes: C(e.variableScopes), + variableScopes: O(e.variableScopes), }), ); }), @@ -2097,7 +2109,7 @@ }, ); if (o && Symbol.iterator in Object(o)) { - const r = P(e, o, t.sortKeyComponents, n); + const r = j(e, o, t.sortKeyComponents, n); for (let t of r) e.append(t); } }), @@ -2117,13 +2129,11 @@ ); r && Symbol.iterator in Object(r) && - ((r = P(e, r, t.sortKeyComponents, o)), + ((r = j(e, r, t.sortKeyComponents, o)), I(r, e, (e) => { - n( - Object.assign(Object.assign({}, e), { - variableScopes: C(e.variableScopes), - }), - ); + ((e.variableScopes = O(e.variableScopes)), + n(e), + e.variableScopes.pop()); })); }), (t.forEachGroup = function (e, t, n) { @@ -2200,7 +2210,7 @@ e.patternMatchCache, n, t, - e.variableScopes, + _(e.variableScopes), o, ) && (A(r, a), (a = []))); }), @@ -2219,7 +2229,7 @@ e.patternMatchCache, n, t, - e.variableScopes, + _(e.variableScopes), o, ) && (A(r, a), (a = [])), a.push(t)); @@ -2228,8 +2238,8 @@ r ); })(e, a, t.groupStartingWith, o)), - (r = P(e, r, t.sortKeyComponents, o)), - j(r, e, n)); + (r = j(e, r, t.sortKeyComponents, o)), + P(r, e, n)); } }), (t.number = function (e, t) { @@ -2263,11 +2273,11 @@ )); }), (t.mkNodeAppender = k), - (t.mkArrayAppender = z), + (t.mkArrayAppender = G), (t.resultDocument = function (e, t, n) { const o = (0, p.mkResolver)(t.namespaces); function r(t) { - return G(e, t, o); + return z(e, t, o); } const a = r(t.format); let s = (0, p.mkOutputDefinition)({ @@ -2350,7 +2360,7 @@ for (let e of o) e.remove(); return e; }), - (t.evaluateAttributeValueTemplate = G), + (t.evaluateAttributeValueTemplate = z), (t.serialize = function (e) { const t = new c.XMLSerializer(); if (!0 !== e.omitXmlDeclaration) { @@ -2411,12 +2421,24 @@ ? e.textContent : e.toString(); } - (Object.defineProperty(t, "greatGrandParentNode", { + (Object.defineProperty(t, "ancestorNodes", { enumerable: !0, get: function () { - return f.greatGrandParentNode; + return f.ancestorNodes; }, }), + Object.defineProperty(t, "greatGrandParentNode", { + enumerable: !0, + get: function () { + return f.greatGrandParentNode; + }, + }), + Object.defineProperty(t, "greatGreatGrandParentNode", { + enumerable: !0, + get: function () { + return f.greatGreatGrandParentNode; + }, + }), Object.defineProperty(t, "grandParentNode", { enumerable: !0, get: function () { @@ -2474,6 +2496,7 @@ } buildDocumentCache(e, t, n) { let o = new Map(); + const r = _(n); return ( h(t, (t) => { if ( @@ -2482,7 +2505,7 @@ e, { xpath: this.match }, t, - n, + r, (0, p.mkResolver)(this.namespaces), ) ) { @@ -2503,15 +2526,15 @@ })); const g = new RegExp(/^[a-z |-]+$/), w = new RegExp(/^@[a-z]+$/), - v = new RegExp(/text\(\)|node\(\)/), - N = new RegExp(/@|attribute|node/); + N = new RegExp(/text\(\)|node\(\)/), + v = new RegExp(/@|attribute|node/); function y(e, t, n, o, r) { return !( (n && (function (e, t) { return ( - (t.nodeType === l.NodeType.ATTRIBUTE && !N.exec(e)) || - (t.nodeType === l.NodeType.TEXT && !v.exec(e)) || + (t.nodeType === l.NodeType.ATTRIBUTE && !v.exec(e)) || + (t.nodeType === l.NodeType.TEXT && !N.exec(e)) || !(!g.exec(e) || t.nodeType === l.NodeType.ELEMENT) || !(!w.exec(e) || t.nodeType === l.NodeType.ATTRIBUTE) ); @@ -2521,14 +2544,13 @@ let a = e.get(t.xpath); a || ((a = new Map()), e.set(t.xpath, a)); let s = n; - const c = _(o); for (; s; ) { let e = a.get(s); if ( (void 0 === e && ((e = t.compiled ? (0, i.executeJavaScriptCompiledXPath)(t.compiled, s) - : (0, i.evaluateXPathToNodes)(t.xpath, s, void 0, c, { + : (0, i.evaluateXPathToNodes)(t.xpath, s, void 0, o, { namespaceResolver: r, functionNameResolver: u.functionNameResolver, })), @@ -2565,11 +2587,12 @@ ("#all" === e.modes[0] || e.modes.includes(o)) && (yield e); })(e.contextItem, e.ruleTree, e.templates, e.mode), r = (function* (e, t, n, o, r, a, s) { - for (let [i, c] of n) { + const i = _(r); + for (let [r, c] of n) { const n = o[c]; - i && + r && ("#all" === n.modes[0] || n.modes.includes(a)) && - y(e, i, t, r, (0, p.mkResolver)(s)) && + y(e, r, t, i, (0, p.mkResolver)(s)) && (yield n); } })( @@ -2583,15 +2606,10 @@ ), a = T(b(o, r)); const s = a.next(); - s.done || - $( - s.value, - Object.assign(Object.assign({}, e), { nextMatches: a }), - t, - ); + ((e.nextMatches = a), s.done || C(s.value, e, t)); } function E(e, t, n, o) { - const r = "descending" === G(e, n.order, o); + const r = "descending" === z(e, n.order, o); return "number" === n.dataType ? (function (e, t, n, o, r) { const a = R(t, e, (e) => { @@ -2609,7 +2627,7 @@ })(e, t, n, o, r) : (function (e, t, n, o, r) { const a = R(t, e, (e) => Y(e, n.sortKey, o)), - s = n.lang && G(e, n.lang, o); + s = n.lang && z(e, n.lang, o); let i = new Intl.Collator(s).compare; return (0, p.zip)(a, t) .sort(r ? (e, t) => i(t[0], e[0]) : (e, t) => i(e[0], t[0])) @@ -2618,24 +2636,16 @@ } function R(e, t, n) { if (e.length > 0) - return (0, l.isNodeGroupArray)(e) ? j(e, t, n) : I(e, t, n); + return (0, l.isNodeGroupArray)(e) ? P(e, t, n) : I(e, t, n); } function I(e, t, n) { let o = 0; + const r = Object.assign(Object.assign({}, t), { contextList: e }); return e.map( - (r) => ( - o++, - n( - Object.assign(Object.assign({}, t), { - contextItem: r, - contextList: e, - position: o, - }), - ) - ), + (e) => (o++, (r.contextItem = e), (r.position = o), n(r)), ); } - function j(e, t, n) { + function P(e, t, n) { let o = 0; return e.map((e) => { o++; @@ -2644,29 +2654,29 @@ contextList: e.nodes, currentGroup: e, position: o, - variableScopes: C(t.variableScopes), + variableScopes: O(t.variableScopes), }); return n(r); }); } - function P(e, t, n, o) { + function j(e, t, n, o) { if (n) for (let r of [...n].reverse()) t = E(e, t, r, o); return t; } - function O(e, t) { + function $(e, t) { for (let n of t) if (n.name === e) return n; } - function $(e, t, n) { - let o = C(t.variableScopes); + function C(e, t, n) { + let o = O(t.variableScopes); for (let r of e.allowedParams) { - let e = O(r.name, n); + let e = $(r.name, n); void 0 !== e ? M(o, e.name, J(t, e)) : M(o, r.name, J(t, r)); } return e.apply( Object.assign(Object.assign({}, t), { variableScopes: o }), ); } - function C(e) { + function O(e) { return e.concat([new Map()]); } new RegExp(/(^\/$|document-node\(|node\()/); @@ -2763,7 +2773,7 @@ } }; } - function z(e) { + function G(e) { return function (t) { if ( (e.push(t), @@ -2774,7 +2784,7 @@ return k(t); }; } - function G(e, t, n) { + function z(e, t, n) { if (!t) return; const o = _(e.variableScopes); return t @@ -2797,7 +2807,7 @@ } function Y(e, t, n, o) { o || (o = "string" == typeof t ? [" "] : []); - const r = G(e, o, n); + const r = z(e, o, n); if ("string" == typeof t) { const o = _(e.variableScopes); return (0, i.evaluateXPath)( @@ -2851,9 +2861,9 @@ return ( t( Object.assign(Object.assign({}, e), { - append: z(n), + append: G(n), mode: "#default", - variableScopes: C(e.variableScopes), + variableScopes: O(e.variableScopes), }), ), 1 === n.length ? n[0] : n @@ -2883,7 +2893,7 @@ append: n, outputDocument: e.outputDocument, mode: "#default", - variableScopes: C(e.variableScopes), + variableScopes: O(e.variableScopes), }), ); }); @@ -2898,10 +2908,6 @@ "use strict"; e.exports = require("slimdom"); }, - 16(e) { - "use strict"; - e.exports = require("url"); - }, }, t = {}, n = (function n(o) { @@ -2909,6 +2915,6 @@ if (void 0 !== r) return r.exports; var a = (t[o] = { exports: {} }); return (e[o].call(a.exports, a, a.exports, n), a.exports); - })(868); + })(813); module.exports = n.transform; })(); diff --git a/src/preprocess/include.js b/src/preprocess/include.js index 87c78fb..ae6779b 100644 --- a/src/preprocess/include.js +++ b/src/preprocess/include.js @@ -1,6 +1,6 @@ (() => { var e = { - 790(e, t, n) { + 337(e, t, n) { (n(898), n(594)); let r = n(821); function o(e, t) { @@ -437,12 +437,14 @@ (t.parentNode = d), (t.grandParentNode = f), (t.greatGrandParentNode = h), + (t.greatGreatGrandParentNode = g), + (t.ancestorNodes = x), (t.xpathToFeatures = function (e, t) { if (e) return (function (e, t) { const n = []; try { - return (I(e, n, t), n); + return (C(e, n, t), n); } catch (e) { return; } @@ -460,33 +462,51 @@ u = n(594), l = s(n(898)), p = "http://www.w3.org/2005/XQueryX"; - function m(e) { - return e; + function* m(e) { + yield e; } - function d(e) { - return e.parentNode || void 0; + function* d(e) { + e.parentNode && (yield e.parentNode); } - function f(e) { + function* f(e) { var t; - return ( - (null === (t = e.parentNode) || void 0 === t - ? void 0 - : t.parentNode) || void 0 - ); + const n = + null === (t = e.parentNode) || void 0 === t ? void 0 : t.parentNode; + n && (yield n); } - function h(e) { + function* h(e) { var t, n; - return ( - (null === + const r = + null === (n = null === (t = e.parentNode) || void 0 === t ? void 0 : t.parentNode) || void 0 === n ? void 0 - : n.parentNode) || void 0 - ); + : n.parentNode; + r && (yield r); + } + function* g(e) { + var t, n, r; + const o = + null === + (r = + null === + (n = + null === (t = e.parentNode) || void 0 === t + ? void 0 + : t.parentNode) || void 0 === n + ? void 0 + : n.parentNode) || void 0 === r + ? void 0 + : r.parentNode; + o && (yield o); } - class g extends c.Feature { + function* x(e) { + let t = e.parentNode; + for (; t; ) (yield t, (t = t.parentNode)); + } + class N extends c.Feature { constructor(e, t) { (super(t), (this.nodeExtractor = e)); } @@ -503,214 +523,215 @@ return this.nodeExtractor === e.nodeExtractor && super.equals(e); } } - class x extends g { + function w(e, t) { + for (const n of e) if (t(n)) return !0; + return !1; + } + class v extends N { matches(e) { - var t; - return ( - (null === (t = this.nodeExtractor(e)) || void 0 === t - ? void 0 - : t.nodeType) === l.Node.ELEMENT_NODE && - e.namespaceURI === this.value + return w( + this.nodeExtractor(e), + (e) => + e.nodeType == l.Node.ELEMENT_NODE && + e.namespaceURI === this.value, ); } } - t.NodeNamespaceFeature = x; - class N extends g { + t.NodeNamespaceFeature = v; + class y extends N { matches(e) { - var t; - return ( - (null === (t = this.nodeExtractor(e)) || void 0 === t - ? void 0 - : t.nodeType) === this.value - ); + return w(this.nodeExtractor(e), (e) => e.nodeType === this.value); } } - t.NodeTypeFeature = N; - class w extends g { + t.NodeTypeFeature = y; + class T extends N { matches(e) { - var t; - return ( - (null === (t = this.nodeExtractor(e)) || void 0 === t - ? void 0 - : t.nodeName) === this.value - ); + return w(this.nodeExtractor(e), (e) => e.nodeName === this.value); } } - t.NodeNameFeature = w; - class v extends g { + t.NodeNameFeature = T; + class b extends N { matches(e) { - var t; - return ( - (null === (t = this.nodeExtractor(e)) || void 0 === t - ? void 0 - : t.textContent) === this.value + return w( + this.nodeExtractor(e), + (e) => e.textContent === this.value, ); } } - t.NodeTextFeature = v; - class y extends g { + t.NodeTextFeature = b; + class S extends N { matches(e) { - const t = this.nodeExtractor(e); - return ( - t.nodeType === l.Node.ELEMENT_NODE && - t.getAttribute(this.value.name) === this.value.value + return w( + this.nodeExtractor(e), + (e) => + e.nodeType == l.Node.ELEMENT_NODE && + e.getAttribute(this.value.name) === this.value.value, ); } } - function T(e) { + function R(e) { return ( (function (e) { return 1 === e.nodeType; })(e) && e.namespaceURI === p ); } - function b(e, t) { - return T(e) && e.localName === t; + function E(e, t) { + return R(e) && e.localName === t; } - function S(e, t) { - for (const n of e.childNodes) if (b(n, t)) return n; + function I(e, t) { + for (const n of e.childNodes) if (E(n, t)) return n; } - function R(e, t, n) { + function P(e, t, n) { for (const r of e.childNodes) { - if (!T(r)) continue; - if (b(r, t) && (!n || n(r))) return r; - const e = R(r, t, n); + if (!R(r)) continue; + if (E(r, t) && (!n || n(r))) return r; + const e = P(r, t, n); if (e) return e; } } - t.NodeAttributeFeature = y; - class E extends Error {} - function I(e, t, n) { - if (!T(e)) return; + function $(e) { + var t; + return ( + "descendant-or-self" === + (null === (t = I(e, "xpathAxis")) || void 0 === t + ? void 0 + : t.textContent) && !!I(e, "anyKindTest") + ); + } + t.NodeAttributeFeature = S; + class O extends Error {} + function C(e, t, n) { + if (!R(e)) return; const r = e.localName; if ("module" === r || "mainModule" === r || "queryBody" === r) - for (const r of e.childNodes) I(r, t, n); + for (const r of e.childNodes) C(r, t, n); else { - if ("pathExpr" !== r) throw new E(); + if ("pathExpr" !== r) throw new O(); { - const r = e.childNodes.filter((e) => b(e, "stepExpr")); - if (b(e.firstChild, "rootExpr")) { + const r = e.childNodes.filter((e) => E(e, "stepExpr")); + if (E(e.firstChild, "rootExpr")) { if (0 === r.length) - return void t.push(new N(m, l.Node.DOCUMENT_NODE)); - if ( - "descendant-or-self" !== - (null === (a = S((o = r[0]), "xpathAxis")) || void 0 === a - ? void 0 - : a.textContent) || - !S(o, "anyKindTest") - ) - throw new E(); + return void t.push(new y(m, l.Node.DOCUMENT_NODE)); + if (!$(r[0])) throw new O(); r.shift(); } - if (0 === r.length) throw new E(); - const s = r.reverse(); - if (0 == s.length || s.length > 4) throw new E(); - (O(m, s[0], t, n), - s[1] && O(d, s[1], t, n), - s[2] && O(f, s[2], t, n), - s[3] && O(h, s[3], t, n)); + if (0 === r.length) throw new O(); + const o = r.reverse(); + if (0 == o.length) throw new O(); + const a = [m, d, f, h, g]; + let s = 0, + i = !1; + for (const e of o) { + if ($(e)) { + i = !0; + continue; + } + const r = i ? x : a[s++]; + if (!r) throw new O(); + D(r, e, t, n); + } } } - var o, a; } - function $(e, t, n) { + function j(e, t, n) { "attribute" === t - ? n.push(new N(e, l.Node.ATTRIBUTE_NODE)) - : n.push(new N(e, l.Node.ELEMENT_NODE)); + ? n.push(new y(e, l.Node.ATTRIBUTE_NODE)) + : n.push(new y(e, l.Node.ELEMENT_NODE)); } - function O(e, t, n, r) { + function D(e, t, n, r) { var o, a; const s = - null === (o = S(t, "xpathAxis")) || void 0 === o + null === (o = I(t, "xpathAxis")) || void 0 === o ? void 0 : o.textContent; if ("child" !== s && "attribute" !== s) - throw new E(`unsupported axis: ${s}`); + throw new O(`unsupported axis: ${s}`); for (const o of t.childNodes.slice(1)) { - if (!T(o)) continue; + if (!R(o)) continue; const i = o.localName; - if ("nameTest" === i) (P(e, t, n, r), $(e, s, n)); + if ("nameTest" === i) (X(e, t, n, r), j(e, s, n)); else if ("Wildcard" === i) { - const t = S(o, "NCName"); + const t = I(o, "NCName"); if (t) { const o = null == r ? void 0 : r(null !== (a = t.textContent) && void 0 !== a ? a : ""); - if (!o) throw new E(`unresolved ns prefix: ${o}`); - n.push(new x(e, o)); + if (!o) throw new O(`unresolved ns prefix: ${o}`); + n.push(new v(e, o)); } - $(e, s, n); + j(e, s, n); } else if ("piTest" === i) { - n.push(new N(e, l.Node.PROCESSING_INSTRUCTION_NODE)); - const t = S(o, "piTarget"); + n.push(new y(e, l.Node.PROCESSING_INSTRUCTION_NODE)); + const t = I(o, "piTarget"); (null == t ? void 0 : t.textContent) && - n.push(new w(e, t.textContent)); + n.push(new T(e, t.textContent)); } else if ("commentTest" === i) - n.push(new N(e, l.Node.COMMENT_NODE)); - else if ("textTest" === i) n.push(new N(e, l.Node.TEXT_NODE)); + n.push(new y(e, l.Node.COMMENT_NODE)); + else if ("textTest" === i) n.push(new y(e, l.Node.TEXT_NODE)); else { - if ("predicates" !== i) throw new E(); - C(e, o, n, r); + if ("predicates" !== i) throw new O(); + M(e, o, n, r); } } } - function P(e, t, n, r) { - const o = S(t, "nameTest"); - if (!o) throw new E(); + function X(e, t, n, r) { + const o = I(t, "nameTest"); + if (!o) throw new O(); const a = o.textContent; - a && n.push(new w(e, a)); + a && n.push(new T(e, a)); const s = o.getAttributeNS(p, "prefix"); if (s) { const t = null == r ? void 0 : r(s); - if (!t) throw new E(`unresolved ns prefix: ${t}`); - n.push(new x(e, t)); + if (!t) throw new O(`unresolved ns prefix: ${t}`); + n.push(new v(e, t)); } const i = o.getAttributeNS(p, "URI"); - i && n.push(new x(e, i)); + i && n.push(new v(e, i)); } - function C(e, t, n, r) { + function M(e, t, n, r) { for (const o of t.childNodes) { - if (!T(o)) throw new E(); + if (!R(o)) throw new O(); const t = o.localName; if ("equalOp" === t) { - const t = S(o, "firstOperand"), - r = S(o, "secondOperand"); - if (!t || !r) throw new E(); - const a = j(e, t, r) || j(e, r, t); - if (!a) throw new E(); + const t = I(o, "firstOperand"), + r = I(o, "secondOperand"); + if (!t || !r) throw new O(); + const a = _(e, t, r) || _(e, r, t); + if (!a) throw new O(); n.push(a); } else { - if ("andOp" !== t) throw new E(); - (C(e, S(o, "firstOperand"), n, r), - C(e, S(o, "secondOperand"), n, r)); + if ("andOp" !== t) throw new O(); + (M(e, I(o, "firstOperand"), n, r), + M(e, I(o, "secondOperand"), n, r)); } } } - function j(e, t, n) { + function _(e, t, n) { var r, o; - const a = R(n, "value"); + const a = P(n, "value"); if (!a) return; const s = null !== (r = a.textContent) && void 0 !== r ? r : "", - i = R(t, "stepExpr", (e) => { + i = P(t, "stepExpr", (e) => { var t; return ( "attribute" === - (null === (t = S(e, "xpathAxis")) || void 0 === t + (null === (t = I(e, "xpathAxis")) || void 0 === t ? void 0 : t.textContent) ); }); if (i) { const t = - null === (o = S(i, "nameTest")) || void 0 === o + null === (o = I(i, "nameTest")) || void 0 === o ? void 0 : o.textContent; if (!t) return; - return new y(e, { name: t, value: s }); + return new S(e, { name: t, value: s }); } - return S(t, "contextItemExpr") || R(t, "textTest") - ? new v(e, s) + return I(t, "contextItemExpr") || P(t, "textTest") + ? new b(e, s) : void 0; } }, @@ -1555,15 +1576,15 @@ } } }, - 472(e, t, n) { + 472(e, t) { "use strict"; (Object.defineProperty(t, "__esModule", { value: !0 }), (t.urlToDom = function (e, t) { - if (!e.readDocument) return; - const n = e.inputURL ? (0, r.resolve)(e.inputURL.toString(), t) : t; + const n = e.inputURL + ? new URL(t, e.inputURL.toString()).toString() + : t; return e.readDocument(n); })); - const r = n(16); }, 821(e, t, n) { "use strict"; @@ -1632,9 +1653,11 @@ t.NodeNamespaceFeature = t.NodeAttributeFeature = t.selfNode = + t.greatGreatGrandParentNode = t.greatGrandParentNode = t.grandParentNode = t.parentNode = + t.ancestorNodes = t.KeyImpl = void 0), (t.visitNodes = h), @@ -1645,12 +1668,7 @@ const n = e.nextMatches; if (n) { const r = n.next(); - r.done || - C( - r.value, - Object.assign(Object.assign({}, e), { nextMatches: n }), - t.params, - ); + r.done || ((e.nextMatches = n), C(r.value, e, t.params)); } }), (t.applyImports = function (e, t) { @@ -1658,15 +1676,10 @@ if (n) { let r = n.next(); for (; !r.done && 1 === r.value.importPrecedence; ) r = n.next(); - r.done || - C( - r.value, - Object.assign(Object.assign({}, e), { nextMatches: n }), - t.params, - ); + r.done || ((e.nextMatches = n), C(r.value, e, t.params)); } }), - (t.sort = O), + (t.sort = $), (t.applyTemplates = function (e, t) { const n = (0, p.mkResolver)(t.namespaces), r = (0, i.evaluateXPathToNodes)( @@ -1682,16 +1695,15 @@ ); let o = t.mode || "#default"; ("#current" === o && (o = e.mode), - I(O(e, r, t.sortKeyComponents, n), e, (e) => { - S( - Object.assign(Object.assign({}, e), { - mode: o, - variableScopes: j(e.variableScopes), - }), - t.params, - t.namespaces, - ); - })); + I( + $(e, r, t.sortKeyComponents, n), + Object.assign(Object.assign({}, e), { mode: o }), + (e) => { + ((e.variableScopes = j(e.variableScopes)), + S(e, t.params, t.namespaces), + e.variableScopes.pop()); + }, + )); }), (t.callTemplate = function (e, t) { const n = e.namedTemplates.get(t.name); @@ -1812,7 +1824,7 @@ let r = U(e, { name: t.name, namespace: t.namespace }); const o = (0, p.mkResolver)(t.namespaces); for (let n of t.attributes) { - const t = G(e, n.value, o), + const t = z(e, n.value, o), a = A(e, { name: n.name, namespace: n.namespace, value: t }); r.setAttributeNode(a); } @@ -1826,8 +1838,8 @@ }), (t.attribute = function (e, t, n) { const r = (0, p.mkResolver)(t.namespaces), - o = G(e, t.name, r), - a = G(e, t.namespace, r), + o = z(e, t.name, r), + a = z(e, t.namespace, r), [s, i] = o.includes(":") ? (0, p.determineNamespace)(o, r, a) : [a, o], @@ -1839,7 +1851,7 @@ e.append(c); }), (t.processingInstruction = function (e, t, n) { - const r = G(e, t.name, (0, p.mkResolver)(t.namespaces)), + const r = z(e, t.name, (0, p.mkResolver)(t.namespaces)), o = J(e, t.select || n, (0, p.mkResolver)(t.namespaces), [ "", ]).trimStart(); @@ -1853,7 +1865,7 @@ }), (t.namespace = function (e, t, n) { const r = (0, p.mkResolver)(t.namespaces), - o = G(e, t.name, r), + o = z(e, t.name, r), a = J(e, t.select || n, r, [""]), s = A(e, { name: `xmlns:${o}`, @@ -1864,8 +1876,8 @@ }), (t.element = function (e, t, n) { const r = (0, p.mkResolver)(t.namespaces); - let o = G(e, t.name, r), - a = G(e, t.namespace, r), + let o = z(e, t.name, r), + a = z(e, t.namespace, r), s = U(e, { name: o, namespace: (0, p.determineNamespace)( @@ -1944,7 +1956,7 @@ }, ); if (r && Symbol.iterator in Object(r)) { - const o = O(e, r, t.sortKeyComponents, n); + const o = $(e, r, t.sortKeyComponents, n); for (let t of o) e.append(t); } }), @@ -1964,13 +1976,11 @@ ); o && Symbol.iterator in Object(o) && - ((o = O(e, o, t.sortKeyComponents, r)), + ((o = $(e, o, t.sortKeyComponents, r)), I(o, e, (e) => { - n( - Object.assign(Object.assign({}, e), { - variableScopes: j(e.variableScopes), - }), - ); + ((e.variableScopes = j(e.variableScopes)), + n(e), + e.variableScopes.pop()); })); }), (t.forEachGroup = function (e, t, n) { @@ -2047,7 +2057,7 @@ e.patternMatchCache, n, t, - e.variableScopes, + L(e.variableScopes), r, ) && (F(o, a), (a = []))); }), @@ -2066,7 +2076,7 @@ e.patternMatchCache, n, t, - e.variableScopes, + L(e.variableScopes), r, ) && (F(o, a), (a = [])), a.push(t)); @@ -2075,8 +2085,8 @@ o ); })(e, a, t.groupStartingWith, r)), - (o = O(e, o, t.sortKeyComponents, r)), - $(o, e, n)); + (o = $(e, o, t.sortKeyComponents, r)), + P(o, e, n)); } }), (t.number = function (e, t) { @@ -2110,11 +2120,11 @@ )); }), (t.mkNodeAppender = k), - (t.mkArrayAppender = z), + (t.mkArrayAppender = G), (t.resultDocument = function (e, t, n) { const r = (0, p.mkResolver)(t.namespaces); function o(t) { - return G(e, t, r); + return z(e, t, r); } const a = o(t.format); let s = (0, p.mkOutputDefinition)({ @@ -2197,7 +2207,7 @@ for (let e of r) e.remove(); return e; }), - (t.evaluateAttributeValueTemplate = G), + (t.evaluateAttributeValueTemplate = z), (t.serialize = function (e) { const t = new c.XMLSerializer(); if (!0 !== e.omitXmlDeclaration) { @@ -2258,12 +2268,24 @@ ? e.textContent : e.toString(); } - (Object.defineProperty(t, "greatGrandParentNode", { + (Object.defineProperty(t, "ancestorNodes", { enumerable: !0, get: function () { - return f.greatGrandParentNode; + return f.ancestorNodes; }, }), + Object.defineProperty(t, "greatGrandParentNode", { + enumerable: !0, + get: function () { + return f.greatGrandParentNode; + }, + }), + Object.defineProperty(t, "greatGreatGrandParentNode", { + enumerable: !0, + get: function () { + return f.greatGreatGrandParentNode; + }, + }), Object.defineProperty(t, "grandParentNode", { enumerable: !0, get: function () { @@ -2321,6 +2343,7 @@ } buildDocumentCache(e, t, n) { let r = new Map(); + const o = L(n); return ( h(t, (t) => { if ( @@ -2329,7 +2352,7 @@ e, { xpath: this.match }, t, - n, + o, (0, p.mkResolver)(this.namespaces), ) ) { @@ -2368,14 +2391,13 @@ let a = e.get(t.xpath); a || ((a = new Map()), e.set(t.xpath, a)); let s = n; - const c = L(r); for (; s; ) { let e = a.get(s); if ( (void 0 === e && ((e = t.compiled ? (0, i.executeJavaScriptCompiledXPath)(t.compiled, s) - : (0, i.evaluateXPathToNodes)(t.xpath, s, void 0, c, { + : (0, i.evaluateXPathToNodes)(t.xpath, s, void 0, r, { namespaceResolver: o, functionNameResolver: u.functionNameResolver, })), @@ -2412,11 +2434,12 @@ ("#all" === e.modes[0] || e.modes.includes(r)) && (yield e); })(e.contextItem, e.ruleTree, e.templates, e.mode), o = (function* (e, t, n, r, o, a, s) { - for (let [i, c] of n) { + const i = L(o); + for (let [o, c] of n) { const n = r[c]; - i && + o && ("#all" === n.modes[0] || n.modes.includes(a)) && - y(e, i, t, o, (0, p.mkResolver)(s)) && + y(e, o, t, i, (0, p.mkResolver)(s)) && (yield n); } })( @@ -2430,15 +2453,10 @@ ), a = T(b(r, o)); const s = a.next(); - s.done || - C( - s.value, - Object.assign(Object.assign({}, e), { nextMatches: a }), - t, - ); + ((e.nextMatches = a), s.done || C(s.value, e, t)); } function R(e, t, n, r) { - const o = "descending" === G(e, n.order, r); + const o = "descending" === z(e, n.order, r); return "number" === n.dataType ? (function (e, t, n, r, o) { const a = E(t, e, (e) => { @@ -2456,7 +2474,7 @@ })(e, t, n, r, o) : (function (e, t, n, r, o) { const a = E(t, e, (e) => J(e, n.sortKey, r)), - s = n.lang && G(e, n.lang, r); + s = n.lang && z(e, n.lang, r); let i = new Intl.Collator(s).compare; return (0, p.zip)(a, t) .sort(o ? (e, t) => i(t[0], e[0]) : (e, t) => i(e[0], t[0])) @@ -2465,24 +2483,16 @@ } function E(e, t, n) { if (e.length > 0) - return (0, l.isNodeGroupArray)(e) ? $(e, t, n) : I(e, t, n); + return (0, l.isNodeGroupArray)(e) ? P(e, t, n) : I(e, t, n); } function I(e, t, n) { let r = 0; + const o = Object.assign(Object.assign({}, t), { contextList: e }); return e.map( - (o) => ( - r++, - n( - Object.assign(Object.assign({}, t), { - contextItem: o, - contextList: e, - position: r, - }), - ) - ), + (e) => (r++, (o.contextItem = e), (o.position = r), n(o)), ); } - function $(e, t, n) { + function P(e, t, n) { let r = 0; return e.map((e) => { r++; @@ -2496,17 +2506,17 @@ return n(o); }); } - function O(e, t, n, r) { + function $(e, t, n, r) { if (n) for (let o of [...n].reverse()) t = R(e, t, o, r); return t; } - function P(e, t) { + function O(e, t) { for (let n of t) if (n.name === e) return n; } function C(e, t, n) { let r = j(t.variableScopes); for (let o of e.allowedParams) { - let e = P(o.name, n); + let e = O(o.name, n); void 0 !== e ? _(r, e.name, Y(t, e)) : _(r, o.name, Y(t, o)); } return e.apply( @@ -2610,7 +2620,7 @@ } }; } - function z(e) { + function G(e) { return function (t) { if ( (e.push(t), @@ -2621,7 +2631,7 @@ return k(t); }; } - function G(e, t, n) { + function z(e, t, n) { if (!t) return; const r = L(e.variableScopes); return t @@ -2644,7 +2654,7 @@ } function J(e, t, n, r) { r || (r = "string" == typeof t ? [" "] : []); - const o = G(e, r, n); + const o = z(e, r, n); if ("string" == typeof t) { const r = L(e.variableScopes); return (0, i.evaluateXPath)( @@ -2698,7 +2708,7 @@ return ( t( Object.assign(Object.assign({}, e), { - append: z(n), + append: G(n), mode: "#default", variableScopes: j(e.variableScopes), }), @@ -2745,10 +2755,6 @@ "use strict"; e.exports = require("slimdom"); }, - 16(e) { - "use strict"; - e.exports = require("url"); - }, }, t = {}, n = (function n(r) { @@ -2756,6 +2762,6 @@ if (void 0 !== o) return o.exports; var a = (t[r] = { exports: {} }); return (e[r].call(a.exports, a, a.exports, n), a.exports); - })(790); + })(337); module.exports = n.transform; })(); diff --git a/src/preprocess/simplified.js b/src/preprocess/simplified.js index f93b633..7f42916 100644 --- a/src/preprocess/simplified.js +++ b/src/preprocess/simplified.js @@ -1,6 +1,6 @@ (() => { var e = { - 571(e, t, n) { + 186(e, t, n) { (n(898), n(594)); let r = n(821); function o(e, t) { @@ -421,12 +421,14 @@ (t.parentNode = d), (t.grandParentNode = f), (t.greatGrandParentNode = g), + (t.greatGreatGrandParentNode = h), + (t.ancestorNodes = N), (t.xpathToFeatures = function (e, t) { if (e) return (function (e, t) { const n = []; try { - return (O(e, n, t), n); + return (C(e, n, t), n); } catch (e) { return; } @@ -444,33 +446,51 @@ u = n(594), l = s(n(898)), p = "http://www.w3.org/2005/XQueryX"; - function m(e) { - return e; + function* m(e) { + yield e; } - function d(e) { - return e.parentNode || void 0; + function* d(e) { + e.parentNode && (yield e.parentNode); } - function f(e) { + function* f(e) { var t; - return ( - (null === (t = e.parentNode) || void 0 === t - ? void 0 - : t.parentNode) || void 0 - ); + const n = + null === (t = e.parentNode) || void 0 === t ? void 0 : t.parentNode; + n && (yield n); } - function g(e) { + function* g(e) { var t, n; - return ( - (null === + const r = + null === (n = null === (t = e.parentNode) || void 0 === t ? void 0 : t.parentNode) || void 0 === n ? void 0 - : n.parentNode) || void 0 - ); + : n.parentNode; + r && (yield r); + } + function* h(e) { + var t, n, r; + const o = + null === + (r = + null === + (n = + null === (t = e.parentNode) || void 0 === t + ? void 0 + : t.parentNode) || void 0 === n + ? void 0 + : n.parentNode) || void 0 === r + ? void 0 + : r.parentNode; + o && (yield o); + } + function* N(e) { + let t = e.parentNode; + for (; t; ) (yield t, (t = t.parentNode)); } - class h extends c.Feature { + class v extends c.Feature { constructor(e, t) { (super(t), (this.nodeExtractor = e)); } @@ -487,214 +507,215 @@ return this.nodeExtractor === e.nodeExtractor && super.equals(e); } } - class v extends h { + function x(e, t) { + for (const n of e) if (t(n)) return !0; + return !1; + } + class w extends v { matches(e) { - var t; - return ( - (null === (t = this.nodeExtractor(e)) || void 0 === t - ? void 0 - : t.nodeType) === l.Node.ELEMENT_NODE && - e.namespaceURI === this.value + return x( + this.nodeExtractor(e), + (e) => + e.nodeType == l.Node.ELEMENT_NODE && + e.namespaceURI === this.value, ); } } - t.NodeNamespaceFeature = v; - class N extends h { + t.NodeNamespaceFeature = w; + class y extends v { matches(e) { - var t; - return ( - (null === (t = this.nodeExtractor(e)) || void 0 === t - ? void 0 - : t.nodeType) === this.value - ); + return x(this.nodeExtractor(e), (e) => e.nodeType === this.value); } } - t.NodeTypeFeature = N; - class x extends h { + t.NodeTypeFeature = y; + class T extends v { matches(e) { - var t; - return ( - (null === (t = this.nodeExtractor(e)) || void 0 === t - ? void 0 - : t.nodeName) === this.value - ); + return x(this.nodeExtractor(e), (e) => e.nodeName === this.value); } } - t.NodeNameFeature = x; - class w extends h { + t.NodeNameFeature = T; + class b extends v { matches(e) { - var t; - return ( - (null === (t = this.nodeExtractor(e)) || void 0 === t - ? void 0 - : t.textContent) === this.value + return x( + this.nodeExtractor(e), + (e) => e.textContent === this.value, ); } } - t.NodeTextFeature = w; - class T extends h { + t.NodeTextFeature = b; + class S extends v { matches(e) { - const t = this.nodeExtractor(e); - return ( - t.nodeType === l.Node.ELEMENT_NODE && - t.getAttribute(this.value.name) === this.value.value + return x( + this.nodeExtractor(e), + (e) => + e.nodeType == l.Node.ELEMENT_NODE && + e.getAttribute(this.value.name) === this.value.value, ); } } - function b(e) { + function R(e) { return ( (function (e) { return 1 === e.nodeType; })(e) && e.namespaceURI === p ); } - function y(e, t) { - return b(e) && e.localName === t; + function E(e, t) { + return R(e) && e.localName === t; } - function S(e, t) { - for (const n of e.childNodes) if (y(n, t)) return n; + function P(e, t) { + for (const n of e.childNodes) if (E(n, t)) return n; } - function R(e, t, n) { + function I(e, t, n) { for (const r of e.childNodes) { - if (!b(r)) continue; - if (y(r, t) && (!n || n(r))) return r; - const e = R(r, t, n); + if (!R(r)) continue; + if (E(r, t) && (!n || n(r))) return r; + const e = I(r, t, n); if (e) return e; } } - t.NodeAttributeFeature = T; - class E extends Error {} - function O(e, t, n) { - if (!b(e)) return; + function $(e) { + var t; + return ( + "descendant-or-self" === + (null === (t = P(e, "xpathAxis")) || void 0 === t + ? void 0 + : t.textContent) && !!P(e, "anyKindTest") + ); + } + t.NodeAttributeFeature = S; + class O extends Error {} + function C(e, t, n) { + if (!R(e)) return; const r = e.localName; if ("module" === r || "mainModule" === r || "queryBody" === r) - for (const r of e.childNodes) O(r, t, n); + for (const r of e.childNodes) C(r, t, n); else { - if ("pathExpr" !== r) throw new E(); + if ("pathExpr" !== r) throw new O(); { - const r = e.childNodes.filter((e) => y(e, "stepExpr")); - if (y(e.firstChild, "rootExpr")) { + const r = e.childNodes.filter((e) => E(e, "stepExpr")); + if (E(e.firstChild, "rootExpr")) { if (0 === r.length) - return void t.push(new N(m, l.Node.DOCUMENT_NODE)); - if ( - "descendant-or-self" !== - (null === (a = S((o = r[0]), "xpathAxis")) || void 0 === a - ? void 0 - : a.textContent) || - !S(o, "anyKindTest") - ) - throw new E(); + return void t.push(new y(m, l.Node.DOCUMENT_NODE)); + if (!$(r[0])) throw new O(); r.shift(); } - if (0 === r.length) throw new E(); - const s = r.reverse(); - if (0 == s.length || s.length > 4) throw new E(); - (P(m, s[0], t, n), - s[1] && P(d, s[1], t, n), - s[2] && P(f, s[2], t, n), - s[3] && P(g, s[3], t, n)); + if (0 === r.length) throw new O(); + const o = r.reverse(); + if (0 == o.length) throw new O(); + const a = [m, d, f, g, h]; + let s = 0, + i = !1; + for (const e of o) { + if ($(e)) { + i = !0; + continue; + } + const r = i ? N : a[s++]; + if (!r) throw new O(); + X(r, e, t, n); + } } } - var o, a; } - function I(e, t, n) { + function D(e, t, n) { "attribute" === t - ? n.push(new N(e, l.Node.ATTRIBUTE_NODE)) - : n.push(new N(e, l.Node.ELEMENT_NODE)); + ? n.push(new y(e, l.Node.ATTRIBUTE_NODE)) + : n.push(new y(e, l.Node.ELEMENT_NODE)); } - function P(e, t, n, r) { + function X(e, t, n, r) { var o, a; const s = - null === (o = S(t, "xpathAxis")) || void 0 === o + null === (o = P(t, "xpathAxis")) || void 0 === o ? void 0 : o.textContent; if ("child" !== s && "attribute" !== s) - throw new E(`unsupported axis: ${s}`); + throw new O(`unsupported axis: ${s}`); for (const o of t.childNodes.slice(1)) { - if (!b(o)) continue; + if (!R(o)) continue; const i = o.localName; - if ("nameTest" === i) ($(e, t, n, r), I(e, s, n)); + if ("nameTest" === i) (M(e, t, n, r), D(e, s, n)); else if ("Wildcard" === i) { - const t = S(o, "NCName"); + const t = P(o, "NCName"); if (t) { const o = null == r ? void 0 : r(null !== (a = t.textContent) && void 0 !== a ? a : ""); - if (!o) throw new E(`unresolved ns prefix: ${o}`); - n.push(new v(e, o)); + if (!o) throw new O(`unresolved ns prefix: ${o}`); + n.push(new w(e, o)); } - I(e, s, n); + D(e, s, n); } else if ("piTest" === i) { - n.push(new N(e, l.Node.PROCESSING_INSTRUCTION_NODE)); - const t = S(o, "piTarget"); + n.push(new y(e, l.Node.PROCESSING_INSTRUCTION_NODE)); + const t = P(o, "piTarget"); (null == t ? void 0 : t.textContent) && - n.push(new x(e, t.textContent)); + n.push(new T(e, t.textContent)); } else if ("commentTest" === i) - n.push(new N(e, l.Node.COMMENT_NODE)); - else if ("textTest" === i) n.push(new N(e, l.Node.TEXT_NODE)); + n.push(new y(e, l.Node.COMMENT_NODE)); + else if ("textTest" === i) n.push(new y(e, l.Node.TEXT_NODE)); else { - if ("predicates" !== i) throw new E(); - C(e, o, n, r); + if ("predicates" !== i) throw new O(); + _(e, o, n, r); } } } - function $(e, t, n, r) { - const o = S(t, "nameTest"); - if (!o) throw new E(); + function M(e, t, n, r) { + const o = P(t, "nameTest"); + if (!o) throw new O(); const a = o.textContent; - a && n.push(new x(e, a)); + a && n.push(new T(e, a)); const s = o.getAttributeNS(p, "prefix"); if (s) { const t = null == r ? void 0 : r(s); - if (!t) throw new E(`unresolved ns prefix: ${t}`); - n.push(new v(e, t)); + if (!t) throw new O(`unresolved ns prefix: ${t}`); + n.push(new w(e, t)); } const i = o.getAttributeNS(p, "URI"); - i && n.push(new v(e, i)); + i && n.push(new w(e, i)); } - function C(e, t, n, r) { + function _(e, t, n, r) { for (const o of t.childNodes) { - if (!b(o)) throw new E(); + if (!R(o)) throw new O(); const t = o.localName; if ("equalOp" === t) { - const t = S(o, "firstOperand"), - r = S(o, "secondOperand"); - if (!t || !r) throw new E(); - const a = D(e, t, r) || D(e, r, t); - if (!a) throw new E(); + const t = P(o, "firstOperand"), + r = P(o, "secondOperand"); + if (!t || !r) throw new O(); + const a = L(e, t, r) || L(e, r, t); + if (!a) throw new O(); n.push(a); } else { - if ("andOp" !== t) throw new E(); - (C(e, S(o, "firstOperand"), n, r), - C(e, S(o, "secondOperand"), n, r)); + if ("andOp" !== t) throw new O(); + (_(e, P(o, "firstOperand"), n, r), + _(e, P(o, "secondOperand"), n, r)); } } } - function D(e, t, n) { + function L(e, t, n) { var r, o; - const a = R(n, "value"); + const a = I(n, "value"); if (!a) return; const s = null !== (r = a.textContent) && void 0 !== r ? r : "", - i = R(t, "stepExpr", (e) => { + i = I(t, "stepExpr", (e) => { var t; return ( "attribute" === - (null === (t = S(e, "xpathAxis")) || void 0 === t + (null === (t = P(e, "xpathAxis")) || void 0 === t ? void 0 : t.textContent) ); }); if (i) { const t = - null === (o = S(i, "nameTest")) || void 0 === o + null === (o = P(i, "nameTest")) || void 0 === o ? void 0 : o.textContent; if (!t) return; - return new T(e, { name: t, value: s }); + return new S(e, { name: t, value: s }); } - return S(t, "contextItemExpr") || R(t, "textTest") - ? new w(e, s) + return P(t, "contextItemExpr") || I(t, "textTest") + ? new b(e, s) : void 0; } }, @@ -928,7 +949,7 @@ 379(e, t, n) { "use strict"; (Object.defineProperty(t, "__esModule", { value: !0 }), - (t.functionNameResolver = b), + (t.functionNameResolver = T), (t.registerFunctions = function () { ((0, r.registerCustomXPathFunction)( { namespaceURI: o.XJSLT_NSURI, localName: "current" }, @@ -988,19 +1009,19 @@ { namespaceURI: o.XJSLT_NSURI, localName: "system-property" }, ["xs:string"], "xs:string", - v, + N, ), (0, r.registerCustomXPathFunction)( { namespaceURI: o.XJSLT_NSURI, localName: "base-uri" }, [], "xs:string?", - N, + v, ), (0, r.registerCustomXPathFunction)( { namespaceURI: o.XJSLT_NSURI, localName: "base-uri" }, ["node()?"], "xs:string?", - N, + v, ), (0, r.registerCustomXPathFunction)( { namespaceURI: o.XJSLT_NSURI, localName: "evaluate" }, @@ -1016,7 +1037,7 @@ r.evaluateXPath.ALL_RESULTS_TYPE, { currentContext: { currentContext: e }, - functionNameResolver: b, + functionNameResolver: T, }, ); return 1 === n.length ? n[0] : n; @@ -1121,7 +1142,7 @@ const [n, r] = t.split(":"); return !(!n || !r) && g.has(r); } - function v(e, t) { + function N(e, t) { return "version" === t.split(":")[1] ? "2.0" : "vendor" === t.split(":")[1] @@ -1139,7 +1160,7 @@ ? "no" : ""; } - function N({ currentContext: e }, t) { + function v({ currentContext: e }, t) { const n = void 0 !== t ? t : e.contextItem; if (!n) return null; let r = n; @@ -1178,7 +1199,7 @@ : o.DEFAULT_DECIMAL_FORMAT; return (0, a.formatNumberWithPicture)(t, n, u); } - const T = [ + const y = [ "base-uri", "current", "current-group", @@ -1193,8 +1214,8 @@ "positionx", "system-property", ]; - function b({ prefix: e, localName: t }, n) { - return (e && "fn" !== e) || !T.includes(t) + function T({ prefix: e, localName: t }, n) { + return (e && "fn" !== e) || !y.includes(t) ? null : { namespaceURI: o.XJSLT_NSURI, localName: t }; } @@ -1377,29 +1398,29 @@ } g >= 0 && (m = f - g); let h = 0, - v = 0; + N = 0; if (s < e.length && e[s] === o) for (s++; s < e.length; ) { const t = e[s]; - if (t === n) (h++, v++); + if (t === n) (h++, N++); else { if (t !== r) break; - v++; + N++; } s++; } - const N = l(); + const v = l(); if (s < e.length) throw new Error( `XTDE1310: Active characters after picture string suffix: ${e.slice(s)}`, ); return { prefix: p, - suffix: N, + suffix: v, integerMinDigits: Math.max(d, 1), integerGroupSize: m, decimalMinDigits: h, - decimalMaxDigits: v, + decimalMaxDigits: N, isPercent: i, isPerMille: c, }; @@ -1539,15 +1560,15 @@ } } }, - 472(e, t, n) { + 472(e, t) { "use strict"; (Object.defineProperty(t, "__esModule", { value: !0 }), (t.urlToDom = function (e, t) { - if (!e.readDocument) return; - const n = e.inputURL ? (0, r.resolve)(e.inputURL.toString(), t) : t; + const n = e.inputURL + ? new URL(t, e.inputURL.toString()).toString() + : t; return e.readDocument(n); })); - const r = n(16); }, 821(e, t, n) { "use strict"; @@ -1616,25 +1637,22 @@ t.NodeNamespaceFeature = t.NodeAttributeFeature = t.selfNode = + t.greatGreatGrandParentNode = t.greatGrandParentNode = t.grandParentNode = t.parentNode = + t.ancestorNodes = t.KeyImpl = void 0), (t.visitNodes = g), - (t.dedupGenerator = b), - (t.mergeTemplateGenerators = y), + (t.dedupGenerator = T), + (t.mergeTemplateGenerators = b), (t.processNode = S), (t.nextMatch = function (e, t) { const n = e.nextMatches; if (n) { const r = n.next(); - r.done || - C( - r.value, - Object.assign(Object.assign({}, e), { nextMatches: n }), - t.params, - ); + r.done || ((e.nextMatches = n), C(r.value, e, t.params)); } }), (t.applyImports = function (e, t) { @@ -1642,22 +1660,17 @@ if (n) { let r = n.next(); for (; !r.done && 1 === r.value.importPrecedence; ) r = n.next(); - r.done || - C( - r.value, - Object.assign(Object.assign({}, e), { nextMatches: n }), - t.params, - ); + r.done || ((e.nextMatches = n), C(r.value, e, t.params)); } }), - (t.sort = P), + (t.sort = $), (t.applyTemplates = function (e, t) { const n = (0, p.mkResolver)(t.namespaces), r = (0, i.evaluateXPathToNodes)( t.select, e.contextItem, void 0, - L(e.variableScopes), + U(e.variableScopes), { currentContext: e, namespaceResolver: n, @@ -1666,16 +1679,15 @@ ); let o = t.mode || "#default"; ("#current" === o && (o = e.mode), - O(P(e, r, t.sortKeyComponents, n), e, (e) => { - S( - Object.assign(Object.assign({}, e), { - mode: o, - variableScopes: D(e.variableScopes), - }), - t.params, - t.namespaces, - ); - })); + P( + $(e, r, t.sortKeyComponents, n), + Object.assign(Object.assign({}, e), { mode: o }), + (e) => { + ((e.variableScopes = D(e.variableScopes)), + S(e, t.params, t.namespaces), + e.variableScopes.pop()); + }, + )); }), (t.callTemplate = function (e, t) { const n = e.namedTemplates.get(t.name); @@ -1739,7 +1751,7 @@ t.select, e.contextItem, void 0, - L(e.variableScopes), + U(e.variableScopes), i.evaluateXPath.ALL_RESULTS_TYPE, { currentContext: e, @@ -1763,15 +1775,15 @@ e.append(J(e, n, (0, p.mkResolver)(t.namespaces), [""])); }), (t.variable = function (e, t) { - j(e.variableScopes, t.name, B(e, t)); + L(e.variableScopes, t.name, B(e, t)); }), (t.param = function (e, t) { - j(e.variableScopes, t.name, e.stylesheetParams[t.name] || B(e, t)); + L(e.variableScopes, t.name, e.stylesheetParams[t.name] || B(e, t)); }), (t.extendScope = D), (t.wrapValue = _), - (t.setVariable = j), - (t.mergeVariableScopes = L), + (t.setVariable = L), + (t.mergeVariableScopes = U), (t.literalText = function (e, t) { e.append(t); }), @@ -1780,7 +1792,7 @@ t.select, e.contextItem, void 0, - L(e.variableScopes), + U(e.variableScopes), i.evaluateXPath.ALL_RESULTS_TYPE, { currentContext: e, @@ -1791,13 +1803,13 @@ e.append(n); }), (t.buildNode = A), - (t.buildAttributeNode = U), + (t.buildAttributeNode = j), (t.literalElement = function (e, t, n) { let r = A(e, { name: t.name, namespace: t.namespace }); const o = (0, p.mkResolver)(t.namespaces); for (let n of t.attributes) { - const t = G(e, n.value, o), - a = U(e, { name: n.name, namespace: n.namespace, value: t }); + const t = z(e, n.value, o), + a = j(e, { name: n.name, namespace: n.namespace, value: t }); r.setAttributeNode(a); } const a = e.append(r); @@ -1810,12 +1822,12 @@ }), (t.attribute = function (e, t, n) { const r = (0, p.mkResolver)(t.namespaces), - o = G(e, t.name, r), - a = G(e, t.namespace, r), + o = z(e, t.name, r), + a = z(e, t.namespace, r), [s, i] = o.includes(":") ? (0, p.determineNamespace)(o, r, a) : [a, o], - c = U(e, { + c = j(e, { name: o, namespace: s, value: J(e, t.select || n, r, t.separator), @@ -1823,7 +1835,7 @@ e.append(c); }), (t.processingInstruction = function (e, t, n) { - const r = G(e, t.name, (0, p.mkResolver)(t.namespaces)), + const r = z(e, t.name, (0, p.mkResolver)(t.namespaces)), o = J(e, t.select || n, (0, p.mkResolver)(t.namespaces), [ "", ]).trimStart(); @@ -1837,9 +1849,9 @@ }), (t.namespace = function (e, t, n) { const r = (0, p.mkResolver)(t.namespaces), - o = G(e, t.name, r), + o = z(e, t.name, r), a = J(e, t.select || n, r, [""]), - s = U(e, { + s = j(e, { name: `xmlns:${o}`, namespace: l.XMLNS_NSURI, value: a, @@ -1848,8 +1860,8 @@ }), (t.element = function (e, t, n) { const r = (0, p.mkResolver)(t.namespaces); - let o = G(e, t.name, r), - a = G(e, t.namespace, r), + let o = z(e, t.name, r), + a = z(e, t.namespace, r), s = A(e, { name: o, namespace: (0, p.determineNamespace)( @@ -1871,7 +1883,7 @@ t.test, e.contextItem, void 0, - L(e.variableScopes), + U(e.variableScopes), { currentContext: e, namespaceResolver: (0, p.mkResolver)(t.namespaces), @@ -1887,7 +1899,7 @@ n.test, e.contextItem, void 0, - L(e.variableScopes), + U(e.variableScopes), { currentContext: e, functionNameResolver: u.functionNameResolver, @@ -1919,7 +1931,7 @@ t.select, e.contextItem, void 0, - L(e.variableScopes), + U(e.variableScopes), i.evaluateXPath.ALL_RESULTS_TYPE, { currentContext: e, @@ -1928,7 +1940,7 @@ }, ); if (r && Symbol.iterator in Object(r)) { - const o = P(e, r, t.sortKeyComponents, n); + const o = $(e, r, t.sortKeyComponents, n); for (let t of o) e.append(t); } }), @@ -1938,7 +1950,7 @@ t.select, e.contextItem, void 0, - L(e.variableScopes), + U(e.variableScopes), i.evaluateXPath.ALL_RESULTS_TYPE, { currentContext: e, @@ -1948,18 +1960,16 @@ ); o && Symbol.iterator in Object(o) && - ((o = P(e, o, t.sortKeyComponents, r)), - O(o, e, (e) => { - n( - Object.assign(Object.assign({}, e), { - variableScopes: D(e.variableScopes), - }), - ); + ((o = $(e, o, t.sortKeyComponents, r)), + P(o, e, (e) => { + ((e.variableScopes = D(e.variableScopes)), + n(e), + e.variableScopes.pop()); })); }), (t.forEachGroup = function (e, t, n) { const r = (0, p.mkResolver)(t.namespaces), - o = L(e.variableScopes), + o = U(e.variableScopes), a = (0, i.evaluateXPathToNodes)( t.select, e.contextItem, @@ -1975,10 +1985,10 @@ let o = []; (t.groupBy ? (o = (function (e, t, n, r) { - const o = L(e.variableScopes); + const o = U(e.variableScopes); let a = []; return ( - O(t, e, (e) => { + P(t, e, (e) => { const t = (0, i.evaluateXPathToString)( n, e.contextItem, @@ -1999,12 +2009,12 @@ })(e, a, t.groupBy, r)) : t.groupAdjacent ? (o = (function (e, t, n, r) { - const o = L(e.variableScopes); + const o = U(e.variableScopes); let a = [], s = null, c = []; return ( - O(t, e, (e) => { + P(t, e, (e) => { const t = e.contextItem, l = (0, i.evaluateXPathToString)(n, t, void 0, o, { currentContext: e, @@ -2024,14 +2034,14 @@ let o = [], a = []; return ( - O(t, e, (e) => { + P(t, e, (e) => { const t = e.contextItem; (a.push(t), - T( + y( e.patternMatchCache, n, t, - e.variableScopes, + U(e.variableScopes), r, ) && (F(o, a), (a = []))); }), @@ -2044,13 +2054,13 @@ let o = [], a = []; return ( - O(t, e, (e) => { + P(t, e, (e) => { const t = e.contextItem; - (T( + (y( e.patternMatchCache, n, t, - e.variableScopes, + U(e.variableScopes), r, ) && (F(o, a), (a = [])), a.push(t)); @@ -2059,13 +2069,13 @@ o ); })(e, a, t.groupStartingWith, r)), - (o = P(e, o, t.sortKeyComponents, r)), + (o = $(e, o, t.sortKeyComponents, r)), I(o, e, n)); } }), (t.number = function (e, t) { const n = (0, p.mkResolver)(t.namespaces), - r = L(e.variableScopes); + r = U(e.variableScopes); let o; (t.value ? (o = (0, i.evaluateXPathToNumber)( @@ -2094,11 +2104,11 @@ )); }), (t.mkNodeAppender = k), - (t.mkArrayAppender = z), + (t.mkArrayAppender = G), (t.resultDocument = function (e, t, n) { const r = (0, p.mkResolver)(t.namespaces); function o(t) { - return G(e, t, r); + return z(e, t, r); } const a = o(t.format); let s = (0, p.mkOutputDefinition)({ @@ -2170,7 +2180,7 @@ let n = new Map(); for (const r of t) { const t = (0, p.mkResolver)(r.namespaces); - if (T(n, r.match, e, [], t)) return !r.preserve; + if (y(n, r.match, e, [], t)) return !r.preserve; } return !1; })(o.parentNode, t) && @@ -2181,7 +2191,7 @@ for (let e of r) e.remove(); return e; }), - (t.evaluateAttributeValueTemplate = G), + (t.evaluateAttributeValueTemplate = z), (t.serialize = function (e) { const t = new c.XMLSerializer(); if (!0 !== e.omitXmlDeclaration) { @@ -2242,12 +2252,24 @@ ? e.textContent : e.toString(); } - (Object.defineProperty(t, "greatGrandParentNode", { + (Object.defineProperty(t, "ancestorNodes", { enumerable: !0, get: function () { - return f.greatGrandParentNode; + return f.ancestorNodes; }, }), + Object.defineProperty(t, "greatGrandParentNode", { + enumerable: !0, + get: function () { + return f.greatGrandParentNode; + }, + }), + Object.defineProperty(t, "greatGreatGrandParentNode", { + enumerable: !0, + get: function () { + return f.greatGreatGrandParentNode; + }, + }), Object.defineProperty(t, "grandParentNode", { enumerable: !0, get: function () { @@ -2305,15 +2327,16 @@ } buildDocumentCache(e, t, n) { let r = new Map(); + const o = U(n); return ( g(t, (t) => { if ( "string" == typeof this.use && - T( + y( e, { xpath: this.match }, t, - n, + o, (0, p.mkResolver)(this.namespaces), ) ) { @@ -2332,19 +2355,19 @@ ); } })); - const v = new RegExp(/^[a-z |-]+$/), - N = new RegExp(/^@[a-z]+$/), + const N = new RegExp(/^[a-z |-]+$/), + v = new RegExp(/^@[a-z]+$/), x = new RegExp(/text\(\)|node\(\)/), w = new RegExp(/@|attribute|node/); - function T(e, t, n, r, o) { + function y(e, t, n, r, o) { return !( (n && (function (e, t) { return ( (t.nodeType === l.NodeType.ATTRIBUTE && !w.exec(e)) || (t.nodeType === l.NodeType.TEXT && !x.exec(e)) || - !(!v.exec(e) || t.nodeType === l.NodeType.ELEMENT) || - !(!N.exec(e) || t.nodeType === l.NodeType.ATTRIBUTE) + !(!N.exec(e) || t.nodeType === l.NodeType.ELEMENT) || + !(!v.exec(e) || t.nodeType === l.NodeType.ATTRIBUTE) ); })(t.xpath, n)) || void 0 === @@ -2352,14 +2375,13 @@ let a = e.get(t.xpath); a || ((a = new Map()), e.set(t.xpath, a)); let s = n; - const c = L(r); for (; s; ) { let e = a.get(s); if ( (void 0 === e && ((e = t.compiled ? (0, i.executeJavaScriptCompiledXPath)(t.compiled, s) - : (0, i.evaluateXPathToNodes)(t.xpath, s, void 0, c, { + : (0, i.evaluateXPathToNodes)(t.xpath, s, void 0, r, { namespaceResolver: o, functionNameResolver: u.functionNameResolver, })), @@ -2374,13 +2396,13 @@ })(e, t, n, r, o) ); } - function* b(e) { + function* T(e) { let t = new Set(), n = e.next(); for (; !n.done; ) (t.has(n.value) || (yield n.value, t.add(n.value)), (n = e.next())); } - function* y(e, t) { + function* b(e, t) { let n = [e.next(), t.next()]; for (; !n[0].done || !n[1].done; ) n[0].done @@ -2396,11 +2418,12 @@ ("#all" === e.modes[0] || e.modes.includes(r)) && (yield e); })(e.contextItem, e.ruleTree, e.templates, e.mode), o = (function* (e, t, n, r, o, a, s) { - for (let [i, c] of n) { + const i = U(o); + for (let [o, c] of n) { const n = r[c]; - i && + o && ("#all" === n.modes[0] || n.modes.includes(a)) && - T(e, i, t, o, (0, p.mkResolver)(s)) && + y(e, o, t, i, (0, p.mkResolver)(s)) && (yield n); } })( @@ -2412,17 +2435,12 @@ e.mode, n, ), - a = b(y(r, o)); + a = T(b(r, o)); const s = a.next(); - s.done || - C( - s.value, - Object.assign(Object.assign({}, e), { nextMatches: a }), - t, - ); + ((e.nextMatches = a), s.done || C(s.value, e, t)); } function R(e, t, n, r) { - const o = "descending" === G(e, n.order, r); + const o = "descending" === z(e, n.order, r); return "number" === n.dataType ? (function (e, t, n, r, o) { const a = E(t, e, (e) => { @@ -2440,7 +2458,7 @@ })(e, t, n, r, o) : (function (e, t, n, r, o) { const a = E(t, e, (e) => J(e, n.sortKey, r)), - s = n.lang && G(e, n.lang, r); + s = n.lang && z(e, n.lang, r); let i = new Intl.Collator(s).compare; return (0, p.zip)(a, t) .sort(o ? (e, t) => i(t[0], e[0]) : (e, t) => i(e[0], t[0])) @@ -2449,21 +2467,13 @@ } function E(e, t, n) { if (e.length > 0) - return (0, l.isNodeGroupArray)(e) ? I(e, t, n) : O(e, t, n); + return (0, l.isNodeGroupArray)(e) ? I(e, t, n) : P(e, t, n); } - function O(e, t, n) { + function P(e, t, n) { let r = 0; + const o = Object.assign(Object.assign({}, t), { contextList: e }); return e.map( - (o) => ( - r++, - n( - Object.assign(Object.assign({}, t), { - contextItem: o, - contextList: e, - position: r, - }), - ) - ), + (e) => (r++, (o.contextItem = e), (o.position = r), n(o)), ); } function I(e, t, n) { @@ -2480,18 +2490,18 @@ return n(o); }); } - function P(e, t, n, r) { + function $(e, t, n, r) { if (n) for (let o of [...n].reverse()) t = R(e, t, o, r); return t; } - function $(e, t) { + function O(e, t) { for (let n of t) if (n.name === e) return n; } function C(e, t, n) { let r = D(t.variableScopes); for (let o of e.allowedParams) { - let e = $(o.name, n); - void 0 !== e ? j(r, e.name, B(t, e)) : j(r, o.name, B(t, o)); + let e = O(o.name, n); + void 0 !== e ? L(r, e.name, B(t, e)) : L(r, o.name, B(t, o)); } return e.apply( Object.assign(Object.assign({}, t), { variableScopes: r }), @@ -2526,10 +2536,10 @@ M(`${o}${a}`)(e, null) ); } - function j(e, t, n) { + function L(e, t, n) { e[e.length - 1].set(t, n); } - function L(e) { + function U(e) { let t = {}; for (let n of e) for (let [e, r] of n) t[e] = r; return t; @@ -2544,7 +2554,7 @@ n ); } - function U(e, t) { + function j(e, t) { let n; return ( (n = t.namespace @@ -2594,7 +2604,7 @@ } }; } - function z(e) { + function G(e) { return function (t) { if ( (e.push(t), @@ -2605,9 +2615,9 @@ return k(t); }; } - function G(e, t, n) { + function z(e, t, n) { if (!t) return; - const r = L(e.variableScopes); + const r = U(e.variableScopes); return t .map((t) => "string" == typeof t @@ -2628,9 +2638,9 @@ } function J(e, t, n, r) { r || (r = "string" == typeof t ? [" "] : []); - const o = G(e, r, n); + const o = z(e, r, n); if ("string" == typeof t) { - const r = L(e.variableScopes); + const r = U(e.variableScopes); return (0, i.evaluateXPath)( t, e.contextItem, @@ -2663,7 +2673,7 @@ t.content, e.contextItem, void 0, - L(e.variableScopes), + U(e.variableScopes), i.evaluateXPath.ALL_RESULTS_TYPE, { currentContext: e, @@ -2682,7 +2692,7 @@ return ( t( Object.assign(Object.assign({}, e), { - append: z(n), + append: G(n), mode: "#default", variableScopes: D(e.variableScopes), }), @@ -2729,10 +2739,6 @@ "use strict"; e.exports = require("slimdom"); }, - 16(e) { - "use strict"; - e.exports = require("url"); - }, }, t = {}, n = (function n(r) { @@ -2740,6 +2746,6 @@ if (void 0 !== o) return o.exports; var a = (t[r] = { exports: {} }); return (e[r].call(a.exports, a, a.exports, n), a.exports); - })(571); + })(186); module.exports = n.transform; })(); diff --git a/src/preprocess/stripWhitespace1.js b/src/preprocess/stripWhitespace1.js index 1fe13b5..df265c2 100644 --- a/src/preprocess/stripWhitespace1.js +++ b/src/preprocess/stripWhitespace1.js @@ -1,6 +1,6 @@ (() => { var e = { - 801(e, t, n) { + 457(e, t, n) { (n(898), n(594)); let r = n(821); function o(e, t) { @@ -174,16 +174,16 @@ t.XMLNS_NSURI = t.XSLT1_NSURI = void 0), - (t.isNodeGroup = u), + (t.isNodeGroup = c), (t.isNodeGroupArray = function (e) { - return Array.isArray(e) && (0 === e.length || u(e[0])); + return Array.isArray(e) && (0 === e.length || c(e[0])); })); const r = n(953), o = String.raw`[^,:\(\)\*\[\]/]`, a = String.raw`(child::|attribute::|@)?`, s = String.raw`(document-node\()?`; var i; - function u(e) { + function c(e) { return ( "object" == typeof e && null !== e && @@ -362,56 +362,76 @@ (t.parentNode = d), (t.grandParentNode = f), (t.greatGrandParentNode = g), + (t.greatGreatGrandParentNode = h), + (t.ancestorNodes = N), (t.xpathToFeatures = function (e, t) { if (e) return (function (e, t) { const n = []; try { - return (I(e, n, t), n); + return (C(e, n, t), n); } catch (e) { return; } })( - (0, c.parseScript)( + (0, u.parseScript)( e, - { language: c.evaluateXPath.XPATH_3_1_LANGUAGE }, + { language: u.evaluateXPath.XPATH_3_1_LANGUAGE }, new l.Document(), ), t, ); })); const i = n(953), - u = n(712), - c = n(594), + c = n(712), + u = n(594), l = s(n(898)), p = "http://www.w3.org/2005/XQueryX"; - function m(e) { - return e; + function* m(e) { + yield e; } - function d(e) { - return e.parentNode || void 0; + function* d(e) { + e.parentNode && (yield e.parentNode); } - function f(e) { + function* f(e) { var t; - return ( - (null === (t = e.parentNode) || void 0 === t - ? void 0 - : t.parentNode) || void 0 - ); + const n = + null === (t = e.parentNode) || void 0 === t ? void 0 : t.parentNode; + n && (yield n); } - function g(e) { + function* g(e) { var t, n; - return ( - (null === + const r = + null === (n = null === (t = e.parentNode) || void 0 === t ? void 0 : t.parentNode) || void 0 === n ? void 0 - : n.parentNode) || void 0 - ); + : n.parentNode; + r && (yield r); + } + function* h(e) { + var t, n, r; + const o = + null === + (r = + null === + (n = + null === (t = e.parentNode) || void 0 === t + ? void 0 + : t.parentNode) || void 0 === n + ? void 0 + : n.parentNode) || void 0 === r + ? void 0 + : r.parentNode; + o && (yield o); + } + function* N(e) { + let t = e.parentNode; + for (; t; ) (yield t, (t = t.parentNode)); } - class h extends u.Feature { + class v extends c.Feature { constructor(e, t) { (super(t), (this.nodeExtractor = e)); } @@ -428,214 +448,215 @@ return this.nodeExtractor === e.nodeExtractor && super.equals(e); } } - class N extends h { + function x(e, t) { + for (const n of e) if (t(n)) return !0; + return !1; + } + class w extends v { matches(e) { - var t; - return ( - (null === (t = this.nodeExtractor(e)) || void 0 === t - ? void 0 - : t.nodeType) === l.Node.ELEMENT_NODE && - e.namespaceURI === this.value + return x( + this.nodeExtractor(e), + (e) => + e.nodeType == l.Node.ELEMENT_NODE && + e.namespaceURI === this.value, ); } } - t.NodeNamespaceFeature = N; - class v extends h { + t.NodeNamespaceFeature = w; + class y extends v { matches(e) { - var t; - return ( - (null === (t = this.nodeExtractor(e)) || void 0 === t - ? void 0 - : t.nodeType) === this.value - ); + return x(this.nodeExtractor(e), (e) => e.nodeType === this.value); } } - t.NodeTypeFeature = v; - class x extends h { + t.NodeTypeFeature = y; + class b extends v { matches(e) { - var t; - return ( - (null === (t = this.nodeExtractor(e)) || void 0 === t - ? void 0 - : t.nodeName) === this.value - ); + return x(this.nodeExtractor(e), (e) => e.nodeName === this.value); } } - t.NodeNameFeature = x; - class w extends h { + t.NodeNameFeature = b; + class T extends v { matches(e) { - var t; - return ( - (null === (t = this.nodeExtractor(e)) || void 0 === t - ? void 0 - : t.textContent) === this.value + return x( + this.nodeExtractor(e), + (e) => e.textContent === this.value, ); } } - t.NodeTextFeature = w; - class b extends h { + t.NodeTextFeature = T; + class S extends v { matches(e) { - const t = this.nodeExtractor(e); - return ( - t.nodeType === l.Node.ELEMENT_NODE && - t.getAttribute(this.value.name) === this.value.value + return x( + this.nodeExtractor(e), + (e) => + e.nodeType == l.Node.ELEMENT_NODE && + e.getAttribute(this.value.name) === this.value.value, ); } } - function y(e) { + function R(e) { return ( (function (e) { return 1 === e.nodeType; })(e) && e.namespaceURI === p ); } - function T(e, t) { - return y(e) && e.localName === t; + function E(e, t) { + return R(e) && e.localName === t; } - function S(e, t) { - for (const n of e.childNodes) if (T(n, t)) return n; + function P(e, t) { + for (const n of e.childNodes) if (E(n, t)) return n; } - function R(e, t, n) { + function I(e, t, n) { for (const r of e.childNodes) { - if (!y(r)) continue; - if (T(r, t) && (!n || n(r))) return r; - const e = R(r, t, n); + if (!R(r)) continue; + if (E(r, t) && (!n || n(r))) return r; + const e = I(r, t, n); if (e) return e; } } - t.NodeAttributeFeature = b; - class E extends Error {} - function I(e, t, n) { - if (!y(e)) return; + function $(e) { + var t; + return ( + "descendant-or-self" === + (null === (t = P(e, "xpathAxis")) || void 0 === t + ? void 0 + : t.textContent) && !!P(e, "anyKindTest") + ); + } + t.NodeAttributeFeature = S; + class O extends Error {} + function C(e, t, n) { + if (!R(e)) return; const r = e.localName; if ("module" === r || "mainModule" === r || "queryBody" === r) - for (const r of e.childNodes) I(r, t, n); + for (const r of e.childNodes) C(r, t, n); else { - if ("pathExpr" !== r) throw new E(); + if ("pathExpr" !== r) throw new O(); { - const r = e.childNodes.filter((e) => T(e, "stepExpr")); - if (T(e.firstChild, "rootExpr")) { + const r = e.childNodes.filter((e) => E(e, "stepExpr")); + if (E(e.firstChild, "rootExpr")) { if (0 === r.length) - return void t.push(new v(m, l.Node.DOCUMENT_NODE)); - if ( - "descendant-or-self" !== - (null === (a = S((o = r[0]), "xpathAxis")) || void 0 === a - ? void 0 - : a.textContent) || - !S(o, "anyKindTest") - ) - throw new E(); + return void t.push(new y(m, l.Node.DOCUMENT_NODE)); + if (!$(r[0])) throw new O(); r.shift(); } - if (0 === r.length) throw new E(); - const s = r.reverse(); - if (0 == s.length || s.length > 4) throw new E(); - (P(m, s[0], t, n), - s[1] && P(d, s[1], t, n), - s[2] && P(f, s[2], t, n), - s[3] && P(g, s[3], t, n)); + if (0 === r.length) throw new O(); + const o = r.reverse(); + if (0 == o.length) throw new O(); + const a = [m, d, f, g, h]; + let s = 0, + i = !1; + for (const e of o) { + if ($(e)) { + i = !0; + continue; + } + const r = i ? N : a[s++]; + if (!r) throw new O(); + M(r, e, t, n); + } } } - var o, a; } - function O(e, t, n) { + function D(e, t, n) { "attribute" === t - ? n.push(new v(e, l.Node.ATTRIBUTE_NODE)) - : n.push(new v(e, l.Node.ELEMENT_NODE)); + ? n.push(new y(e, l.Node.ATTRIBUTE_NODE)) + : n.push(new y(e, l.Node.ELEMENT_NODE)); } - function P(e, t, n, r) { + function M(e, t, n, r) { var o, a; const s = - null === (o = S(t, "xpathAxis")) || void 0 === o + null === (o = P(t, "xpathAxis")) || void 0 === o ? void 0 : o.textContent; if ("child" !== s && "attribute" !== s) - throw new E(`unsupported axis: ${s}`); + throw new O(`unsupported axis: ${s}`); for (const o of t.childNodes.slice(1)) { - if (!y(o)) continue; + if (!R(o)) continue; const i = o.localName; - if ("nameTest" === i) ($(e, t, n, r), O(e, s, n)); + if ("nameTest" === i) (X(e, t, n, r), D(e, s, n)); else if ("Wildcard" === i) { - const t = S(o, "NCName"); + const t = P(o, "NCName"); if (t) { const o = null == r ? void 0 : r(null !== (a = t.textContent) && void 0 !== a ? a : ""); - if (!o) throw new E(`unresolved ns prefix: ${o}`); - n.push(new N(e, o)); + if (!o) throw new O(`unresolved ns prefix: ${o}`); + n.push(new w(e, o)); } - O(e, s, n); + D(e, s, n); } else if ("piTest" === i) { - n.push(new v(e, l.Node.PROCESSING_INSTRUCTION_NODE)); - const t = S(o, "piTarget"); + n.push(new y(e, l.Node.PROCESSING_INSTRUCTION_NODE)); + const t = P(o, "piTarget"); (null == t ? void 0 : t.textContent) && - n.push(new x(e, t.textContent)); + n.push(new b(e, t.textContent)); } else if ("commentTest" === i) - n.push(new v(e, l.Node.COMMENT_NODE)); - else if ("textTest" === i) n.push(new v(e, l.Node.TEXT_NODE)); + n.push(new y(e, l.Node.COMMENT_NODE)); + else if ("textTest" === i) n.push(new y(e, l.Node.TEXT_NODE)); else { - if ("predicates" !== i) throw new E(); - C(e, o, n, r); + if ("predicates" !== i) throw new O(); + _(e, o, n, r); } } } - function $(e, t, n, r) { - const o = S(t, "nameTest"); - if (!o) throw new E(); + function X(e, t, n, r) { + const o = P(t, "nameTest"); + if (!o) throw new O(); const a = o.textContent; - a && n.push(new x(e, a)); + a && n.push(new b(e, a)); const s = o.getAttributeNS(p, "prefix"); if (s) { const t = null == r ? void 0 : r(s); - if (!t) throw new E(`unresolved ns prefix: ${t}`); - n.push(new N(e, t)); + if (!t) throw new O(`unresolved ns prefix: ${t}`); + n.push(new w(e, t)); } const i = o.getAttributeNS(p, "URI"); - i && n.push(new N(e, i)); + i && n.push(new w(e, i)); } - function C(e, t, n, r) { + function _(e, t, n, r) { for (const o of t.childNodes) { - if (!y(o)) throw new E(); + if (!R(o)) throw new O(); const t = o.localName; if ("equalOp" === t) { - const t = S(o, "firstOperand"), - r = S(o, "secondOperand"); - if (!t || !r) throw new E(); - const a = D(e, t, r) || D(e, r, t); - if (!a) throw new E(); + const t = P(o, "firstOperand"), + r = P(o, "secondOperand"); + if (!t || !r) throw new O(); + const a = U(e, t, r) || U(e, r, t); + if (!a) throw new O(); n.push(a); } else { - if ("andOp" !== t) throw new E(); - (C(e, S(o, "firstOperand"), n, r), - C(e, S(o, "secondOperand"), n, r)); + if ("andOp" !== t) throw new O(); + (_(e, P(o, "firstOperand"), n, r), + _(e, P(o, "secondOperand"), n, r)); } } } - function D(e, t, n) { + function U(e, t, n) { var r, o; - const a = R(n, "value"); + const a = I(n, "value"); if (!a) return; const s = null !== (r = a.textContent) && void 0 !== r ? r : "", - i = R(t, "stepExpr", (e) => { + i = I(t, "stepExpr", (e) => { var t; return ( "attribute" === - (null === (t = S(e, "xpathAxis")) || void 0 === t + (null === (t = P(e, "xpathAxis")) || void 0 === t ? void 0 : t.textContent) ); }); if (i) { const t = - null === (o = S(i, "nameTest")) || void 0 === o + null === (o = P(i, "nameTest")) || void 0 === o ? void 0 : o.textContent; if (!t) return; - return new b(e, { name: t, value: s }); + return new S(e, { name: t, value: s }); } - return S(t, "contextItemExpr") || R(t, "textTest") - ? new w(e, s) + return P(t, "contextItemExpr") || I(t, "textTest") + ? new T(e, s) : void 0; } }, @@ -733,14 +754,14 @@ function i(e) { return { type: "ArrayExpression", elements: e }; } - function u(e, t, n) { + function c(e, t, n) { return { type: "VariableDeclaration", declarations: [{ type: "VariableDeclarator", id: e, init: t }], kind: n, }; } - function c(e, t) { + function u(e, t) { return { type: "NewExpression", callee: e, arguments: t }; } (Object.defineProperty(t, "__esModule", { value: !0 }), @@ -821,13 +842,13 @@ return { type: "BlockStatement", body: e }; }), (t.mkLet = function (e, t) { - return u(e, t, "let"); + return c(e, t, "let"); }), (t.mkConst = function (e, t) { - return u(e, t, "const"); + return c(e, t, "const"); }), - (t.mkVariableDeclaration = u), - (t.mkNew = c), + (t.mkVariableDeclaration = c), + (t.mkNew = u), (t.toEstree = function e(t) { const n = typeof t; return null == t || @@ -843,7 +864,7 @@ ? a("xjslt", t.name) : "object" === n ? t instanceof Map - ? c(r("Map"), [e(Array.from(t.entries()))]) + ? u(r("Map"), [e(Array.from(t.entries()))]) : "type" in t ? t : (function (t) { @@ -869,7 +890,7 @@ 379(e, t, n) { "use strict"; (Object.defineProperty(t, "__esModule", { value: !0 }), - (t.functionNameResolver = y), + (t.functionNameResolver = b), (t.registerFunctions = function () { ((0, r.registerCustomXPathFunction)( { namespaceURI: o.XJSLT_NSURI, localName: "current" }, @@ -890,7 +911,7 @@ { namespaceURI: o.XJSLT_NSURI, localName: "doc" }, ["xs:string"], "document-node()", - u, + c, ), (0, r.registerCustomXPathFunction)( { @@ -899,7 +920,7 @@ }, [], "xs:string?", - c, + u, ), (0, r.registerCustomXPathFunction)( { namespaceURI: o.XJSLT_NSURI, localName: "current-group" }, @@ -957,7 +978,7 @@ r.evaluateXPath.ALL_RESULTS_TYPE, { currentContext: { currentContext: e }, - functionNameResolver: y, + functionNameResolver: b, }, ); return 1 === n.length ? n[0] : n; @@ -1001,10 +1022,10 @@ function i({ currentContext: e }) { return e.contextItem; } - function u({ currentContext: e }, t) { + function c({ currentContext: e }, t) { return (0, s.urlToDom)(e, t); } - function c({ currentContext: e }) { + function u({ currentContext: e }) { return e.currentGroup.key; } function l({ currentContext: e }) { @@ -1108,18 +1129,18 @@ } function w({ currentContext: e }, t, n, r) { var s, i; - const u = r || "#default", - c = + const c = r || "#default", + u = null !== (i = null === (s = e.decimalFormats) || void 0 === s ? void 0 - : s.get(u)) && void 0 !== i + : s.get(c)) && void 0 !== i ? i : o.DEFAULT_DECIMAL_FORMAT; - return (0, a.formatNumberWithPicture)(t, n, c); + return (0, a.formatNumberWithPicture)(t, n, u); } - const b = [ + const y = [ "base-uri", "current", "current-group", @@ -1134,8 +1155,8 @@ "positionx", "system-property", ]; - function y({ prefix: e, localName: t }, n) { - return (e && "fn" !== e) || !b.includes(t) + function b({ prefix: e, localName: t }, n) { + return (e && "fn" !== e) || !y.includes(t) ? null : { namespaceURI: o.XJSLT_NSURI, localName: t }; } @@ -1146,8 +1167,8 @@ (t.toAlphabeticUpper = t.toAlphabetic = void 0), (t.groupNumeric = s), (t.toNumeric = i), - (t.mkToAlphabetic = u), - (t.toRoman = c), + (t.mkToAlphabetic = c), + (t.toRoman = u), (t.formatWithToken = l), (t.formatNumber = function (e, t, n, r) { const o = []; @@ -1166,20 +1187,20 @@ if (isNaN(e)) return n.nan; if (!isFinite(e)) return (e < 0 ? n.minusSign : "") + n.infinity; const a = t.split(n.patternSeparator); - let u; + let c; if (e < 0) - if (a.length > 1) u = p(a[1], n); + if (a.length > 1) c = p(a[1], n); else { const e = p(a[0], n); - u = Object.assign(Object.assign({}, e), { + c = Object.assign(Object.assign({}, e), { prefix: `${n.minusSign}${e.prefix || ""}`, }); } - else u = p(a[0], n); + else c = p(a[0], n); return (function (e, t, n) { var a; t.isPercent ? (e *= 100) : t.isPerMille && (e *= 1e3); - const u = (0, r.evaluateXPathToNumber)( + const c = (0, r.evaluateXPathToNumber)( "round-half-to-even($number, $precision)", void 0, void 0, @@ -1188,23 +1209,23 @@ precision: (0, o.wrapValue)(t.decimalMaxDigits, "xs:integer"), }, ); - let c = s( - i(Math.trunc(u), t.integerMinDigits), + let u = s( + i(Math.trunc(c), t.integerMinDigits), n.groupingSeparator, t.integerGroupSize, ), l = - null !== (a = u.toString().split(".")[1]) && void 0 !== a + null !== (a = c.toString().split(".")[1]) && void 0 !== a ? a : ""; for (; l.length < t.decimalMinDigits; ) l += "0"; const p = l.length > 0 ? n.decimalSeparator : "", d = n.zeroDigit.codePointAt(0); return ( - 48 !== d && ((c = m(c, d)), (l = m(l, d))), - `${t.prefix}${c}${p}${l}${t.suffix}` + 48 !== d && ((u = m(u, d)), (l = m(l, d))), + `${t.prefix}${u}${p}${l}${t.suffix}` ); - })(Math.abs(e), u, n); + })(Math.abs(e), c, n); })); const r = n(594), o = n(821), @@ -1227,7 +1248,7 @@ function i(e, t) { return e.toString().padStart(t, "0"); } - function u(e, t) { + function c(e, t) { const n = t - e + 1, r = [...Array(n)].map((t, n) => String.fromCodePoint(e + n)); return function (e) { @@ -1238,7 +1259,7 @@ return t; }; } - function c(e) { + function u(e) { const t = new Map([ [1e3, "m"], [900, "cm"], @@ -1265,8 +1286,8 @@ if (/0*1/.test(n)) return s(i(e, n.length), r, o); if ("A" === n) return (0, t.toAlphabeticUpper)(e) || ""; if ("a" === n) return (0, t.toAlphabetic)(e) || ""; - if ("I" === n) return c(e).toUpperCase(); - if ("i" === n) return c(e); + if ("I" === n) return u(e).toUpperCase(); + if ("i" === n) return u(e); for (const t of a) { if (49 === t) continue; const a = t - 1; @@ -1286,9 +1307,9 @@ a = t.groupingSeparator; let s = 0, i = !1, - u = !1; - function c() { - if (i || u) + c = !1; + function u() { + if (i || c) throw new Error( "XTDE1310: Multiple percent/per-mille characters.", ); @@ -1296,8 +1317,8 @@ function l() { let a = ""; for (; s < e.length && e[s] !== n && e[s] !== r && e[s] !== o; ) - (e[s] === t.percent && (c(), (i = !0)), - e[s] === t.perMille && (c(), (u = !0)), + (e[s] === t.percent && (u(), (i = !0)), + e[s] === t.perMille && (u(), (c = !0)), (a += e[s++])); return a; } @@ -1342,7 +1363,7 @@ decimalMinDigits: h, decimalMaxDigits: N, isPercent: i, - isPerMille: u, + isPerMille: c, }; } function m(e, t) { @@ -1353,7 +1374,7 @@ }) .join(""); } - ((t.toAlphabetic = u(97, 122)), (t.toAlphabeticUpper = u(65, 90))); + ((t.toAlphabetic = c(97, 122)), (t.toAlphabeticUpper = c(65, 90))); }, 777(e, t) { "use strict"; @@ -1406,9 +1427,9 @@ for (let [e, n] of i) if (e.test(t)) return n; return 0.5; }), - (t.compareSortable = u), + (t.compareSortable = c), (t.sortSortable = function (e) { - return e.sort(u); + return e.sort(c); }), (t.zip = function (e, t) { if (void 0 === e || void 0 === t) return []; @@ -1471,7 +1492,7 @@ [new RegExp(String.raw`^\s*${a}\*:${o}+\s*$`), -0.25], [new RegExp(String.raw`^\s*${a}${o}+\s*$`), 0], ]); - function u(e, t) { + function c(e, t) { const n = e.importPrecedence - t.importPrecedence; if (0 !== n) return n; { @@ -1480,15 +1501,15 @@ } } }, - 472(e, t, n) { + 472(e, t) { "use strict"; (Object.defineProperty(t, "__esModule", { value: !0 }), (t.urlToDom = function (e, t) { - if (!e.readDocument) return; - const n = e.inputURL ? (0, r.resolve)(e.inputURL.toString(), t) : t; + const n = e.inputURL + ? new URL(t, e.inputURL.toString()).toString() + : t; return e.readDocument(n); })); - const r = n(16); }, 821(e, t, n) { "use strict"; @@ -1557,25 +1578,22 @@ t.NodeNamespaceFeature = t.NodeAttributeFeature = t.selfNode = + t.greatGreatGrandParentNode = t.greatGrandParentNode = t.grandParentNode = t.parentNode = + t.ancestorNodes = t.KeyImpl = void 0), (t.visitNodes = g), - (t.dedupGenerator = y), + (t.dedupGenerator = b), (t.mergeTemplateGenerators = T), (t.processNode = S), (t.nextMatch = function (e, t) { const n = e.nextMatches; if (n) { const r = n.next(); - r.done || - C( - r.value, - Object.assign(Object.assign({}, e), { nextMatches: n }), - t.params, - ); + r.done || ((e.nextMatches = n), C(r.value, e, t.params)); } }), (t.applyImports = function (e, t) { @@ -1583,15 +1601,10 @@ if (n) { let r = n.next(); for (; !r.done && 1 === r.value.importPrecedence; ) r = n.next(); - r.done || - C( - r.value, - Object.assign(Object.assign({}, e), { nextMatches: n }), - t.params, - ); + r.done || ((e.nextMatches = n), C(r.value, e, t.params)); } }), - (t.sort = P), + (t.sort = $), (t.applyTemplates = function (e, t) { const n = (0, p.mkResolver)(t.namespaces), r = (0, i.evaluateXPathToNodes)( @@ -1602,21 +1615,20 @@ { currentContext: e, namespaceResolver: n, - functionNameResolver: c.functionNameResolver, + functionNameResolver: u.functionNameResolver, }, ); let o = t.mode || "#default"; ("#current" === o && (o = e.mode), - I(P(e, r, t.sortKeyComponents, n), e, (e) => { - S( - Object.assign(Object.assign({}, e), { - mode: o, - variableScopes: D(e.variableScopes), - }), - t.params, - t.namespaces, - ); - })); + P( + $(e, r, t.sortKeyComponents, n), + Object.assign(Object.assign({}, e), { mode: o }), + (e) => { + ((e.variableScopes = D(e.variableScopes)), + S(e, t.params, t.namespaces), + e.variableScopes.pop()); + }, + )); }), (t.callTemplate = function (e, t) { const n = e.namedTemplates.get(t.name); @@ -1685,7 +1697,7 @@ { currentContext: e, namespaceResolver: (0, p.mkResolver)(t.namespaces), - functionNameResolver: c.functionNameResolver, + functionNameResolver: u.functionNameResolver, }, ); for (let t of n) e.append(t); @@ -1704,14 +1716,14 @@ e.append(J(e, n, (0, p.mkResolver)(t.namespaces), [""])); }), (t.variable = function (e, t) { - j(e.variableScopes, t.name, B(e, t)); + U(e.variableScopes, t.name, B(e, t)); }), (t.param = function (e, t) { - j(e.variableScopes, t.name, e.stylesheetParams[t.name] || B(e, t)); + U(e.variableScopes, t.name, e.stylesheetParams[t.name] || B(e, t)); }), (t.extendScope = D), (t.wrapValue = _), - (t.setVariable = j), + (t.setVariable = U), (t.mergeVariableScopes = A), (t.literalText = function (e, t) { e.append(t); @@ -1726,18 +1738,18 @@ { currentContext: e, namespaceResolver: (0, p.mkResolver)(t.namespaces), - functionNameResolver: c.functionNameResolver, + functionNameResolver: u.functionNameResolver, }, ); e.append(n); }), - (t.buildNode = U), + (t.buildNode = j), (t.buildAttributeNode = L), (t.literalElement = function (e, t, n) { - let r = U(e, { name: t.name, namespace: t.namespace }); + let r = j(e, { name: t.name, namespace: t.namespace }); const o = (0, p.mkResolver)(t.namespaces); for (let n of t.attributes) { - const t = G(e, n.value, o), + const t = z(e, n.value, o), a = L(e, { name: n.name, namespace: n.namespace, value: t }); r.setAttributeNode(a); } @@ -1751,20 +1763,20 @@ }), (t.attribute = function (e, t, n) { const r = (0, p.mkResolver)(t.namespaces), - o = G(e, t.name, r), - a = G(e, t.namespace, r), + o = z(e, t.name, r), + a = z(e, t.namespace, r), [s, i] = o.includes(":") ? (0, p.determineNamespace)(o, r, a) : [a, o], - u = L(e, { + c = L(e, { name: o, namespace: s, value: J(e, t.select || n, r, t.separator), }); - e.append(u); + e.append(c); }), (t.processingInstruction = function (e, t, n) { - const r = G(e, t.name, (0, p.mkResolver)(t.namespaces)), + const r = z(e, t.name, (0, p.mkResolver)(t.namespaces)), o = J(e, t.select || n, (0, p.mkResolver)(t.namespaces), [ "", ]).trimStart(); @@ -1778,7 +1790,7 @@ }), (t.namespace = function (e, t, n) { const r = (0, p.mkResolver)(t.namespaces), - o = G(e, t.name, r), + o = z(e, t.name, r), a = J(e, t.select || n, r, [""]), s = L(e, { name: `xmlns:${o}`, @@ -1789,9 +1801,9 @@ }), (t.element = function (e, t, n) { const r = (0, p.mkResolver)(t.namespaces); - let o = G(e, t.name, r), - a = G(e, t.namespace, r), - s = U(e, { + let o = z(e, t.name, r), + a = z(e, t.namespace, r), + s = j(e, { name: o, namespace: (0, p.determineNamespace)( o, @@ -1816,7 +1828,7 @@ { currentContext: e, namespaceResolver: (0, p.mkResolver)(t.namespaces), - functionNameResolver: c.functionNameResolver, + functionNameResolver: u.functionNameResolver, }, ) && n(e); }), @@ -1831,7 +1843,7 @@ A(e.variableScopes), { currentContext: e, - functionNameResolver: c.functionNameResolver, + functionNameResolver: u.functionNameResolver, }, ) ) @@ -1865,11 +1877,11 @@ { currentContext: e, namespaceResolver: n, - functionNameResolver: c.functionNameResolver, + functionNameResolver: u.functionNameResolver, }, ); if (r && Symbol.iterator in Object(r)) { - const o = P(e, r, t.sortKeyComponents, n); + const o = $(e, r, t.sortKeyComponents, n); for (let t of o) e.append(t); } }), @@ -1884,18 +1896,16 @@ { currentContext: e, namespaceResolver: r, - functionNameResolver: c.functionNameResolver, + functionNameResolver: u.functionNameResolver, }, ); o && Symbol.iterator in Object(o) && - ((o = P(e, o, t.sortKeyComponents, r)), - I(o, e, (e) => { - n( - Object.assign(Object.assign({}, e), { - variableScopes: D(e.variableScopes), - }), - ); + ((o = $(e, o, t.sortKeyComponents, r)), + P(o, e, (e) => { + ((e.variableScopes = D(e.variableScopes)), + n(e), + e.variableScopes.pop()); })); }), (t.forEachGroup = function (e, t, n) { @@ -1909,7 +1919,7 @@ { currentContext: e, namespaceResolver: r, - functionNameResolver: c.functionNameResolver, + functionNameResolver: u.functionNameResolver, }, ); if (a && Symbol.iterator in Object(a)) { @@ -1919,7 +1929,7 @@ const o = A(e.variableScopes); let a = []; return ( - I(t, e, (e) => { + P(t, e, (e) => { const t = (0, i.evaluateXPathToString)( n, e.contextItem, @@ -1928,7 +1938,7 @@ { currentContext: e, namespaceResolver: r, - functionNameResolver: c.functionNameResolver, + functionNameResolver: u.functionNameResolver, }, ); let s = a.find((e) => e.key === t); @@ -1943,20 +1953,20 @@ const o = A(e.variableScopes); let a = [], s = null, - u = []; + c = []; return ( - I(t, e, (e) => { + P(t, e, (e) => { const t = e.contextItem, l = (0, i.evaluateXPathToString)(n, t, void 0, o, { currentContext: e, namespaceResolver: r, - functionNameResolver: c.functionNameResolver, + functionNameResolver: u.functionNameResolver, }); l !== s - ? (F(a, u, s), (s = l), (u = [t])) - : u.push(t); + ? (F(a, c, s), (s = l), (c = [t])) + : c.push(t); }), - F(a, u, s), + F(a, c, s), a ); })(e, a, t.groupAdjacent, r)) @@ -1965,14 +1975,14 @@ let o = [], a = []; return ( - I(t, e, (e) => { + P(t, e, (e) => { const t = e.contextItem; (a.push(t), - b( + y( e.patternMatchCache, n, t, - e.variableScopes, + A(e.variableScopes), r, ) && (F(o, a), (a = []))); }), @@ -1985,13 +1995,13 @@ let o = [], a = []; return ( - I(t, e, (e) => { + P(t, e, (e) => { const t = e.contextItem; - (b( + (y( e.patternMatchCache, n, t, - e.variableScopes, + A(e.variableScopes), r, ) && (F(o, a), (a = [])), a.push(t)); @@ -2000,8 +2010,8 @@ o ); })(e, a, t.groupStartingWith, r)), - (o = P(e, o, t.sortKeyComponents, r)), - O(o, e, n)); + (o = $(e, o, t.sortKeyComponents, r)), + I(o, e, n)); } }), (t.number = function (e, t) { @@ -2017,7 +2027,7 @@ { currentContext: e, namespaceResolver: n, - functionNameResolver: c.functionNameResolver, + functionNameResolver: u.functionNameResolver, }, )) : "single" === t.level && @@ -2035,11 +2045,11 @@ )); }), (t.mkNodeAppender = k), - (t.mkArrayAppender = z), + (t.mkArrayAppender = G), (t.resultDocument = function (e, t, n) { const r = (0, p.mkResolver)(t.namespaces); function o(t) { - return G(e, t, r); + return z(e, t, r); } const a = o(t.format); let s = (0, p.mkOutputDefinition)({ @@ -2055,26 +2065,26 @@ Object.assign({}, a ? e.outputDefinitions.get(a) : {}), s, ), - u = o(t.href); - let c = null; + c = o(t.href); + let u = null; if ( ((i.doctypePublic || i.doctypeSystem) && - (c = e.outputDocument.implementation.createDocumentType( + (u = e.outputDocument.implementation.createDocumentType( "out", i.doctypePublic || "", i.doctypeSystem || "", )), - u) + c) ) { const t = e.outputDocument.implementation.createDocument( null, null, - c, + u, ); - if (e.resultDocuments.has(u)) - throw new Error(`XTDE1490: ${u} is a duplicate`); + if (e.resultDocuments.has(c)) + throw new Error(`XTDE1490: ${c} is a duplicate`); (e.resultDocuments.set( - u, + c, Object.assign(Object.assign({}, i), { document: t }), ), n( @@ -2086,11 +2096,11 @@ } else { if (e.outputDocument.documentElement) throw new Error("XTDE1490"); let t = e.outputDocument; - (c && + (u && ((t = e.outputDocument.implementation.createDocument( null, null, - c, + u, )), (e.outputDocument = t), (e.append = k(t))), @@ -2111,7 +2121,7 @@ let n = new Map(); for (const r of t) { const t = (0, p.mkResolver)(r.namespaces); - if (b(n, r.match, e, [], t)) return !r.preserve; + if (y(n, r.match, e, [], t)) return !r.preserve; } return !1; })(o.parentNode, t) && @@ -2122,9 +2132,9 @@ for (let e of r) e.remove(); return e; }), - (t.evaluateAttributeValueTemplate = G), + (t.evaluateAttributeValueTemplate = z), (t.serialize = function (e) { - const t = new u.XMLSerializer(); + const t = new c.XMLSerializer(); if (!0 !== e.omitXmlDeclaration) { let t = new Map([ ["version", "1.0"], @@ -2166,8 +2176,8 @@ }), (t.initialize = function (e, t) {})); const i = n(594), - u = s(n(898)), - c = n(379), + c = s(n(898)), + u = n(379), l = n(712), p = n(777), m = n(845), @@ -2183,12 +2193,24 @@ ? e.textContent : e.toString(); } - (Object.defineProperty(t, "greatGrandParentNode", { + (Object.defineProperty(t, "ancestorNodes", { enumerable: !0, get: function () { - return f.greatGrandParentNode; + return f.ancestorNodes; }, }), + Object.defineProperty(t, "greatGrandParentNode", { + enumerable: !0, + get: function () { + return f.greatGrandParentNode; + }, + }), + Object.defineProperty(t, "greatGreatGrandParentNode", { + enumerable: !0, + get: function () { + return f.greatGreatGrandParentNode; + }, + }), Object.defineProperty(t, "grandParentNode", { enumerable: !0, get: function () { @@ -2246,15 +2268,16 @@ } buildDocumentCache(e, t, n) { let r = new Map(); + const o = A(n); return ( g(t, (t) => { if ( "string" == typeof this.use && - b( + y( e, { xpath: this.match }, t, - n, + o, (0, p.mkResolver)(this.namespaces), ) ) { @@ -2277,7 +2300,7 @@ v = new RegExp(/^@[a-z]+$/), x = new RegExp(/text\(\)|node\(\)/), w = new RegExp(/@|attribute|node/); - function b(e, t, n, r, o) { + function y(e, t, n, r, o) { return !( (n && (function (e, t) { @@ -2293,16 +2316,15 @@ let a = e.get(t.xpath); a || ((a = new Map()), e.set(t.xpath, a)); let s = n; - const u = A(r); for (; s; ) { let e = a.get(s); if ( (void 0 === e && ((e = t.compiled ? (0, i.executeJavaScriptCompiledXPath)(t.compiled, s) - : (0, i.evaluateXPathToNodes)(t.xpath, s, void 0, u, { + : (0, i.evaluateXPathToNodes)(t.xpath, s, void 0, r, { namespaceResolver: o, - functionNameResolver: c.functionNameResolver, + functionNameResolver: u.functionNameResolver, })), a.set(s, e)), -1 !== e.indexOf(n)) @@ -2315,7 +2337,7 @@ })(e, t, n, r, o) ); } - function* y(e) { + function* b(e) { let t = new Set(), n = e.next(); for (; !n.done; ) @@ -2337,11 +2359,12 @@ ("#all" === e.modes[0] || e.modes.includes(r)) && (yield e); })(e.contextItem, e.ruleTree, e.templates, e.mode), o = (function* (e, t, n, r, o, a, s) { - for (let [i, u] of n) { - const n = r[u]; - i && + const i = A(o); + for (let [o, c] of n) { + const n = r[c]; + o && ("#all" === n.modes[0] || n.modes.includes(a)) && - b(e, i, t, o, (0, p.mkResolver)(s)) && + y(e, o, t, i, (0, p.mkResolver)(s)) && (yield n); } })( @@ -2353,17 +2376,12 @@ e.mode, n, ), - a = y(T(r, o)); + a = b(T(r, o)); const s = a.next(); - s.done || - C( - s.value, - Object.assign(Object.assign({}, e), { nextMatches: a }), - t, - ); + ((e.nextMatches = a), s.done || C(s.value, e, t)); } function R(e, t, n, r) { - const o = "descending" === G(e, n.order, r); + const o = "descending" === z(e, n.order, r); return "number" === n.dataType ? (function (e, t, n, r, o) { const a = E(t, e, (e) => { @@ -2381,7 +2399,7 @@ })(e, t, n, r, o) : (function (e, t, n, r, o) { const a = E(t, e, (e) => J(e, n.sortKey, r)), - s = n.lang && G(e, n.lang, r); + s = n.lang && z(e, n.lang, r); let i = new Intl.Collator(s).compare; return (0, p.zip)(a, t) .sort(o ? (e, t) => i(t[0], e[0]) : (e, t) => i(e[0], t[0])) @@ -2390,24 +2408,16 @@ } function E(e, t, n) { if (e.length > 0) - return (0, l.isNodeGroupArray)(e) ? O(e, t, n) : I(e, t, n); + return (0, l.isNodeGroupArray)(e) ? I(e, t, n) : P(e, t, n); } - function I(e, t, n) { + function P(e, t, n) { let r = 0; + const o = Object.assign(Object.assign({}, t), { contextList: e }); return e.map( - (o) => ( - r++, - n( - Object.assign(Object.assign({}, t), { - contextItem: o, - contextList: e, - position: r, - }), - ) - ), + (e) => (r++, (o.contextItem = e), (o.position = r), n(o)), ); } - function O(e, t, n) { + function I(e, t, n) { let r = 0; return e.map((e) => { r++; @@ -2421,18 +2431,18 @@ return n(o); }); } - function P(e, t, n, r) { + function $(e, t, n, r) { if (n) for (let o of [...n].reverse()) t = R(e, t, o, r); return t; } - function $(e, t) { + function O(e, t) { for (let n of t) if (n.name === e) return n; } function C(e, t, n) { let r = D(t.variableScopes); for (let o of e.allowedParams) { - let e = $(o.name, n); - void 0 !== e ? j(r, e.name, B(t, e)) : j(r, o.name, B(t, o)); + let e = O(o.name, n); + void 0 !== e ? U(r, e.name, B(t, e)) : U(r, o.name, B(t, o)); } return e.apply( Object.assign(Object.assign({}, t), { variableScopes: r }), @@ -2467,7 +2477,7 @@ X(`${o}${a}`)(e, null) ); } - function j(e, t, n) { + function U(e, t, n) { e[e.length - 1].set(t, n); } function A(e) { @@ -2475,7 +2485,7 @@ for (let n of e) for (let [e, r] of n) t[e] = r; return t; } - function U(e, t) { + function j(e, t) { let n; return ( (n = @@ -2535,7 +2545,7 @@ } }; } - function z(e) { + function G(e) { return function (t) { if ( (e.push(t), @@ -2546,7 +2556,7 @@ return k(t); }; } - function G(e, t, n) { + function z(e, t, n) { if (!t) return; const r = A(e.variableScopes); return t @@ -2561,7 +2571,7 @@ { currentContext: e, namespaceResolver: n, - functionNameResolver: c.functionNameResolver, + functionNameResolver: u.functionNameResolver, }, ), ) @@ -2569,7 +2579,7 @@ } function J(e, t, n, r) { r || (r = "string" == typeof t ? [" "] : []); - const o = G(e, r, n); + const o = z(e, r, n); if ("string" == typeof t) { const r = A(e.variableScopes); return (0, i.evaluateXPath)( @@ -2581,7 +2591,7 @@ { currentContext: e, namespaceResolver: n, - functionNameResolver: c.functionNameResolver, + functionNameResolver: u.functionNameResolver, }, ).join(o); } @@ -2609,7 +2619,7 @@ { currentContext: e, namespaceResolver: (0, p.mkResolver)(t.namespaces), - functionNameResolver: c.functionNameResolver, + functionNameResolver: u.functionNameResolver, }, ); return (1 !== r.length || n || (r = r[0]), _(r, t.as)); @@ -2623,7 +2633,7 @@ return ( t( Object.assign(Object.assign({}, e), { - append: z(n), + append: G(n), mode: "#default", variableScopes: D(e.variableScopes), }), @@ -2660,7 +2670,7 @@ ); }); } - (0, c.registerFunctions)(); + (0, u.registerFunctions)(); }, 594(e) { "use strict"; @@ -2670,10 +2680,6 @@ "use strict"; e.exports = require("slimdom"); }, - 16(e) { - "use strict"; - e.exports = require("url"); - }, }, t = {}, n = (function n(r) { @@ -2681,6 +2687,6 @@ if (void 0 !== o) return o.exports; var a = (t[r] = { exports: {} }); return (e[r].call(a.exports, a, a.exports, n), a.exports); - })(801); + })(457); module.exports = n.transform; })(); diff --git a/src/preprocess/stripWhitespace2.js b/src/preprocess/stripWhitespace2.js index b077956..943b8d6 100644 --- a/src/preprocess/stripWhitespace2.js +++ b/src/preprocess/stripWhitespace2.js @@ -1,6 +1,6 @@ (() => { var e = { - 524(e, t, n) { + 347(e, t, n) { (n(898), n(594)); let r = n(821); function o(e, t) { @@ -452,12 +452,14 @@ (t.parentNode = d), (t.grandParentNode = f), (t.greatGrandParentNode = g), + (t.greatGreatGrandParentNode = h), + (t.ancestorNodes = N), (t.xpathToFeatures = function (e, t) { if (e) return (function (e, t) { const n = []; try { - return ($(e, n, t), n); + return (C(e, n, t), n); } catch (e) { return; } @@ -475,33 +477,51 @@ u = n(594), l = s(n(898)), p = "http://www.w3.org/2005/XQueryX"; - function m(e) { - return e; + function* m(e) { + yield e; } - function d(e) { - return e.parentNode || void 0; + function* d(e) { + e.parentNode && (yield e.parentNode); } - function f(e) { + function* f(e) { var t; - return ( - (null === (t = e.parentNode) || void 0 === t - ? void 0 - : t.parentNode) || void 0 - ); + const n = + null === (t = e.parentNode) || void 0 === t ? void 0 : t.parentNode; + n && (yield n); } - function g(e) { + function* g(e) { var t, n; - return ( - (null === + const r = + null === (n = null === (t = e.parentNode) || void 0 === t ? void 0 : t.parentNode) || void 0 === n ? void 0 - : n.parentNode) || void 0 - ); + : n.parentNode; + r && (yield r); + } + function* h(e) { + var t, n, r; + const o = + null === + (r = + null === + (n = + null === (t = e.parentNode) || void 0 === t + ? void 0 + : t.parentNode) || void 0 === n + ? void 0 + : n.parentNode) || void 0 === r + ? void 0 + : r.parentNode; + o && (yield o); + } + function* N(e) { + let t = e.parentNode; + for (; t; ) (yield t, (t = t.parentNode)); } - class h extends c.Feature { + class v extends c.Feature { constructor(e, t) { (super(t), (this.nodeExtractor = e)); } @@ -518,214 +538,215 @@ return this.nodeExtractor === e.nodeExtractor && super.equals(e); } } - class v extends h { + function x(e, t) { + for (const n of e) if (t(n)) return !0; + return !1; + } + class w extends v { matches(e) { - var t; - return ( - (null === (t = this.nodeExtractor(e)) || void 0 === t - ? void 0 - : t.nodeType) === l.Node.ELEMENT_NODE && - e.namespaceURI === this.value + return x( + this.nodeExtractor(e), + (e) => + e.nodeType == l.Node.ELEMENT_NODE && + e.namespaceURI === this.value, ); } } - t.NodeNamespaceFeature = v; - class N extends h { + t.NodeNamespaceFeature = w; + class y extends v { matches(e) { - var t; - return ( - (null === (t = this.nodeExtractor(e)) || void 0 === t - ? void 0 - : t.nodeType) === this.value - ); + return x(this.nodeExtractor(e), (e) => e.nodeType === this.value); } } - t.NodeTypeFeature = N; - class x extends h { + t.NodeTypeFeature = y; + class T extends v { matches(e) { - var t; - return ( - (null === (t = this.nodeExtractor(e)) || void 0 === t - ? void 0 - : t.nodeName) === this.value - ); + return x(this.nodeExtractor(e), (e) => e.nodeName === this.value); } } - t.NodeNameFeature = x; - class w extends h { + t.NodeNameFeature = T; + class b extends v { matches(e) { - var t; - return ( - (null === (t = this.nodeExtractor(e)) || void 0 === t - ? void 0 - : t.textContent) === this.value + return x( + this.nodeExtractor(e), + (e) => e.textContent === this.value, ); } } - t.NodeTextFeature = w; - class y extends h { + t.NodeTextFeature = b; + class S extends v { matches(e) { - const t = this.nodeExtractor(e); - return ( - t.nodeType === l.Node.ELEMENT_NODE && - t.getAttribute(this.value.name) === this.value.value + return x( + this.nodeExtractor(e), + (e) => + e.nodeType == l.Node.ELEMENT_NODE && + e.getAttribute(this.value.name) === this.value.value, ); } } - function T(e) { + function R(e) { return ( (function (e) { return 1 === e.nodeType; })(e) && e.namespaceURI === p ); } - function b(e, t) { - return T(e) && e.localName === t; + function E(e, t) { + return R(e) && e.localName === t; } - function S(e, t) { - for (const n of e.childNodes) if (b(n, t)) return n; + function $(e, t) { + for (const n of e.childNodes) if (E(n, t)) return n; } - function R(e, t, n) { + function P(e, t, n) { for (const r of e.childNodes) { - if (!T(r)) continue; - if (b(r, t) && (!n || n(r))) return r; - const e = R(r, t, n); + if (!R(r)) continue; + if (E(r, t) && (!n || n(r))) return r; + const e = P(r, t, n); if (e) return e; } } - t.NodeAttributeFeature = y; - class E extends Error {} - function $(e, t, n) { - if (!T(e)) return; + function I(e) { + var t; + return ( + "descendant-or-self" === + (null === (t = $(e, "xpathAxis")) || void 0 === t + ? void 0 + : t.textContent) && !!$(e, "anyKindTest") + ); + } + t.NodeAttributeFeature = S; + class O extends Error {} + function C(e, t, n) { + if (!R(e)) return; const r = e.localName; if ("module" === r || "mainModule" === r || "queryBody" === r) - for (const r of e.childNodes) $(r, t, n); + for (const r of e.childNodes) C(r, t, n); else { - if ("pathExpr" !== r) throw new E(); + if ("pathExpr" !== r) throw new O(); { - const r = e.childNodes.filter((e) => b(e, "stepExpr")); - if (b(e.firstChild, "rootExpr")) { + const r = e.childNodes.filter((e) => E(e, "stepExpr")); + if (E(e.firstChild, "rootExpr")) { if (0 === r.length) - return void t.push(new N(m, l.Node.DOCUMENT_NODE)); - if ( - "descendant-or-self" !== - (null === (a = S((o = r[0]), "xpathAxis")) || void 0 === a - ? void 0 - : a.textContent) || - !S(o, "anyKindTest") - ) - throw new E(); + return void t.push(new y(m, l.Node.DOCUMENT_NODE)); + if (!I(r[0])) throw new O(); r.shift(); } - if (0 === r.length) throw new E(); - const s = r.reverse(); - if (0 == s.length || s.length > 4) throw new E(); - (O(m, s[0], t, n), - s[1] && O(d, s[1], t, n), - s[2] && O(f, s[2], t, n), - s[3] && O(g, s[3], t, n)); + if (0 === r.length) throw new O(); + const o = r.reverse(); + if (0 == o.length) throw new O(); + const a = [m, d, f, g, h]; + let s = 0, + i = !1; + for (const e of o) { + if (I(e)) { + i = !0; + continue; + } + const r = i ? N : a[s++]; + if (!r) throw new O(); + X(r, e, t, n); + } } } - var o, a; } - function I(e, t, n) { + function D(e, t, n) { "attribute" === t - ? n.push(new N(e, l.Node.ATTRIBUTE_NODE)) - : n.push(new N(e, l.Node.ELEMENT_NODE)); + ? n.push(new y(e, l.Node.ATTRIBUTE_NODE)) + : n.push(new y(e, l.Node.ELEMENT_NODE)); } - function O(e, t, n, r) { + function X(e, t, n, r) { var o, a; const s = - null === (o = S(t, "xpathAxis")) || void 0 === o + null === (o = $(t, "xpathAxis")) || void 0 === o ? void 0 : o.textContent; if ("child" !== s && "attribute" !== s) - throw new E(`unsupported axis: ${s}`); + throw new O(`unsupported axis: ${s}`); for (const o of t.childNodes.slice(1)) { - if (!T(o)) continue; + if (!R(o)) continue; const i = o.localName; - if ("nameTest" === i) (P(e, t, n, r), I(e, s, n)); + if ("nameTest" === i) (M(e, t, n, r), D(e, s, n)); else if ("Wildcard" === i) { - const t = S(o, "NCName"); + const t = $(o, "NCName"); if (t) { const o = null == r ? void 0 : r(null !== (a = t.textContent) && void 0 !== a ? a : ""); - if (!o) throw new E(`unresolved ns prefix: ${o}`); - n.push(new v(e, o)); + if (!o) throw new O(`unresolved ns prefix: ${o}`); + n.push(new w(e, o)); } - I(e, s, n); + D(e, s, n); } else if ("piTest" === i) { - n.push(new N(e, l.Node.PROCESSING_INSTRUCTION_NODE)); - const t = S(o, "piTarget"); + n.push(new y(e, l.Node.PROCESSING_INSTRUCTION_NODE)); + const t = $(o, "piTarget"); (null == t ? void 0 : t.textContent) && - n.push(new x(e, t.textContent)); + n.push(new T(e, t.textContent)); } else if ("commentTest" === i) - n.push(new N(e, l.Node.COMMENT_NODE)); - else if ("textTest" === i) n.push(new N(e, l.Node.TEXT_NODE)); + n.push(new y(e, l.Node.COMMENT_NODE)); + else if ("textTest" === i) n.push(new y(e, l.Node.TEXT_NODE)); else { - if ("predicates" !== i) throw new E(); - C(e, o, n, r); + if ("predicates" !== i) throw new O(); + _(e, o, n, r); } } } - function P(e, t, n, r) { - const o = S(t, "nameTest"); - if (!o) throw new E(); + function M(e, t, n, r) { + const o = $(t, "nameTest"); + if (!o) throw new O(); const a = o.textContent; - a && n.push(new x(e, a)); + a && n.push(new T(e, a)); const s = o.getAttributeNS(p, "prefix"); if (s) { const t = null == r ? void 0 : r(s); - if (!t) throw new E(`unresolved ns prefix: ${t}`); - n.push(new v(e, t)); + if (!t) throw new O(`unresolved ns prefix: ${t}`); + n.push(new w(e, t)); } const i = o.getAttributeNS(p, "URI"); - i && n.push(new v(e, i)); + i && n.push(new w(e, i)); } - function C(e, t, n, r) { + function _(e, t, n, r) { for (const o of t.childNodes) { - if (!T(o)) throw new E(); + if (!R(o)) throw new O(); const t = o.localName; if ("equalOp" === t) { - const t = S(o, "firstOperand"), - r = S(o, "secondOperand"); - if (!t || !r) throw new E(); - const a = D(e, t, r) || D(e, r, t); - if (!a) throw new E(); + const t = $(o, "firstOperand"), + r = $(o, "secondOperand"); + if (!t || !r) throw new O(); + const a = L(e, t, r) || L(e, r, t); + if (!a) throw new O(); n.push(a); } else { - if ("andOp" !== t) throw new E(); - (C(e, S(o, "firstOperand"), n, r), - C(e, S(o, "secondOperand"), n, r)); + if ("andOp" !== t) throw new O(); + (_(e, $(o, "firstOperand"), n, r), + _(e, $(o, "secondOperand"), n, r)); } } } - function D(e, t, n) { + function L(e, t, n) { var r, o; - const a = R(n, "value"); + const a = P(n, "value"); if (!a) return; const s = null !== (r = a.textContent) && void 0 !== r ? r : "", - i = R(t, "stepExpr", (e) => { + i = P(t, "stepExpr", (e) => { var t; return ( "attribute" === - (null === (t = S(e, "xpathAxis")) || void 0 === t + (null === (t = $(e, "xpathAxis")) || void 0 === t ? void 0 : t.textContent) ); }); if (i) { const t = - null === (o = S(i, "nameTest")) || void 0 === o + null === (o = $(i, "nameTest")) || void 0 === o ? void 0 : o.textContent; if (!t) return; - return new y(e, { name: t, value: s }); + return new S(e, { name: t, value: s }); } - return S(t, "contextItemExpr") || R(t, "textTest") - ? new w(e, s) + return $(t, "contextItemExpr") || P(t, "textTest") + ? new b(e, s) : void 0; } }, @@ -1019,19 +1040,19 @@ { namespaceURI: o.XJSLT_NSURI, localName: "system-property" }, ["xs:string"], "xs:string", - v, + N, ), (0, r.registerCustomXPathFunction)( { namespaceURI: o.XJSLT_NSURI, localName: "base-uri" }, [], "xs:string?", - N, + v, ), (0, r.registerCustomXPathFunction)( { namespaceURI: o.XJSLT_NSURI, localName: "base-uri" }, ["node()?"], "xs:string?", - N, + v, ), (0, r.registerCustomXPathFunction)( { namespaceURI: o.XJSLT_NSURI, localName: "evaluate" }, @@ -1152,7 +1173,7 @@ const [n, r] = t.split(":"); return !(!n || !r) && g.has(r); } - function v(e, t) { + function N(e, t) { return "version" === t.split(":")[1] ? "2.0" : "vendor" === t.split(":")[1] @@ -1170,7 +1191,7 @@ ? "no" : ""; } - function N({ currentContext: e }, t) { + function v({ currentContext: e }, t) { const n = void 0 !== t ? t : e.contextItem; if (!n) return null; let r = n; @@ -1408,29 +1429,29 @@ } g >= 0 && (m = f - g); let h = 0, - v = 0; + N = 0; if (s < e.length && e[s] === o) for (s++; s < e.length; ) { const t = e[s]; - if (t === n) (h++, v++); + if (t === n) (h++, N++); else { if (t !== r) break; - v++; + N++; } s++; } - const N = l(); + const v = l(); if (s < e.length) throw new Error( `XTDE1310: Active characters after picture string suffix: ${e.slice(s)}`, ); return { prefix: p, - suffix: N, + suffix: v, integerMinDigits: Math.max(d, 1), integerGroupSize: m, decimalMinDigits: h, - decimalMaxDigits: v, + decimalMaxDigits: N, isPercent: i, isPerMille: c, }; @@ -1570,15 +1591,15 @@ } } }, - 472(e, t, n) { + 472(e, t) { "use strict"; (Object.defineProperty(t, "__esModule", { value: !0 }), (t.urlToDom = function (e, t) { - if (!e.readDocument) return; - const n = e.inputURL ? (0, r.resolve)(e.inputURL.toString(), t) : t; + const n = e.inputURL + ? new URL(t, e.inputURL.toString()).toString() + : t; return e.readDocument(n); })); - const r = n(16); }, 821(e, t, n) { "use strict"; @@ -1647,9 +1668,11 @@ t.NodeNamespaceFeature = t.NodeAttributeFeature = t.selfNode = + t.greatGreatGrandParentNode = t.greatGrandParentNode = t.grandParentNode = t.parentNode = + t.ancestorNodes = t.KeyImpl = void 0), (t.visitNodes = g), @@ -1660,12 +1683,7 @@ const n = e.nextMatches; if (n) { const r = n.next(); - r.done || - C( - r.value, - Object.assign(Object.assign({}, e), { nextMatches: n }), - t.params, - ); + r.done || ((e.nextMatches = n), C(r.value, e, t.params)); } }), (t.applyImports = function (e, t) { @@ -1673,22 +1691,17 @@ if (n) { let r = n.next(); for (; !r.done && 1 === r.value.importPrecedence; ) r = n.next(); - r.done || - C( - r.value, - Object.assign(Object.assign({}, e), { nextMatches: n }), - t.params, - ); + r.done || ((e.nextMatches = n), C(r.value, e, t.params)); } }), - (t.sort = O), + (t.sort = I), (t.applyTemplates = function (e, t) { const n = (0, p.mkResolver)(t.namespaces), r = (0, i.evaluateXPathToNodes)( t.select, e.contextItem, void 0, - j(e.variableScopes), + U(e.variableScopes), { currentContext: e, namespaceResolver: n, @@ -1697,16 +1710,15 @@ ); let o = t.mode || "#default"; ("#current" === o && (o = e.mode), - $(O(e, r, t.sortKeyComponents, n), e, (e) => { - S( - Object.assign(Object.assign({}, e), { - mode: o, - variableScopes: D(e.variableScopes), - }), - t.params, - t.namespaces, - ); - })); + $( + I(e, r, t.sortKeyComponents, n), + Object.assign(Object.assign({}, e), { mode: o }), + (e) => { + ((e.variableScopes = D(e.variableScopes)), + S(e, t.params, t.namespaces), + e.variableScopes.pop()); + }, + )); }), (t.callTemplate = function (e, t) { const n = e.namedTemplates.get(t.name); @@ -1770,7 +1782,7 @@ t.select, e.contextItem, void 0, - j(e.variableScopes), + U(e.variableScopes), i.evaluateXPath.ALL_RESULTS_TYPE, { currentContext: e, @@ -1802,7 +1814,7 @@ (t.extendScope = D), (t.wrapValue = _), (t.setVariable = L), - (t.mergeVariableScopes = j), + (t.mergeVariableScopes = U), (t.literalText = function (e, t) { e.append(t); }), @@ -1811,7 +1823,7 @@ t.select, e.contextItem, void 0, - j(e.variableScopes), + U(e.variableScopes), i.evaluateXPath.ALL_RESULTS_TYPE, { currentContext: e, @@ -1822,13 +1834,13 @@ e.append(n); }), (t.buildNode = A), - (t.buildAttributeNode = U), + (t.buildAttributeNode = j), (t.literalElement = function (e, t, n) { let r = A(e, { name: t.name, namespace: t.namespace }); const o = (0, p.mkResolver)(t.namespaces); for (let n of t.attributes) { - const t = G(e, n.value, o), - a = U(e, { name: n.name, namespace: n.namespace, value: t }); + const t = z(e, n.value, o), + a = j(e, { name: n.name, namespace: n.namespace, value: t }); r.setAttributeNode(a); } const a = e.append(r); @@ -1841,12 +1853,12 @@ }), (t.attribute = function (e, t, n) { const r = (0, p.mkResolver)(t.namespaces), - o = G(e, t.name, r), - a = G(e, t.namespace, r), + o = z(e, t.name, r), + a = z(e, t.namespace, r), [s, i] = o.includes(":") ? (0, p.determineNamespace)(o, r, a) : [a, o], - c = U(e, { + c = j(e, { name: o, namespace: s, value: J(e, t.select || n, r, t.separator), @@ -1854,7 +1866,7 @@ e.append(c); }), (t.processingInstruction = function (e, t, n) { - const r = G(e, t.name, (0, p.mkResolver)(t.namespaces)), + const r = z(e, t.name, (0, p.mkResolver)(t.namespaces)), o = J(e, t.select || n, (0, p.mkResolver)(t.namespaces), [ "", ]).trimStart(); @@ -1868,9 +1880,9 @@ }), (t.namespace = function (e, t, n) { const r = (0, p.mkResolver)(t.namespaces), - o = G(e, t.name, r), + o = z(e, t.name, r), a = J(e, t.select || n, r, [""]), - s = U(e, { + s = j(e, { name: `xmlns:${o}`, namespace: l.XMLNS_NSURI, value: a, @@ -1879,8 +1891,8 @@ }), (t.element = function (e, t, n) { const r = (0, p.mkResolver)(t.namespaces); - let o = G(e, t.name, r), - a = G(e, t.namespace, r), + let o = z(e, t.name, r), + a = z(e, t.namespace, r), s = A(e, { name: o, namespace: (0, p.determineNamespace)( @@ -1902,7 +1914,7 @@ t.test, e.contextItem, void 0, - j(e.variableScopes), + U(e.variableScopes), { currentContext: e, namespaceResolver: (0, p.mkResolver)(t.namespaces), @@ -1918,7 +1930,7 @@ n.test, e.contextItem, void 0, - j(e.variableScopes), + U(e.variableScopes), { currentContext: e, functionNameResolver: u.functionNameResolver, @@ -1950,7 +1962,7 @@ t.select, e.contextItem, void 0, - j(e.variableScopes), + U(e.variableScopes), i.evaluateXPath.ALL_RESULTS_TYPE, { currentContext: e, @@ -1959,7 +1971,7 @@ }, ); if (r && Symbol.iterator in Object(r)) { - const o = O(e, r, t.sortKeyComponents, n); + const o = I(e, r, t.sortKeyComponents, n); for (let t of o) e.append(t); } }), @@ -1969,7 +1981,7 @@ t.select, e.contextItem, void 0, - j(e.variableScopes), + U(e.variableScopes), i.evaluateXPath.ALL_RESULTS_TYPE, { currentContext: e, @@ -1979,18 +1991,16 @@ ); o && Symbol.iterator in Object(o) && - ((o = O(e, o, t.sortKeyComponents, r)), + ((o = I(e, o, t.sortKeyComponents, r)), $(o, e, (e) => { - n( - Object.assign(Object.assign({}, e), { - variableScopes: D(e.variableScopes), - }), - ); + ((e.variableScopes = D(e.variableScopes)), + n(e), + e.variableScopes.pop()); })); }), (t.forEachGroup = function (e, t, n) { const r = (0, p.mkResolver)(t.namespaces), - o = j(e.variableScopes), + o = U(e.variableScopes), a = (0, i.evaluateXPathToNodes)( t.select, e.contextItem, @@ -2006,7 +2016,7 @@ let o = []; (t.groupBy ? (o = (function (e, t, n, r) { - const o = j(e.variableScopes); + const o = U(e.variableScopes); let a = []; return ( $(t, e, (e) => { @@ -2030,7 +2040,7 @@ })(e, a, t.groupBy, r)) : t.groupAdjacent ? (o = (function (e, t, n, r) { - const o = j(e.variableScopes); + const o = U(e.variableScopes); let a = [], s = null, c = []; @@ -2062,7 +2072,7 @@ e.patternMatchCache, n, t, - e.variableScopes, + U(e.variableScopes), r, ) && (F(o, a), (a = []))); }), @@ -2081,7 +2091,7 @@ e.patternMatchCache, n, t, - e.variableScopes, + U(e.variableScopes), r, ) && (F(o, a), (a = [])), a.push(t)); @@ -2090,13 +2100,13 @@ o ); })(e, a, t.groupStartingWith, r)), - (o = O(e, o, t.sortKeyComponents, r)), - I(o, e, n)); + (o = I(e, o, t.sortKeyComponents, r)), + P(o, e, n)); } }), (t.number = function (e, t) { const n = (0, p.mkResolver)(t.namespaces), - r = j(e.variableScopes); + r = U(e.variableScopes); let o; (t.value ? (o = (0, i.evaluateXPathToNumber)( @@ -2125,11 +2135,11 @@ )); }), (t.mkNodeAppender = k), - (t.mkArrayAppender = z), + (t.mkArrayAppender = G), (t.resultDocument = function (e, t, n) { const r = (0, p.mkResolver)(t.namespaces); function o(t) { - return G(e, t, r); + return z(e, t, r); } const a = o(t.format); let s = (0, p.mkOutputDefinition)({ @@ -2212,7 +2222,7 @@ for (let e of r) e.remove(); return e; }), - (t.evaluateAttributeValueTemplate = G), + (t.evaluateAttributeValueTemplate = z), (t.serialize = function (e) { const t = new c.XMLSerializer(); if (!0 !== e.omitXmlDeclaration) { @@ -2273,12 +2283,24 @@ ? e.textContent : e.toString(); } - (Object.defineProperty(t, "greatGrandParentNode", { + (Object.defineProperty(t, "ancestorNodes", { enumerable: !0, get: function () { - return f.greatGrandParentNode; + return f.ancestorNodes; }, }), + Object.defineProperty(t, "greatGrandParentNode", { + enumerable: !0, + get: function () { + return f.greatGrandParentNode; + }, + }), + Object.defineProperty(t, "greatGreatGrandParentNode", { + enumerable: !0, + get: function () { + return f.greatGreatGrandParentNode; + }, + }), Object.defineProperty(t, "grandParentNode", { enumerable: !0, get: function () { @@ -2336,6 +2358,7 @@ } buildDocumentCache(e, t, n) { let r = new Map(); + const o = U(n); return ( g(t, (t) => { if ( @@ -2344,7 +2367,7 @@ e, { xpath: this.match }, t, - n, + o, (0, p.mkResolver)(this.namespaces), ) ) { @@ -2363,8 +2386,8 @@ ); } })); - const v = new RegExp(/^[a-z |-]+$/), - N = new RegExp(/^@[a-z]+$/), + const N = new RegExp(/^[a-z |-]+$/), + v = new RegExp(/^@[a-z]+$/), x = new RegExp(/text\(\)|node\(\)/), w = new RegExp(/@|attribute|node/); function y(e, t, n, r, o) { @@ -2374,8 +2397,8 @@ return ( (t.nodeType === l.NodeType.ATTRIBUTE && !w.exec(e)) || (t.nodeType === l.NodeType.TEXT && !x.exec(e)) || - !(!v.exec(e) || t.nodeType === l.NodeType.ELEMENT) || - !(!N.exec(e) || t.nodeType === l.NodeType.ATTRIBUTE) + !(!N.exec(e) || t.nodeType === l.NodeType.ELEMENT) || + !(!v.exec(e) || t.nodeType === l.NodeType.ATTRIBUTE) ); })(t.xpath, n)) || void 0 === @@ -2383,14 +2406,13 @@ let a = e.get(t.xpath); a || ((a = new Map()), e.set(t.xpath, a)); let s = n; - const c = j(r); for (; s; ) { let e = a.get(s); if ( (void 0 === e && ((e = t.compiled ? (0, i.executeJavaScriptCompiledXPath)(t.compiled, s) - : (0, i.evaluateXPathToNodes)(t.xpath, s, void 0, c, { + : (0, i.evaluateXPathToNodes)(t.xpath, s, void 0, r, { namespaceResolver: o, functionNameResolver: u.functionNameResolver, })), @@ -2427,11 +2449,12 @@ ("#all" === e.modes[0] || e.modes.includes(r)) && (yield e); })(e.contextItem, e.ruleTree, e.templates, e.mode), o = (function* (e, t, n, r, o, a, s) { - for (let [i, c] of n) { + const i = U(o); + for (let [o, c] of n) { const n = r[c]; - i && + o && ("#all" === n.modes[0] || n.modes.includes(a)) && - y(e, i, t, o, (0, p.mkResolver)(s)) && + y(e, o, t, i, (0, p.mkResolver)(s)) && (yield n); } })( @@ -2445,15 +2468,10 @@ ), a = T(b(r, o)); const s = a.next(); - s.done || - C( - s.value, - Object.assign(Object.assign({}, e), { nextMatches: a }), - t, - ); + ((e.nextMatches = a), s.done || C(s.value, e, t)); } function R(e, t, n, r) { - const o = "descending" === G(e, n.order, r); + const o = "descending" === z(e, n.order, r); return "number" === n.dataType ? (function (e, t, n, r, o) { const a = E(t, e, (e) => { @@ -2471,7 +2489,7 @@ })(e, t, n, r, o) : (function (e, t, n, r, o) { const a = E(t, e, (e) => J(e, n.sortKey, r)), - s = n.lang && G(e, n.lang, r); + s = n.lang && z(e, n.lang, r); let i = new Intl.Collator(s).compare; return (0, p.zip)(a, t) .sort(o ? (e, t) => i(t[0], e[0]) : (e, t) => i(e[0], t[0])) @@ -2480,24 +2498,16 @@ } function E(e, t, n) { if (e.length > 0) - return (0, l.isNodeGroupArray)(e) ? I(e, t, n) : $(e, t, n); + return (0, l.isNodeGroupArray)(e) ? P(e, t, n) : $(e, t, n); } function $(e, t, n) { let r = 0; + const o = Object.assign(Object.assign({}, t), { contextList: e }); return e.map( - (o) => ( - r++, - n( - Object.assign(Object.assign({}, t), { - contextItem: o, - contextList: e, - position: r, - }), - ) - ), + (e) => (r++, (o.contextItem = e), (o.position = r), n(o)), ); } - function I(e, t, n) { + function P(e, t, n) { let r = 0; return e.map((e) => { r++; @@ -2511,17 +2521,17 @@ return n(o); }); } - function O(e, t, n, r) { + function I(e, t, n, r) { if (n) for (let o of [...n].reverse()) t = R(e, t, o, r); return t; } - function P(e, t) { + function O(e, t) { for (let n of t) if (n.name === e) return n; } function C(e, t, n) { let r = D(t.variableScopes); for (let o of e.allowedParams) { - let e = P(o.name, n); + let e = O(o.name, n); void 0 !== e ? L(r, e.name, B(t, e)) : L(r, o.name, B(t, o)); } return e.apply( @@ -2560,7 +2570,7 @@ function L(e, t, n) { e[e.length - 1].set(t, n); } - function j(e) { + function U(e) { let t = {}; for (let n of e) for (let [e, r] of n) t[e] = r; return t; @@ -2575,7 +2585,7 @@ n ); } - function U(e, t) { + function j(e, t) { let n; return ( (n = t.namespace @@ -2625,7 +2635,7 @@ } }; } - function z(e) { + function G(e) { return function (t) { if ( (e.push(t), @@ -2636,9 +2646,9 @@ return k(t); }; } - function G(e, t, n) { + function z(e, t, n) { if (!t) return; - const r = j(e.variableScopes); + const r = U(e.variableScopes); return t .map((t) => "string" == typeof t @@ -2659,9 +2669,9 @@ } function J(e, t, n, r) { r || (r = "string" == typeof t ? [" "] : []); - const o = G(e, r, n); + const o = z(e, r, n); if ("string" == typeof t) { - const r = j(e.variableScopes); + const r = U(e.variableScopes); return (0, i.evaluateXPath)( t, e.contextItem, @@ -2694,7 +2704,7 @@ t.content, e.contextItem, void 0, - j(e.variableScopes), + U(e.variableScopes), i.evaluateXPath.ALL_RESULTS_TYPE, { currentContext: e, @@ -2713,7 +2723,7 @@ return ( t( Object.assign(Object.assign({}, e), { - append: z(n), + append: G(n), mode: "#default", variableScopes: D(e.variableScopes), }), @@ -2760,10 +2770,6 @@ "use strict"; e.exports = require("slimdom"); }, - 16(e) { - "use strict"; - e.exports = require("url"); - }, }, t = {}, n = (function n(r) { @@ -2771,6 +2777,6 @@ if (void 0 !== o) return o.exports; var a = (t[r] = { exports: {} }); return (e[r].call(a.exports, a, a.exports, n), a.exports); - })(524); + })(347); module.exports = n.transform; })(); diff --git a/src/preprocess/use-when.js b/src/preprocess/use-when.js index d5e0be9..a2cc1b8 100644 --- a/src/preprocess/use-when.js +++ b/src/preprocess/use-when.js @@ -1,6 +1,6 @@ (() => { var e = { - 882(e, t, n) { + 519(e, t, n) { (n(898), n(594)); let r = n(821); function o(e, t) { @@ -474,12 +474,14 @@ (t.parentNode = d), (t.grandParentNode = f), (t.greatGrandParentNode = h), + (t.greatGreatGrandParentNode = g), + (t.ancestorNodes = x), (t.xpathToFeatures = function (e, t) { if (e) return (function (e, t) { const n = []; try { - return (O(e, n, t), n); + return (C(e, n, t), n); } catch (e) { return; } @@ -497,33 +499,51 @@ u = n(594), l = s(n(898)), p = "http://www.w3.org/2005/XQueryX"; - function m(e) { - return e; + function* m(e) { + yield e; } - function d(e) { - return e.parentNode || void 0; + function* d(e) { + e.parentNode && (yield e.parentNode); } - function f(e) { + function* f(e) { var t; - return ( - (null === (t = e.parentNode) || void 0 === t - ? void 0 - : t.parentNode) || void 0 - ); + const n = + null === (t = e.parentNode) || void 0 === t ? void 0 : t.parentNode; + n && (yield n); } - function h(e) { + function* h(e) { var t, n; - return ( - (null === + const r = + null === (n = null === (t = e.parentNode) || void 0 === t ? void 0 : t.parentNode) || void 0 === n ? void 0 - : n.parentNode) || void 0 - ); + : n.parentNode; + r && (yield r); + } + function* g(e) { + var t, n, r; + const o = + null === + (r = + null === + (n = + null === (t = e.parentNode) || void 0 === t + ? void 0 + : t.parentNode) || void 0 === n + ? void 0 + : n.parentNode) || void 0 === r + ? void 0 + : r.parentNode; + o && (yield o); } - class g extends c.Feature { + function* x(e) { + let t = e.parentNode; + for (; t; ) (yield t, (t = t.parentNode)); + } + class w extends c.Feature { constructor(e, t) { (super(t), (this.nodeExtractor = e)); } @@ -540,214 +560,215 @@ return this.nodeExtractor === e.nodeExtractor && super.equals(e); } } - class x extends g { + function N(e, t) { + for (const n of e) if (t(n)) return !0; + return !1; + } + class v extends w { matches(e) { - var t; - return ( - (null === (t = this.nodeExtractor(e)) || void 0 === t - ? void 0 - : t.nodeType) === l.Node.ELEMENT_NODE && - e.namespaceURI === this.value + return N( + this.nodeExtractor(e), + (e) => + e.nodeType == l.Node.ELEMENT_NODE && + e.namespaceURI === this.value, ); } } - t.NodeNamespaceFeature = x; - class w extends g { + t.NodeNamespaceFeature = v; + class y extends w { matches(e) { - var t; - return ( - (null === (t = this.nodeExtractor(e)) || void 0 === t - ? void 0 - : t.nodeType) === this.value - ); + return N(this.nodeExtractor(e), (e) => e.nodeType === this.value); } } - t.NodeTypeFeature = w; - class N extends g { + t.NodeTypeFeature = y; + class T extends w { matches(e) { - var t; - return ( - (null === (t = this.nodeExtractor(e)) || void 0 === t - ? void 0 - : t.nodeName) === this.value - ); + return N(this.nodeExtractor(e), (e) => e.nodeName === this.value); } } - t.NodeNameFeature = N; - class v extends g { + t.NodeNameFeature = T; + class b extends w { matches(e) { - var t; - return ( - (null === (t = this.nodeExtractor(e)) || void 0 === t - ? void 0 - : t.textContent) === this.value + return N( + this.nodeExtractor(e), + (e) => e.textContent === this.value, ); } } - t.NodeTextFeature = v; - class T extends g { + t.NodeTextFeature = b; + class S extends w { matches(e) { - const t = this.nodeExtractor(e); - return ( - t.nodeType === l.Node.ELEMENT_NODE && - t.getAttribute(this.value.name) === this.value.value + return N( + this.nodeExtractor(e), + (e) => + e.nodeType == l.Node.ELEMENT_NODE && + e.getAttribute(this.value.name) === this.value.value, ); } } - function y(e) { + function R(e) { return ( (function (e) { return 1 === e.nodeType; })(e) && e.namespaceURI === p ); } - function b(e, t) { - return y(e) && e.localName === t; + function E(e, t) { + return R(e) && e.localName === t; } - function S(e, t) { - for (const n of e.childNodes) if (b(n, t)) return n; + function P(e, t) { + for (const n of e.childNodes) if (E(n, t)) return n; } - function R(e, t, n) { + function I(e, t, n) { for (const r of e.childNodes) { - if (!y(r)) continue; - if (b(r, t) && (!n || n(r))) return r; - const e = R(r, t, n); + if (!R(r)) continue; + if (E(r, t) && (!n || n(r))) return r; + const e = I(r, t, n); if (e) return e; } } - t.NodeAttributeFeature = T; - class E extends Error {} - function O(e, t, n) { - if (!y(e)) return; + function $(e) { + var t; + return ( + "descendant-or-self" === + (null === (t = P(e, "xpathAxis")) || void 0 === t + ? void 0 + : t.textContent) && !!P(e, "anyKindTest") + ); + } + t.NodeAttributeFeature = S; + class O extends Error {} + function C(e, t, n) { + if (!R(e)) return; const r = e.localName; if ("module" === r || "mainModule" === r || "queryBody" === r) - for (const r of e.childNodes) O(r, t, n); + for (const r of e.childNodes) C(r, t, n); else { - if ("pathExpr" !== r) throw new E(); + if ("pathExpr" !== r) throw new O(); { - const r = e.childNodes.filter((e) => b(e, "stepExpr")); - if (b(e.firstChild, "rootExpr")) { + const r = e.childNodes.filter((e) => E(e, "stepExpr")); + if (E(e.firstChild, "rootExpr")) { if (0 === r.length) - return void t.push(new w(m, l.Node.DOCUMENT_NODE)); - if ( - "descendant-or-self" !== - (null === (a = S((o = r[0]), "xpathAxis")) || void 0 === a - ? void 0 - : a.textContent) || - !S(o, "anyKindTest") - ) - throw new E(); + return void t.push(new y(m, l.Node.DOCUMENT_NODE)); + if (!$(r[0])) throw new O(); r.shift(); } - if (0 === r.length) throw new E(); - const s = r.reverse(); - if (0 == s.length || s.length > 4) throw new E(); - (P(m, s[0], t, n), - s[1] && P(d, s[1], t, n), - s[2] && P(f, s[2], t, n), - s[3] && P(h, s[3], t, n)); + if (0 === r.length) throw new O(); + const o = r.reverse(); + if (0 == o.length) throw new O(); + const a = [m, d, f, h, g]; + let s = 0, + i = !1; + for (const e of o) { + if ($(e)) { + i = !0; + continue; + } + const r = i ? x : a[s++]; + if (!r) throw new O(); + D(r, e, t, n); + } } } - var o, a; } - function I(e, t, n) { + function j(e, t, n) { "attribute" === t - ? n.push(new w(e, l.Node.ATTRIBUTE_NODE)) - : n.push(new w(e, l.Node.ELEMENT_NODE)); + ? n.push(new y(e, l.Node.ATTRIBUTE_NODE)) + : n.push(new y(e, l.Node.ELEMENT_NODE)); } - function P(e, t, n, r) { + function D(e, t, n, r) { var o, a; const s = - null === (o = S(t, "xpathAxis")) || void 0 === o + null === (o = P(t, "xpathAxis")) || void 0 === o ? void 0 : o.textContent; if ("child" !== s && "attribute" !== s) - throw new E(`unsupported axis: ${s}`); + throw new O(`unsupported axis: ${s}`); for (const o of t.childNodes.slice(1)) { - if (!y(o)) continue; + if (!R(o)) continue; const i = o.localName; - if ("nameTest" === i) ($(e, t, n, r), I(e, s, n)); + if ("nameTest" === i) (X(e, t, n, r), j(e, s, n)); else if ("Wildcard" === i) { - const t = S(o, "NCName"); + const t = P(o, "NCName"); if (t) { const o = null == r ? void 0 : r(null !== (a = t.textContent) && void 0 !== a ? a : ""); - if (!o) throw new E(`unresolved ns prefix: ${o}`); - n.push(new x(e, o)); + if (!o) throw new O(`unresolved ns prefix: ${o}`); + n.push(new v(e, o)); } - I(e, s, n); + j(e, s, n); } else if ("piTest" === i) { - n.push(new w(e, l.Node.PROCESSING_INSTRUCTION_NODE)); - const t = S(o, "piTarget"); + n.push(new y(e, l.Node.PROCESSING_INSTRUCTION_NODE)); + const t = P(o, "piTarget"); (null == t ? void 0 : t.textContent) && - n.push(new N(e, t.textContent)); + n.push(new T(e, t.textContent)); } else if ("commentTest" === i) - n.push(new w(e, l.Node.COMMENT_NODE)); - else if ("textTest" === i) n.push(new w(e, l.Node.TEXT_NODE)); + n.push(new y(e, l.Node.COMMENT_NODE)); + else if ("textTest" === i) n.push(new y(e, l.Node.TEXT_NODE)); else { - if ("predicates" !== i) throw new E(); - j(e, o, n, r); + if ("predicates" !== i) throw new O(); + M(e, o, n, r); } } } - function $(e, t, n, r) { - const o = S(t, "nameTest"); - if (!o) throw new E(); + function X(e, t, n, r) { + const o = P(t, "nameTest"); + if (!o) throw new O(); const a = o.textContent; - a && n.push(new N(e, a)); + a && n.push(new T(e, a)); const s = o.getAttributeNS(p, "prefix"); if (s) { const t = null == r ? void 0 : r(s); - if (!t) throw new E(`unresolved ns prefix: ${t}`); - n.push(new x(e, t)); + if (!t) throw new O(`unresolved ns prefix: ${t}`); + n.push(new v(e, t)); } const i = o.getAttributeNS(p, "URI"); - i && n.push(new x(e, i)); + i && n.push(new v(e, i)); } - function j(e, t, n, r) { + function M(e, t, n, r) { for (const o of t.childNodes) { - if (!y(o)) throw new E(); + if (!R(o)) throw new O(); const t = o.localName; if ("equalOp" === t) { - const t = S(o, "firstOperand"), - r = S(o, "secondOperand"); - if (!t || !r) throw new E(); - const a = C(e, t, r) || C(e, r, t); - if (!a) throw new E(); + const t = P(o, "firstOperand"), + r = P(o, "secondOperand"); + if (!t || !r) throw new O(); + const a = _(e, t, r) || _(e, r, t); + if (!a) throw new O(); n.push(a); } else { - if ("andOp" !== t) throw new E(); - (j(e, S(o, "firstOperand"), n, r), - j(e, S(o, "secondOperand"), n, r)); + if ("andOp" !== t) throw new O(); + (M(e, P(o, "firstOperand"), n, r), + M(e, P(o, "secondOperand"), n, r)); } } } - function C(e, t, n) { + function _(e, t, n) { var r, o; - const a = R(n, "value"); + const a = I(n, "value"); if (!a) return; const s = null !== (r = a.textContent) && void 0 !== r ? r : "", - i = R(t, "stepExpr", (e) => { + i = I(t, "stepExpr", (e) => { var t; return ( "attribute" === - (null === (t = S(e, "xpathAxis")) || void 0 === t + (null === (t = P(e, "xpathAxis")) || void 0 === t ? void 0 : t.textContent) ); }); if (i) { const t = - null === (o = S(i, "nameTest")) || void 0 === o + null === (o = P(i, "nameTest")) || void 0 === o ? void 0 : o.textContent; if (!t) return; - return new T(e, { name: t, value: s }); + return new S(e, { name: t, value: s }); } - return S(t, "contextItemExpr") || R(t, "textTest") - ? new v(e, s) + return P(t, "contextItemExpr") || I(t, "textTest") + ? new b(e, s) : void 0; } }, @@ -981,7 +1002,7 @@ 379(e, t, n) { "use strict"; (Object.defineProperty(t, "__esModule", { value: !0 }), - (t.functionNameResolver = y), + (t.functionNameResolver = T), (t.registerFunctions = function () { ((0, r.registerCustomXPathFunction)( { namespaceURI: o.XJSLT_NSURI, localName: "current" }, @@ -1069,7 +1090,7 @@ r.evaluateXPath.ALL_RESULTS_TYPE, { currentContext: { currentContext: e }, - functionNameResolver: y, + functionNameResolver: T, }, ); return 1 === n.length ? n[0] : n; @@ -1231,7 +1252,7 @@ : o.DEFAULT_DECIMAL_FORMAT; return (0, a.formatNumberWithPicture)(t, n, u); } - const T = [ + const y = [ "base-uri", "current", "current-group", @@ -1246,8 +1267,8 @@ "positionx", "system-property", ]; - function y({ prefix: e, localName: t }, n) { - return (e && "fn" !== e) || !T.includes(t) + function T({ prefix: e, localName: t }, n) { + return (e && "fn" !== e) || !y.includes(t) ? null : { namespaceURI: o.XJSLT_NSURI, localName: t }; } @@ -1592,15 +1613,15 @@ } } }, - 472(e, t, n) { + 472(e, t) { "use strict"; (Object.defineProperty(t, "__esModule", { value: !0 }), (t.urlToDom = function (e, t) { - if (!e.readDocument) return; - const n = e.inputURL ? (0, r.resolve)(e.inputURL.toString(), t) : t; + const n = e.inputURL + ? new URL(t, e.inputURL.toString()).toString() + : t; return e.readDocument(n); })); - const r = n(16); }, 821(e, t, n) { "use strict"; @@ -1669,25 +1690,22 @@ t.NodeNamespaceFeature = t.NodeAttributeFeature = t.selfNode = + t.greatGreatGrandParentNode = t.greatGrandParentNode = t.grandParentNode = t.parentNode = + t.ancestorNodes = t.KeyImpl = void 0), (t.visitNodes = h), - (t.dedupGenerator = y), + (t.dedupGenerator = T), (t.mergeTemplateGenerators = b), (t.processNode = S), (t.nextMatch = function (e, t) { const n = e.nextMatches; if (n) { const r = n.next(); - r.done || - j( - r.value, - Object.assign(Object.assign({}, e), { nextMatches: n }), - t.params, - ); + r.done || ((e.nextMatches = n), C(r.value, e, t.params)); } }), (t.applyImports = function (e, t) { @@ -1695,15 +1713,10 @@ if (n) { let r = n.next(); for (; !r.done && 1 === r.value.importPrecedence; ) r = n.next(); - r.done || - j( - r.value, - Object.assign(Object.assign({}, e), { nextMatches: n }), - t.params, - ); + r.done || ((e.nextMatches = n), C(r.value, e, t.params)); } }), - (t.sort = P), + (t.sort = $), (t.applyTemplates = function (e, t) { const n = (0, p.mkResolver)(t.namespaces), r = (0, i.evaluateXPathToNodes)( @@ -1719,20 +1732,19 @@ ); let o = t.mode || "#default"; ("#current" === o && (o = e.mode), - O(P(e, r, t.sortKeyComponents, n), e, (e) => { - S( - Object.assign(Object.assign({}, e), { - mode: o, - variableScopes: C(e.variableScopes), - }), - t.params, - t.namespaces, - ); - })); + P( + $(e, r, t.sortKeyComponents, n), + Object.assign(Object.assign({}, e), { mode: o }), + (e) => { + ((e.variableScopes = j(e.variableScopes)), + S(e, t.params, t.namespaces), + e.variableScopes.pop()); + }, + )); }), (t.callTemplate = function (e, t) { const n = e.namedTemplates.get(t.name); - if (void 0 !== n) return j(e.templates[n], e, t.params); + if (void 0 !== n) return C(e.templates[n], e, t.params); throw new Error(`Cannot find a template named ${t.name}`); }), (t.functionX = function (e, t) { @@ -1821,7 +1833,7 @@ (t.param = function (e, t) { _(e.variableScopes, t.name, e.stylesheetParams[t.name] || B(e, t)); }), - (t.extendScope = C), + (t.extendScope = j), (t.wrapValue = M), (t.setVariable = _), (t.mergeVariableScopes = L), @@ -1843,32 +1855,32 @@ ); e.append(n); }), - (t.buildNode = A), - (t.buildAttributeNode = U), + (t.buildNode = U), + (t.buildAttributeNode = A), (t.literalElement = function (e, t, n) { - let r = A(e, { name: t.name, namespace: t.namespace }); + let r = U(e, { name: t.name, namespace: t.namespace }); const o = (0, p.mkResolver)(t.namespaces); for (let n of t.attributes) { - const t = G(e, n.value, o), - a = U(e, { name: n.name, namespace: n.namespace, value: t }); + const t = z(e, n.value, o), + a = A(e, { name: n.name, namespace: n.namespace, value: t }); r.setAttributeNode(a); } const a = e.append(r); n( Object.assign(Object.assign({}, e), { - variableScopes: C(e.variableScopes), + variableScopes: j(e.variableScopes), append: a || e.append, }), ); }), (t.attribute = function (e, t, n) { const r = (0, p.mkResolver)(t.namespaces), - o = G(e, t.name, r), - a = G(e, t.namespace, r), + o = z(e, t.name, r), + a = z(e, t.namespace, r), [s, i] = o.includes(":") ? (0, p.determineNamespace)(o, r, a) : [a, o], - c = U(e, { + c = A(e, { name: o, namespace: s, value: J(e, t.select || n, r, t.separator), @@ -1876,7 +1888,7 @@ e.append(c); }), (t.processingInstruction = function (e, t, n) { - const r = G(e, t.name, (0, p.mkResolver)(t.namespaces)), + const r = z(e, t.name, (0, p.mkResolver)(t.namespaces)), o = J(e, t.select || n, (0, p.mkResolver)(t.namespaces), [ "", ]).trimStart(); @@ -1890,9 +1902,9 @@ }), (t.namespace = function (e, t, n) { const r = (0, p.mkResolver)(t.namespaces), - o = G(e, t.name, r), + o = z(e, t.name, r), a = J(e, t.select || n, r, [""]), - s = U(e, { + s = A(e, { name: `xmlns:${o}`, namespace: l.XMLNS_NSURI, value: a, @@ -1901,9 +1913,9 @@ }), (t.element = function (e, t, n) { const r = (0, p.mkResolver)(t.namespaces); - let o = G(e, t.name, r), - a = G(e, t.namespace, r), - s = A(e, { + let o = z(e, t.name, r), + a = z(e, t.namespace, r), + s = U(e, { name: o, namespace: (0, p.determineNamespace)( o, @@ -1914,7 +1926,7 @@ const i = e.append(s); n( Object.assign(Object.assign({}, e), { - variableScopes: C(e.variableScopes), + variableScopes: j(e.variableScopes), append: i || e.append, }), ); @@ -1962,7 +1974,7 @@ outputDocument: r, append: o, mode: "#default", - variableScopes: C(e.variableScopes), + variableScopes: j(e.variableScopes), }), ); }), @@ -1981,7 +1993,7 @@ }, ); if (r && Symbol.iterator in Object(r)) { - const o = P(e, r, t.sortKeyComponents, n); + const o = $(e, r, t.sortKeyComponents, n); for (let t of o) e.append(t); } }), @@ -2001,13 +2013,11 @@ ); o && Symbol.iterator in Object(o) && - ((o = P(e, o, t.sortKeyComponents, r)), - O(o, e, (e) => { - n( - Object.assign(Object.assign({}, e), { - variableScopes: C(e.variableScopes), - }), - ); + ((o = $(e, o, t.sortKeyComponents, r)), + P(o, e, (e) => { + ((e.variableScopes = j(e.variableScopes)), + n(e), + e.variableScopes.pop()); })); }), (t.forEachGroup = function (e, t, n) { @@ -2031,7 +2041,7 @@ const o = L(e.variableScopes); let a = []; return ( - O(t, e, (e) => { + P(t, e, (e) => { const t = (0, i.evaluateXPathToString)( n, e.contextItem, @@ -2057,7 +2067,7 @@ s = null, c = []; return ( - O(t, e, (e) => { + P(t, e, (e) => { const t = e.contextItem, l = (0, i.evaluateXPathToString)(n, t, void 0, o, { currentContext: e, @@ -2077,14 +2087,14 @@ let o = [], a = []; return ( - O(t, e, (e) => { + P(t, e, (e) => { const t = e.contextItem; (a.push(t), - T( + y( e.patternMatchCache, n, t, - e.variableScopes, + L(e.variableScopes), r, ) && (F(o, a), (a = []))); }), @@ -2097,13 +2107,13 @@ let o = [], a = []; return ( - O(t, e, (e) => { + P(t, e, (e) => { const t = e.contextItem; - (T( + (y( e.patternMatchCache, n, t, - e.variableScopes, + L(e.variableScopes), r, ) && (F(o, a), (a = [])), a.push(t)); @@ -2112,7 +2122,7 @@ o ); })(e, a, t.groupStartingWith, r)), - (o = P(e, o, t.sortKeyComponents, r)), + (o = $(e, o, t.sortKeyComponents, r)), I(o, e, n)); } }), @@ -2147,11 +2157,11 @@ )); }), (t.mkNodeAppender = k), - (t.mkArrayAppender = z), + (t.mkArrayAppender = G), (t.resultDocument = function (e, t, n) { const r = (0, p.mkResolver)(t.namespaces); function o(t) { - return G(e, t, r); + return z(e, t, r); } const a = o(t.format); let s = (0, p.mkOutputDefinition)({ @@ -2223,7 +2233,7 @@ let n = new Map(); for (const r of t) { const t = (0, p.mkResolver)(r.namespaces); - if (T(n, r.match, e, [], t)) return !r.preserve; + if (y(n, r.match, e, [], t)) return !r.preserve; } return !1; })(o.parentNode, t) && @@ -2234,7 +2244,7 @@ for (let e of r) e.remove(); return e; }), - (t.evaluateAttributeValueTemplate = G), + (t.evaluateAttributeValueTemplate = z), (t.serialize = function (e) { const t = new c.XMLSerializer(); if (!0 !== e.omitXmlDeclaration) { @@ -2295,12 +2305,24 @@ ? e.textContent : e.toString(); } - (Object.defineProperty(t, "greatGrandParentNode", { + (Object.defineProperty(t, "ancestorNodes", { enumerable: !0, get: function () { - return f.greatGrandParentNode; + return f.ancestorNodes; }, }), + Object.defineProperty(t, "greatGrandParentNode", { + enumerable: !0, + get: function () { + return f.greatGrandParentNode; + }, + }), + Object.defineProperty(t, "greatGreatGrandParentNode", { + enumerable: !0, + get: function () { + return f.greatGreatGrandParentNode; + }, + }), Object.defineProperty(t, "grandParentNode", { enumerable: !0, get: function () { @@ -2358,15 +2380,16 @@ } buildDocumentCache(e, t, n) { let r = new Map(); + const o = L(n); return ( h(t, (t) => { if ( "string" == typeof this.use && - T( + y( e, { xpath: this.match }, t, - n, + o, (0, p.mkResolver)(this.namespaces), ) ) { @@ -2389,7 +2412,7 @@ w = new RegExp(/^@[a-z]+$/), N = new RegExp(/text\(\)|node\(\)/), v = new RegExp(/@|attribute|node/); - function T(e, t, n, r, o) { + function y(e, t, n, r, o) { return !( (n && (function (e, t) { @@ -2405,14 +2428,13 @@ let a = e.get(t.xpath); a || ((a = new Map()), e.set(t.xpath, a)); let s = n; - const c = L(r); for (; s; ) { let e = a.get(s); if ( (void 0 === e && ((e = t.compiled ? (0, i.executeJavaScriptCompiledXPath)(t.compiled, s) - : (0, i.evaluateXPathToNodes)(t.xpath, s, void 0, c, { + : (0, i.evaluateXPathToNodes)(t.xpath, s, void 0, r, { namespaceResolver: o, functionNameResolver: u.functionNameResolver, })), @@ -2427,7 +2449,7 @@ })(e, t, n, r, o) ); } - function* y(e) { + function* T(e) { let t = new Set(), n = e.next(); for (; !n.done; ) @@ -2449,11 +2471,12 @@ ("#all" === e.modes[0] || e.modes.includes(r)) && (yield e); })(e.contextItem, e.ruleTree, e.templates, e.mode), o = (function* (e, t, n, r, o, a, s) { - for (let [i, c] of n) { + const i = L(o); + for (let [o, c] of n) { const n = r[c]; - i && + o && ("#all" === n.modes[0] || n.modes.includes(a)) && - T(e, i, t, o, (0, p.mkResolver)(s)) && + y(e, o, t, i, (0, p.mkResolver)(s)) && (yield n); } })( @@ -2465,17 +2488,12 @@ e.mode, n, ), - a = y(b(r, o)); + a = T(b(r, o)); const s = a.next(); - s.done || - j( - s.value, - Object.assign(Object.assign({}, e), { nextMatches: a }), - t, - ); + ((e.nextMatches = a), s.done || C(s.value, e, t)); } function R(e, t, n, r) { - const o = "descending" === G(e, n.order, r); + const o = "descending" === z(e, n.order, r); return "number" === n.dataType ? (function (e, t, n, r, o) { const a = E(t, e, (e) => { @@ -2493,7 +2511,7 @@ })(e, t, n, r, o) : (function (e, t, n, r, o) { const a = E(t, e, (e) => J(e, n.sortKey, r)), - s = n.lang && G(e, n.lang, r); + s = n.lang && z(e, n.lang, r); let i = new Intl.Collator(s).compare; return (0, p.zip)(a, t) .sort(o ? (e, t) => i(t[0], e[0]) : (e, t) => i(e[0], t[0])) @@ -2502,21 +2520,13 @@ } function E(e, t, n) { if (e.length > 0) - return (0, l.isNodeGroupArray)(e) ? I(e, t, n) : O(e, t, n); + return (0, l.isNodeGroupArray)(e) ? I(e, t, n) : P(e, t, n); } - function O(e, t, n) { + function P(e, t, n) { let r = 0; + const o = Object.assign(Object.assign({}, t), { contextList: e }); return e.map( - (o) => ( - r++, - n( - Object.assign(Object.assign({}, t), { - contextItem: o, - contextList: e, - position: r, - }), - ) - ), + (e) => (r++, (o.contextItem = e), (o.position = r), n(o)), ); } function I(e, t, n) { @@ -2528,29 +2538,29 @@ contextList: e.nodes, currentGroup: e, position: r, - variableScopes: C(t.variableScopes), + variableScopes: j(t.variableScopes), }); return n(o); }); } - function P(e, t, n, r) { + function $(e, t, n, r) { if (n) for (let o of [...n].reverse()) t = R(e, t, o, r); return t; } - function $(e, t) { + function O(e, t) { for (let n of t) if (n.name === e) return n; } - function j(e, t, n) { - let r = C(t.variableScopes); + function C(e, t, n) { + let r = j(t.variableScopes); for (let o of e.allowedParams) { - let e = $(o.name, n); + let e = O(o.name, n); void 0 !== e ? _(r, e.name, B(t, e)) : _(r, o.name, B(t, o)); } return e.apply( Object.assign(Object.assign({}, t), { variableScopes: r }), ); } - function C(e) { + function j(e) { return e.concat([new Map()]); } new RegExp(/(^\/$|document-node\(|node\()/); @@ -2587,7 +2597,7 @@ for (let n of e) for (let [e, r] of n) t[e] = r; return t; } - function A(e, t) { + function U(e, t) { let n; return ( (n = @@ -2597,7 +2607,7 @@ n ); } - function U(e, t) { + function A(e, t) { let n; return ( (n = t.namespace @@ -2647,7 +2657,7 @@ } }; } - function z(e) { + function G(e) { return function (t) { if ( (e.push(t), @@ -2658,7 +2668,7 @@ return k(t); }; } - function G(e, t, n) { + function z(e, t, n) { if (!t) return; const r = L(e.variableScopes); return t @@ -2681,7 +2691,7 @@ } function J(e, t, n, r) { r || (r = "string" == typeof t ? [" "] : []); - const o = G(e, r, n); + const o = z(e, r, n); if ("string" == typeof t) { const r = L(e.variableScopes); return (0, i.evaluateXPath)( @@ -2735,9 +2745,9 @@ return ( t( Object.assign(Object.assign({}, e), { - append: z(n), + append: G(n), mode: "#default", - variableScopes: C(e.variableScopes), + variableScopes: j(e.variableScopes), }), ), 1 === n.length ? n[0] : n @@ -2767,7 +2777,7 @@ append: n, outputDocument: e.outputDocument, mode: "#default", - variableScopes: C(e.variableScopes), + variableScopes: j(e.variableScopes), }), ); }); @@ -2782,10 +2792,6 @@ "use strict"; e.exports = require("slimdom"); }, - 16(e) { - "use strict"; - e.exports = require("url"); - }, }, t = {}, n = (function n(r) { @@ -2793,6 +2799,6 @@ if (void 0 !== o) return o.exports; var a = (t[r] = { exports: {} }); return (e[r].call(a.exports, a, a.exports, n), a.exports); - })(882); + })(519); module.exports = n.transform; })(); diff --git a/src/util.ts b/src/util.ts deleted file mode 100644 index 1b26d5a..0000000 --- a/src/util.ts +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2021-2026 Erik Hetzner - * - * This file is part of XJSLT. - * - * XJSLT is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * XJSLT is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with XJSLT. If not, see - * . - */ - -import { DynamicContext } from "./definitions"; - -export function urlToDom(context: DynamicContext, url: string) { - const absoluteURL = context.inputURL - ? new URL(url, context.inputURL.toString()).toString() - : url; - return context.readDocument(absoluteURL); -} diff --git a/src/util.web.ts b/src/util.web.ts deleted file mode 100644 index 67b9154..0000000 --- a/src/util.web.ts +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) 2021-2026 Erik Hetzner - * - * This file is part of XJSLT. - * - * XJSLT is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * XJSLT is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with XJSLT. If not, see - * . - */ - -import { DynamicContext } from "./definitions"; - -export function urlToDom(context: DynamicContext, url: string) { - // TODO -} diff --git a/test/attribute-namespace.spec.ts b/test/attribute-namespace.spec.ts index 6e753d1..76eca6d 100644 --- a/test/attribute-namespace.spec.ts +++ b/test/attribute-namespace.spec.ts @@ -1,4 +1,4 @@ -import { compile } from "../src/compile"; +import { compile } from "../src/compilex"; import * as slimdom from "slimdom"; import { evaluateXPathToNodes } from "fontoxpath"; @@ -14,7 +14,7 @@ test("xsl:attribute unprefixed name gets no namespace even with default namespac `); - const transform = await compile(xslt); + const transform = compile(xslt, new URL("http://example.org")); const result = transform(slimdom.parseXmlDocument("")).get( "#default", ).document; diff --git a/test/xjslt.spec.ts b/test/xjslt.spec.ts index f4f2d08..f1d7bba 100644 --- a/test/xjslt.spec.ts +++ b/test/xjslt.spec.ts @@ -32,13 +32,13 @@ import { dedupGenerator, } from "../src/xjslt"; import { - compile, compileAvtRaw, compileSequenceConstructorNode, compileTopLevelNode, getNodeNS, + rawCompile, } from "../src/compile"; -import { compileFromPath } from "../src/compilex"; +import { compile, compileFromPath } from "../src/compilex"; import { DynamicContext, Template, @@ -80,7 +80,7 @@ ${template} } async function makeTransform(body: string) { - return await compile( + return compile( slimdom.parseXmlDocument(` @@ -89,6 +89,7 @@ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> ${body} `), + new URL("http://example.org"), ); } @@ -355,7 +356,7 @@ test("compile", async () => { const xslt = slimdom.parseXmlDocument( await readFile(`${__dirname}/simple2.xslt`, "utf-8"), ); - const transform = await compile(xslt); + const transform = compile(xslt, new URL("http://example.org")); expect( slimdom.serializeToWellFormedString( transform( @@ -383,12 +384,12 @@ test("compile with readDocument for xsl:include", async () => { `); - const readDocument = (uri: string) => { + const readDocument = async (uri: string) => { if (uri === "included.xsl") return included; throw new Error(`Unexpected URI: ${uri}`); }; - const transform = await compile(xslt, readDocument); + const transform = compile(xslt, new URL("http://example.org")); const result = slimdom.serializeToWellFormedString( transform(slimdom.parseXmlDocument("hello")).get( "#default", @@ -418,7 +419,11 @@ test("compile with readDocument for xsl:import", async () => { throw new Error(`Unexpected URI: ${uri}`); }; - const transform = await compile(xslt, readDocument); + const transform = rawCompile( + xslt, + readDocument, + new URL("http://example.org"), + ); const result = slimdom.serializeToWellFormedString( transform(slimdom.parseXmlDocument("world")).get( "#default", @@ -444,7 +449,7 @@ test("compile with readDocument for runtime doc()", async () => { throw new Error(`Unexpected URI: ${uri}`); }; - const transform = await compile(xslt, readDocument); + const transform = rawCompile(xslt, readDocument); const result = slimdom.serializeToWellFormedString( transform(slimdom.parseXmlDocument(""), { readDocument }).get( "#default", diff --git a/webpack.config.ts b/webpack.config.ts index 0cf36d4..e1baab1 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -20,11 +20,13 @@ const config: webpack.Configuration = { resolve: { extensions: [".web.ts", ".web.js", ".ts", ".js"], }, +optimization: { + minimize: false, + }, output: { library: { name: "xjslt", - type: "umd", - export: "xjslt.compile", + type: "window", }, filename: "xjslt-web.js", path: path.resolve(__dirname, "dist"), From 2834efb4352b6039f5f0903ced4da11d1f01b5b2 Mon Sep 17 00:00:00 2001 From: Erik Hetzner Date: Mon, 8 Jun 2026 15:17:31 -0700 Subject: [PATCH 05/10] fix tests --- test/xjslt.spec.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/test/xjslt.spec.ts b/test/xjslt.spec.ts index f1d7bba..34cdb52 100644 --- a/test/xjslt.spec.ts +++ b/test/xjslt.spec.ts @@ -384,12 +384,16 @@ test("compile with readDocument for xsl:include", async () => { `); - const readDocument = async (uri: string) => { - if (uri === "included.xsl") return included; + const readDocument = (uri: string) => { + if (uri === "http://example.org/included.xsl") return included; throw new Error(`Unexpected URI: ${uri}`); }; - const transform = compile(xslt, new URL("http://example.org")); + const transform = rawCompile( + xslt, + readDocument, + new URL("http://example.org"), + ); const result = slimdom.serializeToWellFormedString( transform(slimdom.parseXmlDocument("hello")).get( "#default", @@ -415,7 +419,7 @@ test("compile with readDocument for xsl:import", async () => { `); const readDocument = (uri: string) => { - if (uri === "base.xsl") return imported; + if (uri === "http://example.org/base.xsl") return imported; throw new Error(`Unexpected URI: ${uri}`); }; @@ -449,7 +453,11 @@ test("compile with readDocument for runtime doc()", async () => { throw new Error(`Unexpected URI: ${uri}`); }; - const transform = rawCompile(xslt, readDocument); + const transform = rawCompile( + xslt, + readDocument, + new URL("http://example.org"), + ); const result = slimdom.serializeToWellFormedString( transform(slimdom.parseXmlDocument(""), { readDocument }).get( "#default", From 7afcc94c4e7cab7fdc70f9fa378b25c87d542d97 Mon Sep 17 00:00:00 2001 From: Erik Hetzner Date: Mon, 8 Jun 2026 15:20:45 -0700 Subject: [PATCH 06/10] drop debug line --- src/compilex.web.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/compilex.web.ts b/src/compilex.web.ts index 9f109ad..304a3ef 100644 --- a/src/compilex.web.ts +++ b/src/compilex.web.ts @@ -7,7 +7,6 @@ function readDocument(uri: string): slimdom.Document { // This should be async, but fontoxpath can't handle async custom // functions, and this is used by those, so it has to be synchronous // for now. - console.log(uri); const xhr = new XMLHttpRequest(); xhr.open("GET", uri, false); xhr.send(null); // blocks From 2a6b99fb0834c5fe9fe48d97851c7a943ad6d011 Mon Sep 17 00:00:00 2001 From: Erik Hetzner Date: Mon, 8 Jun 2026 15:30:50 -0700 Subject: [PATCH 07/10] fix webpack config --- webpack.config.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/webpack.config.ts b/webpack.config.ts index e1baab1..8df6dd7 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -20,9 +20,6 @@ const config: webpack.Configuration = { resolve: { extensions: [".web.ts", ".web.js", ".ts", ".js"], }, -optimization: { - minimize: false, - }, output: { library: { name: "xjslt", From 0504bab796bcb60a9fe23eef97dde58c29f90ab4 Mon Sep 17 00:00:00 2001 From: Erik Hetzner Date: Mon, 8 Jun 2026 15:44:09 -0700 Subject: [PATCH 08/10] move compile to compilex --- src/compile.ts | 49 ----------------------------------- src/compilex.ts | 63 +++++++++++++++++++++++++++++++++++---------- src/compilex.web.ts | 18 ++++++++++--- test/xjslt.spec.ts | 19 +++----------- 4 files changed, 66 insertions(+), 83 deletions(-) diff --git a/src/compile.ts b/src/compile.ts index 5acada0..6e34311 100644 --- a/src/compile.ts +++ b/src/compile.ts @@ -1499,52 +1499,3 @@ export function preprocess( doc = preprocessErrorAnalysis(doc).get("#default").document; return doc; } - -/** - * Compile an XSLT stylesheet document into a callable transform function. - * - * Unlike `compileToFile`, this API accepts an already-parsed document and - * executes the compiled JavaScript in-memory — no temporary files or symlinks - * are created. - * - * @param xslt - The XSLT stylesheet as a parsed slimdom Document. - * @param readDocument - Optional callback to resolve `xsl:include` / - * `xsl:import` hrefs without touching the filesystem. Receives the resolved - * URI (absolute when a base is known, otherwise the raw href) and must - * return a parsed slimdom Document. Also used at runtime for `doc()` calls. - * @returns A transform function with the signature - * `(document, params?) => Map`. - * The `"#default"` key holds the primary output document. - * - * @example - * ```ts - * import * as slimdom from "slimdom"; - * import { compile } from "xjslt/compile"; - * import { serialize } from "xjslt"; - * - * const xslt = slimdom.parseXmlDocument(` - * - * - * - * - * - * `); - * - * const transform = compile(xslt); - * - * const input = slimdom.parseXmlDocument("Hello"); - * const output = transform(input).get("#default"); - * console.log(serialize(output)); // Hello - * ``` - */ -export function rawCompile( - xslt: slimdom.Document, - readDocument: (uri: string) => slimdom.Document, - inputURL: URL, -): StylesheetTransform { - const xsltDoc = preprocess(xslt, inputURL, readDocument); - const code = generate(compileStylesheetNode(xsltDoc.documentElement, true)); - const m: { exports: { transform?: StylesheetTransform } } = { exports: {} }; - new Function("xjslt", "module", code)(xjslt, m); - return m.exports.transform; -} diff --git a/src/compilex.ts b/src/compilex.ts index f4aa60b..2cba726 100644 --- a/src/compilex.ts +++ b/src/compilex.ts @@ -65,7 +65,7 @@ import { mkResolver, sortSortable, } from "./shared"; -import { rawCompile, compileStylesheetNode, preprocess } from "./compile"; +import { compileStylesheetNode, preprocess } from "./compile"; async function readAndParseXml(path: string): Promise { const str = (await readFile(path)).toString(); @@ -84,19 +84,11 @@ function readAndParseXmlSync(path: string): slimdom.Document { export async function compileFromPath( xsltPath: string, ): Promise { - return rawCompile( - await readAndParseXml(xsltPath), - readDocument, - pathToFileURL(xsltPath), - ); + return compile(await readAndParseXml(xsltPath), pathToFileURL(xsltPath)); } export function compileFromPathSync(xsltPath: string): StylesheetTransform { - return rawCompile( - readAndParseXmlSync(xsltPath), - readDocument, - pathToFileURL(xsltPath), - ); + return compile(readAndParseXmlSync(xsltPath), pathToFileURL(xsltPath)); } export async function compileToFile(xsltPath: string) { @@ -120,7 +112,7 @@ export async function compileToFile(xsltPath: string) { const xsltDoc = await preprocess( await readAndParseXml(xsltPath), xsltURL, - readDocument, + readDocumentDefault, ); await writeFile( tempfile, @@ -130,7 +122,7 @@ export async function compileToFile(xsltPath: string) { // rmSync(tempdir, { recursive: true }); } -function readDocument(uri: string): slimdom.Document { +function readDocumentDefault(uri: string): slimdom.Document { if (uri.startsWith("file:")) { return slimdom.parseXmlDocument( readFileSync(fileURLToPath(new URL(uri))).toString(), @@ -139,9 +131,52 @@ function readDocument(uri: string): slimdom.Document { throw new Error(`FODC0005: document ${uri} not found`); } +/** + * Compile an XSLT stylesheet document into a callable transform function. + * + * @param xslt - The XSLT stylesheet as a parsed slimdom Document. + * @param inputURL The input URL, use to resolve relative URLs. + * @param readDocument - Optional callback to override default. Receives the resolved + * URI (absolute when a base is known, otherwise the raw href) and must + * return a parsed slimdom Document. Also used at runtime for `doc()` calls. + * + * @returns A transform function with the signature + * `(document, params?) => Map`. + * The `"#default"` key holds the primary output document. + * + * @example + * ```ts + * import * as slimdom from "slimdom"; + * import { compile } from "xjslt/compilex"; + * import { serialize } from "xjslt"; + * + * const xslt = slimdom.parseXmlDocument(` + * + * + * + * + * + * `); + * + * const transform = compile(xslt, new URL("http://example.org/"); + * + * const input = slimdom.parseXmlDocument("Hello"); + * const output = transform(input).get("#default"); + * console.log(serialize(output)); // Hello + * ``` + */ export function compile( xslt: slimdom.Document, inputURL: URL, + readDocument?: (uri: string) => slimdom.Document, ): StylesheetTransform { - return rawCompile(xslt, readDocument, inputURL); + const xsltDoc = preprocess( + xslt, + inputURL, + readDocument || readDocumentDefault, + ); + const code = generate(compileStylesheetNode(xsltDoc.documentElement, true)); + const m: { exports: { transform?: StylesheetTransform } } = { exports: {} }; + new Function("xjslt", "module", code)(xjslt, m); + return m.exports.transform; } diff --git a/src/compilex.web.ts b/src/compilex.web.ts index 304a3ef..a84e083 100644 --- a/src/compilex.web.ts +++ b/src/compilex.web.ts @@ -1,9 +1,10 @@ +import { generate } from "astring"; import * as slimdom from "slimdom"; - -import { rawCompile } from "./compile"; +import * as xjslt from "./xjslt"; +import { preprocess, compileStylesheetNode } from "./compile"; import { StylesheetTransform } from "./definitions"; -function readDocument(uri: string): slimdom.Document { +function readDocumentDefault(uri: string): slimdom.Document { // This should be async, but fontoxpath can't handle async custom // functions, and this is used by those, so it has to be synchronous // for now. @@ -16,6 +17,15 @@ function readDocument(uri: string): slimdom.Document { export function compile( xslt: slimdom.Document, inputURL: URL, + readDocument?: (uri: string) => slimdom.Document, ): StylesheetTransform { - return rawCompile(xslt, readDocument, inputURL); + const xsltDoc = preprocess( + xslt, + inputURL, + readDocument || readDocumentDefault, + ); + const code = generate(compileStylesheetNode(xsltDoc.documentElement, true)); + const m: { exports: { transform?: StylesheetTransform } } = { exports: {} }; + new Function("xjslt", "module", code)(xjslt, m); + return m.exports.transform; } diff --git a/test/xjslt.spec.ts b/test/xjslt.spec.ts index 34cdb52..ceff396 100644 --- a/test/xjslt.spec.ts +++ b/test/xjslt.spec.ts @@ -36,7 +36,6 @@ import { compileSequenceConstructorNode, compileTopLevelNode, getNodeNS, - rawCompile, } from "../src/compile"; import { compile, compileFromPath } from "../src/compilex"; import { @@ -389,11 +388,7 @@ test("compile with readDocument for xsl:include", async () => { throw new Error(`Unexpected URI: ${uri}`); }; - const transform = rawCompile( - xslt, - readDocument, - new URL("http://example.org"), - ); + const transform = compile(xslt, new URL("http://example.org"), readDocument); const result = slimdom.serializeToWellFormedString( transform(slimdom.parseXmlDocument("hello")).get( "#default", @@ -423,11 +418,7 @@ test("compile with readDocument for xsl:import", async () => { throw new Error(`Unexpected URI: ${uri}`); }; - const transform = rawCompile( - xslt, - readDocument, - new URL("http://example.org"), - ); + const transform = compile(xslt, new URL("http://example.org"), readDocument); const result = slimdom.serializeToWellFormedString( transform(slimdom.parseXmlDocument("world")).get( "#default", @@ -453,11 +444,7 @@ test("compile with readDocument for runtime doc()", async () => { throw new Error(`Unexpected URI: ${uri}`); }; - const transform = rawCompile( - xslt, - readDocument, - new URL("http://example.org"), - ); + const transform = compile(xslt, new URL("http://example.org"), readDocument); const result = slimdom.serializeToWellFormedString( transform(slimdom.parseXmlDocument(""), { readDocument }).get( "#default", From 17d5bc200a2d3bcadf4dbf8bdeef6d50fad6bb44 Mon Sep 17 00:00:00 2001 From: Erik Hetzner Date: Mon, 8 Jun 2026 15:48:21 -0700 Subject: [PATCH 09/10] rename compilex to compile, compile to compileGeneric --- src/cli.ts | 2 +- src/compile.ts | 1515 ++--------------------- src/{compilex.web.ts => compile.web.ts} | 2 +- src/compileGeneric.ts | 1501 ++++++++++++++++++++++ src/compilex.ts | 182 --- src/index.ts | 2 +- test/attribute-namespace.spec.ts | 2 +- test/numbering.spec.ts | 2 +- test/suite.spec.ts | 2 +- test/xjslt.spec.ts | 4 +- 10 files changed, 1607 insertions(+), 1607 deletions(-) rename src/{compilex.web.ts => compile.web.ts} (93%) create mode 100644 src/compileGeneric.ts delete mode 100644 src/compilex.ts diff --git a/src/cli.ts b/src/cli.ts index ccdc4c8..c7f09fe 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -21,7 +21,7 @@ import * as slimdom from "slimdom"; import { Command, Option } from "commander"; -import { compileFromPath, compileToFile } from "./compilex"; +import { compileFromPath, compileToFile } from "./compile"; import { serialize } from "./xjslt"; import { readFile, writeFile } from "fs/promises"; import { pathToFileURL } from "url"; diff --git a/src/compile.ts b/src/compile.ts index 6e34311..98df8b3 100644 --- a/src/compile.ts +++ b/src/compile.ts @@ -50,28 +50,13 @@ import { evaluateXPathToBoolean, evaluateXPathToNodes, } from "fontoxpath"; -import preprocessSimplified from "./preprocess/simplified"; -import preprocessInclude from "./preprocess/include"; -import preprocessImport from "./preprocess/import"; -import preprocessStripWhitespace1 from "./preprocess/stripWhitespace1"; -import preprocessStripWhitespace2 from "./preprocess/stripWhitespace2"; -import preprocessUseWhen from "./preprocess/use-when"; -import preprocessErrorAnalysis from "./preprocess/error-analysis"; -import preprocessAttributeSet from "./preprocess/attribute-set"; -import { - CompileContext, - XSLT1_NSURI, - XMLNS_NSURI, - NodeType, - NumberFormat, - OutputDefinition, - DecimalFormat, - DEFAULT_DECIMAL_FORMAT, - xpathstring, - TemplateForCompilation, - TemplateIndex, - StylesheetTransform, -} from "./definitions"; +import { readFileSync, symlinkSync } from "fs"; +import { readFile, writeFile } from "fs/promises"; +import { pathToFileURL, fileURLToPath } from "url"; +import * as path from "path"; +import { tmpdir } from "os"; +import { mkdtempSync } from "fs"; +import { StylesheetTransform } from "./definitions"; import { compareSortable, computeDefaultPriority, @@ -80,1422 +65,118 @@ import { mkResolver, sortSortable, } from "./shared"; -import { buildRuleTree } from "./dt"; -import { xpathToFeatures, XMLFeature } from "./dt-xml"; - -/** - * Functions to walk a DOM tree of an XSLT stylesheet and generate an - * ESTree that can be used to process an input document. - */ - -interface SimpleElement { - name: string; - hasChildren: boolean; - arguments: Map; - xpathArguments?: Set; -} - -function buildInResolver(prefix: string): string | null { - if (prefix === "xsl") { - return XSLT1_NSURI; - } - return null; -} - -/** Rewrite xpaths to support any workarounds/hacks we need. */ -function hackXpath( - xpath: string | undefined | null, -): string | undefined | null { - if (!xpath) { - return xpath; - } - // Override to use our own position, but only outside square brackets - // and not when preceded by / or :: - let result = ""; - let depth = 0; - let i = 0; - - while (i < xpath.length) { - const char = xpath[i]; - - if (char === "[") { - depth++; - result += char; - i++; - } else if (char === "]") { - depth--; - result += char; - i++; - } else if (depth === 0) { - // We're outside brackets, check for position() or last() - // But not if preceded by / or :: - const precededBySlash = i > 0 && xpath[i - 1] === "/"; - const precededByDoubleColon = i > 1 && xpath.substring(i - 2, i) === "::"; - - if (!precededBySlash && !precededByDoubleColon) { - if (xpath.substring(i).startsWith("position()")) { - result += "positionx()"; - i += "position()".length; - } else if (xpath.substring(i).startsWith("last()")) { - result += "lastx()"; - i += "last()".length; - } else { - result += char; - i++; - } - } else { - result += char; - i++; - } - } else { - // Inside brackets, don't modify - result += char; - i++; - } - } - - return result; -} - -const simpleElements = new Map([ - ["copy", { name: "copy", arguments: new Map(), hasChildren: true }], - [ - "copy-of", - { - name: "copyOf", - arguments: new Map([["select", undefined]]), - xpathArguments: new Set(["select"]), - hasChildren: false, - }, - ], - ["document", { name: "document", arguments: new Map(), hasChildren: true }], - [ - "if", - { - name: "ifX", - arguments: new Map([["test", undefined]]), - xpathArguments: new Set(["test"]), - hasChildren: true, - }, - ], - [ - "message", - { - name: "message", - arguments: new Map([ - ["select", undefined], - ["terminate", "no"], - ]), - xpathArguments: new Set(["select"]), - hasChildren: true, - }, - ], - [ - "sequence", - { - name: "sequence", - arguments: new Map([["select", undefined]]), - xpathArguments: new Set(["select"]), - hasChildren: false, - }, - ], -]); - -function compileApplyTemplatesNode( - node: slimdom.Element, - context: CompileContext, -) { - const mode = expandQname(node.getAttribute("mode"), getNodeNS(node)); - const args = { - select: hackXpath(node.getAttribute("select") || "child::node()"), - mode: mode || "#default", - params: compileParams("with-param", node.childNodes, context), - sortKeyComponents: compileSortKeyComponents(node.childNodes, context), - namespaces: getNodeNS(node), - }; - return compileFuncall("applyTemplates", [toEstree(args)]); -} - -function compileFunctionNode(node: slimdom.Element, context: CompileContext) { - const [namespace, name] = resolveQname( - node.getAttribute("name"), - getNodeNS(node), - ); - const args = { - name: name, - namespace: namespace, - as: node.getAttribute("as"), - params: compileParams("param", node.childNodes, context), - namespaces: getNodeNS(node), - }; - return mkCall(mkMember("xjslt", "functionX"), [ - toEstree(args), - mkArrowFun(compileSequenceConstructor(node.childNodes, context)), - ]); -} - -/** - * Try to precompile an xpath. - * Returns an AST node for a compiled match function, or undefined literal if compilation fails. - */ -function tryCompilePattern( - pattern: string | null | undefined, - namespaces: object, -): any { - if (!pattern) { - return mkLiteral(undefined); - } +import { compileStylesheetNode, preprocess } from "./compileGeneric"; - const compiled = compileXPathToJavaScript(pattern, evaluateXPath.NODES_TYPE, { - namespaceResolver: mkResolver(namespaces), - }); - let compiledFunc: any = mkLiteral(undefined); - // Apparently a bug in fontoxpath - if (compiled.isAstAccepted && !compiled.code.includes('"name-*"')) { - compiledFunc = { - type: "CallExpression", - callee: mkMember("xjslt", "compileMatchFunction"), - arguments: [mkLiteral(compiled.code)], - optional: false, - }; - } - return toEstree({ - xpath: mkLiteral(pattern), - compiled: compiledFunc, - }); +async function readAndParseXml(path: string): Promise { + const str = (await readFile(path)).toString(); + return slimdom.parseXmlDocument(str); } -function compileForEachNode(node: slimdom.Element, context: CompileContext) { - const args = { - select: hackXpath(node.getAttribute("select")), - sortKeyComponents: compileSortKeyComponents(node.childNodes, context), - namespaces: getNodeNS(node), - }; - return compileFuncallWithChildren(node, "forEach", toEstree(args), context); -} - -function compileForEachGroupNode( - node: slimdom.Element, - context: CompileContext, -) { - const namespaces = getNodeNS(node); - - // Precompile patterns if possible - const groupStartingWith = tryCompilePattern( - node.getAttribute("group-starting-with"), - namespaces, - ); - const groupEndingWith = tryCompilePattern( - node.getAttribute("group-ending-with"), - namespaces, - ); - - return compileFuncallWithChildren( - node, - "forEachGroup", - toEstree({ - select: hackXpath(node.getAttribute("select")), - groupBy: hackXpath(node.getAttribute("group-by")), - groupAdjacent: hackXpath(node.getAttribute("group-adjacent")), - groupStartingWith: groupStartingWith, - groupEndingWith: groupEndingWith, - sortKeyComponents: compileSortKeyComponents(node.childNodes, context), - namespaces: namespaces, - }), - context, - ); +function readAndParseXmlSync(path: string): slimdom.Document { + const str = readFileSync(path).toString(); + return slimdom.parseXmlDocument(str); } /** - * Parse format tokens from a format string at compile time. - * The first token never has a separator. + * Build a stylesheet. Returns a function that will take an input DOM + * document and return an output DOM document. */ -export function parseNumberFormat(format: string): NumberFormat { - let retval: NumberFormat = { - prefix: undefined, - suffix: undefined, - formats: [], - }; - let currentAlpha = ""; - let currentNonAlpha = ""; - let inAlpha = false; - - for (let i = 0; i < format.length; i++) { - const ch = format[i]; - if (isAlphanumeric(ch)) { - if (inAlpha) { - // Continue building the current token - currentAlpha += ch; - } else { - // Transition from non-alpha -> alpha (starting a new token) - if (retval.formats.length === 0) { - // First token - what we've seen so far is the prefix - if (currentNonAlpha) { - retval.prefix = currentNonAlpha; - } - currentNonAlpha = ""; - } - currentAlpha = ch; - inAlpha = true; - } - } else { - // Non-alphanumeric character found - if (inAlpha) { - // Ending a token - push it with its separator - retval.formats.push({ - format: currentAlpha, - separator: currentNonAlpha || ".", - }); - currentAlpha = ""; - currentNonAlpha = ""; - inAlpha = false; - } - currentNonAlpha += ch; - } - } - - // Add the last token if we were in alpha mode - if (inAlpha && currentAlpha) { - retval.formats.push({ - format: currentAlpha, - separator: currentNonAlpha || ".", - }); - } else { - // Any remaining non-alpha text is the suffix - retval.suffix = currentNonAlpha || undefined; - } - - if (retval.formats.length === 0) { - // Defaults per spec. - retval.prefix = retval.suffix; - retval.formats.push({ format: "1", separator: "." }); - } - - return retval; -} - -function compileNumberNode(node: slimdom.Element, context: CompileContext) { - const namespaces = getNodeNS(node); - const format = node.getAttribute("format") || "1"; - - // Precompile patterns if possible - const count = tryCompilePattern(node.getAttribute("count"), namespaces); - const from = tryCompilePattern(node.getAttribute("from"), namespaces); - - return compileFuncall("number", [ - toEstree({ - value: hackXpath(node.getAttribute("value")), - select: hackXpath(node.getAttribute("select")), - count: count, - from: from, - level: node.getAttribute("level") || "single", - format: parseNumberFormat(format), - lang: node.getAttribute("lang"), - letterValue: node.getAttribute("letter-value"), - ordinal: node.getAttribute("ordinal"), - groupingSeparator: node.getAttribute("grouping-separator"), - groupingSize: parseInt(node.getAttribute("grouping-size")), - namespaces: namespaces, - }), - ]); -} - -function compilePerformSortNode( - node: slimdom.Element, - context: CompileContext, -) { - return compileFuncall("performSort", [ - toEstree({ - select: hackXpath(node.getAttribute("select")), - sortKeyComponents: compileSortKeyComponents(node.childNodes, context), - namespaces: getNodeNS(node), - }), - ]); -} - -function compileNextMatchNode(node: slimdom.Element, context: CompileContext) { - return compileFuncall("nextMatch", [ - toEstree({ - params: compileParams("with-param", node.childNodes, context), - namespaces: getNodeNS(node), - }), - ]); -} - -function compileApplyImportsNodes( - node: slimdom.Element, - context: CompileContext, -) { - return compileFuncall("applyImports", [ - toEstree({ - params: compileParams("with-param", node.childNodes, context), - namespaces: getNodeNS(node), - }), - ]); -} - -/* Compile a param or variable, which contains either a select - statement or a SequenceConstructor. */ -function compileVariableLike(node: slimdom.Element, context: CompileContext) { - const name = node.getAttribute("name"); - const as = node.getAttribute("as"); - if (node.hasAttribute("select")) { - return toEstree({ - name: name, - content: hackXpath(node.getAttribute("select")), - namespaces: getNodeNS(node), - as: as, - }); - } else if (node.hasChildNodes()) { - return toEstree({ - name: name, - content: mkArrowFun(compileSequenceConstructor(node.childNodes, context)), - namespaces: getNodeNS(node), - as: as, - }); - } else { - return toEstree({ - name: name, - content: undefined, - namespaces: {}, - as: as, - }); - } -} - -function compileSortKeyComponents(nodes: any[], context: CompileContext) { - let sortKeyComponents = []; - for (let node of nodes) { - if (node.localName === "sort") { - const args = { - namespaces: getNodeNS(node), - order: compileAvt(node.getAttribute("order")), - lang: compileAvt(node.getAttribute("lang")), - dataType: node.getAttribute("data-type"), - }; - if (node.hasChildNodes()) { - sortKeyComponents.push( - toEstree({ - ...args, - sortKey: mkArrowFun( - compileSequenceConstructor(node.childNodes, context), - ), - }), - ); - } else { - sortKeyComponents.push( - toEstree({ - ...args, - sortKey: hackXpath(node.getAttribute("select") || "."), - }), - ); - } - } - } - return toEstree(sortKeyComponents); -} - -function compileVariable(node: slimdom.Element, context: CompileContext) { - return compileFuncall("variable", [compileVariableLike(node, context)]); -} - -function compileParams( - nodename: string, - nodes: any[], - context: CompileContext, -) { - let params = []; - for (let node of nodes) { - if (node.localName === nodename) { - params.push(compileVariableLike(node, context)); - } - } - return toEstree(params); -} - -function compileCallTemplate(node: slimdom.Element, context: CompileContext) { - let args = {}; - let name = expandQname(node.getAttribute("name"), getNodeNS(node)); - args["name"] = name; - if (!args["name"]) { - throw new Error(""); - } - args["params"] = compileParams("with-param", node.childNodes, context); - return compileFuncall("callTemplate", [toEstree(args)]); -} - -function compileResultDocument(node: slimdom.Element, context: CompileContext) { - const args = { - format: compileAvt(node.getAttribute("format")), - href: compileAvt(node.getAttribute("href")), - omitXmlDeclaration: compileAvt(node.getAttribute("omit-xml-declaration")), - doctypeSystem: compileAvt(node.getAttribute("doctype-system")), - doctypePublic: compileAvt(node.getAttribute("doctype-public")), - standalone: compileAvt(node.getAttribute("standalone")), - namespaces: getNodeNS(node), - }; - return compileFuncallWithChildren( - node, - "resultDocument", - toEstree(args), - context, - ); -} - -function compileFuncall(name: string, args: Expression[]) { - return mkCallWithContext(mkMember("xjslt", name), args); -} - -function compileFuncallWithChildren( - node: slimdom.Element, - name: string, - args: ObjectExpression, - context: CompileContext, -): ExpressionStatement { - return mkCallWithContext(mkMember("xjslt", name), [ - args, - mkArrowFun(compileSequenceConstructor(node.childNodes, context)), - ]); -} - -function compileArgs( - node: slimdom.Element, - keyList: Map, - xpathKeys: Set = new Set(), -): ObjectExpression { - var args = {}; - for (let [key, fallback] of keyList) { - let value = node.getAttribute(key); - if (value === null) { - value = fallback; - } - args[key] = xpathKeys.has(key) ? hackXpath(value) : value; - } - args["namespaces"] = getNodeNS(node); - return toEstree(args); -} - -function compileSimpleElement(node: slimdom.Element, context: CompileContext) { - const what = simpleElements.get(node.localName); - const args = compileArgs(node, what.arguments, what.xpathArguments); - if (what.hasChildren) { - return compileFuncallWithChildren(node, what.name, args, context); - } else { - return compileFuncall(what.name, [args]); - } -} - -function compileChooseNode(node: slimdom.Element, context: CompileContext) { - let alternatives = []; - for (let childNode of node.childNodes) { - if (childNode.nodeType === node.ELEMENT_NODE) { - const childElement = childNode as slimdom.Element; - if (childElement.localName === "when") { - alternatives.push( - toEstree({ - test: hackXpath(childElement.getAttribute("test")), - apply: mkArrowFun( - compileSequenceConstructor(childElement.childNodes, context), - ), - }), - ); - } else if (childElement.localName === "otherwise") { - alternatives.push( - toEstree({ - apply: mkArrowFun( - compileSequenceConstructor(childNode.childNodes, context), - ), - }), - ); - } - } - } - return mkCallWithContext(mkMember("xjslt", "choose"), [ - mkArray(alternatives), - ]); -} - -function compileStylesheetParam( - node: slimdom.Element, - context: CompileContext, -) { - let param = compileVariableLike(node, context); - return mkCallWithContext(mkMember("xjslt", "param"), [param]); -} - -function compileWhitespaceDeclarationNode( - node: slimdom.Element, - preserve: boolean, - context: CompileContext, -) { - context.whitespaceDeclarations.push( - ...node - .getAttribute("elements") - .split(/[\n\r\t ]+/) - .map((e) => { - return { - importPrecedence: - parseInt(node.getAttribute("import-precedence")) || 1, - match: toEstree({ - xpath: mkLiteral(e), - }), - preserve: preserve, - namespaces: getNodeNS(node), - priority: computeDefaultPriority(e), - declarationOrder: ++context.declarationCounter, - }; - }), - ); -} - -function skipAttribute(attr: slimdom.Attr): boolean { - if (attr.namespaceURI == XMLNS_NSURI && attr.value === XSLT1_NSURI) { - return true; - } - // Skip XSLT attributes (like xsl:version) on literal result elements - if (attr.namespaceURI === XSLT1_NSURI) { - return true; - } - return false; -} - -function compileLiteralElementNode( - node: slimdom.Element, - context: CompileContext, -) { - let attributes = []; - for (let n in node.attributes) { - let attr = node.attributes[n]; - if (skipAttribute(attr)) { - continue; - } - attributes.push( - toEstree({ - name: attr.name, - value: compileAvt(attr.value), - namespace: attr.namespaceURI || undefined, - }), - ); - } - /* The DOM API is so confusing... we don't need to do this with - attributes. */ - let name = node.localName; - if (node.prefix) { - name = `${node.prefix}:${name}`; - } - return mkCallWithContext(mkMember("xjslt", "literalElement"), [ - toEstree({ - name: name, - attributes: attributes, - namespace: node.namespaceURI, - namespaces: getNodeNS(node), - }), - mkArrowFun(compileSequenceConstructor(node.childNodes, context)), - ]); -} - -export function getNodeNS(node: slimdom.Element, retval: object = undefined) { - if (!retval) { - retval = {}; - } - if (node.parentElement) { - getNodeNS(node.parentElement, retval); - } - if (node.attributes) { - for (let attribute of node.attributes) { - if (attribute.namespaceURI === XMLNS_NSURI) { - let name = attribute.localName; - if (name === "xmlns") { - name = ""; - } - retval[name] = attribute.value; - } - } - } - - const xpathDefaultNs = - node.getAttribute("xpath-default-namespace") || - node.getAttributeNS(XSLT1_NSURI, "xpath-default-namespace"); - if (xpathDefaultNs !== null) { - retval["#xpath-default"] = xpathDefaultNs; - } - - return retval; -} - -/* todo - separate into top-level & sequence-generator versions */ -export function compileTopLevelNode( - node: slimdom.Element, - context: CompileContext, -) { - if (node.nodeType === NodeType.ELEMENT) { - if (node.namespaceURI === XSLT1_NSURI) { - if (node.localName === "template") { - return compileTemplateNode(node, context); - } else if (node.localName === "variable") { - return compileVariable(node, context); - } else if (node.localName === "param") { - return compileStylesheetParam(node, context); - } else if (node.localName === "key") { - return compileKeyNode(node, context); - } else if (node.localName === "function") { - return compileFunctionNode(node, context); - } else if (node.localName === "output") { - return compileOutputNode(node); - } else if (node.localName === "decimal-format") { - return compileDecimalFormatNode(node); - } else if ( - node.localName === "attribute-set" || - node.localName === "character-map" || - node.localName === "import-schema" || - node.localName === "namespace-alias" - ) { - return undefined; - } else if (node.localName === "preserve-space") { - return compileWhitespaceDeclarationNode(node, true, context); - } else if (node.localName === "strip-space") { - return compileWhitespaceDeclarationNode(node, false, context); - } else { - throw new Error( - "XTSE0010: Found unexpected XSL element: " + node.tagName, - ); - } - } - } -} - -export function compileOutputNode(node: slimdom.Element) { - const name = node.getAttribute("name") || "#default"; - const outputDefinition: OutputDefinition = mkOutputDefinition({ - omitXmlDeclaration: node.getAttribute("omit-xml-declaration") || undefined, - doctypeSystem: node.getAttribute("doctype-system") || undefined, - doctypePublic: node.getAttribute("doctype-public") || undefined, - standalone: node.getAttribute("standalone") || undefined, - }); - let tmp = {}; - for (const key in outputDefinition) { - tmp[key] = outputDefinition[key]; - } - if (!name) { - mkCall(mkMember("outputDefinitions", "set"), [ - { - type: "ObjectExpression", - properties: [ - { type: "SpreadElement", argument: toEstree(tmp) }, - { - type: "SpreadElement", - argument: { - type: "CallExpression", - callee: mkMember("outputDefinitions", "get"), - arguments: [mkLiteral("#default")], - optional: false, - }, - }, - ], - }, - ]); - } else { - return mkCall(mkMember("outputDefinitions", "set"), [ - toEstree(name), - toEstree(tmp), - ]); - } -} - -export function compileDecimalFormatNode(node: slimdom.Element) { - const name = node.getAttribute("name") || "#default"; - const attrs = Object.fromEntries( - Object.entries({ - decimalSeparator: node.getAttribute("decimal-separator"), - digit: node.getAttribute("digit"), - groupingSeparator: node.getAttribute("grouping-separator"), - infinity: node.getAttribute("infinity"), - minusSign: node.getAttribute("minus-sign"), - nan: node.getAttribute("NaN"), - patternSeparator: node.getAttribute("pattern-separator"), - percent: node.getAttribute("percent"), - perMille: node.getAttribute("per-mille"), - zeroDigit: node.getAttribute("zero-digit"), - }).filter(([_, v]) => v !== null), - ); - const fmt: DecimalFormat = { - ...DEFAULT_DECIMAL_FORMAT, - ...attrs, - }; - return mkCall(mkMember("decimalFormats", "set"), [ - toEstree(name), - toEstree(fmt), - ]); +export async function compileFromPath( + xsltPath: string, +): Promise { + return compile(await readAndParseXml(xsltPath), pathToFileURL(xsltPath)); } -export function compileSequenceConstructorNode( - node: slimdom.Element, - context: CompileContext, -) { - if (node.nodeType === NodeType.TEXT) { - return compileLiteralTextNode(node); - } else if (node.nodeType === NodeType.ELEMENT) { - if (node.namespaceURI === XSLT1_NSURI) { - if ( - node.hasAttribute("use-when") && - !evaluateXPathToBoolean(node.getAttribute("use-when")) - ) { - return undefined; - } - if (simpleElements.has(node.localName)) { - return compileSimpleElement(node, context); - } else if (node.localName === "apply-imports") { - return compileApplyImportsNodes(node, context); - } else if (node.localName === "apply-templates") { - return compileApplyTemplatesNode(node, context); - } else if (node.localName === "attribute") { - return compileAttributeNode(node, context); - } else if (node.localName === "choose") { - return compileChooseNode(node, context); - } else if (node.localName === "call-template") { - return compileCallTemplate(node, context); - } else if (node.localName === "comment") { - return compileCommentNode(node, context); - } else if (node.localName === "element") { - return compileElementNode(node, context); - } else if (node.localName === "for-each") { - return compileForEachNode(node, context); - } else if (node.localName === "for-each-group") { - return compileForEachGroupNode(node, context); - } else if (node.localName === "perform-sort") { - return compilePerformSortNode(node, context); - } else if (node.localName === "namespace") { - return compileNamespaceNode(node, context); - } else if (node.localName === "next-match") { - return compileNextMatchNode(node, context); - } else if (node.localName === "number") { - return compileNumberNode(node, context); - } else if (node.localName === "param") { - // Handled by special case. - } else if (node.localName === "processing-instruction") { - return compileProcessingInstruction(node, context); - } else if (node.localName === "result-document") { - return compileResultDocument(node, context); - } else if (node.localName === "sort") { - // Handled by special case. - } else if (node.localName === "text") { - return compileTextNode(node); - } else if (node.localName === "variable") { - return compileVariable(node, context); - } else if (node.localName === "strip-space") { - return undefined; - } else if (node.localName === "value-of") { - return compileValueOf(node, context); - } else { - throw new Error( - "XTSE0010: Found unexpected XSL element: " + node.tagName, - ); - } - } else { - return compileLiteralElementNode(node, context); - } - } -} - -function compileElementNode(node: slimdom.Element, context: CompileContext) { - return compileFuncallWithChildren( - node, - "element", - toEstree({ - name: compileAvt(node.getAttribute("name")), - namespace: compileAvt(node.getAttribute("namespace")), - namespaces: getNodeNS(node), - }), - context, - ); -} - -function compileAttributeNode(node: slimdom.Element, context: CompileContext) { - return compileFuncallWithChildren( - node, - "attribute", - toEstree({ - name: compileAvt(node.getAttribute("name")), - separator: compileAvt(node.getAttribute("separator")), - select: hackXpath(node.getAttribute("select")), - namespace: compileAvt(node.getAttribute("namespace")), - namespaces: getNodeNS(node), - }), - context, - ); +export function compileFromPathSync(xsltPath: string): StylesheetTransform { + return compile(readAndParseXmlSync(xsltPath), pathToFileURL(xsltPath)); } -function compileProcessingInstruction( - node: slimdom.Element, - context: CompileContext, -) { - return compileFuncallWithChildren( - node, - "processingInstruction", - toEstree({ - select: hackXpath(node.getAttribute("select")), - name: compileAvt(node.getAttribute("name")), - namespaces: getNodeNS(node), - }), - context, +export async function compileToFile(xsltPath: string) { + let slimdom_path = require.resolve("slimdom").split(path.sep); + let root_dir = path.join( + "/", + ...slimdom_path.slice(0, slimdom_path.indexOf("node_modules")), ); -} - -function compileNamespaceNode(node: slimdom.Element, context: CompileContext) { - return compileFuncallWithChildren( - node, - "namespace", - toEstree({ - select: hackXpath(node.getAttribute("select")), - name: compileAvt(node.getAttribute("name")), - namespaces: getNodeNS(node), - }), - context, + var tempdir = mkdtempSync(path.join(tmpdir(), "xjslt-")); + symlinkSync( + path.join(root_dir, "node_modules"), + path.join(tempdir, "node_modules"), ); -} - -function compileCommentNode(node: slimdom.Element, context: CompileContext) { - return compileFuncallWithChildren( - node, - "comment", - toEstree({ - select: hackXpath(node.getAttribute("select")), - namespaces: getNodeNS(node), - }), - context, + symlinkSync( + path.join(root_dir, "package.json"), + path.join(tempdir, "package.json"), ); -} - -function compileValueOf(node: slimdom.Element, context: CompileContext) { - return compileFuncallWithChildren( - node, - "valueOf", - toEstree({ - select: hackXpath(node.getAttribute("select")), - separator: compileAvt(node.getAttribute("separator")), - namespaces: getNodeNS(node), - }), - context, + symlinkSync(path.join(root_dir, "dist"), path.join(tempdir, "dist")); + var tempfile = path.join(tempdir, "transform.js"); + const xsltURL = pathToFileURL(xsltPath); + const xsltDoc = await preprocess( + await readAndParseXml(xsltPath), + xsltURL, + readDocumentDefault, ); -} - -function compileTextNode(node: slimdom.Element) { - if (node.nodeType === node.ELEMENT_NODE && node.childElementCount > 0) { - throw new Error("XTSE0010 element found as child of xsl:text"); - } - return mkCallWithContext(mkMember("xjslt", "text"), [ - toEstree({ - disableOutputEscaping: false, // TODO - }), - mkArrowFun([compileLiteralTextNode(node)]), - ]); -} - -function compileNodeArray( - nodes: Array, - context: CompileContext, - compilerFunc: (node: any, context: CompileContext) => Statement | void, -): Array { - let body = []; - for (let n in nodes) { - let compiled = compilerFunc(nodes[n], context); - if (compiled) body.push(compiled); - } - return body; -} - -function compileSequenceConstructor( - nodes: Array, - context: CompileContext, -): Array { - return compileNodeArray(nodes, context, compileSequenceConstructorNode); -} - -/** Only one named template "wins" - the highest priority one. Map the array to the first element. */ -function buildNamedTemplates( - namedTemplates: Map>, -) { - const retval = new Map( - Array.from(namedTemplates).map(([key, value]) => [key, value[0]]), + await writeFile( + tempfile, + generate(compileStylesheetNode(xsltDoc.documentElement)), ); - return toEstree(retval); -} - -export function compileStylesheetNode( - node: slimdom.Element, - injectDeps = false, -): Program { - let context: CompileContext = { - declarationCounter: 0, - namedTemplates: new Map(), - nonRuleTemplates: [], - rules: [], - templates: [], - whitespaceDeclarations: [], - }; - setupBuiltinTemplates(context, getNodeNS(node)); - return { - type: "Program", - sourceType: "module", - body: [ - ...(injectDeps ? [] : mkImportsNode()), - mkFun( - mkIdentifier("transform"), - [mkIdentifier("document"), mkIdentifier("params")], - mkBlock([ - { - type: "ExpressionStatement", - expression: { - type: "AssignmentExpression", - operator: "=", - left: mkIdentifier("params"), - right: { - type: "CallExpression", - callee: mkMember("xjslt", "setParamDefaults"), - arguments: [mkIdentifier("document"), mkIdentifier("params")], - optional: false, - }, - }, - }, - mkLet( - mkIdentifier("resultDocuments"), - mkNew(mkIdentifier("Map"), []), - ), - mkCall(mkMember("resultDocuments", "set"), [ - mkLiteral("#default"), - toEstree({ document: mkMember("params", "outputDocument") }), - ]), - mkLet(mkIdentifier("keys"), mkNew(mkIdentifier("Map"), [])), - mkLet( - mkIdentifier("outputDefinitions"), - mkNew(mkIdentifier("Map"), []), - ), - mkLet(mkIdentifier("decimalFormats"), mkNew(mkIdentifier("Map"), [])), - /* First compile the keys */ - ...compileNodeArray( - evaluateXPathToNodes("./xsl:key", node, undefined, undefined, { - namespaceResolver: buildInResolver, - }), - context, - compileTopLevelNode, - ), - /* Then the functions */ - ...compileNodeArray( - evaluateXPathToNodes("./xsl:function", node, undefined, undefined, { - namespaceResolver: buildInResolver, - }), - context, - compileTopLevelNode, - ), - /* Then the output definitions */ - ...compileNodeArray( - evaluateXPathToNodes("./xsl:output", node, undefined, undefined, { - namespaceResolver: buildInResolver, - }), - context, - compileTopLevelNode, - ), - /* Then the decimal formats */ - ...compileNodeArray( - evaluateXPathToNodes( - "./xsl:decimal-format", - node, - undefined, - undefined, - { namespaceResolver: buildInResolver }, - ), - context, - compileTopLevelNode, - ), - /* Then compile the templates */ - ...compileNodeArray( - evaluateXPathToNodes("./xsl:template", node, undefined, undefined, { - namespaceResolver: buildInResolver, - }), - context, - compileTopLevelNode, - ), - mkLet( - mkIdentifier("context"), - toEstree({ - outputDocument: mkMember("params", "outputDocument"), - append: { - type: "CallExpression", - callee: mkMember("xjslt", "mkNodeAppender"), - arguments: [mkMember("params", "outputNode")], - optional: false, - }, - resultDocuments: mkIdentifier("resultDocuments"), - contextItem: mkIdentifier("document"), - contextList: mkArray([mkIdentifier("document")]), - position: mkLiteral(1), - mode: mkMember("params", "initialMode"), - templates: context.templates, - nonRuleTemplateIndexes: context.nonRuleTemplates.sort((a, b) => - compareSortable( - context.templates[a[1]], - context.templates[b[1]], - ), - ), - namedTemplates: buildNamedTemplates(context.namedTemplates), - variableScopes: [mkNew(mkIdentifier("Map"), [])], - inputURL: mkMember("params", "inputURL"), - ruleTree: toEstree(buildRuleTree(context.rules)), - readDocument: mkMember("params", "readDocument"), - keys: mkIdentifier("keys"), - outputDefinitions: mkIdentifier("outputDefinitions"), - decimalFormats: mkIdentifier("decimalFormats"), - patternMatchCache: mkNew(mkIdentifier("Map"), []), - stylesheetParams: mkMember("params", "stylesheetParams"), - }), - ), - mkCallWithContext(mkMember("xjslt", "initialize"), [ - toEstree(getNodeNS(node)), - ]), - /* Then everything else */ - ...compileNodeArray( - evaluateXPathToNodes( - "./xsl:*[local-name()!='template' and local-name()!='key' and local-name()!='function' and local-name()!='output' and local-name()!='decimal-format']", - node, - undefined, - undefined, - { namespaceResolver: buildInResolver }, - ), - context, - compileTopLevelNode, - ), - mkCall(mkMember("xjslt", "stripSpace"), [ - mkIdentifier("document"), - toEstree(sortSortable(context.whitespaceDeclarations)), - ]), - mkCallWithContext(mkMember("xjslt", "processNode"), [ - toEstree([]), - toEstree(getNodeNS(node)), - ]), - mkReturn(mkIdentifier("resultDocuments")), - ]), - ), - { - type: "ExpressionStatement", - expression: { - type: "AssignmentExpression", - operator: "=", - left: { - type: "MemberExpression", - object: mkMember("module", "exports"), - property: mkIdentifier("transform"), - computed: false, - optional: false, - }, - right: mkIdentifier("transform"), - }, - }, - { - type: "ExpressionStatement", - expression: { - type: "AssignmentExpression", - operator: "=", - left: { - type: "MemberExpression", - object: mkIdentifier("global"), - property: mkIdentifier("transform"), - computed: false, - optional: false, - }, - right: mkIdentifier("transform"), - }, - }, - ], - }; -} - -function expandQname(name: string | null, namespaces: object) { - if (!name) { - return name; - } - const [prefix, localName] = name.split(":"); - if (localName && namespaces[prefix]) { - return `${namespaces[prefix]}#${localName}`; - } - return name; -} - -function resolveQname(name: string | null, namespaces: object) { - if (!name) { - return [undefined, name]; - } - const [prefix, localName] = name.split(":"); - if (localName && namespaces[prefix]) { - return [namespaces[prefix], localName]; - } - return [undefined, name]; -} - -function setupTemplate( - name: string, - matchStr: string, - context: CompileContext, - template: TemplateForCompilation, -) { - const index = context.templates.length; - context.templates.push(template); - if (name) { - if (!context.namedTemplates.has(name)) { - context.namedTemplates.set(name, [index]); - } else { - let templates = context.namedTemplates.get(name); - templates.push(index); - templates.sort((a, b) => - compareSortable(context.templates[a], context.templates[b]), - ); - context.namedTemplates.set(name, templates); - } - } - if (matchStr !== undefined) { - for (const subMatch of matchStr.split("|").map((s) => s.trim())) { - const features: XMLFeature[] = xpathToFeatures(subMatch); - if (features) { - context.rules.push({ result: index, features }); - } else { - const match = tryCompilePattern(subMatch, template.namespaces); - context.nonRuleTemplates.push([match, index]); - } - } - } -} - -function compileTemplateNode(node: slimdom.Element, context: CompileContext) { - let allowedParams = compileParams("param", node.childNodes, context); - let namespaces = getNodeNS(node); - const matchStr = node.getAttribute("match") || undefined; - const name = expandQname(node.getAttribute("name"), namespaces) || undefined; - const template: TemplateForCompilation = { - modes: (node.getAttribute("mode") || "#default") - .split(" ") - .filter((s) => s !== "") - .map((m) => expandQname(m.trim(), namespaces)), - allowedParams: allowedParams, - apply: mkArrowFun( - compileNodeArray( - node.childNodes, - context, - compileSequenceConstructorNode, - ), - ), - namespaces: namespaces, - priority: - parseFloat(node.getAttribute("priority")) || - computeDefaultPriority(matchStr), - declarationOrder: ++context.declarationCounter, - importPrecedence: parseInt(node.getAttribute("import-precedence")) || 1, - }; - setupTemplate(name, matchStr, context, template); -} - -function setupBuiltinTemplates(context: CompileContext, namespaces: object) { - setupTemplate(undefined, "processing-instruction()|comment()", context, { - apply: mkArrowFun([]), - allowedParams: [], - modes: ["#all"], - namespaces: namespaces, - importPrecedence: Number.MAX_VALUE, - declarationOrder: Number.MIN_VALUE, - }); - setupTemplate(undefined, "text()|@*", context, { - apply: mkArrowFun([ - mkCallWithContext(mkMember("xjslt", "valueOf"), [ - toEstree({ - select: ".", - separator: undefined, - namespaces: namespaces, - }), - ]), - ]), - allowedParams: [], - modes: ["#all"], - namespaces: namespaces, - importPrecedence: Number.MAX_VALUE, - declarationOrder: Number.MIN_VALUE, - }); - setupTemplate(undefined, "*|/", context, { - apply: mkArrowFun([ - mkCallWithContext(mkMember("xjslt", "applyTemplates"), [ - toEstree({ - select: "child::node()", - params: [], - mode: "#current", - namespaces: namespaces, - sortKeyComponents: [], - }), - ]), - ]), - allowedParams: [], - modes: ["#all"], - namespaces: namespaces, - importPrecedence: Number.MAX_VALUE, - declarationOrder: Number.MIN_VALUE, - }); -} - -function compileKeyNode( - node: slimdom.Element, - context: CompileContext, -): ExpressionStatement { - let namespaces = getNodeNS(node); - - return mkCall(mkMember("keys", "set"), [ - mkLiteral(expandQname(node.getAttribute("name"), namespaces)), - mkNew(mkMember("xjslt", "KeyImpl"), [ - mkLiteral(node.getAttribute("match")), - node.getAttribute("use") - ? mkLiteral(node.getAttribute("use")) - : mkArrowFun( - compileNodeArray( - node.childNodes, - context, - compileSequenceConstructorNode, - ), - ), - toEstree(getNodeNS(node)), - ]), - ]); -} - -function compileLiteralTextNode(node: slimdom.Element): ExpressionStatement { - return mkCallWithContext(mkMember("xjslt", "literalText"), [ - mkLiteral(node.textContent), - ]); -} - -export function compileAvtRaw(avt: string | undefined | null): any { - if (avt === undefined || avt === null) { - return undefined; - } - let retval: Array = []; - let strOutput: string = ""; - let xpathOutput: xpathstring = { xpath: "" }; - let inXpath = false; - for (let i = 0; i < avt.length; i++) { - if (avt[i] === "{") { - if (i + 1 < avt.length && avt[i + 1] === "{") { - // quoted { - i++; - strOutput += "{"; - } else { - // starting xpath - if (inXpath) { - throw new Error(); - } - if (strOutput != "") { - retval = retval.concat(strOutput); - } - strOutput = ""; - inXpath = true; - } - } else if (avt[i] === "}") { - if (i + 1 < avt.length && avt[i + 1] === "}") { - // quoted } - i++; - strOutput += "}"; - } else { - if (!inXpath) { - throw new Error("XTSE0370"); - } - // Ending xpath - retval = retval.concat({ xpath: hackXpath(xpathOutput.xpath) }); - xpathOutput = { xpath: "" }; - inXpath = false; - } - } else { - if (inXpath) { - if (avt[i] === "'" || avt[i] === '"') { - /* In a silly exception, you don't need to escape braces in literals. Consume the literal. */ - const quote = avt[i]; - do { - xpathOutput.xpath += avt[i++]; - } while (i < avt.length && avt[i] !== quote); - } - xpathOutput.xpath += avt[i]; - } else { - strOutput += avt[i]; - } - } - } - /* Finish up */ - if (inXpath) { - throw new Error("XTSE0350"); - } else { - if (strOutput != "") { - retval = retval.concat(strOutput); - } - } - return retval; + return tempfile; + // rmSync(tempdir, { recursive: true }); } -function compileAvt(avt: string | null) { - const avtRaw = compileAvtRaw(avt); - if (Array.isArray(avtRaw)) { - return toEstree( - avtRaw.map((comp) => { - if (typeof comp === "string") { - return comp; - } else { - return { xpath: comp.xpath }; - } - }), +function readDocumentDefault(uri: string): slimdom.Document { + if (uri.startsWith("file:")) { + return slimdom.parseXmlDocument( + readFileSync(fileURLToPath(new URL(uri))).toString(), ); - } else { - return toEstree(avtRaw); } + throw new Error(`FODC0005: document ${uri} not found`); } -export function preprocess( - doc: slimdom.Document, +/** + * Compile an XSLT stylesheet document into a callable transform function. + * + * @param xslt - The XSLT stylesheet as a parsed slimdom Document. + * @param inputURL The input URL, use to resolve relative URLs. + * @param readDocument - Optional callback to override default. Receives the resolved + * URI (absolute when a base is known, otherwise the raw href) and must + * return a parsed slimdom Document. Also used at runtime for `doc()` calls. + * + * @returns A transform function with the signature + * `(document, params?) => Map`. + * The `"#default"` key holds the primary output document. + * + * @example + * ```ts + * import * as slimdom from "slimdom"; + * import { compile } from "xjslt/compile"; + * import { serialize } from "xjslt"; + * + * const xslt = slimdom.parseXmlDocument(` + * + * + * + * + * + * `); + * + * const transform = compile(xslt, new URL("http://example.org/"); + * + * const input = slimdom.parseXmlDocument("Hello"); + * const output = transform(input).get("#default"); + * console.log(serialize(output)); // Hello + * ``` + */ +export function compile( + xslt: slimdom.Document, inputURL: URL, - readDocument: (uri: string) => slimdom.Document, -): slimdom.Document { - if ( - !evaluateXPathToBoolean( - "/xsl:stylesheet|/xsl:transform", - doc, - undefined, - undefined, - { namespaceResolver: mkResolver({ xsl: XSLT1_NSURI }) }, - ) - ) { - doc = preprocessSimplified(doc).get("#default").document; - } - let counter = 0; - let basePrecedence = 100; - while ( - evaluateXPathToBoolean( - "//xsl:include|//xsl:import", - doc, - undefined, - undefined, - { - namespaceResolver: mkResolver({ xsl: XSLT1_NSURI }), - }, - ) - ) { - doc = preprocessInclude(doc, { - inputURL: inputURL, - readDocument: readDocument, - }).get("#default").document; - doc = preprocessImport(doc, { - inputURL: inputURL, - readDocument: readDocument, - stylesheetParams: { "base-precedence": basePrecedence }, - }).get("#default").document; - basePrecedence += 100; - if (counter > 100) throw new Error("Import level too deep!"); - counter++; - } - /* https://www.w3.org/TR/xslt20/#stylesheet-stripping */ - doc = preprocessAttributeSet(doc).get("#default").document; - doc = preprocessStripWhitespace1(doc).get("#default").document; - doc = preprocessStripWhitespace2(doc).get("#default").document; - doc = preprocessUseWhen(doc).get("#default").document; - doc = preprocessErrorAnalysis(doc).get("#default").document; - return doc; + readDocument?: (uri: string) => slimdom.Document, +): StylesheetTransform { + const xsltDoc = preprocess( + xslt, + inputURL, + readDocument || readDocumentDefault, + ); + const code = generate(compileStylesheetNode(xsltDoc.documentElement, true)); + const m: { exports: { transform?: StylesheetTransform } } = { exports: {} }; + new Function("xjslt", "module", code)(xjslt, m); + return m.exports.transform; } diff --git a/src/compilex.web.ts b/src/compile.web.ts similarity index 93% rename from src/compilex.web.ts rename to src/compile.web.ts index a84e083..d4db492 100644 --- a/src/compilex.web.ts +++ b/src/compile.web.ts @@ -1,7 +1,7 @@ import { generate } from "astring"; import * as slimdom from "slimdom"; import * as xjslt from "./xjslt"; -import { preprocess, compileStylesheetNode } from "./compile"; +import { preprocess, compileStylesheetNode } from "./compileGeneric"; import { StylesheetTransform } from "./definitions"; function readDocumentDefault(uri: string): slimdom.Document { diff --git a/src/compileGeneric.ts b/src/compileGeneric.ts new file mode 100644 index 0000000..6e34311 --- /dev/null +++ b/src/compileGeneric.ts @@ -0,0 +1,1501 @@ +/* + * Copyright (C) 2021-2026 Erik Hetzner + * + * This file is part of XJSLT. + * + * XJSLT is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * XJSLT is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with XJSLT. If not, see + * . + */ + +import { generate } from "astring"; +import { + mkArray, + mkArrowFun, + mkBlock, + mkCall, + mkCallWithContext, + mkFun, + mkIdentifier, + mkImportsNode, + mkLet, + mkLiteral, + mkMember, + mkNew, + mkReturn, + toEstree, +} from "./estree-util"; +import { + Expression, + ExpressionStatement, + ObjectExpression, + Program, + Statement, +} from "estree"; +import * as slimdom from "slimdom"; +import * as xjslt from "./xjslt"; +import { + compileXPathToJavaScript, + evaluateXPath, + evaluateXPathToBoolean, + evaluateXPathToNodes, +} from "fontoxpath"; +import preprocessSimplified from "./preprocess/simplified"; +import preprocessInclude from "./preprocess/include"; +import preprocessImport from "./preprocess/import"; +import preprocessStripWhitespace1 from "./preprocess/stripWhitespace1"; +import preprocessStripWhitespace2 from "./preprocess/stripWhitespace2"; +import preprocessUseWhen from "./preprocess/use-when"; +import preprocessErrorAnalysis from "./preprocess/error-analysis"; +import preprocessAttributeSet from "./preprocess/attribute-set"; +import { + CompileContext, + XSLT1_NSURI, + XMLNS_NSURI, + NodeType, + NumberFormat, + OutputDefinition, + DecimalFormat, + DEFAULT_DECIMAL_FORMAT, + xpathstring, + TemplateForCompilation, + TemplateIndex, + StylesheetTransform, +} from "./definitions"; +import { + compareSortable, + computeDefaultPriority, + isAlphanumeric, + mkOutputDefinition, + mkResolver, + sortSortable, +} from "./shared"; +import { buildRuleTree } from "./dt"; +import { xpathToFeatures, XMLFeature } from "./dt-xml"; + +/** + * Functions to walk a DOM tree of an XSLT stylesheet and generate an + * ESTree that can be used to process an input document. + */ + +interface SimpleElement { + name: string; + hasChildren: boolean; + arguments: Map; + xpathArguments?: Set; +} + +function buildInResolver(prefix: string): string | null { + if (prefix === "xsl") { + return XSLT1_NSURI; + } + return null; +} + +/** Rewrite xpaths to support any workarounds/hacks we need. */ +function hackXpath( + xpath: string | undefined | null, +): string | undefined | null { + if (!xpath) { + return xpath; + } + // Override to use our own position, but only outside square brackets + // and not when preceded by / or :: + let result = ""; + let depth = 0; + let i = 0; + + while (i < xpath.length) { + const char = xpath[i]; + + if (char === "[") { + depth++; + result += char; + i++; + } else if (char === "]") { + depth--; + result += char; + i++; + } else if (depth === 0) { + // We're outside brackets, check for position() or last() + // But not if preceded by / or :: + const precededBySlash = i > 0 && xpath[i - 1] === "/"; + const precededByDoubleColon = i > 1 && xpath.substring(i - 2, i) === "::"; + + if (!precededBySlash && !precededByDoubleColon) { + if (xpath.substring(i).startsWith("position()")) { + result += "positionx()"; + i += "position()".length; + } else if (xpath.substring(i).startsWith("last()")) { + result += "lastx()"; + i += "last()".length; + } else { + result += char; + i++; + } + } else { + result += char; + i++; + } + } else { + // Inside brackets, don't modify + result += char; + i++; + } + } + + return result; +} + +const simpleElements = new Map([ + ["copy", { name: "copy", arguments: new Map(), hasChildren: true }], + [ + "copy-of", + { + name: "copyOf", + arguments: new Map([["select", undefined]]), + xpathArguments: new Set(["select"]), + hasChildren: false, + }, + ], + ["document", { name: "document", arguments: new Map(), hasChildren: true }], + [ + "if", + { + name: "ifX", + arguments: new Map([["test", undefined]]), + xpathArguments: new Set(["test"]), + hasChildren: true, + }, + ], + [ + "message", + { + name: "message", + arguments: new Map([ + ["select", undefined], + ["terminate", "no"], + ]), + xpathArguments: new Set(["select"]), + hasChildren: true, + }, + ], + [ + "sequence", + { + name: "sequence", + arguments: new Map([["select", undefined]]), + xpathArguments: new Set(["select"]), + hasChildren: false, + }, + ], +]); + +function compileApplyTemplatesNode( + node: slimdom.Element, + context: CompileContext, +) { + const mode = expandQname(node.getAttribute("mode"), getNodeNS(node)); + const args = { + select: hackXpath(node.getAttribute("select") || "child::node()"), + mode: mode || "#default", + params: compileParams("with-param", node.childNodes, context), + sortKeyComponents: compileSortKeyComponents(node.childNodes, context), + namespaces: getNodeNS(node), + }; + return compileFuncall("applyTemplates", [toEstree(args)]); +} + +function compileFunctionNode(node: slimdom.Element, context: CompileContext) { + const [namespace, name] = resolveQname( + node.getAttribute("name"), + getNodeNS(node), + ); + const args = { + name: name, + namespace: namespace, + as: node.getAttribute("as"), + params: compileParams("param", node.childNodes, context), + namespaces: getNodeNS(node), + }; + return mkCall(mkMember("xjslt", "functionX"), [ + toEstree(args), + mkArrowFun(compileSequenceConstructor(node.childNodes, context)), + ]); +} + +/** + * Try to precompile an xpath. + * Returns an AST node for a compiled match function, or undefined literal if compilation fails. + */ +function tryCompilePattern( + pattern: string | null | undefined, + namespaces: object, +): any { + if (!pattern) { + return mkLiteral(undefined); + } + + const compiled = compileXPathToJavaScript(pattern, evaluateXPath.NODES_TYPE, { + namespaceResolver: mkResolver(namespaces), + }); + let compiledFunc: any = mkLiteral(undefined); + // Apparently a bug in fontoxpath + if (compiled.isAstAccepted && !compiled.code.includes('"name-*"')) { + compiledFunc = { + type: "CallExpression", + callee: mkMember("xjslt", "compileMatchFunction"), + arguments: [mkLiteral(compiled.code)], + optional: false, + }; + } + return toEstree({ + xpath: mkLiteral(pattern), + compiled: compiledFunc, + }); +} + +function compileForEachNode(node: slimdom.Element, context: CompileContext) { + const args = { + select: hackXpath(node.getAttribute("select")), + sortKeyComponents: compileSortKeyComponents(node.childNodes, context), + namespaces: getNodeNS(node), + }; + return compileFuncallWithChildren(node, "forEach", toEstree(args), context); +} + +function compileForEachGroupNode( + node: slimdom.Element, + context: CompileContext, +) { + const namespaces = getNodeNS(node); + + // Precompile patterns if possible + const groupStartingWith = tryCompilePattern( + node.getAttribute("group-starting-with"), + namespaces, + ); + const groupEndingWith = tryCompilePattern( + node.getAttribute("group-ending-with"), + namespaces, + ); + + return compileFuncallWithChildren( + node, + "forEachGroup", + toEstree({ + select: hackXpath(node.getAttribute("select")), + groupBy: hackXpath(node.getAttribute("group-by")), + groupAdjacent: hackXpath(node.getAttribute("group-adjacent")), + groupStartingWith: groupStartingWith, + groupEndingWith: groupEndingWith, + sortKeyComponents: compileSortKeyComponents(node.childNodes, context), + namespaces: namespaces, + }), + context, + ); +} + +/** + * Parse format tokens from a format string at compile time. + * The first token never has a separator. + */ +export function parseNumberFormat(format: string): NumberFormat { + let retval: NumberFormat = { + prefix: undefined, + suffix: undefined, + formats: [], + }; + let currentAlpha = ""; + let currentNonAlpha = ""; + let inAlpha = false; + + for (let i = 0; i < format.length; i++) { + const ch = format[i]; + if (isAlphanumeric(ch)) { + if (inAlpha) { + // Continue building the current token + currentAlpha += ch; + } else { + // Transition from non-alpha -> alpha (starting a new token) + if (retval.formats.length === 0) { + // First token - what we've seen so far is the prefix + if (currentNonAlpha) { + retval.prefix = currentNonAlpha; + } + currentNonAlpha = ""; + } + currentAlpha = ch; + inAlpha = true; + } + } else { + // Non-alphanumeric character found + if (inAlpha) { + // Ending a token - push it with its separator + retval.formats.push({ + format: currentAlpha, + separator: currentNonAlpha || ".", + }); + currentAlpha = ""; + currentNonAlpha = ""; + inAlpha = false; + } + currentNonAlpha += ch; + } + } + + // Add the last token if we were in alpha mode + if (inAlpha && currentAlpha) { + retval.formats.push({ + format: currentAlpha, + separator: currentNonAlpha || ".", + }); + } else { + // Any remaining non-alpha text is the suffix + retval.suffix = currentNonAlpha || undefined; + } + + if (retval.formats.length === 0) { + // Defaults per spec. + retval.prefix = retval.suffix; + retval.formats.push({ format: "1", separator: "." }); + } + + return retval; +} + +function compileNumberNode(node: slimdom.Element, context: CompileContext) { + const namespaces = getNodeNS(node); + const format = node.getAttribute("format") || "1"; + + // Precompile patterns if possible + const count = tryCompilePattern(node.getAttribute("count"), namespaces); + const from = tryCompilePattern(node.getAttribute("from"), namespaces); + + return compileFuncall("number", [ + toEstree({ + value: hackXpath(node.getAttribute("value")), + select: hackXpath(node.getAttribute("select")), + count: count, + from: from, + level: node.getAttribute("level") || "single", + format: parseNumberFormat(format), + lang: node.getAttribute("lang"), + letterValue: node.getAttribute("letter-value"), + ordinal: node.getAttribute("ordinal"), + groupingSeparator: node.getAttribute("grouping-separator"), + groupingSize: parseInt(node.getAttribute("grouping-size")), + namespaces: namespaces, + }), + ]); +} + +function compilePerformSortNode( + node: slimdom.Element, + context: CompileContext, +) { + return compileFuncall("performSort", [ + toEstree({ + select: hackXpath(node.getAttribute("select")), + sortKeyComponents: compileSortKeyComponents(node.childNodes, context), + namespaces: getNodeNS(node), + }), + ]); +} + +function compileNextMatchNode(node: slimdom.Element, context: CompileContext) { + return compileFuncall("nextMatch", [ + toEstree({ + params: compileParams("with-param", node.childNodes, context), + namespaces: getNodeNS(node), + }), + ]); +} + +function compileApplyImportsNodes( + node: slimdom.Element, + context: CompileContext, +) { + return compileFuncall("applyImports", [ + toEstree({ + params: compileParams("with-param", node.childNodes, context), + namespaces: getNodeNS(node), + }), + ]); +} + +/* Compile a param or variable, which contains either a select + statement or a SequenceConstructor. */ +function compileVariableLike(node: slimdom.Element, context: CompileContext) { + const name = node.getAttribute("name"); + const as = node.getAttribute("as"); + if (node.hasAttribute("select")) { + return toEstree({ + name: name, + content: hackXpath(node.getAttribute("select")), + namespaces: getNodeNS(node), + as: as, + }); + } else if (node.hasChildNodes()) { + return toEstree({ + name: name, + content: mkArrowFun(compileSequenceConstructor(node.childNodes, context)), + namespaces: getNodeNS(node), + as: as, + }); + } else { + return toEstree({ + name: name, + content: undefined, + namespaces: {}, + as: as, + }); + } +} + +function compileSortKeyComponents(nodes: any[], context: CompileContext) { + let sortKeyComponents = []; + for (let node of nodes) { + if (node.localName === "sort") { + const args = { + namespaces: getNodeNS(node), + order: compileAvt(node.getAttribute("order")), + lang: compileAvt(node.getAttribute("lang")), + dataType: node.getAttribute("data-type"), + }; + if (node.hasChildNodes()) { + sortKeyComponents.push( + toEstree({ + ...args, + sortKey: mkArrowFun( + compileSequenceConstructor(node.childNodes, context), + ), + }), + ); + } else { + sortKeyComponents.push( + toEstree({ + ...args, + sortKey: hackXpath(node.getAttribute("select") || "."), + }), + ); + } + } + } + return toEstree(sortKeyComponents); +} + +function compileVariable(node: slimdom.Element, context: CompileContext) { + return compileFuncall("variable", [compileVariableLike(node, context)]); +} + +function compileParams( + nodename: string, + nodes: any[], + context: CompileContext, +) { + let params = []; + for (let node of nodes) { + if (node.localName === nodename) { + params.push(compileVariableLike(node, context)); + } + } + return toEstree(params); +} + +function compileCallTemplate(node: slimdom.Element, context: CompileContext) { + let args = {}; + let name = expandQname(node.getAttribute("name"), getNodeNS(node)); + args["name"] = name; + if (!args["name"]) { + throw new Error(""); + } + args["params"] = compileParams("with-param", node.childNodes, context); + return compileFuncall("callTemplate", [toEstree(args)]); +} + +function compileResultDocument(node: slimdom.Element, context: CompileContext) { + const args = { + format: compileAvt(node.getAttribute("format")), + href: compileAvt(node.getAttribute("href")), + omitXmlDeclaration: compileAvt(node.getAttribute("omit-xml-declaration")), + doctypeSystem: compileAvt(node.getAttribute("doctype-system")), + doctypePublic: compileAvt(node.getAttribute("doctype-public")), + standalone: compileAvt(node.getAttribute("standalone")), + namespaces: getNodeNS(node), + }; + return compileFuncallWithChildren( + node, + "resultDocument", + toEstree(args), + context, + ); +} + +function compileFuncall(name: string, args: Expression[]) { + return mkCallWithContext(mkMember("xjslt", name), args); +} + +function compileFuncallWithChildren( + node: slimdom.Element, + name: string, + args: ObjectExpression, + context: CompileContext, +): ExpressionStatement { + return mkCallWithContext(mkMember("xjslt", name), [ + args, + mkArrowFun(compileSequenceConstructor(node.childNodes, context)), + ]); +} + +function compileArgs( + node: slimdom.Element, + keyList: Map, + xpathKeys: Set = new Set(), +): ObjectExpression { + var args = {}; + for (let [key, fallback] of keyList) { + let value = node.getAttribute(key); + if (value === null) { + value = fallback; + } + args[key] = xpathKeys.has(key) ? hackXpath(value) : value; + } + args["namespaces"] = getNodeNS(node); + return toEstree(args); +} + +function compileSimpleElement(node: slimdom.Element, context: CompileContext) { + const what = simpleElements.get(node.localName); + const args = compileArgs(node, what.arguments, what.xpathArguments); + if (what.hasChildren) { + return compileFuncallWithChildren(node, what.name, args, context); + } else { + return compileFuncall(what.name, [args]); + } +} + +function compileChooseNode(node: slimdom.Element, context: CompileContext) { + let alternatives = []; + for (let childNode of node.childNodes) { + if (childNode.nodeType === node.ELEMENT_NODE) { + const childElement = childNode as slimdom.Element; + if (childElement.localName === "when") { + alternatives.push( + toEstree({ + test: hackXpath(childElement.getAttribute("test")), + apply: mkArrowFun( + compileSequenceConstructor(childElement.childNodes, context), + ), + }), + ); + } else if (childElement.localName === "otherwise") { + alternatives.push( + toEstree({ + apply: mkArrowFun( + compileSequenceConstructor(childNode.childNodes, context), + ), + }), + ); + } + } + } + return mkCallWithContext(mkMember("xjslt", "choose"), [ + mkArray(alternatives), + ]); +} + +function compileStylesheetParam( + node: slimdom.Element, + context: CompileContext, +) { + let param = compileVariableLike(node, context); + return mkCallWithContext(mkMember("xjslt", "param"), [param]); +} + +function compileWhitespaceDeclarationNode( + node: slimdom.Element, + preserve: boolean, + context: CompileContext, +) { + context.whitespaceDeclarations.push( + ...node + .getAttribute("elements") + .split(/[\n\r\t ]+/) + .map((e) => { + return { + importPrecedence: + parseInt(node.getAttribute("import-precedence")) || 1, + match: toEstree({ + xpath: mkLiteral(e), + }), + preserve: preserve, + namespaces: getNodeNS(node), + priority: computeDefaultPriority(e), + declarationOrder: ++context.declarationCounter, + }; + }), + ); +} + +function skipAttribute(attr: slimdom.Attr): boolean { + if (attr.namespaceURI == XMLNS_NSURI && attr.value === XSLT1_NSURI) { + return true; + } + // Skip XSLT attributes (like xsl:version) on literal result elements + if (attr.namespaceURI === XSLT1_NSURI) { + return true; + } + return false; +} + +function compileLiteralElementNode( + node: slimdom.Element, + context: CompileContext, +) { + let attributes = []; + for (let n in node.attributes) { + let attr = node.attributes[n]; + if (skipAttribute(attr)) { + continue; + } + attributes.push( + toEstree({ + name: attr.name, + value: compileAvt(attr.value), + namespace: attr.namespaceURI || undefined, + }), + ); + } + /* The DOM API is so confusing... we don't need to do this with + attributes. */ + let name = node.localName; + if (node.prefix) { + name = `${node.prefix}:${name}`; + } + return mkCallWithContext(mkMember("xjslt", "literalElement"), [ + toEstree({ + name: name, + attributes: attributes, + namespace: node.namespaceURI, + namespaces: getNodeNS(node), + }), + mkArrowFun(compileSequenceConstructor(node.childNodes, context)), + ]); +} + +export function getNodeNS(node: slimdom.Element, retval: object = undefined) { + if (!retval) { + retval = {}; + } + if (node.parentElement) { + getNodeNS(node.parentElement, retval); + } + if (node.attributes) { + for (let attribute of node.attributes) { + if (attribute.namespaceURI === XMLNS_NSURI) { + let name = attribute.localName; + if (name === "xmlns") { + name = ""; + } + retval[name] = attribute.value; + } + } + } + + const xpathDefaultNs = + node.getAttribute("xpath-default-namespace") || + node.getAttributeNS(XSLT1_NSURI, "xpath-default-namespace"); + if (xpathDefaultNs !== null) { + retval["#xpath-default"] = xpathDefaultNs; + } + + return retval; +} + +/* todo - separate into top-level & sequence-generator versions */ +export function compileTopLevelNode( + node: slimdom.Element, + context: CompileContext, +) { + if (node.nodeType === NodeType.ELEMENT) { + if (node.namespaceURI === XSLT1_NSURI) { + if (node.localName === "template") { + return compileTemplateNode(node, context); + } else if (node.localName === "variable") { + return compileVariable(node, context); + } else if (node.localName === "param") { + return compileStylesheetParam(node, context); + } else if (node.localName === "key") { + return compileKeyNode(node, context); + } else if (node.localName === "function") { + return compileFunctionNode(node, context); + } else if (node.localName === "output") { + return compileOutputNode(node); + } else if (node.localName === "decimal-format") { + return compileDecimalFormatNode(node); + } else if ( + node.localName === "attribute-set" || + node.localName === "character-map" || + node.localName === "import-schema" || + node.localName === "namespace-alias" + ) { + return undefined; + } else if (node.localName === "preserve-space") { + return compileWhitespaceDeclarationNode(node, true, context); + } else if (node.localName === "strip-space") { + return compileWhitespaceDeclarationNode(node, false, context); + } else { + throw new Error( + "XTSE0010: Found unexpected XSL element: " + node.tagName, + ); + } + } + } +} + +export function compileOutputNode(node: slimdom.Element) { + const name = node.getAttribute("name") || "#default"; + const outputDefinition: OutputDefinition = mkOutputDefinition({ + omitXmlDeclaration: node.getAttribute("omit-xml-declaration") || undefined, + doctypeSystem: node.getAttribute("doctype-system") || undefined, + doctypePublic: node.getAttribute("doctype-public") || undefined, + standalone: node.getAttribute("standalone") || undefined, + }); + let tmp = {}; + for (const key in outputDefinition) { + tmp[key] = outputDefinition[key]; + } + if (!name) { + mkCall(mkMember("outputDefinitions", "set"), [ + { + type: "ObjectExpression", + properties: [ + { type: "SpreadElement", argument: toEstree(tmp) }, + { + type: "SpreadElement", + argument: { + type: "CallExpression", + callee: mkMember("outputDefinitions", "get"), + arguments: [mkLiteral("#default")], + optional: false, + }, + }, + ], + }, + ]); + } else { + return mkCall(mkMember("outputDefinitions", "set"), [ + toEstree(name), + toEstree(tmp), + ]); + } +} + +export function compileDecimalFormatNode(node: slimdom.Element) { + const name = node.getAttribute("name") || "#default"; + const attrs = Object.fromEntries( + Object.entries({ + decimalSeparator: node.getAttribute("decimal-separator"), + digit: node.getAttribute("digit"), + groupingSeparator: node.getAttribute("grouping-separator"), + infinity: node.getAttribute("infinity"), + minusSign: node.getAttribute("minus-sign"), + nan: node.getAttribute("NaN"), + patternSeparator: node.getAttribute("pattern-separator"), + percent: node.getAttribute("percent"), + perMille: node.getAttribute("per-mille"), + zeroDigit: node.getAttribute("zero-digit"), + }).filter(([_, v]) => v !== null), + ); + const fmt: DecimalFormat = { + ...DEFAULT_DECIMAL_FORMAT, + ...attrs, + }; + return mkCall(mkMember("decimalFormats", "set"), [ + toEstree(name), + toEstree(fmt), + ]); +} + +export function compileSequenceConstructorNode( + node: slimdom.Element, + context: CompileContext, +) { + if (node.nodeType === NodeType.TEXT) { + return compileLiteralTextNode(node); + } else if (node.nodeType === NodeType.ELEMENT) { + if (node.namespaceURI === XSLT1_NSURI) { + if ( + node.hasAttribute("use-when") && + !evaluateXPathToBoolean(node.getAttribute("use-when")) + ) { + return undefined; + } + if (simpleElements.has(node.localName)) { + return compileSimpleElement(node, context); + } else if (node.localName === "apply-imports") { + return compileApplyImportsNodes(node, context); + } else if (node.localName === "apply-templates") { + return compileApplyTemplatesNode(node, context); + } else if (node.localName === "attribute") { + return compileAttributeNode(node, context); + } else if (node.localName === "choose") { + return compileChooseNode(node, context); + } else if (node.localName === "call-template") { + return compileCallTemplate(node, context); + } else if (node.localName === "comment") { + return compileCommentNode(node, context); + } else if (node.localName === "element") { + return compileElementNode(node, context); + } else if (node.localName === "for-each") { + return compileForEachNode(node, context); + } else if (node.localName === "for-each-group") { + return compileForEachGroupNode(node, context); + } else if (node.localName === "perform-sort") { + return compilePerformSortNode(node, context); + } else if (node.localName === "namespace") { + return compileNamespaceNode(node, context); + } else if (node.localName === "next-match") { + return compileNextMatchNode(node, context); + } else if (node.localName === "number") { + return compileNumberNode(node, context); + } else if (node.localName === "param") { + // Handled by special case. + } else if (node.localName === "processing-instruction") { + return compileProcessingInstruction(node, context); + } else if (node.localName === "result-document") { + return compileResultDocument(node, context); + } else if (node.localName === "sort") { + // Handled by special case. + } else if (node.localName === "text") { + return compileTextNode(node); + } else if (node.localName === "variable") { + return compileVariable(node, context); + } else if (node.localName === "strip-space") { + return undefined; + } else if (node.localName === "value-of") { + return compileValueOf(node, context); + } else { + throw new Error( + "XTSE0010: Found unexpected XSL element: " + node.tagName, + ); + } + } else { + return compileLiteralElementNode(node, context); + } + } +} + +function compileElementNode(node: slimdom.Element, context: CompileContext) { + return compileFuncallWithChildren( + node, + "element", + toEstree({ + name: compileAvt(node.getAttribute("name")), + namespace: compileAvt(node.getAttribute("namespace")), + namespaces: getNodeNS(node), + }), + context, + ); +} + +function compileAttributeNode(node: slimdom.Element, context: CompileContext) { + return compileFuncallWithChildren( + node, + "attribute", + toEstree({ + name: compileAvt(node.getAttribute("name")), + separator: compileAvt(node.getAttribute("separator")), + select: hackXpath(node.getAttribute("select")), + namespace: compileAvt(node.getAttribute("namespace")), + namespaces: getNodeNS(node), + }), + context, + ); +} + +function compileProcessingInstruction( + node: slimdom.Element, + context: CompileContext, +) { + return compileFuncallWithChildren( + node, + "processingInstruction", + toEstree({ + select: hackXpath(node.getAttribute("select")), + name: compileAvt(node.getAttribute("name")), + namespaces: getNodeNS(node), + }), + context, + ); +} + +function compileNamespaceNode(node: slimdom.Element, context: CompileContext) { + return compileFuncallWithChildren( + node, + "namespace", + toEstree({ + select: hackXpath(node.getAttribute("select")), + name: compileAvt(node.getAttribute("name")), + namespaces: getNodeNS(node), + }), + context, + ); +} + +function compileCommentNode(node: slimdom.Element, context: CompileContext) { + return compileFuncallWithChildren( + node, + "comment", + toEstree({ + select: hackXpath(node.getAttribute("select")), + namespaces: getNodeNS(node), + }), + context, + ); +} + +function compileValueOf(node: slimdom.Element, context: CompileContext) { + return compileFuncallWithChildren( + node, + "valueOf", + toEstree({ + select: hackXpath(node.getAttribute("select")), + separator: compileAvt(node.getAttribute("separator")), + namespaces: getNodeNS(node), + }), + context, + ); +} + +function compileTextNode(node: slimdom.Element) { + if (node.nodeType === node.ELEMENT_NODE && node.childElementCount > 0) { + throw new Error("XTSE0010 element found as child of xsl:text"); + } + return mkCallWithContext(mkMember("xjslt", "text"), [ + toEstree({ + disableOutputEscaping: false, // TODO + }), + mkArrowFun([compileLiteralTextNode(node)]), + ]); +} + +function compileNodeArray( + nodes: Array, + context: CompileContext, + compilerFunc: (node: any, context: CompileContext) => Statement | void, +): Array { + let body = []; + for (let n in nodes) { + let compiled = compilerFunc(nodes[n], context); + if (compiled) body.push(compiled); + } + return body; +} + +function compileSequenceConstructor( + nodes: Array, + context: CompileContext, +): Array { + return compileNodeArray(nodes, context, compileSequenceConstructorNode); +} + +/** Only one named template "wins" - the highest priority one. Map the array to the first element. */ +function buildNamedTemplates( + namedTemplates: Map>, +) { + const retval = new Map( + Array.from(namedTemplates).map(([key, value]) => [key, value[0]]), + ); + return toEstree(retval); +} + +export function compileStylesheetNode( + node: slimdom.Element, + injectDeps = false, +): Program { + let context: CompileContext = { + declarationCounter: 0, + namedTemplates: new Map(), + nonRuleTemplates: [], + rules: [], + templates: [], + whitespaceDeclarations: [], + }; + setupBuiltinTemplates(context, getNodeNS(node)); + return { + type: "Program", + sourceType: "module", + body: [ + ...(injectDeps ? [] : mkImportsNode()), + mkFun( + mkIdentifier("transform"), + [mkIdentifier("document"), mkIdentifier("params")], + mkBlock([ + { + type: "ExpressionStatement", + expression: { + type: "AssignmentExpression", + operator: "=", + left: mkIdentifier("params"), + right: { + type: "CallExpression", + callee: mkMember("xjslt", "setParamDefaults"), + arguments: [mkIdentifier("document"), mkIdentifier("params")], + optional: false, + }, + }, + }, + mkLet( + mkIdentifier("resultDocuments"), + mkNew(mkIdentifier("Map"), []), + ), + mkCall(mkMember("resultDocuments", "set"), [ + mkLiteral("#default"), + toEstree({ document: mkMember("params", "outputDocument") }), + ]), + mkLet(mkIdentifier("keys"), mkNew(mkIdentifier("Map"), [])), + mkLet( + mkIdentifier("outputDefinitions"), + mkNew(mkIdentifier("Map"), []), + ), + mkLet(mkIdentifier("decimalFormats"), mkNew(mkIdentifier("Map"), [])), + /* First compile the keys */ + ...compileNodeArray( + evaluateXPathToNodes("./xsl:key", node, undefined, undefined, { + namespaceResolver: buildInResolver, + }), + context, + compileTopLevelNode, + ), + /* Then the functions */ + ...compileNodeArray( + evaluateXPathToNodes("./xsl:function", node, undefined, undefined, { + namespaceResolver: buildInResolver, + }), + context, + compileTopLevelNode, + ), + /* Then the output definitions */ + ...compileNodeArray( + evaluateXPathToNodes("./xsl:output", node, undefined, undefined, { + namespaceResolver: buildInResolver, + }), + context, + compileTopLevelNode, + ), + /* Then the decimal formats */ + ...compileNodeArray( + evaluateXPathToNodes( + "./xsl:decimal-format", + node, + undefined, + undefined, + { namespaceResolver: buildInResolver }, + ), + context, + compileTopLevelNode, + ), + /* Then compile the templates */ + ...compileNodeArray( + evaluateXPathToNodes("./xsl:template", node, undefined, undefined, { + namespaceResolver: buildInResolver, + }), + context, + compileTopLevelNode, + ), + mkLet( + mkIdentifier("context"), + toEstree({ + outputDocument: mkMember("params", "outputDocument"), + append: { + type: "CallExpression", + callee: mkMember("xjslt", "mkNodeAppender"), + arguments: [mkMember("params", "outputNode")], + optional: false, + }, + resultDocuments: mkIdentifier("resultDocuments"), + contextItem: mkIdentifier("document"), + contextList: mkArray([mkIdentifier("document")]), + position: mkLiteral(1), + mode: mkMember("params", "initialMode"), + templates: context.templates, + nonRuleTemplateIndexes: context.nonRuleTemplates.sort((a, b) => + compareSortable( + context.templates[a[1]], + context.templates[b[1]], + ), + ), + namedTemplates: buildNamedTemplates(context.namedTemplates), + variableScopes: [mkNew(mkIdentifier("Map"), [])], + inputURL: mkMember("params", "inputURL"), + ruleTree: toEstree(buildRuleTree(context.rules)), + readDocument: mkMember("params", "readDocument"), + keys: mkIdentifier("keys"), + outputDefinitions: mkIdentifier("outputDefinitions"), + decimalFormats: mkIdentifier("decimalFormats"), + patternMatchCache: mkNew(mkIdentifier("Map"), []), + stylesheetParams: mkMember("params", "stylesheetParams"), + }), + ), + mkCallWithContext(mkMember("xjslt", "initialize"), [ + toEstree(getNodeNS(node)), + ]), + /* Then everything else */ + ...compileNodeArray( + evaluateXPathToNodes( + "./xsl:*[local-name()!='template' and local-name()!='key' and local-name()!='function' and local-name()!='output' and local-name()!='decimal-format']", + node, + undefined, + undefined, + { namespaceResolver: buildInResolver }, + ), + context, + compileTopLevelNode, + ), + mkCall(mkMember("xjslt", "stripSpace"), [ + mkIdentifier("document"), + toEstree(sortSortable(context.whitespaceDeclarations)), + ]), + mkCallWithContext(mkMember("xjslt", "processNode"), [ + toEstree([]), + toEstree(getNodeNS(node)), + ]), + mkReturn(mkIdentifier("resultDocuments")), + ]), + ), + { + type: "ExpressionStatement", + expression: { + type: "AssignmentExpression", + operator: "=", + left: { + type: "MemberExpression", + object: mkMember("module", "exports"), + property: mkIdentifier("transform"), + computed: false, + optional: false, + }, + right: mkIdentifier("transform"), + }, + }, + { + type: "ExpressionStatement", + expression: { + type: "AssignmentExpression", + operator: "=", + left: { + type: "MemberExpression", + object: mkIdentifier("global"), + property: mkIdentifier("transform"), + computed: false, + optional: false, + }, + right: mkIdentifier("transform"), + }, + }, + ], + }; +} + +function expandQname(name: string | null, namespaces: object) { + if (!name) { + return name; + } + const [prefix, localName] = name.split(":"); + if (localName && namespaces[prefix]) { + return `${namespaces[prefix]}#${localName}`; + } + return name; +} + +function resolveQname(name: string | null, namespaces: object) { + if (!name) { + return [undefined, name]; + } + const [prefix, localName] = name.split(":"); + if (localName && namespaces[prefix]) { + return [namespaces[prefix], localName]; + } + return [undefined, name]; +} + +function setupTemplate( + name: string, + matchStr: string, + context: CompileContext, + template: TemplateForCompilation, +) { + const index = context.templates.length; + context.templates.push(template); + if (name) { + if (!context.namedTemplates.has(name)) { + context.namedTemplates.set(name, [index]); + } else { + let templates = context.namedTemplates.get(name); + templates.push(index); + templates.sort((a, b) => + compareSortable(context.templates[a], context.templates[b]), + ); + context.namedTemplates.set(name, templates); + } + } + if (matchStr !== undefined) { + for (const subMatch of matchStr.split("|").map((s) => s.trim())) { + const features: XMLFeature[] = xpathToFeatures(subMatch); + if (features) { + context.rules.push({ result: index, features }); + } else { + const match = tryCompilePattern(subMatch, template.namespaces); + context.nonRuleTemplates.push([match, index]); + } + } + } +} + +function compileTemplateNode(node: slimdom.Element, context: CompileContext) { + let allowedParams = compileParams("param", node.childNodes, context); + let namespaces = getNodeNS(node); + const matchStr = node.getAttribute("match") || undefined; + const name = expandQname(node.getAttribute("name"), namespaces) || undefined; + const template: TemplateForCompilation = { + modes: (node.getAttribute("mode") || "#default") + .split(" ") + .filter((s) => s !== "") + .map((m) => expandQname(m.trim(), namespaces)), + allowedParams: allowedParams, + apply: mkArrowFun( + compileNodeArray( + node.childNodes, + context, + compileSequenceConstructorNode, + ), + ), + namespaces: namespaces, + priority: + parseFloat(node.getAttribute("priority")) || + computeDefaultPriority(matchStr), + declarationOrder: ++context.declarationCounter, + importPrecedence: parseInt(node.getAttribute("import-precedence")) || 1, + }; + setupTemplate(name, matchStr, context, template); +} + +function setupBuiltinTemplates(context: CompileContext, namespaces: object) { + setupTemplate(undefined, "processing-instruction()|comment()", context, { + apply: mkArrowFun([]), + allowedParams: [], + modes: ["#all"], + namespaces: namespaces, + importPrecedence: Number.MAX_VALUE, + declarationOrder: Number.MIN_VALUE, + }); + setupTemplate(undefined, "text()|@*", context, { + apply: mkArrowFun([ + mkCallWithContext(mkMember("xjslt", "valueOf"), [ + toEstree({ + select: ".", + separator: undefined, + namespaces: namespaces, + }), + ]), + ]), + allowedParams: [], + modes: ["#all"], + namespaces: namespaces, + importPrecedence: Number.MAX_VALUE, + declarationOrder: Number.MIN_VALUE, + }); + setupTemplate(undefined, "*|/", context, { + apply: mkArrowFun([ + mkCallWithContext(mkMember("xjslt", "applyTemplates"), [ + toEstree({ + select: "child::node()", + params: [], + mode: "#current", + namespaces: namespaces, + sortKeyComponents: [], + }), + ]), + ]), + allowedParams: [], + modes: ["#all"], + namespaces: namespaces, + importPrecedence: Number.MAX_VALUE, + declarationOrder: Number.MIN_VALUE, + }); +} + +function compileKeyNode( + node: slimdom.Element, + context: CompileContext, +): ExpressionStatement { + let namespaces = getNodeNS(node); + + return mkCall(mkMember("keys", "set"), [ + mkLiteral(expandQname(node.getAttribute("name"), namespaces)), + mkNew(mkMember("xjslt", "KeyImpl"), [ + mkLiteral(node.getAttribute("match")), + node.getAttribute("use") + ? mkLiteral(node.getAttribute("use")) + : mkArrowFun( + compileNodeArray( + node.childNodes, + context, + compileSequenceConstructorNode, + ), + ), + toEstree(getNodeNS(node)), + ]), + ]); +} + +function compileLiteralTextNode(node: slimdom.Element): ExpressionStatement { + return mkCallWithContext(mkMember("xjslt", "literalText"), [ + mkLiteral(node.textContent), + ]); +} + +export function compileAvtRaw(avt: string | undefined | null): any { + if (avt === undefined || avt === null) { + return undefined; + } + let retval: Array = []; + let strOutput: string = ""; + let xpathOutput: xpathstring = { xpath: "" }; + let inXpath = false; + for (let i = 0; i < avt.length; i++) { + if (avt[i] === "{") { + if (i + 1 < avt.length && avt[i + 1] === "{") { + // quoted { + i++; + strOutput += "{"; + } else { + // starting xpath + if (inXpath) { + throw new Error(); + } + if (strOutput != "") { + retval = retval.concat(strOutput); + } + strOutput = ""; + inXpath = true; + } + } else if (avt[i] === "}") { + if (i + 1 < avt.length && avt[i + 1] === "}") { + // quoted } + i++; + strOutput += "}"; + } else { + if (!inXpath) { + throw new Error("XTSE0370"); + } + // Ending xpath + retval = retval.concat({ xpath: hackXpath(xpathOutput.xpath) }); + xpathOutput = { xpath: "" }; + inXpath = false; + } + } else { + if (inXpath) { + if (avt[i] === "'" || avt[i] === '"') { + /* In a silly exception, you don't need to escape braces in literals. Consume the literal. */ + const quote = avt[i]; + do { + xpathOutput.xpath += avt[i++]; + } while (i < avt.length && avt[i] !== quote); + } + xpathOutput.xpath += avt[i]; + } else { + strOutput += avt[i]; + } + } + } + /* Finish up */ + if (inXpath) { + throw new Error("XTSE0350"); + } else { + if (strOutput != "") { + retval = retval.concat(strOutput); + } + } + return retval; +} + +function compileAvt(avt: string | null) { + const avtRaw = compileAvtRaw(avt); + if (Array.isArray(avtRaw)) { + return toEstree( + avtRaw.map((comp) => { + if (typeof comp === "string") { + return comp; + } else { + return { xpath: comp.xpath }; + } + }), + ); + } else { + return toEstree(avtRaw); + } +} + +export function preprocess( + doc: slimdom.Document, + inputURL: URL, + readDocument: (uri: string) => slimdom.Document, +): slimdom.Document { + if ( + !evaluateXPathToBoolean( + "/xsl:stylesheet|/xsl:transform", + doc, + undefined, + undefined, + { namespaceResolver: mkResolver({ xsl: XSLT1_NSURI }) }, + ) + ) { + doc = preprocessSimplified(doc).get("#default").document; + } + let counter = 0; + let basePrecedence = 100; + while ( + evaluateXPathToBoolean( + "//xsl:include|//xsl:import", + doc, + undefined, + undefined, + { + namespaceResolver: mkResolver({ xsl: XSLT1_NSURI }), + }, + ) + ) { + doc = preprocessInclude(doc, { + inputURL: inputURL, + readDocument: readDocument, + }).get("#default").document; + doc = preprocessImport(doc, { + inputURL: inputURL, + readDocument: readDocument, + stylesheetParams: { "base-precedence": basePrecedence }, + }).get("#default").document; + basePrecedence += 100; + if (counter > 100) throw new Error("Import level too deep!"); + counter++; + } + /* https://www.w3.org/TR/xslt20/#stylesheet-stripping */ + doc = preprocessAttributeSet(doc).get("#default").document; + doc = preprocessStripWhitespace1(doc).get("#default").document; + doc = preprocessStripWhitespace2(doc).get("#default").document; + doc = preprocessUseWhen(doc).get("#default").document; + doc = preprocessErrorAnalysis(doc).get("#default").document; + return doc; +} diff --git a/src/compilex.ts b/src/compilex.ts deleted file mode 100644 index 2cba726..0000000 --- a/src/compilex.ts +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright (C) 2021-2026 Erik Hetzner - * - * This file is part of XJSLT. - * - * XJSLT is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * XJSLT is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with XJSLT. If not, see - * . - */ - -import { generate } from "astring"; -import { - mkArray, - mkArrowFun, - mkBlock, - mkCall, - mkCallWithContext, - mkFun, - mkIdentifier, - mkImportsNode, - mkLet, - mkLiteral, - mkMember, - mkNew, - mkReturn, - toEstree, -} from "./estree-util"; -import { - Expression, - ExpressionStatement, - ObjectExpression, - Program, - Statement, -} from "estree"; -import * as slimdom from "slimdom"; -import * as xjslt from "./xjslt"; -import { - compileXPathToJavaScript, - evaluateXPath, - evaluateXPathToBoolean, - evaluateXPathToNodes, -} from "fontoxpath"; -import { readFileSync, symlinkSync } from "fs"; -import { readFile, writeFile } from "fs/promises"; -import { pathToFileURL, fileURLToPath } from "url"; -import * as path from "path"; -import { tmpdir } from "os"; -import { mkdtempSync } from "fs"; -import { StylesheetTransform } from "./definitions"; -import { - compareSortable, - computeDefaultPriority, - isAlphanumeric, - mkOutputDefinition, - mkResolver, - sortSortable, -} from "./shared"; -import { compileStylesheetNode, preprocess } from "./compile"; - -async function readAndParseXml(path: string): Promise { - const str = (await readFile(path)).toString(); - return slimdom.parseXmlDocument(str); -} - -function readAndParseXmlSync(path: string): slimdom.Document { - const str = readFileSync(path).toString(); - return slimdom.parseXmlDocument(str); -} - -/** - * Build a stylesheet. Returns a function that will take an input DOM - * document and return an output DOM document. - */ -export async function compileFromPath( - xsltPath: string, -): Promise { - return compile(await readAndParseXml(xsltPath), pathToFileURL(xsltPath)); -} - -export function compileFromPathSync(xsltPath: string): StylesheetTransform { - return compile(readAndParseXmlSync(xsltPath), pathToFileURL(xsltPath)); -} - -export async function compileToFile(xsltPath: string) { - let slimdom_path = require.resolve("slimdom").split(path.sep); - let root_dir = path.join( - "/", - ...slimdom_path.slice(0, slimdom_path.indexOf("node_modules")), - ); - var tempdir = mkdtempSync(path.join(tmpdir(), "xjslt-")); - symlinkSync( - path.join(root_dir, "node_modules"), - path.join(tempdir, "node_modules"), - ); - symlinkSync( - path.join(root_dir, "package.json"), - path.join(tempdir, "package.json"), - ); - symlinkSync(path.join(root_dir, "dist"), path.join(tempdir, "dist")); - var tempfile = path.join(tempdir, "transform.js"); - const xsltURL = pathToFileURL(xsltPath); - const xsltDoc = await preprocess( - await readAndParseXml(xsltPath), - xsltURL, - readDocumentDefault, - ); - await writeFile( - tempfile, - generate(compileStylesheetNode(xsltDoc.documentElement)), - ); - return tempfile; - // rmSync(tempdir, { recursive: true }); -} - -function readDocumentDefault(uri: string): slimdom.Document { - if (uri.startsWith("file:")) { - return slimdom.parseXmlDocument( - readFileSync(fileURLToPath(new URL(uri))).toString(), - ); - } - throw new Error(`FODC0005: document ${uri} not found`); -} - -/** - * Compile an XSLT stylesheet document into a callable transform function. - * - * @param xslt - The XSLT stylesheet as a parsed slimdom Document. - * @param inputURL The input URL, use to resolve relative URLs. - * @param readDocument - Optional callback to override default. Receives the resolved - * URI (absolute when a base is known, otherwise the raw href) and must - * return a parsed slimdom Document. Also used at runtime for `doc()` calls. - * - * @returns A transform function with the signature - * `(document, params?) => Map`. - * The `"#default"` key holds the primary output document. - * - * @example - * ```ts - * import * as slimdom from "slimdom"; - * import { compile } from "xjslt/compilex"; - * import { serialize } from "xjslt"; - * - * const xslt = slimdom.parseXmlDocument(` - * - * - * - * - * - * `); - * - * const transform = compile(xslt, new URL("http://example.org/"); - * - * const input = slimdom.parseXmlDocument("Hello"); - * const output = transform(input).get("#default"); - * console.log(serialize(output)); // Hello - * ``` - */ -export function compile( - xslt: slimdom.Document, - inputURL: URL, - readDocument?: (uri: string) => slimdom.Document, -): StylesheetTransform { - const xsltDoc = preprocess( - xslt, - inputURL, - readDocument || readDocumentDefault, - ); - const code = generate(compileStylesheetNode(xsltDoc.documentElement, true)); - const m: { exports: { transform?: StylesheetTransform } } = { exports: {} }; - new Function("xjslt", "module", code)(xjslt, m); - return m.exports.transform; -} diff --git a/src/index.ts b/src/index.ts index 55d6760..23102b8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,3 @@ -import { compile } from "./compilex"; +import { compile } from "./compile"; export { compile }; diff --git a/test/attribute-namespace.spec.ts b/test/attribute-namespace.spec.ts index 76eca6d..7d2227d 100644 --- a/test/attribute-namespace.spec.ts +++ b/test/attribute-namespace.spec.ts @@ -1,4 +1,4 @@ -import { compile } from "../src/compilex"; +import { compile } from "../src/compile"; import * as slimdom from "slimdom"; import { evaluateXPathToNodes } from "fontoxpath"; diff --git a/test/numbering.spec.ts b/test/numbering.spec.ts index 99287f4..5d570b7 100644 --- a/test/numbering.spec.ts +++ b/test/numbering.spec.ts @@ -18,7 +18,7 @@ * . */ -import { parseNumberFormat } from "../src/compile"; +import { parseNumberFormat } from "../src/compileGeneric"; import { groupNumeric, formatNumber, diff --git a/test/suite.spec.ts b/test/suite.spec.ts index b8b5273..7f90849 100644 --- a/test/suite.spec.ts +++ b/test/suite.spec.ts @@ -19,7 +19,7 @@ */ import { log } from "console"; -import { compileFromPathSync } from "../src/compilex"; +import { compileFromPathSync } from "../src/compile"; import * as slimdom from "slimdom"; import * as path from "path"; import { diff --git a/test/xjslt.spec.ts b/test/xjslt.spec.ts index ceff396..366e8f5 100644 --- a/test/xjslt.spec.ts +++ b/test/xjslt.spec.ts @@ -36,8 +36,8 @@ import { compileSequenceConstructorNode, compileTopLevelNode, getNodeNS, -} from "../src/compile"; -import { compile, compileFromPath } from "../src/compilex"; +} from "../src/compileGeneric"; +import { compile, compileFromPath } from "../src/compile"; import { DynamicContext, Template, From c410e42e0959cb885d210f1a2f640691d0fee683 Mon Sep 17 00:00:00 2001 From: Erik Hetzner Date: Mon, 8 Jun 2026 21:55:08 -0700 Subject: [PATCH 10/10] add dynamic browser compilation example --- README.md | 16 +++ examples/html/dynamic.html | 38 +++++ package.json | 1 + src/compileGeneric.ts | 285 +++++++++++++++++-------------------- webpack.config.ts | 5 + 5 files changed, 194 insertions(+), 151 deletions(-) create mode 100644 examples/html/dynamic.html diff --git a/README.md b/README.md index 5f377da..b576af6 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,22 @@ const xml = slimdom.serializeToWellFormedString(resultDocument); console.log(xml); ``` +# Dynamic (not precompiled) use + +xjslt can be used dynamically as well - that is, not precompiled. While precompiling the stylesheet is faster, this may be helpful in some circumstances. + +## In the browser + +``` +npm exec webpack && cp dist/xjslt-web.js examples/html/ +``` + +Open `examples/html/dynamic.html` in your browser. + +## In node + +(To be documented.) + # Supported features All core features of XSLT 2.0. Roughly 50% of tests in the XSLT test suite (https://github.com/w3c/xslt30-test) pass - but many of these tests are for edge cases. diff --git a/examples/html/dynamic.html b/examples/html/dynamic.html new file mode 100644 index 0000000..a1deb47 --- /dev/null +++ b/examples/html/dynamic.html @@ -0,0 +1,38 @@ + + + + + + + + + + + + diff --git a/package.json b/package.json index b906110..93ece9e 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "xjslt", "version": "1.0.0", "description": "xslt 2 transpiler to javascript", + "type": "module", "keywords": [ "xslt", "xslt2", diff --git a/src/compileGeneric.ts b/src/compileGeneric.ts index 6e34311..d300beb 100644 --- a/src/compileGeneric.ts +++ b/src/compileGeneric.ts @@ -38,6 +38,7 @@ import { import { Expression, ExpressionStatement, + FunctionDeclaration, ObjectExpression, Program, Statement, @@ -1021,10 +1022,9 @@ function buildNamedTemplates( return toEstree(retval); } -export function compileStylesheetNode( +export function compileStylesheetNodeFunction( node: slimdom.Element, - injectDeps = false, -): Program { +): FunctionDeclaration { let context: CompileContext = { declarationCounter: 0, namedTemplates: new Map(), @@ -1034,162 +1034,145 @@ export function compileStylesheetNode( whitespaceDeclarations: [], }; setupBuiltinTemplates(context, getNodeNS(node)); - return { - type: "Program", - sourceType: "module", - body: [ - ...(injectDeps ? [] : mkImportsNode()), - mkFun( - mkIdentifier("transform"), - [mkIdentifier("document"), mkIdentifier("params")], - mkBlock([ - { - type: "ExpressionStatement", - expression: { - type: "AssignmentExpression", - operator: "=", - left: mkIdentifier("params"), - right: { - type: "CallExpression", - callee: mkMember("xjslt", "setParamDefaults"), - arguments: [mkIdentifier("document"), mkIdentifier("params")], - optional: false, - }, - }, - }, - mkLet( - mkIdentifier("resultDocuments"), - mkNew(mkIdentifier("Map"), []), - ), - mkCall(mkMember("resultDocuments", "set"), [ - mkLiteral("#default"), - toEstree({ document: mkMember("params", "outputDocument") }), - ]), - mkLet(mkIdentifier("keys"), mkNew(mkIdentifier("Map"), [])), - mkLet( - mkIdentifier("outputDefinitions"), - mkNew(mkIdentifier("Map"), []), - ), - mkLet(mkIdentifier("decimalFormats"), mkNew(mkIdentifier("Map"), [])), - /* First compile the keys */ - ...compileNodeArray( - evaluateXPathToNodes("./xsl:key", node, undefined, undefined, { - namespaceResolver: buildInResolver, - }), - context, - compileTopLevelNode, - ), - /* Then the functions */ - ...compileNodeArray( - evaluateXPathToNodes("./xsl:function", node, undefined, undefined, { - namespaceResolver: buildInResolver, - }), - context, - compileTopLevelNode, - ), - /* Then the output definitions */ - ...compileNodeArray( - evaluateXPathToNodes("./xsl:output", node, undefined, undefined, { - namespaceResolver: buildInResolver, - }), - context, - compileTopLevelNode, - ), - /* Then the decimal formats */ - ...compileNodeArray( - evaluateXPathToNodes( - "./xsl:decimal-format", - node, - undefined, - undefined, - { namespaceResolver: buildInResolver }, - ), - context, - compileTopLevelNode, - ), - /* Then compile the templates */ - ...compileNodeArray( - evaluateXPathToNodes("./xsl:template", node, undefined, undefined, { - namespaceResolver: buildInResolver, - }), - context, - compileTopLevelNode, - ), - mkLet( - mkIdentifier("context"), - toEstree({ - outputDocument: mkMember("params", "outputDocument"), - append: { - type: "CallExpression", - callee: mkMember("xjslt", "mkNodeAppender"), - arguments: [mkMember("params", "outputNode")], - optional: false, - }, - resultDocuments: mkIdentifier("resultDocuments"), - contextItem: mkIdentifier("document"), - contextList: mkArray([mkIdentifier("document")]), - position: mkLiteral(1), - mode: mkMember("params", "initialMode"), - templates: context.templates, - nonRuleTemplateIndexes: context.nonRuleTemplates.sort((a, b) => - compareSortable( - context.templates[a[1]], - context.templates[b[1]], - ), - ), - namedTemplates: buildNamedTemplates(context.namedTemplates), - variableScopes: [mkNew(mkIdentifier("Map"), [])], - inputURL: mkMember("params", "inputURL"), - ruleTree: toEstree(buildRuleTree(context.rules)), - readDocument: mkMember("params", "readDocument"), - keys: mkIdentifier("keys"), - outputDefinitions: mkIdentifier("outputDefinitions"), - decimalFormats: mkIdentifier("decimalFormats"), - patternMatchCache: mkNew(mkIdentifier("Map"), []), - stylesheetParams: mkMember("params", "stylesheetParams"), - }), - ), - mkCallWithContext(mkMember("xjslt", "initialize"), [ - toEstree(getNodeNS(node)), - ]), - /* Then everything else */ - ...compileNodeArray( - evaluateXPathToNodes( - "./xsl:*[local-name()!='template' and local-name()!='key' and local-name()!='function' and local-name()!='output' and local-name()!='decimal-format']", - node, - undefined, - undefined, - { namespaceResolver: buildInResolver }, - ), - context, - compileTopLevelNode, - ), - mkCall(mkMember("xjslt", "stripSpace"), [ - mkIdentifier("document"), - toEstree(sortSortable(context.whitespaceDeclarations)), - ]), - mkCallWithContext(mkMember("xjslt", "processNode"), [ - toEstree([]), - toEstree(getNodeNS(node)), - ]), - mkReturn(mkIdentifier("resultDocuments")), - ]), - ), + return mkFun( + mkIdentifier("transform"), + [mkIdentifier("document"), mkIdentifier("params")], + mkBlock([ { type: "ExpressionStatement", expression: { type: "AssignmentExpression", operator: "=", - left: { - type: "MemberExpression", - object: mkMember("module", "exports"), - property: mkIdentifier("transform"), - computed: false, + left: mkIdentifier("params"), + right: { + type: "CallExpression", + callee: mkMember("xjslt", "setParamDefaults"), + arguments: [mkIdentifier("document"), mkIdentifier("params")], optional: false, }, - right: mkIdentifier("transform"), }, }, + mkLet(mkIdentifier("resultDocuments"), mkNew(mkIdentifier("Map"), [])), + mkCall(mkMember("resultDocuments", "set"), [ + mkLiteral("#default"), + toEstree({ document: mkMember("params", "outputDocument") }), + ]), + mkLet(mkIdentifier("keys"), mkNew(mkIdentifier("Map"), [])), + mkLet(mkIdentifier("outputDefinitions"), mkNew(mkIdentifier("Map"), [])), + mkLet(mkIdentifier("decimalFormats"), mkNew(mkIdentifier("Map"), [])), + /* First compile the keys */ + ...compileNodeArray( + evaluateXPathToNodes("./xsl:key", node, undefined, undefined, { + namespaceResolver: buildInResolver, + }), + context, + compileTopLevelNode, + ), + /* Then the functions */ + ...compileNodeArray( + evaluateXPathToNodes("./xsl:function", node, undefined, undefined, { + namespaceResolver: buildInResolver, + }), + context, + compileTopLevelNode, + ), + /* Then the output definitions */ + ...compileNodeArray( + evaluateXPathToNodes("./xsl:output", node, undefined, undefined, { + namespaceResolver: buildInResolver, + }), + context, + compileTopLevelNode, + ), + /* Then the decimal formats */ + ...compileNodeArray( + evaluateXPathToNodes( + "./xsl:decimal-format", + node, + undefined, + undefined, + { namespaceResolver: buildInResolver }, + ), + context, + compileTopLevelNode, + ), + /* Then compile the templates */ + ...compileNodeArray( + evaluateXPathToNodes("./xsl:template", node, undefined, undefined, { + namespaceResolver: buildInResolver, + }), + context, + compileTopLevelNode, + ), + mkLet( + mkIdentifier("context"), + toEstree({ + outputDocument: mkMember("params", "outputDocument"), + append: { + type: "CallExpression", + callee: mkMember("xjslt", "mkNodeAppender"), + arguments: [mkMember("params", "outputNode")], + optional: false, + }, + resultDocuments: mkIdentifier("resultDocuments"), + contextItem: mkIdentifier("document"), + contextList: mkArray([mkIdentifier("document")]), + position: mkLiteral(1), + mode: mkMember("params", "initialMode"), + templates: context.templates, + nonRuleTemplateIndexes: context.nonRuleTemplates.sort((a, b) => + compareSortable(context.templates[a[1]], context.templates[b[1]]), + ), + namedTemplates: buildNamedTemplates(context.namedTemplates), + variableScopes: [mkNew(mkIdentifier("Map"), [])], + inputURL: mkMember("params", "inputURL"), + ruleTree: toEstree(buildRuleTree(context.rules)), + readDocument: mkMember("params", "readDocument"), + keys: mkIdentifier("keys"), + outputDefinitions: mkIdentifier("outputDefinitions"), + decimalFormats: mkIdentifier("decimalFormats"), + patternMatchCache: mkNew(mkIdentifier("Map"), []), + stylesheetParams: mkMember("params", "stylesheetParams"), + }), + ), + mkCallWithContext(mkMember("xjslt", "initialize"), [ + toEstree(getNodeNS(node)), + ]), + /* Then everything else */ + ...compileNodeArray( + evaluateXPathToNodes( + "./xsl:*[local-name()!='template' and local-name()!='key' and local-name()!='function' and local-name()!='output' and local-name()!='decimal-format']", + node, + undefined, + undefined, + { namespaceResolver: buildInResolver }, + ), + context, + compileTopLevelNode, + ), + mkCall(mkMember("xjslt", "stripSpace"), [ + mkIdentifier("document"), + toEstree(sortSortable(context.whitespaceDeclarations)), + ]), + mkCallWithContext(mkMember("xjslt", "processNode"), [ + toEstree([]), + toEstree(getNodeNS(node)), + ]), + mkReturn(mkIdentifier("resultDocuments")), + ]), + ); +} + +export function compileStylesheetNode( + node: slimdom.Element, + injectDeps = false, +): Program { + return { + type: "Program", + sourceType: "module", + body: [ + ...(injectDeps ? [] : mkImportsNode()), + compileStylesheetNodeFunction(node), { type: "ExpressionStatement", expression: { @@ -1197,7 +1180,7 @@ export function compileStylesheetNode( operator: "=", left: { type: "MemberExpression", - object: mkIdentifier("global"), + object: mkMember("module", "exports"), property: mkIdentifier("transform"), computed: false, optional: false, diff --git a/webpack.config.ts b/webpack.config.ts index 8df6dd7..c0d52ac 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -20,6 +20,11 @@ const config: webpack.Configuration = { resolve: { extensions: [".web.ts", ".web.js", ".ts", ".js"], }, + // TODO: We should be able to turn this off, but it breaks + // compilation right now. + optimization: { + minimize: false, + }, output: { library: { name: "xjslt",