object-scan
Advanced tools
Comparing version 18.0.2 to 18.0.3
/* compile needles to hierarchical map object */ | ||
import parser from './parser.js'; | ||
import iterator from '../generic/iterator.js'; | ||
import traverser from '../generic/traverser.js'; | ||
import { defineProperty } from '../generic/helper.js'; | ||
import { Wildcard } from './wildcard.js'; | ||
const COUNTER = Symbol('counter'); | ||
const LEAF = Symbol('leaf'); | ||
@@ -135,4 +132,5 @@ const markLeaf = (input, match, readonly) => defineProperty(input, LEAF, match, readonly); | ||
cur[wc.value] = child; | ||
ctx.stack.push(cur, child); | ||
if (ctx.orderByNeedles) { | ||
setOrder(child, ctx[COUNTER]); | ||
setOrder(child, ctx.counter); | ||
} | ||
@@ -165,4 +163,4 @@ setWildcard(child, wc); | ||
markLeaf(cur, !excluded, ctx.strict); | ||
setIndex(cur, ctx[COUNTER], ctx.strict); | ||
ctx[COUNTER] += 1; | ||
setIndex(cur, ctx.counter, ctx.strict); | ||
ctx.counter += 1; | ||
} | ||
@@ -173,19 +171,17 @@ }); | ||
const finalizeTower = (tower, ctx) => { | ||
const matches = []; | ||
let lastDepth = -1; | ||
const { stack } = ctx; | ||
traverser.traverse(tower, (type, obj, depth) => { | ||
if (type === 'EXIT') { | ||
const isUp = lastDepth === depth + 1; | ||
if ((isUp && matches[lastDepth] === true) || isMatch(obj)) { | ||
matches[depth] = true; | ||
setHasMatches(obj); | ||
} | ||
if (isUp) { | ||
matches[lastDepth] = false; | ||
} | ||
setValues(obj, Object.values(obj).reverse()); | ||
lastDepth = depth; | ||
while (stack.length !== 0) { | ||
const child = stack.pop(); | ||
const parent = stack.pop(); | ||
setValues(child, Object.values(child).reverse()); | ||
if (isMatch(child)) { | ||
setHasMatches(child); | ||
} | ||
}); | ||
if (hasMatches(child) && !hasMatches(parent)) { | ||
setHasMatches(parent); | ||
} | ||
} | ||
setValues(tower, Object.values(tower).reverse()); | ||
@@ -204,3 +200,4 @@ if (ctx.useArraySelector === false) { | ||
const tower = {}; | ||
ctx[COUNTER] = 0; | ||
ctx.counter = 0; | ||
ctx.stack = []; | ||
for (let idx = 0; idx < needles.length; idx += 1) { | ||
@@ -207,0 +204,0 @@ const needle = needles[idx]; |
{ | ||
"name": "object-scan", | ||
"type": "module", | ||
"version": "18.0.2", | ||
"version": "18.0.3", | ||
"description": "Traverse object hierarchies using matching and callbacks.", | ||
@@ -6,0 +6,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
62108
13
837