Use for-of instead of forEach (#3583)

Co-authored-by: syuilo <syuilotan@yahoo.co.jp>
Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>
This commit is contained in:
Aya Morisawa
2018-12-11 20:36:55 +09:00
committed by GitHub
parent 30c53e9ee0
commit 125849673a
84 changed files with 345 additions and 283 deletions

View File

@@ -8,7 +8,9 @@ export default function(html: string): string {
let text = '';
dom.childNodes.forEach((n: any) => analyze(n));
for (const n of dom.childNodes) {
analyze(n);
}
return text.trim();
@@ -61,13 +63,17 @@ export default function(html: string): string {
case 'p':
text += '\n\n';
if (node.childNodes) {
node.childNodes.forEach((n: any) => analyze(n));
for (const n of node.childNodes) {
analyze(n);
}
}
break;
default:
if (node.childNodes) {
node.childNodes.forEach((n: any) => analyze(n));
for (const n of node.childNodes) {
analyze(n);
}
}
break;
}

View File

@@ -17,21 +17,20 @@ export default (source: string, plainText = false): Node[] => {
es[0].name === 'text' ? [combineText(es)] : es
));
const concatTextRecursive = (es: Node[]): void =>
es.filter(x => x.children).forEach(x => {
const concatTextRecursive = (es: Node[]): void => {
for (const x of es.filter(x => x.children)) {
x.children = concatText(x.children);
concatTextRecursive(x.children);
});
}
};
nodes = concatText(nodes);
concatTextRecursive(nodes);
const removeEmptyTextNodes = (nodes: Node[]) => {
nodes.forEach(n => {
if (n.children) {
n.children = removeEmptyTextNodes(n.children);
}
});
for (const n of nodes.filter(n => n.children)) {
n.children = removeEmptyTextNodes(n.children);
}
return nodes.filter(n => !(n.name == 'text' && n.props.text == ''));
};