Fix source mapping of Window-style line breaks in presence of Unicode chars.
`content.chars().nth(i + 1)` gets the `i + 1`th *char*, but `i` is a byte offset not a char offset.
The replacement `content.as_bytes().get(i + 1)` gets the `i + 1`th *byte*, and should also be faster as doesn't require iterating through `chars` again.
#2565 added source map support in codegen. But there was a bug in creating the line offset tables for Unicode. This PR fixes that.
This function could probably be made more efficient, but I think this at least makes it correct.
`config_path` was not use in initialization.
Must merge #2568 before to fix vscode.
Co-authored-by: Clément Lafont <johnrazeur@MacBook-Pro-de-Clement.local>
Change behavior of `byte_search!` macro, to make it easier to understand and use:
1. `handle_match` removed. Macro instead evaluates to the first matching byte.
2. `handle_eof` does not return from enclosing function.
3. Alter syntax to make clear that `continue_if` and `handle_eof` are not closures, so can use `return` statements in them.
These changes enabled by #2552.
This PR greatly simplifies the `byte_search!` macro.
Mainly removing `cold_branch()` from the "not enough bytes remaining for a batch" branch, which allows refactoring so that `handle_match` and `continue_if` don't need to be repeated twice.
Result for performance is inconsistent - a little better on some benchmarks, a little worse on others. But not by significant amounts either way. In my view, the benefit of making the macro simpler outweighs a small speed loss anyway.
Sorry for the rather large size of PR. 😓 But essentially, not changed so
much.
#### 1. Reorganize directories and namings
```
src/jsdoc
├── builder.rs 👈🏻 for SemanticBuilder
├── finder.rs 👈🏻 `semantic.jsdoc()`
├── mod.rs
└── parser
├── jsdoc.rs 👈🏻 `JSDoc` struct which has `comment` and `tags`
├── jsdoc_tag.rs 👈🏻 `JSDocTag` struct
├── mod.rs
├── parse.rs 👈🏻 parsing logic by `JSDocParser`
└── utils.rs
```
Now `mod.rs` has only export things.
#### 2. Introduce `JSDocTagKind::Unknown(name)`
We need to keep their name as-is to check valid tag names are used.(e.g.
`jsdoc/check-tag-names` rule)
#### 3. Support multiline description
- Comment for JSDoc
- Comment for each JSDocTag
```js
/**
* @foo this comment continues
* here but leading * should be ignored!!
*/
```
- - -
Please correct me if I am doing something wrong... 🐰
Speed up lexing template strings.
This was the last use of `AutoCow` remaining in the lexer, and it's now removed.
Implementation is quite complex, to avoid repeatedly branching on whether an unescaped string is required or not (the way `AutoCow` did). I tried to simplify it down to a single function, but this hurt performance significantly.
Benchmarks do not show much movement, but I believe that's because there aren't many template strings in the benchmarks. Where there are template strings, I believe this speeds up lexing them significantly.
Simplify lexing JSX string attributes. As the search is purely for 1
byte value (the closing quote), and so doesn't require a byte table, use
`memchr`.
This change doesn't really register on benchmarks, but it's one step
closer to removing `AutoCow`, and transitioning all the searches in the
lexer to byte-by-byte.