@esm.sh/cjs-module-lexer 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +4 -4
- package/package.json +2 -2
- package/pkg/cjs_module_lexer.js +52 -79
- package/pkg/cjs_module_lexer_bg.wasm +0 -0
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
#
|
|
1
|
+
# cjs-module-lexer
|
|
2
2
|
|
|
3
|
-
A lexer for detecting the `module.exports` of a CJS module, written in Rust
|
|
3
|
+
A lexer for detecting the `module.exports` of a CJS module, written in Rust.
|
|
4
4
|
|
|
5
5
|
## Usage
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
cjs-module-lexer currently only supports Node.js environment. You can install it via npm CLI:
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
10
|
npm i @esm.sh/cjs-module-lexer
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
cjs-module-lexer provides a `parse` function that detects the `module.exports` of a commonjs module. The function returns an object with two properties: `exports` and `reexports`. The `exports` property is an array of the exported names, and the `reexports` property is an array of the reexported modules.
|
|
14
14
|
|
|
15
15
|
```js
|
|
16
16
|
const { parse } = require("@esm.sh/cjs-module-lexer");
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@esm.sh/cjs-module-lexer",
|
|
3
|
-
"description": "A
|
|
4
|
-
"version": "1.0.
|
|
3
|
+
"description": "A lexer for detecting the `module.exports` of a CJS module.",
|
|
4
|
+
"version": "1.0.1",
|
|
5
5
|
"main": "pkg/cjs_module_lexer.js",
|
|
6
6
|
"types": "pkg/cjs_module_lexer.d.ts",
|
|
7
7
|
"scripts": {
|
package/pkg/cjs_module_lexer.js
CHANGED
|
@@ -4,26 +4,6 @@ imports['__wbindgen_placeholder__'] = module.exports;
|
|
|
4
4
|
let wasm;
|
|
5
5
|
const { TextEncoder, TextDecoder } = require(`util`);
|
|
6
6
|
|
|
7
|
-
const heap = new Array(128).fill(undefined);
|
|
8
|
-
|
|
9
|
-
heap.push(undefined, null, true, false);
|
|
10
|
-
|
|
11
|
-
function getObject(idx) { return heap[idx]; }
|
|
12
|
-
|
|
13
|
-
let heap_next = heap.length;
|
|
14
|
-
|
|
15
|
-
function dropObject(idx) {
|
|
16
|
-
if (idx < 132) return;
|
|
17
|
-
heap[idx] = heap_next;
|
|
18
|
-
heap_next = idx;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function takeObject(idx) {
|
|
22
|
-
const ret = getObject(idx);
|
|
23
|
-
dropObject(idx);
|
|
24
|
-
return ret;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
7
|
let WASM_VECTOR_LEN = 0;
|
|
28
8
|
|
|
29
9
|
let cachedUint8ArrayMemory0 = null;
|
|
@@ -111,15 +91,6 @@ function getStringFromWasm0(ptr, len) {
|
|
|
111
91
|
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
112
92
|
}
|
|
113
93
|
|
|
114
|
-
function addHeapObject(obj) {
|
|
115
|
-
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
116
|
-
const idx = heap_next;
|
|
117
|
-
heap_next = heap[idx];
|
|
118
|
-
|
|
119
|
-
heap[idx] = obj;
|
|
120
|
-
return idx;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
94
|
function debugString(val) {
|
|
124
95
|
// primitive types
|
|
125
96
|
const type = typeof val;
|
|
@@ -184,6 +155,12 @@ function debugString(val) {
|
|
|
184
155
|
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
185
156
|
return className;
|
|
186
157
|
}
|
|
158
|
+
|
|
159
|
+
function takeFromExternrefTable0(idx) {
|
|
160
|
+
const value = wasm.__wbindgen_export_2.get(idx);
|
|
161
|
+
wasm.__externref_table_dealloc(idx);
|
|
162
|
+
return value;
|
|
163
|
+
}
|
|
187
164
|
/**
|
|
188
165
|
* @param {string} specifier
|
|
189
166
|
* @param {string} code
|
|
@@ -191,47 +168,35 @@ function debugString(val) {
|
|
|
191
168
|
* @returns {any}
|
|
192
169
|
*/
|
|
193
170
|
module.exports.parse = function(specifier, code, options) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
202
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
203
|
-
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
204
|
-
if (r2) {
|
|
205
|
-
throw takeObject(r1);
|
|
206
|
-
}
|
|
207
|
-
return takeObject(r0);
|
|
208
|
-
} finally {
|
|
209
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
171
|
+
const ptr0 = passStringToWasm0(specifier, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
172
|
+
const len0 = WASM_VECTOR_LEN;
|
|
173
|
+
const ptr1 = passStringToWasm0(code, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
174
|
+
const len1 = WASM_VECTOR_LEN;
|
|
175
|
+
const ret = wasm.parse(ptr0, len0, ptr1, len1, options);
|
|
176
|
+
if (ret[2]) {
|
|
177
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
210
178
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
module.exports.__wbindgen_object_drop_ref = function(arg0) {
|
|
214
|
-
takeObject(arg0);
|
|
179
|
+
return takeFromExternrefTable0(ret[0]);
|
|
215
180
|
};
|
|
216
181
|
|
|
217
182
|
module.exports.__wbindgen_is_undefined = function(arg0) {
|
|
218
|
-
const ret =
|
|
183
|
+
const ret = arg0 === undefined;
|
|
219
184
|
return ret;
|
|
220
185
|
};
|
|
221
186
|
|
|
222
187
|
module.exports.__wbindgen_in = function(arg0, arg1) {
|
|
223
|
-
const ret =
|
|
188
|
+
const ret = arg0 in arg1;
|
|
224
189
|
return ret;
|
|
225
190
|
};
|
|
226
191
|
|
|
227
192
|
module.exports.__wbindgen_boolean_get = function(arg0) {
|
|
228
|
-
const v =
|
|
193
|
+
const v = arg0;
|
|
229
194
|
const ret = typeof(v) === 'boolean' ? (v ? 1 : 0) : 2;
|
|
230
195
|
return ret;
|
|
231
196
|
};
|
|
232
197
|
|
|
233
198
|
module.exports.__wbindgen_string_get = function(arg0, arg1) {
|
|
234
|
-
const obj =
|
|
199
|
+
const obj = arg1;
|
|
235
200
|
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
236
201
|
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
237
202
|
var len1 = WASM_VECTOR_LEN;
|
|
@@ -240,28 +205,23 @@ module.exports.__wbindgen_string_get = function(arg0, arg1) {
|
|
|
240
205
|
};
|
|
241
206
|
|
|
242
207
|
module.exports.__wbindgen_is_object = function(arg0) {
|
|
243
|
-
const val =
|
|
208
|
+
const val = arg0;
|
|
244
209
|
const ret = typeof(val) === 'object' && val !== null;
|
|
245
210
|
return ret;
|
|
246
211
|
};
|
|
247
212
|
|
|
248
213
|
module.exports.__wbindgen_error_new = function(arg0, arg1) {
|
|
249
214
|
const ret = new Error(getStringFromWasm0(arg0, arg1));
|
|
250
|
-
return
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
module.exports.__wbindgen_object_clone_ref = function(arg0) {
|
|
254
|
-
const ret = getObject(arg0);
|
|
255
|
-
return addHeapObject(ret);
|
|
215
|
+
return ret;
|
|
256
216
|
};
|
|
257
217
|
|
|
258
218
|
module.exports.__wbindgen_jsval_loose_eq = function(arg0, arg1) {
|
|
259
|
-
const ret =
|
|
219
|
+
const ret = arg0 == arg1;
|
|
260
220
|
return ret;
|
|
261
221
|
};
|
|
262
222
|
|
|
263
223
|
module.exports.__wbindgen_number_get = function(arg0, arg1) {
|
|
264
|
-
const obj =
|
|
224
|
+
const obj = arg1;
|
|
265
225
|
const ret = typeof(obj) === 'number' ? obj : undefined;
|
|
266
226
|
getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
|
|
267
227
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
@@ -269,36 +229,36 @@ module.exports.__wbindgen_number_get = function(arg0, arg1) {
|
|
|
269
229
|
|
|
270
230
|
module.exports.__wbindgen_string_new = function(arg0, arg1) {
|
|
271
231
|
const ret = getStringFromWasm0(arg0, arg1);
|
|
272
|
-
return
|
|
232
|
+
return ret;
|
|
273
233
|
};
|
|
274
234
|
|
|
275
235
|
module.exports.__wbg_getwithrefkey_edc2c8960f0f1191 = function(arg0, arg1) {
|
|
276
|
-
const ret =
|
|
277
|
-
return
|
|
236
|
+
const ret = arg0[arg1];
|
|
237
|
+
return ret;
|
|
278
238
|
};
|
|
279
239
|
|
|
280
240
|
module.exports.__wbg_set_f975102236d3c502 = function(arg0, arg1, arg2) {
|
|
281
|
-
|
|
241
|
+
arg0[arg1] = arg2;
|
|
282
242
|
};
|
|
283
243
|
|
|
284
244
|
module.exports.__wbg_new_16b304a2cfa7ff4a = function() {
|
|
285
245
|
const ret = new Array();
|
|
286
|
-
return
|
|
246
|
+
return ret;
|
|
287
247
|
};
|
|
288
248
|
|
|
289
249
|
module.exports.__wbg_new_72fb9a18b5ae2624 = function() {
|
|
290
250
|
const ret = new Object();
|
|
291
|
-
return
|
|
251
|
+
return ret;
|
|
292
252
|
};
|
|
293
253
|
|
|
294
254
|
module.exports.__wbg_set_d4638f722068f043 = function(arg0, arg1, arg2) {
|
|
295
|
-
|
|
255
|
+
arg0[arg1 >>> 0] = arg2;
|
|
296
256
|
};
|
|
297
257
|
|
|
298
258
|
module.exports.__wbg_instanceof_ArrayBuffer_836825be07d4c9d2 = function(arg0) {
|
|
299
259
|
let result;
|
|
300
260
|
try {
|
|
301
|
-
result =
|
|
261
|
+
result = arg0 instanceof ArrayBuffer;
|
|
302
262
|
} catch (_) {
|
|
303
263
|
result = false;
|
|
304
264
|
}
|
|
@@ -307,19 +267,19 @@ module.exports.__wbg_instanceof_ArrayBuffer_836825be07d4c9d2 = function(arg0) {
|
|
|
307
267
|
};
|
|
308
268
|
|
|
309
269
|
module.exports.__wbg_buffer_12d079cc21e14bdb = function(arg0) {
|
|
310
|
-
const ret =
|
|
311
|
-
return
|
|
270
|
+
const ret = arg0.buffer;
|
|
271
|
+
return ret;
|
|
312
272
|
};
|
|
313
273
|
|
|
314
274
|
module.exports.__wbg_new_63b92bc8671ed464 = function(arg0) {
|
|
315
|
-
const ret = new Uint8Array(
|
|
316
|
-
return
|
|
275
|
+
const ret = new Uint8Array(arg0);
|
|
276
|
+
return ret;
|
|
317
277
|
};
|
|
318
278
|
|
|
319
279
|
module.exports.__wbg_instanceof_Uint8Array_2b3bbecd033d19f6 = function(arg0) {
|
|
320
280
|
let result;
|
|
321
281
|
try {
|
|
322
|
-
result =
|
|
282
|
+
result = arg0 instanceof Uint8Array;
|
|
323
283
|
} catch (_) {
|
|
324
284
|
result = false;
|
|
325
285
|
}
|
|
@@ -328,16 +288,16 @@ module.exports.__wbg_instanceof_Uint8Array_2b3bbecd033d19f6 = function(arg0) {
|
|
|
328
288
|
};
|
|
329
289
|
|
|
330
290
|
module.exports.__wbg_length_c20a40f15020d68a = function(arg0) {
|
|
331
|
-
const ret =
|
|
291
|
+
const ret = arg0.length;
|
|
332
292
|
return ret;
|
|
333
293
|
};
|
|
334
294
|
|
|
335
295
|
module.exports.__wbg_set_a47bac70306a19a7 = function(arg0, arg1, arg2) {
|
|
336
|
-
|
|
296
|
+
arg0.set(arg1, arg2 >>> 0);
|
|
337
297
|
};
|
|
338
298
|
|
|
339
299
|
module.exports.__wbindgen_debug_string = function(arg0, arg1) {
|
|
340
|
-
const ret = debugString(
|
|
300
|
+
const ret = debugString(arg1);
|
|
341
301
|
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
342
302
|
const len1 = WASM_VECTOR_LEN;
|
|
343
303
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
@@ -350,7 +310,18 @@ module.exports.__wbindgen_throw = function(arg0, arg1) {
|
|
|
350
310
|
|
|
351
311
|
module.exports.__wbindgen_memory = function() {
|
|
352
312
|
const ret = wasm.memory;
|
|
353
|
-
return
|
|
313
|
+
return ret;
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
module.exports.__wbindgen_init_externref_table = function() {
|
|
317
|
+
const table = wasm.__wbindgen_export_2;
|
|
318
|
+
const offset = table.grow(4);
|
|
319
|
+
table.set(0, undefined);
|
|
320
|
+
table.set(offset + 0, undefined);
|
|
321
|
+
table.set(offset + 1, null);
|
|
322
|
+
table.set(offset + 2, true);
|
|
323
|
+
table.set(offset + 3, false);
|
|
324
|
+
;
|
|
354
325
|
};
|
|
355
326
|
|
|
356
327
|
const path = require('path').join(__dirname, 'cjs_module_lexer_bg.wasm');
|
|
@@ -361,3 +332,5 @@ const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
|
|
|
361
332
|
wasm = wasmInstance.exports;
|
|
362
333
|
module.exports.__wasm = wasm;
|
|
363
334
|
|
|
335
|
+
wasm.__wbindgen_start();
|
|
336
|
+
|
|
Binary file
|