Skip to content

Commit

Permalink
Merge pull request #64 from gtm-nayan/error-path-post-map
Browse files Browse the repository at this point in the history
fix: wrong path in error message if value comes after a map
  • Loading branch information
Rich-Harris committed Apr 19, 2024
2 parents 4ce76d6 + 8de4fca commit 49a88ec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export function stringify(value, reducers) {
`.get(${is_primitive(key) ? stringify_primitive(key) : '...'})`
);
str += `,${flatten(key)},${flatten(value)}`;
keys.pop();
}

str += ']';
Expand Down
15 changes: 15 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,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', () => {
Expand Down

0 comments on commit 49a88ec

Please sign in to comment.