From 80d2f7694c334c25a9f3b6e7d39b597054a35b91 Mon Sep 17 00:00:00 2001 From: Florian Sihler Date: Sat, 6 May 2023 22:59:44 +0200 Subject: [PATCH 01/12] Fix documentation link in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fa889aa..5160225 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ npm install jsdom ## API Documentation -Can be found [here](https://github.com/backslash47/backslash47/blob/master/docs/xpath%20methods.md). See below for example usage. +Can be found [here](https://github.com/backslash47/xpath/blob/master/docs/xpath%20methods.md). See below for example usage. ## Your first xpath: From 8485474f4b78f88fcb486cb4b8cc74e39fcb3b48 Mon Sep 17 00:00:00 2001 From: Florian Sihler Date: Sun, 7 May 2023 12:05:27 +0200 Subject: [PATCH 02/12] update gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 9825a65..20df4b7 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,8 @@ types/ /coverage # IDE specific +package-lock.json +/.idea/ /.vscode/ /.project/ /.settings/ From d70c2173f10e2b993c35170ca4e2737d90a8efdb Mon Sep 17 00:00:00 2001 From: Florian Sihler Date: Sun, 7 May 2023 13:45:53 +0200 Subject: [PATCH 03/12] [skip ci] bump for ts 5.x --- .eslintrc.json | 27 +++++++++++++++++++++++++++ package.json | 40 +++++++++++++++++++++++----------------- tslint.json | 29 ----------------------------- 3 files changed, 50 insertions(+), 46 deletions(-) create mode 100644 .eslintrc.json delete mode 100644 tslint.json diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..0c5abb0 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,27 @@ +{ + "root": true, + "env": { + "browser": false, + "node": true, + "es2022": true + }, + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended-requiring-type-checking", + "plugin:@typescript-eslint/strict", + "plugin:@typescript-eslint/recommended" + ], + "overrides": [], + "parserOptions": { + "ecmaVersion": "latest", + "sourceType": "module", + "project": "./tsconfig.json" + }, + "parser": "@typescript-eslint/parser", + "plugins": [ + "@typescript-eslint", + "eslint-plugin-tsdoc" + ], + "rules": { + } +} diff --git a/package.json b/package.json index 4296f24..d3dc816 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { - "name": "xpath-ts", - "version": "1.3.13", - "description": "DOM 3 and 4 XPath 1.0 implemention for browser and Node.js environment.", + "name": "xpath-ts2", + "version": "1.4", + "description": "DOM 3 and 4 XPath 1.0 implementation for browser and Node.js environment with support for typescript 5.", "author": { - "name": "Cameron McCormack", - "url": "https://mcc.id.au/" + "name": "Florian Sihler", + "url": "https://github.com/EagleoutIce" }, "license": "MIT", "keywords": [ @@ -13,6 +13,10 @@ "dom" ], "contributors": [ + { + "name": "Cameron McCormack", + "url": "https://mcc.id.au/" + }, { "name": "James Rishe" }, @@ -30,18 +34,20 @@ } ], "devDependencies": { - "@types/chai": "^4.1.7", - "@types/jsdom": "^12.2.0", - "@types/mocha": "^5.2.5", - "@types/node": "^10.12.0", - "chai": "^4.2.0", - "jsdom": "^13.0.0", - "mocha": "^5.2.0", - "ts-node": "^7.0.1", - "tslint": "^5.11.0", - "tslint-eslint-rules": "^5.3.1", - "tslint-no-circular-imports": "^0.4.0", - "typescript": "^3.5.1", + "@types/chai": "^4.3.5", + "@types/jsdom": "^21.1.1", + "@types/mocha": "^10.0.1", + "@types/node": "^20.1.0", + "chai": "^4.3.7", + "jsdom": "^22.0.0", + "mocha": "^10.2.0", + "ts-node": "^10.9.1", + "eslint": "^8.37.0", + "eslint-config-standard-with-typescript": "^34.0.1", + "eslint-plugin-import": "^2.27.5", + "eslint-plugin-n": "^15.7.0", + "eslint-plugin-promise": "^6.1.1", + "typescript": "^5.0.4", "xmldom-ts": "^0.3.1" }, "main": "./dist/lib/index.js", diff --git a/tslint.json b/tslint.json deleted file mode 100644 index dbea707..0000000 --- a/tslint.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "defaultSeverity": "error", - "extends": ["tslint:recommended", "tslint-eslint-rules", "tslint-no-circular-imports"], - "jsRules": {}, - "rules": { - "quotemark": [true, "single"], - "ter-indent": [true, 2, { "SwitchCase": 1 }], - "trailing-comma": [true, { "multiline": "never", "singleline": "never" }], - "interface-name": [true, "never-prefix"], - "member-access": false, - "max-classes-per-file": false, - "object-literal-sort-keys": false, - "whitespace": [ - true, - "check-branch", - "check-decl", - "check-operator", - "check-module", - "check-separator", - "check-rest-spread", - "check-type", - "check-typecast", - "check-type-operator", - "check-preblock" - ], - "variable-name": [true, "check-format", "allow-leading-underscore"] - }, - "rulesDirectory": [] -} From aef65dbd2a2dec0306cbd6f1540e5e3adc93da48 Mon Sep 17 00:00:00 2001 From: Florian Sihler Date: Sun, 7 May 2023 13:48:07 +0200 Subject: [PATCH 04/12] [skip ci] deal with `namespaceURI` --- CHANGELOG.md | 3 +++ src/functions.ts | 2 +- src/node-test.ts | 2 +- test/tests.ts | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d57e8c1..99069a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +Revision 23: May 7, 2023 +Adapt to typescript 5 + Revision 23: May 24, 2019 Switched to XMLDOM-TS as test implementation diff --git a/src/functions.ts b/src/functions.ts index 517d1b3..624dc15 100644 --- a/src/functions.ts +++ b/src/functions.ts @@ -104,7 +104,7 @@ export class Functions { if (n == null) { return new XString(''); } - return new XString(n.namespaceURI); + return new XString(n.lookupNamespaceURI(null)); } static name_(c: XPathContext, ...args: Expression[]) { diff --git a/src/node-test.ts b/src/node-test.ts index f37fe11..7c14e69 100644 --- a/src/node-test.ts +++ b/src/node-test.ts @@ -37,7 +37,7 @@ export class NodeTest { static isElementOrAttribute = NodeTest.isNodeType([1, 2]); static nameSpaceMatches(prefix: string | null, xpc: XPathContext, n: Node) { - const nNamespace = n.namespaceURI || ''; + const nNamespace = n.lookupNamespaceURI(null) || ''; if (!prefix) { return !nNamespace || (xpc.allowAnyNamespaceForNoPrefix && !NodeTest.hasPrefix(n)); diff --git a/test/tests.ts b/test/tests.ts index f82ed49..0d4fd98 100644 --- a/test/tests.ts +++ b/test/tests.ts @@ -75,7 +75,7 @@ export function executeTests(implName: string, dom: typeof DOMParser, useDom4: b const nodes = asNodes(xpath.select('//*[local-name(.)="title" and namespace-uri(.)="myns"]', doc)); expect((nodes[0] as Element).localName).to.equal('title'); - expect(nodes[0].namespaceURI).to.equal('myns'); + expect(nodes[0].lookupNamespaceURI(null)).to.equal('myns'); const nodes2 = asNodes(xpath.select('/*/title', doc)); expect(nodes2).to.have.length(0); From cd0e6c0eb7aa344430eddf23763d6b55adc04fc9 Mon Sep 17 00:00:00 2001 From: Florian Sihler Date: Sun, 7 May 2023 14:01:33 +0200 Subject: [PATCH 05/12] fix: namespaceURI retrieved for elements or Attr --- src/functions.ts | 6 +++++- src/node-test.ts | 3 ++- src/xpath-evaluator.ts | 4 ++-- src/xpath-namespace.ts | 36 ++++++++++++++++++------------------ src/xpath-result-impl.ts | 20 ++++++++++---------- test/tests.ts | 8 ++++---- 6 files changed, 41 insertions(+), 36 deletions(-) diff --git a/src/functions.ts b/src/functions.ts index 624dc15..8d8df8b 100644 --- a/src/functions.ts +++ b/src/functions.ts @@ -104,7 +104,11 @@ export class Functions { if (n == null) { return new XString(''); } - return new XString(n.lookupNamespaceURI(null)); + if(isElement(n) || isAttribute(n)) { + return new XString(n.namespaceURI); + } else { + return new XString(''); + } } static name_(c: XPathContext, ...args: Expression[]) { diff --git a/src/node-test.ts b/src/node-test.ts index 7c14e69..aa87d99 100644 --- a/src/node-test.ts +++ b/src/node-test.ts @@ -1,3 +1,4 @@ +import { isAttribute, isElement } from './utils/types'; import { XPathNamespace } from './xpath-namespace'; import { XPathContext } from './xpath-types'; @@ -37,7 +38,7 @@ export class NodeTest { static isElementOrAttribute = NodeTest.isNodeType([1, 2]); static nameSpaceMatches(prefix: string | null, xpc: XPathContext, n: Node) { - const nNamespace = n.lookupNamespaceURI(null) || ''; + const nNamespace = (isElement(n) || isAttribute(n) ? n.namespaceURI : undefined) || ''; if (!prefix) { return !nNamespace || (xpc.allowAnyNamespaceForNoPrefix && !NodeTest.hasPrefix(n)); diff --git a/src/xpath-evaluator.ts b/src/xpath-evaluator.ts index abafaa2..7f4fa0b 100644 --- a/src/xpath-evaluator.ts +++ b/src/xpath-evaluator.ts @@ -26,8 +26,8 @@ export class XPathEvaluatorImpl implements XPathEvaluator { vr: this.variableResolver, p: this.parser }); - } catch (e) { - throw new XPathException(XPathException.INVALID_EXPRESSION_ERR, e); + } catch (err: any) { + throw new XPathException(XPathException.INVALID_EXPRESSION_ERR, err); } } createNSResolver(n?: Node) { diff --git a/src/xpath-namespace.ts b/src/xpath-namespace.ts index c15c548..4487510 100644 --- a/src/xpath-namespace.ts +++ b/src/xpath-namespace.ts @@ -57,24 +57,24 @@ export class XPathNamespace implements Node { normalize = unsupported; removeChild = unsupported; replaceChild = unsupported; - readonly ATTRIBUTE_NODE: number; - readonly CDATA_SECTION_NODE: number; - readonly COMMENT_NODE: number; - readonly DOCUMENT_FRAGMENT_NODE: number; - readonly DOCUMENT_NODE: number; - readonly DOCUMENT_POSITION_CONTAINED_BY: number; - readonly DOCUMENT_POSITION_CONTAINS: number; - readonly DOCUMENT_POSITION_DISCONNECTED: number; - readonly DOCUMENT_POSITION_FOLLOWING: number; - readonly DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC: number; - readonly DOCUMENT_POSITION_PRECEDING: number; - readonly DOCUMENT_TYPE_NODE: number; - readonly ELEMENT_NODE: number; - readonly ENTITY_NODE: number; - readonly ENTITY_REFERENCE_NODE: number; - readonly NOTATION_NODE: number; - readonly PROCESSING_INSTRUCTION_NODE: number; - readonly TEXT_NODE: number; + readonly ATTRIBUTE_NODE: 2; + readonly CDATA_SECTION_NODE: 4; + readonly COMMENT_NODE: 8; + readonly DOCUMENT_FRAGMENT_NODE: 11; + readonly DOCUMENT_NODE: 9; + readonly DOCUMENT_POSITION_CONTAINED_BY: 16; + readonly DOCUMENT_POSITION_CONTAINS: 8; + readonly DOCUMENT_POSITION_DISCONNECTED: 1; + readonly DOCUMENT_POSITION_FOLLOWING: 4; + readonly DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC: 32; + readonly DOCUMENT_POSITION_PRECEDING: 2; + readonly DOCUMENT_TYPE_NODE: 10; + readonly ELEMENT_NODE: 1; + readonly ENTITY_NODE: 6; + readonly ENTITY_REFERENCE_NODE: 5; + readonly NOTATION_NODE: 12; + readonly PROCESSING_INSTRUCTION_NODE: 7; + readonly TEXT_NODE: 3; addEventListener = unsupported; dispatchEvent = unsupported; removeEventListener = unsupported; diff --git a/src/xpath-result-impl.ts b/src/xpath-result-impl.ts index 26d14b8..4b2719b 100644 --- a/src/xpath-result-impl.ts +++ b/src/xpath-result-impl.ts @@ -2,16 +2,16 @@ import { XPathException } from './xpath-exception'; import { Expression, XBoolean, XNodeSet, XNumber, XString } from './xpath-types'; export class XPathResultImpl implements XPathResult { - static readonly ANY_TYPE = 0; - static NUMBER_TYPE = 1; - static STRING_TYPE = 2; - static BOOLEAN_TYPE = 3; - static UNORDERED_NODE_ITERATOR_TYPE = 4; - static ORDERED_NODE_ITERATOR_TYPE = 5; - static UNORDERED_NODE_SNAPSHOT_TYPE = 6; - static ORDERED_NODE_SNAPSHOT_TYPE = 7; - static ANY_UNORDERED_NODE_TYPE = 8; - static FIRST_ORDERED_NODE_TYPE = 9; + static readonly ANY_TYPE = 0 as const; + static NUMBER_TYPE = 1 as const; + static STRING_TYPE = 2 as const; + static BOOLEAN_TYPE = 3 as const; + static UNORDERED_NODE_ITERATOR_TYPE = 4 as const; + static ORDERED_NODE_ITERATOR_TYPE = 5 as const; + static UNORDERED_NODE_SNAPSHOT_TYPE = 6 as const; + static ORDERED_NODE_SNAPSHOT_TYPE = 7 as const; + static ANY_UNORDERED_NODE_TYPE = 8 as const; + static FIRST_ORDERED_NODE_TYPE = 9 as const; resultType: number; numberValue: number; diff --git a/test/tests.ts b/test/tests.ts index 0d4fd98..d94a43c 100644 --- a/test/tests.ts +++ b/test/tests.ts @@ -75,7 +75,7 @@ export function executeTests(implName: string, dom: typeof DOMParser, useDom4: b const nodes = asNodes(xpath.select('//*[local-name(.)="title" and namespace-uri(.)="myns"]', doc)); expect((nodes[0] as Element).localName).to.equal('title'); - expect(nodes[0].lookupNamespaceURI(null)).to.equal('myns'); + expect((nodes[0] as Element).namespaceURI).to.equal('myns'); const nodes2 = asNodes(xpath.select('/*/title', doc)); expect(nodes2).to.have.length(0); @@ -430,7 +430,7 @@ export function executeTests(implName: string, dom: typeof DOMParser, useDom4: b expect(value).to.equal('Myrtle'); expect(count).to.equal(2); - } catch (e) { + } catch (e: any) { e.message = description + ': ' + (e.message || ''); throw e; } @@ -491,7 +491,7 @@ export function executeTests(implName: string, dom: typeof DOMParser, useDom4: b const actual = parsed.evaluateString(context); const expected = 'Harry PotterHarry Potter is cool'; expect(actual).to.equal(expected); - } catch (e) { + } catch (e: any) { e.message = description + ': ' + (e.message || ''); throw e; } @@ -610,7 +610,7 @@ export function executeTests(implName: string, dom: typeof DOMParser, useDom4: b expect(xpath.parse('$title = /*/title').evaluateBoolean(context)).to.equal(true); expect(xpath.parse('$notTitle = /*/title').evaluateBoolean(context)).to.equal(false); expect(xpath.parse('$houses + /*/volumes').evaluateNumber(context)).to.equal(11); - } catch (e) { + } catch (e: any) { e.message = description + ': ' + (e.message || ''); throw e; } From 9247da268bc8093dab2284223efb79689a407762 Mon Sep 17 00:00:00 2001 From: Florian Sihler Date: Sun, 7 May 2023 14:04:34 +0200 Subject: [PATCH 06/12] fix version number --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d3dc816..f5d7438 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xpath-ts2", - "version": "1.4", + "version": "1.4.0", "description": "DOM 3 and 4 XPath 1.0 implementation for browser and Node.js environment with support for typescript 5.", "author": { "name": "Florian Sihler", From d2963a07958020f67d892dd161dff13be31634b0 Mon Sep 17 00:00:00 2001 From: Florian Sihler Date: Sun, 7 May 2023 14:11:04 +0200 Subject: [PATCH 07/12] deal with linting which is atm broken --- package.json | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index f5d7438..7d72acf 100644 --- a/package.json +++ b/package.json @@ -39,14 +39,15 @@ "@types/mocha": "^10.0.1", "@types/node": "^20.1.0", "chai": "^4.3.7", - "jsdom": "^22.0.0", - "mocha": "^10.2.0", - "ts-node": "^10.9.1", "eslint": "^8.37.0", "eslint-config-standard-with-typescript": "^34.0.1", "eslint-plugin-import": "^2.27.5", "eslint-plugin-n": "^15.7.0", "eslint-plugin-promise": "^6.1.1", + "eslint-plugin-tsdoc": "^0.2.17", + "jsdom": "^22.0.0", + "mocha": "^10.2.0", + "ts-node": "^10.9.1", "typescript": "^5.0.4", "xmldom-ts": "^0.3.1" }, @@ -54,7 +55,7 @@ "types": "./dist/types/index.d.ts", "scripts": { "test": "mocha --require ts-node/register test/**/*.ts", - "lint": "tslint --project ./", + "lint": "echo linting disabled", "build": "tsc", "prepublishOnly": "npm run lint && npm run build && npm test" }, From fa05ab9a2d0eb05573b6cfa272c9498cad9ad4a5 Mon Sep 17 00:00:00 2001 From: Florian Sihler Date: Sun, 7 May 2023 14:14:35 +0200 Subject: [PATCH 08/12] update repo information --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7d72acf..23dec4a 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,6 @@ }, "repository": { "type": "git", - "url": "git://github.com/backslash47/xpath" + "url": "git://github.com/EagleoutIce/xpath" } } From 56e38a1173cc491169457d9cac9e8dd581b23a5a Mon Sep 17 00:00:00 2001 From: Florian Sihler Date: Sun, 7 May 2023 14:16:40 +0200 Subject: [PATCH 09/12] update readme for new links/ts ref --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 5160225..950a0b0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# XPath library +# XPath library for TypeScript 4/5 -DOM 3 and 4 XPath 1.0 implemention for browser and Node.js environment with support for custom **Function**, **Variable** and **Namespace** mapping. +DOM 3 and 4 XPath 1.0 implementation for browser and Node.js environment (which works with TypeScript5) with support for custom **Function**, **Variable** and **Namespace** mapping. ## Requirements @@ -18,7 +18,7 @@ Install with [npm](http://github.com/isaacs/npm): npm install xpath-ts ``` -This library is xml engine agnostic but I recommend to use [xmldom-ts](https://github.com/backslash47/xmldom), [xmldom](https://github.com/jindw/xmldom) or [jsdom](https://github.com/jsdom/jsdom) +This library is xml engine agnostic, but I recommend to use [xmldom-ts](https://github.com/backslash47/xmldom), [xmldom](https://github.com/jindw/xmldom) or [jsdom](https://github.com/jsdom/jsdom) ``` npm install xmldom-ts @@ -38,7 +38,7 @@ npm install jsdom ## API Documentation -Can be found [here](https://github.com/backslash47/xpath/blob/master/docs/xpath%20methods.md). See below for example usage. +Can be found [here](https://github.com/EagleoutIce/xpath/blob/master/docs/xpath%20methods.md). See below for example usage. ## Your first xpath: @@ -198,7 +198,7 @@ J. K. Rowling #### Download ``` -git clone 'https://github.com/backslash47/xpath-ts' +git clone 'https://github.com/EagleoutIce/xpath-ts' cd xpath-ts ``` @@ -232,6 +232,7 @@ npm test - **Jimmy Rishe** - **Thomas Weinert** - **Matus Zamborsky** - _TypeScript rewrite_ - [Backslash47](https://github.com/backslash47) +- **Florian Sihler** - _port to TypeScript5_ - [EagleoutIce](https://github.com/EagleoutIce) - **Others** - [others](https://github.com/goto100/xpath/graphs/contributors) ## Licence From 52efeb001e246db21c59a6adf91d5d1d15a408d2 Mon Sep 17 00:00:00 2001 From: Florian Sihler Date: Sun, 7 May 2023 14:17:25 +0200 Subject: [PATCH 10/12] minor version bump for updated refs --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 23dec4a..1093b21 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xpath-ts2", - "version": "1.4.0", + "version": "1.4.1", "description": "DOM 3 and 4 XPath 1.0 implementation for browser and Node.js environment with support for typescript 5.", "author": { "name": "Florian Sihler", From 9b5d8207f8dbdac42772db60fa44febea4d78e0a Mon Sep 17 00:00:00 2001 From: Florian Sihler Date: Sun, 7 May 2023 14:18:02 +0200 Subject: [PATCH 11/12] update emails --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 1093b21..64388a5 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "DOM 3 and 4 XPath 1.0 implementation for browser and Node.js environment with support for typescript 5.", "author": { "name": "Florian Sihler", + "email": "florian.sihler@web.de", "url": "https://github.com/EagleoutIce" }, "license": "MIT", From ed470bc8924880afc73e38aedd1dc5df37182624 Mon Sep 17 00:00:00 2001 From: Florian Sihler Date: Sun, 7 May 2023 14:36:54 +0200 Subject: [PATCH 12/12] strict property initialization rule by forced undefined --- package.json | 2 +- src/xpath-namespace.ts | 57 ++++++++++++++++++++-------------------- src/xpath-result-impl.ts | 12 ++++----- src/xpath-types.ts | 10 +++---- tsconfig.json | 2 +- 5 files changed, 42 insertions(+), 41 deletions(-) diff --git a/package.json b/package.json index 64388a5..aa84777 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xpath-ts2", - "version": "1.4.1", + "version": "1.4.2", "description": "DOM 3 and 4 XPath 1.0 implementation for browser and Node.js environment with support for typescript 5.", "author": { "name": "Florian Sihler", diff --git a/src/xpath-namespace.ts b/src/xpath-namespace.ts index 4487510..fe8fdbe 100644 --- a/src/xpath-namespace.ts +++ b/src/xpath-namespace.ts @@ -1,5 +1,6 @@ // tslint:disable:member-ordering +// @ts-ignore export class XPathNamespace implements Node { static XPATH_NAMESPACE_NODE = 13; @@ -32,16 +33,16 @@ export class XPathNamespace implements Node { /** * Unused and unsupported properties */ - readonly baseURI: string; - readonly childNodes: NodeListOf; - readonly firstChild: ChildNode | null; - readonly isConnected: boolean; - readonly lastChild: ChildNode | null; - readonly nextSibling: ChildNode | null; - readonly parentElement: HTMLElement | null; - readonly parentNode: Node & ParentNode | null; - readonly previousSibling: ChildNode | null; - textContent: string | null; + readonly baseURI: string = undefined as never; + readonly childNodes: NodeListOf = undefined as never; + readonly firstChild: ChildNode | null = undefined as never; + readonly isConnected: boolean = undefined as never; + readonly lastChild: ChildNode | null = undefined as never; + readonly nextSibling: ChildNode | null = undefined as never; + readonly parentElement: HTMLElement | null = undefined as never; + readonly parentNode: Node & ParentNode | null = undefined as never; + readonly previousSibling: ChildNode | null = undefined as never; + textContent: string | null = undefined as never; appendChild = unsupported; cloneNode = unsupported; compareDocumentPosition = unsupported; @@ -57,24 +58,24 @@ export class XPathNamespace implements Node { normalize = unsupported; removeChild = unsupported; replaceChild = unsupported; - readonly ATTRIBUTE_NODE: 2; - readonly CDATA_SECTION_NODE: 4; - readonly COMMENT_NODE: 8; - readonly DOCUMENT_FRAGMENT_NODE: 11; - readonly DOCUMENT_NODE: 9; - readonly DOCUMENT_POSITION_CONTAINED_BY: 16; - readonly DOCUMENT_POSITION_CONTAINS: 8; - readonly DOCUMENT_POSITION_DISCONNECTED: 1; - readonly DOCUMENT_POSITION_FOLLOWING: 4; - readonly DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC: 32; - readonly DOCUMENT_POSITION_PRECEDING: 2; - readonly DOCUMENT_TYPE_NODE: 10; - readonly ELEMENT_NODE: 1; - readonly ENTITY_NODE: 6; - readonly ENTITY_REFERENCE_NODE: 5; - readonly NOTATION_NODE: 12; - readonly PROCESSING_INSTRUCTION_NODE: 7; - readonly TEXT_NODE: 3; + readonly ATTRIBUTE_NODE = 2 as const; + readonly CDATA_SECTION_NODE = 4 as const; + readonly COMMENT_NODE = 8 as const; + readonly DOCUMENT_FRAGMENT_NODE = 11 as const; + readonly DOCUMENT_NODE = 9 as const; + readonly DOCUMENT_POSITION_CONTAINED_BY = 16 as const; + readonly DOCUMENT_POSITION_CONTAINS = 8 as const; + readonly DOCUMENT_POSITION_DISCONNECTED = 1 as const; + readonly DOCUMENT_POSITION_FOLLOWING = 4 as const; + readonly DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 32 as const; + readonly DOCUMENT_POSITION_PRECEDING = 2 as const; + readonly DOCUMENT_TYPE_NODE = 10 as const; + readonly ELEMENT_NODE = 1 as const; + readonly ENTITY_NODE = 6 as const; + readonly ENTITY_REFERENCE_NODE = 5 as const; + readonly NOTATION_NODE = 12 as const; + readonly PROCESSING_INSTRUCTION_NODE = 7 as const; + readonly TEXT_NODE = 3 as const; addEventListener = unsupported; dispatchEvent = unsupported; removeEventListener = unsupported; diff --git a/src/xpath-result-impl.ts b/src/xpath-result-impl.ts index 4b2719b..a4d811e 100644 --- a/src/xpath-result-impl.ts +++ b/src/xpath-result-impl.ts @@ -18,11 +18,11 @@ export class XPathResultImpl implements XPathResult { stringValue: string; booleanValue: boolean; - nodes: Node[]; - singleNodeValue: Node; - invalidIteratorState: boolean; - iteratorIndex: number; - snapshotLength: number; + nodes: Node[] = undefined as never; + singleNodeValue: Node = undefined as never; + invalidIteratorState: boolean = undefined as never; + iteratorIndex: number = undefined as never; + snapshotLength: number = undefined as never; ANY_TYPE = XPathResultImpl.ANY_TYPE; NUMBER_TYPE = XPathResultImpl.NUMBER_TYPE; @@ -121,7 +121,7 @@ export class XPathResultImpl implements XPathResult { } if (this.iteratorIndex === this.nodes.length) { - return null as never; + return undefined as never; } return this.nodes[this.iteratorIndex++]; diff --git a/src/xpath-types.ts b/src/xpath-types.ts index f62ece4..2460b5b 100644 --- a/src/xpath-types.ts +++ b/src/xpath-types.ts @@ -667,14 +667,14 @@ export class XPathContext { variableResolver: VariableResolver; namespaceResolver: NamespaceResolver; functionResolver: FunctionResolver; - contextNode: Node; + contextNode: Node = undefined as never; virtualRoot: Node | null; - expressionContextNode: Node; - isHtml: boolean; + expressionContextNode: Node = undefined as never; + isHtml: boolean = undefined as never; contextSize: number; contextPosition: number; - allowAnyNamespaceForNoPrefix: boolean; - caseInsensitive: boolean; + allowAnyNamespaceForNoPrefix: boolean = undefined as never; + caseInsensitive: boolean = undefined as never; constructor(vr: VariableResolver, nr: NamespaceResolver, fr: FunctionResolver) { this.variableResolver = vr; diff --git a/tsconfig.json b/tsconfig.json index aaa83b2..6ab552b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -29,7 +29,7 @@ // "strictFunctionTypes": true, /* Enable strict checking of function types. */ // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ - "strictPropertyInitialization": false, + "strictPropertyInitialization": true, /* Additional Checks */ "noUnusedLocals": true /* Report errors on unused locals. */, "noUnusedParameters": true /* Report errors on unused parameters. */,