Commit graph

368 commits

Author SHA1 Message Date
Boshen
bd9fc6d169
feat(transformer): react jsx transform (#2961) 2024-04-14 10:50:17 +08:00
Miles Johnson
e67355045e
feat(transformer): start on TypeScript annotation removal (#2951) 2024-04-13 18:49:54 +08:00
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
f903a225a8
feat(transformer): implement react-jsx-self (#2946) 2024-04-12 18:08:36 +08:00
Boshen
0c04bf743f
feat(transformer): transform TypeScript namespace (#2942) 2024-04-12 10:19:13 +08:00
Boshen
614f73b66c
Release crates v0.12.3 2024-04-11 16:18:17 +08:00
Boshen
59748199da
refactor(ast): clean up the ts type visit methods 2024-04-11 15:26:24 +08:00
Brad Zacher
6c0090882f
feat(oxc_ast): add missing ast visits for types (#2938)
Fixes #2936

*personally* I think it's best if all of the `_ => {}` match cases were
removed from the codebase so that things are provably exhaustive.
This does exactly that specifically for `walk_ts_type` - filling in the
missing cases and all the required code for them.
2024-04-11 07:11:00 +00:00
Boshen
09452659e2
Release crates v0.12.2 2024-04-08 11:13:13 +08:00
Boshen
fb2ebf462e
chore: fix clippy on unsafe comment 2024-04-03 19:57:21 +08:00
Boshen
366a7fb0d4
Release crates v0.11.2 2024-04-03 19:36:54 +08:00
Boshen
504698ab4a
chore: guard against unsafe code as much as possible. 2024-04-03 19:35:07 +08:00
Boshen
54f7cd3978
Release crates v0.11.1 2024-04-03 16:57:52 +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
Ali Rezvani
5f8f7f8d2f
fix(ast): FinallyClause won't get visited as BlockStatement anymore. (#2881)
This would fix the issue found in #2877,

As it is right now, the `FinallyClause` gets visited 2 times, once as
the Finally and once as a block.

This PR addresses this issue by making the `visit_finally_clause` method
visit the body statements instead of visiting the block itself. Now it
works similar to the `CatchClause`.
2024-04-01 10:25:50 +08:00
Boshen
31ed532b79
Release crates v0.11.0 2024-03-30 13:54:53 +08:00
Ali Rezvani
b76b02d019
fix(parser): add support for empty module declaration (#2834)
Should be merged after #2829, Tried a few times to get it done with
graphite stacking but found no success. I guess it either doesn't work
with forks or It is just a skill issue since I'm not familiar with it.

closes: #2829
closes: #2830

---------

Co-authored-by: Dmytro Maretskyi <maretskii@gmail.com>
2024-03-27 13:48:03 +08:00
Ali Rezvani
fc3878350f
refactor(ast): add walk_mut functions (#2776)
* move `visit` and `visit_mut` modules to a super module called `visit`
* add `walk_mut` module containing walk functions
* update `enter_node` and `leave_node` events to not pass a reference in the `VisitMut` trait
* add `AstType`, a non-referencing version of `AstKind` to use with `VisitMut` trait
* update the `VisitMut` trait's usages.
2024-03-25 20:40:13 +03:30
Ali Rezvani
198eea0bce
refactor(ast): add walk functions to Visit trait. (#2791)
closes #2442
2024-03-25 10:44:29 +08:00
Ali Rezvani
813226b648
refactor(ast): get rid of unsafe transmutation in VisitMut trait. (#2764)
This will close #2745,

In this PR I attempt to fix this issue using a combination of ideas
discussed in the issue mentioned above, I've created this early draft so
people can pitch in if there is something I should consider doing.

The first goal of this PR is to resolve the issue with the possible
illegal references, As a result of my approach it would also end up with
a bunch of walk_* and walk_*_mut functions to help with the abstraction.
I want to eliminate enter_node and leave_node functions, but I still
haven't started working on it since I first want to familiarize myself
with all of its usage throughout the project. I'm hesitating to do it at
the moment, When we want to do this it would require quite a bit of
refactoring so we should make sure it is probably going to work and end
up being a better implementation.
2024-03-23 13:48:30 +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
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
overlookmotel
c820a5b661
fix(ast): serialize empty array elements as null (#2707)
Serialize `ArrayExpressionElement::Elision` variant as `null` in JSON
AST, to align with ESTree.
2024-03-13 10:10:23 +00:00
Boshen
0d7bc8f255
feat(ast): fill in missing ast visits (#2705)
closes #2700
2024-03-13 16:31:01 +08:00
overlookmotel
acf127be35
fix(ast): correct TS type for ArrayAssignmentTarget (#2699)
`trailing_comma` field in JSON AST is camel case `trailingComma`.
2024-03-13 00:15:57 +00:00
overlookmotel
89e8d1526f
refactor: derive SerAttrs on all AST types (#2698)
Add `SerAttrs` derive to a few types that I missed out in #2669.
2024-03-13 00:14:04 +00:00
Boshen
0f86333437
refactor(ast): refactor Trivias API - have less noise around it (#2692) 2024-03-12 20:16:36 +08:00
overlookmotel
3305734b34
fix(ast): add type field to TS types for ObjectPattern etc (#2670)
Fixes #2658 (details given in https://github.com/oxc-project/oxc/issues/2657#issuecomment-1987289481).

Add `type` fields to TS types for `ObjectPattern`, `ArrayPattern` etc which were missing previously.
2024-03-11 13:42:28 +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
f27db301a9
fix(ast): fix TS type for AssignmentTargetRest (#2668)
Fix for #2657.
2024-03-11 12:42:45 +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
overlookmotel
d47f0e247d
fix(ast): rename TSIndexSignatureName in JSON AST (#2664)
Fixes #2656.
2024-03-10 17:11:28 +00:00
Arnaud Barré
c3477de64e
fix(ast)!: rename BigintLiteral to BigIntLiteral (#2659)
This matches the case for the name in Babel. (in ESTree everything is a
`Literal`)
2024-03-10 13:31:51 +08:00
overlookmotel
a01cf9f115
refactor(ast): remove Serialize impls for Identifier types (#2651)
`Serialize` can be derived for `IdentifierName` etc without explicit
`impl Serialize`, as they just need serde to skip some fields. No
changes to the JSON output, just a bit simpler.
2024-03-10 13:31:25 +08:00
Arnaud Barré
b453a072cc
fix(parser): parse named rest element in type tuple (#2655)
This is fixing the parser for `type X = [...args: string[]];`

In TSESLint TSNamedTupleMember in part of the TSType union, so I did the
same.
2024-03-10 13:25:15 +08:00
Arnaud Barré
776812315d
fix(parser)!: drop TSImportEqualsDeclaration.is_export (#2654)
This is one point where Babel and TSESLint diverge. For linter purposes
TSESLint structure makes more sense and that the reason of
https://github.com/typescript-eslint/typescript-eslint/issues/4130

The remaining `is_export` was creating redundant information and made
prettier (and the WIP oxc/prettier) print the AST of `export import X =
Y` as `export export import X = Y`.
2024-03-10 13:22:18 +08:00
overlookmotel
cc5be633f2
fix(ast): fix serializing rest elements (#2652)
Fix a mistake I made in #2567. Length that `serialize_seq` is called
with should only be `+1` if there is a rest element being added on the
end.

Makes no difference for serializing to JSON, as JSON serializer doesn't
use the `len` value, but still better to get it right.
2024-03-10 02:03:05 +00:00
overlookmotel
88f94bb6f6
fix(ast): add RestElements in serialized AST to elements array (#2567)
A step towards #2463.

This PR adds `rest` onto end of `elements` / `properties` array in JSON
AST for `ObjectPattern`, `ArrayPattern`, `ObjectAssignmentTarget`,
`ArrayAssignmentTarget` and `FormalParameters`.
2024-03-08 02:56:12 +00: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
Dunqing
308b780ff6
feat(transformer/decorators): handling the coexistence of class decorators and member decorators (#2636)
No snapshots have been updated. Because our output is a bit different
from babel's
<img width="961" alt="image"
src="https://github.com/oxc-project/oxc/assets/29533304/9926766c-b1ec-46c3-8c8f-53f053b14f84">
2024-03-07 16:52:30 +08:00
magic-akari
8e3e4043bc
feat(prettier): print with_clause in reexport declaration (#2635) 2024-03-07 14:24:16 +08:00
magic-akari
2a235d3b8c
fix(ast): parse with_clause in re-export declaration (#2634) 2024-03-07 14:09:31 +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
Boshen
cca6eb073c
Release crates v0.9.0 2024-03-05 15:57:31 +08:00
Boshen
49778abb80
fix(ast): temporary fix tsify not generating some typings (#2611)
seems like a bug in tsify
2024-03-05 14:13:28 +08:00
Boshen
1db307abbf
feat(ast): serialize BindingPattern to estree (#2610) 2024-03-05 13:48:43 +08:00
Arnaud Barré
f6709e4737
feat(ast): serialize identifiers to ESTree (#2521) 2024-03-04 14:53:33 +00:00
Boshen
20c7bf7835
feat(ast): add AssignmentTargetRest (#2601)
closes #2598
2024-03-04 14:31:22 +08:00