Improve json error code frame (#10433)
This commit is contained in:
1 parent
7aff95cac1
commit
ed9e9ab649
3 files changed
+35
-18
No files matched your search
@@ -96,15 +96,15 @@ function assertJsonNode(node, parent) {
|
||||
}
|
||||
|
||||
function createJsonError(attribute) {
|
||||
const name = !attribute
|
||||
? node.type
|
||||
: `${node.type} with ${attribute}=${JSON.stringify(node[attribute])}`;
|
||||
return createError(`${name} is not allowed in JSON.`, {
|
||||
start: {
|
||||
line: node.loc.start.line,
|
||||
column: node.loc.start.column + 1,
|
||||
},
|
||||
});
|
||||
const { type, loc } = node;
|
||||
const name = attribute
|
||||
? `${type} with ${attribute}=${JSON.stringify(node[attribute])}`
|
||||
: type;
|
||||
const [start, end] = [loc.start, loc.end].map(({ line, column }) => ({
|
||||
line,
|
||||
column: column + 1,
|
||||
}));
|
||||
return createError(`${name} is not allowed in JSON.`, { start, end });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user