Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

How line and column of `SourceNode` instance related to the contained chunk(s)?

Open
#442 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Documentation
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript
Domain
documentation

Research direction

Start with the SourceNode API and the linked source-map PR #163. Check how the constructor's line and column values are handled when a chunk contains newlines, then document the observed behavior and the recommended handling for multi-line chunks.

Written by the indexing model from the issue text.

Description

Working on the PR that enables support of source-maps for peggyjs parsers I found that high-level SourceNode API is not documented enough. In particular, it is non-obvious would SourceNode constructor automatically recalculate lines if chunk parameter is a multi-line string?

I have the following simplified code for generating source-map:

let userSourceCodeInGrammar = `potentially
   multi
   line
   string`;
// Actual SourceNode used for mapping is behind a hierarchy of SourceNodes
let node = new SourceNode(
  null, null, grammarSource,
  [
    "some code before",
    // actual mapping
    new SourceNode(
      line, column, grammarSource,
      userSourceCodeInGrammar
    ),
    "some code after",
  ]
);

let { code, map } = node.toStringWithSourceMap();

In the result, the code contains content of the userSourceCodeInGrammar as-is, but map maps all strings in it to the (line, column) supplied to the SourceNode constructor.

How to correctly work with multi-line code chunks?

Dominant language
JavaScript
Stars
3.7k
Forks
370
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from mozilla/source-map

All issues in mozilla/source-map

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.