Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
OPT: check element fisrt (#2429)
Browse files Browse the repository at this point in the history
run ` if (!element)` at first to avoid rest code running.

If` if (!element)` equals true, then stop executing the rest other wise we run `element.forEach(item => walkTree(item, context, visitor, newContext));`  all the time at first
  • Loading branch information
HOUCe authored and hwillson committed Sep 28, 2018
1 parent fb0bc0e commit e6d2570
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/getDataFromTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ export function walkTree(
) => boolean | void,
newContext: Map<any, any> = new Map(),
) {
if (Array.isArray(element)) {
element.forEach(item => walkTree(item, context, visitor, newContext));
if (!element) {
return;
}

if (!element) {

if (Array.isArray(element)) {
element.forEach(item => walkTree(item, context, visitor, newContext));
return;
}

Expand Down

0 comments on commit e6d2570

Please sign in to comment.