MCPcopy Create free account
hub / github.com/CashScript/cashscript / sourceMapToLocationData

Function sourceMapToLocationData

packages/utils/src/source-map.ts:82–115  ·  view source on GitHub ↗
(sourceMap: string)

Source from the content-addressed store, hash-verified

80}
81
82export const sourceMapToLocationData = (sourceMap: string): FullLocationData => {
83 let prevStartLine = 0;
84 let prevStartColumn = 0;
85 let prevEndLine = 0;
86 let prevEndColumn = 0;
87 let prevHint: PositionHint = PositionHint.START;
88
89 return sourceMap.split(';').map((entry: string) => {
90 const [startLineStr, startColumnStr, endLineStr, endColumnStr, positionHintStr] = entry.split(':');
91
92 const startLine = startLineStr ? Number(startLineStr) : prevStartLine;
93 prevStartLine = startLine;
94
95 const startColumn = startColumnStr ? Number(startColumnStr) : prevStartColumn;
96 prevStartColumn = startColumn;
97
98 const endLine = endLineStr ? Number(endLineStr) : prevEndLine;
99 prevEndLine = endLine;
100
101 const endColumn = endColumnStr ? Number(endColumnStr) : prevEndColumn;
102 prevEndColumn = endColumn;
103
104 const hint: PositionHint = parsePositionHint(positionHintStr) ?? prevHint;
105 prevHint = hint;
106
107 return {
108 location: {
109 start: { line: startLine, column: startColumn },
110 end: { line: endLine, column: endColumn },
111 },
112 positionHint: hint,
113 };
114 });
115};
116
117const parsePositionHint = (hint: string): PositionHint | undefined => {
118 if (hint === '1') return PositionHint.END;

Callers 5

compileStringFunction · 0.90
source-map.test.tsFile · 0.85
buildLineToOpcodesMapFunction · 0.85
formatBitAuthScriptFunction · 0.85

Calls 1

parsePositionHintFunction · 0.85

Tested by

no test coverage detected