diff options
| author | 2022-03-11 03:09:57 -0800 | |
|---|---|---|
| committer | 2022-03-11 03:09:57 -0800 | |
| commit | 313ad01e4213f0297221fef0c2ba454244b40c55 (patch) | |
| tree | 0777573f29507b230ec5e9096c3d6c58934bf62c /packages/bun-error/sourcemap.ts | |
| parent | 44b0c8153a7092f97c36c5aab82b692f672c3ddf (diff) | |
| download | bun-313ad01e4213f0297221fef0c2ba454244b40c55.tar.gz bun-313ad01e4213f0297221fef0c2ba454244b40c55.tar.zst bun-313ad01e4213f0297221fef0c2ba454244b40c55.zip | |
fix bug with freeing typed arrays
Diffstat (limited to 'packages/bun-error/sourcemap.ts')
| -rw-r--r-- | packages/bun-error/sourcemap.ts | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/packages/bun-error/sourcemap.ts b/packages/bun-error/sourcemap.ts index 827231490..23bd4cf8a 100644 --- a/packages/bun-error/sourcemap.ts +++ b/packages/bun-error/sourcemap.ts @@ -233,7 +233,7 @@ export function remapPosition( const index = indexOfMapping(decodedMappings, line, column); if (index === -1) return null; - return [decodedMappings[index + 3], decodedMappings[index + 4]]; + return [decodedMappings[index + 3] + 1, decodedMappings[index + 4]]; } async function fetchRemoteSourceMap(file: string, signal) { @@ -255,6 +255,7 @@ async function fetchRemoteSourceMap(file: string, signal) { export var sourceMappings = new Map(); export function fetchMappings(file, signal) { + if (file.includes(".bun")) return null; if (sourceMappings.has(file)) { return sourceMappings.get(file); } @@ -267,6 +268,48 @@ export function fetchMappings(file, signal) { }); } +// this batches duplicate requests +export function fetchAllMappings(files, signal) { + var results = new Array(files.length); + var map = new Map(); + for (var i = 0; i < files.length; i++) { + const existing = map.get(files[i]); + if (existing) { + existing.push(i); + } else map.set(files[i], [i]); + } + + for (const [file, indices] of [...map.entries()]) { + const mapped = fetchMappings(file, signal); + if (mapped.then) { + var resolvers = []; + for (let i = 0; i < indices.length; i++) { + results[indices[i]] = new Promise((resolve, reject) => { + resolvers[i] = (res) => resolve(res ? [res, i] : null); + }); + } + + mapped.finally((a) => { + for (let resolve of resolvers) { + try { + resolve(a); + } catch { + } finally { + } + } + resolvers.length = 0; + resolvers = null; + }); + } else { + for (let i = 0; i < indices.length; i++) { + results[indices[i]] = mapped ? [mapped, indices[i]] : null; + } + } + } + + return results; +} + function indexOfMapping(mappings: Int32Array, line: number, column: number) { // the array is [generatedLine, generatedColumn, sourceIndex, sourceLine, sourceColumn, nameIndex] // 0 - generated line |
