Commit graph

7832 commits

Author SHA1 Message Date
Yuji Sugiura
64d38b86b6
refactor(prettier): Verify printing class related nodes (#8559)
Part of #5068
2025-01-17 13:46:07 +08:00
overlookmotel
30a869ead2 perf(semantic): use oxc_allocator::HashMap in ScopeTree (#8554)
Use `oxc_allocator::HashMap` in `ScopeTree`, replacing `hashbrown::HashMap`. `oxc_allocator::HashMap` is non-drop, so it may reduce drop time of `ScopeTree` a little.
2025-01-16 23:29:58 +00:00
overlookmotel
bf4e5e1c18 feat(allocator): add HashMap (#8553)
Add `HashMap` type to `oxc_allocator`. `HashMap` is a thin wrapper around `hashbrown::HashMap`, which allocates in the arena. The inner map is wrapped in `ManuallyDrop`, so `HashMap` is non-`Drop` (same as `oxc_allocator::Vec`).

We use `FxHasher` for all hash maps, so I figured just make that part of the type, rather than having to specify the hasher everywhere we use `HashMap`.
2025-01-16 23:29:57 +00:00
overlookmotel
fa1a6d5ede docs(allocator): update docs for Vec (#8555)
Remove line from `oxc_allocator::Vec` docs saying "Should only be used for storing AST types.". We are now using `Vec` in `Semantic` too, and there's no problem with that.
2025-01-16 19:18:16 +00:00
overlookmotel
a04833787d fix(transformer/class-static-blocks): static block converted to IIFE use span of original block (#8549)
Fix spans in class static blocks and class properties transforms. When a static block is converted to an IIFE, the IIFE should take the span of the static block.
2025-01-16 14:55:53 +00:00
overlookmotel
712633f0bc refactor(transformer): wrap_statements_in_arrow_function_iife utility function (#8548)
Move utility function for creating an IIFE from `ClassStaticBlock` transform to utils module.
2025-01-16 14:55:52 +00:00
overlookmotel
b552f5cfd3 fix(transformer): wrap_in_arrow_function_iife take span of input Expression (#8547)
#8530 introduced a small change. Previously the IIFE had the span of the original expression which is being wrapped, but after that PR it got a dummy `SPAN`. Fix that.
2025-01-16 14:55:51 +00:00
overlookmotel
5206c6ae06 refactor(transformer): rename wrap_in_arrow_function_iife (#8546)
Pure refactor. Rename this function to be more descriptive.
2025-01-16 14:55:51 +00:00
overlookmotel
61077cae9f refactor(transformer): wrap_arrow_function_iife receive an owned Expression (#8545)
Follow-on after #8529. Pure refactor. `wrap_arrow_function_iife` receive an owned `Expression`, instead of `&mut Expression`.

This does require a bit more repeated code in the caller, but still I think it's more appropriate for a utility function. If we use it again elsewhere, it's non-obvious if it replaces the input `&mut Expression` with a `NullLiteral` via `move_expression`. Better to leave that to the caller.
2025-01-16 14:55:50 +00:00
camc314
65c596d002 fix(minifer): keep idents if not in scope when minimizing array exprs (#8551) 2025-01-16 14:26:37 +00:00
camc314
7cc81ef5ef feat(minifier): fold invalid typeof comparisons (#8550) 2025-01-16 14:26:36 +00:00
Boshen
c479a58718
feat(napi/parser): expose dynamic import expressions (#8540)
closes #8369
2025-01-16 22:25:22 +08:00
camc314
f57aac2aee fix(minifier): incorrect folding of expr in bool ctx (#8542)
esbuild code comment is wrong.

8f1faf7d4a/internal/js_ast/js_ast_helpers.go (L2127-L2128)

https://esbuild.github.io/try/#dAAwLjI0LjIALS1taW5pZnkAaWYgKGFueXRoaW5nMSA/ICgwLCBmYWxzZSkgOiBhbnl0aGluZzIpOw
2025-01-16 14:18:03 +00:00
Dunqing
c30654a793 refactor(transformer/arrow-function): wrapping arrow function iife by using wrap_arrow_function_iife (#8530) 2025-01-16 12:49:28 +00:00
Dunqing
6820d24c4a refactor(transformer): move wrap_arrow_function_iife to root utils module (#8529) 2025-01-16 12:42:14 +00:00
Dunqing
f413bb5c64 feat(transformer/optional-chaining): change parent scope for expression when it wrapped with an arrow function (#8511) 2025-01-16 12:21:44 +00:00
overlookmotel
8dd0013e72 refactor(linter/consistent-function-scoping): remove Visit::enter_node usage (#8538)
Use `Visit::visit_*` method instead of `Visit::enter_node` / `leave_node`. A step towards solving #8461, but also may improve performance.
2025-01-16 11:00:11 +00:00
overlookmotel
30c0689dfc refactor(linter/no-map-spread): remove Visit::enter_node usage (#8537)
Use `Visit::visit_*` method instead of `Visit::enter_node` / `leave_node`. A step towards solving #8461, but also may improve performance.
2025-01-16 10:55:16 +00:00
Alexander S.
b4c87e27a1
refactor(linter): move DiagnosticsReporters to oxlint (#8454)
it was never the plan that oxc_diagnostics should be the
`std::io::stdout` writer:

8fc238ac34/crates/oxc_diagnostics/src/service.rs (L84-L85)

This PR does refactor all reporters to `oxlint` crate and make the
current implementation of `oxc_diagnostics` public for others to
consume.

I added some tests to reflect to expected output (and found some bugs^^)

For the future I think the BufWriter for `std::io::stdout` should come
from outside.
Or maybe `std::fmt::stdout`? I do not know^^"

I could not test 100% of the code, I hope I can fix this with the next
PR which will include a own Tester for oxlint (like `oxc_linter`).
Please be extra careful when reviewing it.

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-01-16 16:11:22 +08:00
Boshen
9ec4e24eb7
test(napi/minify): fix more broken tests 2025-01-16 16:09:23 +08:00
Boshen
0acbef356a
test(napi/minify): fix matching of arrays 2025-01-16 15:34:20 +08:00
Boshen
855c8395cf fix(codegen): shorthand assignment target identifier consider mangled names (#8536) 2025-01-16 07:26:07 +00:00
Boshen
946ad7690b fix(minifier): (-Infinity).toString() -> '-Infinity' (#8535) 2025-01-16 06:47:40 +00:00
Boshen
e0f5d6c7bb
test(minifier): update esbuild test 2025-01-16 14:46:12 +08:00
Boshen
927f43ff84 feat(minifier): improve .charCodeAt(arg) when arg is valid (#8534) 2025-01-16 06:36:34 +00:00
Boshen
b1d018622b fix(minifier): do not fold !!void b (#8533) 2025-01-16 05:52:03 +00:00
Dunqing
f5c5c3c9f1 chore(coverage/runtime): skip tests which are eval in class (#8532)
These tests need performing `eval`, we cannot support them. @overlookmotel and I have agreed to ignore them to reduce the noise.
2025-01-16 05:44:32 +00:00
Boshen
53adde5003
fix(minifier): x['-2147483648'] -> x[-2147483648] (#8528) 2025-01-16 13:43:23 +08:00
Boshen
405b73d8e7 fix(minifier): do not change delete undefined to delete void 0 (#8527)
`delete undefined` returns `false`
`delete void 0` returns `true`
2025-01-16 03:08:26 +00:00
Boshen
92e44cba6b fix(minifier): do not remove undefined in var x = undefined (#8526) 2025-01-16 02:57:28 +00:00
Boshen
06f14d526b feat(minifier): remove empty class static block class Foo { static {} } (#8525) 2025-01-16 02:46:25 +00:00
overlookmotel
2857ae15cd refactor(parser): refactor visitor in regexp example (#8524)
Refactor visitor in example to use `visit_*` methods instead of `enter_node`. This is our recommended style as it's more performant.
2025-01-16 02:40:29 +00:00
Boshen
1860411656 feat(minifier): remove last redundant return statement (#8523) 2025-01-16 02:07:28 +00:00
Valentinas Janeiko
4ce63298e8
fix(semantic)!: ensure program outlives semantic (#8455)
fixes: #8437 

In semantic builder make sure `Program` reference has a lifetime of the
Arena.

---------

Co-authored-by: overlookmotel <theoverlookmotel@gmail.com>
2025-01-16 10:04:25 +08:00
overlookmotel
250bbd193b perf(linter/react-exhaustive-deps): use stack of AstTypes instead of AstKinds (#8522)
This lint rule keeps a stack tracing the "visitation path" during `Visit`. Only the type of the nodes is used, not their values, so store only `AstType` (1 byte) rather than `AstKind` (16 bytes).

This should be more performant, but the main motivation is #8461. This is one of very few places in the codebase which uses `enter_node` and `leave_node`. Not storing `AstKind`s here clears the way to remove the unsound lifetime extension in `Visit::alloc`.
2025-01-16 00:32:38 +00:00
overlookmotel
a6d71f8f27 feat(ast): add AstKind::ty method (#8521)
Add `AstKind::ty` method to get `AstType` from an `AstKind`.

Works by setting the enum discriminants of `AstKind` and `AstType` to be the same, so one can be converted to the other at zero cost.
2025-01-16 00:32:37 +00:00
Dunqing
06ccb51fae fix(transformer/async-to-generator): move parameters to the inner generator function when they could throw errors (#8500)
The new implementation port from [esbuild](df815ac27b/internal/js_parser/js_parser_lower.go (L355-L467)), before from `Babel`.

Babel's transform implementation for the async method is incorrect because the async method should return a rejecting promise when it throws an error. Everything is good if the errors are thrown in the async method body, but the following case will throw an error in the parameters which causes the whole program crushed not a rejecting promise. So we should move the parameters to the inner generator function when the parameters could throw an error.

Input:
```js
class Cls {
  // ReferenceError: Cannot access 'b' before initialization
  async method(a = b, b = 0) {}
}
```

Before output
```js
class Cls {
  method(a = b, b = 0) {
    return babelHelpers.asyncToGenerator(function* () {})();
  }
}
```

After output:
```js
class Cls {
  method() {
     // ReferenceError: Cannot access 'b' before initialization
    return babelHelpers.asyncToGenerator(function* (a = b, b = 0) {}).apply(this, arguments);
  }
}
```

No override tests because Babel doesn't cover this case.
2025-01-16 00:18:05 +00:00
overlookmotel
3789d2faf9 style(linter/react-exhaustive-deps): fix indentation (#8520) 2025-01-15 23:46:38 +00:00
Dunqing
52bd0b1004 refactor(transformer): move common utils functions to the root module (#8513)
These utils functions are very useful for other plugins, I am going to gradually move utils functions where in separate plugins into the root utils module. It also will include scope adjusting functions.
2025-01-15 20:41:09 +00:00
overlookmotel
04bc25963d refactor(traverse): remove unnecessary #[allow] (#8518)
Pure refactor. Remove unnecessary `#[allow]` attrs. Replace remaining ones with `#[expect]`.
2025-01-15 17:38:03 +00:00
Boshen
209e313e40 fix(minifier): class C { ['-1']() {} } cannot be minifized (#8516) 2025-01-15 16:15:01 +00:00
overlookmotel
7e61b231b4 refactor(transformer/typescript): shorten code (#8504)
Pure refactor. Just shorten code by using `BoundIdentifier::create_write_target`, which returns an `AssignmentTarget`.
2025-01-15 15:17:59 +00:00
overlookmotel
356f0c1a6a fix(transformer/class-properties): handle nested super() calls (#8506)
Similar to #8494. Handle nested `super()` calls in class constructor e.g. `super(self = super())`. Very weird code, but legal!
2025-01-15 15:09:00 +00:00
overlookmotel
7066d1cc4f feat(ast, span, syntax, regular_expression)!: remove ContentHash (#8512)
#8483 removed codegen-ed impls of `ContentHash` for AST nodes, because `ContentHash` is not useful. Complete the removal by removing `ContentHash` trait definition, and all remaining references to it.
2025-01-15 15:01:14 +00:00
overlookmotel
cfd783aa19
chore(coverage): bump babel submodule (#8508)
Update babel submodule for conformance tests to latest HEAD.

The test fixtures include a new one for a bug fix which @branchseer
intends to also apply to Oxc - https://github.com/babel/babel/pull/17050
(see #8342).
2025-01-15 22:58:15 +08:00
overlookmotel
a368726208 refactor(traverse): harden soundness of Traverse and document safety invariants better (#8507)
Harden soundness of `Traverse` by:

1. Not exposing `walk_*` methods outside of `walk.rs`.
2. Adding more debug assertions.
3. Adding `#[must_use]` to `TraverseAncestry::push_stack`, so we'll get a lint error if codegen-ed code pushes to `TraverseAncestry`'s stack and doesn't pop it off again.

Document the safety invariants better.
2025-01-15 14:02:25 +00:00
renovate
8b6d331631 chore(deps): update rust crates (#8452)
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [convert_case](https://redirect.github.com/rutrum/convert-case) | workspace.dependencies | minor | `0.6.0` -> `0.7.0` |
| [prettyplease](https://redirect.github.com/dtolnay/prettyplease) | workspace.dependencies | patch | `0.2.27` -> `0.2.28` |
| [proc-macro2](https://redirect.github.com/dtolnay/proc-macro2) | workspace.dependencies | patch | `1.0.92` -> `1.0.93` |

---

### Release Notes

<details>
<summary>dtolnay/prettyplease (prettyplease)</summary>

### [`v0.2.28`](https://redirect.github.com/dtolnay/prettyplease/releases/tag/0.2.28)

[Compare Source](https://redirect.github.com/dtolnay/prettyplease/compare/0.2.27...0.2.28)

-   Expression precedence fixes ([#&#8203;90](https://redirect.github.com/dtolnay/prettyplease/issues/90), [#&#8203;92](https://redirect.github.com/dtolnay/prettyplease/issues/92), [#&#8203;95](https://redirect.github.com/dtolnay/prettyplease/issues/95), [#&#8203;96](https://redirect.github.com/dtolnay/prettyplease/issues/96), [#&#8203;97](https://redirect.github.com/dtolnay/prettyplease/issues/97), [#&#8203;98](https://redirect.github.com/dtolnay/prettyplease/issues/98), [#&#8203;100](https://redirect.github.com/dtolnay/prettyplease/issues/100))

</details>

<details>
<summary>dtolnay/proc-macro2 (proc-macro2)</summary>

### [`v1.0.93`](https://redirect.github.com/dtolnay/proc-macro2/releases/tag/1.0.93)

[Compare Source](https://redirect.github.com/dtolnay/proc-macro2/compare/1.0.92...1.0.93)

-   Optimize TokenStream's Drop ([#&#8203;489](https://redirect.github.com/dtolnay/proc-macro2/issues/489), [#&#8203;490](https://redirect.github.com/dtolnay/proc-macro2/issues/490), thanks [@&#8203;WalkerKnapp](https://redirect.github.com/WalkerKnapp))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "before 11am on monday" in timezone Asia/Shanghai, Automerge - "before 11am on monday" in timezone Asia/Shanghai.

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://redirect.github.com/renovatebot/renovate/discussions) if that's undesired.

---

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

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/oxc-project/oxc).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS45Mi4wIiwidXBkYXRlZEluVmVyIjoiMzkuOTIuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->
2025-01-15 13:29:46 +00:00
Boshen
c63c8b924d
test(napi/minify): add runtime test (#8501) 2025-01-15 21:13:00 +08:00
Boshen
aa9d7e47ea build(napi): napi build --no-dts-cache (#8499) 2025-01-15 07:02:29 +00:00
Boshen
629c41713b test(minifier): port esbuild minification tests (#8497) 2025-01-15 06:29:01 +00:00