Pure refactor. Re-order `use` statements in `oxc_semantic` to follow this order:
1. `std`
2. External crates.
3. `oxc_*` crates.
4. Local crate.
5. `super`
6. `mod`
This is intended to be in order from "furthest above" to "furthest below".
Realized we can get the source type from the AST.
The next PR will introduce `unambiguous` to `SourceType` and directly set `Program::source_type` to either `script` or `module`.
Same as #3550.
`Rc<T>` is already a reference, so instead of passing an `&Rc<T>` to a function and then `Rc::clone()` it in the function, it's better to clone it first and pass `Rc<T>` to the function.
`Rc<T>` and `&Rc<T>` are both 8 bytes, so it introduces no additional overhead to the function call, and reduces indirection.
This is a very small optimization. Am only submitting these changes for purpose of code tidying - making the patterns around `Rc` consistent and optimal throughout the codebase.
We should probably look if we can remove some of these `Rc`s entirely and replace them with plain `&` refs. I suspect `Rc` is not actually required in most places and we're only using it to avoid dealing with lifetimes, but it's sub-optimal as `Rc::clone` has a cost, whereas copying a `&` ref has none.
This PR aims to support these cases.
````js
/**
* This is normal comment, `@xxx` should not parsed as tag.
*
* @example ```ts
// @comment
@decoratorInComment
class Foo { }
```
*/
````
Only `@example` should be parsed as tag.
> The error message emphasizes "empty text" so I would put the span on
the extra text.
> https://github.com/oxc-project/oxc/pull/2893#discussion_r1548843621
To address this, special `Span` handling should be implemented for
comment part.
So, this PR introduces:
- `JSDocCommentPart` struct holds raw `.span` and special
`.span_trimmed_first_line()`
- Add `JSDocKindPart`, `JSDocTypePart` and `JSDocTypeNamePart` in the
same manner
- `JSDocTag` uses these depending on the purpose
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... 🐰
Partial fix for #168
- [x] Fix general finding behavior for leading comments
- [x] Accept multiple jsdoc comments per node
- [x] Provide `get_one` and also `get_all`
- [x] Add `iter_all()` for non-node related usage
- [x] Limit AST node kinds to parse