@srcmap/sourcemap-wasm 0.1.0 → 0.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@srcmap/sourcemap-wasm",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "High-performance source map parser and consumer powered by Rust (WebAssembly)",
5
5
  "type": "module",
6
6
  "main": "pkg/srcmap_sourcemap_wasm.js",
@@ -16,7 +16,7 @@
16
16
  },
17
17
  "repository": {
18
18
  "type": "git",
19
- "url": "https://github.com/bartwaardenburg/srcmap"
19
+ "url": "https://github.com/BartWaardenburg/srcmap"
20
20
  },
21
21
  "keywords": [
22
22
  "sourcemap",
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "srcmap-sourcemap-wasm",
3
+ "description": "WebAssembly bindings for srcmap-sourcemap",
4
+ "version": "0.1.2",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/bartwaardenburg/srcmap"
9
+ },
10
+ "files": [
11
+ "srcmap_sourcemap_wasm_bg.wasm",
12
+ "srcmap_sourcemap_wasm.js",
13
+ "srcmap_sourcemap_wasm.d.ts"
14
+ ],
15
+ "main": "srcmap_sourcemap_wasm.js",
16
+ "types": "srcmap_sourcemap_wasm.d.ts"
17
+ }
@@ -0,0 +1,53 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ export class SourceMap {
5
+ free(): void;
6
+ [Symbol.dispose](): void;
7
+ /**
8
+ * Look up the generated position for an original source position.
9
+ * Returns null if no mapping exists, or an object {line, column}.
10
+ */
11
+ generatedPositionFor(source: string, line: number, column: number): any;
12
+ /**
13
+ * Resolve a name index to its string.
14
+ */
15
+ name(index: number): string;
16
+ /**
17
+ * Parse a source map from a JSON string.
18
+ */
19
+ constructor(json: string);
20
+ /**
21
+ * Look up the original source position for a generated position.
22
+ * Both line and column are 0-based.
23
+ * Returns null if no mapping exists, or an object {source, line, column, name}.
24
+ */
25
+ originalPositionFor(line: number, column: number): any;
26
+ /**
27
+ * Batch lookup: find original positions for multiple generated positions.
28
+ * Takes a flat array [line0, col0, line1, col1, ...].
29
+ * Returns a flat array [srcIdx0, line0, col0, nameIdx0, srcIdx1, ...].
30
+ * -1 means no mapping found / no name.
31
+ */
32
+ originalPositionsFor(positions: Int32Array): Int32Array;
33
+ /**
34
+ * Resolve a source index to its filename.
35
+ */
36
+ source(index: number): string;
37
+ /**
38
+ * Number of generated lines.
39
+ */
40
+ readonly lineCount: number;
41
+ /**
42
+ * Total number of decoded mappings.
43
+ */
44
+ readonly mappingCount: number;
45
+ /**
46
+ * Get all names.
47
+ */
48
+ readonly names: any[];
49
+ /**
50
+ * Get all source filenames.
51
+ */
52
+ readonly sources: any[];
53
+ }
@@ -0,0 +1,380 @@
1
+ /* @ts-self-types="./srcmap_sourcemap_wasm.d.ts" */
2
+
3
+ class SourceMap {
4
+ __destroy_into_raw() {
5
+ const ptr = this.__wbg_ptr;
6
+ this.__wbg_ptr = 0;
7
+ SourceMapFinalization.unregister(this);
8
+ return ptr;
9
+ }
10
+ free() {
11
+ const ptr = this.__destroy_into_raw();
12
+ wasm.__wbg_sourcemap_free(ptr, 0);
13
+ }
14
+ /**
15
+ * Look up the generated position for an original source position.
16
+ * Returns null if no mapping exists, or an object {line, column}.
17
+ * @param {string} source
18
+ * @param {number} line
19
+ * @param {number} column
20
+ * @returns {any}
21
+ */
22
+ generatedPositionFor(source, line, column) {
23
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
24
+ const len0 = WASM_VECTOR_LEN;
25
+ const ret = wasm.sourcemap_generatedPositionFor(this.__wbg_ptr, ptr0, len0, line, column);
26
+ return takeObject(ret);
27
+ }
28
+ /**
29
+ * Number of generated lines.
30
+ * @returns {number}
31
+ */
32
+ get lineCount() {
33
+ const ret = wasm.sourcemap_lineCount(this.__wbg_ptr);
34
+ return ret >>> 0;
35
+ }
36
+ /**
37
+ * Total number of decoded mappings.
38
+ * @returns {number}
39
+ */
40
+ get mappingCount() {
41
+ const ret = wasm.sourcemap_mappingCount(this.__wbg_ptr);
42
+ return ret >>> 0;
43
+ }
44
+ /**
45
+ * Resolve a name index to its string.
46
+ * @param {number} index
47
+ * @returns {string}
48
+ */
49
+ name(index) {
50
+ let deferred1_0;
51
+ let deferred1_1;
52
+ try {
53
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
54
+ wasm.sourcemap_name(retptr, this.__wbg_ptr, index);
55
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
56
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
57
+ deferred1_0 = r0;
58
+ deferred1_1 = r1;
59
+ return getStringFromWasm0(r0, r1);
60
+ } finally {
61
+ wasm.__wbindgen_add_to_stack_pointer(16);
62
+ wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
63
+ }
64
+ }
65
+ /**
66
+ * Get all names.
67
+ * @returns {any[]}
68
+ */
69
+ get names() {
70
+ try {
71
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
72
+ wasm.sourcemap_names(retptr, this.__wbg_ptr);
73
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
74
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
75
+ var v1 = getArrayJsValueFromWasm0(r0, r1).slice();
76
+ wasm.__wbindgen_export4(r0, r1 * 4, 4);
77
+ return v1;
78
+ } finally {
79
+ wasm.__wbindgen_add_to_stack_pointer(16);
80
+ }
81
+ }
82
+ /**
83
+ * Parse a source map from a JSON string.
84
+ * @param {string} json
85
+ */
86
+ constructor(json) {
87
+ try {
88
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
89
+ const ptr0 = passStringToWasm0(json, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
90
+ const len0 = WASM_VECTOR_LEN;
91
+ wasm.sourcemap_new(retptr, ptr0, len0);
92
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
93
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
94
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
95
+ if (r2) {
96
+ throw takeObject(r1);
97
+ }
98
+ this.__wbg_ptr = r0 >>> 0;
99
+ SourceMapFinalization.register(this, this.__wbg_ptr, this);
100
+ return this;
101
+ } finally {
102
+ wasm.__wbindgen_add_to_stack_pointer(16);
103
+ }
104
+ }
105
+ /**
106
+ * Look up the original source position for a generated position.
107
+ * Both line and column are 0-based.
108
+ * Returns null if no mapping exists, or an object {source, line, column, name}.
109
+ * @param {number} line
110
+ * @param {number} column
111
+ * @returns {any}
112
+ */
113
+ originalPositionFor(line, column) {
114
+ const ret = wasm.sourcemap_originalPositionFor(this.__wbg_ptr, line, column);
115
+ return takeObject(ret);
116
+ }
117
+ /**
118
+ * Batch lookup: find original positions for multiple generated positions.
119
+ * Takes a flat array [line0, col0, line1, col1, ...].
120
+ * Returns a flat array [srcIdx0, line0, col0, nameIdx0, srcIdx1, ...].
121
+ * -1 means no mapping found / no name.
122
+ * @param {Int32Array} positions
123
+ * @returns {Int32Array}
124
+ */
125
+ originalPositionsFor(positions) {
126
+ try {
127
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
128
+ const ptr0 = passArray32ToWasm0(positions, wasm.__wbindgen_export2);
129
+ const len0 = WASM_VECTOR_LEN;
130
+ wasm.sourcemap_originalPositionsFor(retptr, this.__wbg_ptr, ptr0, len0);
131
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
132
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
133
+ var v2 = getArrayI32FromWasm0(r0, r1).slice();
134
+ wasm.__wbindgen_export4(r0, r1 * 4, 4);
135
+ return v2;
136
+ } finally {
137
+ wasm.__wbindgen_add_to_stack_pointer(16);
138
+ }
139
+ }
140
+ /**
141
+ * Resolve a source index to its filename.
142
+ * @param {number} index
143
+ * @returns {string}
144
+ */
145
+ source(index) {
146
+ let deferred1_0;
147
+ let deferred1_1;
148
+ try {
149
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
150
+ wasm.sourcemap_source(retptr, this.__wbg_ptr, index);
151
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
152
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
153
+ deferred1_0 = r0;
154
+ deferred1_1 = r1;
155
+ return getStringFromWasm0(r0, r1);
156
+ } finally {
157
+ wasm.__wbindgen_add_to_stack_pointer(16);
158
+ wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
159
+ }
160
+ }
161
+ /**
162
+ * Get all source filenames.
163
+ * @returns {any[]}
164
+ */
165
+ get sources() {
166
+ try {
167
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
168
+ wasm.sourcemap_sources(retptr, this.__wbg_ptr);
169
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
170
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
171
+ var v1 = getArrayJsValueFromWasm0(r0, r1).slice();
172
+ wasm.__wbindgen_export4(r0, r1 * 4, 4);
173
+ return v1;
174
+ } finally {
175
+ wasm.__wbindgen_add_to_stack_pointer(16);
176
+ }
177
+ }
178
+ }
179
+ if (Symbol.dispose) SourceMap.prototype[Symbol.dispose] = SourceMap.prototype.free;
180
+ exports.SourceMap = SourceMap;
181
+
182
+ function __wbg_get_imports() {
183
+ const import0 = {
184
+ __proto__: null,
185
+ __wbg_Error_83742b46f01ce22d: function(arg0, arg1) {
186
+ const ret = Error(getStringFromWasm0(arg0, arg1));
187
+ return addHeapObject(ret);
188
+ },
189
+ __wbg___wbindgen_throw_6ddd609b62940d55: function(arg0, arg1) {
190
+ throw new Error(getStringFromWasm0(arg0, arg1));
191
+ },
192
+ __wbg_new_ab79df5bd7c26067: function() {
193
+ const ret = new Object();
194
+ return addHeapObject(ret);
195
+ },
196
+ __wbg_set_7eaa4f96924fd6b3: function() { return handleError(function (arg0, arg1, arg2) {
197
+ const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
198
+ return ret;
199
+ }, arguments); },
200
+ __wbindgen_cast_0000000000000001: function(arg0) {
201
+ // Cast intrinsic for `F64 -> Externref`.
202
+ const ret = arg0;
203
+ return addHeapObject(ret);
204
+ },
205
+ __wbindgen_cast_0000000000000002: function(arg0, arg1) {
206
+ // Cast intrinsic for `Ref(String) -> Externref`.
207
+ const ret = getStringFromWasm0(arg0, arg1);
208
+ return addHeapObject(ret);
209
+ },
210
+ __wbindgen_object_drop_ref: function(arg0) {
211
+ takeObject(arg0);
212
+ },
213
+ };
214
+ return {
215
+ __proto__: null,
216
+ "./srcmap_sourcemap_wasm_bg.js": import0,
217
+ };
218
+ }
219
+
220
+ const SourceMapFinalization = (typeof FinalizationRegistry === 'undefined')
221
+ ? { register: () => {}, unregister: () => {} }
222
+ : new FinalizationRegistry(ptr => wasm.__wbg_sourcemap_free(ptr >>> 0, 1));
223
+
224
+ function addHeapObject(obj) {
225
+ if (heap_next === heap.length) heap.push(heap.length + 1);
226
+ const idx = heap_next;
227
+ heap_next = heap[idx];
228
+
229
+ heap[idx] = obj;
230
+ return idx;
231
+ }
232
+
233
+ function dropObject(idx) {
234
+ if (idx < 1028) return;
235
+ heap[idx] = heap_next;
236
+ heap_next = idx;
237
+ }
238
+
239
+ function getArrayI32FromWasm0(ptr, len) {
240
+ ptr = ptr >>> 0;
241
+ return getInt32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
242
+ }
243
+
244
+ function getArrayJsValueFromWasm0(ptr, len) {
245
+ ptr = ptr >>> 0;
246
+ const mem = getDataViewMemory0();
247
+ const result = [];
248
+ for (let i = ptr; i < ptr + 4 * len; i += 4) {
249
+ result.push(takeObject(mem.getUint32(i, true)));
250
+ }
251
+ return result;
252
+ }
253
+
254
+ let cachedDataViewMemory0 = null;
255
+ function getDataViewMemory0() {
256
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
257
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
258
+ }
259
+ return cachedDataViewMemory0;
260
+ }
261
+
262
+ let cachedInt32ArrayMemory0 = null;
263
+ function getInt32ArrayMemory0() {
264
+ if (cachedInt32ArrayMemory0 === null || cachedInt32ArrayMemory0.byteLength === 0) {
265
+ cachedInt32ArrayMemory0 = new Int32Array(wasm.memory.buffer);
266
+ }
267
+ return cachedInt32ArrayMemory0;
268
+ }
269
+
270
+ function getStringFromWasm0(ptr, len) {
271
+ ptr = ptr >>> 0;
272
+ return decodeText(ptr, len);
273
+ }
274
+
275
+ let cachedUint32ArrayMemory0 = null;
276
+ function getUint32ArrayMemory0() {
277
+ if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
278
+ cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
279
+ }
280
+ return cachedUint32ArrayMemory0;
281
+ }
282
+
283
+ let cachedUint8ArrayMemory0 = null;
284
+ function getUint8ArrayMemory0() {
285
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
286
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
287
+ }
288
+ return cachedUint8ArrayMemory0;
289
+ }
290
+
291
+ function getObject(idx) { return heap[idx]; }
292
+
293
+ function handleError(f, args) {
294
+ try {
295
+ return f.apply(this, args);
296
+ } catch (e) {
297
+ wasm.__wbindgen_export(addHeapObject(e));
298
+ }
299
+ }
300
+
301
+ let heap = new Array(1024).fill(undefined);
302
+ heap.push(undefined, null, true, false);
303
+
304
+ let heap_next = heap.length;
305
+
306
+ function passArray32ToWasm0(arg, malloc) {
307
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
308
+ getUint32ArrayMemory0().set(arg, ptr / 4);
309
+ WASM_VECTOR_LEN = arg.length;
310
+ return ptr;
311
+ }
312
+
313
+ function passStringToWasm0(arg, malloc, realloc) {
314
+ if (realloc === undefined) {
315
+ const buf = cachedTextEncoder.encode(arg);
316
+ const ptr = malloc(buf.length, 1) >>> 0;
317
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
318
+ WASM_VECTOR_LEN = buf.length;
319
+ return ptr;
320
+ }
321
+
322
+ let len = arg.length;
323
+ let ptr = malloc(len, 1) >>> 0;
324
+
325
+ const mem = getUint8ArrayMemory0();
326
+
327
+ let offset = 0;
328
+
329
+ for (; offset < len; offset++) {
330
+ const code = arg.charCodeAt(offset);
331
+ if (code > 0x7F) break;
332
+ mem[ptr + offset] = code;
333
+ }
334
+ if (offset !== len) {
335
+ if (offset !== 0) {
336
+ arg = arg.slice(offset);
337
+ }
338
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
339
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
340
+ const ret = cachedTextEncoder.encodeInto(arg, view);
341
+
342
+ offset += ret.written;
343
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
344
+ }
345
+
346
+ WASM_VECTOR_LEN = offset;
347
+ return ptr;
348
+ }
349
+
350
+ function takeObject(idx) {
351
+ const ret = getObject(idx);
352
+ dropObject(idx);
353
+ return ret;
354
+ }
355
+
356
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
357
+ cachedTextDecoder.decode();
358
+ function decodeText(ptr, len) {
359
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
360
+ }
361
+
362
+ const cachedTextEncoder = new TextEncoder();
363
+
364
+ if (!('encodeInto' in cachedTextEncoder)) {
365
+ cachedTextEncoder.encodeInto = function (arg, view) {
366
+ const buf = cachedTextEncoder.encode(arg);
367
+ view.set(buf);
368
+ return {
369
+ read: arg.length,
370
+ written: buf.length
371
+ };
372
+ };
373
+ }
374
+
375
+ let WASM_VECTOR_LEN = 0;
376
+
377
+ const wasmPath = `${__dirname}/srcmap_sourcemap_wasm_bg.wasm`;
378
+ const wasmBytes = require('fs').readFileSync(wasmPath);
379
+ const wasmModule = new WebAssembly.Module(wasmBytes);
380
+ let wasm = new WebAssembly.Instance(wasmModule, __wbg_get_imports()).exports;
@@ -0,0 +1,19 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __wbg_sourcemap_free: (a: number, b: number) => void;
5
+ export const sourcemap_generatedPositionFor: (a: number, b: number, c: number, d: number, e: number) => number;
6
+ export const sourcemap_lineCount: (a: number) => number;
7
+ export const sourcemap_mappingCount: (a: number) => number;
8
+ export const sourcemap_name: (a: number, b: number, c: number) => void;
9
+ export const sourcemap_names: (a: number, b: number) => void;
10
+ export const sourcemap_new: (a: number, b: number, c: number) => void;
11
+ export const sourcemap_originalPositionFor: (a: number, b: number, c: number) => number;
12
+ export const sourcemap_originalPositionsFor: (a: number, b: number, c: number, d: number) => void;
13
+ export const sourcemap_source: (a: number, b: number, c: number) => void;
14
+ export const sourcemap_sources: (a: number, b: number) => void;
15
+ export const __wbindgen_export: (a: number) => void;
16
+ export const __wbindgen_export2: (a: number, b: number) => number;
17
+ export const __wbindgen_export3: (a: number, b: number, c: number, d: number) => number;
18
+ export const __wbindgen_add_to_stack_pointer: (a: number) => number;
19
+ export const __wbindgen_export4: (a: number, b: number, c: number) => void;