feat: add startIndex parser option#16849
Conversation
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/58201 |
| 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.
When startLine is 2 and startColumn is 0, we should still throw if startIndex is undefined.
There was a problem hiding this comment.
@JLHwung are you suggesting just changing options.startColumn > 0 to options.startColumn >= 0?
There was a problem hiding this comment.
👍 That should work for this case.
There was a problem hiding this comment.
Awesome, I've updated the pr 😄
There was a problem hiding this comment.
@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
startColumnandstartLinebut no way to ensure the correct location information for indexes (egstart,endandrangeon node,indexonloc).This PR adds a new
startIndexoverride which ensures all created position information on the AST is offset by thestartIndex.