Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
miku1958 committed Jun 3, 2024
1 parent 71f3606 commit aec9abb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ export function optimize(root: Node, isRecursive = false) {
return;
}
if (!isRecursive && root.parentElement != null) {
let computedAttributes = {} as Record<string, Attr>;
const computedAttributes = {} as Record<string, Attr>;
// html doesn't provide computed attributes, use parent's attributes directly
Array.from(root.parentElement.attributes).forEach((attr) => {
computedAttributes[attr.name] = attr;
});
removeUnnecessaryAttribute(root, computedAttributes);

let computedStyle = {} as Record<string, Set<string>>;
const computedStyle = {} as Record<string, Set<string>>;
enumerateComputedStyle(root.parentElement, (key, values) => {
computedStyle[key] = values;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function removeUnnecessaryAttribute(root: Node, computedAttributes: Recor
if (!isNodeOfType(root, 'ELEMENT_NODE')) {
return
}
let newComputedAttributes = {
const newComputedAttributes = {
...computedAttributes,
};
for (let i = root.attributes.length - 1; i >= 0; i--) {
Expand All @@ -34,7 +34,7 @@ export function enumerateComputedStyle(element: HTMLElement, handler: (key: stri
return;
}
key = key.trim();
let values = new Set(valueText.split(",").map((value) => value.trim()));
const values = new Set(valueText.split(",").map((value) => value.trim()));

handler(key, values);
});
Expand All @@ -47,7 +47,7 @@ export function removeUnnecessaryStyle(root: Node, computedCSS: Record<string, S
if (!isNodeOfType(root, 'ELEMENT_NODE')) {
return
}
let newComputedCSS = {
const newComputedCSS = {
...computedCSS
}
enumerateComputedStyle(root, (key, values) => {
Expand All @@ -71,7 +71,7 @@ export function removeUnnecessaryStyle(root: Node, computedCSS: Record<string, S
* @internal
*/
export function removeUnnecessarySpan(root: Node) {
for (let child = root.firstChild; child; ) {
for (let child = root.firstChild; child;) {
if (
isNodeOfType(child, 'ELEMENT_NODE') &&
child.tagName == 'SPAN' &&
Expand Down

0 comments on commit aec9abb

Please sign in to comment.