| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ea23939 commit d7f0e3e
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,4 @@ | |||
| 1 | + 0.4.3 | ||
| 2 | + - Support for Babel 7.12 reexports (https://github.com/guybedford/cjs-module-lexer/pull/16) | ||
| 3 | + - Support module.exports = { ...require('x') } reexports (https://github.com/guybedford/cjs-module-lexer/pull/18) | ||
| 4 | + - "if" keyword space parsing in exports matching (https://github.com/guybedford/cjs-module-lexer/pull/17) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,7 +10,6 @@ let openTokenDepth, | |||
| 10 | 10 | nextBraceIsClass, | |
| 11 | 11 | starExportMap, | |
| 12 | 12 | lastStarExportSpecifier, | |
| 13 | - lastExportsAssignSpecifier, | ||
| 14 | 13 | _exports, | |
| 15 | 14 | reexports; | |
| 16 | 15 | ||
@@ -26,7 +25,6 @@ function resetState () { | |||
| 26 | 25 | nextBraceIsClass = false; | |
| 27 | 26 | starExportMap = Object.create(null); | |
| 28 | 27 | lastStarExportSpecifier = null; | |
| 29 | - lastExportsAssignSpecifier = null; | ||
| 30 | 28 | ||
| 31 | 29 | _exports = new Set(); | |
| 32 | 30 | reexports = new Set(); | |
@@ -49,8 +47,6 @@ module.exports = function parseCJS (source, name = '@') { | |||
| 49 | 47 | e.loc = pos; | |
| 50 | 48 | throw e; | |
| 51 | 49 | } | |
| 52 | - if (lastExportsAssignSpecifier) | ||
| 53 | - reexports.add(lastExportsAssignSpecifier); | ||
| 54 | 50 | const result = { exports: [..._exports], reexports: [...reexports] }; | |
| 55 | 51 | resetState(); | |
| 56 | 52 | return result; | |
@@ -330,8 +326,8 @@ function tryParseObjectDefineOrKeys (keys) { | |||
| 330 | 326 | if (ch !== 123/*{*/) break; | |
| 331 | 327 | pos++; | |
| 332 | 328 | ch = commentWhitespace(); | |
| 333 | - if (ch !== 105/*i*/ || !source.startsWith('f ', pos + 1)) break; | ||
| 334 | - pos += 3; | ||
| 329 | + if (ch !== 105/*i*/ || source.charCodeAt(pos + 1) !== 102/*f*/) break; | ||
| 330 | + pos += 2; | ||
| 335 | 331 | ch = commentWhitespace(); | |
| 336 | 332 | if (ch !== 40/*(*/) break; | |
| 337 | 333 | pos++; | |
@@ -398,6 +394,61 @@ function tryParseObjectDefineOrKeys (keys) { | |||
| 398 | 394 | } | |
| 399 | 395 | else break; | |
| 400 | 396 | ||
| 397 | + // `if (` IDENTIFIER$2 `in` EXPORTS_IDENTIFIER `&&` EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] ===` IDENTIFIER$1 `[` IDENTIFIER$2 `]) return` `;`? | ||
| 398 | + if (ch === 105/*i*/ && source.charCodeAt(pos + 1) === 102/*f*/) { | ||
| 399 | + pos += 2; | ||
| 400 | + ch = commentWhitespace(); | ||
| 401 | + if (ch !== 40/*(*/) break; | ||
| 402 | + pos++; | ||
| 403 | + ch = commentWhitespace(); | ||
| 404 | + if (!source.startsWith(it_id, pos)) break; | ||
| 405 | + pos += it_id.length; | ||
| 406 | + ch = commentWhitespace(); | ||
| 407 | + if (ch !== 105/*i*/ || !source.startsWith('n ', pos + 1)) break; | ||
| 408 | + pos += 3; | ||
| 409 | + ch = commentWhitespace(); | ||
| 410 | + if (!readExportsOrModuleDotExports(ch)) break; | ||
| 411 | + ch = commentWhitespace(); | ||
| 412 | + if (ch !== 38/*&*/ || source.charCodeAt(pos + 1) !== 38/*&*/) break; | ||
| 413 | + pos += 2; | ||
| 414 | + ch = commentWhitespace(); | ||
| 415 | + if (!readExportsOrModuleDotExports(ch)) break; | ||
| 416 | + ch = commentWhitespace(); | ||
| 417 | + if (ch !== 91/*[*/) break; | ||
| 418 | + pos++; | ||
| 419 | + ch = commentWhitespace(); | ||
| 420 | + if (!source.startsWith(it_id, pos)) break; | ||
| 421 | + pos += it_id.length; | ||
| 422 | + ch = commentWhitespace(); | ||
| 423 | + if (ch !== 93/*]*/) break; | ||
| 424 | + pos++; | ||
| 425 | + ch = commentWhitespace(); | ||
| 426 | + if (ch !== 61/*=*/ || !source.startsWith('==', pos + 1)) break; | ||
| 427 | + pos += 3; | ||
| 428 | + ch = commentWhitespace(); | ||
| 429 | + if (!source.startsWith(id, pos)) break; | ||
| 430 | + pos += id.length; | ||
| 431 | + ch = commentWhitespace(); | ||
| 432 | + if (ch !== 91/*[*/) break; | ||
| 433 | + pos++; | ||
| 434 | + ch = commentWhitespace(); | ||
| 435 | + if (!source.startsWith(it_id, pos)) break; | ||
| 436 | + pos += it_id.length; | ||
| 437 | + ch = commentWhitespace(); | ||
| 438 | + if (ch !== 93/*]*/) break; | ||
| 439 | + pos++; | ||
| 440 | + ch = commentWhitespace(); | ||
| 441 | + if (ch !== 41/*)*/) break; | ||
| 442 | + pos++; | ||
| 443 | + ch = commentWhitespace(); | ||
| 444 | + if (ch !== 114/*r*/ || !source.startsWith('eturn', pos + 1)) break; | ||
| 445 | + pos += 6; | ||
| 446 | + ch = commentWhitespace(); | ||
| 447 | + if (ch === 59/*;*/) | ||
| 448 | + pos++; | ||
| 449 | + ch = commentWhitespace(); | ||
| 450 | + } | ||
| 451 | + | ||
| 401 | 452 | // EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] =` IDENTIFIER$1 `[` IDENTIFIER$2 `]` | |
| 402 | 453 | if (readExportsOrModuleDotExports(ch)) { | |
| 403 | 454 | ch = commentWhitespace(); | |
@@ -622,6 +673,8 @@ function tryParseExportsDotAssign (assign) { | |||
| 622 | 673 | // module.exports = | |
| 623 | 674 | case 61/*=*/: { | |
| 624 | 675 | if (assign) { | |
| 676 | + if (reexports.size) | ||
| 677 | + reexports = new Set(); | ||
| 625 | 678 | pos++; | |
| 626 | 679 | ch = commentWhitespace(); | |
| 627 | 680 | // { ... } | |
@@ -641,9 +694,9 @@ function tryParseExportsDotAssign (assign) { | |||
| 641 | 694 | ||
| 642 | 695 | function tryParseRequire (requireType) { | |
| 643 | 696 | // require('...') | |
| 697 | + const revertPos = pos; | ||
| 644 | 698 | if (source.startsWith('equire', pos + 1)) { | |
| 645 | 699 | pos += 7; | |
| 646 | - const revertPos = pos - 1; | ||
| 647 | 700 | let ch = commentWhitespace(); | |
| 648 | 701 | if (ch === 40/*(*/) { | |
| 649 | 702 | pos++; | |
@@ -656,7 +709,7 @@ function tryParseRequire (requireType) { | |||
| 656 | 709 | if (ch === 41/*)*/) { | |
| 657 | 710 | switch (requireType) { | |
| 658 | 711 | case ExportAssign: | |
| 659 | - lastExportsAssignSpecifier = source.slice(reexportStart, reexportEnd); | ||
| 712 | + reexports.add(source.slice(reexportStart, reexportEnd)); | ||
| 660 | 713 | return true; | |
| 661 | 714 | case ExportStar: | |
| 662 | 715 | reexports.add(source.slice(reexportStart, reexportEnd)); | |
@@ -674,7 +727,7 @@ function tryParseRequire (requireType) { | |||
| 674 | 727 | if (ch === 41/*)*/) { | |
| 675 | 728 | switch (requireType) { | |
| 676 | 729 | case ExportAssign: | |
| 677 | - lastExportsAssignSpecifier = source.slice(reexportStart, reexportEnd); | ||
| 730 | + reexports.add(source.slice(reexportStart, reexportEnd)); | ||
| 678 | 731 | return true; | |
| 679 | 732 | case ExportStar: | |
| 680 | 733 | reexports.add(source.slice(reexportStart, reexportEnd)); | |
@@ -711,6 +764,17 @@ function tryParseLiteralExports () { | |||
| 711 | 764 | } | |
| 712 | 765 | addExport(source.slice(startPos, endPos)); | |
| 713 | 766 | } | |
| 767 | + else if (ch === 46/*.*/ && source.startsWith('..', pos + 1)) { | ||
| 768 | + pos += 3; | ||
| 769 | + if (source.charCodeAt(pos) === 114/*r*/ && tryParseRequire(ExportAssign)) { | ||
| 770 | + pos++; | ||
| 771 | + } | ||
| 772 | + else if (!identifier()) { | ||
| 773 | + pos = revertPos; | ||
| 774 | + return; | ||
| 775 | + } | ||
| 776 | + ch = commentWhitespace(); | ||
| 777 | + } | ||
| 714 | 778 | else if (ch === 39/*'*/ || ch === 34/*"*/) { | |
| 715 | 779 | const startPos = ++pos; | |
| 716 | 780 | if (identifier() && source.charCodeAt(pos) === ch) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | 1 | { | |
| 2 | 2 | "name": "cjs-module-lexer", | |
| 3 | - "version": "0.4.2", | ||
| 3 | + "version": "0.4.3", | ||
| 4 | 4 | "description": "Lexes CommonJS modules, returning their named exports metadata", | |
| 5 | 5 | "main": "lexer.js", | |
| 6 | 6 | "exports": { | |
@@ -14,8 +14,8 @@ | |||
| 14 | 14 | "bench": "node --expose-gc bench/index.mjs", | |
| 15 | 15 | "build": "node build.js && babel dist/lexer.mjs | terser -o dist/lexer.js", | |
| 16 | 16 | "build-wasm": "make lib/lexer.wasm && node build.js", | |
| 17 | - "prepublishOnly": "make optimize && npm run build", | ||
| 18 | - "footprint": "make optimize && npm run build && cat dist/lexer.js | gzip -9f | wc -c" | ||
| 17 | + "prepublishOnly": "make && npm run build", | ||
| 18 | + "footprint": "npm run build && cat dist/lexer.js | gzip -9f | wc -c" | ||
| 19 | 19 | }, | |
| 20 | 20 | "author": "Guy Bedford", | |
| 21 | 21 | "license": "MIT", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1296,7 +1296,7 @@ success! | |||
| 1296 | 1296 | [`Uint8Array`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array | |
| 1297 | 1297 | [dynamic instantiate hook]: #esm_code_dynamicinstantiate_code_hook | |
| 1298 | 1298 | [`util.TextDecoder`]: util.md#util_class_util_textdecoder | |
| 1299 | - [cjs-module-lexer]: https://github.com/guybedford/cjs-module-lexer/tree/0.4.2 | ||
| 1299 | + [cjs-module-lexer]: https://github.com/guybedford/cjs-module-lexer/tree/0.4.3 | ||
| 1300 | 1300 | [special scheme]: https://url.spec.whatwg.org/#special-scheme | |
| 1301 | 1301 | [the official standard format]: https://tc39.github.io/ecma262/#sec-modules | |
| 1302 | 1302 | [transpiler loader example]: #esm_transpiler_loader | |
| Back | FazBrowse Home | New Git URL |
0 commit comments