Commit graph

2808 commits

Author SHA1 Message Date
Don Isaac
8f5655dfe6
feat(linter): add eslint/no-useless-constructor (#3594)
Co-authored-by: Boshen <boshenc@gmail.com>
2024-06-13 13:12:18 +08:00
Yuji Sugiura
70fc69b916
fix(semantic): Add Eq to CtxFlags (#3651)
I've just created example using `oxc_semantic`. 

> https://gist.github.com/leaysgur/bcb748daa665d1615eabda6967366d05

But it could not be compiled due to:

```
error: to use a constant of type `CtxFlags` in a pattern, `CtxFlags` must be annotated with `#[derive(PartialEq, Eq)]`
```

- 0.14.0: 🆖 
- ...
- 0.13.0: 🆖 
- 0.12.5: 🆗 

This change seems to fix this.
2024-06-13 13:04:42 +08:00
github-actions[bot]
95e0571c2e
Release crates v0.14.0 (#3643)
## [0.14.0] - 2024-06-12

### Breaking

* fix(codegen)!: remove the unecessary 4th argument from `Codegen::new`
(#3640)
* feat(ast)!: make `Trivias` clonable by adding `Arc` (#3638)

### Features

- f6d9ca6 linter: Add `eslint/sort-imports` rule (#3568) (Wang Wenzhe)
- 129f91e span: Port over more methods from TextRange (#3592) (Don
Isaac)

### Bug Fixes

- f8f6d33 ast: Correct `visited_node` attr for strict mode of arrow fns
(#3635) (overlookmotel)
- e6ad3fb diagnostics: Do not print ansi color codes in non-TTYs (#3624)
(Boshen)
- d65202d span: Correct doc comments (#3608) (overlookmotel)
- 35e267b transformer: Arrow function transform use UIDs for `_this`
vars (#3634) (overlookmotel)
- 39bdebc transformer: Arrow func transform maintain scope ID (#3633)
(overlookmotel)
- 5cb7e6a transformer: Arrow func transform use correct spans (#3630)
(overlookmotel)
- 0c4ccb4 transformer: Arrow function transform alter `</this>` (#3627)
(overlookmotel)
- 8d237c4 transformer: JSX source calculate correct column when Unicode
chars (#3615) (overlookmotel)
- 9e8f4d6 transformer: Do not add `__source` for generated nodes (#3614)
(overlookmotel)
- 0fb4c35 transformer: Use UID for JSX source filename var (#3612)
(overlookmotel)

### Performance

- 3a59294 transformer: React display name transform reduce Atom
allocations (#3616) (overlookmotel)
- f4c1389 transformer: Create `Vec` with capacity (#3613)
(overlookmotel)

### Refactor

- 0f92521 ast: Replace recursion with loop (#3626) (overlookmotel)
- 08f1010 ast: Make `AstBuilder` `Copy` (#3602) (overlookmotel)
- 84304b4 linter: Add a `ctx.module_record()` method (#3637) (Boshen)
- f98f777 linter: Add rule fixer (#3589) (Don Isaac)
- e90e6a2 minifier: Make `Prepass` `Copy` (#3603) (overlookmotel)
- 7d61832 semantic: Pass `Rc` by value (#3586) (overlookmotel)
- 89bcbd5 transformer: Move `BoundIdentifier` into helpers (#3610)
(overlookmotel)
- 5793ff1 transformer: Replace `&’a Trivias` with `Rc<Trivias>` (#3580)
(Dunqing)
- 509871f transformer: Comment for unimplemented `spec` option in arrow
fns transform (#3618) (overlookmotel)
- 4b2e3a7 transformer: Fix indentation (#3617) (overlookmotel)
- 3467e3d transformer: Remove outdated comment (#3606) (overlookmotel)
- a799225 transformer: Flatten file structure for React transform
(#3604) (overlookmotel)
- 70f31a8 transformer: Reduce branching in JSX transform (#3596)
(overlookmotel)
- 3ae567d transformer: Remove dead code (#3588) (overlookmotel)
- 60cbdec traverse: `generate_uid_in_root_scope` method (#3611)
(overlookmotel)

Co-authored-by: Boshen <Boshen@users.noreply.github.com>
2024-06-12 17:52:41 +08:00
kaykdm
29c78db358
feat(linter): implement @typescript-eslint/explicit-function-return-type (#3455)
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/explicit-function-return-type.ts
- test:
https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts
- doc: https://typescript-eslint.io/rules/explicit-function-return-type/

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2024-06-12 16:45:02 +08:00
Boshen
b58d8eb88f fix!(codegen): remove the unecessary 4th argument from Codegen::new (#3640) 2024-06-12 07:58:54 +00:00
Boshen
d77ec9f95a
chore: remove trailing whitespaces for all files; add .editorconfig (#3639) 2024-06-12 15:47:26 +08:00
overlookmotel
35e267ba17 fix(transformer): arrow function transform use UIDs for _this vars (#3634)
Change arrow function transform to use UIDs for `_this` vars, which can't clash with an existing binding.

I believe there are some problems with our current implementation, but have struggled to fix them due to weird interactions with TS transforms. Have added "TODO" comments, so we can return to this and fix them later on, once scopes in TS transforms are correct.

My failed attempt at fixing is on this branch: https://github.com/oxc-project/oxc/tree/transform-arrow-functions
2024-06-12 05:22:46 +00:00
overlookmotel
39bdebc90e fix(transformer): arrow func transform maintain scope ID (#3633)
In arrow function transform, set `scope_id` of new `function () {}` to `scope_id` of arrow function it replaces, and alter scope flags.
2024-06-12 05:22:43 +00:00
Boshen
f6752b482f
feat!(ast): make Trivias clonable by adding Arc (#3638)
This makes `Trivias` cloneable and stops us from using `Rc::new` and
`Rc::clone` everywhere.

`Trivias` is rarely cloned so an `Arc` should suffice.
2024-06-12 13:16:10 +08:00
Boshen
84304b4f8f refactor(linter): add a ctx.module_record() method (#3637) 2024-06-12 04:32:38 +00:00
overlookmotel
5cb7e6ae56 fix(transformer): arrow func transform use correct spans (#3630)
Arrow function transform generate output with correct spans.
2024-06-12 04:10:42 +00:00
keita hino
21d3425db0
feat(linter): typescript-eslint no-useless-empty-export (#3605)
partof: #2180

docs: https://typescript-eslint.io/rules/no-useless-empty-export/
code:
584db29ec4/packages/eslint-plugin/src/rules/no-useless-empty-export.ts
test:
ac397f1817/packages/eslint-plugin/tests/rules/no-useless-empty-export.test.ts

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2024-06-12 12:05:38 +08:00
overlookmotel
0c4ccb4906 fix(transformer): arrow function transform alter </this> (#3627)
Arrow function transform transforms `this` in `<this>` (JSX opening element), but was missing out transforming `</this>` (JSX closing element).
2024-06-12 02:59:22 +00:00
Yuji Sugiura
e32ce00bfb
feat(linter/jsdoc): Implement require-param-name rule (#3636)
Part of #1170 

>
https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-param-name.md
2024-06-12 10:55:37 +08:00
overlookmotel
f8f6d33722 fix(ast): correct visited_node attr for strict mode of arrow fns (#3635)
Correct the `#[visited_node]` attr on `ArrowFunctionExpression` to recognise strict mode functions.

This change has no effect at present as `Traverse` codegen currently ignores `strict_if`. But useful for it to be correct for if we codegen `Visit` / `VisitMut` later on (#3392).
2024-06-11 21:57:56 +00:00
overlookmotel
0f925210af
refactor(ast): replace recursion with loop (#3626)
Replace recursion with loop in
`JSXMemberExpression::get_object_identifier`.

Also add a mutable version
`JSXMemberExpression::get_object_identifier_mut`.
2024-06-11 21:56:08 +08:00
cinchen
85c3b83f5f
feat(linter): eslint-plugin-jest/max-nested-describes (#3585)
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/max-nested-describe.ts)
2024-06-11 20:13:31 +08:00
Boshen
0654400cfa
chore(linter): fix clippy 2024-06-11 16:52:02 +08:00
Boshen
b3d4a53396
chore(linter): fix merge conflict 2024-06-11 16:43:11 +08:00
Yuji Sugiura
110661cc80
feat(linter/jsdoc): Implement require-param-description (#3621)
Part of #1170

>
https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-param-description.md
2024-06-11 16:31:53 +08:00
Wang Wenzhe
f6d9ca6e47
feat(linter): add eslint/sort-imports rule (#3568)
Rule detail: https://eslint.org/docs/latest/rules/sort-imports
2024-06-11 16:31:14 +08:00
Boshen
e6ad3fbf16
fix(diagnostics): do not print ansi color codes in non-TTYs (#3624)
closes #3539

upstream issue https://github.com/zkat/miette/issues/380
2024-06-11 16:16:28 +08:00
overlookmotel
3a59294c72 perf(transformer): React display name transform reduce Atom allocations (#3616)
Re-use existing `Atom`s in React Display Name transform rather than writing duplicate strings into the arena.

Also add comments for where our implementation diverges from Babel's (in my opinion, ours is an improvement).
2024-06-11 06:41:19 +00:00
overlookmotel
8d237c49a9 fix(transformer): JSX source calculate correct column when Unicode chars (#3615)
Fix column number in JSX source transform, and add tests.

It was correct in all cases, except for when a Unicode character with code point above `0xFFFF` appears earlier on the line.

Such characters are:

* 4 bytes in UTF-8.
* 2 characters in UTF-16.
* 1 `char` in Rust.

Babel (which we're trying to match) uses count of UTF-16 characters for column number, whereas we were using count of Rust `char`s.
2024-06-11 06:41:18 +00:00
overlookmotel
9e8f4d60b5 fix(transformer): do not add __source for generated nodes (#3614)
JSX transform don't add `__source` to nodes which were generated (not present in source).

Following:
8e39f35eb9/packages/babel-plugin-transform-react-jsx-source/src/index.ts (L57-L64)
2024-06-11 06:41:16 +00:00
overlookmotel
f4c1389e99 perf(transformer): create Vec with capacity (#3613)
Tiny optimization. Where we know the required capacity of a `Vec`, initialize it with that capacity.
2024-06-11 06:41:15 +00:00
overlookmotel
0fb4c35083 fix(transformer): use UID for JSX source filename var (#3612)
React JSX Source transform generates a top-level variable `_jsxFileName` containing file path.

Previously this var name was hard-coded. Generate a UID instead to avoid clash with existing var called `_jsxFileName`. Add this binding to scopes.
2024-06-11 06:41:14 +00:00
overlookmotel
60cbdece65 refactor(traverse): generate_uid_in_root_scope method (#3611)
Add method on `TraverseCtx` for common case of creating a UID binding in root scope.
2024-06-11 06:41:12 +00:00
overlookmotel
89bcbd5b8d refactor(transformer): move BoundIdentifier into helpers (#3610)
Pure refactor. Move `BoundIdentifier` into helpers module so it can be reused by other transforms.
2024-06-11 06:41:11 +00:00
Dunqing
5793ff1986
refactor(transformer): replace &’a Trivias with Rc<Trivias> (#3580)
`Transformer` needs to borrow `Trivias`.
8be1cc8052 (r1630711060)
2024-06-11 13:23:41 +08:00
overlookmotel
509871f478 refactor(transformer): comment for unimplemented spec option in arrow fns transform (#3618)
Babel's arrow functions transform has a `spec` option which alters the behavior of the the transform significantly.

https://babel.dev/docs/babel-plugin-transform-arrow-functions

We don't yet support that option. Add a TODO comment to that effect.
2024-06-10 19:53:35 +00:00
overlookmotel
4b2e3a705e refactor(transformer): fix indentation (#3617)
Fix indentation.
2024-06-10 19:36:12 +00:00
overlookmotel
d65202d788
fix(span): correct doc comments (#3608)
Fix doc comments for `Span` methods. `Span` offsets are in bytes, not
characters.
2024-06-10 23:24:29 +08:00
overlookmotel
3467e3da8e refactor(transformer): remove outdated comment (#3606)
Remove a TODO comment where the do is done.

This was covered by #3258 and #3287.
2024-06-10 12:59:43 +00:00
overlookmotel
a799225471 refactor(transformer): flatten file structure for React transform (#3604)
Purely moving files around to flatten folder structure. No substantive changes to the content of the files themselves.
2024-06-10 12:59:41 +00:00
overlookmotel
e90e6a2a7c refactor(minifier): make Prepass Copy (#3603)
Similar to #3602. `Prepass<'a>` only contains `AstBuilder<'a>`, which only contains shared ref `&'a Allocator`. So make `Prepass` `Copy` and pass around `Prepass<'a>` instead of `&Prepass<'a>` (so avoiding extra indirection).
2024-06-10 11:17:45 +00:00
overlookmotel
08f1010dca refactor(ast): make AstBuilder Copy (#3602)
`AstBuilder` only contains a shared ref `&Allocator`. So make it `Copy` and pass around `AstBuilder<'a>` instead of `&AstBuilder<'a>` - 1 less level of indirection.

Hopefully this will have little effect on benchmarks as all `AstBuilder`'s methods are marked `#[inline]`, but this change will minimize impact if compiler decides not to inline for some reason.
2024-06-10 11:17:43 +00:00
Yuji Sugiura
d6370f19fe
feat(linter/jsdoc): Implement require-param-type rule (#3601)
Part of #1170

>
https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-param-type.md
2024-06-10 17:23:41 +08:00
Don Isaac
f98f7771d8
refactor(linter): add rule fixer (#3589)
Adds a new `RuleFixer` struct that gets passed to
`ctx.diagnostic_with_fix`.
2024-06-10 17:20:14 +08:00
overlookmotel
70f31a8953
refactor(transformer): reduce branching in JSX transform (#3596)
Small optimization to JSX transform. Replace 2 branches on
element/fragment with 1.
2024-06-10 12:41:02 +08:00
Don Isaac
129f91e444
feat(span): port over more methods from TextRange (#3592)
Ports over more utility methods from `TextRange`, as per feedback in
[this
comment](https://github.com/oxc-project/oxc/pull/3589#discussion_r1632169132)
from #3589
2024-06-10 00:59:00 +08:00
Don Isaac
f0b689d115
fix(linter): panic in jsdoc/require-param (#3590) 2024-06-08 18:44:22 -04:00
overlookmotel
3ae567de9d refactor(transformer): remove dead code (#3588)
Remove a commented-out line of dead code.
2024-06-08 12:54:58 +00:00
overlookmotel
fa116448c9 refactor(linter): pass Rc by value (#3587)
Same as #3586.
2024-06-08 11:19:02 +00:00
overlookmotel
7d61832284 refactor(semantic): pass Rc by value (#3586)
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.
2024-06-08 11:18:58 +00:00
github-actions[bot]
6bdd74c476
Release crates v0.13.5 (#3584)
## [0.13.5] - 2024-06-08

### Bug Fixes

- 48bb97e traverse: Do not publish the build script (Boshen)

Co-authored-by: Boshen <Boshen@users.noreply.github.com>
2024-06-08 16:44:50 +08:00
Boshen
060819894d
chore: crates should only publish src and examples directory 2024-06-08 16:35:16 +08:00
Boshen
4b67f8e45b
chore: only publish src 2024-06-08 16:31:47 +08:00
Boshen
48bb97e53a
fix(traverse): do not publish the build script 2024-06-08 16:31:21 +08:00
Don Isaac
3e694573df
up(linter): add fixer for no-useless-spread (#3583)
Only fixes array spreads for now.

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2024-06-08 11:38:38 +08:00