Commit graph

5953 commits

Author SHA1 Message Date
no-yan
07196ae0a8
perf(justfile): optimize submodule cloining with shallow fetch (#6292)
fix #6291, where `just submodules` takes around 8 minutes to clone
repositories.

This change reduces the clone time from around 8 minutes to 42 seconds
in reported scenario.
 
<img width="534" alt="image"
src="https://github.com/user-attachments/assets/bf74e412-f1ed-419e-b180-09ed96a8eb67">

<details><summary>Command log: time just submodules</summary>
<p>

```
❯ time just submodules
just clone-submodule tasks/coverage/test262 git@github.com:tc39/test262.git d62fa93c8f9ce5e687c0bbaa5d2b59670ab2ff60
cd tasks/coverage/test262 || git init tasks/coverage/test262
bash: 1 行: cd: tasks/coverage/test262: No such file or directory
Initialized empty Git repository in /Users/noyan/ghq/github.com/oxc-project/oxc/tasks/coverage/test262/.git/
cd tasks/coverage/test262 && git remote add origin git@github.com:tc39/test262.git || true
cd tasks/coverage/test262 && git fetch --depth=1 origin d62fa93c8f9ce5e687c0bbaa5d2b59670ab2ff60 && git reset --hard d62fa93c8f9ce5e687c0bbaa5d2b59670ab2ff60
remote: Enumerating objects: 53504, done.
remote: Counting objects: 100% (53504/53504), done.
remote: Compressing objects: 100% (19436/19436), done.
remote: Total 53504 (delta 39436), reused 39428 (delta 33947), pack-reused 0 (from 0)
Receiving objects: 100% (53504/53504), 12.32 MiB | 9.06 MiB/s, done.
Resolving deltas: 100% (39436/39436), done.
From github.com:tc39/test262
 * branch              d62fa93c8f9ce5e687c0bbaa5d2b59670ab2ff60 -> FETCH_HEAD
Updating files: 100% (51664/51664), done.
HEAD is now at d62fa93c [explicit-resource-management] Complete exception handling
just clone-submodule tasks/coverage/babel git@github.com:babel/babel.git 3bcfee232506a4cebe410f02042fb0f0adeeb0b1
cd tasks/coverage/babel || git init tasks/coverage/babel
bash: 1 行: cd: tasks/coverage/babel: No such file or directory
Initialized empty Git repository in /Users/noyan/ghq/github.com/oxc-project/oxc/tasks/coverage/babel/.git/
cd tasks/coverage/babel && git remote add origin git@github.com:babel/babel.git || true
cd tasks/coverage/babel && git fetch --depth=1 origin 3bcfee232506a4cebe410f02042fb0f0adeeb0b1 && git reset --hard 3bcfee232506a4cebe410f02042fb0f0adeeb0b1
remote: Enumerating objects: 36357, done.
remote: Counting objects: 100% (36357/36357), done.
remote: Compressing objects: 100% (21830/21830), done.
remote: Total 36357 (delta 8527), reused 30780 (delta 7455), pack-reused 0 (from 0)
Receiving objects: 100% (36357/36357), 9.34 MiB | 9.24 MiB/s, done.
Resolving deltas: 100% (8527/8527), done.
From github.com:babel/babel
 * branch              3bcfee232506a4cebe410f02042fb0f0adeeb0b1 -> FETCH_HEAD
Updating files: 100% (31735/31735), done.
HEAD is now at 3bcfee23 Fix printing of TS `infer` in compact mode (#16788)
just clone-submodule tasks/coverage/typescript git@github.com:microsoft/TypeScript.git a709f9899c2a544b6de65a0f2623ecbbe1394eab
cd tasks/coverage/typescript || git init tasks/coverage/typescript
bash: 1 行: cd: tasks/coverage/typescript: No such file or directory
Initialized empty Git repository in /Users/noyan/ghq/github.com/oxc-project/oxc/tasks/coverage/typescript/.git/
cd tasks/coverage/typescript && git remote add origin git@github.com:microsoft/TypeScript.git || true
cd tasks/coverage/typescript && git fetch --depth=1 origin a709f9899c2a544b6de65a0f2623ecbbe1394eab && git reset --hard a709f9899c2a544b6de65a0f2623ecbbe1394eab
remote: Enumerating objects: 69880, done.
remote: Counting objects: 100% (69880/69880), done.
remote: Compressing objects: 100% (52067/52067), done.
remote: Total 69880 (delta 17267), reused 39053 (delta 16227), pack-reused 0 (from 0)
Receiving objects: 100% (69880/69880), 32.80 MiB | 8.54 MiB/s, done.
Resolving deltas: 100% (17267/17267), done.
From github.com:microsoft/TypeScript
 * branch                a709f9899c2a544b6de65a0f2623ecbbe1394eab -> FETCH_HEAD
Updating files: 100% (72575/72575), done.
HEAD is now at a709f9899 Update deps, dprint plugins (#59810)
just clone-submodule tasks/prettier_conformance/prettier git@github.com:prettier/prettier.git 52829385bcc4d785e58ae2602c0b098a643523c9
cd tasks/prettier_conformance/prettier || git init tasks/prettier_conformance/prettier
bash: 1 行: cd: tasks/prettier_conformance/prettier: No such file or directory
Initialized empty Git repository in /Users/noyan/ghq/github.com/oxc-project/oxc/tasks/prettier_conformance/prettier/.git/
cd tasks/prettier_conformance/prettier && git remote add origin git@github.com:prettier/prettier.git || true
cd tasks/prettier_conformance/prettier && git fetch --depth=1 origin 52829385bcc4d785e58ae2602c0b098a643523c9 && git reset --hard 52829385bcc4d785e58ae2602c0b098a643523c9
remote: Enumerating objects: 10259, done.
remote: Counting objects: 100% (10259/10259), done.
remote: Compressing objects: 100% (6662/6662), done.
remote: Total 10259 (delta 970), reused 8226 (delta 696), pack-reused 0 (from 0)
Receiving objects: 100% (10259/10259), 12.85 MiB | 10.34 MiB/s, done.
Resolving deltas: 100% (970/970), done.
From github.com:prettier/prettier
 * branch            52829385bcc4d785e58ae2602c0b098a643523c9 -> FETCH_HEAD
HEAD is now at 5282938 Release 3.3.3
just submodules  1.56s user 12.29s system 32% cpu 42.408 total
``` 

</p>
</details> 

## Solution
To optimize the cloning process:
- Fetch only the specified commit, eliminating the need for a git clone
(which fetches HEAD and subsequently updates with differences).
- Initialize it with git init when the repository doesn't exist locally.
- Use `git fetch --depth=1` to prevent fetching previous commits.

See: https://stackoverflow.com/a/3489576

I initially suggested using `git fetch --depth=1`, but after testing, I
found that removing clone could speed up the process by about 20
seconds. Therefore, I've changed the approach.
2024-10-05 23:58:03 +08:00
overlookmotel
c7fbf686b9 refactor(transformer): logical assignment operator transform: no cloning identifier references (#6290)
Use `BoundIdentifier` to generate `IdentifierReference`s from, instead of cloning `IdentifierReference`s. This simplifies the code and is a less error-prone pattern.
2024-10-05 14:48:38 +00:00
overlookmotel
06797b6900 fix(transformer): logical assignment operator transform: fix reference IDs (#6289) 2024-10-05 14:48:37 +00:00
overlookmotel
e19deaa102 ci(transformer): move post-transform checker to tasks crate (#6288)
Move post-transform checker into a `tasks` crate. It doesn't feel like it belongs in `oxc_semantic`. It also feels like too heavy a lump of code to put in `tasks/common`.
2024-10-05 14:48:37 +00:00
overlookmotel
d4f2ee99c1 test(transformer): tidy up transform checker (#6287)
Pure refactor. Use `oxc_semantic`'s public APIs and shorten a few lines.
2024-10-05 14:48:36 +00:00
overlookmotel
0f5afd7ede test(transformer): transform checker output symbol name for mismatches (#6286)
Transform checker include symbol names in output for symbol mismatches. This is rather more helpful for locating bugs than just `SymbolId(3)`.
2024-10-05 14:42:06 +00:00
dalaoshu
d953a6be02
fix(minifier): correct the reference link (#6283)
These are minor changes, and recently I’ve been learning and trying to
implement some features of `oxc_minifier`, which feels a bit complex.

By the way, I’m wondering whether we should gradually add test cases
during the feature implementation process or just copy all the
corresponding tests directly? Perhaps we could implement something like
`rulegen` similar to `linter`?
2024-10-05 08:54:59 +08:00
overlookmotel
f0a74ca7c6 refactor(transformer): prefer create_bound_reference_id to create_reference_id (#6282)
`TraverseCtx::create_reference_id` is intended for when you don't know if a reference is bound or not. Replace uses of it with the more specific `create_bound_reference_id` and `create_unbound_reference_id`.
2024-10-04 15:25:31 +00:00
dalaoshu
841317538f
refactor(linter): move shared function from utils to rule (#6127)
I previously extracted the common parts of `prefer_to_be_truthy` and
`prefer_to_be_falsy` into `utils`. However, we should place
rule-specific logic that isn't general-purpose directly within the
respective rules.

Co-authored-by: Don Isaac <donald.isaac@gmail.com>
2024-10-04 23:24:08 +08:00
IWANABETHATGUY
9736aa0112 fix(oxc_transformer): define import.meta and import.meta.* (#6277)
1. related esbuild test
d34e79e2a9/internal/bundler_tests/bundler_default_test.go (L5077-L5119)
2024-10-04 14:22:56 +00:00
overlookmotel
ba3e85b157 refactor(transformer): fix spelling (#6279)
`property` not `proeperty`.
2024-10-04 13:44:59 +00:00
camchenry
50a0029a97 perf(linter): do not concat vec in no-useless-length-check (#6276)
Probably a very small win, but rather than making lots of small vecs and concatenating, we should just use one vec and then push to it as we visit nodes.
2024-10-04 04:41:59 +00:00
camchenry
ba9c372a15 refactor(linter): make jest/vitest rule mapping more clear (#6273)
- Renamed the `map_jest` method to make it more clear what it does, now called `map_jest_rule_to_vitest`
- Tried to use a `phf_set!` over a list of strings for checking if we should map rules. Probably not faster, but should be simpler a constant amount of work if we expand the list of rules in the future.
- Made it easier to not mess up the arguments to the `map_jest` function by making it accept a `RuleWithSeverity` instead of just strings.
2024-10-03 21:46:57 -04:00
camchenry
7ca70ddab6 docs(linter): add docs for ContextHost and LintContext (#6272)
- towards https://github.com/oxc-project/oxc/issues/5870

Adds some very basic docs for methods and properties related to `LintContext` and `ContextHost`.
2024-10-03 21:46:57 -04:00
Boshen
2f888ed871 feat(oxc): add napi transform options (#6268) 2024-10-03 13:36:38 +00:00
7086cmd
37cbabbac4 fix(minifier): should not handle the strict operation for bool comparison. (#6261) 2024-10-03 12:16:10 +00:00
7086cmd
fcb4651819 test(minifier): enable null comparison with bigint. (#6252) 2024-10-03 12:16:09 +00:00
H11
e0a3378864
fix(linter): correct false positive in unicorn/prefer-string-replace-all (#6263)
closes #6259
2024-10-03 12:58:09 +08:00
Boshen
f51cbadf93
ci: temporary disable windows due to napi failing
Running unittests src\lib.rs (target\debug\deps\oxc_coverage-c37180833952f95b.exe)
Load Node-API [napi_get_last_error_info] from host runtime failed: GetProcAddress failed
2024-10-03 12:39:32 +08:00
Boshen
aa0dbb6375 refactor(oxc): add napi feature, change napi parser to use oxc crate (#6265) 2024-10-03 04:28:38 +00:00
Yuji Sugiura
7e4fa337d9
chore(just): Fix typo to make just r works (#6264)
Apparently this is only happening on my end, but a typo is still a typo.
🙄
2024-10-03 11:41:52 +08:00
Boshen
7bb745b085
ci: add trigger monitor oxc in prepare_release_crates
closes https://github.com/oxc-project/monitor-oxc/issues/44
2024-10-03 11:19:53 +08:00
7086cmd
e29c0676d6 fix(minifier): handle exceeded shifts. (#6237)
Related: #6161, the last situation.

```js
// https://github.com/tc39/test262/blob/main/test/language/expressions/unsigned-right-shift/S9.6_A2.2.js
test((-2147483649 >>> 0) !== 2147483647)
```
2024-10-03 02:52:05 +00:00
leaysgur
5a73a663dc refactor(regular_expression)!: Simplify public APIs (#6262)
This PR makes 2 changes to improve the existing API that are not very useful.

- Remove `(Literal)Parser` and `FlagsParser` and their ASTs
- Add `with_flags(flags_text)` helper to `ParserOptions`

Here are the details.

> Remove `(Literal)Parser` and `FlagsParser` and their ASTs

Previously, the `oxc_regular_expression` crate exposed 3 parsers.

- `(Literal)Parser`: assumes `/pattern/flags` format
- `PatternParser`: assumes `pattern` part only
- `FlagsParser`: assumes `flags` part only

However, it turns out that in actual usecases, only the `PatternParser` is actually sufficient, as the pattern and flags are validated and sliced in advance on the `oxc_parser` side.

The current usecase for `(Literal)Parser` is mostly for internal testing.

There were also some misuses of `(Literal)Parser` that restore `format!("/{pattern}/{flags}")` back and use `(Literal)Parser`.

Therefore, only `PatternParser` is now published, and unnecessary ASTs have been removed.
(This also obsoletes #5592 .)

> Added `with_flags(flags_text)` helper to `ParserOptions`

Strictly speaking, there was a subtle difference between the "flag" strings that users were aware of and the "mode" recognised by the parser.

Therefore, it was a common mistake to forget to enable `unicode_mode` when using the `v` flag.

With this helper, crate users no longer need to distinguish between flags and modes.
2024-10-03 02:47:08 +00:00
camchenry
5957214f4c feat(linter): allow fixing in files with source offsets (#6197)
- fixes https://github.com/oxc-project/oxc/issues/5913

This PR fixes the calculation of spans when dealing with files that have multiple sources and non-zero source start offsets. This is almost always the case for `.vue`, `.astro`, and `.svelte` files. This enables us to correctly apply fixes for these file types both in the CLI with `oxlint` and also in editors like VS Code.

https://github.com/user-attachments/assets/2836c8bd-09be-4e59-801d-7c95f8c2491f

I'm open to ideas on how to improve testing in this area, as I don't think that we currently have any tests for fixing files end-to-end (beyond what the linter rules check). I did run this locally on the gitlab repository (which is written in Vue) and all of the fixes appeared to be applied correctly.
2024-10-03 00:53:30 +00:00
Boshen
294da86283
fix(napi/transform): fix index.d.ts 2024-10-03 08:52:10 +08:00
Boshen
099ff3a033 refactor(napi/transform): remove "Binding" from types; fix type error (#6260)
closes #6254
closes #6255
2024-10-03 00:44:07 +00:00
overlookmotel
32d972e2a4 refactor(parser)!: treat unambiguous files containing TS export assignments as modules (#6253)
An "unambiguous" TS source which contains an `export = <value>;` statement should be interpreted as an ES module.

This is in line with [this Babel test case](94e166782a/packages/babel-parser/test/fixtures/typescript/export/equals-in-unambiguous) which has [input option of `sourceType: "unambiguous"`](94e166782a/packages/babel-parser/test/fixtures/typescript/export/equals-in-unambiguous/options.json (L2)), and [outputs an AST with `sourceType: "module"`](94e166782a/packages/babel-parser/test/fixtures/typescript/export/equals-in-unambiguous/output.json (L7)).
2024-10-03 00:28:00 +00:00
overlookmotel
4f6bc79734 refactor(transformer)!: remove source_type param from Transformer::new (#6251)
Closes #6248.
2024-10-03 00:21:01 +00:00
7086cmd
115ccc941e feat(minifier): bitwise not in exceeded value. (#6235)
```rs
        test("x = ~2147483658.0", "x = 2147483637");
        test("x = ~-2147483658", "x = -2147483639");
```

Used `wrapping_neg`, and maybe it is a great solution for #6161.
2024-10-03 00:16:05 +00:00
Boshen
f98e12c13a feat(napi/transform): add inject plugin (#6250) 2024-10-02 15:15:51 +00:00
Boshen
d085c2cd25
chore: update license copyright holder 2024-10-02 22:37:53 +08:00
overlookmotel
bc757c89b4 refactor(transformer): move functionality of common transforms into stores (#6243)
In common transforms, move all functionality into the `*Store` structs. The `Traverse` impls become just thin wrappers which call into methods on the `*Store` structs.

I think this is clearer because now reading these files from top-to-bottom, you have the code that inserts into the stores before the code that reads from the stores and acts on it.
2024-10-02 14:13:48 +00:00
7086cmd
ee6c85003d feat(minifier): scaffold peephole replace known methods. (#6245) 2024-10-02 14:06:05 +00:00
7086cmd
c32af57e13 feat(minifier): fold demical bitwise not for bigint. (#6233)
Only demical first, because the rest bases are not natively supported by transforming from raw str.
2024-10-02 13:44:20 +00:00
7086cmd
23b646484c feat(minifier): fold true / false comparison. (#6225)
Input:
```js
a == false
```
Previous:
```js
a == !1
```
Current:
```js
a == 0
```

Only handle it when it is non-plus, non-relation binary expressions. Align with [Closure Compiler](https://closure-compiler.appspot.com/home#code%3D%252F%252F%2520%253D%253DClosureCompiler%253D%253D%250A%252F%252F%2520%2540compilation_level%2520SIMPLE_OPTIMIZATIONS%250A%252F%252F%2520%2540output_file_name%2520default.js%250A%252F%252F%2520%2540formatting%2520pretty_print%250A%252F%252F%2520%253D%253D%252FClosureCompiler%253D%253D%250Ax%2520%253C%253C%2520true%253B%250A%250Ax%2520%252B%2520true%253B%250A%250Ax%2520-%2520true%253B%250A%250Ax%2520%257C%2520true%253B%250A%250Ax%2520%2525%2520true%253B%250A%250Ay%2520!%253D%2520false%253B%250A%250Af()%2520%253D%253D%2520false%253B%250A%250Ax%2520instanceof%2520true%250A%250Ax%2520**%2520true%250A%250Ax%2520%2526%2520true%250A%250Ax%2520%255E%2520false%250A%250Ax%2520%253D%253D%2520(x%2520instanceof%2520false)%250A%250Ax%2520instanceof%2520(x%2520%253C%253C%2520true)%250A%250Ax%2520%253D%253D%2520fake(false)).
2024-10-02 13:37:17 +00:00
leaysgur
acab777c0a refactor(regular_expression): Misc fixes (#6234)
Preparation for #6141

- Keep `enum` size + add size asserts tests
- Arrange AST related directories
- Renaming
2024-10-02 13:32:29 +00:00
overlookmotel
1c31932f03 refactor(transformer): rename var in VarDeclarations common transform (#6242)
Pure refactor. Just rename a variable for clarity.
2024-10-02 11:38:27 +00:00
7086cmd
585ccdad8c feat(minifier): support subtraction assignment. (#6214)
Due to the potential for string concatenation when using the `+=` operator, we should only handle the scenario when using the `-=` operator.
2024-10-02 01:42:56 +00:00
dalaoshu
ea28ee9eda
fix(linter): improve the fixer of prefer-namespace-keyword (#6230)
closes #6204
2024-10-02 09:41:22 +08:00
yoho
a089e19cf9
feat(linter): eslint/no-else-return (#4305) 2024-10-01 19:09:58 -04:00
overlookmotel
0400ff9ea5 refactor(transformer): VarDeclarations common transform: check if at top level with ctx.parent() (#6231)
Micro-optimization. The stack of ancestors is now a `NonEmptyStack`, so `ctx.parent()` is now cheaper than `ctx.ancestors_depth()`.
2024-10-01 22:44:51 +00:00
DonIsaac
a949ecb052 docs(linter): improve docs for eslint/getter-return (#6229) 2024-10-01 19:38:24 +00:00
DonIsaac
d883562741 test(linter): invalid eslint/no-unused-vars options (#6228)
No behavior changes. Just test cases for invalid config objects.
2024-10-01 18:30:01 +00:00
overlookmotel
911e4e58ab ci(minifier): minifier benchmark measure only the minifier itself (#6222)
Minifier benchmark currently includes the time to run parser and semantic as well as the minifier itself. Similar to transformer benchmark, only measure the minifier itself in the benchmark.

This will give us a clearer picture of performance changes, and should also reduce variance in the benchmarks.
2024-10-01 17:43:39 +00:00
overlookmotel
4b42047fef fix(transformer): fix memory leak in ReplaceGlobalDefines (#6224)
`ReplaceGlobalDefines` was putting a `String` into the arena. `String` allocates on the heap, so this was a memory leak because it didn't get dropped when the allocator is dropped. This was caught by Miri.

Allocate a string slice instead.
2024-10-01 15:10:05 +00:00
overlookmotel
cc57541281 refactor(data_structures): NonEmptyStack::len hint that len is never 0 (#6220)
Tiny optimization. Make sure compiler knows that `NonEmptyStack::len` can never return 0.
2024-10-01 14:58:36 +00:00
overlookmotel
147a5d50fd refactor(data_structures): remove is_empty methods for non-empty stacks (#6219)
Remove `SparseStack::is_empty` method. It's pointless as the stack is never empty.

Add a dummy `NonEmptyStack::is_empty` method that always returns `false`. This is also pointless, but it overrides `slice::is_empty` which is otherwise accessible via `Deref`.
2024-10-01 14:58:35 +00:00
overlookmotel
3da0334396
ci(miri): run Miri on changes to more crates (#6223)
Run Miri when changes are made to crates which contain a lot of unsafe
code.
2024-10-01 22:56:05 +08:00
Boshen
291891e71a feat(napi/transform): add define option (#6212)
part of #6156
2024-10-01 12:57:29 +00:00