Commit graph

8056 commits

Author SHA1 Message Date
Boshen
d8fac6d76b perf(codegen): avoid a heap allocation when printing floats (#8807) 2025-01-31 08:48:52 +00:00
sapphi-red
f8548ec9c7
fix(minifier): unreachable error when compressing string literal arrays with .split() (#8806) 2025-01-31 08:16:21 +00:00
sapphi-red
e353a018f0
feat(minifier): compress a != null ? a.b : undefined to a?.b (#8802) 2025-01-31 07:27:49 +00:00
Boshen
3ac5020b70 test(minifier): enable more passed esbuild tests (#8804) 2025-01-31 07:02:49 +00:00
sapphi-red
72d74a2fdc
feat(minifier): compress a != null ? a : b into a ?? b (#8801)
It seems this was implemented in past by #8352 and was reverted in #8411. I'm not sure what was buggy, but one difference with this PR is that the previous PR doesn't check whether the identifier is a global reference or not.
2025-01-31 06:47:47 +00:00
Boshen
a861d93722
refactor(minifier): port esbuild's mangleStmts (#8770) 2025-01-31 13:43:10 +08:00
Ethan Goh
249895f423
feat(minifier): implement variadic Math methods in known methods (#8783) 2025-01-31 12:45:59 +08:00
Tyler Earls
4f30a170eb
fix(linter): unicorn/switch-case-braces mangles code when applying fix (#8758)
Addresses #8491.

Essentially, the fix was ensuring that we track the indentation of a
`StatementExpression` or `BreakStatement` when we apply a fix for this
lint rule, and to make sure we add these statements on a new line with
the proper indentation. I also made sure we're indenting the closing
case brackets correctly.

To do this, I added a `get_preceding_indent_str` fn to the `ast_utils`
that handles getting the preceding indentation of a `Span` in a
`source_text` &str. It returns an Option in case no indentation is
found, or if the statement is not the only one on a given line.

This new fn was useful when addressing this particular bug, but I figure
it might be useful for other fixer use cases, too. I added some
documentation for this fn for clarity.
2025-01-31 12:32:11 +08:00
Cam McHenry
c63291a8ea
docs(ast): add more docs for JS expressions, declarations, and module AST types (#8800)
Tried to add documentation and examples for as many of the remaining AST
methods as I could. There are still around 30 or so remaining in this
file, but this PR adds around 50 documentation comments.

I tried my best to check that each comment is correct, but I was
inferring from the source and usage, so it may not be 100% accurate.
Please take a quick look over the comments and see if it looks right.

Co-authored-by: camchenry <1514176+camchenry@users.noreply.github.com>
2025-01-31 12:24:54 +08:00
dalaoshu
9cc9d5f1d1
fix(linter): ignorePatterns does not work when files are provided as command arguments (#8590)
closes #8505 

Here is why this issue occurs:

c15af02e52/apps/oxlint/src/lint.rs (L66-L70)
2025-01-31 12:24:23 +08:00
sapphi-red
7ea99f40ac
feat(minifier): compress array of string literals to 'str1,str2'.split(',') (#8786)
Ported `["str1", "str2", ...]` => `"str1 str2".split(" ")` compression from closure compiler with some tweaks.
2025-01-31 04:13:41 +00:00
sapphi-red
2eac9c0370
fix(minifier): fix var undefined = 1; foo === null || foo === undefined should not be compressed (#8803)
`evaluate_to_undefined` does not take shadowed `undefined` into account.
2025-01-31 04:06:24 +00:00
Boshen
bebee7597e
Revert "test(oxlint): ignore windows path mismatch"
This reverts commit 48bfed9f43.
2025-01-31 11:49:24 +08:00
Alexander S.
45648e794a
test(oxlint): fix InvalidOptionTsConfig tests for windows (#8791)
because of:
https://github.com/oxc-project/oxc/actions/runs/13058657372/job/36435970934
> The tsconfig file "E:\\oxc\\apps\\oxlint\\oxc/tsconfig.json"

now I know the reason why eslint is printing it in POSIX style

---------

Co-authored-by: Sysix <alexander.schlegel@clicksports.de>
2025-01-31 11:49:00 +08:00
Yuji Sugiura
3e3fbefecc
refactor(prettier): Verify printing member expr (#8797)
Part of #5068 

- MemberExpression
  - Computed
  - Static, PrivateField
2025-01-31 11:48:12 +08:00
dalaoshu
c2fdfc4a62
refactor(linter): correctly handle loose options for eslint/eqeqeq (#8798)
Related to #8790 

For the configuration `"eqeqeq": ["warn", "alw", { "null": "ignore" }]`,
we should default `"alw"` to `"always"` and correctly handle the option
`{ "null": "ignore" }`.
2025-01-31 11:47:45 +08:00
renovate[bot]
b3bf205c3d
chore(deps): update dependency rust to v1.84.1 (#8799) 2025-01-31 11:44:18 +08:00
Boshen
48bfed9f43
test(oxlint): ignore windows path mismatch 2025-01-31 11:42:42 +08:00
dalaoshu
0aeaedd05d
refactor(linter): support loose options for eslint/eqeqeq (#8790)
closes #8773
2025-01-31 09:51:55 +08:00
overlookmotel
d4eee5002b refactor(ast): comments for enums with no AstKind in generated code for Visit trait (#8796)
"No `AstKind` for this type" comments appear in `walk_*` functions for structs with no `AstKind`. Do the same for enums.
2025-01-31 01:24:51 +00:00
overlookmotel
87a7711d29 refactor(ast): shorten generated code for VisitMut (#8795)
`for x in vec.iter_mut()` is unnecessarily long - `for x in vec` works just as well.
2025-01-31 00:58:47 +00:00
overlookmotel
70ad8797b0 refactor(ast): remove unnecessary lint from generated code for AstKind (#8794) 2025-01-30 22:32:16 +00:00
overlookmotel
beeda9a3b8 refactor(ast): alter comments in generated Visit trait (#8793)
Make these comments more descriptive.
2025-01-30 22:16:42 +00:00
Sysix
6f4a0234ca test(oxlint): remove "--print-config" test (#8792)
it is only removing one test. This test is removed because of: https://github.com/oxc-project/oxc/pull/8789#discussion_r1935775539
Boshen thought too that this should be a problem in the future. I did not believe him :/

Merging without review
2025-01-30 18:14:30 +00:00
7086cmd
6c627dfb98 feat(minifier): implement unary Math functions in known methods (#8781)
The rounding logic between Rust and JavaScript differs, necessitating manual handling.

Furthermore, there is a potential risk of being eliminated from the test suite. Consequently, we must implement an approach that assigns to `x` to mitigate this risk.
2025-01-30 15:07:13 +00:00
7086cmd
ae7f670024 fix(minifier): avoid minifying +void unknown to NaN and fix typo (#8784)
fixes #8782
This bug appears when we arbitrarily eliminate potential side-effective elements in unary expression.
2025-01-30 15:01:22 +00:00
Yuji Sugiura
b3a57696a1
feat(tasks/prettier): Show total match ratio with updating snapshot format (#8788)
Previously, #8634 visualized each spec result, but this was not enough.

If the implementation has been updated but the spec still fails, there
is no way to know if there is an improvement or not.

This time, finally, all progress is visualized! 🤩 


![image](https://github.com/user-attachments/assets/df5b4658-450a-4b0c-8348-ffc9b977c50c)

e.g. here `arrow_function_expression` is mostly passing, except for
comment handling.
2025-01-30 22:27:34 +08:00
Sysix
55c2025a3b test(oxlint): add CliRunResult to snapshot (#8780) 2025-01-30 01:43:42 +00:00
Sysix
9731c56b6a refactor(oxlint): move output from CliRunResult::InvalidOption to outside and use more Enums for different invalid options (#8778)
Now we can choose which exit code to use for a specific (unexpected) result
2025-01-30 01:43:42 +00:00
Sysix
fe45bee0c2 refactor(oxlint): create different CliRunResult instead of passing ExitCode to it (#8777) 2025-01-30 01:43:42 +00:00
Sysix
2378fef3cf refactor(oxlint): move ConfigFileInit output outside CliRunResult, exit code 1 when it fails (#8776) 2025-01-30 01:43:41 +00:00
Sysix
f4cecb52b1 refactor(oxlint): remove unused CliRunResult::PathNotFound (#8775) 2025-01-30 01:43:41 +00:00
overlookmotel
fb5b1fa015 docs(ast): reformat AstBuilder doc comments (#8774)
Reformat doc comments for `AstBuilder` methods, for better readability and consistency.
2025-01-29 15:24:36 +00:00
Sysix
194a5ff76a refactor(linter): remove LintResult (#8712) 2025-01-29 02:26:18 +00:00
Sysix
ad35e82165 test(linter): use snapshot testing instead of LintResult (#8711)
Welcome to the new testing area for oxlint CLI 🥳

There is still one test left to be snapshotted (for invalid options), but everything else works great.
I put some comments on code which I think are the key points of the PR
2025-01-29 02:26:17 +00:00
sapphi-red
86b6219d26
feat(mangler): use characters in the order of their likely frequency (#8771)
Just noticed that we can use a static list here. I think this has no downsides. To have better compression, we can actually count the characters, but I guess there won't be much difference normally.
2025-01-29 02:20:44 +00:00
sapphi-red
0c4c739afc
test(minifier): cleanup some tests in substitute_alternate_syntax (#8768) 2025-01-28 12:26:04 +00:00
sapphi-red
79d5481b14
test(minifier): add and enable some tests in fold_constants (#8769)
Ported some tests that was missing from closure compiler.
Also enabled some tests.
2025-01-28 12:18:05 +00:00
overlookmotel
8cf9d3443c refactor(ast): rename #[estree(type)] attr on struct fields to #[estree(ts_type)] (#8767)
To override the TS type of a struct field in ESTree AST, use `#[estree(ts_type = "Identifier")]` instead of `#[estree(type = "Identifier")]`.

This is clearer, and avoids using the keyword `type`, which makes the attributes simpler to parse.
2025-01-28 12:09:27 +00:00
overlookmotel
a316b10fcd refactor(ast): rename #[estree(type)] attr on types to #[estree(rename)] (#8766)
To rename a type in ESTree AST, use `#[estree(rename = "Identifier")]` instead of `#[estree(type = "Identifier")]`.

This aligns with `serde`'s attribute, and avoids using the keyword `type`, which makes the attributes simpler to parse.
2025-01-28 12:02:05 +00:00
Boshen
878153733c fix(minifier): { let foo; const bar = undefined; } -> { let foo, bar; } (#8764) 2025-01-28 10:14:01 +00:00
Yuji Sugiura
602becd747
refactor(prettier): Verify printing array (#8762)
Part of #5068 

Mostly trivial this time. 😪
2025-01-28 16:50:00 +08:00
Boshen
8a6ae8a062 fix(minifier): do not change const to let if assignment to constant variable. (#8761) 2025-01-28 06:04:25 +00:00
Boshen
003c190d93
chore(deps): update github-actions (#8760)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-01-28 13:30:28 +08:00
翠 / green
66c33ed0af
fix(minifier): remove incorrect not + conditional expression compression (#8759)
```js
var foo = (a) => {
  if (!(a == null ? void 0 : a.b))
    return
  a.b(to);
};
foo(null)
```
was minified into
```js
var foo = (a) => {
	if (a == null && a.b) return;
	a.b(to);
};
foo(null);
```
which is incorrect (no error happens before and error happens after).
I found this while trying rolldown-vite with ecosystem-ci.

refs #8651
2025-01-28 13:30:00 +08:00
Boshen
ef55e7c37c test(minifier): check idempotency for all tests (#8754) 2025-01-27 15:13:08 +00:00
Boshen
d072f09236 test(minifier): enable more ignored tests (#8753) 2025-01-27 14:56:05 +00:00
sapphi-red
e78e46885f
test(minifier): cleanup some tests in minimize_conditions (#8752) 2025-01-27 14:47:09 +00:00
sapphi-red
ad14403f9e
feat(minifier): compress typeof a.b === 'undefined' to a.b === void 0 (#8751)
The special behavior of `typeof` is only for the identifier, so it should be safe to compress `typeof a.b === 'undefined'` (and other expressions) to `a.b === void 0`.
2025-01-27 14:31:13 +00:00
sapphi-red
f7f2d2f93a
feat(minifier): compress a == null && b to a ?? b when return value is ignored (#8749)
Compress `a == null && b` to `a ?? b` when return value is ignored

When `a` is `null` or `undefined`, `a == null && b` returns `b`.
When `a` is not `null` or `undefined`, `a == null && b` returns `false`.

When `a` is `null` or `undefined`, `a ?? b` returns `b`.
When `a` is not `null` or `undefined`, `a ?? b` returns `a`.

**References**
- [Spec of `??`](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-binary-logical-operators-runtime-semantics-evaluation)
2025-01-27 14:31:12 +00:00