Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
98ac3c4
build: label PRs with GitHub Action instead of nodejs-github-bot
phillipj Mar 6, 2021
499e56b
build: fix label-pr workflow
targos Apr 25, 2021
93a1a3c
deps: V8: cherry-pick 530080c44af2
May 3, 2021
bbceab4
deps: V8: backport 1b1eda0876aa
targos Jul 3, 2021
2b54156
deps: V8: cherry-pick 92e6d3317082
targos Jul 3, 2021
492b0d6
deps: V8: cherry-pick e6f62a41f5ee
targos Jul 3, 2021
a73275f
deps: V8: cherry-pick 7b3332844212
targos Jul 3, 2021
add7b5b
deps: V8: cherry-pick cc641f6be756
targos Jul 3, 2021
f4377b1
deps: V8: cherry-pick 7c182bd65f42
targos Jul 3, 2021
8046daf
deps: V8: cherry-pick 0b3a4ecf7083
targos Jul 7, 2021
15b91fa
deps: V8: backport 895949419186
targos Jul 7, 2021
906b43e
deps: V8: update build dependencies
targos Jul 3, 2021
7d5a2f9
deps: update to cjs-module-lexer@1.1.1
guybedford Mar 30, 2021
b3c698a
deps: update to cjs-module-lexer@1.2.1
guybedford Apr 28, 2021
30ce0e6
src: update cares_wrap OpenBSD defines
addaleax May 13, 2021
f552c45
src: move CHECK in AddIsolateFinishedCallback
indutny Mar 31, 2021
e459c79
deps: V8: cherry-pick 035c305ce776
targos May 1, 2021
39e9cd5
deps: restore minimum ICU version to 65
richardlau Jun 17, 2021
e11a862
deps: update to c-ares 1.17.1
lxdicted Nov 21, 2020
b263f25
http2: on receiving rst_stream with cancel code add it to pending list
kumarak Jul 26, 2021
ddc8dde
deps: upgrade npm to 6.14.14
darcyclarke Jul 27, 2021
3e4bc1b
module: fix legacy `node` specifier resolution to resolve `"main"` field
aduh95 Jun 9, 2021
2fdf989
2021-07-29, Version 12.22.4 'Erbium' (LTS)
richardlau Jul 23, 2021
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.2.1
PR-URL: #38450
Backport-PR-URL: #39422
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
guybedford authored and richardlau committed Jul 23, 2021
commit b3c698a5d8357152504a100768c2c68ea25b5c5d
7 changes: 7 additions & 0 deletions deps/cjs-module-lexer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
1.2.1
- Support Unicode escapes in strings (https://github.com/guybedford/cjs-module-lexer/pull/55)
- Filter export strings to valid surrogate pairs (https://github.com/guybedford/cjs-module-lexer/pull/56)

1.2.0
- Support for non-identifier exports (https://github.com/guybedford/cjs-module-lexer/pull/54, @nicolo-ribaudo)

1.1.1
- Better support for Babel reexport getter function forms (https://github.com/guybedford/cjs-module-lexer/issues/50)
- Support Babel interopRequireWildcard reexports patterns (https://github.com/guybedford/cjs-module-lexer/issues/52)
Expand Down
14 changes: 6 additions & 8 deletions deps/cjs-module-lexer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,29 +70,27 @@ IDENTIFIER: As defined by ECMA-262, without support for identifier `\` escapes,

STRING_LITERAL: A `"` or `'` bounded ECMA-262 string literal.

IDENTIFIER_STRING: ( `"` IDENTIFIER `"` | `'` IDENTIFIER `'` )

MODULE_EXPORTS: `module` `.` `exports`

EXPORTS_IDENTIFIER: MODULE_EXPORTS_IDENTIFIER | `exports`

EXPORTS_DOT_ASSIGN: EXPORTS_IDENTIFIER `.` IDENTIFIER `=`

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

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

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

EXPORTS_MEMBER: EXPORTS_DOT_ASSIGN | EXPORTS_LITERAL_COMPUTED_ASSIGN

EXPORTS_DEFINE: `Object` `.` `defineProperty `(` EXPORTS_IDENFITIER `,` IDENTIFIER_STRING
EXPORTS_DEFINE: `Object` `.` `defineProperty `(` EXPORTS_IDENFITIER `,` STRING_LITERAL

EXPORTS_DEFINE_VALUE: EXPORTS_DEFINE `, {`
(`enumerable: true,`)?
(
`value:` |
`get` (`: function` IDENTIFIER? )? `() {` return IDENTIFIER (`.` IDENTIFIER | `[` IDENTIFIER_STRING `]`)? `;`? `}` `,`?
`get` (`: function` IDENTIFIER? )? `() {` return IDENTIFIER (`.` IDENTIFIER | `[` STRING_LITERAL `]`)? `;`? `}` `,`?
)
`})`

Expand Down Expand Up @@ -127,8 +125,8 @@ EXPORT_STAR_LIB: `Object.keys(` IDENTIFIER$1 `).forEach(function (` IDENTIFIER$2
Spacing between tokens is taken to be any ECMA-262 whitespace, ECMA-262 block comment or ECMA-262 line comment.

* The returned export names are taken to be the combination of:
1. All `IDENTIFIER` and `IDENTIFIER_STRING` slots for `EXPORTS_MEMBER` and `EXPORTS_LITERAL` matches.
2. The first `IDENTIFIER_STRING` slot for all `EXPORTS_DEFINE_VALUE` matches where that same string is not an `EXPORTS_DEFINE` match that is not also an `EXPORTS_DEFINE_VALUE` match.
1. All `IDENTIFIER` and `STRING_LITERAL` slots for `EXPORTS_MEMBER` and `EXPORTS_LITERAL` matches.
2. The first `STRING_LITERAL` slot for all `EXPORTS_DEFINE_VALUE` matches where that same string is not an `EXPORTS_DEFINE` match that is not also an `EXPORTS_DEFINE_VALUE` match.
* The reexport specifiers are taken to be the combination of:
1. The `REQUIRE` matches of the last matched of either `MODULE_EXPORTS_ASSIGN` or `EXPORTS_LITERAL`.
2. All _top-level_ `EXPORT_STAR` `REQUIRE` matches and `EXPORTS_ASSIGN` matches whose `IDENTIFIER` also matches the first `IDENTIFIER` in `EXPORT_STAR_LIB`.
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.

159 changes: 69 additions & 90 deletions deps/cjs-module-lexer/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ const Import = 0;
const ExportAssign = 1;
const ExportStar = 2;

const strictReserved = new Set(['implements', 'interface', 'let', 'package', 'private', 'protected', 'public', 'static', 'yield', 'enum']);

function parseCJS (source, name = '@') {
resetState();
try {
Expand All @@ -49,14 +47,39 @@ function parseCJS (source, name = '@') {
e.loc = pos;
throw e;
}
const result = { exports: [..._exports].filter(expt => !unsafeGetters.has(expt)), reexports: [...reexports] };
const result = { exports: [..._exports].filter(expt => expt !== undefined && !unsafeGetters.has(expt)), reexports: [...reexports].filter(reexpt => reexpt !== undefined) };
resetState();
return result;
}

function addExport (name) {
if (!strictReserved.has(name))
_exports.add(name);
function decode (str) {
if (str[0] === '"' || str[0] === '\'') {
try {
const decoded = (0, eval)(str);
// Filter to exclude non-matching UTF-16 surrogate strings
for (let i = 0; i < decoded.length; i++) {
const surrogatePrefix = decoded.charCodeAt(i) & 0xFC00;
if (surrogatePrefix < 0xD800) {
// Not a surrogate
continue;
}
else if (surrogatePrefix === 0xD800) {
// Validate surrogate pair
if ((decoded.charCodeAt(++i) & 0xFC00) !== 0xDC00)
return;
}
else {
// Out-of-range surrogate code (above 0xD800)
return;
}
}
return decoded;
}
catch {}
}
else {
return str;
}
}

function parseSource (cjsSource) {
Expand Down Expand Up @@ -173,10 +196,8 @@ function parseSource (cjsSource) {
// TODO: <!-- XML comment support
break;
case 39/*'*/:
singleQuoteString();
break;
case 34/*"*/:
doubleQuoteString();
stringLiteral(ch);
break;
case 47/*/*/: {
const next_ch = source.charCodeAt(pos + 1);
Expand Down Expand Up @@ -329,11 +350,9 @@ function tryParseObjectDefineOrKeys (keys) {
pos++;
ch = commentWhitespace();
if (ch !== 39/*'*/ && ch !== 34/*"*/) break;
let quot = ch;
const exportPos = ++pos;
if (!identifier() || source.charCodeAt(pos) !== quot) break;
expt = source.slice(exportPos, pos);
pos++;
const exportPos = pos;
stringLiteral(ch);
expt = source.slice(exportPos, ++pos);
ch = commentWhitespace();
if (ch !== 44/*,*/) break;
pos++;
Expand All @@ -360,7 +379,7 @@ function tryParseObjectDefineOrKeys (keys) {
pos += 5;
ch = commentWhitespace();
if (ch !== 58/*:*/) break;
addExport(expt);
_exports.add(decode(expt));
pos = revertPos;
return;
}
Expand Down Expand Up @@ -403,8 +422,7 @@ function tryParseObjectDefineOrKeys (keys) {
else if (ch === 91/*[*/) {
pos++;
ch = commentWhitespace();
if (ch === 39/*'*/) singleQuoteString();
else if (ch === 34/*"*/) doubleQuoteString();
if (ch === 39/*'*/ || ch === 34/*"*/) stringLiteral(ch);
else break;
pos++;
ch = commentWhitespace();
Expand All @@ -427,13 +445,13 @@ function tryParseObjectDefineOrKeys (keys) {
pos++;
ch = commentWhitespace();
if (ch !== 41/*)*/) break;
addExport(expt);
_exports.add(decode(expt));
return;
}
break;
}
if (expt) {
unsafeGetters.add(expt);
unsafeGetters.add(decode(expt));
}
}
else if (keys && ch === 107/*k*/ && source.startsWith('eys', pos + 1)) {
Expand Down Expand Up @@ -801,7 +819,7 @@ function tryParseObjectDefineOrKeys (keys) {

const starExportSpecifier = starExportMap[id];
if (starExportSpecifier) {
reexports.add(starExportSpecifier);
reexports.add(decode(starExportSpecifier));
pos = revertPos;
return;
}
Expand Down Expand Up @@ -863,7 +881,7 @@ function tryParseExportsDotAssign (assign) {
const endPos = pos;
ch = commentWhitespace();
if (ch === 61/*=*/) {
addExport(source.slice(startPos, endPos));
_exports.add(decode(source.slice(startPos, endPos)));
return;
}
}
Expand All @@ -874,19 +892,15 @@ function tryParseExportsDotAssign (assign) {
pos++;
ch = commentWhitespace();
if (ch === 39/*'*/ || ch === 34/*"*/) {
pos++;
const startPos = pos;
if (identifier() && source.charCodeAt(pos) === ch) {
const endPos = pos++;
ch = commentWhitespace();
if (ch !== 93/*]*/)
break;
pos++;
ch = commentWhitespace();
if (ch !== 61/*=*/)
break;
addExport(source.slice(startPos, endPos));
}
stringLiteral(ch);
const endPos = ++pos;
ch = commentWhitespace();
if (ch !== 93/*]*/) break;
pos++;
ch = commentWhitespace();
if (ch !== 61/*=*/) break;
_exports.add(decode(source.slice(startPos, endPos)));
}
break;
}
Expand Down Expand Up @@ -921,39 +935,21 @@ function tryParseRequire (requireType) {
if (ch === 40/*(*/) {
pos++;
ch = commentWhitespace();
const reexportStart = pos + 1;
if (ch === 39/*'*/) {
singleQuoteString();
const reexportEnd = pos++;
ch = commentWhitespace();
if (ch === 41/*)*/) {
switch (requireType) {
case ExportAssign:
reexports.add(source.slice(reexportStart, reexportEnd));
return true;
case ExportStar:
reexports.add(source.slice(reexportStart, reexportEnd));
return true;
default:
lastStarExportSpecifier = source.slice(reexportStart, reexportEnd);
return true;
}
}
}
else if (ch === 34/*"*/) {
doubleQuoteString();
const reexportEnd = pos++;
const reexportStart = pos;
if (ch === 39/*'*/ || ch === 34/*"*/) {
stringLiteral(ch);
const reexportEnd = ++pos;
ch = commentWhitespace();
if (ch === 41/*)*/) {
switch (requireType) {
case ExportAssign:
reexports.add(source.slice(reexportStart, reexportEnd));
reexports.add(decode(source.slice(reexportStart, reexportEnd)));
return true;
case ExportStar:
reexports.add(source.slice(reexportStart, reexportEnd));
reexports.add(decode(source.slice(reexportStart, reexportEnd)));
return true;
default:
lastStarExportSpecifier = source.slice(reexportStart, reexportEnd);
lastStarExportSpecifier = decode(source.slice(reexportStart, reexportEnd));
return true;
}
}
Expand Down Expand Up @@ -982,7 +978,7 @@ function tryParseLiteralExports () {
}
ch = source.charCodeAt(pos);
}
addExport(source.slice(startPos, endPos));
_exports.add(decode(source.slice(startPos, endPos)));
}
else if (ch === 46/*.*/ && source.startsWith('..', pos + 1)) {
pos += 3;
Expand All @@ -996,21 +992,20 @@ function tryParseLiteralExports () {
ch = commentWhitespace();
}
else if (ch === 39/*'*/ || ch === 34/*"*/) {
const startPos = ++pos;
if (identifier() && source.charCodeAt(pos) === ch) {
const endPos = pos++;
const startPos = pos;
stringLiteral(ch);
const endPos = ++pos;
ch = commentWhitespace();
if (ch === 58/*:*/) {
pos++;
ch = commentWhitespace();
if (ch === 58/*:*/) {
pos++;
ch = commentWhitespace();
// nothing more complex than identifier expressions for now
if (!identifier()) {
pos = revertPos;
return;
}
ch = source.charCodeAt(pos);
addExport(source.slice(startPos, endPos));
// nothing more complex than identifier expressions for now
if (!identifier()) {
pos = revertPos;
return;
}
ch = source.charCodeAt(pos);
_exports.add(decode(source.slice(startPos, endPos)));
}
}
else {
Expand Down Expand Up @@ -1248,26 +1243,10 @@ function lineComment () {
}
}

function singleQuoteString () {
while (pos++ < end) {
let ch = source.charCodeAt(pos);
if (ch === 39/*'*/)
return;
if (ch === 92/*\*/) {
ch = source.charCodeAt(++pos);
if (ch === 13/*\r*/ && source.charCodeAt(pos + 1) === 10/*\n*/)
pos++;
}
else if (isBr(ch))
break;
}
throw new Error('Unterminated string.');
}

function doubleQuoteString () {
function stringLiteral (quote) {
while (pos++ < end) {
let ch = source.charCodeAt(pos);
if (ch === 34/*"*/)
if (ch === quote)
return;
if (ch === 92/*\*/) {
ch = source.charCodeAt(++pos);
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.1.1",
"version": "1.2.1",
"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.1.1
[cjs-module-lexer]: https://github.com/guybedford/cjs-module-lexer/tree/1.2.1
[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
5 changes: 4 additions & 1 deletion test/fixtures/es-modules/cjs-exports.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import { strictEqual, deepEqual } from 'assert';
import m, { π } from './exports-cases.js';
import * as ns from './exports-cases.js';

deepEqual(Object.keys(ns), ['default', 'isObject', 'z', 'π']);
deepEqual(Object.keys(ns), ['?invalid', 'default', 'invalid identifier', 'isObject', 'package', 'z', 'π', '\u{d83c}\u{df10}']);
strictEqual(π, 'yes');
strictEqual(typeof m.isObject, 'undefined');
strictEqual(m.π, 'yes');
strictEqual(m.z, 'yes');
strictEqual(m.package, 10);
strictEqual(m['invalid identifier'], 'yes');
strictEqual(m['?invalid'], 'yes');

import m2, { __esModule as __esModule2, name as name2 } from './exports-cases2.js';
import * as ns2 from './exports-cases2.js';
Expand Down
8 changes: 5 additions & 3 deletions test/fixtures/es-modules/exports-cases.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
if (global.maybe)
module.exports = require('../is-object');
exports['invalid identifier'] = 'no';
module.exports['?invalid'] = 'no';
exports['invalid identifier'] = 'yes';
module.exports['?invalid'] = 'yes';
module.exports['π'] = 'yes';
exports.package = 10; // reserved word -> not used
exports['\u{D83C}'] = 'no';
exports['\u{D83C}\u{DF10}'] = 'yes';
exports.package = 10; // reserved word
Object.defineProperty(exports, 'z', { value: 'yes' });