CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-istanbul-lib-source-maps

Source maps support for Istanbul code coverage toolkit, enabling accurate coverage reporting for transpiled JavaScript code

Overall
score

98%

Overview
Eval results
Files

task.mdevals/scenario-5/

Source Map Position Mapper

Build a utility that maps code locations from transpiled/generated JavaScript back to their original source positions using source maps.

Background

When debugging transpiled JavaScript code, developers need to map stack trace locations from generated code back to the original source. Your task is to build a simple utility that takes source map data and performs position mapping for code locations.

Requirements

Create a Node.js module that performs source map position lookups. The module should:

  1. Accept source map data (as an object) along with a position in the generated code
  2. Map the generated position to the corresponding position in the original source
  3. Return the original file path, line, and column numbers
  4. Handle cases where a position cannot be mapped

The module should work with standard source map objects that contain version, sources, sourcesContent, mappings, and names fields.

Test Cases

  • Given a source map with a mapping at line 1, column 50 that maps to "src/index.ts" line 5, column 10, looking up line 1, column 50 returns the correct original position @test
  • Given a source map, looking up a position that has no mapping (e.g., empty line, comment) returns null or undefined @test
  • Given a source map with multiple source files, looking up positions correctly identifies which source file each position maps to @test

Implementation

@generates

API

/**
 * Maps a position in generated code to its original source location.
 *
 * @param {Object} sourceMapData - Source map object with version, sources, mappings, etc.
 * @param {number} line - Line number in generated code (1-based)
 * @param {number} column - Column number in generated code (0-based)
 * @returns {Object|null} Original position with { source, line, column } or null if no mapping
 */
function mapPosition(sourceMapData, line, column) {
  // Implementation here
}

module.exports = {
  mapPosition
};

Dependencies { .dependencies }

istanbul-lib-source-maps { .dependency }

Provides source map support for position mapping and transformation utilities.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-istanbul-lib-source-maps

tile.json