Skip to content

feat: Add missing node props#728

Merged
karfau merged 16 commits into
xmldom:masterfrom
Ponynjaa:add-missing-node-props
Sep 20, 2024
Merged

feat: Add missing node props#728
karfau merged 16 commits into
xmldom:masterfrom
Ponynjaa:add-missing-node-props

Conversation

@Ponynjaa

@Ponynjaa Ponynjaa commented Sep 10, 2024

Copy link
Copy Markdown
Collaborator

Adds missing properties and methods of Node to be compatible with the default DOM-typings.
Added properties parentElement, baseURI, isConnected.
Added methods contains(otherNode), getRootNode(options), isEqualNode(otherNode), isSameNode(otherNode).

@codecov

codecov Bot commented Sep 10, 2024

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.78%. Comparing base (301619e) to head (f5b2649).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #728      +/-   ##
==========================================
+ Coverage   94.36%   94.78%   +0.41%     
==========================================
  Files           8        8              
  Lines        2094     2165      +71     
  Branches      538      569      +31     
==========================================
+ Hits         1976     2052      +76     
+ Misses        118      113       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Ponynjaa

Copy link
Copy Markdown
Collaborator Author

FYI: I'm not done yet. I only added the logic and some descriptions to the props/methods that I added however I didn't have time yet to update the README, add typings or add tests.
If you want to take over from here feel free @karfau.

@Ponynjaa Ponynjaa changed the title Add missing node props feat: Add missing node props Sep 10, 2024

@karfau karfau left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just had a first glance at the diff, but already wanted to share the feedback

Comment thread lib/dom.js Outdated
Comment thread lib/dom.js Outdated
Comment thread readme.md
@Ponynjaa Ponynjaa requested a review from karfau September 11, 2024 22:23
@Ponynjaa

Copy link
Copy Markdown
Collaborator Author

graphic
Haha all this might have been for nothing 😢

@karfau

karfau commented Sep 14, 2024

Copy link
Copy Markdown
Member

graphic Haha all this might have been for nothing 😢

I don't think so.
It's a step towards a more complete implementation, but I never expected that we will implement all properties/methods, unless we clutter the code with a lot of "NotImplemented" methods.

One possible approach would be to vendor the whole lib.dom.d.ts and mark all methods that are not implemented as deprecated ... but that would again mean that type checks would pass that shouldn't.

But I think we will need some kind of helper to make it possible/easy to tell typescript it should be treated as compatible. Maybe by using some generic types?
Something on the level of DocumentImplementation that is passed down to all the methods of the document it creates, so that the global types can be passed as type argument?
Will have to experiment with it.

Comment thread index.d.ts Outdated
Comment thread lib/dom.js Outdated
Comment on lines +1103 to +1105
if (!other) {
return false;
}

@karfau karfau Sep 14, 2024

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest we add a test that passes undefined or null to the function to cover the condition.
It makes sense to have it, even though the types say you can only pass a Node which can never be falsy.

Comment thread lib/dom.js Outdated
Comment thread lib/dom.js Outdated
Comment thread lib/dom.js Outdated
Comment on lines +1158 to +1160
(this.childNodes && otherNode.childNodes && this.childNodes.length !== otherNode.childNodes.length) ||
(!this.childNodes && otherNode.childNodes) ||
(this.childNodes && !otherNode.childNodes)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All Nodes have a childNodes attribute, right? How can it not be set?

I think it is because we do not really have classes and inheritance so the property is not set from all the "constructors"...

We could fix it in this PR, by setting childNodes in all contructors, with the benefit of simpifying this check to
this.childNodes.length !== otherNode.childNodes.length,
or we keep it for another PR and will file an issue.

What do you think?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: I added childNodes = new NodeList() for every Document.create*() => Node method, but kept the condition for now, we will see if it's possible to produce test cases for all the missing cases.

Comment thread lib/dom.js Outdated

@karfau karfau left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completed my review, once the comments have been resolved, I will approve it.

@karfau

karfau commented Sep 14, 2024

Copy link
Copy Markdown
Member

By the way, collaboration would be much easier for me if you push the branch to the xmldom repository, which you should be able to.

Update: I have now configured your repo as a remote, so we can keep this option for the next PR and continue on this one in your repo.

@karfau karfau added this to the 0.9.3 milestone Sep 14, 2024
@karfau

karfau commented Sep 15, 2024

Copy link
Copy Markdown
Member

I resolved most of my comments, but there are some uncovered cases, which we need to add tests for.
They appear on the related lines when reviewing the files.
I will try to pick up one after the other during the week, unless you are faster :)

@Ponynjaa

Ponynjaa commented Sep 15, 2024

Copy link
Copy Markdown
Collaborator Author

I agree, we should just remove the checks for .nodeList on isEqualNode since it should always be there. It's too bad we can't just add this to the Node constructor, since it's easy to miss this on some "child classes" (or in our case the createXXX methods), I actually found one method that you probably missed, it was createDocumentType.
But with this out of the way it should be fine to just remove the checks so I don't have to write any more tests for these edge cases... there are already like 20 tests just for the isEqualNode function alone 😅
But yeah this should be fine for the release now I think :)

Btw I have no idea why CodeCov wanted tests for this added line but it seems like it doesn't want them anymore soooo.. works for me ^^

and decouple tests from each other
@karfau

karfau commented Sep 16, 2024

Copy link
Copy Markdown
Member

Btw I have no idea why CodeCov wanted tests for this added line

Because there are no tests for Document.createEntityReference so far and we changed it :)

Even though codecov seems to be happy (I need to see how to configure this better), I would prefer that all changed code is covered before the PR is merged.

@karfau karfau left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx, great contribution and collaboration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants