Skip to content

Off-by-one in column numbers when applying source maps #22

Description

@rmuratov

Problem

Browsers report column numbers in stack traces as 1-based, but the source-map library's originalPositionFor expects 0-based columns (lines are 1-based). In src/lib.ts:37 the column from the parsed stack frame is passed as-is:

result = bindings[file].consumer.originalPositionFor({ column, line })

Symmetrically, on output (generateStackTraceLine, src/lib.ts:44) the column returned by originalPositionFor is 0-based but is printed directly, while users expect the browser's 1-based convention.

Existing tests don't catch this because the default GREATEST_LOWER_BOUND bias usually resolves the +1-shifted column to the same mapping.

Suggested fix

  • Pass column - 1 into originalPositionFor.
  • Print column + 1 for mapped positions.
  • Add a test fixture where the off-by-one produces a visibly different result.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions