aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-tracing-utils/src/get_source_range_snippet.ts
blob: c1f6e3a4e9837b1e883aacbe0df630bec5703841 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { SourceRange, SourceSnippet } from './types';
import { utils } from './utils';

/**
 * Gets the source range snippet by source range to be used by revert trace.
 * @param sourceRange source range
 * @param sourceCode source code
 */
export function getSourceRangeSnippet(sourceRange: SourceRange, sourceCode: string): SourceSnippet {
    const sourceCodeInRange = utils.getRange(sourceCode, sourceRange.location);
    return {
        range: sourceRange.location,
        source: sourceCodeInRange,
        fileName: sourceRange.fileName,
    };
}