Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
deps: update to cjs-module-lexer@1.1.0
PR-URL: #37712
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
  • Loading branch information
guybedford authored and richardlau committed Mar 17, 2021
commit 18726259908377cc3fbc9a046ca69aef3fa37497
5 changes: 5 additions & 0 deletions deps/cjs-module-lexer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
1.1.0
- Support for Babel reexport conflict filter (https://github.com/guybedford/cjs-module-lexer/issues/36, @nicolo-ribaudo)
- Support trailing commas in getter patterns (https://github.com/guybedford/cjs-module-lexer/issues/31)
- Support for RollupJS reexports property checks (https://github.com/guybedford/cjs-module-lexer/issues/38)

1.0.0
- Unsafe getter tracking (https://github.com/guybedford/cjs-module-lexer/pull/29)

Expand Down
31 changes: 22 additions & 9 deletions deps/cjs-module-lexer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ EXPORTS_DOT_ASSIGN: EXPORTS_IDENTIFIER `.` IDENTIFIER `=`

EXPORTS_LITERAL_COMPUTED_ASSIGN: EXPORTS_IDENTIFIER `[` IDENTIFIER_STRING `]` `=`

EXPORTS_LITERAL_PROP: (IDENTIFIER `:` IDENTIFIER)?) | (IDENTIFIER_STRING `:` IDENTIFIER)
EXPORTS_LITERAL_PROP: (IDENTIFIER (`:` IDENTIFIER)?) | (IDENTIFIER_STRING `:` IDENTIFIER)

EXPORTS_SPREAD: `...` (IDENTIFIER | REQUIRE)

Expand All @@ -92,7 +92,7 @@ EXPORTS_DEFINE_VALUE: EXPORTS_DEFINE `, {`
(`enumerable: true,`)?
(
`value:` |
`get` (`: function` IDENTIFIER? )? `()` {` return IDENTIFIER (`.` IDENTIFIER | `[` IDENTIFIER_STRING `]`)? `;`? `}`
`get` (`: function` IDENTIFIER? )? `()` {` return IDENTIFIER (`.` IDENTIFIER | `[` IDENTIFIER_STRING `]`)? `;`? `}` `,`?
)
`})`

Expand All @@ -108,15 +108,18 @@ EXPORT_STAR: (`__export` | `__exportStar`) `(` REQUIRE

EXPORT_STAR_LIB: `Object.keys(` IDENTIFIER$1 `).forEach(function (` IDENTIFIER$2 `) {`
(
`if (` IDENTIFIER$2 `===` ( `'default'` | `"default"` ) `||` IDENTIFIER$2 `===` ( '__esModule' | `"__esModule"` ) `) return` `;`? |
`if (` IDENTIFIER$2 `!==` ( `'default'` | `"default"` ) `)`
(
`if (` IDENTIFIER$2 `===` ( `'default'` | `"default"` ) `||` IDENTIFIER$2 `===` ( '__esModule' | `"__esModule"` ) `) return` `;`?
(
(`if (Object` `.prototype`? `.hasOwnProperty.call(` IDENTIFIER `, ` IDENTIFIER$2 `)) return` `;`?)?
(`if (` IDENTIFIER$2 `in` EXPORTS_IDENTIFIER `&&` EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] ===` IDENTIFIER$1 `[` IDENTIFIER$2 `]) return` `;`)?
)?
) |
`if (` IDENTIFIER$2 `!==` ( `'default'` | `"default"` ) (`&& !` (`Object` `.prototype`? `.hasOwnProperty.call(` IDENTIFIER$1 `, ` IDENTIFIER$2 `)` | IDENTIFIER$1 `.hasOwnProperty(` IDENTIFIER$2 `)`))? `)`
)
(
`if (` IDENTIFIER$2 `in` EXPORTS_IDENTIFIER `&&` EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] ===` IDENTIFIER$1 `[` IDENTIFIER$2 `]) return` `;`?
)?
(
EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] =` IDENTIFIER$1 `[` IDENTIFIER$2 `]` `;`? |
`Object.defineProperty(` EXPORTS_IDENTIFIER `, ` IDENTIFIER$2 `, { enumerable: true, get: function () { return ` IDENTIFIER$1 `[` IDENTIFIER$2 `]` `;`? } })` `;`?
`Object.defineProperty(` EXPORTS_IDENTIFIER `, ` IDENTIFIER$2 `, { enumerable: true, get: function () { return ` IDENTIFIER$1 `[` IDENTIFIER$2 `]` `;`? `}` `,`? `})` `;`?
)
`})`
```
Expand Down Expand Up @@ -194,13 +197,23 @@ Object.defineProperty(exports, 'd', { value: 'd' });
Object.defineProperty(exports, '__esModule', { value: true });
```

Value properties are also detected specifically:

```js
Object.defineProperty(exports, 'a', {
value: 'no problem'
});
```

To avoid matching getters that have side effects, any getter for an export name that does not support the forms above will
opt-out of the getter matching:

```js
// DETECTS: NO EXPORTS
Object.defineProperty(exports, 'a', {
value: 'no problem'
get () {
return 'nope';
}
});

if (false) {
Expand Down
2 changes: 1 addition & 1 deletion deps/cjs-module-lexer/dist/lexer.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions deps/cjs-module-lexer/dist/lexer.mjs

Large diffs are not rendered by default.

222 changes: 165 additions & 57 deletions deps/cjs-module-lexer/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,48 @@ function tryBacktrackAddStarExportBinding (bPos) {
}
}

// `Object.` `prototype.`? hasOwnProperty.call(` IDENTIFIER `, ` IDENTIFIER$2 `)`
function tryParseObjectHasOwnProperty (it_id) {
ch = commentWhitespace();
if (ch !== 79/*O*/ || !source.startsWith('bject', pos + 1)) return false;
pos += 6;
ch = commentWhitespace();
if (ch !== 46/*.*/) return false;
pos++;
ch = commentWhitespace();
if (ch === 112/*p*/) {
if (!source.startsWith('rototype', pos + 1)) return false;
pos += 9;
ch = commentWhitespace();
if (ch !== 46/*.*/) return false;
pos++;
ch = commentWhitespace();
}
if (ch !== 104/*h*/ || !source.startsWith('asOwnProperty', pos + 1)) return false;
pos += 14;
ch = commentWhitespace();
if (ch !== 46/*.*/) return false;
pos++;
ch = commentWhitespace();
if (ch !== 99/*c*/ || !source.startsWith('all', pos + 1)) return false;
pos += 4;
ch = commentWhitespace();
if (ch !== 40/*(*/) return false;
pos++;
ch = commentWhitespace();
if (!identifier()) return false;
ch = commentWhitespace();
if (ch !== 44/*,*/) return false;
pos++;
ch = commentWhitespace();
if (!source.startsWith(it_id, pos)) return false;
pos += it_id.length;
ch = commentWhitespace();
if (ch !== 41/*)*/) return false;
pos++;
return true;
}

function tryParseObjectDefineOrKeys (keys) {
pos += 6;
let revertPos = pos - 1;
Expand Down Expand Up @@ -366,6 +408,10 @@ function tryParseObjectDefineOrKeys (keys) {
if (ch !== 125/*}*/) break;
pos++;
ch = commentWhitespace();
if (ch === 44/*,*/) {
pos++;
ch = commentWhitespace();
}
if (ch !== 125/*}*/) break;
pos++;
ch = commentWhitespace();
Expand Down Expand Up @@ -469,8 +515,94 @@ function tryParseObjectDefineOrKeys (keys) {
if (ch === 59/*;*/)
pos++;
ch = commentWhitespace();

// `if (`
if (ch === 105/*i*/ && source.charCodeAt(pos + 1) === 102/*f*/) {
let inIf = true;
pos += 2;
ch = commentWhitespace();
if (ch !== 40/*(*/) break;
pos++;
const ifInnerPos = pos;
// `Object.prototype.hasOwnProperty.call(` IDENTIFIER `, ` IDENTIFIER$2 `)) return` `;`?
if (tryParseObjectHasOwnProperty(it_id)) {
ch = commentWhitespace();
if (ch !== 41/*)*/) break;
pos++;
ch = commentWhitespace();
if (ch !== 114/*r*/ || !source.startsWith('eturn', pos + 1)) break;
pos += 6;
ch = commentWhitespace();
if (ch === 59/*;*/)
pos++;
ch = commentWhitespace();
// match next if
if (ch === 105/*i*/ && source.charCodeAt(pos + 1) === 102/*f*/) {
pos += 2;
ch = commentWhitespace();
if (ch !== 40/*(*/) break;
pos++;
}
else {
inIf = false;
}
}
else {
pos = ifInnerPos;
}

// IDENTIFIER$2 `in` EXPORTS_IDENTIFIER `&&` EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] ===` IDENTIFIER$1 `[` IDENTIFIER$2 `]) return` `;`?
if (inIf) {
if (!source.startsWith(it_id, pos)) break;
pos += it_id.length;
ch = commentWhitespace();
if (ch !== 105/*i*/ || !source.startsWith('n ', pos + 1)) break;
pos += 3;
ch = commentWhitespace();
if (!readExportsOrModuleDotExports(ch)) break;
ch = commentWhitespace();
if (ch !== 38/*&*/ || source.charCodeAt(pos + 1) !== 38/*&*/) break;
pos += 2;
ch = commentWhitespace();
if (!readExportsOrModuleDotExports(ch)) break;
ch = commentWhitespace();
if (ch !== 91/*[*/) break;
pos++;
ch = commentWhitespace();
if (!source.startsWith(it_id, pos)) break;
pos += it_id.length;
ch = commentWhitespace();
if (ch !== 93/*]*/) break;
pos++;
ch = commentWhitespace();
if (ch !== 61/*=*/ || !source.startsWith('==', pos + 1)) break;
pos += 3;
ch = commentWhitespace();
if (!source.startsWith(id, pos)) break;
pos += id.length;
ch = commentWhitespace();
if (ch !== 91/*[*/) break;
pos++;
ch = commentWhitespace();
if (!source.startsWith(it_id, pos)) break;
pos += it_id.length;
ch = commentWhitespace();
if (ch !== 93/*]*/) break;
pos++;
ch = commentWhitespace();
if (ch !== 41/*)*/) break;
pos++;
ch = commentWhitespace();
if (ch !== 114/*r*/ || !source.startsWith('eturn', pos + 1)) break;
pos += 6;
ch = commentWhitespace();
if (ch === 59/*;*/)
pos++;
ch = commentWhitespace();
}
}
}
// `if (` IDENTIFIER$2 `!==` ( `'default'` | `"default"` ) `)`
// `if (` IDENTIFIER$2 `!==` ( `'default'` | `"default"` ) (`&& !` IDENTIFIER `.hasOwnProperty(` IDENTIFIER$2 `)` )? `)`
else if (ch === 33/*!*/) {
if (!source.startsWith('==', pos + 1)) break;
pos += 3;
Expand All @@ -483,67 +615,40 @@ function tryParseObjectDefineOrKeys (keys) {
if (ch !== quot) break;
pos += 1;
ch = commentWhitespace();
if (ch === 38/*&*/) {
if (source.charCodeAt(pos + 1) !== 38/*&*/) break;
pos += 2;
ch = commentWhitespace();
if (ch !== 33/*!*/) break;
pos += 1;
ch = commentWhitespace();
if (source.startsWith(id, pos)) {
pos += id.length;
ch = commentWhitespace();
if (ch !== 46/*.*/) break;
pos++;
ch = commentWhitespace();
if (ch !== 104/*h*/ || !source.startsWith('asOwnProperty', pos + 1)) break;
pos += 14;
ch = commentWhitespace();
if (ch !== 40/*(*/) break;
pos += 1;
ch = commentWhitespace();
if (!source.startsWith(it_id, pos)) break;
pos += it_id.length;
ch = commentWhitespace();
if (ch !== 41/*)*/) break;
pos += 1;
}
else if (!tryParseObjectHasOwnProperty(it_id)) break;
ch = commentWhitespace();
}
if (ch !== 41/*)*/) break;
pos += 1;
ch = commentWhitespace();
}
else break;

// `if (` IDENTIFIER$2 `in` EXPORTS_IDENTIFIER `&&` EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] ===` IDENTIFIER$1 `[` IDENTIFIER$2 `]) return` `;`?
if (ch === 105/*i*/ && source.charCodeAt(pos + 1) === 102/*f*/) {
pos += 2;
ch = commentWhitespace();
if (ch !== 40/*(*/) break;
pos++;
ch = commentWhitespace();
if (!source.startsWith(it_id, pos)) break;
pos += it_id.length;
ch = commentWhitespace();
if (ch !== 105/*i*/ || !source.startsWith('n ', pos + 1)) break;
pos += 3;
ch = commentWhitespace();
if (!readExportsOrModuleDotExports(ch)) break;
ch = commentWhitespace();
if (ch !== 38/*&*/ || source.charCodeAt(pos + 1) !== 38/*&*/) break;
pos += 2;
ch = commentWhitespace();
if (!readExportsOrModuleDotExports(ch)) break;
ch = commentWhitespace();
if (ch !== 91/*[*/) break;
pos++;
ch = commentWhitespace();
if (!source.startsWith(it_id, pos)) break;
pos += it_id.length;
ch = commentWhitespace();
if (ch !== 93/*]*/) break;
pos++;
ch = commentWhitespace();
if (ch !== 61/*=*/ || !source.startsWith('==', pos + 1)) break;
pos += 3;
ch = commentWhitespace();
if (!source.startsWith(id, pos)) break;
pos += id.length;
ch = commentWhitespace();
if (ch !== 91/*[*/) break;
pos++;
ch = commentWhitespace();
if (!source.startsWith(it_id, pos)) break;
pos += it_id.length;
ch = commentWhitespace();
if (ch !== 93/*]*/) break;
pos++;
ch = commentWhitespace();
if (ch !== 41/*)*/) break;
pos++;
ch = commentWhitespace();
if (ch !== 114/*r*/ || !source.startsWith('eturn', pos + 1)) break;
pos += 6;
ch = commentWhitespace();
if (ch === 59/*;*/)
pos++;
ch = commentWhitespace();
}

// EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] =` IDENTIFIER$1 `[` IDENTIFIER$2 `]`
if (readExportsOrModuleDotExports(ch)) {
ch = commentWhitespace();
Expand Down Expand Up @@ -656,6 +761,10 @@ function tryParseObjectDefineOrKeys (keys) {
if (ch !== 125/*}*/) break;
pos++;
ch = commentWhitespace();
if (ch === 44/*,*/) {
pos++;
ch = commentWhitespace();
}
if (ch !== 125/*}*/) break;
pos++;
ch = commentWhitespace();
Expand Down Expand Up @@ -1039,7 +1148,6 @@ function throwIfImportStatement () {
// import.meta
case 46/*.*/:
throw new Error('Unexpected import.meta in CJS module.');
return;

default:
// no space after "import" -> not an import keyword
Expand Down
2 changes: 1 addition & 1 deletion deps/cjs-module-lexer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cjs-module-lexer",
"version": "1.0.0",
"version": "1.1.0",
"description": "Lexes CommonJS modules, returning their named exports metadata",
"main": "lexer.js",
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,7 @@ success!
[`Uint8Array`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
[dynamic instantiate hook]: #esm_code_dynamicinstantiate_code_hook
[`util.TextDecoder`]: util.md#util_class_util_textdecoder
[cjs-module-lexer]: https://github.com/guybedford/cjs-module-lexer/tree/1.0.0
[cjs-module-lexer]: https://github.com/guybedford/cjs-module-lexer/tree/1.1.0
[special scheme]: https://url.spec.whatwg.org/#special-scheme
[the official standard format]: https://tc39.github.io/ecma262/#sec-modules
[transpiler loader example]: #esm_transpiler_loader
Expand Down