Skip to content

Commit 49a88ec

Browse files
authored
Merge pull request #64 from gtm-nayan/error-path-post-map
fix: wrong path in error message if value comes after a map
2 parents 4ce76d6 + 8de4fca commit 49a88ec

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/stringify.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ export function stringify(value, reducers) {
128128
`.get(${is_primitive(key) ? stringify_primitive(key) : '...'})`
129129
);
130130
str += `,${flatten(key)},${flatten(value)}`;
131+
keys.pop();
131132
}
132133

133134
str += ']';

test/test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,21 @@ for (const fn of [uneval, stringify]) {
571571
assert.equal(e.path, '.foo.map.get("key")');
572572
}
573573
});
574+
575+
uvu.test(`${fn.name} populates error.path after maps (#64)`, () => {
576+
try {
577+
fn({
578+
map: new Map([['key', 'value']]),
579+
object: {
580+
invalid() {}
581+
}
582+
});
583+
} catch (e) {
584+
assert.equal(e.name, 'DevalueError');
585+
assert.equal(e.message, 'Cannot stringify a function');
586+
assert.equal(e.path, '.object.invalid');
587+
}
588+
});
574589
}
575590

576591
uvu.test('does not create duplicate parameter names', () => {

0 commit comments

Comments
 (0)