Interface SourceMapper

All Known Implementing Classes:
SourceMapV3

public interface SourceMapper
Maps positions in a transpiled (target) script back to positions in the original source. Attach an instance via CompileSpec.Builder.sourceMapper(SourceMapper) (or the equivalent on FunctionCompileSpec) so that line numbers in stack traces, the debugger source handoff, and parser error messages refer to the original source rather than the transpiled output.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the full text of the primary original source so the debugger can display it during compilation handoff.
    getSourceLineText(String sourcePath, int lineNumber)
    Returns the text of the given line within the named original source file.
    mapPosition(int targetLine, int targetColumn)
    Maps a target (line, column) position to the corresponding original-source position.
  • Method Details

    • mapPosition

      Position mapPosition(int targetLine, int targetColumn)
      Maps a target (line, column) position to the corresponding original-source position.
      Parameters:
      targetLine - 1-indexed line in the transpiled source
      targetColumn - 1-indexed column in the transpiled source
      Returns:
      the original-source position, or null if no mapping exists for this position
    • getSourceLineText

      String getSourceLineText(String sourcePath, int lineNumber)
      Returns the text of the given line within the named original source file. Used to populate parser error messages with the offending line from the original source.
      Parameters:
      sourcePath - the resolved source path (as returned in Position.getSourcePath())
      lineNumber - 1-indexed line number in the original source
      Returns:
      the line text, or null if the source is unknown, the line is out of range, or no original-source content is available
    • getPrimarySourceContent

      String getPrimarySourceContent()
      Returns the full text of the primary original source so the debugger can display it during compilation handoff. When the underlying source map references multiple sources, an implementation must pick one (typically the first) — this method does not enumerate them.
      Returns:
      the primary original source content, or null if it is not available