Improve json error code frame (#10433)

This commit is contained in:
fisker Cheung authored and GitHub committed 2021-03-01 10:04:09 +08:00
1 parent 7aff95cac1
commit ed9e9ab649
3 files changed
+35 -18

No files matched your search

+9 -9
View File
@@ -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 });
}
}