Commit graph

266 commits

Author SHA1 Message Date
branchseer
f159f60084
Make ast types covariant over the allocator lifetime. (#2943)
## Why

Due to the usage of `&'alloc mut T` in `oxc_allocator::Box`, and
`bumpalo::collections::Vec` in `oxc_allocator::Vec`, ast types are
currently invariant over their allocator lifetime `'a`. This prevents
`ouroboros` from generating `borrow_*` on ast type fields, leading to
the unfriendly `with_*` api:
c250b288ef/crates/oxc_parser/examples/multi-thread.rs (L82-L84)

## How

- For `oxc_allocator::Vec`, switch to `allocator_api2::vec::Vec`, which
has a covariant relationship with the allocator lifetime.
- For `oxc_allocator::Box`, use `std::ptr::NonNull` which is
specifically designed to be covariant. I don't use
`allocator_api2::boxed::Box` because it holds the allocator for
dropping, so the size is bigger.

## Downside

Now that `oxc_allocator::Box` uses the unsafe `NonNull`. It has to be a
private field to be safe. This make it impossible to do `Box(....)`
pattern matching.
2024-04-12 18:12:18 +08:00
Boshen
614f73b66c
Release crates v0.12.3 2024-04-11 16:18:17 +08:00
Yuji Sugiura
0a77d621e2
refactor(semantic/jsdoc): Rework JSDoc struct for better Span handling (#2917)
> 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
2024-04-10 14:32:51 +08:00
Boshen
09452659e2
Release crates v0.12.2 2024-04-08 11:13:13 +08:00
Don Isaac
1ea24ea0a7
fix(semantic): symbols inside functions and classes incorrectly flagged as exported (#2896)
# What This PR Does

Symbols declared inside exported functions and classes were being
incorrectly flagged with `SymbolFlags::Export`.

For example,
```ts
export function foo<T>(a: T) {
  let b = String(a)
  return b
}
```
`T`, `a`, and `b` were all flagged as exported.

## Further Work
It doesn't seem like exported enums and interfaces are being included in
`ModuleRecord`. Am I looking in the wrong place, or are they actually
missing?
2024-04-05 23:01:27 +08:00
Yuji Sugiura
aa63b6491f
feat(linter): Implement jsdoc/check-access (#2642)
Part of #1170, Finally... 🗻 

Some preparation PRs may be needed in advance.

- [x] settings.jsdoc #2706 
- [x] new struct design #2765
- [x] handle `Span` for diagnostics #2815

Implement plugin itself.

-
https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/check-access.md
-
https://github.com/gajus/eslint-plugin-jsdoc/blob/main/src/rules/checkAccess.js

I'll send a PR to make this plugin public after confirming that a few
more rules can be implemented without any problems.
2024-04-04 22:36:39 +08:00
Boshen
366a7fb0d4
Release crates v0.11.2 2024-04-03 19:36:54 +08:00
Boshen
54f7cd3978
Release crates v0.11.1 2024-04-03 16:57:52 +08:00
Don Isaac
d3eb1c3318
fix(semantic): flag function expressions with SymbolFlags::Function (#2891)
# What This PR Does

Consider the following code snippet

```js
const x = function y () {{
```

`y` will now be flagged with `SymbolFlags::Function`. This follow's
tsc's behavior.

- [Example in OXC
Playground](https://oxc-project.github.io/oxc/playground/?code=3YCAAICagICAgICAgICxG0qZRraXZOpcCHVsSRwDq2kRR0HprsTfRRT5WMw%2Ff2epoIA%3D)
- [Example in TypeScript AST
Viewer](https://ts-ast-viewer.com/#code/MYewdgzgLgBAHjAvDAZgVzMKBLcMCeAFAJQwDeAvgFBA)
2024-04-03 10:42:11 +08:00
Boshen
23d3c4e0a4
chore: add changelogs via git cliff (#2878)
This is generated alongside https://github.com/oxc-project/release-oxc
2024-04-01 20:04:48 +08:00
Boshen
31ed532b79
Release crates v0.11.0 2024-03-30 13:54:53 +08:00
Dunqing
df628289ff
fix(linter/import): ignore export declaration in no-duplicates (#2863) 2024-03-30 12:57:43 +08:00
Dunqing
1b5e544a36
refactor(semantic): distinguish whether requested_modules is type imports/exports (#2848) 2024-03-29 19:52:30 +08:00
Dunqing
947a9f05e8
fix(semantic): missing SymbolFlags::Export when identifier used in ExportDefaultDeclaration (#2837) 2024-03-27 14:13:25 +08:00
Boshen
95fc28168c
chore: apply cargo autoinherit (#2826)
See https://github.com/mainmatter/cargo-autoinherit
2024-03-26 23:57:50 +08:00
Yuji Sugiura
df744b205a
feat(semantic/jsdoc): Add Span for JSDoc, JSDocTag (#2815) 2024-03-26 18:40:31 +08:00
Dunqing
b28b61774b
fix(semantic): incorrect ExportEntry span for ExportAllDeclaration in ModuleRecord (#2793)
Now the span is ExportAllDeclaration's span
2024-03-25 10:32:02 +08:00
Dunqing
b6e493bd78
fix(semantic): ModuleRecord's indirect_export_entires missing reexported imports (#2792)
local_name has `name` and `span`. We can't directly compare
ExportEntry's local_name and ImportEntry's local_name. because the span
is never equal.
2024-03-25 04:50:04 +08:00
Dunqing
712b3d2a11
feat(semantic): distinguish type imports in ModuleRecord (#2785)
I am not sure moving `ImportOrExportKind` to `oxc-syntax` is a good
solution.
2024-03-23 21:38:17 +08:00
Yuji Sugiura
4a42c5fd7d
refactor(semantic/jsdoc): JSDocTag parser rework (#2765)
Address
https://github.com/oxc-project/oxc/pull/2642#issuecomment-2001950723


0fd67cb874/crates/oxc_semantic/src/jsdoc/parser/jsdoc_tag.rs (L3-L25)
2024-03-23 00:16:59 +08:00
Boshen
ef1108a749
chore: Rust v1.77.0 (#2781) 2024-03-21 17:21:57 +00:00
overlookmotel
75226f3b4a
chore: silence erroneous RA warnings for Tsify (#2731) 2024-03-15 12:42:12 +00:00
Boshen
a5ddb5b452
Release crates v0.10.0 2024-03-14 18:23:34 +08:00
Boshen
cbc2f5ff97
refactor: remove unused dependencies (#2718) 2024-03-14 17:50:31 +08:00
Boshen
697b6b70c0
feat: merge features serde and wasm to serialize (#2716)
This PR merges the previous confusing features `serde` and `wasm` into a
single `serialize` feature.

We'll eventually do serialize + type information for both wasm and napi
targets.

`oxc_macros` is removed from `oxc_ast`'s dependency because it requires
`syn` and friends, which goes against our policy ["Third-party
dependencies should be
minimal."](https://oxc-project.github.io/docs/contribute/rules.html#development-policy)
2024-03-14 17:13:12 +08:00
Yuji Sugiura
b00d4b8110
fix(semantic/jsdoc): Support multibyte chars (#2694)
Co-authored-by: Boshen <boshenc@gmail.com>
2024-03-13 19:00:01 +08:00
Boshen
0f86333437
refactor(ast): refactor Trivias API - have less noise around it (#2692) 2024-03-12 20:16:36 +08:00
overlookmotel
3c1e0db53f
refactor: reduce cfg_attr boilerplate with SerAttrs derive (#2669)
Closes #2641.

Also added `tsify` attribute to the `SerAttrs` derive macro, so `#[cfg_attr(feature = "wasm", tsify(...))]` can also be reduced to `#[tsify(...)]`.
2024-03-11 13:38:24 +08:00
overlookmotel
cba1e2f338
refactor(ast): import Tsify to shorten code (#2665)
Pure refactor. Import `tsify::Tsify` in files that use it, so then shorten a load of:

```diff
- #[cfg_attr(feature = "wasm", derive(tsify::Tsify))]
+ #[cfg_attr(feature = "wasm", derive(Tsify))]
```
2024-03-11 12:37:10 +08:00
Yuji Sugiura
2609e9021b
fix(semantic/jsdoc): Fix up builder (#2623)
- [x] Update `should_attach_jsdoc` definition
- [x] Update ~poem~ architecture decision comments
- [x] Refine tests
2024-03-08 10:49:51 +08:00
overlookmotel
d76ee6b2db
refactor: "wasm" feature enable "serde" feature (#2639)
Make `wasm` feature also enable `serde` feature. This allows shortening
a lot of `#[cfg_attr]`s.

As discussed in
https://github.com/oxc-project/oxc/pull/2638#issuecomment-1984066757.
2024-03-08 10:06:49 +08:00
overlookmotel
6b5723cdbe
refactor(ast): shorten manual TS defs (#2638)
Does the same thing, just (in my opinion) a little bit more readable.
2024-03-08 00:53:51 +08:00
Boshen
4f9dd98a97
feat(span): remove From<String> and From<Cow> API because they create memory leak (#2628)
closes #2621
2024-03-06 20:38:21 +08:00
Dunqing
57ce737b09
feat(semantic): move redeclare varaibles to symbol table (#2614)
close: #2219
2024-03-06 15:34:12 +08:00
overlookmotel
8001b2f796
refactor: make CompactStr immutable (#2620)
First step towards #2516.

This replaces `compact_str::CompactString` with an immutable interface `CompactStr`.

Currently just implemented as a wrapper around `CompactString` which hides all its mutation methods. A more optimized implementation to follow, which shrinks size of `CompactStr` to 16 bytes by removing the `capacity` field.

The rationale for the change of name is: `CompactString` is like `String` in that it's mutable. `CompactStr` is more like `str` - immutable - so its name mirrors `str`.
2024-03-06 12:29:32 +08:00
overlookmotel
0646bf34fa
refactor: rename CompactString to CompactStr (#2619)
Preparatory step for #2620.

This PR purely changes names of types and methods:

* `CompactString` -> `CompactStr`
* `Atom::to_compact_string` -> `to_compact_str`
* `Atom::into_compact_string` -> `into_compact_str`

Have split this into a separate PR as the diff is large, but it does absolutely nothing but renaming (I've checked the whole diff twice, so feel free not to check it again!). This should make it easier to see the content of the substantive change in #2620.
2024-03-06 12:24:23 +08:00
Boshen
cca6eb073c
Release crates v0.9.0 2024-03-05 15:57:31 +08:00
Dunqing
37de80d9c9
fix(semantic): jsx reference with an incorrect node id (#2546)
The get kind from the node id should be `JSXIdentifier`, but now it's `JSXOpeningElement`.
2024-03-01 21:07:57 +08:00
Yuji Sugiura
1391e4a86b
refactor(semantic/jsdoc): Misc fixes for JSDoc related things (#2531)
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... 🐰
2024-02-29 17:28:14 +08:00
Boshen
d41dcc316e
feat(linter): remove all commonjs logic for import plugin (#2537) 2024-02-28 18:13:44 +08:00
Dunqing
f760108094
feat(transformer): call build module record (#2529) 2024-02-28 14:35:35 +08:00
Boshen
c56b6cb643
refactor: replace InlinableString with CompactString for Atom (#2517)
relates #2516
2024-02-26 23:11:46 +08:00
Dunqing
1519b9000b
fix(semantic): incorrect scope for switch statement (#2513)
close: #2501
2024-02-26 22:54:19 +08:00
Boshen
be6b8b7ce6
[BREAKING CHANGE] Change Atom to Atom<'a> to make it safe (#2497)
Part of #2295

This PR splits the `Atom` type into `Atom<'a>` and `CompactString`.

All the AST node strings now use `Atom<'a>` instead of `Atom` to signify
it belongs to the arena.

It is now up to the user to select which form of the string to use.

This PR essentially removes the really unsafe code 


93742f89e9/crates/oxc_span/src/atom.rs (L98-L107)

which can lead to 

![image](https://github.com/oxc-project/oxc/assets/1430279/8c513c4f-19b0-4b63-b61c-e07c187c95b5)
2024-02-26 19:34:40 +08:00
Boshen
4fabe66621
Publish crates v0.8.0 2024-02-26 19:01:51 +08:00
Dunqing
4c2e2bdf61
fix(semantic): add export symbol flag to identifiers in export declarations (#2508)
Related PR: #2335
2024-02-26 15:48:05 +08:00
Boshen
fba66dcc75
fix(linter): improve import/no-named-as-default (#2494) 2024-02-25 21:24:08 +08:00
Boshen
f5aadc767f
feat(linter): handle cjs `module.exports = {} as default export (#2493) 2024-02-25 00:11:48 +08:00
Boshen
f64c7e04a3
feat(linter): handle cjs module.exports.foo = bar and exports.foo = bar (#2492) 2024-02-24 23:54:43 +08:00
Boshen
d0a9c465f7
feat(linter): handle top-level require for import plugin (#2491) 2024-02-24 21:48:23 +08:00