Commit graph

7940 commits

Author SHA1 Message Date
Yuji Sugiura
a529412fe7
refactor(prettier): Verify printing module exports (#8670)
Part of #5068 

- ExportAllDeclaration
- ExportNamedDeclaration
- ExportDefaultDeclaration
- (ExportNamespaceSpecifier = ExportAllDeclaration+exported)

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-01-23 14:54:06 +08:00
Boshen
13e4a4593f refactor(minifier): move conditional assignment to minimize_conditions (#8669) 2025-01-23 04:42:44 +00:00
Boshen
ba201a6511 fix(minifier): remove "non esbuild optimizations" which is incorrect (#8668) 2025-01-23 03:45:42 +00:00
Alexander S.
4ae568e8c9
feat(linter): add DiagnosticResult to the Reporters for receiving a sub part result (#8666)
We are currently outputting only for the default-outputter some extra
information:


3be03926e8/apps/oxlint/src/result.rs (L61-L87)

My goal is that all information will be passed to our new
DiagnosticReporter / OutputFormatter.
This will break the output format in the next PR. **Merging this PR is
the OK for me to make this change** ⚠️
The only breaking point:
`"Found {number_of_warnings} warning{} and {number_of_errors} error{}."`
will still be outputted when `max_warnings_exceeded` is true.

Because this is something the `DiagnosticReporter` should do and not the
`OutputFormatter`.

The end goal is:
- no `println!`, our `OutputFormatter` and his `DiagnosticReporter` will
return `Option<String>` and we output it the our `stdout`
- `LintResult` will only handle `ExitCode` result and nothing more
- `stdout` can be changed from outside (for the next part)
- add snapshots with a custom `stdout`

I do not know if all goals can be done easily. Last two parts should be
a bit tricky for me, never did test setups in rust.
But we do never stop to learn ;)
2025-01-23 10:09:51 +08:00
Boshen
db863a35bc
refactor(codegen): use Stack for binary_expr_stack (#8663)
Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2025-01-23 10:08:21 +08:00
Yuji Sugiura
1e9f3857ab
refactor(prettier): Verify printing module imports (#8633)
Part of #5068 

- [x] ImportDeclaration
- [x] ImportSpecifier
- [x] ImportDefaultSpecifier
- [x] ImportNamespaceSpecifier
- [x] WithClause
- [x] ImportAttribute
2025-01-23 09:58:44 +08:00
overlookmotel
3be03926e8 docs(lexer): fix doc comment (#8664)
The comment showing expansion of `ascii_byte_handler!` macro was inaccurate.
2025-01-22 16:22:32 +00:00
Boshen
ae895d8c0e refactor(minifier): use NonEmptyStack for function stack (#8661) 2025-01-22 16:04:36 +00:00
Dunqing
a730f999a8 refactor(transformer): move create_prototype_member to utils module (#8657)
This function can also used in #8614, so move it.
2025-01-22 15:51:28 +00:00
Boshen
3802d28233 refactor(minifier): clean up try_minimize_conditional (#8660) 2025-01-22 15:17:47 +00:00
overlookmotel
ae8db53d65 refactor(allocator): move Allocator into own module (#8656)
Pure refactor. `oxc_allocator` crate is getting quite crowded now. Move `Allocator` into a separate file.
2025-01-22 13:45:32 +00:00
overlookmotel
0f85bc6918 refactor(allocator): reduce repeat code to prevent Drop types in arena (#8655)
Pure refactor. Reduce repeated code.
2025-01-22 13:17:58 +00:00
overlookmotel
d1c5dc4d12 fix(semantic): fix const assertions in UnresolvedReferencesStack (#8653)
The `_SIZE_CHECK` assertion was ignored, because `const`s are only evaluated if they're referenced in a function which is called. Fix that by referencing the const in `UnresolvedReferencesStack::new`.

Also add more assertions to cover all the invariants.
2025-01-22 13:13:15 +00:00
overlookmotel
de76eb1b90 refactor(allocator): reorder Box methods (#8654)
Pure refactor. Move `Box::unbox` down. `Box::new_in` is the most important method, so should be at the top.
2025-01-22 12:29:56 +00:00
overlookmotel
50295474cc docs(semantic): fix and reformat doc comments (#8652)
Update doc comment for `TempUnresolvedReferences` which was out of date. Reformat other comments.
2025-01-22 12:22:27 +00:00
Boshen
9953ac7cad
perf(minifier): add LatePeepholeOptimizations (#8651)
This PR adds a `LatePeepholeOptimizations` pass for minifications that
don't interact with the fixed point loop.

While working on this I found a couple of cases where the previous fixed
point loop is not idempotent.
2025-01-22 16:19:06 +08:00
Boshen
00dc63f6a5 perf(minifier): only substitute typed array constructor once (#8649) 2025-01-22 02:49:52 +00:00
Alexander S.
40316afa7e
fix(linter): fix github endColumn output (#8647)
added `start` and `end` for `Info`, so every reporter can use both if
they want.
Then end calculation is a bit hacky, but i looks like it works.
2025-01-22 09:10:40 +08:00
Tapan Prakash
dc912fa58e
fix(linter): Added missing $schema property to default config (#8625)
The $schema property was not added when the --init command was used to
create the configuration. Now, $schema is added based on the
availability of configuration_schema.json in the current working
directory.

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-01-22 09:09:39 +08:00
Boshen
3e19e4e004
perf(minifier): remove the useless empty statement removal code in statement fusion (#8646) 2025-01-22 09:08:56 +08:00
Boshen
5b3c412e26
perf(minifier): only run optimizations on local changes (#8644)
Previously all code are ran in a fixed point loop when ast changes.

This PR changes running code when a function changes its enclosing ast only.
2025-01-21 23:55:54 +08:00
camc314
b75d4919ee chore(linter): update doc comment to reflect existance of stylish formatter (#8645)
after:
```
Output
    -f, --format=ARG          Use a specific output format (default, json, unix, checkstyle, github,
                              stylish)
```
2025-01-21 15:38:15 +00:00
sapphi-red
835b25889b
feat(minifier): compress typeof foo === 'object' && foo !== null to typeof foo == 'object' && !!foo (#8638)
If `typeof foo == 'object'`, then `foo` is guaranteed to be an object or null. In that case, `foo !== null` can be replaced with `!!foo` because objects return `true` for `!!foo` and null returns `false` for it.

**References**
- [Spec of `typeof`](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-typeof-operator)
- [Spec of `!`](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-logical-not-operator)
- [Spec of `ToBoolean`](https://tc39.es/ecma262/multipage/abstract-operations.html#sec-toboolean)
2025-01-21 14:59:25 +00:00
sapphi-red
2bcbed2d50
feat(minifier): compress (a = b) === null || a === undefined to (a = b) == null (#8637) 2025-01-21 14:59:23 +00:00
overlookmotel
864b8efe1a refactor(parser): shorten code (#8640)
Pure refactor. Shorten code by using `AstBuilder` methods which produce the desired type in a single call.
2025-01-21 14:36:00 +00:00
overlookmotel
e66da9fe41 refactor(isolated_declarations, linter, minifier, prettier, semantic, transformer): remove unnecessary ref / ref mut syntax (#8643)
While working on #8641, I found a lot of places where we unnecessarily use `ref` / `ref mut` in match arms.

In many cases, we're creating double-references (turning a `&T` into a `&&T`). The compiler should be smart enough to remove them for us, but there doesn't seem much point in explicitly creating double-references when we don't actually want them, and relying on compiler to optimize them out again.
2025-01-21 14:20:07 +00:00
overlookmotel
54d0fac987 refactor(span)!: remove PartialEq impl for &Atom (#8642)
Remove this unnecessary impl. It's pretty odd to have a method which takes an `&&Atom` (which is essentially a `&&&str`).
2025-01-21 14:20:06 +00:00
overlookmotel
b8d9a51462 refactor(span): deal only in owned Atoms (#8641)
#8596 made `Atom` a `Copy` type. Now we can deal exclusively in owned `Atom`s. Refactor code to not pass `&Atom` into functions etc.
2025-01-21 14:20:06 +00:00
overlookmotel
20f52b1fee refactor(span): remove unnecessary lifetimes on Atom impls (#8639)
Pure refactor. The lifetime of the `Atom` is not relevant in these trait impls. Remove the lifetimes to make that clearer.
2025-01-21 14:20:06 +00:00
overlookmotel
61d96fde64 refactor(transformer/class-properties): correct comments (#8636) 2025-01-21 11:18:02 +00:00
Boshen
dcc1f2bcb3 refactor(minifier): rename ast_passes to peephole (#8635) 2025-01-21 11:09:53 +00:00
Yuji Sugiura
891a9c2040
feat(tasks/prettier): Visualize test details (#8634)
For example, if there are 3 tests in 1 spec and all of them fail:

- 💥💥💥

After some implementation, if 1 test passes:

- 💥💥

However, in this case, the coverage as number does not change.

This PR visualizes these details for better mental well-being. 😃
(But in practice, specs are so detailed, there is not much opportunity
for this...)
2025-01-21 17:01:34 +08:00
Boshen
52458de00b refactor(minifier): remove unused code and traits (#8632) 2025-01-21 05:41:11 +00:00
overlookmotel
c1d243be46 docs(allocator): improve docs for Allocator (#8623)
Improve docs for `Allocator`:

1. Explain how allocator works.
2. Demonstrate how to achieve good performance by re-using `Allocator`s.

Also fix the doc test for `CloneIn`.
2025-01-21 04:01:41 +00:00
Andrew Powell
8a0eb2abb7
feat(oxlint): add stylish formatter (#8607)
👋 This implements a reporter for `--format` on `oxlint` which aims to be
visually similar to
https://eslint.org/docs/latest/use/formatters/#stylish

Please note that this is my first time working with Rust and my
knowledge is very limited. I'm unlikely to understand best-practice or
best-pattern references outside of what clippy/cargo lint has already
had me change. If this needs modification, please help me out by making
code suggestions that can be merged to this PR.

Resolves #8422

---------

Co-authored-by: Cameron <cameron.clark@hey.com>
2025-01-21 09:55:07 +08:00
Kevin Deng 三咲智子
178c2322f5
fix(parser): parse intrinsic TS keyword (#8627) 2025-01-21 09:54:10 +08:00
Kevin Deng 三咲智子
48717ab87c
fix(parser): parse true as TSLiteralType (#8626)
closes #8624
2025-01-21 09:50:49 +08:00
overlookmotel
2a2ad53ea6 feat(allocator): add Allocator::capacity and used_bytes methods (#8621)
Add 2 methods for determining the size of `Allocator`:

* `capacity` returns total size of memory owned by the `Allocator` (including space not yet used).
* `used_bytes` returns total size of data so far allocated in the arena.
2025-01-20 17:11:17 +00:00
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