MCPcopy
hub / github.com/loggerhead/json4u / onLiteralValue

Method onLiteralValue

src/lib/parser/parse.ts:255–290  ·  view source on GitHub ↗
(value: any, offset: number, length: number, pathSupplier: () => jsonc.JSONPath)

Source from the content-addressed store, hash-verified

253 }
254
255 onLiteralValue(value: any, offset: number, length: number, pathSupplier: () => jsonc.JSONPath) {
256 if (this.parseErrors.length > 0) {
257 return;
258 }
259
260 let node: ParseNode | undefined = undefined;
261 let errors = undefined;
262 const path = this.genPath(pathSupplier);
263
264 if (this.options?.nest && maybeIterable(value)) {
265 const { root, nodeMap, parseErrors } = doParseJSON(value, this.options, { path });
266 node = root;
267 errors = parseErrors;
268
269 if (node && isEmpty(errors)) {
270 for (const key in nodeMap) {
271 const nd = nodeMap[key];
272 this.nodeMap[nd.id] = nd;
273 }
274
275 // boundOffset and boundLength will be fixed in stringifyNestNodes or stringify
276 node.offset = offset;
277 node.length = length;
278 this.nestNodeMap[node.id] = node;
279 } else {
280 node = undefined;
281 }
282 }
283
284 if (node === undefined) {
285 node = this.newNode(path, getNodeType(value), offset, length);
286 this.setValue(node, value, offset, length);
287 }
288
289 this.addChild(node);
290 }
291
292 onError(error: jsonc.ParseErrorCode, offset: number, length: number) {
293 this.parseErrors.push({ error, offset, length });

Callers 1

onLiteralValueFunction · 0.80

Calls 7

genPathMethod · 0.95
newNodeMethod · 0.95
setValueMethod · 0.95
addChildMethod · 0.95
maybeIterableFunction · 0.85
doParseJSONFunction · 0.85
getNodeTypeFunction · 0.85

Tested by

no test coverage detected