Commit graph

3832 commits

Author SHA1 Message Date
rzvxa
f2dfd667df feat(semantic/cfg): add iteration instructions. (#3566) 2024-06-13 07:36:20 +00:00
rzvxa
defef057e1 improvement(semantic/cfg): better control flow for switch statements. (#3547)
There was an issue similar to the one in loops see #3451 to #3453
2024-06-13 07:36:18 +00:00
rzvxa
9b3097147e improvement(semantic/cfg): rework error path. (#3519)
This PR aims to provide a more accurate error/finalization flow, I've nuked the old error path approach and rewrote it with more versatility in mind.

We used to visit the finalizer block twice and create 2 sets of AstNodes/Basic Blocks for them, This was there to differentiate between the error path finalizer and success path one. There is no longer a need for having 2 separate sets of nodes to do this differentiation.

As for the error path now we have 2 kinds of them, Everything is attached to an error block - even if it is not in a try-catch statement - this results in a lot of extra edges to keep track of these "Implicit" error blocks but I believe in future it can help us to track cross block error paths, For example, we can dynamically attach and cache the implicit error block of a function to its call site error path (either implicit or explicit).
2024-06-13 07:36:16 +00:00
Dunqing
59666e0127
fix(transformer): do not rename accessible identifier references (#3623)
close: #3620

In `Babel`, the expected output is:

```ts
var x = 10;
var Foo = function(Foo) {
       Foo[Foo['a'] = 10] = 'a';
       Foo[Foo['b'] = 10] = 'b';
       Foo[Foo['c'] = 30] = 'c';
       return Foo;
}(Foo || {});
```

IMO, `Foo.b + x` is enough, because `x` is not a const variable. The
output same as with `typescript`
2024-06-13 15:26:38 +08:00
Don Isaac
f96b6b18c9
build(website): use typescript (#3653)
Co-authored-by: Boshen <boshenc@gmail.com>
2024-06-13 15:02:32 +08:00
Boshen
1edcd87203
chore: change all usages of static_assertions to dev-dependencies (#3654) 2024-06-13 13:18:53 +08:00
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
Ali Rezvani
c4f47c985f
docs(README): change the website domain. (#3652) 2024-06-13 13:05:37 +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
Rihards Gravis
dbf7c3aaa2
fix(napi/parser): typescript types for Comment is out of order (#3646)
Fix `oxc-parser` Typescript type definition for `Comment` type where the
`type` and `value` have reversed types in place.
2024-06-13 00:20:26 +08:00
Boshen
14b44062c2
ci: pin typos to a specific version (#3647) 2024-06-13 00:04:46 +08:00
Boshen
c041e9d1a9
chore: bump test262, babel and TypeScript submodules (#3644) 2024-06-12 18:42:32 +08:00
Boshen
a798ff4e89
ci: add actions: write permission to release_crates 2024-06-12 18:00:50 +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
Boshen
8dcab3d3fb
chore: features_always_bump_minor = true for changelog 2024-06-12 17:38:05 +08:00
Boshen
bf19c7c895
chore: relax rustc-hash version 2024-06-12 17:31:24 +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
Boshen
9698be5479 chore(coverage): ignore eval related code in codegen runtime (#3628)
Properly misconfigured test setup for `eval`, but can't figure out where
2024-06-11 15:23:36 +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
1959930ee7
fix(coverage): fix clippy 2024-06-11 17:01:52 +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
Boshen
f9c08d1e28 feat(coverage): add --debug option for finding crash scene (#3622)
The `--debug` options turns off rayon and prints the paths so we can
find the crashing file by looking at the last printed out file.

closes #3497
2024-06-11 07:10:02 +00: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
Boshen
c95d691af6
ci: use node-version-file (#3607) 2024-06-10 22:06:09 +08:00