Skip to content

Commit b8c4d30

Browse files
guybedfordtargos
authored andcommitted
deps: update to cjs-module-lexer@1.2.1
PR-URL: #38450 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>
1 parent 839e8d1 commit b8c4d30

9 files changed

Lines changed: 96 additions & 107 deletions

File tree

‎deps/cjs-module-lexer/CHANGELOG.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
1.2.1
2+
- Support Unicode escapes in strings (https://github.com/guybedford/cjs-module-lexer/pull/55)
3+
- Filter export strings to valid surrogate pairs (https://github.com/guybedford/cjs-module-lexer/pull/56)
4+
5+
1.2.0
6+
- Support for non-identifier exports (https://github.com/guybedford/cjs-module-lexer/pull/54, @nicolo-ribaudo)
7+
18
1.1.1
29
- Better support for Babel reexport getter function forms (https://github.com/guybedford/cjs-module-lexer/issues/50)
310
- Support Babel interopRequireWildcard reexports patterns (https://github.com/guybedford/cjs-module-lexer/issues/52)

‎deps/cjs-module-lexer/README.md‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,29 +70,27 @@ IDENTIFIER: As defined by ECMA-262, without support for identifier `\` escapes,
7070
7171
STRING_LITERAL: A `"` or `'` bounded ECMA-262 string literal.
7272
73-
IDENTIFIER_STRING: ( `"` IDENTIFIER `"` | `'` IDENTIFIER `'` )
74-
7573
MODULE_EXPORTS: `module` `.` `exports`
7674
7775
EXPORTS_IDENTIFIER: MODULE_EXPORTS_IDENTIFIER | `exports`
7876
7977
EXPORTS_DOT_ASSIGN: EXPORTS_IDENTIFIER `.` IDENTIFIER `=`
8078
81-
EXPORTS_LITERAL_COMPUTED_ASSIGN: EXPORTS_IDENTIFIER `[` IDENTIFIER_STRING `]` `=`
79+
EXPORTS_LITERAL_COMPUTED_ASSIGN: EXPORTS_IDENTIFIER `[` STRING_LITERAL `]` `=`
8280
83-
EXPORTS_LITERAL_PROP: (IDENTIFIER (`:` IDENTIFIER)?) | (IDENTIFIER_STRING `:` IDENTIFIER)
81+
EXPORTS_LITERAL_PROP: (IDENTIFIER (`:` IDENTIFIER)?) | (STRING_LITERAL `:` IDENTIFIER)
8482
8583
EXPORTS_SPREAD: `...` (IDENTIFIER | REQUIRE)
8684
8785
EXPORTS_MEMBER: EXPORTS_DOT_ASSIGN | EXPORTS_LITERAL_COMPUTED_ASSIGN
8886
89-
EXPORTS_DEFINE: `Object` `.` `defineProperty `(` EXPORTS_IDENFITIER `,` IDENTIFIER_STRING
87+
EXPORTS_DEFINE: `Object` `.` `defineProperty `(` EXPORTS_IDENFITIER `,` STRING_LITERAL
9088
9189
EXPORTS_DEFINE_VALUE: EXPORTS_DEFINE `, {`
9290
(`enumerable: true,`)?
9391
(
9492
`value:` |
95-
`get` (`: function` IDENTIFIER? )? `() {` return IDENTIFIER (`.` IDENTIFIER | `[` IDENTIFIER_STRING `]`)? `;`? `}` `,`?
93+
`get` (`: function` IDENTIFIER? )? `() {` return IDENTIFIER (`.` IDENTIFIER | `[` STRING_LITERAL `]`)? `;`? `}` `,`?
9694
)
9795
`})`
9896
@@ -127,8 +125,8 @@ EXPORT_STAR_LIB: `Object.keys(` IDENTIFIER$1 `).forEach(function (` IDENTIFIER$2
127125
Spacing between tokens is taken to be any ECMA-262 whitespace, ECMA-262 block comment or ECMA-262 line comment.
128126

129127
* The returned export names are taken to be the combination of:
130-
1. All `IDENTIFIER` and `IDENTIFIER_STRING` slots for `EXPORTS_MEMBER` and `EXPORTS_LITERAL` matches.
131-
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.
128+
1. All `IDENTIFIER` and `STRING_LITERAL` slots for `EXPORTS_MEMBER` and `EXPORTS_LITERAL` matches.
129+
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.
132130
* The reexport specifiers are taken to be the combination of:
133131
1. The `REQUIRE` matches of the last matched of either `MODULE_EXPORTS_ASSIGN` or `EXPORTS_LITERAL`.
134132
2. All _top-level_`EXPORT_STAR``REQUIRE` matches and `EXPORTS_ASSIGN` matches whose `IDENTIFIER` also matches the first `IDENTIFIER` in `EXPORT_STAR_LIB`.

‎deps/cjs-module-lexer/dist/lexer.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎deps/cjs-module-lexer/dist/lexer.mjs‎

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

‎deps/cjs-module-lexer/lexer.js‎

Lines changed: 69 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ const Import = 0;
3737
constExportAssign=1;
3838
constExportStar=2;
3939

40-
conststrictReserved=newSet(['implements','interface','let','package','private','protected','public','static','yield','enum']);
41-
4240
functionparseCJS(source,name='@'){
4341
resetState();
4442
try{
@@ -49,14 +47,39 @@ function parseCJS (source, name = '@') {
4947
e.loc=pos;
5048
throwe;
5149
}
52-
constresult={exports: [..._exports].filter(expt=>!unsafeGetters.has(expt)),reexports: [...reexports]};
50+
constresult={exports: [..._exports].filter(expt=>expt!==undefined&&!unsafeGetters.has(expt)),reexports: [...reexports].filter(reexpt=>reexpt!==undefined)};
5351
resetState();
5452
returnresult;
5553
}
5654

57-
functionaddExport(name){
58-
if(!strictReserved.has(name))
59-
_exports.add(name);
55+
functiondecode(str){
56+
if(str[0]==='"'||str[0]==='\''){
57+
try{
58+
constdecoded=(0,eval)(str);
59+
// Filter to exclude non-matching UTF-16 surrogate strings
60+
for(leti=0;i<decoded.length;i++){
61+
constsurrogatePrefix=decoded.charCodeAt(i)&0xFC00;
62+
if(surrogatePrefix<0xD800){
63+
// Not a surrogate
64+
continue;
65+
}
66+
elseif(surrogatePrefix===0xD800){
67+
// Validate surrogate pair
68+
if((decoded.charCodeAt(++i)&0xFC00)!==0xDC00)
69+
return;
70+
}
71+
else{
72+
// Out-of-range surrogate code (above 0xD800)
73+
return;
74+
}
75+
}
76+
returndecoded;
77+
}
78+
catch{}
79+
}
80+
else{
81+
returnstr;
82+
}
6083
}
6184

6285
functionparseSource(cjsSource){
@@ -173,10 +196,8 @@ function parseSource (cjsSource) {
173196
// TODO: <!-- XML comment support
174197
break;
175198
case39/*'*/:
176-
singleQuoteString();
177-
break;
178199
case34/*"*/:
179-
doubleQuoteString();
200+
stringLiteral(ch);
180201
break;
181202
case47/*/*/: {
182203
constnext_ch=source.charCodeAt(pos+1);
@@ -329,11 +350,9 @@ function tryParseObjectDefineOrKeys (keys) {
329350
pos++;
330351
ch=commentWhitespace();
331352
if(ch!==39/*'*/&&ch!==34/*"*/)break;
332-
letquot=ch;
333-
constexportPos=++pos;
334-
if(!identifier()||source.charCodeAt(pos)!==quot)break;
335-
expt=source.slice(exportPos,pos);
336-
pos++;
353+
constexportPos=pos;
354+
stringLiteral(ch);
355+
expt=source.slice(exportPos,++pos);
337356
ch=commentWhitespace();
338357
if(ch!==44/*,*/)break;
339358
pos++;
@@ -360,7 +379,7 @@ function tryParseObjectDefineOrKeys (keys) {
360379
pos+=5;
361380
ch=commentWhitespace();
362381
if(ch!==58/*:*/)break;
363-
addExport(expt);
382+
_exports.add(decode(expt));
364383
pos=revertPos;
365384
return;
366385
}
@@ -403,8 +422,7 @@ function tryParseObjectDefineOrKeys (keys) {
403422
elseif(ch===91/*[*/){
404423
pos++;
405424
ch=commentWhitespace();
406-
if(ch===39/*'*/)singleQuoteString();
407-
elseif(ch===34/*"*/)doubleQuoteString();
425+
if(ch===39/*'*/||ch===34/*"*/)stringLiteral(ch);
408426
elsebreak;
409427
pos++;
410428
ch=commentWhitespace();
@@ -427,13 +445,13 @@ function tryParseObjectDefineOrKeys (keys) {
427445
pos++;
428446
ch=commentWhitespace();
429447
if(ch!==41/*)*/)break;
430-
addExport(expt);
448+
_exports.add(decode(expt));
431449
return;
432450
}
433451
break;
434452
}
435453
if(expt){
436-
unsafeGetters.add(expt);
454+
unsafeGetters.add(decode(expt));
437455
}
438456
}
439457
elseif(keys&&ch===107/*k*/&&source.startsWith('eys',pos+1)){
@@ -801,7 +819,7 @@ function tryParseObjectDefineOrKeys (keys) {
801819

802820
conststarExportSpecifier=starExportMap[id];
803821
if(starExportSpecifier){
804-
reexports.add(starExportSpecifier);
822+
reexports.add(decode(starExportSpecifier));
805823
pos=revertPos;
806824
return;
807825
}
@@ -863,7 +881,7 @@ function tryParseExportsDotAssign (assign) {
863881
constendPos=pos;
864882
ch=commentWhitespace();
865883
if(ch===61/*=*/){
866-
addExport(source.slice(startPos,endPos));
884+
_exports.add(decode(source.slice(startPos,endPos)));
867885
return;
868886
}
869887
}
@@ -874,19 +892,15 @@ function tryParseExportsDotAssign (assign) {
874892
pos++;
875893
ch=commentWhitespace();
876894
if(ch===39/*'*/||ch===34/*"*/){
877-
pos++;
878895
conststartPos=pos;
879-
if(identifier()&&source.charCodeAt(pos)===ch){
880-
constendPos=pos++;
881-
ch=commentWhitespace();
882-
if(ch!==93/*]*/)
883-
break;
884-
pos++;
885-
ch=commentWhitespace();
886-
if(ch!==61/*=*/)
887-
break;
888-
addExport(source.slice(startPos,endPos));
889-
}
896+
stringLiteral(ch);
897+
constendPos=++pos;
898+
ch=commentWhitespace();
899+
if(ch!==93/*]*/)break;
900+
pos++;
901+
ch=commentWhitespace();
902+
if(ch!==61/*=*/)break;
903+
_exports.add(decode(source.slice(startPos,endPos)));
890904
}
891905
break;
892906
}
@@ -921,39 +935,21 @@ function tryParseRequire (requireType) {
921935
if(ch===40/*(*/){
922936
pos++;
923937
ch=commentWhitespace();
924-
constreexportStart=pos+1;
925-
if(ch===39/*'*/){
926-
singleQuoteString();
927-
constreexportEnd=pos++;
928-
ch=commentWhitespace();
929-
if(ch===41/*)*/){
930-
switch(requireType){
931-
caseExportAssign:
932-
reexports.add(source.slice(reexportStart,reexportEnd));
933-
returntrue;
934-
caseExportStar:
935-
reexports.add(source.slice(reexportStart,reexportEnd));
936-
returntrue;
937-
default:
938-
lastStarExportSpecifier=source.slice(reexportStart,reexportEnd);
939-
returntrue;
940-
}
941-
}
942-
}
943-
elseif(ch===34/*"*/){
944-
doubleQuoteString();
945-
constreexportEnd=pos++;
938+
constreexportStart=pos;
939+
if(ch===39/*'*/||ch===34/*"*/){
940+
stringLiteral(ch);
941+
constreexportEnd=++pos;
946942
ch=commentWhitespace();
947943
if(ch===41/*)*/){
948944
switch(requireType){
949945
caseExportAssign:
950-
reexports.add(source.slice(reexportStart,reexportEnd));
946+
reexports.add(decode(source.slice(reexportStart,reexportEnd)));
951947
returntrue;
952948
caseExportStar:
953-
reexports.add(source.slice(reexportStart,reexportEnd));
949+
reexports.add(decode(source.slice(reexportStart,reexportEnd)));
954950
returntrue;
955951
default:
956-
lastStarExportSpecifier=source.slice(reexportStart,reexportEnd);
952+
lastStarExportSpecifier=decode(source.slice(reexportStart,reexportEnd));
957953
returntrue;
958954
}
959955
}
@@ -982,7 +978,7 @@ function tryParseLiteralExports () {
982978
}
983979
ch=source.charCodeAt(pos);
984980
}
985-
addExport(source.slice(startPos,endPos));
981+
_exports.add(decode(source.slice(startPos,endPos)));
986982
}
987983
elseif(ch===46/*.*/&&source.startsWith('..',pos+1)){
988984
pos+=3;
@@ -996,21 +992,20 @@ function tryParseLiteralExports () {
996992
ch=commentWhitespace();
997993
}
998994
elseif(ch===39/*'*/||ch===34/*"*/){
999-
conststartPos=++pos;
1000-
if(identifier()&&source.charCodeAt(pos)===ch){
1001-
constendPos=pos++;
995+
conststartPos=pos;
996+
stringLiteral(ch);
997+
constendPos=++pos;
998+
ch=commentWhitespace();
999+
if(ch===58/*:*/){
1000+
pos++;
10021001
ch=commentWhitespace();
1003-
if(ch===58/*:*/){
1004-
pos++;
1005-
ch=commentWhitespace();
1006-
// nothing more complex than identifier expressions for now
1007-
if(!identifier()){
1008-
pos=revertPos;
1009-
return;
1010-
}
1011-
ch=source.charCodeAt(pos);
1012-
addExport(source.slice(startPos,endPos));
1002+
// nothing more complex than identifier expressions for now
1003+
if(!identifier()){
1004+
pos=revertPos;
1005+
return;
10131006
}
1007+
ch=source.charCodeAt(pos);
1008+
_exports.add(decode(source.slice(startPos,endPos)));
10141009
}
10151010
}
10161011
else{
@@ -1248,26 +1243,10 @@ function lineComment () {
12481243
}
12491244
}
12501245

1251-
functionsingleQuoteString(){
1252-
while(pos++<end){
1253-
letch=source.charCodeAt(pos);
1254-
if(ch===39/*'*/)
1255-
return;
1256-
if(ch===92/*\*/){
1257-
ch=source.charCodeAt(++pos);
1258-
if(ch===13/*\r*/&&source.charCodeAt(pos+1)===10/*\n*/)
1259-
pos++;
1260-
}
1261-
elseif(isBr(ch))
1262-
break;
1263-
}
1264-
thrownewError('Unterminated string.');
1265-
}
1266-
1267-
functiondoubleQuoteString(){
1246+
functionstringLiteral(quote){
12681247
while(pos++<end){
12691248
letch=source.charCodeAt(pos);
1270-
if(ch===34/*"*/)
1249+
if(ch===quote)
12711250
return;
12721251
if(ch===92/*\*/){
12731252
ch=source.charCodeAt(++pos);

‎deps/cjs-module-lexer/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cjs-module-lexer",
3-
"version": "1.1.1",
3+
"version": "1.2.1",
44
"description": "Lexes CommonJS modules, returning their named exports metadata",
55
"main": "lexer.js",
66
"exports": {

‎doc/api/esm.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1327,7 +1327,7 @@ success!
13271327
[`transformSource` hook]: #esm_transformsource_source_context_defaulttransformsource
13281328
[`string`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
13291329
[`util.TextDecoder`]:util.md#util_class_util_textdecoder
1330-
[cjs-module-lexer]: https://github.com/guybedford/cjs-module-lexer/tree/1.1.1
1330+
[cjs-module-lexer]: https://github.com/guybedford/cjs-module-lexer/tree/1.2.1
13311331
[custom https loader]: #esm_https_loader
13321332
[special scheme]: https://url.spec.whatwg.org/#special-scheme
13331333
[the official standard format]: https://tc39.github.io/ecma262/#sec-modules

‎test/fixtures/es-modules/cjs-exports.mjs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ import { strictEqual, deepEqual } from 'assert';
33
importm,{π}from'./exports-cases.js';
44
import*asnsfrom'./exports-cases.js';
55

6-
deepEqual(Object.keys(ns),['default','isObject','z','π']);
6+
deepEqual(Object.keys(ns),['?invalid','default','invalid identifier','isObject','package','z',','\u{d83c}\u{df10}']);
77
strictEqual(π,'yes');
88
strictEqual(typeofm.isObject,'undefined');
99
strictEqual(m.π,'yes');
1010
strictEqual(m.z,'yes');
11+
strictEqual(m.package,10);
12+
strictEqual(m['invalid identifier'],'yes');
13+
strictEqual(m['?invalid'],'yes');
1114

1215
importm2,{__esModuleas__esModule2,nameasname2}from'./exports-cases2.js';
1316
import*asns2from'./exports-cases2.js';
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
if(global.maybe)
22
module.exports=require('../is-object');
3-
exports['invalid identifier']='no';
4-
module.exports['?invalid']='no';
3+
exports['invalid identifier']='yes';
4+
module.exports['?invalid']='yes';
55
module.exports['π']='yes';
6-
exports.package=10;// reserved word -> not used
6+
exports['\u{D83C}']='no';
7+
exports['\u{D83C}\u{DF10}']='yes';
8+
exports.package=10;// reserved word
79
Object.defineProperty(exports,'z',{value: 'yes'});

0 commit comments

Comments
 (0)