Add optional support for source locations#63
Conversation
Scrum
left a comment
There was a problem hiding this comment.
Thanks for your input - it's very cool. Could you please adjust a little PR
src/index.ts
Outdated
| }; | ||
|
|
||
| let lastIndex = 0; | ||
| function getLoc(index: number) { |
There was a problem hiding this comment.
I think it will be good if you take it into a separate method / file with explicit transmission of the required parameters.
I think it will be not bad if we use the name for example getLocation.
src/index.ts
Outdated
| const buf: NodeTag = {tag}; | ||
|
|
||
| if (options.sourceLocations) { | ||
| buf.loc = { |
There was a problem hiding this comment.
I think it will be not bad if we use the name for example location.
There was a problem hiding this comment.
Sure, if you prefer. loc is pretty commonly used e.g. in Babel and other parsers
|
Attempted to refactor into a separate file as requested. Let me know if you want other changes! |
Everything looks very cool. Can you add a description of this functionality to the documentation? |
…rser into source_locations
|
Done! |
Fixes #44.
This adds a
sourceLocationsoption, which is turned off by default, but when enabled, records source locations on each node in thelocproperty. These each have astartandendproperty, which include alineandcolumn. Both lines and columns are 1-based, inclusive, which seems to match how most editors work.