-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Conversation
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
plugins/removeUnusedNS.js
Outdated
// 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); | ||
} | ||
} |
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.
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)) {
// ...
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.
Tweaked comments