Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Mingun opened this issue Jun 26, 2021 · 0 comments

Comments

@Mingun
Copy link

Mingun commented Jun 26, 2021

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant