Skip to content

Commit ee33ef3

Browse files
mhdawsontargos
authored andcommittedFeb 5, 2025
deps: update cjs-module-lexer to 2.0.0
Signed-off-by: Michael Dawson <mdawson@devrus.com> PR-URL: #56855 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Richard Lau <rlau@redhat.com>
1 parent 93d0beb commit ee33ef3

27 files changed

+6432
-736
lines changed
 

‎deps/cjs-module-lexer/LICENSE

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
MIT License
2-
-----------
3-
4-
Copyright (C) 2018-2020 Guy Bedford
5-
6-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7-
8-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9-
10-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1+
MIT License
2+
-----------
3+
4+
Copyright (C) 2018-2020 Guy Bedford
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7+
8+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9+
10+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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

+464-462
Large diffs are not rendered by default.

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

-91
This file was deleted.

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

+1-1
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

+2-2
Large diffs are not rendered by default.

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

100644100755
File mode changed.

‎deps/cjs-module-lexer/src/.babelrc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"plugins": [
3+
[
4+
"@babel/plugin-transform-modules-commonjs",
5+
{
6+
"strict": true
7+
},
8+
]
9+
]
10+
}
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
1.2.2
2+
- Fix RollupJS reexports bug (https://github.com/nodejs/cjs-module-lexer/pull/59)
3+
4+
1.2.1
5+
- Support Unicode escapes in strings (https://github.com/nodejs/cjs-module-lexer/pull/55)
6+
- Filter export strings to valid surrogate pairs (https://github.com/nodejs/cjs-module-lexer/pull/56)
7+
8+
1.2.0
9+
- Support for non-identifier exports (https://github.com/nodejs/cjs-module-lexer/pull/54, @nicolo-ribaudo)
10+
11+
1.1.1
12+
- Better support for Babel reexport getter function forms (https://github.com/nodejs/cjs-module-lexer/issues/50)
13+
- Support Babel interopRequireWildcard reexports patterns (https://github.com/nodejs/cjs-module-lexer/issues/52)
14+
15+
1.1.0
16+
- Support for Babel reexport conflict filter (https://github.com/nodejs/cjs-module-lexer/issues/36, @nicolo-ribaudo)
17+
- Support trailing commas in getter patterns (https://github.com/nodejs/cjs-module-lexer/issues/31)
18+
- Support for RollupJS reexports property checks (https://github.com/nodejs/cjs-module-lexer/issues/38)
19+
20+
1.0.0
21+
- Unsafe getter tracking (https://github.com/nodejs/cjs-module-lexer/pull/29)
22+
23+
0.6.0
24+
- API-only breaking change: Unify JS and Wasm interfaces (https://github.com/nodejs/cjs-module-lexer/pull/27)
25+
- Add type definitions (https://github.com/nodejs/cjs-module-lexer/pull/28)
26+
27+
0.5.2
28+
- Support named getter functions (https://github.com/nodejs/cjs-module-lexer/pull/26)
29+
30+
0.5.1:
31+
- Feature: Implement specific reexport getter forms (https://github.com/nodejs/cjs-module-lexer/pull/25)
32+
33+
0.5.0
34+
- Breaking Change: No longer emit Object.defineProperty exports (https://github.com/nodejs/cjs-module-lexer/pull/24)
35+
- Doc: Update link to WASI SDK (https://github.com/nodejs/cjs-module-lexer/pull/19)
36+
37+
0.4.3
38+
- Support for Babel 7.12 reexports (https://github.com/nodejs/cjs-module-lexer/pull/16)
39+
- Support module.exports = { ...require('x') } reexports (https://github.com/nodejs/cjs-module-lexer/pull/18)
40+
- "if" keyword space parsing in exports matching (https://github.com/nodejs/cjs-module-lexer/pull/17)

‎deps/cjs-module-lexer/src/LICENSE

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
MIT License
2+
-----------
3+
4+
Copyright (C) 2018-2020 Guy Bedford
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7+
8+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9+
10+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

‎deps/cjs-module-lexer/src/Makefile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
WASM2WAT := ../wabt/bin/wasm2wat
2+
WASM_OPT := ../binaryen/bin/wasm-opt
3+
4+
.PHONY: optimize clean
5+
6+
lib/lexer.wat: lib/lexer.wasm
7+
$(WASM2WAT) lib/lexer.wasm -o lib/lexer.wat
8+
9+
lib/lexer.wasm: include-wasm/cjs-module-lexer.h src/lexer.c | lib/
10+
node build/wasm.js --docker
11+
12+
lib/:
13+
@mkdir -p $@
14+
15+
clean:
16+
$(RM) lib/*

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

+464
Large diffs are not rendered by default.

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

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const fs = require('fs');
2+
const terser = require('terser');
3+
4+
const MINIFY = true;
5+
6+
try { fs.mkdirSync('./dist'); }
7+
catch (e) {}
8+
9+
const wasmBuffer = fs.readFileSync('./lib/lexer.wasm');
10+
const jsSource = fs.readFileSync('./src/lexer.js').toString();
11+
const pjson = JSON.parse(fs.readFileSync('./package.json').toString());
12+
13+
const jsSourceProcessed = jsSource.replace('WASM_BINARY', wasmBuffer.toString('base64'));
14+
15+
const minified = MINIFY && terser.minify(jsSourceProcessed, {
16+
module: true,
17+
output: {
18+
preamble: `/* cjs-module-lexer ${pjson.version} */`
19+
}
20+
});
21+
22+
if (minified.error)
23+
throw minified.error;
24+
25+
fs.writeFileSync('./dist/lexer.mjs', minified ? minified.code : jsSourceProcessed);
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
lib/lexer.wasm: include-wasm/cjs-module-lexer.h src/lexer.c
2+
@mkdir -p lib
3+
clang --sysroot=/usr/share/wasi-sysroot -target wasm32-unknown-wasi src/lexer.c -I include-wasm -o lib/lexer.wasm -nostartfiles \
4+
-Wl,-z,stack-size=13312,--no-entry,--compress-relocations,--strip-all,--export=__heap_base,\
5+
--export=parseCJS,--export=sa,--export=e,--export=re,--export=es,--export=ee,--export=rre,--export=ree,--export=res,--export=ru,--export=us,--export=ue \
6+
-Wno-logical-op-parentheses -Wno-parentheses \
7+
-Oz
8+
9+
optimize: lib/lexer.wasm
10+
${WASM_OPT} -Oz lib/lexer.wasm -o lib/lexer.wasm
11+
12+
clean:
13+
rm lib/*
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
'use strict'
2+
3+
const WASM_BUILDER_CONTAINER = 'ghcr.io/nodejs/wasm-builder@sha256:975f391d907e42a75b8c72eb77c782181e941608687d4d8694c3e9df415a0970' // v0.0.9
4+
5+
const WASM_OPT = './wasm-opt'
6+
7+
const { execSync } = require('node:child_process')
8+
const { writeFileSync, readFileSync, existsSync, mkdirSync } = require('node:fs')
9+
const { join, resolve } = require('node:path')
10+
11+
const ROOT = resolve(__dirname, '../')
12+
13+
let platform = process.env.WASM_PLATFORM
14+
if (!platform && process.argv[2]) {
15+
platform = execSync('docker info -f "{{.OSType}}/{{.Architecture}}"').toString().trim()
16+
}
17+
18+
if (process.argv[2] === '--docker') {
19+
let cmd = `docker run --rm --platform=${platform.toString().trim()} `
20+
if (process.platform === 'linux') {
21+
cmd += ` --user ${process.getuid()}:${process.getegid()}`
22+
}
23+
24+
if (!existsSync(`${ROOT}/dist`)){
25+
mkdirSync(`${ROOT}/dist`);
26+
}
27+
28+
cmd += ` --mount type=bind,source=${ROOT}/lib,target=/home/node/build/lib \
29+
--mount type=bind,source=${ROOT}/src,target=/home/node/build/src \
30+
--mount type=bind,source=${ROOT}/dist,target=/home/node/build/dist \
31+
--mount type=bind,source=${ROOT}/node_modules,target=/home/node/build/node_modules \
32+
--mount type=bind,source=${ROOT}/build/wasm.js,target=/home/node/build/wasm.js \
33+
--mount type=bind,source=${ROOT}/build/Makefile,target=/home/node/build/Makefile \
34+
--mount type=bind,source=${ROOT}/build.js,target=/home/node/build/build.js \
35+
--mount type=bind,source=${ROOT}/package.json,target=/home/node/build/package.json \
36+
--mount type=bind,source=${ROOT}/include-wasm,target=/home/node/build/include-wasm \
37+
-t ${WASM_BUILDER_CONTAINER} node wasm.js`
38+
console.log(`> ${cmd}\n\n`)
39+
execSync(cmd, { stdio: 'inherit' })
40+
process.exit(0)
41+
}
42+
43+
const hasOptimizer = (function () {
44+
try { execSync(`${WASM_OPT} --version`); return true } catch (error) { return false }
45+
})()
46+
47+
// Build wasm binary
48+
console.log('Building wasm');
49+
execSync(`make lib/lexer.wasm`, { stdio: 'inherit' })
50+
if (hasOptimizer) {
51+
console.log('Optimizing wasm');
52+
execSync(`make optimize`, { stdio: 'inherit' })
53+
}
54+
execSync(`node build.js`, { stdio: 'inherit' })
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
#include <stdint.h>
2+
#include <stdbool.h>
3+
#include <stddef.h>
4+
#include <limits.h>
5+
#include <string.h>
6+
7+
extern unsigned char __heap_base;
8+
9+
const uint16_t* source = (void*)&__heap_base;
10+
uint32_t parse_error;
11+
12+
struct Slice {
13+
const uint16_t* start;
14+
const uint16_t* end;
15+
struct Slice* next;
16+
};
17+
typedef struct Slice Slice;
18+
19+
struct StarExportBinding {
20+
const uint16_t* specifier_start;
21+
const uint16_t* specifier_end;
22+
const uint16_t* id_start;
23+
const uint16_t* id_end;
24+
};
25+
typedef struct StarExportBinding StarExportBinding;
26+
27+
Slice* first_export = NULL;
28+
Slice* export_read_head = NULL;
29+
Slice* export_write_head = NULL;
30+
Slice* first_reexport = NULL;
31+
Slice* reexport_read_head = NULL;
32+
Slice* reexport_write_head = NULL;
33+
Slice* first_unsafe_getter = NULL;
34+
Slice* unsafe_getter_read_head = NULL;
35+
Slice* unsafe_getter_write_head = NULL;
36+
void* analysis_base;
37+
void* analysis_head;
38+
39+
void bail (uint32_t err);
40+
41+
// allocateSource
42+
const uint16_t* sa (uint32_t utf16Len) {
43+
const uint16_t* sourceEnd = source + utf16Len + 1;
44+
// ensure source is null terminated
45+
*(uint16_t*)(source + utf16Len) = '\0';
46+
analysis_base = (void*)sourceEnd;
47+
analysis_head = analysis_base;
48+
first_export = NULL;
49+
export_write_head = NULL;
50+
export_read_head = NULL;
51+
first_reexport = NULL;
52+
reexport_write_head = NULL;
53+
reexport_read_head = NULL;
54+
first_unsafe_getter = NULL;
55+
unsafe_getter_write_head = NULL;
56+
unsafe_getter_read_head = NULL;
57+
return source;
58+
}
59+
60+
// getErr
61+
uint32_t e () {
62+
return parse_error;
63+
}
64+
65+
// getExportStart
66+
uint32_t es () {
67+
return export_read_head->start - source;
68+
}
69+
// getExportEnd
70+
uint32_t ee () {
71+
return export_read_head->end - source;
72+
}
73+
// getReexportStart
74+
uint32_t res () {
75+
return reexport_read_head->start - source;
76+
}
77+
// getReexportEnd
78+
uint32_t ree () {
79+
return reexport_read_head->end - source;
80+
}
81+
// getUnsafeGetterStart
82+
uint32_t us () {
83+
return unsafe_getter_read_head->start - source;
84+
}
85+
// getUnsafeGetterEnd
86+
uint32_t ue () {
87+
return unsafe_getter_read_head->end - source;
88+
}
89+
// readExport
90+
bool re () {
91+
if (export_read_head == NULL)
92+
export_read_head = first_export;
93+
else
94+
export_read_head = export_read_head->next;
95+
if (export_read_head == NULL)
96+
return false;
97+
return true;
98+
}
99+
// readReexport
100+
bool rre () {
101+
if (reexport_read_head == NULL)
102+
reexport_read_head = first_reexport;
103+
else
104+
reexport_read_head = reexport_read_head->next;
105+
if (reexport_read_head == NULL)
106+
return false;
107+
return true;
108+
}
109+
// readUnsafeGetter
110+
bool ru () {
111+
if (unsafe_getter_read_head == NULL)
112+
unsafe_getter_read_head = first_unsafe_getter;
113+
else
114+
unsafe_getter_read_head = unsafe_getter_read_head->next;
115+
if (unsafe_getter_read_head == NULL)
116+
return false;
117+
return true;
118+
}
119+
120+
void _addExport (const uint16_t* start, const uint16_t* end) {
121+
Slice* export = (Slice*)(analysis_head);
122+
analysis_head = analysis_head + sizeof(Slice);
123+
if (export_write_head == NULL)
124+
first_export = export;
125+
else
126+
export_write_head->next = export;
127+
export_write_head = export;
128+
export->start = start;
129+
export->end = end;
130+
export->next = NULL;
131+
}
132+
void _addReexport (const uint16_t* start, const uint16_t* end) {
133+
Slice* reexport = (Slice*)(analysis_head);
134+
analysis_head = analysis_head + sizeof(Slice);
135+
if (reexport_write_head == NULL)
136+
first_reexport = reexport;
137+
else
138+
reexport_write_head->next = reexport;
139+
reexport_write_head = reexport;
140+
reexport->start = start;
141+
reexport->end = end;
142+
reexport->next = NULL;
143+
}
144+
void _addUnsafeGetter (const uint16_t* start, const uint16_t* end) {
145+
Slice* unsafe_getter = (Slice*)(analysis_head);
146+
analysis_head = analysis_head + sizeof(Slice);
147+
if (unsafe_getter_write_head == NULL)
148+
first_unsafe_getter = unsafe_getter;
149+
else
150+
unsafe_getter_write_head->next = unsafe_getter;
151+
unsafe_getter_write_head = unsafe_getter;
152+
unsafe_getter->start = start;
153+
unsafe_getter->end = end;
154+
unsafe_getter->next = NULL;
155+
}
156+
void _clearReexports () {
157+
reexport_write_head = NULL;
158+
first_reexport = NULL;
159+
}
160+
void (*addExport)(const uint16_t*, const uint16_t*) = &_addExport;
161+
void (*addReexport)(const uint16_t*, const uint16_t*) = &_addReexport;
162+
void (*addUnsafeGetter)(const uint16_t*, const uint16_t*) = &_addUnsafeGetter;
163+
void (*clearReexports)() = &_clearReexports;
164+
uint32_t parseCJS (uint16_t* source, uint32_t sourceLen, void (*addExport)(const uint16_t* start, const uint16_t* end), void (*addReexport)(const uint16_t* start, const uint16_t* end), void (*addUnsafeGetter)(const uint16_t*, const uint16_t*), void (*clearReexports)());
165+
166+
enum RequireType {
167+
Import,
168+
ExportAssign,
169+
ExportStar
170+
};
171+
172+
void tryBacktrackAddStarExportBinding (uint16_t* pos);
173+
bool tryParseRequire (enum RequireType requireType);
174+
void tryParseLiteralExports ();
175+
bool readExportsOrModuleDotExports (uint16_t ch);
176+
void tryParseModuleExportsDotAssign ();
177+
void tryParseExportsDotAssign (bool assign);
178+
void tryParseObjectDefineOrKeys (bool keys);
179+
bool identifier (uint16_t ch);
180+
181+
void throwIfImportStatement ();
182+
void throwIfExportStatement ();
183+
184+
void readImportString (const uint16_t* ss, uint16_t ch);
185+
uint16_t readExportAs (uint16_t* startPos, uint16_t* endPos);
186+
187+
uint16_t commentWhitespace ();
188+
void stringLiteral (uint16_t quote);
189+
void regularExpression ();
190+
void templateString ();
191+
void blockComment ();
192+
void lineComment ();
193+
194+
uint16_t readToWsOrPunctuator (uint16_t ch);
195+
196+
uint32_t fullCharCode (uint16_t ch);
197+
uint32_t fullCharCodeAtLast (uint16_t* pos);
198+
bool isIdentifierStart (uint32_t code);
199+
bool isIdentifierChar (uint32_t code);
200+
int charCodeByteLen (uint32_t ch);
201+
202+
bool isBr (uint16_t c);
203+
bool isBrOrWs (uint16_t c);
204+
bool isBrOrWsOrPunctuator (uint16_t c);
205+
bool isBrOrWsOrPunctuatorNotDot (uint16_t c);
206+
207+
bool str_eq2 (uint16_t* pos, uint16_t c1, uint16_t c2);
208+
bool str_eq3 (uint16_t* pos, uint16_t c1, uint16_t c2, uint16_t c3);
209+
bool str_eq4 (uint16_t* pos, uint16_t c1, uint16_t c2, uint16_t c3, uint16_t c4);
210+
bool str_eq5 (uint16_t* pos, uint16_t c1, uint16_t c2, uint16_t c3, uint16_t c4, uint16_t c5);
211+
bool str_eq6 (uint16_t* pos, uint16_t c1, uint16_t c2, uint16_t c3, uint16_t c4, uint16_t c5, uint16_t c6);
212+
bool str_eq7 (uint16_t* pos, uint16_t c1, uint16_t c2, uint16_t c3, uint16_t c4, uint16_t c5, uint16_t c6, uint16_t c7);
213+
bool str_eq8 (uint16_t* pos, uint16_t c1, uint16_t c2, uint16_t c3, uint16_t c4, uint16_t c5, uint16_t c6, uint16_t c7, uint16_t c8);
214+
bool str_eq9 (uint16_t* pos, uint16_t c1, uint16_t c2, uint16_t c3, uint16_t c4, uint16_t c5, uint16_t c6, uint16_t c7, uint16_t c8, uint16_t c9);
215+
bool str_eq10 (uint16_t* pos, uint16_t c1, uint16_t c2, uint16_t c3, uint16_t c4, uint16_t c5, uint16_t c6, uint16_t c7, uint16_t c8, uint16_t c9, uint16_t c10);
216+
bool str_eq13 (uint16_t* pos, uint16_t c1, uint16_t c2, uint16_t c3, uint16_t c4, uint16_t c5, uint16_t c6, uint16_t c7, uint16_t c8, uint16_t c9, uint16_t c10, uint16_t c11, uint16_t c12, uint16_t c13);
217+
bool str_eq18 (uint16_t* pos, uint16_t c1, uint16_t c2, uint16_t c3, uint16_t c4, uint16_t c5, uint16_t c6, uint16_t c7, uint16_t c8, uint16_t c9, uint16_t c10, uint16_t c11, uint16_t c12, uint16_t c13, uint16_t c14, uint16_t c15, uint16_t c16, uint16_t c17, uint16_t c18);
218+
bool str_eq22 (uint16_t* pos, uint16_t c1, uint16_t c2, uint16_t c3, uint16_t c4, uint16_t c5, uint16_t c6, uint16_t c7, uint16_t c8, uint16_t c9, uint16_t c10, uint16_t c11, uint16_t c12, uint16_t c13, uint16_t c14, uint16_t c15, uint16_t c16, uint16_t c17, uint16_t c18, uint16_t c19, uint16_t c20, uint16_t c21, uint16_t c22);
219+
220+
bool readPrecedingKeyword2(uint16_t* pos, uint16_t c1, uint16_t c2);
221+
bool readPrecedingKeyword3(uint16_t* pos, uint16_t c1, uint16_t c2, uint16_t c3);
222+
bool readPrecedingKeyword4(uint16_t* pos, uint16_t c1, uint16_t c2, uint16_t c3, uint16_t c4);
223+
bool readPrecedingKeyword5(uint16_t* pos, uint16_t c1, uint16_t c2, uint16_t c3, uint16_t c4, uint16_t c5);
224+
bool readPrecedingKeyword6(uint16_t* pos, uint16_t c1, uint16_t c2, uint16_t c3, uint16_t c4, uint16_t c5, uint16_t c6);
225+
bool readPrecedingKeyword7(uint16_t* pos, uint16_t c1, uint16_t c2, uint16_t c3, uint16_t c4, uint16_t c5, uint16_t c6, uint16_t c7);
226+
227+
bool keywordStart (uint16_t* pos);
228+
bool isExpressionKeyword (uint16_t* pos);
229+
bool isParenKeyword (uint16_t* pos);
230+
bool isPunctuator (uint16_t charCode);
231+
bool isExpressionPunctuator (uint16_t charCode);
232+
bool isExpressionTerminator (uint16_t* pos);
233+
234+
void nextChar (uint16_t ch);
235+
void nextCharSurrogate (uint16_t ch);
236+
uint16_t readChar ();
237+
238+
void syntaxError (uint32_t code);

‎deps/cjs-module-lexer/src/lexer.d.mts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './lexer.js'
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
export interface Exports {
2-
exports: string[];
3-
reexports: string[];
4-
}
5-
6-
export declare function parse(source: string, name?: string): Exports;
7-
export declare function init(): Promise<void>;
8-
export declare function initSync(): void;
1+
export interface Exports {
2+
exports: string[];
3+
reexports: string[];
4+
}
5+
6+
export declare function parse(source: string, name?: string): Exports;
7+
export declare function init(): Promise<void>;
8+
export declare function initSync(): void;

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

+1,443
Large diffs are not rendered by default.
21.6 KB
Binary file not shown.

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

+1,901
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
1-
{
2-
"name": "cjs-module-lexer",
3-
"version": "1.4.1",
4-
"description": "Lexes CommonJS modules, returning their named exports metadata",
5-
"main": "lexer.js",
6-
"exports": {
7-
"import": {
8-
"types": "./lexer.d.mts",
9-
"default": "./dist/lexer.mjs"
10-
},
11-
"default": "./lexer.js"
12-
},
13-
"types": "lexer.d.ts",
14-
"scripts": {
15-
"test-js": "mocha -b -u tdd test/*.js",
16-
"test-wasm": "cross-env WASM=1 mocha -b -u tdd test/*.js",
17-
"test-wasm-sync": "cross-env WASM_SYNC=1 mocha -b -u tdd test/*.js",
18-
"test": "npm run test-wasm ; npm run test-wasm-sync ; npm run test-js",
19-
"bench": "node --expose-gc bench/index.mjs",
20-
"build": "node build.js ; babel dist/lexer.mjs -o dist/lexer.js ; terser dist/lexer.js -o dist/lexer.js",
21-
"build-wasm": "make lib/lexer.wasm ; node build.js",
22-
"prepublishOnly": "make && npm run build",
23-
"footprint": "npm run build && cat dist/lexer.js | gzip -9f | wc -c"
24-
},
25-
"author": "Guy Bedford",
26-
"license": "MIT",
27-
"devDependencies": {
28-
"@babel/cli": "^7.5.5",
29-
"@babel/core": "^7.5.5",
30-
"@babel/plugin-transform-modules-commonjs": "^7.5.0",
31-
"cross-env": "^7.0.3",
32-
"kleur": "^2.0.2",
33-
"mocha": "^9.1.3",
34-
"terser": "^4.1.4"
35-
},
36-
"files": [
37-
"dist",
38-
"lexer.d.ts"
39-
],
40-
"repository": {
41-
"type": "git",
42-
"url": "git+https://github.com/nodejs/cjs-module-lexer.git"
43-
},
44-
"bugs": {
45-
"url": "https://github.com/nodejs/cjs-module-lexer/issues"
46-
},
47-
"homepage": "https://github.com/nodejs/cjs-module-lexer#readme"
48-
}
1+
{
2+
"name": "cjs-module-lexer",
3+
"version": "2.0.0",
4+
"description": "Lexes CommonJS modules, returning their named exports metadata",
5+
"main": "lexer.js",
6+
"exports": {
7+
"import": {
8+
"types": "./lexer.d.mts",
9+
"default": "./dist/lexer.mjs"
10+
},
11+
"default": "./lexer.js"
12+
},
13+
"types": "lexer.d.ts",
14+
"scripts": {
15+
"test-js": "mocha -b -u tdd test/*.js",
16+
"test-wasm": "cross-env WASM=1 mocha -b -u tdd test/*.js",
17+
"test-wasm-sync": "cross-env WASM_SYNC=1 mocha -b -u tdd test/*.js",
18+
"test": "npm run test-wasm ; npm run test-wasm-sync ; npm run test-js",
19+
"bench": "node --expose-gc bench/index.mjs",
20+
"build": "node build.js ; babel dist/lexer.mjs -o dist/lexer.js ; terser dist/lexer.js -o dist/lexer.js",
21+
"build-wasm": "make lib/lexer.wasm ; node build.js",
22+
"prepublishOnly": "make && npm run build",
23+
"footprint": "npm run build && cat dist/lexer.js | gzip -9f | wc -c"
24+
},
25+
"author": "Guy Bedford",
26+
"license": "MIT",
27+
"devDependencies": {
28+
"@babel/cli": "^7.5.5",
29+
"@babel/core": "^7.5.5",
30+
"@babel/plugin-transform-modules-commonjs": "^7.5.0",
31+
"cross-env": "^7.0.3",
32+
"kleur": "^2.0.2",
33+
"mocha": "^9.1.3",
34+
"terser": "^4.1.4"
35+
},
36+
"files": [
37+
"dist",
38+
"lexer.d.ts"
39+
],
40+
"repository": {
41+
"type": "git",
42+
"url": "git+https://github.com/nodejs/cjs-module-lexer.git"
43+
},
44+
"bugs": {
45+
"url": "https://github.com/nodejs/cjs-module-lexer/issues"
46+
},
47+
"homepage": "https://github.com/nodejs/cjs-module-lexer#readme"
48+
}

‎deps/cjs-module-lexer/src/src/lexer.c

+1,516
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,119 @@
1-
let wasm;
2-
3-
const isLE = new Uint8Array(new Uint16Array([1]).buffer)[0] === 1;
4-
5-
export function parse (source, name = '@') {
6-
if (!wasm)
7-
throw new Error('Not initialized');
8-
9-
const len = source.length + 1;
10-
11-
// need 2 bytes per code point plus analysis space so we double again
12-
const extraMem = (wasm.__heap_base.value || wasm.__heap_base) + len * 4 - wasm.memory.buffer.byteLength;
13-
if (extraMem > 0)
14-
wasm.memory.grow(Math.ceil(extraMem / 65536));
15-
16-
const addr = wasm.sa(len);
17-
(isLE ? copyLE : copyBE)(source, new Uint16Array(wasm.memory.buffer, addr, len));
18-
19-
const err_code = wasm.parseCJS(addr, source.length, 0, 0, 0);
20-
21-
if (err_code) {
22-
const err = new Error(`Parse error ${name}${wasm.e()}:${source.slice(0, wasm.e()).split('\n').length}:${wasm.e() - source.lastIndexOf('\n', wasm.e() - 1)}`);
23-
Object.assign(err, { idx: wasm.e() });
24-
if (err_code === 5 || err_code === 6 || err_code === 7)
25-
Object.assign(err, { code: 'ERR_LEXER_ESM_SYNTAX' });
26-
throw err;
27-
}
28-
29-
let exports = new Set(), reexports = new Set(), unsafeGetters = new Set();
30-
31-
while (wasm.rre()) {
32-
const reexptStr = decode(source.slice(wasm.res(), wasm.ree()));
33-
if (reexptStr)
34-
reexports.add(reexptStr);
35-
}
36-
while (wasm.ru())
37-
unsafeGetters.add(decode(source.slice(wasm.us(), wasm.ue())));
38-
while (wasm.re()) {
39-
let exptStr = decode(source.slice(wasm.es(), wasm.ee()));
40-
if (exptStr !== undefined && !unsafeGetters.has(exptStr))
41-
exports.add(exptStr);
42-
}
43-
44-
return { exports: [...exports], reexports: [...reexports] };
45-
}
46-
47-
function decode (str) {
48-
if (str[0] === '"' || str[0] === '\'') {
49-
try {
50-
const decoded = (0, eval)(str);
51-
// Filter to exclude non-matching UTF-16 surrogate strings
52-
for (let i = 0; i < decoded.length; i++) {
53-
const surrogatePrefix = decoded.charCodeAt(i) & 0xFC00;
54-
if (surrogatePrefix < 0xD800) {
55-
// Not a surrogate
56-
continue;
57-
}
58-
else if (surrogatePrefix === 0xD800) {
59-
// Validate surrogate pair
60-
if ((decoded.charCodeAt(++i) & 0xFC00) !== 0xDC00)
61-
return;
62-
}
63-
else {
64-
// Out-of-range surrogate code (above 0xD800)
65-
return;
66-
}
67-
}
68-
return decoded;
69-
}
70-
catch {}
71-
}
72-
else {
73-
return str;
74-
}
75-
}
76-
77-
function copyBE (src, outBuf16) {
78-
const len = src.length;
79-
let i = 0;
80-
while (i < len) {
81-
const ch = src.charCodeAt(i);
82-
outBuf16[i++] = (ch & 0xff) << 8 | ch >>> 8;
83-
}
84-
}
85-
86-
function copyLE (src, outBuf16) {
87-
const len = src.length;
88-
let i = 0;
89-
while (i < len)
90-
outBuf16[i] = src.charCodeAt(i++);
91-
}
92-
93-
let initPromise;
94-
export function init () {
95-
if (initPromise)
96-
return initPromise;
97-
return initPromise = (async () => {
98-
const compiled = await WebAssembly.compile(
99-
(await import('node:fs')).readFileSync(new URL(import.meta.resolve('../lib/lexer.wasm')))
100-
);
101-
const { exports } = await WebAssembly.instantiate(compiled);
102-
wasm = exports;
103-
})();
104-
}
1+
let wasm;
2+
3+
const isLE = new Uint8Array(new Uint16Array([1]).buffer)[0] === 1;
4+
5+
export function parse (source, name = '@') {
6+
if (!wasm)
7+
throw new Error('Not initialized');
8+
9+
const len = source.length + 1;
10+
11+
// need 2 bytes per code point plus analysis space so we double again
12+
const extraMem = (wasm.__heap_base.value || wasm.__heap_base) + len * 4 - wasm.memory.buffer.byteLength;
13+
if (extraMem > 0)
14+
wasm.memory.grow(Math.ceil(extraMem / 65536));
15+
16+
const addr = wasm.sa(len);
17+
(isLE ? copyLE : copyBE)(source, new Uint16Array(wasm.memory.buffer, addr, len));
18+
19+
const err_code = wasm.parseCJS(addr, source.length, 0, 0, 0);
20+
21+
if (err_code) {
22+
const err = new Error(`Parse error ${name}${wasm.e()}:${source.slice(0, wasm.e()).split('\n').length}:${wasm.e() - source.lastIndexOf('\n', wasm.e() - 1)}`);
23+
Object.assign(err, { idx: wasm.e() });
24+
if (err_code === 5 || err_code === 6 || err_code === 7)
25+
Object.assign(err, { code: 'ERR_LEXER_ESM_SYNTAX' });
26+
throw err;
27+
}
28+
29+
let exports = new Set(), reexports = new Set(), unsafeGetters = new Set();
30+
31+
while (wasm.rre()) {
32+
const reexptStr = decode(source.slice(wasm.res(), wasm.ree()));
33+
if (reexptStr)
34+
reexports.add(reexptStr);
35+
}
36+
while (wasm.ru())
37+
unsafeGetters.add(decode(source.slice(wasm.us(), wasm.ue())));
38+
while (wasm.re()) {
39+
let exptStr = decode(source.slice(wasm.es(), wasm.ee()));
40+
if (exptStr !== undefined && !unsafeGetters.has(exptStr))
41+
exports.add(exptStr);
42+
}
43+
44+
return { exports: [...exports], reexports: [...reexports] };
45+
}
46+
47+
function decode (str) {
48+
if (str[0] === '"' || str[0] === '\'') {
49+
try {
50+
const decoded = (0, eval)(str);
51+
// Filter to exclude non-matching UTF-16 surrogate strings
52+
for (let i = 0; i < decoded.length; i++) {
53+
const surrogatePrefix = decoded.charCodeAt(i) & 0xFC00;
54+
if (surrogatePrefix < 0xD800) {
55+
// Not a surrogate
56+
continue;
57+
}
58+
else if (surrogatePrefix === 0xD800) {
59+
// Validate surrogate pair
60+
if ((decoded.charCodeAt(++i) & 0xFC00) !== 0xDC00)
61+
return;
62+
}
63+
else {
64+
// Out-of-range surrogate code (above 0xD800)
65+
return;
66+
}
67+
}
68+
return decoded;
69+
}
70+
catch {}
71+
}
72+
else {
73+
return str;
74+
}
75+
}
76+
77+
function copyBE (src, outBuf16) {
78+
const len = src.length;
79+
let i = 0;
80+
while (i < len) {
81+
const ch = src.charCodeAt(i);
82+
outBuf16[i++] = (ch & 0xff) << 8 | ch >>> 8;
83+
}
84+
}
85+
86+
function copyLE (src, outBuf16) {
87+
const len = src.length;
88+
let i = 0;
89+
while (i < len)
90+
outBuf16[i] = src.charCodeAt(i++);
91+
}
92+
93+
function getWasmBytes() {
94+
const binary = 'WASM_BINARY'; // This string will be replaced by build.js.
95+
if (typeof Buffer !== 'undefined')
96+
return Buffer.from(binary, 'base64');
97+
return Uint8Array.from(atob(binary), x => x.charCodeAt(0));
98+
}
99+
100+
let initPromise;
101+
export function init () {
102+
if (initPromise)
103+
return initPromise;
104+
return initPromise = (async () => {
105+
const compiled = await WebAssembly.compile(getWasmBytes());
106+
const { exports } = await WebAssembly.instantiate(compiled);
107+
wasm = exports;
108+
})();
109+
}
110+
111+
export function initSync () {
112+
if (wasm) {
113+
return;
114+
}
115+
const compiled = new WebAssembly.Module(getWasmBytes());
116+
const { exports } = new WebAssembly.Instance(compiled);
117+
wasm = exports;
118+
return;
119+
}

‎doc/api/esm.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ resolution for ESM specifiers is [commonjs-extension-resolution-loader][].
11381138
[`process.dlopen`]: process.md#processdlopenmodule-filename-flags
11391139
[`require(esm)`]: modules.md#loading-ecmascript-modules-using-require
11401140
[`url.fileURLToPath()`]: url.md#urlfileurltopathurl-options
1141-
[cjs-module-lexer]: https://github.com/nodejs/cjs-module-lexer/tree/1.2.2
1141+
[cjs-module-lexer]: https://github.com/nodejs/cjs-module-lexer/tree/2.0.0
11421142
[commonjs-extension-resolution-loader]: https://github.com/nodejs/loaders-test/tree/main/commonjs-extension-resolution-loader
11431143
[custom https loader]: module.md#import-from-https
11441144
[import.meta.resolve]: #importmetaresolvespecifier

‎src/cjs_module_lexer_version.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
// Refer to tools/dep_updaters/update-cjs-module-lexer.sh
33
#ifndef SRC_CJS_MODULE_LEXER_VERSION_H_
44
#define SRC_CJS_MODULE_LEXER_VERSION_H_
5-
#define CJS_MODULE_LEXER_VERSION "1.4.1"
5+
#define CJS_MODULE_LEXER_VERSION "2.0.0"
66
#endif // SRC_CJS_MODULE_LEXER_VERSION_H_

‎test/parallel/test-process-versions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const assert = require('assert');
44

55
// Import of pure js (non-shared) deps for comparison
66
const acorn = require('../../deps/acorn/acorn/package.json');
7-
const cjs_module_lexer = require('../../deps/cjs-module-lexer/package.json');
7+
const cjs_module_lexer = require('../../deps/cjs-module-lexer/src/package.json');
88

99
const expected_keys = [
1010
'ares',

‎tools/dep_updaters/update-cjs-module-lexer.sh

+46-7
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ console.log(name);
2727
EOF
2828
)"
2929

30-
CURRENT_VERSION=$("$NODE" -p "require('./deps/cjs-module-lexer/package.json').version")
30+
31+
CURRENT_VERSION=$("$NODE" -p "require('./deps/cjs-module-lexer/src/package.json').version")
3132

3233
# This function exit with 0 if new version and current version are the same
3334
compare_dependency_version "cjs-module-lexer" "$NEW_VERSION" "$CURRENT_VERSION"
@@ -44,15 +45,53 @@ cleanup () {
4445

4546
trap cleanup INT TERM EXIT
4647

47-
cd "$WORKSPACE"
48-
49-
"$NODE" "$NPM" init --yes
48+
CJS_MODULE_LEXER_ZIP="cjs-module-lexer-$NEW_VERSION"
5049

51-
"$NODE" "$NPM" install --global-style --no-bin-links --ignore-scripts "cjs-module-lexer@$NEW_VERSION"
50+
# remove existing source and built files
51+
rm -rf "$DEPS_DIR/cjs-module-lexer/src"
52+
rm -rf "$DEPS_DIR/cjs-module-lexer/dist"
53+
rm "$DEPS_DIR/cjs-module-lexer/lexer.js"
5254

53-
rm -rf "$DEPS_DIR/cjs-module-lexer"
55+
cd "$WORKSPACE"
5456

55-
mv node_modules/cjs-module-lexer "$DEPS_DIR/cjs-module-lexer"
57+
curl -sL -o "$CJS_MODULE_LEXER_ZIP.zip" "https://github.com/nodejs/cjs-module-lexer/archive/refs/tags/$NEW_VERSION.zip"
58+
59+
log_and_verify_sha256sum "cjs-module-lexer" "$CJS_MODULE_LEXER_ZIP.zip"
60+
61+
echo "Unzipping..."
62+
unzip "$CJS_MODULE_LEXER_ZIP.zip" -d "src"
63+
mv "src/$CJS_MODULE_LEXER_ZIP" "$DEPS_DIR/cjs-module-lexer/src"
64+
rm "$CJS_MODULE_LEXER_ZIP.zip"
65+
cd "$ROOT"
66+
67+
(
68+
# remove components we don't need to keep in nodejs/deps
69+
# these are files that we don't need to build from source
70+
cd "$DEPS_DIR/cjs-module-lexer/src"
71+
rm -rf bench
72+
rm -rf .github || true
73+
rm -rf test
74+
rm .gitignore
75+
rm .travis.yml
76+
rm CODE_OF_CONDUCT.md
77+
rm CONTRIBUTING.md
78+
79+
# Rebuild components from source
80+
rm lib/*.*
81+
"$NODE" "$NPM" install --ignore-scripts
82+
"$NODE" "$NPM" run build-wasm
83+
"$NODE" "$NPM" run build
84+
"$NODE" "$NPM" prune --production
85+
86+
# remove files we don't need in Node.js
87+
rm -rf node_modules
88+
89+
# copy over the built files to the expected locations
90+
mv dist ..
91+
cp lexer.js ..
92+
cp LICENSE ..
93+
cp README.md ..
94+
)
5695

5796
# update cjs_module_lexer_version.h
5897
cat > "$BASE_DIR/src/cjs_module_lexer_version.h" << EOL

0 commit comments

Comments
 (0)
Please sign in to comment.