-
Notifications
You must be signed in to change notification settings - Fork 92
feat: Add compareDocumentPosition method from level 3 spec. #488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for picking up this topic and providing an implementation and happy to hear that it was already proven to work for a long time.
I added some comments/remarks/questions. Let me know what you think.
I would also prefer to have tests for this method, to make sure it doesn't break in the future.
Are you able and willing to extend your PR by adding those tests?
Thanks for the review. I'll follow up with revisions after the Easter break. |
Willing yes, able remains to be seen. But I know what goes wrong in SRE when |
Great. You can push whatever you are able to do and let me know in case I should finalize it. |
Finally got round to following this up. As mentioned, this was originally not my code, so I was not really aware of some of its problems. But I've now refactored it to
PTAL. |
@@ -0,0 +1,92 @@ | |||
'use strict'; | |||
const { DOMParser } = require('../../lib'); | |||
const { DOMException } = require('../../lib/dom'); |
Check notice
Code scanning / CodeQL
Unused variable, import, function or class
const x1 = x0.childNodes[0]; | ||
const y1 = x0.childNodes[1]; | ||
const x2 = x1.childNodes[0]; | ||
const y2 = x1.childNodes[1]; |
Check notice
Code scanning / CodeQL
Unused variable, import, function or class
expect(foo.compareDocumentPosition(x0)).toBe(result); | ||
}); | ||
it('Step 8', () => { | ||
let result = x0.DOCUMENT_POSITION_CONTAINED_BY + x0.DOCUMENT_POSITION_FOLLOWING; |
Check notice
Code scanning / CodeQL
Unused variable, import, function or class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Such a great contribution, thx a lot.
It will be part of version 0.9.0, I will soon release a pre-release version using the next
label.
PR contributes a more efficient coding for the `compareDocumentPosition` method contributed in PR #488 . In detail: * Removes the `parentChain` method and replaces it with a parent chain computation that immediately compares target nodes, thus avoiding unnecessary computations. * Uses `push` and `reverse` instead of `unshift` to assemble chains as this is considerably faster.
The PR adds an implementation of level 3 method
compareDocumentPosition
. This is an updated version of the code suggested in jindw/xmldom#113The code ran for many years error-free in Speech Rule Engine together with wicked-good-xpath.