@esm.sh/cjs-module-lexer 1.0.7 → 1.0.8

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/package.json CHANGED
@@ -1,12 +1,13 @@
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.7",
4
+ "version": "1.0.8",
5
5
  "type": "module",
6
6
  "main": "index.mjs",
7
7
  "scripts": {
8
- "prepublishOnly": "wasm-pack build --target web --out-name cjs-module-lexer",
9
- "test": "node test.mjs"
8
+ "prepublishOnly": "npm run build",
9
+ "build": "wasm-pack build --target web --out-name cjs-module-lexer",
10
+ "test": "npm run build && node test.mjs"
10
11
  },
11
12
  "files": [
12
13
  "./index.mjs",
@@ -65,10 +65,25 @@ function debugString(val) {
65
65
  return className;
66
66
  }
67
67
 
68
- let WASM_VECTOR_LEN = 0;
68
+ function getArrayU8FromWasm0(ptr, len) {
69
+ ptr = ptr >>> 0;
70
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
71
+ }
69
72
 
70
- let cachedUint8ArrayMemory0 = null;
73
+ let cachedDataViewMemory0 = null;
74
+ function getDataViewMemory0() {
75
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
76
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
77
+ }
78
+ return cachedDataViewMemory0;
79
+ }
71
80
 
81
+ function getStringFromWasm0(ptr, len) {
82
+ ptr = ptr >>> 0;
83
+ return decodeText(ptr, len);
84
+ }
85
+
86
+ let cachedUint8ArrayMemory0 = null;
72
87
  function getUint8ArrayMemory0() {
73
88
  if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
74
89
  cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
@@ -76,23 +91,11 @@ function getUint8ArrayMemory0() {
76
91
  return cachedUint8ArrayMemory0;
77
92
  }
78
93
 
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);
94
+ function isLikeNone(x) {
95
+ return x === undefined || x === null;
84
96
  }
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
97
 
94
98
  function passStringToWasm0(arg, malloc, realloc) {
95
-
96
99
  if (realloc === undefined) {
97
100
  const buf = cachedTextEncoder.encode(arg);
98
101
  const ptr = malloc(buf.length, 1) >>> 0;
@@ -113,14 +116,13 @@ function passStringToWasm0(arg, malloc, realloc) {
113
116
  if (code > 0x7F) break;
114
117
  mem[ptr + offset] = code;
115
118
  }
116
-
117
119
  if (offset !== len) {
118
120
  if (offset !== 0) {
119
121
  arg = arg.slice(offset);
120
122
  }
121
123
  ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
122
124
  const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
123
- const ret = encodeString(arg, view);
125
+ const ret = cachedTextEncoder.encodeInto(arg, view);
124
126
 
125
127
  offset += ret.written;
126
128
  ptr = realloc(ptr, len, offset, 1) >>> 0;
@@ -130,33 +132,41 @@ function passStringToWasm0(arg, malloc, realloc) {
130
132
  return ptr;
131
133
  }
132
134
 
133
- let cachedDataViewMemory0 = null;
135
+ function takeFromExternrefTable0(idx) {
136
+ const value = wasm.__wbindgen_externrefs.get(idx);
137
+ wasm.__externref_table_dealloc(idx);
138
+ return value;
139
+ }
134
140
 
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);
141
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
142
+ cachedTextDecoder.decode();
143
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
144
+ let numBytesDecoded = 0;
145
+ function decodeText(ptr, len) {
146
+ numBytesDecoded += len;
147
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
148
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
149
+ cachedTextDecoder.decode();
150
+ numBytesDecoded = len;
138
151
  }
139
- return cachedDataViewMemory0;
152
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
140
153
  }
141
154
 
142
- const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
155
+ const cachedTextEncoder = new TextEncoder();
143
156
 
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));
157
+ if (!('encodeInto' in cachedTextEncoder)) {
158
+ cachedTextEncoder.encodeInto = function (arg, view) {
159
+ const buf = cachedTextEncoder.encode(arg);
160
+ view.set(buf);
161
+ return {
162
+ read: arg.length,
163
+ written: buf.length
164
+ };
165
+ }
149
166
  }
150
167
 
151
- function isLikeNone(x) {
152
- return x === undefined || x === null;
153
- }
168
+ let WASM_VECTOR_LEN = 0;
154
169
 
155
- function takeFromExternrefTable0(idx) {
156
- const value = wasm.__wbindgen_export_2.get(idx);
157
- wasm.__externref_table_dealloc(idx);
158
- return value;
159
- }
160
170
  /**
161
171
  * @param {string} filename
162
172
  * @param {string} code
@@ -175,14 +185,17 @@ export function parse(filename, code, options) {
175
185
  return takeFromExternrefTable0(ret[0]);
176
186
  }
177
187
 
188
+ const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
189
+
178
190
  async function __wbg_load(module, imports) {
179
191
  if (typeof Response === 'function' && module instanceof Response) {
180
192
  if (typeof WebAssembly.instantiateStreaming === 'function') {
181
193
  try {
182
194
  return await WebAssembly.instantiateStreaming(module, imports);
183
-
184
195
  } catch (e) {
185
- if (module.headers.get('Content-Type') != 'application/wasm') {
196
+ const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
197
+
198
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
186
199
  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
200
 
188
201
  } else {
@@ -193,13 +206,11 @@ async function __wbg_load(module, imports) {
193
206
 
194
207
  const bytes = await module.arrayBuffer();
195
208
  return await WebAssembly.instantiate(bytes, imports);
196
-
197
209
  } else {
198
210
  const instance = await WebAssembly.instantiate(module, imports);
199
211
 
200
212
  if (instance instanceof WebAssembly.Instance) {
201
213
  return { instance, module };
202
-
203
214
  } else {
204
215
  return instance;
205
216
  }
@@ -209,15 +220,61 @@ async function __wbg_load(module, imports) {
209
220
  function __wbg_get_imports() {
210
221
  const imports = {};
211
222
  imports.wbg = {};
212
- imports.wbg.__wbg_buffer_61b7ce01341d7f88 = function(arg0) {
213
- const ret = arg0.buffer;
223
+ imports.wbg.__wbg_Error_52673b7de5a0ca89 = function(arg0, arg1) {
224
+ const ret = Error(getStringFromWasm0(arg0, arg1));
225
+ return ret;
226
+ };
227
+ imports.wbg.__wbg___wbindgen_boolean_get_dea25b33882b895b = function(arg0) {
228
+ const v = arg0;
229
+ const ret = typeof(v) === 'boolean' ? v : undefined;
230
+ return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
231
+ };
232
+ imports.wbg.__wbg___wbindgen_debug_string_adfb662ae34724b6 = function(arg0, arg1) {
233
+ const ret = debugString(arg1);
234
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
235
+ const len1 = WASM_VECTOR_LEN;
236
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
237
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
238
+ };
239
+ imports.wbg.__wbg___wbindgen_in_0d3e1e8f0c669317 = function(arg0, arg1) {
240
+ const ret = arg0 in arg1;
241
+ return ret;
242
+ };
243
+ imports.wbg.__wbg___wbindgen_is_object_ce774f3490692386 = function(arg0) {
244
+ const val = arg0;
245
+ const ret = typeof(val) === 'object' && val !== null;
246
+ return ret;
247
+ };
248
+ imports.wbg.__wbg___wbindgen_is_undefined_f6b95eab589e0269 = function(arg0) {
249
+ const ret = arg0 === undefined;
250
+ return ret;
251
+ };
252
+ imports.wbg.__wbg___wbindgen_jsval_loose_eq_766057600fdd1b0d = function(arg0, arg1) {
253
+ const ret = arg0 == arg1;
214
254
  return ret;
215
255
  };
216
- imports.wbg.__wbg_getwithrefkey_1dc361bd10053bfe = function(arg0, arg1) {
256
+ imports.wbg.__wbg___wbindgen_number_get_9619185a74197f95 = function(arg0, arg1) {
257
+ const obj = arg1;
258
+ const ret = typeof(obj) === 'number' ? obj : undefined;
259
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
260
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
261
+ };
262
+ imports.wbg.__wbg___wbindgen_string_get_a2a31e16edf96e42 = function(arg0, arg1) {
263
+ const obj = arg1;
264
+ const ret = typeof(obj) === 'string' ? obj : undefined;
265
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
266
+ var len1 = WASM_VECTOR_LEN;
267
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
268
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
269
+ };
270
+ imports.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e = function(arg0, arg1) {
271
+ throw new Error(getStringFromWasm0(arg0, arg1));
272
+ };
273
+ imports.wbg.__wbg_get_with_ref_key_1dc361bd10053bfe = function(arg0, arg1) {
217
274
  const ret = arg0[arg1];
218
275
  return ret;
219
276
  };
220
- imports.wbg.__wbg_instanceof_ArrayBuffer_670ddde44cdb2602 = function(arg0) {
277
+ imports.wbg.__wbg_instanceof_ArrayBuffer_f3320d2419cd0355 = function(arg0) {
221
278
  let result;
222
279
  try {
223
280
  result = arg0 instanceof ArrayBuffer;
@@ -227,7 +284,7 @@ function __wbg_get_imports() {
227
284
  const ret = result;
228
285
  return ret;
229
286
  };
230
- imports.wbg.__wbg_instanceof_Uint8Array_28af5bc19d6acad8 = function(arg0) {
287
+ imports.wbg.__wbg_instanceof_Uint8Array_da54ccc9d3e09434 = function(arg0) {
231
288
  let result;
232
289
  try {
233
290
  result = arg0 instanceof Uint8Array;
@@ -237,107 +294,49 @@ function __wbg_get_imports() {
237
294
  const ret = result;
238
295
  return ret;
239
296
  };
240
- imports.wbg.__wbg_length_65d1cd11729ced11 = function(arg0) {
297
+ imports.wbg.__wbg_length_22ac23eaec9d8053 = function(arg0) {
241
298
  const ret = arg0.length;
242
299
  return ret;
243
300
  };
244
- imports.wbg.__wbg_new_254fa9eac11932ae = function() {
245
- const ret = new Array();
301
+ imports.wbg.__wbg_new_1ba21ce319a06297 = function() {
302
+ const ret = new Object();
246
303
  return ret;
247
304
  };
248
- imports.wbg.__wbg_new_3ff5b33b1ce712df = function(arg0) {
249
- const ret = new Uint8Array(arg0);
305
+ imports.wbg.__wbg_new_25f239778d6112b9 = function() {
306
+ const ret = new Array();
250
307
  return ret;
251
308
  };
252
- imports.wbg.__wbg_new_688846f374351c92 = function() {
253
- const ret = new Object();
309
+ imports.wbg.__wbg_new_6421f6084cc5bc5a = function(arg0) {
310
+ const ret = new Uint8Array(arg0);
254
311
  return ret;
255
312
  };
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);
313
+ imports.wbg.__wbg_prototypesetcall_dfe9b766cdc1f1fd = function(arg0, arg1, arg2) {
314
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
261
315
  };
262
316
  imports.wbg.__wbg_set_3f1d0b984ed272ed = function(arg0, arg1, arg2) {
263
317
  arg0[arg1] = arg2;
264
318
  };
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;
319
+ imports.wbg.__wbg_set_7df433eea03a5c14 = function(arg0, arg1, arg2) {
320
+ arg0[arg1 >>> 0] = arg2;
280
321
  };
281
- imports.wbg.__wbindgen_in = function(arg0, arg1) {
282
- const ret = arg0 in arg1;
322
+ imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
323
+ // Cast intrinsic for `Ref(String) -> Externref`.
324
+ const ret = getStringFromWasm0(arg0, arg1);
283
325
  return ret;
284
326
  };
285
327
  imports.wbg.__wbindgen_init_externref_table = function() {
286
- const table = wasm.__wbindgen_export_2;
328
+ const table = wasm.__wbindgen_externrefs;
287
329
  const offset = table.grow(4);
288
330
  table.set(0, undefined);
289
331
  table.set(offset + 0, undefined);
290
332
  table.set(offset + 1, null);
291
333
  table.set(offset + 2, true);
292
334
  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
335
  };
333
336
 
334
337
  return imports;
335
338
  }
336
339
 
337
- function __wbg_init_memory(imports, memory) {
338
-
339
- }
340
-
341
340
  function __wbg_finalize_init(instance, module) {
342
341
  wasm = instance.exports;
343
342
  __wbg_init.__wbindgen_wasm_module = module;
@@ -362,15 +361,10 @@ function initSync(module) {
362
361
  }
363
362
 
364
363
  const imports = __wbg_get_imports();
365
-
366
- __wbg_init_memory(imports);
367
-
368
364
  if (!(module instanceof WebAssembly.Module)) {
369
365
  module = new WebAssembly.Module(module);
370
366
  }
371
-
372
367
  const instance = new WebAssembly.Instance(module, imports);
373
-
374
368
  return __wbg_finalize_init(instance, module);
375
369
  }
376
370
 
@@ -395,8 +389,6 @@ async function __wbg_init(module_or_path) {
395
389
  module_or_path = fetch(module_or_path);
396
390
  }
397
391
 
398
- __wbg_init_memory(imports);
399
-
400
392
  const { instance, module } = await __wbg_load(await module_or_path, imports);
401
393
 
402
394
  return __wbg_finalize_init(instance, module);
Binary file