UNPKG

@storm-stack/core

Version:

A build toolkit and runtime used by Storm Software in TypeScript applications

58 lines (56 loc) 1.57 kB
import { __name } from './chunk-43IZMM3W.js'; import Diff from 'diff-match-patch'; var dmp = new Diff(); function generateSourceMap(id, source, transpiled) { if (!transpiled) { return; } const diff = dmp.diff_main(source.toString(), transpiled); dmp.diff_cleanupSemantic(diff); let offset = 0; for (let index = 0; index < diff.length; index++) { if (diff[index]) { const [type, text] = diff[index]; const textLength = text.length; switch (type) { case 0: { offset += textLength; break; } case 1: { source.prependLeft(offset, text); break; } case -1: { const next = diff.at(index + 1); if (next && next[0] === 1) { const replaceText = next[1]; const firstNonWhitespaceIndexOfText = text.search(/\S/); const offsetStart = offset + Math.max(firstNonWhitespaceIndexOfText, 0); source.update(offsetStart, offset + textLength, replaceText); index += 1; } else { source.remove(offset, offset + textLength); } offset += textLength; break; } } } } if (!source.hasChanged()) { return; } return { code: source.toString(), map: source.generateMap({ source: id, file: `${id}.map`, includeContent: true }) }; } __name(generateSourceMap, "generateSourceMap"); export { generateSourceMap }; //# sourceMappingURL=chunk-E3IP23TH.js.map //# sourceMappingURL=chunk-E3IP23TH.js.map