@@ -254,6 +254,48 @@ function tryBacktrackAddStarExportBinding (bPos) { |
254 | 254 | } |
255 | 255 | } |
256 | 256 |
|
| 257 | +// `Object.` `prototype.`? hasOwnProperty.call(` IDENTIFIER `, ` IDENTIFIER$2 `)` |
| 258 | +function tryParseObjectHasOwnProperty (it_id) { |
| 259 | + ch = commentWhitespace(); |
| 260 | + if (ch !== 79/*O*/ || !source.startsWith('bject', pos + 1)) return false; |
| 261 | + pos += 6; |
| 262 | + ch = commentWhitespace(); |
| 263 | + if (ch !== 46/*.*/) return false; |
| 264 | + pos++; |
| 265 | + ch = commentWhitespace(); |
| 266 | + if (ch === 112/*p*/) { |
| 267 | + if (!source.startsWith('rototype', pos + 1)) return false; |
| 268 | + pos += 9; |
| 269 | + ch = commentWhitespace(); |
| 270 | + if (ch !== 46/*.*/) return false; |
| 271 | + pos++; |
| 272 | + ch = commentWhitespace(); |
| 273 | + } |
| 274 | + if (ch !== 104/*h*/ || !source.startsWith('asOwnProperty', pos + 1)) return false; |
| 275 | + pos += 14; |
| 276 | + ch = commentWhitespace(); |
| 277 | + if (ch !== 46/*.*/) return false; |
| 278 | + pos++; |
| 279 | + ch = commentWhitespace(); |
| 280 | + if (ch !== 99/*c*/ || !source.startsWith('all', pos + 1)) return false; |
| 281 | + pos += 4; |
| 282 | + ch = commentWhitespace(); |
| 283 | + if (ch !== 40/*(*/) return false; |
| 284 | + pos++; |
| 285 | + ch = commentWhitespace(); |
| 286 | + if (!identifier()) return false; |
| 287 | + ch = commentWhitespace(); |
| 288 | + if (ch !== 44/*,*/) return false; |
| 289 | + pos++; |
| 290 | + ch = commentWhitespace(); |
| 291 | + if (!source.startsWith(it_id, pos)) return false; |
| 292 | + pos += it_id.length; |
| 293 | + ch = commentWhitespace(); |
| 294 | + if (ch !== 41/*)*/) return false; |
| 295 | + pos++; |
| 296 | + return true; |
| 297 | +} |
| 298 | + |
257 | 299 | function tryParseObjectDefineOrKeys (keys) { |
258 | 300 | pos += 6; |
259 | 301 | let revertPos = pos - 1; |
@@ -366,6 +408,10 @@ function tryParseObjectDefineOrKeys (keys) { |
366 | 408 | if (ch !== 125/*}*/) break; |
367 | 409 | pos++; |
368 | 410 | ch = commentWhitespace(); |
| 411 | + if (ch === 44/*,*/) { |
| 412 | + pos++; |
| 413 | + ch = commentWhitespace(); |
| 414 | + } |
369 | 415 | if (ch !== 125/*}*/) break; |
370 | 416 | pos++; |
371 | 417 | ch = commentWhitespace(); |
@@ -469,8 +515,94 @@ function tryParseObjectDefineOrKeys (keys) { |
469 | 515 | if (ch === 59/*;*/) |
470 | 516 | pos++; |
471 | 517 | ch = commentWhitespace(); |
| 518 | + |
| 519 | + // `if (` |
| 520 | + if (ch === 105/*i*/ && source.charCodeAt(pos + 1) === 102/*f*/) { |
| 521 | + let inIf = true; |
| 522 | + pos += 2; |
| 523 | + ch = commentWhitespace(); |
| 524 | + if (ch !== 40/*(*/) break; |
| 525 | + pos++; |
| 526 | + const ifInnerPos = pos; |
| 527 | + // `Object.prototype.hasOwnProperty.call(` IDENTIFIER `, ` IDENTIFIER$2 `)) return` `;`? |
| 528 | + if (tryParseObjectHasOwnProperty(it_id)) { |
| 529 | + ch = commentWhitespace(); |
| 530 | + if (ch !== 41/*)*/) break; |
| 531 | + pos++; |
| 532 | + ch = commentWhitespace(); |
| 533 | + if (ch !== 114/*r*/ || !source.startsWith('eturn', pos + 1)) break; |
| 534 | + pos += 6; |
| 535 | + ch = commentWhitespace(); |
| 536 | + if (ch === 59/*;*/) |
| 537 | + pos++; |
| 538 | + ch = commentWhitespace(); |
| 539 | + // match next if |
| 540 | + if (ch === 105/*i*/ && source.charCodeAt(pos + 1) === 102/*f*/) { |
| 541 | + pos += 2; |
| 542 | + ch = commentWhitespace(); |
| 543 | + if (ch !== 40/*(*/) break; |
| 544 | + pos++; |
| 545 | + } |
| 546 | + else { |
| 547 | + inIf = false; |
| 548 | + } |
| 549 | + } |
| 550 | + else { |
| 551 | + pos = ifInnerPos; |
| 552 | + } |
| 553 | + |
| 554 | + // IDENTIFIER$2 `in` EXPORTS_IDENTIFIER `&&` EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] ===` IDENTIFIER$1 `[` IDENTIFIER$2 `]) return` `;`? |
| 555 | + if (inIf) { |
| 556 | + if (!source.startsWith(it_id, pos)) break; |
| 557 | + pos += it_id.length; |
| 558 | + ch = commentWhitespace(); |
| 559 | + if (ch !== 105/*i*/ || !source.startsWith('n ', pos + 1)) break; |
| 560 | + pos += 3; |
| 561 | + ch = commentWhitespace(); |
| 562 | + if (!readExportsOrModuleDotExports(ch)) break; |
| 563 | + ch = commentWhitespace(); |
| 564 | + if (ch !== 38/*&*/ || source.charCodeAt(pos + 1) !== 38/*&*/) break; |
| 565 | + pos += 2; |
| 566 | + ch = commentWhitespace(); |
| 567 | + if (!readExportsOrModuleDotExports(ch)) break; |
| 568 | + ch = commentWhitespace(); |
| 569 | + if (ch !== 91/*[*/) break; |
| 570 | + pos++; |
| 571 | + ch = commentWhitespace(); |
| 572 | + if (!source.startsWith(it_id, pos)) break; |
| 573 | + pos += it_id.length; |
| 574 | + ch = commentWhitespace(); |
| 575 | + if (ch !== 93/*]*/) break; |
| 576 | + pos++; |
| 577 | + ch = commentWhitespace(); |
| 578 | + if (ch !== 61/*=*/ || !source.startsWith('==', pos + 1)) break; |
| 579 | + pos += 3; |
| 580 | + ch = commentWhitespace(); |
| 581 | + if (!source.startsWith(id, pos)) break; |
| 582 | + pos += id.length; |
| 583 | + ch = commentWhitespace(); |
| 584 | + if (ch !== 91/*[*/) break; |
| 585 | + pos++; |
| 586 | + ch = commentWhitespace(); |
| 587 | + if (!source.startsWith(it_id, pos)) break; |
| 588 | + pos += it_id.length; |
| 589 | + ch = commentWhitespace(); |
| 590 | + if (ch !== 93/*]*/) break; |
| 591 | + pos++; |
| 592 | + ch = commentWhitespace(); |
| 593 | + if (ch !== 41/*)*/) break; |
| 594 | + pos++; |
| 595 | + ch = commentWhitespace(); |
| 596 | + if (ch !== 114/*r*/ || !source.startsWith('eturn', pos + 1)) break; |
| 597 | + pos += 6; |
| 598 | + ch = commentWhitespace(); |
| 599 | + if (ch === 59/*;*/) |
| 600 | + pos++; |
| 601 | + ch = commentWhitespace(); |
| 602 | + } |
| 603 | + } |
472 | 604 | } |
473 | | - // `if (` IDENTIFIER$2 `!==` ( `'default'` | `"default"` ) `)` |
| 605 | + // `if (` IDENTIFIER$2 `!==` ( `'default'` | `"default"` ) (`&& !` IDENTIFIER `.hasOwnProperty(` IDENTIFIER$2 `)` )? `)` |
474 | 606 | else if (ch === 33/*!*/) { |
475 | 607 | if (!source.startsWith('==', pos + 1)) break; |
476 | 608 | pos += 3; |
@@ -483,67 +615,40 @@ function tryParseObjectDefineOrKeys (keys) { |
483 | 615 | if (ch !== quot) break; |
484 | 616 | pos += 1; |
485 | 617 | ch = commentWhitespace(); |
| 618 | + if (ch === 38/*&*/) { |
| 619 | + if (source.charCodeAt(pos + 1) !== 38/*&*/) break; |
| 620 | + pos += 2; |
| 621 | + ch = commentWhitespace(); |
| 622 | + if (ch !== 33/*!*/) break; |
| 623 | + pos += 1; |
| 624 | + ch = commentWhitespace(); |
| 625 | + if (source.startsWith(id, pos)) { |
| 626 | + pos += id.length; |
| 627 | + ch = commentWhitespace(); |
| 628 | + if (ch !== 46/*.*/) break; |
| 629 | + pos++; |
| 630 | + ch = commentWhitespace(); |
| 631 | + if (ch !== 104/*h*/ || !source.startsWith('asOwnProperty', pos + 1)) break; |
| 632 | + pos += 14; |
| 633 | + ch = commentWhitespace(); |
| 634 | + if (ch !== 40/*(*/) break; |
| 635 | + pos += 1; |
| 636 | + ch = commentWhitespace(); |
| 637 | + if (!source.startsWith(it_id, pos)) break; |
| 638 | + pos += it_id.length; |
| 639 | + ch = commentWhitespace(); |
| 640 | + if (ch !== 41/*)*/) break; |
| 641 | + pos += 1; |
| 642 | + } |
| 643 | + else if (!tryParseObjectHasOwnProperty(it_id)) break; |
| 644 | + ch = commentWhitespace(); |
| 645 | + } |
486 | 646 | if (ch !== 41/*)*/) break; |
487 | 647 | pos += 1; |
488 | 648 | ch = commentWhitespace(); |
489 | 649 | } |
490 | 650 | else break; |
491 | 651 |
|
492 | | - // `if (` IDENTIFIER$2 `in` EXPORTS_IDENTIFIER `&&` EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] ===` IDENTIFIER$1 `[` IDENTIFIER$2 `]) return` `;`? |
493 | | - if (ch === 105/*i*/ && source.charCodeAt(pos + 1) === 102/*f*/) { |
494 | | - pos += 2; |
495 | | - ch = commentWhitespace(); |
496 | | - if (ch !== 40/*(*/) break; |
497 | | - pos++; |
498 | | - ch = commentWhitespace(); |
499 | | - if (!source.startsWith(it_id, pos)) break; |
500 | | - pos += it_id.length; |
501 | | - ch = commentWhitespace(); |
502 | | - if (ch !== 105/*i*/ || !source.startsWith('n ', pos + 1)) break; |
503 | | - pos += 3; |
504 | | - ch = commentWhitespace(); |
505 | | - if (!readExportsOrModuleDotExports(ch)) break; |
506 | | - ch = commentWhitespace(); |
507 | | - if (ch !== 38/*&*/ || source.charCodeAt(pos + 1) !== 38/*&*/) break; |
508 | | - pos += 2; |
509 | | - ch = commentWhitespace(); |
510 | | - if (!readExportsOrModuleDotExports(ch)) break; |
511 | | - ch = commentWhitespace(); |
512 | | - if (ch !== 91/*[*/) break; |
513 | | - pos++; |
514 | | - ch = commentWhitespace(); |
515 | | - if (!source.startsWith(it_id, pos)) break; |
516 | | - pos += it_id.length; |
517 | | - ch = commentWhitespace(); |
518 | | - if (ch !== 93/*]*/) break; |
519 | | - pos++; |
520 | | - ch = commentWhitespace(); |
521 | | - if (ch !== 61/*=*/ || !source.startsWith('==', pos + 1)) break; |
522 | | - pos += 3; |
523 | | - ch = commentWhitespace(); |
524 | | - if (!source.startsWith(id, pos)) break; |
525 | | - pos += id.length; |
526 | | - ch = commentWhitespace(); |
527 | | - if (ch !== 91/*[*/) break; |
528 | | - pos++; |
529 | | - ch = commentWhitespace(); |
530 | | - if (!source.startsWith(it_id, pos)) break; |
531 | | - pos += it_id.length; |
532 | | - ch = commentWhitespace(); |
533 | | - if (ch !== 93/*]*/) break; |
534 | | - pos++; |
535 | | - ch = commentWhitespace(); |
536 | | - if (ch !== 41/*)*/) break; |
537 | | - pos++; |
538 | | - ch = commentWhitespace(); |
539 | | - if (ch !== 114/*r*/ || !source.startsWith('eturn', pos + 1)) break; |
540 | | - pos += 6; |
541 | | - ch = commentWhitespace(); |
542 | | - if (ch === 59/*;*/) |
543 | | - pos++; |
544 | | - ch = commentWhitespace(); |
545 | | - } |
546 | | - |
547 | 652 | // EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] =` IDENTIFIER$1 `[` IDENTIFIER$2 `]` |
548 | 653 | if (readExportsOrModuleDotExports(ch)) { |
549 | 654 | ch = commentWhitespace(); |
@@ -656,6 +761,10 @@ function tryParseObjectDefineOrKeys (keys) { |
656 | 761 | if (ch !== 125/*}*/) break; |
657 | 762 | pos++; |
658 | 763 | ch = commentWhitespace(); |
| 764 | + if (ch === 44/*,*/) { |
| 765 | + pos++; |
| 766 | + ch = commentWhitespace(); |
| 767 | + } |
659 | 768 | if (ch !== 125/*}*/) break; |
660 | 769 | pos++; |
661 | 770 | ch = commentWhitespace(); |
@@ -1039,7 +1148,6 @@ function throwIfImportStatement () { |
1039 | 1148 | // import.meta |
1040 | 1149 | case 46/*.*/: |
1041 | 1150 | throw new Error('Unexpected import.meta in CJS module.'); |
1042 | | - return; |
1043 | 1151 |
|
1044 | 1152 | default: |
1045 | 1153 | // no space after "import" -> not an import keyword |
|