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 to use source map? #278

Open
physikerwelt opened this issue Jun 7, 2022 · 4 comments
Open

How to use source map? #278

physikerwelt opened this issue Jun 7, 2022 · 4 comments
Labels
documentation Improvements or additions to documentation

Comments

@physikerwelt
Copy link

I implemented the source map feature, but I was unable to set breakpoints in the pegjs file which would stop the program (using webstorm). Also, my collaborator was unable to find someone who knows how to use the generated map file in a node.js context.

Is there some general interest in understanding how the generated maps can be used in IDEs? I think it would be helpful to have a step by step guide on how to use the maps in the examples so that one can differentiate if the generated map was faulty or if the IDE does not support that feature.

@hildjj hildjj added the documentation Improvements or additions to documentation label Jun 7, 2022
@hildjj
Copy link
Contributor

hildjj commented Jun 7, 2022

I've labelled this documentation, but I bet we'll run into several issues as we create those docs. Source maps should also get a lot easier to use for breakpoints in when #240 lands.

In the meantime, see if -m inline works?

@physikerwelt
Copy link
Author

Thank you with -m inline it works out of the box with webstorm. Maybe I find a way to use the -m inline option from within the API.

@hildjj
Copy link
Contributor

hildjj commented Jun 7, 2022

I'm going to leave this issue as documentation, then start a new issue for getting the inline output out of the API. In the meantime, this is roughly what the CLI is doing:

const res = peggy.generate("foo = 'foo'", {
  output: "source-and-map",
});

const sourceMap = res.toStringWithSourceMap();
const json = sourceMap.map.toJSON();
const buf = Buffer.from(JSON.stringify(json));
console.log(sourceMap.code + `\
//\x23 sourceMappingURL=data:application/json;charset=utf-8;base64,${buf.toString("base64")}
`);

@physikerwelt
Copy link
Author

Thank you. My issue has been resolved and I was able to use breakpoints in the generated code.

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

No branches or pull requests

2 participants