Commit graph

3371 commits

Author SHA1 Message Date
Boshen
fde7d65992
fix(linter): handle named export default in import-plugin/named (#3158) 2024-05-04 17:40:56 +08:00
Boshen
b1bddacd09
fix(linter): fix hang if a file fails to parse while using --import-plugin 2024-05-04 17:16:43 +08:00
Boshen
222030c4c5
refactor(linter): render --rules in a table 2024-05-04 15:31:20 +08:00
Boshen
bf932be94f
chore(README): add sponsors 2024-05-04 10:57:53 +08:00
Boshen
cf2db1ef3a
ci: fix broken cargo bloat command 2024-05-04 00:03:21 +08:00
Wang Wenzhe
32df6d779c
feat(linter/tree-shaking): support While/Switch/Yield Statement (#3155)
All test cases passed now. There are something remain. I'll change the category when it's ready.

- [ ] Port [`isPureFuncion`](96f0d1c825/src/utils/helpers.ts (L53-L67)), [pure-function](198432ecc9/src/utils/pure-functions.ts) 
- [ ] Support [options](463fa1f0be/src/rules/no-side-effects-in-initialization.ts (L1130-L1138))
- [ ] Clean TODO
- [ ] Add more support of operator computation. [The original version](463fa1f0be/src/rules/no-side-effects-in-initialization.ts (L139-L210)) is straightforward benefit of JS. We only [support Number](f91a063616/crates/oxc_linter/src/utils/tree_shaking.rs (L194)) now.
2024-05-03 23:21:28 +08:00
Wang Wenzhe
8290421e72
feat(linter/tree-shaking): support SequenceExpression (#3154) 2024-05-03 23:19:36 +08:00
Wang Wenzhe
5c21b7f843
feat(linter/tree-shaking): support UnaryExpression (#3153) 2024-05-03 23:17:15 +08:00
renovate[bot]
56a0db8621
chore(deps): update dependency rust to v1.78.0 (#3151) 2024-05-03 00:01:42 +08:00
Yuji Sugiura
5a1d63afed
feat(linter/jsdoc): Implement require-yields rule (#3150)
Part of #1170 

>
https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-yields.md

With:

- Fix typo of JSDocPluginSettings
- Update utils/jsdoc
2024-05-02 22:49:19 +08:00
Yuji Sugiura
d7a8345e4c
feat(linter/jsdoc): Support settings.ignore(Private|Internal) (#3147)
>
https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/settings.md#user-content-settings-allow-tags-private-or-internal-to-disable-rules-for-that-comment-block

...and fixed the issue that intended initial settings values are not
used in some cases.
2024-05-01 19:48:28 +08:00
Wang Wenzhe
8cdd5b0fd8
feat(linter/tree_shaking): support LogicExpression and MemberExpression (#3148)
MemberExpression's message is not accurate, I will update later.
2024-05-01 19:46:40 +08:00
kaykdm
80cf0b2b2e
feat(linter): @typescript-eslint/prefer-literal-enum-member (#3134)
Related issue: https://github.com/oxc-project/oxc/issues/2180

original implementation

- code: https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/rules/prefer-literal-enum-member.ts
- test: https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/tests/rules/prefer-literal-enum-member.test.ts
- doc: https://typescript-eslint.io/rules/prefer-literal-enum-member/
2024-05-01 11:17:46 +08:00
Dunqing
a52e321b25
feat(transformer/jsx-source): get the correct lineNumber and columnNumber from the span. (#3142) 2024-05-01 00:30:47 +00:00
Boshen
bdae6b0e4e
chore(npm/oxc-parser): document parseOptions
closes #3114
2024-04-30 23:11:31 +08:00
Boshen
f5dccc96fd
refactor(coverage): avoid an String::from_utf8 over head during serialization (#3145) 2024-04-30 23:11:22 +08:00
Boshen
67225a8091
refactor(coverage): replace yaml parsing with saphyr (#3144)
closes #3128

Profiling `cargo run -p oxc_coverage -- parser` no longer shows a
bottleneck in yaml parsing
2024-04-30 22:49:39 +08:00
Dunqing
be8fabedab
feat(transformer/react): enable jsx plugin when development is true (#3141) 2024-04-30 15:48:17 +08:00
Boshen
a63a45d5b2
refactor(transformer): remove the requirement of Semantic (#3140)
It seems like we need to rebuild the scopes and symbols while
traversing. We can't utilize the scopes and symbols built by semantic
because they are immutable.
2024-04-30 12:48:21 +08:00
Wang Wenzhe
733361822e
feat(linter/tree-shaking): support JSX (#3139) 2024-04-30 11:25:39 +08:00
Wang Wenzhe
16a31e95b8
feat(linter/tree-shaking): support import statement (#3138) 2024-04-30 11:23:23 +08:00
Boshen
d76507699d
chore(transform_conformance): skip transform-destructuring (#3136) 2024-04-30 00:09:22 +08:00
Boshen
5a3f8a5811
feat(transform_conformance): handle parse error (#3135) 2024-04-30 00:07:53 +08:00
Dunqing
b5894964d1
fix(transformer/arrow-functions): should not transform this in class (#3129) 2024-04-29 13:44:10 +00:00
Boshen
f1ccbd4856
feat(syntax): add ToJsInt32 trait for f64 (#3132) 2024-04-29 21:13:04 +08:00
Boshen
870d11f1bb
feat(syntax): add ToJsString trait for f64 (#3131) 2024-04-29 21:00:04 +08:00
Boshen
a8af5de8f5
refactor(syntax): move number related functions to number module (#3130) 2024-04-29 18:54:35 +08:00
Dunqing
843318cdbe
refactor(transformer/typescript): reimplementation of Enum conversion based on Babel (#3102)
The remaining test cases will perform better with a scope
implementation, and while we can implement them without the scope, it
still requires us to do what the scope did.

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2024-04-29 16:26:22 +08:00
Dunqing
905ee3fef1
feat(transformer): add arrow-functions plugin (#3083)
close: #2983
2024-04-29 08:04:01 +00:00
renovate[bot]
6fd6170154
chore(deps): lock file maintenance rust crates (#3125) 2024-04-29 06:00:15 +00:00
Boshen
ae6561308c
refactor(syntax): use FxHashMap for ModuleRecord::request_modules (#3124)
closes #3121

The ordering is not important here.
2024-04-29 03:37:34 +00:00
renovate[bot]
14e4c58540
chore(deps): update pnpm to v9.0.6 (#3123)
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [pnpm](https://pnpm.io) ([source](https://togithub.com/pnpm/pnpm)) |
[`9.0.5` -> `9.0.6`](https://renovatebot.com/diffs/npm/pnpm/9.0.5/9.0.6)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/pnpm/9.0.6?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/pnpm/9.0.6?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/pnpm/9.0.5/9.0.6?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/pnpm/9.0.5/9.0.6?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>pnpm/pnpm (pnpm)</summary>

### [`v9.0.6`](https://togithub.com/pnpm/pnpm/compare/v9.0.5...v9.0.6)

[Compare Source](https://togithub.com/pnpm/pnpm/compare/v9.0.5...v9.0.6)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "before 8am on monday" in timezone
Asia/Shanghai, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/oxc-project/oxc).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zMjEuMiIsInVwZGF0ZWRJblZlciI6IjM3LjMyMS4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-29 09:37:30 +08:00
overlookmotel
514228ad42
deps(allocator): disable serde dep by default (#3120)
`oxc_allocator` currently depends on `serde`, although it's generally
not required.

This PR puts the dependency behind a feature `serialize`.

NB: `serde` is needed for the crate's tests, but this can be enabled by
adding it to `dev-dependencies` and putting the impls behind
`#[cfg(any(feature = "serialize", test))]`.
2024-04-28 22:17:32 +08:00
Wang Wenzhe
8f31ad618e
chore(linter/tree-shaking): uncomment function and identifier test cases (#3119) 2024-04-28 22:05:33 +08:00
overlookmotel
7e1fe36c68
refactor(ast): squash nested enums (#3115)
OK, this is a big one...

I have done this as part of work on Traversable AST, but I believe it
has wider benefits, so thought better to spin it off into its own PR.

## What this PR does

This PR squashes all nested AST enum types (#2685).

e.g.: Previously:

```rs
pub enum Statement<'a> {
    BlockStatement(Box<'a, BlockStatement<'a>>),
    /* ...other Statement variants... */
    Declaration(Declaration<'a>),
}

pub enum Declaration<'a> {
    VariableDeclaration(Box<'a, VariableDeclaration<'a>>),
    /* ...other Declaration variants... */
}
```

After this PR:

```rs
#[repr(C, u8)]
pub enum Statement<'a> {
    BlockStatement(Box<'a, BlockStatement<'a>>) = 0,
    /* ...other Statement variants... */

    VariableDeclaration(Box<'a, VariableDeclaration<'a>>) = 32,
    /* ...other Declaration variants... */
}

#[repr(C, u8)]
pub enum Declaration<'a> {
    VariableDeclaration(Box<'a, VariableDeclaration<'a>>) = 32,
    /* ...other Declaration variants... */
}
```

All `Declaration`'s variants are combined into `Statement`, but
`Declaration` type still exists.

As both types are `#[repr(C, u8)]`, and the discriminants are aligned, a
`Declaration` can be transmuted to a `Statement` at zero cost.

This is the same thing as #2847, but here applied to *all* nested enums
in the AST, and with improved helper methods.

No enums increase in size, and a few get smaller. Indirection is reduced
for some types (this removes multiple levels of boxing).

## Why?

1. It is a prerequisite for Traversable AST (#2987).
2. It would help a lot with AST Transfer (#2409) - it solves the only
remaining blocker for this.
3. It is a step closer to making the whole AST `#[repr(C)]`.

## Why is it a good thing for the AST to be `#[repr(C)]`?

Oxc's direction appears to be increasingly to build up control over the
fundamental primitives we use, in order to unlock performance and
features. We have our own allocator, our own custom implementations for
`Box` and `Vec`, our own `IndexVec` (TBC). The AST is the central
building block of Oxc, and taking control of its memory layout feels
like a step in this same direction.

Oxc has a major advantage over other similar libraries in that it keeps
all the AST data in an arena. This opens the door to treating the AST
either as Rust types or as *pure data* (just bytes). That data can be
moved around and manipulated beyond what Rust natively allows.

However, to enable that, the types need to be well-specified, with
completely stable layouts. `#[repr(C)]` is the only tool Rust provides
to do this.

Once the types are `#[repr(C)]`, various features become possible:

1. Cheap transfer of the AST across boundaries without ser/deser - the
property used by AST Transfer.
2. Having multiple versions of the AST (standard, read-only,
traversable), and these AST representations can be converted to one
other at zero cost via transmute - the property used by Traversable AST
scheme.
3. Caching AST data on disk (#3079) or transferring across network.
4. Stuff we haven't thought of yet!

Allowing the AST to be treated as pure data will likely unlock other
"next level" features further down the track (caching for "edge
bundling" comes to mind).

## The problem with `#[repr(C)]`

It's not *required* to squash nested enums to make the AST `#[repr(C)]`.

But the problem with `#[repr(C)]` is that it disables some compiler
optimizations. Without `#[repr(C)]`, the compiler squashes enums itself
in some cases (which is how `Statement` is currently 16 bytes). But
making the types `#[repr(C)]` as they are currently disables this
optimization.

So this PR essentially makes explicit what the compiler is already doing
- and in fact goes a bit further with the optimization than the compiler
is able to, in squashing 3 or 4 layers of nested enums (the compiler
only does up to 2 layers).

## Implementation

One enum "inheriting" variants from another is implemented with
`inherit_variants!` macro.

```rs
inherit_variants! {
#[repr(C, u8)]
pub enum Statement<'a> {
    BlockStatement(Box<'a, BlockStatement<'a>>),
    /* ...other Statement variants... */
    
    // `Declaration` variants added here by `inherit_variants!` macro
    @inherit Declaration
    // `ModuleDeclaration` variants added here by `inherit_variants!` macro
    @inherit ModuleDeclaration
}
}
```

The macro is *fairly* lightweight, and I think the above is quite easy
to understand. No proc macros.

The macro also implements utility methods for converting between enums
e.g. `Statement::as_declaration`. These methods are all zero-cost
(essentially transmutes).

New patterns for dealing with nested enums are introduced:

Creation:

```rs
// Old
let stmt = Statement::Declaration(Declaration::VariableDeclaration(var_decl));

// New
let stmt = Statement::VariableDeclaration(var_decl);
```

Conversion:

```rs
// Old
let stmt = Statement::Declaration(decl);

// New
let stmt = Statement::from(decl);
```

Testing:

```rs
// Old
if matches!(stmt, Statement::Declaration(_)) { }
if matches!(stmt, Statement::ModuleDeclaration(m) if m.is_import()) { }

// New
if stmt.is_declaration() { }
if matches!(stmt, Statement::ImportDeclaration(_)) { }
```

Branching:

```rs
// Old
if let Statement::Declaration(decl) = &stmt { decl.do_stuff() };

// New
if let Some(decl) = stmt.as_declaration() { decl.do_stuff() };
```

Matching:

```rs
// Old
match stmt {
    Statement::Declaration(decl) => visitor.visit(decl),
}

// New (exhaustive match)
match stmt {
    match_declaration!(Statement) => visitor.visit(stmt.to_declaration()),
}

// New (alternative)
match stmt {
    _ if stmt.is_declaration() => visitor.visit(stmt.to_declaration()),
}
```

New syntax has pluses and minuses vs the old. `match` syntax is worse,
but when working with a deeply nested enum, the code is much nicer -
it's shorter and easier to read.

This PR removes 200 lines from the linter with changes like this:


https://github.com/oxc-project/oxc/pull/3115/files#diff-dc417ff57352da6727a760ec6dee22de6816f8231fb69dbef1bf05d478699103L92-R95

```diff
- let AssignmentTarget::SimpleAssignmentTarget(simple_assignment_target) =
-     &assignment_expr.left
- else {
-     return;
- };
- let SimpleAssignmentTarget::AssignmentTargetIdentifier(ident) =
-     simple_assignment_target
+ let AssignmentTarget::AssignmentTargetIdentifier(ident) = &assignment_expr.left
else {
    return;
};
```
2024-04-28 20:40:37 +08:00
Boshen
264404431c
chore: fix renovate error "Use matchDepNames instead of matchPackageNames" 2024-04-28 14:49:23 +08:00
Vasilii A
dcda1f6128
fix(cli): update --format documentation (#3118)
Refs: #3039 #3044
2024-04-28 11:56:10 +08:00
Dunqing
c3d8a85eb5
feat(semantic): report that enum member must have initializer (#3113)
See
https://www.typescriptlang.org/play/?target=99#code/KYOwrgtgBAglDeAoKKoEMoF4oFk0BcALAOgGcBLEACgEYBKAGmVQCMmBfRRUSKAIQTMUGbACIaAJgDMopqihtEnRABtg+KADMwIAMZYoVOlgB8USVIDc3cNADCg+SK07dRuaw6IgA
2024-04-27 22:08:02 +08:00
Yuji Sugiura
1f12aee149
refactor(linter/jsdoc): Misc improvements (#3109)
- [x] Always use resolved_tag_name
- [x] Nits syntax, naming fixes
- [x] Split up utils
2024-04-27 21:47:33 +08:00
overlookmotel
17131d23b8
refactor(prettier): reduce recursion (#3112)
Use a loop rather than recursive function call.
2024-04-27 10:54:14 +08:00
谭光志
cd600fade4
feat(linter): add more "ban-ts-comment" test cases. (#3107)
https://github.com/oxc-project/oxc/issues/2934

| name           | passed | failed |
| -------------- | ------ | ------ |
| ts-expect-error| 14     | 20     |
| ts-ignore      | 15     | 20     |
| ts-nocheck     | 11     | 9      |
| ts-check       | 11     | 8      |
| total          | 51     | 57
2024-04-26 22:54:05 +08:00
Boshen
5d0f165f51
ci: "Coverage and check diff" -> "Check Conformance" 2024-04-26 21:31:44 +08:00
cinchen
bef8a71b9d
feat(linter): eslint-plugin-jest/require-hook (#3110)
part of https://github.com/oxc-project/oxc/issues/492

Rule Detail: [link](https://github.com/jest-community/eslint-plugin-jest/blob/main/src/rules/require-hook.ts)
2024-04-26 21:26:28 +08:00
Todor Andonov
388ee5135a
feat(linter): typescript-eslint/prefer-enum-initializers (#3097) 2024-04-26 21:09:05 +08:00
Ali Rezvani
51de41cc7a
fix(index): add example_generated to create the docs. (#3106)
This dummy feature is for generating the documentations made by macros, I've missed it in my initial fork.
2024-04-26 20:37:38 +08:00
Ali Rezvani
df2beb2d75
chore: make oxc_index dependency on serde optional. (#3103)
nothing fancy here, just a simple change.
2024-04-26 20:34:59 +08:00
Yuji Sugiura
5866086d17
feat(linter/jsdoc): Implement no-defaults rule (#3098)
Part of #1170

>
https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/no-defaults.md#repos-sticky-header
2024-04-26 00:03:21 +08:00
overlookmotel
0185eb2edc
refactor(ast): remove duplicate TSNamedTupleMember representation (#3101)
Removes duplicate representation of a `TSTupleElement` which is a
`TSNamedTupleMember`.

Closes #3100.
2024-04-25 19:16:24 +08:00
Boshen
78875b79fe
feat(transformer): implement typescript namespace (#3025)
Co-authored-by: Dunqing <dengqing0821@gmail.com>
2024-04-25 10:26:11 +00:00
Ali Rezvani
ac72d08592
chore: cleanup the dependencies on static_assertions and oxc_index. (#3095)
We used to export `static_assertions` as part of the `oxc_index`. It
would've made sense back when it was only a vessel for exporting other
crates - although even then it wouldn't make much sense other than being
convenient - Now with it turning into a port of `index_vec` and
potentially getting bigger as the result of specific needs of the
project; It makes much more sense to stop exporting it from `oxc_index`
and use the crate directly in places that used to use what `oxc_index`
were exporting.


PS: we may want to follow up this with an `oxc_asset` crate containing
our own set of assertion tools which would also export
`static_assertions`.
2024-04-25 16:56:23 +08:00