-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
feat: add startIndex
parser option
#16849
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/58201 |
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.
This seems ok to me
packages/babel-parser/src/options.ts
Outdated
options.startIndex = options.startColumn; | ||
} else if (process.env.BABEL_8_BREAKING) { | ||
throw new Error( | ||
"When `startColumn` is used with a `startLine > 1` you must also provide a `startIndex`.", |
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.
When startLine
is 2 and startColumn
is 0, we should still throw if startIndex
is undefined.
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.
@JLHwung are you suggesting just changing options.startColumn > 0
to options.startColumn >= 0
?
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.
👍 That should work for this case.
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.
Awesome, I've updated the pr 😄
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.
@JLHwung I've refactored the default/error checking code slightly and added another test.
I think it errors in all the cases we want now.
@DylanPiercey Thank you. This PR will be included in the next minor release. Could you prepare a docs PR? You can start by editing https://github.com/babel/website/blob/main/docs/parser.md. |
@JLHwung thanks for working with me on this! I've now added a PR for the docs website. |
8c65626
to
2ec1c13
Compare
startIndex
parser option
Currently @babel/parser supports
startColumn
andstartLine
but no way to ensure the correct location information for indexes (egstart
,end
andrange
on node,index
onloc
).This PR adds a new
startIndex
override which ensures all created position information on the AST is offset by thestartIndex
.