| 343 | } |
| 344 | |
| 345 | function removeObjectProperty(loc: {start: number; end: number}): void { |
| 346 | if (!s) return |
| 347 | // Find the property boundaries: walk back to find key start, walk forward past trailing comma |
| 348 | let propStart = loc.start |
| 349 | // Walk backward past value, colon, key, and any whitespace |
| 350 | let i = loc.start - 1 |
| 351 | while ( |
| 352 | i >= 0 && |
| 353 | (code[i] === ' ' || |
| 354 | code[i] === '\t' || |
| 355 | code[i] === '\n' || |
| 356 | code[i] === '\r') |
| 357 | ) |
| 358 | i-- |
| 359 | // Skip colon |
| 360 | if (i >= 0 && code[i] === ':') i-- |
| 361 | while ( |
| 362 | i >= 0 && |
| 363 | (code[i] === ' ' || |
| 364 | code[i] === '\t' || |
| 365 | code[i] === '\n' || |
| 366 | code[i] === '\r') |
| 367 | ) |
| 368 | i-- |
| 369 | // Walk backward through key (identifier or string literal) |
| 370 | if (i >= 0 && (code[i] === '"' || code[i] === "'")) { |
| 371 | const quote = code[i] |
| 372 | i-- |
| 373 | while (i >= 0 && code[i] !== quote) i-- |
| 374 | if (i >= 0) i-- // skip opening quote |
| 375 | } else { |
| 376 | while (i >= 0 && /[a-zA-Z0-9_$]/.test(code[i])) i-- |
| 377 | } |
| 378 | propStart = i + 1 |
| 379 | |
| 380 | let propEnd = loc.end |
| 381 | // Walk forward past trailing comma and whitespace |
| 382 | let j = loc.end |
| 383 | while (j < code.length && (code[j] === ' ' || code[j] === '\t')) j++ |
| 384 | if (j < code.length && code[j] === ',') { |
| 385 | j++ |
| 386 | // Also skip whitespace after comma |
| 387 | while (j < code.length && (code[j] === ' ' || code[j] === '\t')) j++ |
| 388 | // Skip one newline |
| 389 | if (j < code.length && code[j] === '\n') j++ |
| 390 | else if (j < code.length && code[j] === '\r') { |
| 391 | j++ |
| 392 | if (j < code.length && code[j] === '\n') j++ |
| 393 | } |
| 394 | } |
| 395 | propEnd = j |
| 396 | |
| 397 | // Also remove leading whitespace/newline |
| 398 | let k = propStart - 1 |
| 399 | while (k >= 0 && (code[k] === ' ' || code[k] === '\t')) k-- |
| 400 | if (k >= 0 && (code[k] === '\n' || code[k] === ',')) { |
| 401 | propStart = k + 1 |
| 402 | } |