@esm.sh/cjs-module-lexer 1.0.0 → 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 CHANGED
@@ -1,19 +1,21 @@
1
- # @esm.sh/cjs-module-lexer
1
+ # cjs-module-lexer
2
2
 
3
- A lexer for detecting the `module.exports` of a CJS module, written in Rust and compiled to WebAssembly.
3
+ A lexer for detecting the `module.exports` of a CJS module, written in Rust.
4
4
 
5
- ## Usage
5
+ ## Installation
6
6
 
7
- `@esm.sh/cjs-module-lexer` currently only supports Node.js environment. You can install it via npm CLI:
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
- `@esm.sh/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.
13
+ ## Usage
14
+
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
- const { parse } = require("@esm.sh/cjs-module-lexer");
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
- "description": "A WASM module to parse the `module.exports` of a commonjs module.",
4
- "version": "1.0.0",
5
- "main": "pkg/cjs_module_lexer.js",
6
- "types": "pkg/cjs_module_lexer.d.ts",
3
+ "description": "A lexer for detecting the `module.exports` of a CJS module.",
4
+ "version": "1.0.2",
5
+ "type": "module",
6
+ "main": "index.mjs",
7
7
  "scripts": {
8
- "prepublishOnly": "wasm-pack build --target nodejs"
8
+ "prepublishOnly": "wasm-pack build --target web --out-name cjs-module-lexer",
9
+ "test": "node test.mjs"
9
10
  },
10
11
  "files": [
11
- "pkg/cjs_module_lexer_bg.wasm",
12
- "pkg/cjs_module_lexer.js",
13
- "pkg/cjs_module_lexer.d.ts"
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) 2020-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.
@@ -1,9 +0,0 @@
1
- /* tslint:disable */
2
- /* eslint-disable */
3
- /**
4
- * @param {string} specifier
5
- * @param {string} code
6
- * @param {any} options
7
- * @returns {any}
8
- */
9
- export function parse(specifier: string, code: string, options: any): any;
@@ -1,363 +0,0 @@
1
-
2
- let imports = {};
3
- imports['__wbindgen_placeholder__'] = module.exports;
4
- let wasm;
5
- const { TextEncoder, TextDecoder } = require(`util`);
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
- let WASM_VECTOR_LEN = 0;
28
-
29
- let cachedUint8ArrayMemory0 = null;
30
-
31
- function getUint8ArrayMemory0() {
32
- if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
33
- cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
34
- }
35
- return cachedUint8ArrayMemory0;
36
- }
37
-
38
- let cachedTextEncoder = new TextEncoder('utf-8');
39
-
40
- const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
41
- ? function (arg, view) {
42
- return cachedTextEncoder.encodeInto(arg, view);
43
- }
44
- : function (arg, view) {
45
- const buf = cachedTextEncoder.encode(arg);
46
- view.set(buf);
47
- return {
48
- read: arg.length,
49
- written: buf.length
50
- };
51
- });
52
-
53
- function passStringToWasm0(arg, malloc, realloc) {
54
-
55
- if (realloc === undefined) {
56
- const buf = cachedTextEncoder.encode(arg);
57
- const ptr = malloc(buf.length, 1) >>> 0;
58
- getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
59
- WASM_VECTOR_LEN = buf.length;
60
- return ptr;
61
- }
62
-
63
- let len = arg.length;
64
- let ptr = malloc(len, 1) >>> 0;
65
-
66
- const mem = getUint8ArrayMemory0();
67
-
68
- let offset = 0;
69
-
70
- for (; offset < len; offset++) {
71
- const code = arg.charCodeAt(offset);
72
- if (code > 0x7F) break;
73
- mem[ptr + offset] = code;
74
- }
75
-
76
- if (offset !== len) {
77
- if (offset !== 0) {
78
- arg = arg.slice(offset);
79
- }
80
- ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
81
- const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
82
- const ret = encodeString(arg, view);
83
-
84
- offset += ret.written;
85
- ptr = realloc(ptr, len, offset, 1) >>> 0;
86
- }
87
-
88
- WASM_VECTOR_LEN = offset;
89
- return ptr;
90
- }
91
-
92
- function isLikeNone(x) {
93
- return x === undefined || x === null;
94
- }
95
-
96
- let cachedDataViewMemory0 = null;
97
-
98
- function getDataViewMemory0() {
99
- if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
100
- cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
101
- }
102
- return cachedDataViewMemory0;
103
- }
104
-
105
- let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
106
-
107
- cachedTextDecoder.decode();
108
-
109
- function getStringFromWasm0(ptr, len) {
110
- ptr = ptr >>> 0;
111
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
112
- }
113
-
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
- function debugString(val) {
124
- // primitive types
125
- const type = typeof val;
126
- if (type == 'number' || type == 'boolean' || val == null) {
127
- return `${val}`;
128
- }
129
- if (type == 'string') {
130
- return `"${val}"`;
131
- }
132
- if (type == 'symbol') {
133
- const description = val.description;
134
- if (description == null) {
135
- return 'Symbol';
136
- } else {
137
- return `Symbol(${description})`;
138
- }
139
- }
140
- if (type == 'function') {
141
- const name = val.name;
142
- if (typeof name == 'string' && name.length > 0) {
143
- return `Function(${name})`;
144
- } else {
145
- return 'Function';
146
- }
147
- }
148
- // objects
149
- if (Array.isArray(val)) {
150
- const length = val.length;
151
- let debug = '[';
152
- if (length > 0) {
153
- debug += debugString(val[0]);
154
- }
155
- for(let i = 1; i < length; i++) {
156
- debug += ', ' + debugString(val[i]);
157
- }
158
- debug += ']';
159
- return debug;
160
- }
161
- // Test for built-in
162
- const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
163
- let className;
164
- if (builtInMatches.length > 1) {
165
- className = builtInMatches[1];
166
- } else {
167
- // Failed to match the standard '[object ClassName]'
168
- return toString.call(val);
169
- }
170
- if (className == 'Object') {
171
- // we're a user defined class or Object
172
- // JSON.stringify avoids problems with cycles, and is generally much
173
- // easier than looping through ownProperties of `val`.
174
- try {
175
- return 'Object(' + JSON.stringify(val) + ')';
176
- } catch (_) {
177
- return 'Object';
178
- }
179
- }
180
- // errors
181
- if (val instanceof Error) {
182
- return `${val.name}: ${val.message}\n${val.stack}`;
183
- }
184
- // TODO we could test for more things here, like `Set`s and `Map`s.
185
- return className;
186
- }
187
- /**
188
- * @param {string} specifier
189
- * @param {string} code
190
- * @param {any} options
191
- * @returns {any}
192
- */
193
- module.exports.parse = function(specifier, code, options) {
194
- try {
195
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
196
- const ptr0 = passStringToWasm0(specifier, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
197
- const len0 = WASM_VECTOR_LEN;
198
- const ptr1 = passStringToWasm0(code, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
199
- const len1 = WASM_VECTOR_LEN;
200
- wasm.parse(retptr, ptr0, len0, ptr1, len1, addHeapObject(options));
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);
210
- }
211
- };
212
-
213
- module.exports.__wbindgen_object_drop_ref = function(arg0) {
214
- takeObject(arg0);
215
- };
216
-
217
- module.exports.__wbindgen_is_undefined = function(arg0) {
218
- const ret = getObject(arg0) === undefined;
219
- return ret;
220
- };
221
-
222
- module.exports.__wbindgen_in = function(arg0, arg1) {
223
- const ret = getObject(arg0) in getObject(arg1);
224
- return ret;
225
- };
226
-
227
- module.exports.__wbindgen_boolean_get = function(arg0) {
228
- const v = getObject(arg0);
229
- const ret = typeof(v) === 'boolean' ? (v ? 1 : 0) : 2;
230
- return ret;
231
- };
232
-
233
- module.exports.__wbindgen_string_get = function(arg0, arg1) {
234
- const obj = getObject(arg1);
235
- const ret = typeof(obj) === 'string' ? obj : undefined;
236
- var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
237
- var len1 = WASM_VECTOR_LEN;
238
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
239
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
240
- };
241
-
242
- module.exports.__wbindgen_is_object = function(arg0) {
243
- const val = getObject(arg0);
244
- const ret = typeof(val) === 'object' && val !== null;
245
- return ret;
246
- };
247
-
248
- module.exports.__wbindgen_error_new = function(arg0, arg1) {
249
- const ret = new Error(getStringFromWasm0(arg0, arg1));
250
- return addHeapObject(ret);
251
- };
252
-
253
- module.exports.__wbindgen_object_clone_ref = function(arg0) {
254
- const ret = getObject(arg0);
255
- return addHeapObject(ret);
256
- };
257
-
258
- module.exports.__wbindgen_jsval_loose_eq = function(arg0, arg1) {
259
- const ret = getObject(arg0) == getObject(arg1);
260
- return ret;
261
- };
262
-
263
- module.exports.__wbindgen_number_get = function(arg0, arg1) {
264
- const obj = getObject(arg1);
265
- const ret = typeof(obj) === 'number' ? obj : undefined;
266
- getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
267
- getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
268
- };
269
-
270
- module.exports.__wbindgen_string_new = function(arg0, arg1) {
271
- const ret = getStringFromWasm0(arg0, arg1);
272
- return addHeapObject(ret);
273
- };
274
-
275
- module.exports.__wbg_getwithrefkey_edc2c8960f0f1191 = function(arg0, arg1) {
276
- const ret = getObject(arg0)[getObject(arg1)];
277
- return addHeapObject(ret);
278
- };
279
-
280
- module.exports.__wbg_set_f975102236d3c502 = function(arg0, arg1, arg2) {
281
- getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
282
- };
283
-
284
- module.exports.__wbg_new_16b304a2cfa7ff4a = function() {
285
- const ret = new Array();
286
- return addHeapObject(ret);
287
- };
288
-
289
- module.exports.__wbg_new_72fb9a18b5ae2624 = function() {
290
- const ret = new Object();
291
- return addHeapObject(ret);
292
- };
293
-
294
- module.exports.__wbg_set_d4638f722068f043 = function(arg0, arg1, arg2) {
295
- getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
296
- };
297
-
298
- module.exports.__wbg_instanceof_ArrayBuffer_836825be07d4c9d2 = function(arg0) {
299
- let result;
300
- try {
301
- result = getObject(arg0) instanceof ArrayBuffer;
302
- } catch (_) {
303
- result = false;
304
- }
305
- const ret = result;
306
- return ret;
307
- };
308
-
309
- module.exports.__wbg_buffer_12d079cc21e14bdb = function(arg0) {
310
- const ret = getObject(arg0).buffer;
311
- return addHeapObject(ret);
312
- };
313
-
314
- module.exports.__wbg_new_63b92bc8671ed464 = function(arg0) {
315
- const ret = new Uint8Array(getObject(arg0));
316
- return addHeapObject(ret);
317
- };
318
-
319
- module.exports.__wbg_instanceof_Uint8Array_2b3bbecd033d19f6 = function(arg0) {
320
- let result;
321
- try {
322
- result = getObject(arg0) instanceof Uint8Array;
323
- } catch (_) {
324
- result = false;
325
- }
326
- const ret = result;
327
- return ret;
328
- };
329
-
330
- module.exports.__wbg_length_c20a40f15020d68a = function(arg0) {
331
- const ret = getObject(arg0).length;
332
- return ret;
333
- };
334
-
335
- module.exports.__wbg_set_a47bac70306a19a7 = function(arg0, arg1, arg2) {
336
- getObject(arg0).set(getObject(arg1), arg2 >>> 0);
337
- };
338
-
339
- module.exports.__wbindgen_debug_string = function(arg0, arg1) {
340
- const ret = debugString(getObject(arg1));
341
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
342
- const len1 = WASM_VECTOR_LEN;
343
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
344
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
345
- };
346
-
347
- module.exports.__wbindgen_throw = function(arg0, arg1) {
348
- throw new Error(getStringFromWasm0(arg0, arg1));
349
- };
350
-
351
- module.exports.__wbindgen_memory = function() {
352
- const ret = wasm.memory;
353
- return addHeapObject(ret);
354
- };
355
-
356
- const path = require('path').join(__dirname, 'cjs_module_lexer_bg.wasm');
357
- const bytes = require('fs').readFileSync(path);
358
-
359
- const wasmModule = new WebAssembly.Module(bytes);
360
- const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
361
- wasm = wasmInstance.exports;
362
- module.exports.__wasm = wasm;
363
-
Binary file