Skip to content

Commit

Permalink
fix: do not modify path
Browse files Browse the repository at this point in the history
  • Loading branch information
arlac77 committed Feb 16, 2021
1 parent 13d6036 commit f372138
Showing 1 changed file with 31 additions and 26 deletions.
57 changes: 31 additions & 26 deletions src/expander.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,15 @@ export function createContext(options = {}) {
if (object instanceof Map) {
const r = new Map();
for (const [key, value] of object.entries()) {
path.push({
key,
value
});

r.set(_expand(key, path, promises), _expand(value, path, promises));
const path2 = [
...path,
{
key,
value
}
];

path.pop();
r.set(_expand(key, path2, promises), _expand(value, path2, promises));
}

return r;
Expand All @@ -190,13 +191,7 @@ export function createContext(options = {}) {
if (object instanceof Set) {
const r = new Set();
for (const value of object.values()) {
path.push({
value
});

r.add(_expand(value, path, promises));

path.pop();
r.add(_expand(value, [...path, { value }], promises));
}

return r;
Expand All @@ -207,18 +202,23 @@ export function createContext(options = {}) {

for (let index = 0; index < object.length; index++) {
const o = object[index];
path.push({
key: index,
value: o
});

const r = _expand(o, path, promises);
const r = _expand(
o,
[
...path,
{
key: index,
value: o
}
],
promises
);
if (r instanceof Promise) {
promises.push(r);
r.then(f => (array[index] = f));
}
array[index] = r;
path.pop();
}

return array;
Expand All @@ -229,17 +229,22 @@ export function createContext(options = {}) {
for (let [key, value] of Object.entries(object)) {
const newKey = _expand(key, path, promises);
if (typeof newKey === "string" || newKey instanceof String) {
path.push({
key,
value
});
value = _expand(value, path, promises);
value = _expand(
value,
[
...path,
{
key,
value
}
],
promises
);
if (value instanceof Promise) {
promises.push(value);
value.then(v => (newObject[newKey] = v));
}
newObject[newKey] = value;
path.pop();
} else {
newObject = newKey;
}
Expand Down

0 comments on commit f372138

Please sign in to comment.