Skip to content
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

Refactor removeUnusedNS plugin #1559

Merged
merged 2 commits into from Sep 10, 2021
Merged

Refactor removeUnusedNS plugin #1559

merged 2 commits into from Sep 10, 2021

Conversation

TrySound
Copy link
Member

@TrySound TrySound commented Sep 5, 2021

  • covered with types
  • migrated to visitor plugin api
  • dropped traverse utility which is replaced by visitor

- covered with types
- migrated to visitor plugin api
- dropped traverse utility which is replaced by visitor
Comment on lines 33 to 46
// remove element namespace from collected list
if (node.name.includes(':')) {
const [ns] = node.name.split(':');
if (definedNamespaces.has(ns)) {
definedNamespaces.delete(ns);
}
}
// check each attr for the ns-attrs
for (const name of Object.keys(node.attributes)) {
if (name.includes(':')) {
const [ns] = name.split(':');
definedNamespaces.delete(ns);
}
}
Copy link
Collaborator

@omgovich omgovich Sep 10, 2021

Choose a reason for hiding this comment

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

The code looks good, but it feels like it doesn't have enough explanation to help other developers to understand it faster. For example, we remove some elements from definedNamespaces but there is a lack of explanation why we do that. Would be better to have reference to some specs or describe the goal. Examples:

         // Collect all namespaces from the svg element
         // (such as `xmlns:xlink="http://www.w3.org/1999/xlink"`) 
         if (node.name === 'svg' && parentNode.type === 'root') {

         // We must preserve a namespace if there are nested elements that refer
         // to the same namespace in their names
         if (node.name.includes(':')) {
         // ...

         // Dropping a namespace from the root element might break the rendering of elements
         // that use this namespace in attribute names
         for (const name of Object.keys(node.attributes)) {
         // ...

Copy link
Member Author

Choose a reason for hiding this comment

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

Tweaked comments

@TrySound TrySound merged commit 6eb4524 into master Sep 10, 2021
@TrySound TrySound deleted the refactor-remove-unused-ns branch September 10, 2021 17:30
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.

None yet

3 participants