MCPcopy Create free account
hub / github.com/denoland/std / #parseObject

Method #parseObject

jsonc/parse.ts:206–261  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

204 }
205
206 #parseObject(): { [key: string]: JsonValue | undefined } {
207 const target: { [key: string]: JsonValue | undefined } = {};
208 // ┌─token1
209 // { }
210 // ┌─────────────token1
211 // │ ┌─────────token2
212 // │ │ ┌─────token3
213 // │ │ │ ┌─token4
214 // { "key" : value }
215 // ┌───────────────token1
216 // │ ┌───────────token2
217 // │ │ ┌───────token3
218 // │ │ │ ┌───token4
219 // │ │ │ │ ┌─token1
220 // { "key" : value , }
221 // ┌─────────────────────────────token1
222 // │ ┌─────────────────────────token2
223 // │ │ ┌─────────────────────token3
224 // │ │ │ ┌─────────────────token4
225 // │ │ │ │ ┌─────────────token1
226 // │ │ │ │ │ ┌─────────token2
227 // │ │ │ │ │ │ ┌─────token3
228 // │ │ │ │ │ │ │ ┌─token4
229 // { "key" : value , "key" : value }
230 while (true) {
231 const token1 = this.#getNext();
232 if (token1.type === "EndObject") {
233 return target;
234 }
235 if (token1.type !== "String") {
236 throw new SyntaxError(buildErrorMessage(token1));
237 }
238 const key = this.#parseString(token1);
239
240 const token2 = this.#getNext();
241 if (token2.type !== "NameSeparator") {
242 throw new SyntaxError(buildErrorMessage(token2));
243 }
244
245 const token3 = this.#getNext();
246 Object.defineProperty(target, key, {
247 value: this.#parseJsonValue(token3),
248 writable: true,
249 enumerable: true,
250 configurable: true,
251 });
252
253 const token4 = this.#getNext();
254 if (token4.type === "EndObject") {
255 return target;
256 }
257 if (token4.type !== "ValueSeparator") {
258 throw new SyntaxError(buildErrorMessage(token4));
259 }
260 }
261 }
262
263 #parseArray(): JsonValue[] {

Callers 1

#parseJsonValueMethod · 0.95

Calls 4

#getNextMethod · 0.95
#parseStringMethod · 0.95
#parseJsonValueMethod · 0.95
buildErrorMessageFunction · 0.85

Tested by

no test coverage detected