()
| 35 | } |
| 36 | |
| 37 | private parseObject(): any { |
| 38 | const obj: Record<string, any> = {}; |
| 39 | this.expectChar('{'); |
| 40 | this.skipWhitespace(); |
| 41 | // Empty object? |
| 42 | if (this.currentChar() === '}') { |
| 43 | this.index++; // consume "}" |
| 44 | return obj; |
| 45 | } |
| 46 | while (true) { |
| 47 | this.skipWhitespace(); |
| 48 | let key: string; |
| 49 | const ch = this.currentChar(); |
| 50 | if (ch === '"' || ch === "'") { |
| 51 | key = this.parseString(); |
| 52 | } else { |
| 53 | key = this.parseIdentifier(); |
| 54 | } |
| 55 | this.skipWhitespace(); |
| 56 | this.expectChar(':'); |
| 57 | this.skipWhitespace(); |
| 58 | const value = this.parseValue(); |
| 59 | obj[key] = value; |
| 60 | this.skipWhitespace(); |
| 61 | if (this.currentChar() === ',') { |
| 62 | this.index++; // consume comma |
| 63 | this.skipWhitespace(); |
| 64 | // Allow trailing comma: if next is "}", break out. |
| 65 | if (this.currentChar() === '}') { |
| 66 | this.index++; |
| 67 | break; |
| 68 | } |
| 69 | } else if (this.currentChar() === '}') { |
| 70 | this.index++; // consume "}" |
| 71 | break; |
| 72 | } else { |
| 73 | throw this.error( |
| 74 | `Expected ',' or '}' in object but found '${this.currentChar()}'` |
| 75 | ); |
| 76 | } |
| 77 | } |
| 78 | return obj; |
| 79 | } |
| 80 | |
| 81 | private parseArray(): any[] { |
| 82 | const arr: any[] = []; |
no test coverage detected