oxc/crates/oxc_parser
overlookmotel f3470163d9
refactor(parser): make Source::set_position safe (#2341)
Make `Source::set_position` a safe function.

This addresses a shortcoming of #2288.

Instead of requiring caller of `Source::set_position` to guarantee that the `SourcePosition` is created from this `Source`, the preceding PRs enforce this guarantee at the type level.

`Source::set_position` is going to be a central API for transitioning the lexer to processing the source as bytes, rather than `char`s (and the anticipated speed-ups that will produce). So making this method safe will remove the need for a *lot* of unsafe code blocks, and boilerplate comments promising "SAFETY: There's only one `Source`", when to the developer, this is blindingly obvious anyway.

So, while splitting the parser into `Parser` and `ParserImpl` (#2339) is an annoying change to have to make, I believe the benefit of this PR justifies it.
2024-02-08 14:56:26 +08:00
..
examples chore(parser): add visitor example (#2271) 2024-02-02 17:08:00 +08:00
src refactor(parser): make Source::set_position safe (#2341) 2024-02-08 14:56:26 +08:00
Cargo.toml parser(refactor): promise only one Source on a thread at a time (#2340) 2024-02-08 14:51:17 +08:00