@esm.sh/cjs-module-lexer 1.0.1 → 1.0.2
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/README.md +5 -19
- package/index.mjs +35 -0
- package/package.json +8 -7
- package/pkg/cjs-module-lexer.js +406 -0
- package/pkg/cjs-module-lexer_bg.wasm +0 -0
- package/LICENSE +0 -21
- package/pkg/cjs_module_lexer.d.ts +0 -9
- package/pkg/cjs_module_lexer.js +0 -336
- package/pkg/cjs_module_lexer_bg.wasm +0 -0
package/README.md
CHANGED
|
@@ -2,18 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
A lexer for detecting the `module.exports` of a CJS module, written in Rust.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Installation
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
You can install cjs-module-lexer via npm CLI:
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
10
|
npm i @esm.sh/cjs-module-lexer
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
13
15
|
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
16
|
|
|
15
17
|
```js
|
|
16
|
-
|
|
18
|
+
import { parse } from "@esm.sh/cjs-module-lexer";
|
|
17
19
|
|
|
18
20
|
// named exports by assignment
|
|
19
21
|
// exports: ["a", "b", "c", "__esModule", "foo"]
|
|
@@ -144,19 +146,3 @@ export function parse(
|
|
|
144
146
|
reexports: string[],
|
|
145
147
|
};
|
|
146
148
|
```
|
|
147
|
-
|
|
148
|
-
## Development Setup
|
|
149
|
-
|
|
150
|
-
You will need [rust](https://www.rust-lang.org/tools/install) 1.56+ and [wasm-pack](https://rustwasm.github.io/wasm-pack/installer/).
|
|
151
|
-
|
|
152
|
-
## Build
|
|
153
|
-
|
|
154
|
-
```bash
|
|
155
|
-
wasm-pack build --target nodejs
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
## Run tests
|
|
159
|
-
|
|
160
|
-
```bash
|
|
161
|
-
cargo test --all
|
|
162
|
-
```
|
package/index.mjs
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { initSync, parse as __wbg_parse } from "./pkg/cjs-module-lexer.js";
|
|
2
|
+
const wasmPath = "./pkg/cjs-module-lexer_bg.wasm";
|
|
3
|
+
|
|
4
|
+
let wasm;
|
|
5
|
+
if (globalThis.process || globalThis.Deno || globalThis.Bun) {
|
|
6
|
+
const { readFileSync } = await import("node:fs");
|
|
7
|
+
const url = new URL(wasmPath, import.meta.url);
|
|
8
|
+
const wasmData = readFileSync(url.pathname);
|
|
9
|
+
wasm = await WebAssembly.compile(wasmData);
|
|
10
|
+
} else {
|
|
11
|
+
const url = new URL(wasmPath, import.meta.url);
|
|
12
|
+
const pkgPrefix = "/@esm.sh/cjs-module-lexer@";
|
|
13
|
+
if (url.pathname.startsWith(pkgPrefix)) {
|
|
14
|
+
const version = url.pathname.slice(pkgPrefix.length).split("/", 1)[0];
|
|
15
|
+
url.pathname = pkgPrefix + version + wasmPath.slice(1);
|
|
16
|
+
}
|
|
17
|
+
const res = await fetch(url);
|
|
18
|
+
if (!res.ok) {
|
|
19
|
+
throw new Error(`failed to fetch wasm: ${res.statusText}`);
|
|
20
|
+
}
|
|
21
|
+
wasm = await WebAssembly.compileStreaming(res);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
initSync({ module: wasm });
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* parse the given code and return the exports and reexports
|
|
28
|
+
* @param {string} filename
|
|
29
|
+
* @param {string} code
|
|
30
|
+
* @param {{ nodeEnv?: 'development' | 'production', callMode?: boolean }} options
|
|
31
|
+
* @returns {{ exports: string[], reexports: string[] }}
|
|
32
|
+
*/
|
|
33
|
+
export function parse(filename, code, options = {}) {
|
|
34
|
+
return __wbg_parse(filename, code, options);
|
|
35
|
+
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@esm.sh/cjs-module-lexer",
|
|
3
3
|
"description": "A lexer for detecting the `module.exports` of a CJS module.",
|
|
4
|
-
"version": "1.0.
|
|
5
|
-
"
|
|
6
|
-
"
|
|
4
|
+
"version": "1.0.2",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.mjs",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"prepublishOnly": "wasm-pack build --target
|
|
8
|
+
"prepublishOnly": "wasm-pack build --target web --out-name cjs-module-lexer",
|
|
9
|
+
"test": "node test.mjs"
|
|
9
10
|
},
|
|
10
11
|
"files": [
|
|
11
|
-
"
|
|
12
|
-
"pkg/
|
|
13
|
-
"pkg/
|
|
12
|
+
"./index.mjs",
|
|
13
|
+
"./pkg/cjs-module-lexer_bg.wasm",
|
|
14
|
+
"./pkg/cjs-module-lexer.js"
|
|
14
15
|
],
|
|
15
16
|
"repository": {
|
|
16
17
|
"type": "git",
|
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
let wasm;
|
|
2
|
+
|
|
3
|
+
function debugString(val) {
|
|
4
|
+
// primitive types
|
|
5
|
+
const type = typeof val;
|
|
6
|
+
if (type == 'number' || type == 'boolean' || val == null) {
|
|
7
|
+
return `${val}`;
|
|
8
|
+
}
|
|
9
|
+
if (type == 'string') {
|
|
10
|
+
return `"${val}"`;
|
|
11
|
+
}
|
|
12
|
+
if (type == 'symbol') {
|
|
13
|
+
const description = val.description;
|
|
14
|
+
if (description == null) {
|
|
15
|
+
return 'Symbol';
|
|
16
|
+
} else {
|
|
17
|
+
return `Symbol(${description})`;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (type == 'function') {
|
|
21
|
+
const name = val.name;
|
|
22
|
+
if (typeof name == 'string' && name.length > 0) {
|
|
23
|
+
return `Function(${name})`;
|
|
24
|
+
} else {
|
|
25
|
+
return 'Function';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
// objects
|
|
29
|
+
if (Array.isArray(val)) {
|
|
30
|
+
const length = val.length;
|
|
31
|
+
let debug = '[';
|
|
32
|
+
if (length > 0) {
|
|
33
|
+
debug += debugString(val[0]);
|
|
34
|
+
}
|
|
35
|
+
for(let i = 1; i < length; i++) {
|
|
36
|
+
debug += ', ' + debugString(val[i]);
|
|
37
|
+
}
|
|
38
|
+
debug += ']';
|
|
39
|
+
return debug;
|
|
40
|
+
}
|
|
41
|
+
// Test for built-in
|
|
42
|
+
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
|
43
|
+
let className;
|
|
44
|
+
if (builtInMatches && builtInMatches.length > 1) {
|
|
45
|
+
className = builtInMatches[1];
|
|
46
|
+
} else {
|
|
47
|
+
// Failed to match the standard '[object ClassName]'
|
|
48
|
+
return toString.call(val);
|
|
49
|
+
}
|
|
50
|
+
if (className == 'Object') {
|
|
51
|
+
// we're a user defined class or Object
|
|
52
|
+
// JSON.stringify avoids problems with cycles, and is generally much
|
|
53
|
+
// easier than looping through ownProperties of `val`.
|
|
54
|
+
try {
|
|
55
|
+
return 'Object(' + JSON.stringify(val) + ')';
|
|
56
|
+
} catch (_) {
|
|
57
|
+
return 'Object';
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// errors
|
|
61
|
+
if (val instanceof Error) {
|
|
62
|
+
return `${val.name}: ${val.message}\n${val.stack}`;
|
|
63
|
+
}
|
|
64
|
+
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
65
|
+
return className;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
let WASM_VECTOR_LEN = 0;
|
|
69
|
+
|
|
70
|
+
let cachedUint8ArrayMemory0 = null;
|
|
71
|
+
|
|
72
|
+
function getUint8ArrayMemory0() {
|
|
73
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
74
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
75
|
+
}
|
|
76
|
+
return cachedUint8ArrayMemory0;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
|
|
80
|
+
|
|
81
|
+
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
|
|
82
|
+
? function (arg, view) {
|
|
83
|
+
return cachedTextEncoder.encodeInto(arg, view);
|
|
84
|
+
}
|
|
85
|
+
: function (arg, view) {
|
|
86
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
87
|
+
view.set(buf);
|
|
88
|
+
return {
|
|
89
|
+
read: arg.length,
|
|
90
|
+
written: buf.length
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
95
|
+
|
|
96
|
+
if (realloc === undefined) {
|
|
97
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
98
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
99
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
100
|
+
WASM_VECTOR_LEN = buf.length;
|
|
101
|
+
return ptr;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
let len = arg.length;
|
|
105
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
106
|
+
|
|
107
|
+
const mem = getUint8ArrayMemory0();
|
|
108
|
+
|
|
109
|
+
let offset = 0;
|
|
110
|
+
|
|
111
|
+
for (; offset < len; offset++) {
|
|
112
|
+
const code = arg.charCodeAt(offset);
|
|
113
|
+
if (code > 0x7F) break;
|
|
114
|
+
mem[ptr + offset] = code;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (offset !== len) {
|
|
118
|
+
if (offset !== 0) {
|
|
119
|
+
arg = arg.slice(offset);
|
|
120
|
+
}
|
|
121
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
122
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
123
|
+
const ret = encodeString(arg, view);
|
|
124
|
+
|
|
125
|
+
offset += ret.written;
|
|
126
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
WASM_VECTOR_LEN = offset;
|
|
130
|
+
return ptr;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
let cachedDataViewMemory0 = null;
|
|
134
|
+
|
|
135
|
+
function getDataViewMemory0() {
|
|
136
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
137
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
138
|
+
}
|
|
139
|
+
return cachedDataViewMemory0;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
|
|
143
|
+
|
|
144
|
+
if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
|
|
145
|
+
|
|
146
|
+
function getStringFromWasm0(ptr, len) {
|
|
147
|
+
ptr = ptr >>> 0;
|
|
148
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function isLikeNone(x) {
|
|
152
|
+
return x === undefined || x === null;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function takeFromExternrefTable0(idx) {
|
|
156
|
+
const value = wasm.__wbindgen_export_2.get(idx);
|
|
157
|
+
wasm.__externref_table_dealloc(idx);
|
|
158
|
+
return value;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* @param {string} filename
|
|
162
|
+
* @param {string} code
|
|
163
|
+
* @param {any} options
|
|
164
|
+
* @returns {any}
|
|
165
|
+
*/
|
|
166
|
+
export function parse(filename, code, options) {
|
|
167
|
+
const ptr0 = passStringToWasm0(filename, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
168
|
+
const len0 = WASM_VECTOR_LEN;
|
|
169
|
+
const ptr1 = passStringToWasm0(code, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
170
|
+
const len1 = WASM_VECTOR_LEN;
|
|
171
|
+
const ret = wasm.parse(ptr0, len0, ptr1, len1, options);
|
|
172
|
+
if (ret[2]) {
|
|
173
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
174
|
+
}
|
|
175
|
+
return takeFromExternrefTable0(ret[0]);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
async function __wbg_load(module, imports) {
|
|
179
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
180
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
181
|
+
try {
|
|
182
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
183
|
+
|
|
184
|
+
} catch (e) {
|
|
185
|
+
if (module.headers.get('Content-Type') != 'application/wasm') {
|
|
186
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
187
|
+
|
|
188
|
+
} else {
|
|
189
|
+
throw e;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const bytes = await module.arrayBuffer();
|
|
195
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
196
|
+
|
|
197
|
+
} else {
|
|
198
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
199
|
+
|
|
200
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
201
|
+
return { instance, module };
|
|
202
|
+
|
|
203
|
+
} else {
|
|
204
|
+
return instance;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function __wbg_get_imports() {
|
|
210
|
+
const imports = {};
|
|
211
|
+
imports.wbg = {};
|
|
212
|
+
imports.wbg.__wbg_buffer_61b7ce01341d7f88 = function(arg0) {
|
|
213
|
+
const ret = arg0.buffer;
|
|
214
|
+
return ret;
|
|
215
|
+
};
|
|
216
|
+
imports.wbg.__wbg_getwithrefkey_1dc361bd10053bfe = function(arg0, arg1) {
|
|
217
|
+
const ret = arg0[arg1];
|
|
218
|
+
return ret;
|
|
219
|
+
};
|
|
220
|
+
imports.wbg.__wbg_instanceof_ArrayBuffer_670ddde44cdb2602 = function(arg0) {
|
|
221
|
+
let result;
|
|
222
|
+
try {
|
|
223
|
+
result = arg0 instanceof ArrayBuffer;
|
|
224
|
+
} catch (_) {
|
|
225
|
+
result = false;
|
|
226
|
+
}
|
|
227
|
+
const ret = result;
|
|
228
|
+
return ret;
|
|
229
|
+
};
|
|
230
|
+
imports.wbg.__wbg_instanceof_Uint8Array_28af5bc19d6acad8 = function(arg0) {
|
|
231
|
+
let result;
|
|
232
|
+
try {
|
|
233
|
+
result = arg0 instanceof Uint8Array;
|
|
234
|
+
} catch (_) {
|
|
235
|
+
result = false;
|
|
236
|
+
}
|
|
237
|
+
const ret = result;
|
|
238
|
+
return ret;
|
|
239
|
+
};
|
|
240
|
+
imports.wbg.__wbg_length_65d1cd11729ced11 = function(arg0) {
|
|
241
|
+
const ret = arg0.length;
|
|
242
|
+
return ret;
|
|
243
|
+
};
|
|
244
|
+
imports.wbg.__wbg_new_254fa9eac11932ae = function() {
|
|
245
|
+
const ret = new Array();
|
|
246
|
+
return ret;
|
|
247
|
+
};
|
|
248
|
+
imports.wbg.__wbg_new_3ff5b33b1ce712df = function(arg0) {
|
|
249
|
+
const ret = new Uint8Array(arg0);
|
|
250
|
+
return ret;
|
|
251
|
+
};
|
|
252
|
+
imports.wbg.__wbg_new_688846f374351c92 = function() {
|
|
253
|
+
const ret = new Object();
|
|
254
|
+
return ret;
|
|
255
|
+
};
|
|
256
|
+
imports.wbg.__wbg_set_1d80752d0d5f0b21 = function(arg0, arg1, arg2) {
|
|
257
|
+
arg0[arg1 >>> 0] = arg2;
|
|
258
|
+
};
|
|
259
|
+
imports.wbg.__wbg_set_23d69db4e5c66a6e = function(arg0, arg1, arg2) {
|
|
260
|
+
arg0.set(arg1, arg2 >>> 0);
|
|
261
|
+
};
|
|
262
|
+
imports.wbg.__wbg_set_3f1d0b984ed272ed = function(arg0, arg1, arg2) {
|
|
263
|
+
arg0[arg1] = arg2;
|
|
264
|
+
};
|
|
265
|
+
imports.wbg.__wbindgen_boolean_get = function(arg0) {
|
|
266
|
+
const v = arg0;
|
|
267
|
+
const ret = typeof(v) === 'boolean' ? (v ? 1 : 0) : 2;
|
|
268
|
+
return ret;
|
|
269
|
+
};
|
|
270
|
+
imports.wbg.__wbindgen_debug_string = function(arg0, arg1) {
|
|
271
|
+
const ret = debugString(arg1);
|
|
272
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
273
|
+
const len1 = WASM_VECTOR_LEN;
|
|
274
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
275
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
276
|
+
};
|
|
277
|
+
imports.wbg.__wbindgen_error_new = function(arg0, arg1) {
|
|
278
|
+
const ret = new Error(getStringFromWasm0(arg0, arg1));
|
|
279
|
+
return ret;
|
|
280
|
+
};
|
|
281
|
+
imports.wbg.__wbindgen_in = function(arg0, arg1) {
|
|
282
|
+
const ret = arg0 in arg1;
|
|
283
|
+
return ret;
|
|
284
|
+
};
|
|
285
|
+
imports.wbg.__wbindgen_init_externref_table = function() {
|
|
286
|
+
const table = wasm.__wbindgen_export_2;
|
|
287
|
+
const offset = table.grow(4);
|
|
288
|
+
table.set(0, undefined);
|
|
289
|
+
table.set(offset + 0, undefined);
|
|
290
|
+
table.set(offset + 1, null);
|
|
291
|
+
table.set(offset + 2, true);
|
|
292
|
+
table.set(offset + 3, false);
|
|
293
|
+
;
|
|
294
|
+
};
|
|
295
|
+
imports.wbg.__wbindgen_is_object = function(arg0) {
|
|
296
|
+
const val = arg0;
|
|
297
|
+
const ret = typeof(val) === 'object' && val !== null;
|
|
298
|
+
return ret;
|
|
299
|
+
};
|
|
300
|
+
imports.wbg.__wbindgen_is_undefined = function(arg0) {
|
|
301
|
+
const ret = arg0 === undefined;
|
|
302
|
+
return ret;
|
|
303
|
+
};
|
|
304
|
+
imports.wbg.__wbindgen_jsval_loose_eq = function(arg0, arg1) {
|
|
305
|
+
const ret = arg0 == arg1;
|
|
306
|
+
return ret;
|
|
307
|
+
};
|
|
308
|
+
imports.wbg.__wbindgen_memory = function() {
|
|
309
|
+
const ret = wasm.memory;
|
|
310
|
+
return ret;
|
|
311
|
+
};
|
|
312
|
+
imports.wbg.__wbindgen_number_get = function(arg0, arg1) {
|
|
313
|
+
const obj = arg1;
|
|
314
|
+
const ret = typeof(obj) === 'number' ? obj : undefined;
|
|
315
|
+
getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
|
|
316
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
317
|
+
};
|
|
318
|
+
imports.wbg.__wbindgen_string_get = function(arg0, arg1) {
|
|
319
|
+
const obj = arg1;
|
|
320
|
+
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
321
|
+
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
322
|
+
var len1 = WASM_VECTOR_LEN;
|
|
323
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
324
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
325
|
+
};
|
|
326
|
+
imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
|
|
327
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
328
|
+
return ret;
|
|
329
|
+
};
|
|
330
|
+
imports.wbg.__wbindgen_throw = function(arg0, arg1) {
|
|
331
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
return imports;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function __wbg_init_memory(imports, memory) {
|
|
338
|
+
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function __wbg_finalize_init(instance, module) {
|
|
342
|
+
wasm = instance.exports;
|
|
343
|
+
__wbg_init.__wbindgen_wasm_module = module;
|
|
344
|
+
cachedDataViewMemory0 = null;
|
|
345
|
+
cachedUint8ArrayMemory0 = null;
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
wasm.__wbindgen_start();
|
|
349
|
+
return wasm;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function initSync(module) {
|
|
353
|
+
if (wasm !== undefined) return wasm;
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
if (typeof module !== 'undefined') {
|
|
357
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
358
|
+
({module} = module)
|
|
359
|
+
} else {
|
|
360
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const imports = __wbg_get_imports();
|
|
365
|
+
|
|
366
|
+
__wbg_init_memory(imports);
|
|
367
|
+
|
|
368
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
369
|
+
module = new WebAssembly.Module(module);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
373
|
+
|
|
374
|
+
return __wbg_finalize_init(instance, module);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
async function __wbg_init(module_or_path) {
|
|
378
|
+
if (wasm !== undefined) return wasm;
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
if (typeof module_or_path !== 'undefined') {
|
|
382
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
383
|
+
({module_or_path} = module_or_path)
|
|
384
|
+
} else {
|
|
385
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
if (typeof module_or_path === 'undefined') {
|
|
390
|
+
module_or_path = new URL('cjs-module-lexer_bg.wasm', import.meta.url);
|
|
391
|
+
}
|
|
392
|
+
const imports = __wbg_get_imports();
|
|
393
|
+
|
|
394
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
395
|
+
module_or_path = fetch(module_or_path);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
__wbg_init_memory(imports);
|
|
399
|
+
|
|
400
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
401
|
+
|
|
402
|
+
return __wbg_finalize_init(instance, module);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
export { initSync };
|
|
406
|
+
export default __wbg_init;
|
|
Binary file
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 Je Xia <i@jex.me>
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
|
13
|
-
all copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
THE SOFTWARE.
|
package/pkg/cjs_module_lexer.js
DELETED
|
@@ -1,336 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
let imports = {};
|
|
3
|
-
imports['__wbindgen_placeholder__'] = module.exports;
|
|
4
|
-
let wasm;
|
|
5
|
-
const { TextEncoder, TextDecoder } = require(`util`);
|
|
6
|
-
|
|
7
|
-
let WASM_VECTOR_LEN = 0;
|
|
8
|
-
|
|
9
|
-
let cachedUint8ArrayMemory0 = null;
|
|
10
|
-
|
|
11
|
-
function getUint8ArrayMemory0() {
|
|
12
|
-
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
13
|
-
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
14
|
-
}
|
|
15
|
-
return cachedUint8ArrayMemory0;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
let cachedTextEncoder = new TextEncoder('utf-8');
|
|
19
|
-
|
|
20
|
-
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
|
|
21
|
-
? function (arg, view) {
|
|
22
|
-
return cachedTextEncoder.encodeInto(arg, view);
|
|
23
|
-
}
|
|
24
|
-
: function (arg, view) {
|
|
25
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
26
|
-
view.set(buf);
|
|
27
|
-
return {
|
|
28
|
-
read: arg.length,
|
|
29
|
-
written: buf.length
|
|
30
|
-
};
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
function passStringToWasm0(arg, malloc, realloc) {
|
|
34
|
-
|
|
35
|
-
if (realloc === undefined) {
|
|
36
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
37
|
-
const ptr = malloc(buf.length, 1) >>> 0;
|
|
38
|
-
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
39
|
-
WASM_VECTOR_LEN = buf.length;
|
|
40
|
-
return ptr;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
let len = arg.length;
|
|
44
|
-
let ptr = malloc(len, 1) >>> 0;
|
|
45
|
-
|
|
46
|
-
const mem = getUint8ArrayMemory0();
|
|
47
|
-
|
|
48
|
-
let offset = 0;
|
|
49
|
-
|
|
50
|
-
for (; offset < len; offset++) {
|
|
51
|
-
const code = arg.charCodeAt(offset);
|
|
52
|
-
if (code > 0x7F) break;
|
|
53
|
-
mem[ptr + offset] = code;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (offset !== len) {
|
|
57
|
-
if (offset !== 0) {
|
|
58
|
-
arg = arg.slice(offset);
|
|
59
|
-
}
|
|
60
|
-
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
61
|
-
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
62
|
-
const ret = encodeString(arg, view);
|
|
63
|
-
|
|
64
|
-
offset += ret.written;
|
|
65
|
-
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
WASM_VECTOR_LEN = offset;
|
|
69
|
-
return ptr;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function isLikeNone(x) {
|
|
73
|
-
return x === undefined || x === null;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
let cachedDataViewMemory0 = null;
|
|
77
|
-
|
|
78
|
-
function getDataViewMemory0() {
|
|
79
|
-
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
80
|
-
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
81
|
-
}
|
|
82
|
-
return cachedDataViewMemory0;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
86
|
-
|
|
87
|
-
cachedTextDecoder.decode();
|
|
88
|
-
|
|
89
|
-
function getStringFromWasm0(ptr, len) {
|
|
90
|
-
ptr = ptr >>> 0;
|
|
91
|
-
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function debugString(val) {
|
|
95
|
-
// primitive types
|
|
96
|
-
const type = typeof val;
|
|
97
|
-
if (type == 'number' || type == 'boolean' || val == null) {
|
|
98
|
-
return `${val}`;
|
|
99
|
-
}
|
|
100
|
-
if (type == 'string') {
|
|
101
|
-
return `"${val}"`;
|
|
102
|
-
}
|
|
103
|
-
if (type == 'symbol') {
|
|
104
|
-
const description = val.description;
|
|
105
|
-
if (description == null) {
|
|
106
|
-
return 'Symbol';
|
|
107
|
-
} else {
|
|
108
|
-
return `Symbol(${description})`;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
if (type == 'function') {
|
|
112
|
-
const name = val.name;
|
|
113
|
-
if (typeof name == 'string' && name.length > 0) {
|
|
114
|
-
return `Function(${name})`;
|
|
115
|
-
} else {
|
|
116
|
-
return 'Function';
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
// objects
|
|
120
|
-
if (Array.isArray(val)) {
|
|
121
|
-
const length = val.length;
|
|
122
|
-
let debug = '[';
|
|
123
|
-
if (length > 0) {
|
|
124
|
-
debug += debugString(val[0]);
|
|
125
|
-
}
|
|
126
|
-
for(let i = 1; i < length; i++) {
|
|
127
|
-
debug += ', ' + debugString(val[i]);
|
|
128
|
-
}
|
|
129
|
-
debug += ']';
|
|
130
|
-
return debug;
|
|
131
|
-
}
|
|
132
|
-
// Test for built-in
|
|
133
|
-
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
|
134
|
-
let className;
|
|
135
|
-
if (builtInMatches.length > 1) {
|
|
136
|
-
className = builtInMatches[1];
|
|
137
|
-
} else {
|
|
138
|
-
// Failed to match the standard '[object ClassName]'
|
|
139
|
-
return toString.call(val);
|
|
140
|
-
}
|
|
141
|
-
if (className == 'Object') {
|
|
142
|
-
// we're a user defined class or Object
|
|
143
|
-
// JSON.stringify avoids problems with cycles, and is generally much
|
|
144
|
-
// easier than looping through ownProperties of `val`.
|
|
145
|
-
try {
|
|
146
|
-
return 'Object(' + JSON.stringify(val) + ')';
|
|
147
|
-
} catch (_) {
|
|
148
|
-
return 'Object';
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
// errors
|
|
152
|
-
if (val instanceof Error) {
|
|
153
|
-
return `${val.name}: ${val.message}\n${val.stack}`;
|
|
154
|
-
}
|
|
155
|
-
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
156
|
-
return className;
|
|
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
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* @param {string} specifier
|
|
166
|
-
* @param {string} code
|
|
167
|
-
* @param {any} options
|
|
168
|
-
* @returns {any}
|
|
169
|
-
*/
|
|
170
|
-
module.exports.parse = function(specifier, code, options) {
|
|
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]);
|
|
178
|
-
}
|
|
179
|
-
return takeFromExternrefTable0(ret[0]);
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
module.exports.__wbindgen_is_undefined = function(arg0) {
|
|
183
|
-
const ret = arg0 === undefined;
|
|
184
|
-
return ret;
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
module.exports.__wbindgen_in = function(arg0, arg1) {
|
|
188
|
-
const ret = arg0 in arg1;
|
|
189
|
-
return ret;
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
module.exports.__wbindgen_boolean_get = function(arg0) {
|
|
193
|
-
const v = arg0;
|
|
194
|
-
const ret = typeof(v) === 'boolean' ? (v ? 1 : 0) : 2;
|
|
195
|
-
return ret;
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
module.exports.__wbindgen_string_get = function(arg0, arg1) {
|
|
199
|
-
const obj = arg1;
|
|
200
|
-
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
201
|
-
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
202
|
-
var len1 = WASM_VECTOR_LEN;
|
|
203
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
204
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
module.exports.__wbindgen_is_object = function(arg0) {
|
|
208
|
-
const val = arg0;
|
|
209
|
-
const ret = typeof(val) === 'object' && val !== null;
|
|
210
|
-
return ret;
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
module.exports.__wbindgen_error_new = function(arg0, arg1) {
|
|
214
|
-
const ret = new Error(getStringFromWasm0(arg0, arg1));
|
|
215
|
-
return ret;
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
module.exports.__wbindgen_jsval_loose_eq = function(arg0, arg1) {
|
|
219
|
-
const ret = arg0 == arg1;
|
|
220
|
-
return ret;
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
module.exports.__wbindgen_number_get = function(arg0, arg1) {
|
|
224
|
-
const obj = arg1;
|
|
225
|
-
const ret = typeof(obj) === 'number' ? obj : undefined;
|
|
226
|
-
getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
|
|
227
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
module.exports.__wbindgen_string_new = function(arg0, arg1) {
|
|
231
|
-
const ret = getStringFromWasm0(arg0, arg1);
|
|
232
|
-
return ret;
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
module.exports.__wbg_getwithrefkey_edc2c8960f0f1191 = function(arg0, arg1) {
|
|
236
|
-
const ret = arg0[arg1];
|
|
237
|
-
return ret;
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
module.exports.__wbg_set_f975102236d3c502 = function(arg0, arg1, arg2) {
|
|
241
|
-
arg0[arg1] = arg2;
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
module.exports.__wbg_new_16b304a2cfa7ff4a = function() {
|
|
245
|
-
const ret = new Array();
|
|
246
|
-
return ret;
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
module.exports.__wbg_new_72fb9a18b5ae2624 = function() {
|
|
250
|
-
const ret = new Object();
|
|
251
|
-
return ret;
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
module.exports.__wbg_set_d4638f722068f043 = function(arg0, arg1, arg2) {
|
|
255
|
-
arg0[arg1 >>> 0] = arg2;
|
|
256
|
-
};
|
|
257
|
-
|
|
258
|
-
module.exports.__wbg_instanceof_ArrayBuffer_836825be07d4c9d2 = function(arg0) {
|
|
259
|
-
let result;
|
|
260
|
-
try {
|
|
261
|
-
result = arg0 instanceof ArrayBuffer;
|
|
262
|
-
} catch (_) {
|
|
263
|
-
result = false;
|
|
264
|
-
}
|
|
265
|
-
const ret = result;
|
|
266
|
-
return ret;
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
module.exports.__wbg_buffer_12d079cc21e14bdb = function(arg0) {
|
|
270
|
-
const ret = arg0.buffer;
|
|
271
|
-
return ret;
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
module.exports.__wbg_new_63b92bc8671ed464 = function(arg0) {
|
|
275
|
-
const ret = new Uint8Array(arg0);
|
|
276
|
-
return ret;
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
module.exports.__wbg_instanceof_Uint8Array_2b3bbecd033d19f6 = function(arg0) {
|
|
280
|
-
let result;
|
|
281
|
-
try {
|
|
282
|
-
result = arg0 instanceof Uint8Array;
|
|
283
|
-
} catch (_) {
|
|
284
|
-
result = false;
|
|
285
|
-
}
|
|
286
|
-
const ret = result;
|
|
287
|
-
return ret;
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
module.exports.__wbg_length_c20a40f15020d68a = function(arg0) {
|
|
291
|
-
const ret = arg0.length;
|
|
292
|
-
return ret;
|
|
293
|
-
};
|
|
294
|
-
|
|
295
|
-
module.exports.__wbg_set_a47bac70306a19a7 = function(arg0, arg1, arg2) {
|
|
296
|
-
arg0.set(arg1, arg2 >>> 0);
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
module.exports.__wbindgen_debug_string = function(arg0, arg1) {
|
|
300
|
-
const ret = debugString(arg1);
|
|
301
|
-
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
302
|
-
const len1 = WASM_VECTOR_LEN;
|
|
303
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
304
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
module.exports.__wbindgen_throw = function(arg0, arg1) {
|
|
308
|
-
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
309
|
-
};
|
|
310
|
-
|
|
311
|
-
module.exports.__wbindgen_memory = function() {
|
|
312
|
-
const ret = wasm.memory;
|
|
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
|
-
;
|
|
325
|
-
};
|
|
326
|
-
|
|
327
|
-
const path = require('path').join(__dirname, 'cjs_module_lexer_bg.wasm');
|
|
328
|
-
const bytes = require('fs').readFileSync(path);
|
|
329
|
-
|
|
330
|
-
const wasmModule = new WebAssembly.Module(bytes);
|
|
331
|
-
const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
|
|
332
|
-
wasm = wasmInstance.exports;
|
|
333
|
-
module.exports.__wasm = wasm;
|
|
334
|
-
|
|
335
|
-
wasm.__wbindgen_start();
|
|
336
|
-
|
|
Binary file
|