-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
Add optional support for source locations #63
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it will be not bad if we use the name for example location
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
sourceLocations
option, which is turned off by default, but when enabled, records source locations on each node in theloc
property. These each have astart
andend
property, which include aline
andcolumn
. Both lines and columns are 1-based, inclusive, which seems to match how most editors work.