Skip to content

Commit

Permalink
fix(resolve-map): deep resolve of yet unknown path values
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Sep 1, 2018
1 parent f018353 commit a710453
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/resolve-map/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { isFunction } from "@thi.ng/checks/is-function";
import { isPlainObject } from "@thi.ng/checks/is-plain-object";
import { isString } from "@thi.ng/checks/is-string";
import { illegalArgs } from "@thi.ng/errors/illegal-arguments";
import { getIn, mutIn } from "@thi.ng/paths";
import { exists, getIn, mutIn } from "@thi.ng/paths";

const RE_ARGS = /^(function\s+\w+)?\s*\(\{([\w\s,:]+)\}/

Expand Down Expand Up @@ -145,7 +145,7 @@ const _resolve = (root: any, path: LookupPath, resolved: any, stack: string[]) =
res = _resolve(root, absPath(path, v), resolved, stack);
} else if (isFunction(v)) {
res = resolveFunction(v, (p: string) => _resolve(root, absPath(path, p, 0), resolved, stack), pathID, resolved);
} else if (v === undefined) {
} else if (!exists(root, path)) {
v = resolvePath(root, path, resolved, stack);
}
if (res !== SEMAPHORE) {
Expand Down
8 changes: 7 additions & 1 deletion packages/resolve-map/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ describe("resolve-map", () => {
it("cycles", () => {
assert.throws(() => resolve({ a: "@a" }));
assert.throws(() => resolve({ a: { b: "@b" } }));
// console.log(resolve({ a: { b: "@/a" } }));
assert.throws(() => resolve({ a: { b: "@/a" } }));
assert.throws(() => resolve({ a: { b: "@/a/b" } }));
assert.throws(() => resolve({ a: "@b", b: "@a" }));
Expand All @@ -70,6 +69,13 @@ describe("resolve-map", () => {
assert.equal(n, 1);
});

it("deep resolve of yet unknown refs", () => {
assert.deepEqual(
resolve({ a: "@b/c/d", b: ($) => ({ c: { d: { e: $("/x") } } }), x: 1 }),
{ a: { e: 1 }, b: { c: { d: { e: 1 } } }, x: 1 }
);
});

it("destructure", () => {
const stats = {
// sequence average
Expand Down

0 comments on commit a710453

Please sign in to comment.