UNPKG

@remotion/studio

Version:

APIs for interacting with the Remotion Studio

54 lines (53 loc) 1.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getOriginalLocationFromStack = void 0; const source_map_1 = require("source-map"); const get_source_map_1 = require("../../../error-overlay/react-overlay/utils/get-source-map"); const get_location_of_sequence_1 = require("../../../helpers/get-location-of-sequence"); const waiters = []; const sourceMapConsumerCache = {}; const isCreating = {}; const getSourceMapCache = async (fileName) => { if (sourceMapConsumerCache[fileName]) { return sourceMapConsumerCache[fileName]; } if (isCreating[fileName]) { return new Promise((resolve) => { waiters.push({ id: String(Math.random()), forFileName: fileName, resolve, }); }); } isCreating[fileName] = true; const res = await fetch(`${fileName}.map`); const json = await res.json(); const map = await new Promise((resolve) => { source_map_1.SourceMapConsumer.with(json, null, (consumer) => { resolve(consumer); }); }); waiters.filter((w) => { if (w.forFileName === fileName) { w.resolve(map); return false; } return true; }); sourceMapConsumerCache[fileName] = map; isCreating[fileName] = false; return map; }; const getOriginalLocationFromStack = async (stack, type) => { const location = type === 'sequence' ? (0, get_location_of_sequence_1.getLocationOfSequence)(stack) : (0, get_location_of_sequence_1.getLocationOfFunctionCall)(stack, 'visualControl'); if (!location) { return null; } const map = await getSourceMapCache(location.fileName); const originalPosition = (0, get_source_map_1.getOriginalPosition)(map, location.lineNumber, location.columnNumber); return originalPosition; }; exports.getOriginalLocationFromStack = getOriginalLocationFromStack;