Commit graph

7902 commits

Author SHA1 Message Date
Boshen
c9f3c5fc2b chore(allocator): remove default features from hashbrown (#8619) 2025-01-20 16:18:41 +00:00
overlookmotel
6801c81b86 feat(allocator): add Allocator::new and with_capacity methods (#8620)
Add `Allocator::with_capacity` method to allow specifying initial capacity when creating `Allocator`. Also add `Allocator::new` as an alternative to `Allocator::default` (does the same thing).
2025-01-20 15:21:16 +00:00
Boshen
6f95cd599a
refactor(minifier): remove all the unnecessary fake ast passes (#8618)
This also removes handling of making cjs-module-lexer to work.
2025-01-20 22:05:51 +08:00
overlookmotel
787aaad977 perf(allocator): make String non-drop (#8617)
Wrap `bumpalo::collections::String` in `ManuallyDrop` inside our `String` type.

This has 2 advantages:

1. Perf improvement (although it's very minor, because we don't use owned `String` type much).
2. `String`s can be stored in `Allocator` if you want to (#8570 made that impossible, if `String` is `Drop`).
2025-01-20 12:30:20 +00:00
overlookmotel
01a5e5d74a docs(allocator): improve docs for HashMap (#8616)
Clarify docs for `HashMap` on `Drop` restriction.
2025-01-20 11:46:13 +00:00
overlookmotel
87568a1942 docs(allocator): reformat docs (#8615)
Make formatting of doc comments in `oxc_allocator` consistent.
2025-01-20 11:34:29 +00:00
Boshen
d9f5e7fd52
test(minifier): enable passed esbuild tests 2025-01-20 16:39:39 +08:00
Boshen
712cae034c refactor(minifier): run the compressor on all test cases (#8604)
Running individual plugins causes too much confusion.

- [x] fix 110 failed tests :-)
2025-01-20 08:11:11 +00:00
翠 / green
8c8b5fa9be
fix(minifier): avoid minifing String(a) into "" + a for symbols (#8612)
We shouldn't change `String(a)` into `"" + a` if `a` can be a Symbol.
`String(Symbol())` does not throw an error, but `"" + Symbol()` does.

**References**
- [Spec of `ToString` (called for `"" +
variable`)](https://tc39.es/ecma262/multipage/abstract-operations.html#sec-tostring)
- [Spec of
`String(a)`](https://tc39.es/ecma262/multipage/text-processing.html#sec-string-constructor-string-value)

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-01-20 13:34:46 +08:00
Boshen
a78a72fb16
ci: fix overly broad permissions reported by zizmor (#8611)
https://woodruffw.github.io/zizmor/audits/#excessive-permissions
2025-01-20 13:19:50 +08:00
renovate[bot]
11f33af06b
chore(deps): update npm packages 2025-01-20 03:57:17 +00:00
renovate[bot]
7923971783
chore(deps): update github-actions 2025-01-20 01:06:44 +00:00
Alexander S.
259a47b2ac
refactor(vscode): move commands and findBinary to separate files (#8605)
pure refactor. wanted to add tests but needs to mocks :/
2025-01-20 09:06:06 +08:00
sapphi-red
997859c42e
refactor(ast): align #[estree(via)] behavior (#8599)
Follow-on after #8564. Aligned the behavior of `#[estree(via)]` for fields with `#[estree(via)]` for structs.
2025-01-19 20:44:33 +00:00
Boshen
4ff6e85137 fix(minifier): remove expression statement void 0 (#8602) 2025-01-19 14:47:00 +00:00
Alexander S.
1a99d3539e
ci(lint_rules): trigger on utils/mod.rs and on its workflow file (#8601)
The vitest rules documentation did not get updated after
https://github.com/oxc-project/oxc/pull/8445
2025-01-19 22:38:39 +08:00
Boshen
d966e0adda perf(codegen): do not check for comments if turned off (#8598) 2025-01-19 09:07:24 +00:00
Boshen
8cce69a602 refactor(codegen): remove match_member_expression (#8597) 2025-01-19 09:00:25 +00:00
branchseer
ac4f98e376
refactor(span): derive Copy on Atom (#8596)
Follow up from
https://github.com/oxc-project/oxc/pull/8543#discussion_r1918592423

> I agree. https://github.com/oxc-project/backlog/issues/155

> Originally we were considering some form of interning and
reference-counting, so we didn't make it Copy to leave the door open for
that. But now all strings are stored in the arena anyway, so even if we
did decide to intern strings, reference-counting would be irrelevant -
our bump allocator doesn't allow freeing individual allocations anyway.

Most of the changes are done automatically by `just fix` (`cargo clippy
--fix` && `cargo fmt --all`). See the commit list for the manual edits.
2025-01-19 16:14:23 +08:00
Boshen
066ffe8e8d
fix(tasks/prettier_conformance): fix compile error 2025-01-19 12:17:25 +08:00
Boshen
83caa56926
fix(tasks/prettier_conformance): enable test coverage 2025-01-19 12:07:15 +08:00
Boshen
2a2a2eb5ea
chore(tasks/minsize): enable test coverage 2025-01-19 12:00:40 +08:00
Boshen
9dc65cfa6a
ci: fix release napi script 2025-01-19 10:35:51 +08:00
camc314
93d643e6a4 fix(minifier): keep side effects when folding const conditional exprs (#8591) 2025-01-19 01:53:21 +00:00
oxc-bot
8f5be07ed6
release(crates): v0.47.1 (#8593)
## [0.47.1] - 2025-01-19

### Features

- ee8ee55 napi/parser: Add `.hasChanged()` to `MagicString` (#8586)
(Boshen)
- 1bef911 napi/parser: Add source map API (#8584) (Boshen)

### Bug Fixes

- 7b219a9 minifier: Fix dce shadowed undefined (#8582) (Boshen)
- 7421a52 transformer/typescript: Correctly resolve references to
non-constant enum members (#8543) (branchseer)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2025-01-19 09:44:29 +08:00
oxc-bot
66c8720002
release(oxlint): v0.15.7 (#8592)
## [0.15.7] - 2025-01-19

### Features

- 01ac773 linter: Support `ignoreTypeOfTestName` for `jest/valid-title`
(#8589) (dalaoshu)
- 538b24a linter: Format the configuration documentation correctly
(#8583) (Tapan Prakash)
- 7ab14cc linter: Add more Vitest compatible Jest rules (#8445) (Anson
Heung)
- d178360 linter: Implement `eslint/prefer-promise-reject-errors`
(#8254) (tbashiyy)
- 4ac2e99 oxlint: Implement `--init` cli option (#8453) (Tapan Prakash)

### Bug Fixes

- 855c839 codegen: Shorthand assignment target identifier consider
mangled names (#8536) (Boshen)
- c15af02 linter: False positive in `eslint/no-lone-blocks` (#8587)
(dalaoshu)
- 41f2070 linter: Rule `no-restricted-imports` support missing options
(#8076) (Alexander S.)
- 869bc73 linter: Enhance `default_param_last` rule to handle optional
parameters (#8563) (Tapan Prakash)
- c6260c2 linter: Support rest params for `prefer_promise_reject_errors`
(#8468) (Yuichiro Yamashita)
- 2be1e82 linter/no-unused-vars: False positives when variable and type
have same name (#8465) (Dunqing)

### Performance

- 250bbd1 linter/react-exhaustive-deps: Use stack of `AstType`s instead
of `AstKind`s (#8522) (overlookmotel)

### Refactor

- 40f5165 linter: Improve `eslint/no-lone-blocks` (#8588) (dalaoshu)
- b4c87e2 linter: Move DiagnosticsReporters to oxlint (#8454) (Alexander
S.)
- bf00f82 linter: Move rule `prefer-each` from vitest to jest +
remapping (#8448) (Alexander S.)
- 8dd0013 linter/consistent-function-scoping: Remove `Visit::enter_node`
usage (#8538) (overlookmotel)
- 30c0689 linter/no-map-spread: Remove `Visit::enter_node` usage (#8537)
(overlookmotel)
- b5ed58e span: All methods take owned `Span` (#8297) (overlookmotel)

### Styling

- 3789d2f linter/react-exhaustive-deps: Fix indentation (#8520)
(overlookmotel)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2025-01-19 09:00:00 +08:00
dalaoshu
40f51654ec
refactor(linter): improve eslint/no-lone-blocks (#8588)
The code `let mut lone_blocks = Vec::new();` is unnecessary because it
will contain at most one element throughout its usage.

Additionally, special test cases has been added for when
`parent_node.kind()` is `AstKind::FunctionBody(_)`.
2025-01-18 23:54:17 +00:00
dalaoshu
01ac773d0c
feat(linter): support ignoreTypeOfTestName for jest/valid-title (#8589)
closes #8531 

I'm not sure if we should support it because both `vitest` and `jest`
have this issue
2025-01-18 23:52:51 +00:00
dalaoshu
c15af02e52
fix(linter): false positive in eslint/no-lone-blocks (#8587)
closes #8515
2025-01-19 00:08:57 +08:00
Boshen
ee8ee55cda feat(napi/parser): add .hasChanged() to MagicString (#8586) 2025-01-18 15:29:17 +00:00
Boshen
1bef911e59
feat(napi/parser): add source map API (#8584) 2025-01-18 23:06:42 +08:00
Boshen
62f1881ec4
chore: pnpm v10.0.0 (#8585) 2025-01-18 22:09:01 +08:00
Boshen
7b219a930f fix(minifier): fix dce shadowed undefined (#8582) 2025-01-18 09:04:28 +00:00
branchseer
7421a52f7c
fix(transformer/typescript): correctly resolve references to non-constant enum members (#8543)
fixes #8342

---------

Co-authored-by: overlookmotel <theoverlookmotel@gmail.com>
Co-authored-by: Dunqing <dengqing0821@gmail.com>
2025-01-18 17:02:50 +08:00
Tapan Prakash
538b24a719
feat(linter): Format the configuration documentation correctly (#8583)
The categories section in the documentation is not formatted correctly.
This fix aims to correct the formatting.

Before 
<img width="1194" alt="before"
src="https://github.com/user-attachments/assets/d2eb682b-5971-43ee-bdf0-92eb2e9c78a2"
/>

After 
<img width="1266" alt="after"
src="https://github.com/user-attachments/assets/a4b992c2-fe33-4781-ad0b-de822f87c2d6"
/>
2025-01-18 17:02:32 +08:00
Boshen
4a59d29c30
refactor(workflows): add reusable_release_napi.yml (#8581) 2025-01-18 15:27:22 +08:00
oxc-bot
d3fd7a9741
release(crates): v0.47.0 (#8580)
## [0.47.0] - 2025-01-18

- fae4cd2 allocator: [**BREAKING**] Remove `Vec::into_string` (#8571)
(overlookmotel)

- 95bc0d7 allocator: [**BREAKING**] `Allocator` do not deref to
`bumpalo::Bump` (#8569) (overlookmotel)

- 19d3677 ast: [**BREAKING**] Always return
`Array<ImportDeclarationSpecifier>` for `ImportDeclaration.specifiers`
(#8560) (sapphi-red)

- 4ce6329 semantic: [**BREAKING**] Ensure program outlives semantic
(#8455) (Valentinas Janeiko)

- 7066d1c ast, span, syntax, regular_expression: [**BREAKING**] Remove
`ContentHash` (#8512) (overlookmotel)

### Features

- bf4e5e1 allocator: Add `HashMap` (#8553) (overlookmotel)
- a6d71f8 ast: Add `AstKind::ty` method (#8521) (overlookmotel)
- 4d4e805 minifier: Collapse if stmt with empty consequent (#8577)
(camc314)
- 991a22f minifier: Fold `Array::concat` into literal (#8442)
(sapphi-red)
- 3dc2d8b minifier: Fold string concat chaining (#8441) (sapphi-red)
- a4ae450 minifier: Fold array concat chaining (#8440) (sapphi-red)
- 7cc81ef minifier: Fold invalid typeof comparisons (#8550) (camc314)
- 927f43f minifier: Improve `.charCodeAt(arg)` when arg is valid (#8534)
(Boshen)
- 06f14d5 minifier: Remove empty class static block `class Foo { static
{} }` (#8525) (Boshen)
- 1860411 minifier: Remove last redundant return statement (#8523)
(Boshen)
- c479a58 napi/parser: Expose dynamic import expressions (#8540)
(Boshen)
- 2f0314e npm/oxc-minify: Npm package and publish script (#8579)
(Boshen)
- f413bb5 transformer/optional-chaining: Change parent scope for
expression when it wrapped with an arrow function (#8511) (Dunqing)

### Bug Fixes

- e87c001 allocator: Statically prevent memory leaks in allocator
(#8570) (overlookmotel)
- 855c839 codegen: Shorthand assignment target identifier consider
mangled names (#8536) (Boshen)
- 65c596d minifer: Keep idents if not in scope when minimizing array
exprs (#8551) (camc314)
- f57aac2 minifier: Incorrect folding of expr in bool ctx (#8542)
(camc314)
- 946ad76 minifier: `(-Infinity).toString()` -> `'-Infinity'` (#8535)
(Boshen)
- b1d0186 minifier: Do not fold `!!void b` (#8533) (Boshen)
- 53adde5 minifier: `x['-2147483648']` -> `x[-2147483648]` (#8528)
(Boshen)
- 405b73d minifier: Do not change `delete undefined` to `delete void 0`
(#8527) (Boshen)
- 92e44cb minifier: Do not remove `undefined` in `var x = undefined`
(#8526) (Boshen)
- 209e313 minifier: `class C { ['-1']() {} }` cannot be minifized
(#8516) (Boshen)
- 6585463 minifier: Always keep the last value of sequence expression
(#8490) (Boshen)
- b552f5c transformer: `wrap_in_arrow_function_iife` take span of input
`Expression` (#8547) (overlookmotel)
- 9963533 transformer/arrow-functions: Visit arguments to `super()` call
(#8494) (overlookmotel)
- 06ccb51 transformer/async-to-generator: Move parameters to the inner
generator function when they could throw errors (#8500) (Dunqing)
- 356f0c1 transformer/class-properties: Handle nested `super()` calls
(#8506) (overlookmotel)
- a048337 transformer/class-static-blocks: Static block converted to
IIFE use span of original block (#8549) (overlookmotel)

### Performance

- 76ea52b allocator: Inline `Box` methods (#8572) (overlookmotel)
- 93df57f allocator: `#[inline(always)]` methods of `Vec` which just
delegate to `allocator_api2` (#8567) (overlookmotel)
- 5a28d68 allocator: `#[inline(always)]` methods of `HashMap` which just
delegate to `hashbrown` (#8565) (overlookmotel)
- d17021c mangler: Optimize `base54` function (#8557) (overlookmotel)
- 6b52d7a mangler: Use a single allocation space for temporary vecs
(#8495) (Boshen)
- 30a869e semantic: Use `oxc_allocator::HashMap` in `ScopeTree` (#8554)
(overlookmotel)
- 63eb298 span: Compare `Span`s as single `u64`s (#8300) (overlookmotel)
- a43560c span: Hash `Span` as a single `u64` (#8299) (overlookmotel)
- 3fff7d2 span: Align `Span` same as `usize` (#8298) (overlookmotel)
- 53ef263 transformer/arrow-functions: Bail out of visiting early when
inserting `_this = this` after `super()` (#8482) (overlookmotel)

### Documentation

- fa1a6d5 allocator: Update docs for `Vec` (#8555) (overlookmotel)

### Refactor

- ac05134 allocator: `String` type (#8568) (overlookmotel)
- 68fab81 allocator: Rename inner `Vec` type (#8566) (overlookmotel)
- fcbca32 ast: Rename `#[estree(with)]` to `#[estree(via)]` (#8564)
(overlookmotel)
- 007e8c0 ast, regular_expression: Shorten `ContentEq` implementations
(#8519) (overlookmotel)
- b4c87e2 linter: Move DiagnosticsReporters to oxlint (#8454) (Alexander
S.)
- 8f57929 minifier: Merge `try_compress_type_of_equal_string` into
`try_minimize_binary` (#8561) (sapphi-red)
- 2857ae1 parser: Refactor visitor in regexp example (#8524)
(overlookmotel)
- b5ed58e span: All methods take owned `Span` (#8297) (overlookmotel)
- 712633f transformer: `wrap_statements_in_arrow_function_iife` utility
function (#8548) (overlookmotel)
- 5206c6a transformer: Rename `wrap_in_arrow_function_iife` (#8546)
(overlookmotel)
- 61077ca transformer: `wrap_arrow_function_iife` receive an owned
`Expression` (#8545) (overlookmotel)
- 6820d24 transformer: Move `wrap_arrow_function_iife` to root utils
module (#8529) (Dunqing)
- 52bd0b1 transformer: Move common utils functions to the root module
(#8513) (Dunqing)
- c30654a transformer/arrow-function: Wrapping arrow function iife by
using `wrap_arrow_function_iife` (#8530) (Dunqing)
- 2bc5175 transformer/arrow-functions: Rename method (#8481)
(overlookmotel)
- 72f425f transformer/class-properties: Fix lint warning in release mode
(#8539) (overlookmotel)
- 7e61b23 transformer/typescript: Shorten code (#8504) (overlookmotel)
- 04bc259 traverse: Remove unnecessary `#[allow]` (#8518)
(overlookmotel)
- a368726 traverse: Harden soundness of `Traverse` and document safety
invariants better (#8507) (overlookmotel)

### Testing

- e0f5d6c minifier: Update esbuild test (Boshen)
- 629c417 minifier: Port esbuild minification tests (#8497) (Boshen)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2025-01-18 14:26:20 +08:00
Boshen
3d64cefe10
feat(allocator): add Send + Sync to HashMap 2025-01-18 14:24:12 +08:00
Boshen
6c4081e148
chore: update pnpm lock file 2025-01-18 14:05:58 +08:00
Boshen
2f0314eec2
feat(npm/oxc-minify): npm package and publish script (#8579) 2025-01-18 12:12:42 +08:00
Boshen
7f4b302508
chore: vitest 3.0.0 (#8578) 2025-01-18 12:10:01 +08:00
overlookmotel
fcbca322d7 refactor(ast): rename #[estree(with)] to #[estree(via)] (#8564)
Follow-on after #8560. Rename `#[estree(with)]` attr introduced in #8560 for struct fields to `#[estree(via)]`. This is to match the attr which does the same thing on struct itself. e.g.:

869bc73e67/crates/oxc_ast/src/ast/literal.rs (L23-L29)
2025-01-18 03:59:59 +00:00
camc314
4d4e805691 feat(minifier): collapse if stmt with empty consequent (#8577) 2025-01-18 03:51:40 +00:00
Alexander S.
41f2070895
fix(linter): rule no-restricted-imports support missing options (#8076)
> The regex property is used to specify the regex patterns for
restricting modules.
> Note: regex cannot be used in combination with group.

_https://eslint.org/docs/latest/rules/no-restricted-imports#regex_

> This option allows you to use regex patterns to restrict import names:


_https://eslint.org/docs/latest/rules/no-restricted-imports#importnamepattern_

> This is a string option. Inverse of importNamePattern, this option
allows imports that matches the specified regex pattern. So it restricts
all imports from a module, except specified allowed patterns.
> Note: allowImportNamePattern cannot be used in combination with
importNames, importNamePattern or allowImportNames.


_https://eslint.org/docs/latest/rules/no-restricted-imports#allowimportnamepattern_

Needed to install `regress` to support JS Sntax like Lookaheads and
Lookbehinds

Next Goals:
- https://github.com/oxc-project/oxc/pull/7894
- Improve spans
- Error for wrong configurations
- update documentation
- Output messages like
[eslint](https://github.com/eslint/eslint/blob/main/lib/rules/no-restricted-imports.js#L140-L184)
2025-01-18 11:50:36 +08:00
Alexander S.
8c6e0a6fa3
refactor(language_server): simplify IsolatedLintHandler (#8183)
the `PathBuf` is only leeded in line 47. I do not know why the other
methods should handle it and return the result.
And a simple fast return.
2025-01-18 11:49:21 +08:00
overlookmotel
63eb29868d perf(span): compare Spans as single u64s (#8300)
#8298 made `Span` aligned on 8 on 64-bit platforms. Utilize this property to compare `Span`s as a single `u64` instead of 2 x `u32`s. This removes some really weird assembly which compiler otherwise produces, using expensive SIMD operations for a simple comparison: https://godbolt.org/z/sEf9MGvsr

Note: This only affects comparing `&Span`s. Makes no difference when comparing owned `Span`s.
2025-01-18 01:47:10 +00:00
overlookmotel
a43560c056 perf(span): hash Span as a single u64 (#8299)
#8298 made `Span` aligned on 8 on 64-bit platforms. Utilize this property to hash `Span` as a single `u64` instead of 2 x `u32`s. This reduces hashing a `Span` with `FxHash` to 3 instructions (down from 7), and 1 register (down from 3). https://godbolt.org/z/4q36xrWG8
2025-01-18 01:47:10 +00:00
overlookmotel
b5ed58e237 refactor(span): all methods take owned Span (#8297)
`Span` is `Copy` and 8 bytes. There is no point in the extra indirection of passing `&Span` to functions (`&Span` is also 8 bytes).
2025-01-18 01:47:09 +00:00
overlookmotel
3fff7d293b perf(span): align Span same as usize (#8298)
`Span` consists of 2 x `u32` (8 bytes total). Align `Span` on 8 bytes on 64-bit platforms. This means that, on 64-bit platforms, `Span` can be treated as equivalent to a `u64` and stored in a single register (instead of requiring 2).

A side-effect is that all AST structs also become aligned on 8. This will be a useful property later on as we can remove alignment calculations from `Allocator::alloc` (since everything now has same alignment).

`BooleanLiteral` (and `BoundaryAssertion`, `CharacterClassEscape` and `IndexedReference` from `oxc_regular_expression` crate) increase from 12 bytes to 16 bytes due to the higher alignment. But this makes no practical difference as they'd almost always end up with padding around them in arena anyway, as they'll be surrounded by 8-aligned types.
2025-01-18 01:47:08 +00:00
overlookmotel
bfd0b0da17 ci(benchmark): make lexer benchmark more realistic (#8573)
The lexer benchmarks had a problem. The lexer alone cannot make sense of regexp literals, template literals, or JSX text elements - it needs the parser "driving" it.

So lexer was producing plenty of errors on some benchmarks. This is unrealistic - when driven by the parser, the lexer produces no errors. Generating diagnostics is relatively expensive, so this was skewing the benchmarks somewhat.

Solve this by cleaning up the input source text to replace these syntaxes with string literals prior to running the benchmarks.

Unfortunately lexer benchmarks don't exercise the code paths for these syntaxes, but there isn't much we can do about that. We can judge by the parser benchmarks, which are the more important ones anyway.
2025-01-18 01:47:07 +00:00