1let source, pos, end; 2let openTokenDepth, 3 templateDepth, 4 lastTokenPos, 5 lastSlashWasDivision, 6 templateStack, 7 templateStackDepth, 8 openTokenPosStack, 9 openClassPosStack, 10 nextBraceIsClass, 11 starExportMap, 12 lastStarExportSpecifier, 13 _exports, 14 unsafeGetters, 15 reexports; 16 17function resetState () { 18 openTokenDepth = 0; 19 templateDepth = -1; 20 lastTokenPos = -1; 21 lastSlashWasDivision = false; 22 templateStack = new Array(1024); 23 templateStackDepth = 0; 24 openTokenPosStack = new Array(1024); 25 openClassPosStack = new Array(1024); 26 nextBraceIsClass = false; 27 starExportMap = Object.create(null); 28 lastStarExportSpecifier = null; 29 30 _exports = new Set(); 31 unsafeGetters = new Set(); 32 reexports = new Set(); 33} 34 35// RequireType 36const Import = 0; 37const ExportAssign = 1; 38const ExportStar = 2; 39 40const strictReserved = new Set(['implements', 'interface', 'let', 'package', 'private', 'protected', 'public', 'static', 'yield', 'enum']); 41 42function parseCJS (source, name = '@') { 43 resetState(); 44 try { 45 parseSource(source); 46 } 47 catch (e) { 48 e.message += `\n at ${name}:${source.slice(0, pos).split('\n').length}:${pos - source.lastIndexOf('\n', pos - 1)}`; 49 e.loc = pos; 50 throw e; 51 } 52 const result = { exports: [..._exports].filter(expt => !unsafeGetters.has(expt)), reexports: [...reexports] }; 53 resetState(); 54 return result; 55} 56 57function addExport (name) { 58 if (!strictReserved.has(name)) 59 _exports.add(name); 60} 61 62function parseSource (cjsSource) { 63 source = cjsSource; 64 pos = -1; 65 end = source.length - 1; 66 let ch = 0; 67 68 // Handle #! 69 if (source.charCodeAt(0) === 35/*#*/ && source.charCodeAt(1) === 33/*!*/) { 70 if (source.length === 2) 71 return true; 72 pos += 2; 73 while (pos++ < end) { 74 ch = source.charCodeAt(pos); 75 if (ch === 10/*\n*/ || ch === 13/*\r*/) 76 break; 77 } 78 } 79 80 while (pos++ < end) { 81 ch = source.charCodeAt(pos); 82 83 if (ch === 32 || ch < 14 && ch > 8) 84 continue; 85 86 if (openTokenDepth === 0) { 87 switch (ch) { 88 case 105/*i*/: 89 if (source.startsWith('mport', pos + 1) && keywordStart(pos)) 90 throwIfImportStatement(); 91 lastTokenPos = pos; 92 continue; 93 case 114/*r*/: 94 const startPos = pos; 95 if (tryParseRequire(Import) && keywordStart(startPos)) 96 tryBacktrackAddStarExportBinding(startPos - 1); 97 lastTokenPos = pos; 98 continue; 99 case 95/*_*/: 100 if (source.startsWith('_export', pos + 1) && (keywordStart(pos) || source.charCodeAt(pos - 1) === 46/*.*/)) { 101 pos += 8; 102 if (source.startsWith('Star', pos)) 103 pos += 4; 104 if (source.charCodeAt(pos) === 40/*(*/) { 105 openTokenPosStack[openTokenDepth++] = lastTokenPos; 106 if (source.charCodeAt(++pos) === 114/*r*/) 107 tryParseRequire(ExportStar); 108 } 109 } 110 lastTokenPos = pos; 111 continue; 112 } 113 } 114 115 switch (ch) { 116 case 101/*e*/: 117 if (source.startsWith('xport', pos + 1) && keywordStart(pos)) { 118 if (source.charCodeAt(pos + 6) === 115/*s*/) 119 tryParseExportsDotAssign(false); 120 else if (openTokenDepth === 0) 121 throwIfExportStatement(); 122 } 123 break; 124 case 99/*c*/: 125 if (keywordStart(pos) && source.startsWith('lass', pos + 1) && isBrOrWs(source.charCodeAt(pos + 5))) 126 nextBraceIsClass = true; 127 break; 128 case 109/*m*/: 129 if (source.startsWith('odule', pos + 1) && keywordStart(pos)) 130 tryParseModuleExportsDotAssign(); 131 break; 132 case 79/*O*/: 133 if (source.startsWith('bject', pos + 1) && keywordStart(pos)) 134 tryParseObjectDefineOrKeys(openTokenDepth === 0); 135 break; 136 case 40/*(*/: 137 openTokenPosStack[openTokenDepth++] = lastTokenPos; 138 break; 139 case 41/*)*/: 140 if (openTokenDepth === 0) 141 throw new Error('Unexpected closing bracket.'); 142 openTokenDepth--; 143 break; 144 case 123/*{*/: 145 openClassPosStack[openTokenDepth] = nextBraceIsClass; 146 nextBraceIsClass = false; 147 openTokenPosStack[openTokenDepth++] = lastTokenPos; 148 break; 149 case 125/*}*/: 150 if (openTokenDepth === 0) 151 throw new Error('Unexpected closing brace.'); 152 if (openTokenDepth-- === templateDepth) { 153 templateDepth = templateStack[--templateStackDepth]; 154 templateString(); 155 } 156 else { 157 if (templateDepth !== -1 && openTokenDepth < templateDepth) 158 throw new Error('Unexpected closing brace.'); 159 } 160 break; 161 case 60/*>*/: 162 // TODO: <!-- XML comment support 163 break; 164 case 39/*'*/: 165 singleQuoteString(); 166 break; 167 case 34/*"*/: 168 doubleQuoteString(); 169 break; 170 case 47/*/*/: { 171 const next_ch = source.charCodeAt(pos + 1); 172 if (next_ch === 47/*/*/) { 173 lineComment(); 174 // dont update lastToken 175 continue; 176 } 177 else if (next_ch === 42/***/) { 178 blockComment(); 179 // dont update lastToken 180 continue; 181 } 182 else { 183 // Division / regex ambiguity handling based on checking backtrack analysis of: 184 // - what token came previously (lastToken) 185 // - if a closing brace or paren, what token came before the corresponding 186 // opening brace or paren (lastOpenTokenIndex) 187 const lastToken = source.charCodeAt(lastTokenPos); 188 if (isExpressionPunctuator(lastToken) && 189 !(lastToken === 46/*.*/ && (source.charCodeAt(lastTokenPos - 1) >= 48/*0*/ && source.charCodeAt(lastTokenPos - 1) <= 57/*9*/)) && 190 !(lastToken === 43/*+*/ && source.charCodeAt(lastTokenPos - 1) === 43/*+*/) && !(lastToken === 45/*-*/ && source.charCodeAt(lastTokenPos - 1) === 45/*-*/) || 191 lastToken === 41/*)*/ && isParenKeyword(openTokenPosStack[openTokenDepth]) || 192 lastToken === 125/*}*/ && (isExpressionTerminator(openTokenPosStack[openTokenDepth]) || openClassPosStack[openTokenDepth]) || 193 lastToken === 47/*/*/ && lastSlashWasDivision || 194 isExpressionKeyword(lastTokenPos) || 195 !lastToken) { 196 regularExpression(); 197 lastSlashWasDivision = false; 198 } 199 else { 200 lastSlashWasDivision = true; 201 } 202 } 203 break; 204 } 205 case 96/*`*/: 206 templateString(); 207 break; 208 } 209 lastTokenPos = pos; 210 } 211 212 if (templateDepth !== -1) 213 throw new Error('Unterminated template.'); 214 215 if (openTokenDepth) 216 throw new Error('Unterminated braces.'); 217} 218 219function tryBacktrackAddStarExportBinding (bPos) { 220 while (source.charCodeAt(bPos) === 32/* */ && bPos >= 0) 221 bPos--; 222 if (source.charCodeAt(bPos) === 61/*=*/) { 223 bPos--; 224 while (source.charCodeAt(bPos) === 32/* */ && bPos >= 0) 225 bPos--; 226 let codePoint; 227 const id_end = bPos; 228 let identifierStart = false; 229 while ((codePoint = codePointAtLast(bPos)) && bPos >= 0) { 230 if (codePoint === 92/*\*/) 231 return; 232 if (!isIdentifierChar(codePoint, true)) 233 break; 234 identifierStart = isIdentifierStart(codePoint, true); 235 bPos -= codePointLen(codePoint); 236 } 237 if (identifierStart && source.charCodeAt(bPos) === 32/* */) { 238 const starExportId = source.slice(bPos + 1, id_end + 1); 239 while (source.charCodeAt(bPos) === 32/* */ && bPos >= 0) 240 bPos--; 241 switch (source.charCodeAt(bPos)) { 242 case 114/*r*/: 243 if (!source.startsWith('va', bPos - 2)) 244 return; 245 break; 246 case 116/*t*/: 247 if (!source.startsWith('le', bPos - 2) && !source.startsWith('cons', bPos - 4)) 248 return; 249 break; 250 default: return; 251 } 252 starExportMap[starExportId] = lastStarExportSpecifier; 253 } 254 } 255} 256 257function tryParseObjectDefineOrKeys (keys) { 258 pos += 6; 259 let revertPos = pos - 1; 260 let ch = commentWhitespace(); 261 if (ch === 46/*.*/) { 262 pos++; 263 ch = commentWhitespace(); 264 if (ch === 100/*d*/ && source.startsWith('efineProperty', pos + 1)) { 265 let expt; 266 while (true) { 267 pos += 14; 268 revertPos = pos - 1; 269 ch = commentWhitespace(); 270 if (ch !== 40/*(*/) break; 271 pos++; 272 ch = commentWhitespace(); 273 if (!readExportsOrModuleDotExports(ch)) break; 274 ch = commentWhitespace(); 275 if (ch !== 44/*,*/) break; 276 pos++; 277 ch = commentWhitespace(); 278 if (ch !== 39/*'*/ && ch !== 34/*"*/) break; 279 let quot = ch; 280 const exportPos = ++pos; 281 if (!identifier() || source.charCodeAt(pos) !== quot) break; 282 expt = source.slice(exportPos, pos); 283 pos++; 284 ch = commentWhitespace(); 285 if (ch !== 44/*,*/) break; 286 pos++; 287 ch = commentWhitespace(); 288 if (ch !== 123/*{*/) break; 289 pos++; 290 ch = commentWhitespace(); 291 if (ch === 101/*e*/) { 292 if (!source.startsWith('numerable', pos + 1)) break; 293 pos += 10; 294 ch = commentWhitespace(); 295 if (ch !== 58/*:*/) break; 296 pos++; 297 ch = commentWhitespace(); 298 if (ch !== 116/*t*/ || !source.startsWith('rue', pos + 1)) break; 299 pos += 4; 300 ch = commentWhitespace(); 301 if (ch !== 44) break; 302 pos++; 303 ch = commentWhitespace(); 304 } 305 if (ch === 118/*v*/) { 306 if (!source.startsWith('alue', pos + 1)) break; 307 pos += 5; 308 ch = commentWhitespace(); 309 if (ch !== 58/*:*/) break; 310 addExport(expt); 311 pos = revertPos; 312 return; 313 } 314 else if (ch === 103/*g*/) { 315 if (!source.startsWith('et', pos + 1)) break; 316 pos += 3; 317 ch = commentWhitespace(); 318 if (ch === 58/*:*/) { 319 pos++; 320 ch = commentWhitespace(); 321 if (ch !== 102/*f*/) break; 322 if (!source.startsWith('unction', pos + 1)) break; 323 pos += 8; 324 let lastPos = pos; 325 ch = commentWhitespace(); 326 if (ch !== 40 && (lastPos === pos || !identifier())) break; 327 ch = commentWhitespace(); 328 } 329 if (ch !== 40/*(*/) break; 330 pos++; 331 ch = commentWhitespace(); 332 if (ch !== 41/*)*/) break; 333 pos++; 334 ch = commentWhitespace(); 335 if (ch !== 123/*{*/) break; 336 pos++; 337 ch = commentWhitespace(); 338 if (ch !== 114/*r*/) break; 339 if (!source.startsWith('eturn', pos + 1)) break; 340 pos += 6; 341 ch = commentWhitespace(); 342 if (!identifier()) break; 343 ch = commentWhitespace(); 344 if (ch === 46/*.*/) { 345 pos++; 346 commentWhitespace(); 347 if (!identifier()) break; 348 ch = commentWhitespace(); 349 } 350 else if (ch === 91/*[*/) { 351 pos++; 352 ch = commentWhitespace(); 353 if (ch === 39/*'*/) singleQuoteString(); 354 else if (ch === 34/*"*/) doubleQuoteString(); 355 else break; 356 pos++; 357 ch = commentWhitespace(); 358 if (ch !== 93/*]*/) break; 359 pos++; 360 ch = commentWhitespace(); 361 } 362 if (ch === 59/*;*/) { 363 pos++; 364 ch = commentWhitespace(); 365 } 366 if (ch !== 125/*}*/) break; 367 pos++; 368 ch = commentWhitespace(); 369 if (ch !== 125/*}*/) break; 370 pos++; 371 ch = commentWhitespace(); 372 if (ch !== 41/*)*/) break; 373 addExport(expt); 374 return; 375 } 376 break; 377 } 378 if (expt) { 379 unsafeGetters.add(expt); 380 } 381 } 382 else if (keys && ch === 107/*k*/ && source.startsWith('eys', pos + 1)) { 383 while (true) { 384 pos += 4; 385 revertPos = pos - 1; 386 ch = commentWhitespace(); 387 if (ch !== 40/*(*/) break; 388 pos++; 389 ch = commentWhitespace(); 390 const id_start = pos; 391 if (!identifier()) break; 392 const id = source.slice(id_start, pos); 393 ch = commentWhitespace(); 394 if (ch !== 41/*)*/) break; 395 396 revertPos = pos++; 397 ch = commentWhitespace(); 398 if (ch !== 46/*.*/) break; 399 pos++; 400 ch = commentWhitespace(); 401 if (ch !== 102/*f*/ || !source.startsWith('orEach', pos + 1)) break; 402 pos += 7; 403 ch = commentWhitespace(); 404 revertPos = pos - 1; 405 if (ch !== 40/*(*/) break; 406 pos++; 407 ch = commentWhitespace(); 408 if (ch !== 102/*f*/ || !source.startsWith('unction', pos + 1)) break; 409 pos += 8; 410 ch = commentWhitespace(); 411 if (ch !== 40/*(*/) break; 412 pos++; 413 ch = commentWhitespace(); 414 const it_id_start = pos; 415 if (!identifier()) break; 416 const it_id = source.slice(it_id_start, pos); 417 ch = commentWhitespace(); 418 if (ch !== 41/*)*/) break; 419 pos++; 420 ch = commentWhitespace(); 421 if (ch !== 123/*{*/) break; 422 pos++; 423 ch = commentWhitespace(); 424 if (ch !== 105/*i*/ || source.charCodeAt(pos + 1) !== 102/*f*/) break; 425 pos += 2; 426 ch = commentWhitespace(); 427 if (ch !== 40/*(*/) break; 428 pos++; 429 ch = commentWhitespace(); 430 if (!source.startsWith(it_id, pos)) break; 431 pos += it_id.length; 432 ch = commentWhitespace(); 433 // `if (` IDENTIFIER$2 `===` ( `'default'` | `"default"` ) `||` IDENTIFIER$2 `===` ( '__esModule' | `"__esModule"` ) `) return` `;`? | 434 if (ch === 61/*=*/) { 435 if (!source.startsWith('==', pos + 1)) break; 436 pos += 3; 437 ch = commentWhitespace(); 438 if (ch !== 34/*"*/ && ch !== 39/*'*/) break; 439 let quot = ch; 440 if (!source.startsWith('default', pos + 1)) break; 441 pos += 8; 442 ch = commentWhitespace(); 443 if (ch !== quot) break; 444 pos += 1; 445 ch = commentWhitespace(); 446 if (ch !== 124/*|*/ || source.charCodeAt(pos + 1) !== 124/*|*/) break; 447 pos += 2; 448 ch = commentWhitespace(); 449 if (source.slice(pos, pos + it_id.length) !== it_id) break; 450 pos += it_id.length; 451 ch = commentWhitespace(); 452 if (ch !== 61/*=*/ || source.slice(pos + 1, pos + 3) !== '==') break; 453 pos += 3; 454 ch = commentWhitespace(); 455 if (ch !== 34/*"*/ && ch !== 39/*'*/) break; 456 quot = ch; 457 if (!source.startsWith('__esModule', pos + 1)) break; 458 pos += 11; 459 ch = commentWhitespace(); 460 if (ch !== quot) break; 461 pos += 1; 462 ch = commentWhitespace(); 463 if (ch !== 41/*)*/) break; 464 pos += 1; 465 ch = commentWhitespace(); 466 if (ch !== 114/*r*/ || !source.startsWith('eturn', pos + 1)) break; 467 pos += 6; 468 ch = commentWhitespace(); 469 if (ch === 59/*;*/) 470 pos++; 471 ch = commentWhitespace(); 472 } 473 // `if (` IDENTIFIER$2 `!==` ( `'default'` | `"default"` ) `)` 474 else if (ch === 33/*!*/) { 475 if (!source.startsWith('==', pos + 1)) break; 476 pos += 3; 477 ch = commentWhitespace(); 478 if (ch !== 34/*"*/ && ch !== 39/*'*/) break; 479 const quot = ch; 480 if (!source.startsWith('default', pos + 1)) break; 481 pos += 8; 482 ch = commentWhitespace(); 483 if (ch !== quot) break; 484 pos += 1; 485 ch = commentWhitespace(); 486 if (ch !== 41/*)*/) break; 487 pos += 1; 488 ch = commentWhitespace(); 489 } 490 else break; 491 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 // EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] =` IDENTIFIER$1 `[` IDENTIFIER$2 `]` 548 if (readExportsOrModuleDotExports(ch)) { 549 ch = commentWhitespace(); 550 if (ch !== 91/*[*/) break; 551 pos++; 552 ch = commentWhitespace(); 553 if (source.slice(pos, pos + it_id.length) !== it_id) break; 554 pos += it_id.length; 555 ch = commentWhitespace(); 556 if (ch !== 93/*]*/) break; 557 pos++; 558 ch = commentWhitespace(); 559 if (ch !== 61/*=*/) break; 560 pos++; 561 ch = commentWhitespace(); 562 if (source.slice(pos, pos + id.length) !== id) break; 563 pos += id.length; 564 ch = commentWhitespace(); 565 if (ch !== 91/*[*/) break; 566 pos++; 567 ch = commentWhitespace(); 568 if (source.slice(pos, pos + it_id.length) !== it_id) break; 569 pos += it_id.length; 570 ch = commentWhitespace(); 571 if (ch !== 93/*]*/) break; 572 pos++; 573 ch = commentWhitespace(); 574 if (ch === 59/*;*/) { 575 pos++; 576 ch = commentWhitespace(); 577 } 578 } 579 // `Object.defineProperty(` EXPORTS_IDENTIFIER `, ` IDENTIFIER$2 `, { enumerable: true, get: function () { return ` IDENTIFIER$1 `[` IDENTIFIER$2 `]; } })` 580 else if (ch === 79/*O*/) { 581 if (source.slice(pos + 1, pos + 6) !== 'bject') break; 582 pos += 6; 583 ch = commentWhitespace(); 584 if (ch !== 46/*.*/) break; 585 pos++; 586 ch = commentWhitespace(); 587 if (ch !== 100/*d*/ || !source.startsWith('efineProperty', pos + 1)) break; 588 pos += 14; 589 ch = commentWhitespace(); 590 if (ch !== 40/*(*/) break; 591 pos++; 592 ch = commentWhitespace(); 593 if (!readExportsOrModuleDotExports(ch)) break; 594 ch = commentWhitespace(); 595 if (ch !== 44/*,*/) break; 596 pos++; 597 ch = commentWhitespace(); 598 if (!source.startsWith(it_id, pos)) break; 599 pos += it_id.length; 600 ch = commentWhitespace(); 601 if (ch !== 44/*,*/) break; 602 pos++; 603 ch = commentWhitespace(); 604 if (ch !== 123/*{*/) break; 605 pos++; 606 ch = commentWhitespace(); 607 if (ch !== 101/*e*/ || !source.startsWith('numerable', pos + 1)) break; 608 pos += 10; 609 ch = commentWhitespace(); 610 if (ch !== 58/*:*/) break; 611 pos++; 612 ch = commentWhitespace(); 613 if (ch !== 116/*t*/ && !source.startsWith('rue', pos + 1)) break; 614 pos += 4; 615 ch = commentWhitespace(); 616 if (ch !== 44/*,*/) break; 617 pos++; 618 ch = commentWhitespace(); 619 if (ch !== 103/*g*/ || !source.startsWith('et', pos + 1)) break; 620 pos += 3; 621 ch = commentWhitespace(); 622 if (ch !== 58/*:*/) break; 623 pos++; 624 ch = commentWhitespace(); 625 if (ch !== 102/*f*/ || !source.startsWith('unction', pos + 1)) break; 626 pos += 8; 627 ch = commentWhitespace(); 628 if (ch !== 40/*(*/) break; 629 pos++; 630 ch = commentWhitespace(); 631 if (ch !== 41/*)*/) break; 632 pos++; 633 ch = commentWhitespace(); 634 if (ch !== 123/*{*/) break; 635 pos++; 636 ch = commentWhitespace(); 637 if (ch !== 114/*r*/ || !source.startsWith('eturn', pos + 1)) break; 638 pos += 6; 639 ch = commentWhitespace(); 640 if (!source.startsWith(id, pos)) break; 641 pos += id.length; 642 ch = commentWhitespace(); 643 if (ch !== 91/*[*/) break; 644 pos++; 645 ch = commentWhitespace(); 646 if (!source.startsWith(it_id, pos)) break; 647 pos += it_id.length; 648 ch = commentWhitespace(); 649 if (ch !== 93/*]*/) break; 650 pos++; 651 ch = commentWhitespace(); 652 if (ch === 59/*;*/) { 653 pos++; 654 ch = commentWhitespace(); 655 } 656 if (ch !== 125/*}*/) break; 657 pos++; 658 ch = commentWhitespace(); 659 if (ch !== 125/*}*/) break; 660 pos++; 661 ch = commentWhitespace(); 662 if (ch !== 41/*)*/) break; 663 pos++; 664 ch = commentWhitespace(); 665 if (ch === 59/*;*/) { 666 pos++; 667 ch = commentWhitespace(); 668 } 669 } 670 else break; 671 672 if (ch !== 125/*}*/) break; 673 pos++; 674 ch = commentWhitespace(); 675 if (ch !== 41/*)*/) break; 676 677 const starExportSpecifier = starExportMap[id]; 678 if (starExportSpecifier) { 679 reexports.add(starExportSpecifier); 680 pos = revertPos; 681 return; 682 } 683 return; 684 } 685 } 686 } 687 pos = revertPos; 688} 689 690function readExportsOrModuleDotExports (ch) { 691 const revertPos = pos; 692 if (ch === 109/*m*/ && source.startsWith('odule', pos + 1)) { 693 pos += 6; 694 ch = commentWhitespace(); 695 if (ch !== 46/*.*/) { 696 pos = revertPos; 697 return false; 698 } 699 pos++; 700 ch = commentWhitespace(); 701 } 702 if (ch === 101/*e*/ && source.startsWith('xports', pos + 1)) { 703 pos += 7; 704 return true; 705 } 706 else { 707 pos = revertPos; 708 return false; 709 } 710} 711 712function tryParseModuleExportsDotAssign () { 713 pos += 6; 714 const revertPos = pos - 1; 715 let ch = commentWhitespace(); 716 if (ch === 46/*.*/) { 717 pos++; 718 ch = commentWhitespace(); 719 if (ch === 101/*e*/ && source.startsWith('xports', pos + 1)) { 720 tryParseExportsDotAssign(true); 721 return; 722 } 723 } 724 pos = revertPos; 725} 726 727function tryParseExportsDotAssign (assign) { 728 pos += 7; 729 const revertPos = pos - 1; 730 let ch = commentWhitespace(); 731 switch (ch) { 732 // exports.asdf 733 case 46/*.*/: { 734 pos++; 735 ch = commentWhitespace(); 736 const startPos = pos; 737 if (identifier()) { 738 const endPos = pos; 739 ch = commentWhitespace(); 740 if (ch === 61/*=*/) { 741 addExport(source.slice(startPos, endPos)); 742 return; 743 } 744 } 745 break; 746 } 747 // exports['asdf'] 748 case 91/*[*/: { 749 pos++; 750 ch = commentWhitespace(); 751 if (ch === 39/*'*/ || ch === 34/*"*/) { 752 pos++; 753 const startPos = pos; 754 if (identifier() && source.charCodeAt(pos) === ch) { 755 const endPos = pos++; 756 ch = commentWhitespace(); 757 if (ch !== 93/*]*/) 758 break; 759 pos++; 760 ch = commentWhitespace(); 761 if (ch !== 61/*=*/) 762 break; 763 addExport(source.slice(startPos, endPos)); 764 } 765 } 766 break; 767 } 768 // module.exports = 769 case 61/*=*/: { 770 if (assign) { 771 if (reexports.size) 772 reexports = new Set(); 773 pos++; 774 ch = commentWhitespace(); 775 // { ... } 776 if (ch === 123/*{*/) { 777 tryParseLiteralExports(); 778 return; 779 } 780 781 // require('...') 782 if (ch === 114/*r*/) 783 tryParseRequire(ExportAssign); 784 } 785 } 786 } 787 pos = revertPos; 788} 789 790function tryParseRequire (requireType) { 791 // require('...') 792 const revertPos = pos; 793 if (source.startsWith('equire', pos + 1)) { 794 pos += 7; 795 let ch = commentWhitespace(); 796 if (ch === 40/*(*/) { 797 pos++; 798 ch = commentWhitespace(); 799 const reexportStart = pos + 1; 800 if (ch === 39/*'*/) { 801 singleQuoteString(); 802 const reexportEnd = pos++; 803 ch = commentWhitespace(); 804 if (ch === 41/*)*/) { 805 switch (requireType) { 806 case ExportAssign: 807 reexports.add(source.slice(reexportStart, reexportEnd)); 808 return true; 809 case ExportStar: 810 reexports.add(source.slice(reexportStart, reexportEnd)); 811 return true; 812 default: 813 lastStarExportSpecifier = source.slice(reexportStart, reexportEnd); 814 return true; 815 } 816 } 817 } 818 else if (ch === 34/*"*/) { 819 doubleQuoteString(); 820 const reexportEnd = pos++; 821 ch = commentWhitespace(); 822 if (ch === 41/*)*/) { 823 switch (requireType) { 824 case ExportAssign: 825 reexports.add(source.slice(reexportStart, reexportEnd)); 826 return true; 827 case ExportStar: 828 reexports.add(source.slice(reexportStart, reexportEnd)); 829 return true; 830 default: 831 lastStarExportSpecifier = source.slice(reexportStart, reexportEnd); 832 return true; 833 } 834 } 835 } 836 } 837 pos = revertPos; 838 } 839 return false; 840} 841 842function tryParseLiteralExports () { 843 const revertPos = pos - 1; 844 while (pos++ < end) { 845 let ch = commentWhitespace(); 846 const startPos = pos; 847 if (identifier()) { 848 const endPos = pos; 849 ch = commentWhitespace(); 850 if (ch === 58/*:*/) { 851 pos++; 852 ch = commentWhitespace(); 853 // nothing more complex than identifier expressions for now 854 if (!identifier()) { 855 pos = revertPos; 856 return; 857 } 858 ch = source.charCodeAt(pos); 859 } 860 addExport(source.slice(startPos, endPos)); 861 } 862 else if (ch === 46/*.*/ && source.startsWith('..', pos + 1)) { 863 pos += 3; 864 if (source.charCodeAt(pos) === 114/*r*/ && tryParseRequire(ExportAssign)) { 865 pos++; 866 } 867 else if (!identifier()) { 868 pos = revertPos; 869 return; 870 } 871 ch = commentWhitespace(); 872 } 873 else if (ch === 39/*'*/ || ch === 34/*"*/) { 874 const startPos = ++pos; 875 if (identifier() && source.charCodeAt(pos) === ch) { 876 const endPos = pos++; 877 ch = commentWhitespace(); 878 if (ch === 58/*:*/) { 879 pos++; 880 ch = commentWhitespace(); 881 // nothing more complex than identifier expressions for now 882 if (!identifier()) { 883 pos = revertPos; 884 return; 885 } 886 ch = source.charCodeAt(pos); 887 addExport(source.slice(startPos, endPos)); 888 } 889 } 890 } 891 else { 892 pos = revertPos; 893 return; 894 } 895 896 if (ch === 125/*}*/) 897 return; 898 899 if (ch !== 44/*,*/) { 900 pos = revertPos; 901 return; 902 } 903 } 904} 905 906// --- Extracted from AcornJS --- 907//(https://github.com/acornjs/acorn/blob/master/acorn/src/identifier.js#L23 908// 909// MIT License 910 911// Copyright (C) 2012-2018 by various contributors (see AUTHORS) 912 913// Permission is hereby granted, free of charge, to any person obtaining a copy 914// of this software and associated documentation files (the "Software"), to deal 915// in the Software without restriction, including without limitation the rights 916// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 917// copies of the Software, and to permit persons to whom the Software is 918// furnished to do so, subject to the following conditions: 919 920// The above copyright notice and this permission notice shall be included in 921// all copies or substantial portions of the Software. 922 923// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 924// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 925// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 926// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 927// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 928// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 929// THE SOFTWARE. 930 931// ## Character categories 932 933// Big ugly regular expressions that match characters in the 934// whitespace, identifier, and identifier-start categories. These 935// are only applied when a character is found to actually have a 936// code point above 128. 937// Generated by `bin/generate-identifier-regex.js`. 938let nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0560-\u0588\u05d0-\u05ea\u05ef-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u0860-\u086a\u08a0-\u08b4\u08b6-\u08c7\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u09fc\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d04-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e86-\u0e8a\u0e8c-\u0ea3\u0ea5\u0ea7-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c88\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5\u1cf6\u1cfa\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31bf\u31f0-\u31ff\u3400-\u4dbf\u4e00-\u9ffc\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7bf\ua7c2-\ua7ca\ua7f5-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab69\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc" 939let nonASCIIidentifierChars = "\u200c\u200d\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08d3-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b55-\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d81-\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0ebc\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1abf\u1ac0\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf4\u1cf7-\u1cf9\u1dc0-\u1df9\u1dfb-\u1dff\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua82c\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f" 940 941const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]") 942const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]") 943 944nonASCIIidentifierStartChars = nonASCIIidentifierChars = null 945 946// These are a run-length and offset encoded representation of the 947// >0xffff code points that are a valid part of identifiers. The 948// offset starts at 0x10000, and each pair of numbers represents an 949// offset to the next range, and then a size of the range. They were 950// generated by bin/generate-identifier-regex.js 951 952// eslint-disable-next-line comma-spacing 953const astralIdentifierStartCodes = [0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,14,29,6,37,11,29,3,35,5,7,2,4,43,157,19,35,5,35,5,39,9,51,157,310,10,21,11,7,153,5,3,0,2,43,2,1,4,0,3,22,11,22,10,30,66,18,2,1,11,21,11,25,71,55,7,1,65,0,16,3,2,2,2,28,43,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,14,35,349,41,7,1,79,28,11,0,9,21,107,20,28,22,13,52,76,44,33,24,27,35,30,0,3,0,9,34,4,0,13,47,15,3,22,0,2,0,36,17,2,24,85,6,2,0,2,3,2,14,2,9,8,46,39,7,3,1,3,21,2,6,2,1,2,4,4,0,19,0,13,4,159,52,19,3,21,2,31,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,14,0,72,26,230,43,117,63,32,7,3,0,3,7,2,1,2,23,16,0,2,0,95,7,3,38,17,0,2,0,29,0,11,39,8,0,22,0,12,45,20,0,35,56,264,8,2,36,18,0,50,29,113,6,2,1,2,37,22,0,26,5,2,1,2,31,15,0,328,18,190,0,80,921,103,110,18,195,2749,1070,4050,582,8634,568,8,30,114,29,19,47,17,3,32,20,6,18,689,63,129,74,6,0,67,12,65,1,2,0,29,6135,9,1237,43,8,8952,286,50,2,18,3,9,395,2309,106,6,12,4,8,8,9,5991,84,2,70,2,1,3,0,3,1,3,3,2,11,2,0,2,6,2,64,2,3,3,7,2,6,2,27,2,3,2,4,2,0,4,6,2,339,3,24,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,7,2357,44,11,6,17,0,370,43,1301,196,60,67,8,0,1205,3,2,26,2,1,2,0,3,0,2,9,2,3,2,0,2,0,7,0,5,0,2,0,2,0,2,2,2,1,2,0,3,0,2,0,2,0,2,0,2,0,2,1,2,0,3,3,2,6,2,3,2,3,2,0,2,9,2,16,6,2,2,4,2,16,4421,42717,35,4148,12,221,3,5761,15,7472,3104,541,1507,4938] 954 955// eslint-disable-next-line comma-spacing 956const astralIdentifierCodes = [509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,166,1,574,3,9,9,370,1,154,10,176,2,54,14,32,9,16,3,46,10,54,9,7,2,37,13,2,9,6,1,45,0,13,2,49,13,9,3,2,11,83,11,7,0,161,11,6,9,7,3,56,1,2,6,3,1,3,2,10,0,11,1,3,6,4,4,193,17,10,9,5,0,82,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,84,14,5,9,243,14,166,9,71,5,2,1,3,3,2,0,2,1,13,9,120,6,3,6,4,0,29,9,41,6,2,3,9,0,10,10,47,15,406,7,2,7,17,9,57,21,2,13,123,5,4,0,2,1,2,6,2,0,9,9,49,4,2,1,2,4,9,9,330,3,19306,9,135,4,60,6,26,9,1014,0,2,54,8,3,82,0,12,1,19628,1,5319,4,4,5,9,7,3,6,31,3,149,2,1418,49,513,54,5,49,9,0,15,0,23,4,2,14,1361,6,2,16,3,6,2,1,2,4,262,6,10,9,419,13,1495,6,110,6,6,9,4759,9,787719,239] 957 958// This has a complexity linear to the value of the code. The 959// assumption is that looking up astral identifier characters is 960// rare. 961function isInAstralSet(code, set) { 962 let pos = 0x10000 963 for (let i = 0; i < set.length; i += 2) { 964 pos += set[i] 965 if (pos > code) return false 966 pos += set[i + 1] 967 if (pos >= code) return true 968 } 969} 970 971// Test whether a given character code starts an identifier. 972 973function isIdentifierStart(code, astral) { 974 if (code < 65) return code === 36 975 if (code < 91) return true 976 if (code < 97) return code === 95 977 if (code < 123) return true 978 if (code <= 0xffff) return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code)) 979 if (astral === false) return false 980 return isInAstralSet(code, astralIdentifierStartCodes) 981} 982 983// Test whether a given character is part of an identifier. 984 985function isIdentifierChar(code, astral) { 986 if (code < 48) return code === 36 987 if (code < 58) return true 988 if (code < 65) return false 989 if (code < 91) return true 990 if (code < 97) return code === 95 991 if (code < 123) return true 992 if (code <= 0xffff) return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code)) 993 if (astral === false) return false 994 return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes) 995} 996 997function identifier () { 998 let ch = source.codePointAt(pos); 999 if (!isIdentifierStart(ch, true) || ch === '\\') 1000 return false; 1001 pos += codePointLen(ch); 1002 while (ch = source.codePointAt(pos)) { 1003 if (isIdentifierChar(ch, true)) { 1004 pos += codePointLen(ch); 1005 } 1006 else if (ch === '\\') { 1007 // no identifier escapes support for now 1008 return false; 1009 } 1010 else { 1011 break; 1012 } 1013 } 1014 return true; 1015} 1016 1017function codePointLen (ch) { 1018 if (ch < 0x10000) return 1; 1019 return 2; 1020} 1021 1022function codePointAtLast (bPos) { 1023 // Gives the UTF char for backtracking surrogates 1024 const ch = source.charCodeAt(bPos); 1025 if ((ch & 0xFC00) === 0xDC00) 1026 return (((source.charCodeAt(bPos - 1) & 0x3FF) << 10) | (ch & 0x3FF)) + 0x10000; 1027 return ch; 1028} 1029 1030function throwIfImportStatement () { 1031 const startPos = pos; 1032 pos += 6; 1033 const ch = commentWhitespace(); 1034 switch (ch) { 1035 // dynamic import 1036 case 40/*(*/: 1037 openTokenPosStack[openTokenDepth++] = startPos; 1038 return; 1039 // import.meta 1040 case 46/*.*/: 1041 throw new Error('Unexpected import.meta in CJS module.'); 1042 return; 1043 1044 default: 1045 // no space after "import" -> not an import keyword 1046 if (pos === startPos + 6) 1047 break; 1048 case 34/*"*/: 1049 case 39/*'*/: 1050 case 123/*{*/: 1051 case 42/***/: 1052 // import statement only permitted at base-level 1053 if (openTokenDepth !== 0) { 1054 pos--; 1055 return; 1056 } 1057 // import statements are a syntax error in CommonJS 1058 throw new Error('Unexpected import statement in CJS module.'); 1059 } 1060} 1061 1062function throwIfExportStatement () { 1063 pos += 6; 1064 const curPos = pos; 1065 const ch = commentWhitespace(); 1066 if (pos === curPos && !isPunctuator(ch)) 1067 return; 1068 throw new Error('Unexpected export statement in CJS module.'); 1069} 1070 1071function commentWhitespace () { 1072 let ch; 1073 do { 1074 ch = source.charCodeAt(pos); 1075 if (ch === 47/*/*/) { 1076 const next_ch = source.charCodeAt(pos + 1); 1077 if (next_ch === 47/*/*/) 1078 lineComment(); 1079 else if (next_ch === 42/***/) 1080 blockComment(); 1081 else 1082 return ch; 1083 } 1084 else if (!isBrOrWs(ch)) { 1085 return ch; 1086 } 1087 } while (pos++ < end); 1088 return ch; 1089} 1090 1091function templateString () { 1092 while (pos++ < end) { 1093 const ch = source.charCodeAt(pos); 1094 if (ch === 36/*$*/ && source.charCodeAt(pos + 1) === 123/*{*/) { 1095 pos++; 1096 templateStack[templateStackDepth++] = templateDepth; 1097 templateDepth = ++openTokenDepth; 1098 return; 1099 } 1100 if (ch === 96/*`*/) 1101 return; 1102 if (ch === 92/*\*/) 1103 pos++; 1104 } 1105 syntaxError(); 1106} 1107 1108function blockComment () { 1109 pos++; 1110 while (pos++ < end) { 1111 const ch = source.charCodeAt(pos); 1112 if (ch === 42/***/ && source.charCodeAt(pos + 1) === 47/*/*/) { 1113 pos++; 1114 return; 1115 } 1116 } 1117} 1118 1119function lineComment () { 1120 while (pos++ < end) { 1121 const ch = source.charCodeAt(pos); 1122 if (ch === 10/*\n*/ || ch === 13/*\r*/) 1123 return; 1124 } 1125} 1126 1127function singleQuoteString () { 1128 while (pos++ < end) { 1129 let ch = source.charCodeAt(pos); 1130 if (ch === 39/*'*/) 1131 return; 1132 if (ch === 92/*\*/) { 1133 ch = source.charCodeAt(++pos); 1134 if (ch === 13/*\r*/ && source.charCodeAt(pos + 1) === 10/*\n*/) 1135 pos++; 1136 } 1137 else if (isBr(ch)) 1138 break; 1139 } 1140 throw new Error('Unterminated string.'); 1141} 1142 1143function doubleQuoteString () { 1144 while (pos++ < end) { 1145 let ch = source.charCodeAt(pos); 1146 if (ch === 34/*"*/) 1147 return; 1148 if (ch === 92/*\*/) { 1149 ch = source.charCodeAt(++pos); 1150 if (ch === 13/*\r*/ && source.charCodeAt(pos + 1) === 10/*\n*/) 1151 pos++; 1152 } 1153 else if (isBr(ch)) 1154 break; 1155 } 1156 throw new Error('Unterminated string.'); 1157} 1158 1159function regexCharacterClass () { 1160 while (pos++ < end) { 1161 let ch = source.charCodeAt(pos); 1162 if (ch === 93/*]*/) 1163 return ch; 1164 if (ch === 92/*\*/) 1165 pos++; 1166 else if (ch === 10/*\n*/ || ch === 13/*\r*/) 1167 break; 1168 } 1169 throw new Error('Syntax error reading regular expression class.'); 1170} 1171 1172function regularExpression () { 1173 while (pos++ < end) { 1174 let ch = source.charCodeAt(pos); 1175 if (ch === 47/*/*/) 1176 return; 1177 if (ch === 91/*[*/) 1178 ch = regexCharacterClass(); 1179 else if (ch === 92/*\*/) 1180 pos++; 1181 else if (ch === 10/*\n*/ || ch === 13/*\r*/) 1182 break; 1183 } 1184 throw new Error('Syntax error reading regular expression.'); 1185} 1186 1187// Note: non-asii BR and whitespace checks omitted for perf / footprint 1188// if there is a significant user need this can be reconsidered 1189function isBr (c) { 1190 return c === 13/*\r*/ || c === 10/*\n*/; 1191} 1192 1193function isBrOrWs (c) { 1194 return c > 8 && c < 14 || c === 32 || c === 160; 1195} 1196 1197function isBrOrWsOrPunctuatorNotDot (c) { 1198 return c > 8 && c < 14 || c === 32 || c === 160 || isPunctuator(c) && c !== 46/*.*/; 1199} 1200 1201function keywordStart (pos) { 1202 return pos === 0 || isBrOrWsOrPunctuatorNotDot(source.charCodeAt(pos - 1)); 1203} 1204 1205function readPrecedingKeyword (pos, match) { 1206 if (pos < match.length - 1) 1207 return false; 1208 return source.startsWith(match, pos - match.length + 1) && (pos === 0 || isBrOrWsOrPunctuatorNotDot(source.charCodeAt(pos - match.length))); 1209} 1210 1211function readPrecedingKeyword1 (pos, ch) { 1212 return source.charCodeAt(pos) === ch && (pos === 0 || isBrOrWsOrPunctuatorNotDot(source.charCodeAt(pos - 1))); 1213} 1214 1215// Detects one of case, debugger, delete, do, else, in, instanceof, new, 1216// return, throw, typeof, void, yield, await 1217function isExpressionKeyword (pos) { 1218 switch (source.charCodeAt(pos)) { 1219 case 100/*d*/: 1220 switch (source.charCodeAt(pos - 1)) { 1221 case 105/*i*/: 1222 // void 1223 return readPrecedingKeyword(pos - 2, 'vo'); 1224 case 108/*l*/: 1225 // yield 1226 return readPrecedingKeyword(pos - 2, 'yie'); 1227 default: 1228 return false; 1229 } 1230 case 101/*e*/: 1231 switch (source.charCodeAt(pos - 1)) { 1232 case 115/*s*/: 1233 switch (source.charCodeAt(pos - 2)) { 1234 case 108/*l*/: 1235 // else 1236 return readPrecedingKeyword1(pos - 3, 101/*e*/); 1237 case 97/*a*/: 1238 // case 1239 return readPrecedingKeyword1(pos - 3, 99/*c*/); 1240 default: 1241 return false; 1242 } 1243 case 116/*t*/: 1244 // delete 1245 return readPrecedingKeyword(pos - 2, 'dele'); 1246 default: 1247 return false; 1248 } 1249 case 102/*f*/: 1250 if (source.charCodeAt(pos - 1) !== 111/*o*/ || source.charCodeAt(pos - 2) !== 101/*e*/) 1251 return false; 1252 switch (source.charCodeAt(pos - 3)) { 1253 case 99/*c*/: 1254 // instanceof 1255 return readPrecedingKeyword(pos - 4, 'instan'); 1256 case 112/*p*/: 1257 // typeof 1258 return readPrecedingKeyword(pos - 4, 'ty'); 1259 default: 1260 return false; 1261 } 1262 case 110/*n*/: 1263 // in, return 1264 return readPrecedingKeyword1(pos - 1, 105/*i*/) || readPrecedingKeyword(pos - 1, 'retur'); 1265 case 111/*o*/: 1266 // do 1267 return readPrecedingKeyword1(pos - 1, 100/*d*/); 1268 case 114/*r*/: 1269 // debugger 1270 return readPrecedingKeyword(pos - 1, 'debugge'); 1271 case 116/*t*/: 1272 // await 1273 return readPrecedingKeyword(pos - 1, 'awai'); 1274 case 119/*w*/: 1275 switch (source.charCodeAt(pos - 1)) { 1276 case 101/*e*/: 1277 // new 1278 return readPrecedingKeyword1(pos - 2, 110/*n*/); 1279 case 111/*o*/: 1280 // throw 1281 return readPrecedingKeyword(pos - 2, 'thr'); 1282 default: 1283 return false; 1284 } 1285 } 1286 return false; 1287} 1288 1289function isParenKeyword (curPos) { 1290 return source.charCodeAt(curPos) === 101/*e*/ && source.startsWith('whil', curPos - 4) || 1291 source.charCodeAt(curPos) === 114/*r*/ && source.startsWith('fo', curPos - 2) || 1292 source.charCodeAt(curPos - 1) === 105/*i*/ && source.charCodeAt(curPos) === 102/*f*/; 1293} 1294 1295function isPunctuator (ch) { 1296 // 23 possible punctuator endings: !%&()*+,-./:;<=>?[]^{}|~ 1297 return ch === 33/*!*/ || ch === 37/*%*/ || ch === 38/*&*/ || 1298 ch > 39 && ch < 48 || ch > 57 && ch < 64 || 1299 ch === 91/*[*/ || ch === 93/*]*/ || ch === 94/*^*/ || 1300 ch > 122 && ch < 127; 1301} 1302 1303function isExpressionPunctuator (ch) { 1304 // 20 possible expression endings: !%&(*+,-.:;<=>?[^{|~ 1305 return ch === 33/*!*/ || ch === 37/*%*/ || ch === 38/*&*/ || 1306 ch > 39 && ch < 47 && ch !== 41 || ch > 57 && ch < 64 || 1307 ch === 91/*[*/ || ch === 94/*^*/ || ch > 122 && ch < 127 && ch !== 125/*}*/; 1308} 1309 1310function isExpressionTerminator (curPos) { 1311 // detects: 1312 // => ; ) finally catch else 1313 // as all of these followed by a { will indicate a statement brace 1314 switch (source.charCodeAt(curPos)) { 1315 case 62/*>*/: 1316 return source.charCodeAt(curPos - 1) === 61/*=*/; 1317 case 59/*;*/: 1318 case 41/*)*/: 1319 return true; 1320 case 104/*h*/: 1321 return source.startsWith('catc', curPos - 4); 1322 case 121/*y*/: 1323 return source.startsWith('finall', curPos - 6); 1324 case 101/*e*/: 1325 return source.startsWith('els', curPos - 3); 1326 } 1327 return false; 1328} 1329 1330const initPromise = Promise.resolve(); 1331 1332module.exports.init = () => initPromise; 1333module.exports.parse = parseCJS; 1334