From eab3761da600c5c4726b1c2710b1ea2d5b93bef9 Mon Sep 17 00:00:00 2001 From: gtmnayan Date: Sun, 16 Apr 2023 19:39:49 +0545 Subject: [PATCH 1/2] fix: wrong path in error if value comes after a map --- src/stringify.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/stringify.js b/src/stringify.js index 8ce427e..64b53bf 100644 --- a/src/stringify.js +++ b/src/stringify.js @@ -128,6 +128,7 @@ export function stringify(value, reducers) { `.get(${is_primitive(key) ? stringify_primitive(key) : '...'})` ); str += `,${flatten(key)},${flatten(value)}`; + keys.pop(); } str += ']'; From a306b98a52f3edd0c9ce13ae8b41a73663d98da2 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Fri, 19 Apr 2024 12:44:10 -0400 Subject: [PATCH 2/2] add test --- test/test.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/test.js b/test/test.js index 1857c6b..ecc786e 100644 --- a/test/test.js +++ b/test/test.js @@ -560,6 +560,21 @@ for (const fn of [uneval, stringify]) { assert.equal(e.path, '.foo.map.get("key")'); } }); + + uvu.test(`${fn.name} populates error.path after maps (#64)`, () => { + try { + fn({ + map: new Map([['key', 'value']]), + object: { + invalid() {} + } + }); + } catch (e) { + assert.equal(e.name, 'DevalueError'); + assert.equal(e.message, 'Cannot stringify a function'); + assert.equal(e.path, '.object.invalid'); + } + }); } uvu.test('does not create duplicate parameter names', () => {