Boshen
d55331815d
feat(minifier): complete MangleIf ( #8810 )
...
Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2025-02-02 17:21:17 +08:00
Daniel Bulant
6aa2ddeb85
refactor(codegen): accept SymbolTable instead of Mangler ( #8829 )
...
It seems to be that the easiest way to rename variables is to use
rename_symbol from SymbolTable and to let it be applied during codegen -
this is what Mangler does.
This PR changes Codegen to accept (any) SymbolTable instead of just
Mangler itself, and for Mangler build output to be a new SymbolTable,
after consuming itself (which makes it clear at the type level if a
Mangler has been built or not).
This also moves the few symbol table helper methods from Mangler to
SymbolTable itself, and adds an example of Mangler use to it's
documentation.
Codegen dependencies now include semantic (which was transient by
mangler before). It's dependency on Mangler could be removed, though
I've left it to allow easy linking of docs (with_symbol_table points
users to Mangler, hopefully helps with migration?)
2025-02-02 17:13:09 +08:00
camchenry
bb9d76352f
refactor(linter): remove usage of url crate ( #8833 )
...
In the linter, this was only used for getting a query parameter value out of a URL. These lint rules already check that the URL value is a known-good URL so we don't need to validate and parse it. I've replaced these usages with a simple helper function to get the value from the query string.
There was also a usage in the tasks directory for getting test files and I've also skipped validating here since it's not strictly necessary as we control all inputs.
2025-02-02 01:16:03 +00:00
sapphi-red
5cfea76bc3
feat(minifier): compress (a = _a) != null ? a : b and (a = _a) != null ? a.b() : undefined ( #8823 )
...
Compresses `(a = _a) != null ? a : b` to `(a = _a) ?? b` and `(a = _a) != null ? a.b() : undefined` to `(a = _a).b()`. This commonly happens when lowered.
2025-02-02 01:09:20 +00:00
overlookmotel
0568210f78
refactor(ast): remove excess line breaks from generated code ( #8830 )
...
Pure refactor. Just remove excess line breaks.
2025-02-01 20:05:17 +00:00
overlookmotel
30eec26c4a
refactor(ast): make generated code for Visit more understandable ( #8825 )
...
Pure refactor. `for elements in it.elements.iter().flatten()` doesn't make much sense - each item is a single element, not multiple elements. Change to `for el in it.elements.iter().flatten()`.
2025-02-01 15:22:11 +00:00
Cam McHenry
57b7ca8eae
docs(ast): add documentation for all remaining JS AST methods ( #8820 )
...
Finishes the remaining items that require documenting for the JS AST
implementations. Once again, I tried my best to ensure these are
accurate, but it might not be 100% correct.
I also renamed the `get_identifier` method to `get_identifier_name` to
make it clear that it returns an `Atom`/`str` and not an `Identifier`.
2025-02-01 21:41:15 +08:00
Dunqing
256ae785ca
feat(semantic): report error for empty JSX attribute expression ( #8815 )
...
https://www.typescriptlang.org/play/?#code/DwEwlgbgBAhgvAbwL4D5gHpwRUA
This is not a valid JSX syntax
2025-02-01 02:30:39 +00:00
sapphi-red
d9f1d0daa1
feat(minifier): merge expressions in for-in statement head ( #8811 )
...
Compress `a; for (var b in c) d` into `for (var b in a, c) d`. This is possible when the left hand does not have a sideeffectful initializer. (Initializers on the left hand of for-in is Annex B thing.)
**References**
- [Spec of `ForIn/OfHeadEvaluation`](https://tc39.es/ecma262/multipage/ecmascript-language-statements-and-declarations.html#sec-runtime-semantics-forinofheadevaluation ): `c` in the example above is passed as `expr` to this abstract operation. No side effect exists before Step 3.
- [Spec of the initializer in ForIn](https://tc39.es/ecma262/multipage/additional-ecmascript-features-for-web-browsers.html#sec-initializers-in-forin-statement-heads ): See "The runtime semantics of ForInOfLoopEvaluation in 14.7.5.5 are augmented with the following:" part. Evaluation of Initializer is executed before `ForIn/OfHeadEvalution`. This is the reason why it cannot be compressed when a sideeffectful initializer exists.
2025-01-31 15:31:24 +00:00
Boshen
3bc05faf27
feat(transformer): implement jsx spread child ( #8763 )
...
closes #8690
2025-01-31 15:20:54 +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
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
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
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
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
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! 🤩

e.g. here `arrow_function_expression` is mostly passing, except for
comment handling.
2025-01-30 22:27:34 +08: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
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
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
翠 / 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
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
sapphi-red
3c1c92cac0
feat(minifier): support a[0] and this.a in has_no_side_effect_for_evaluation_same_target ( #8748 )
...
Add support for `a[0]` and `this.a` in `has_no_side_effect_for_evaluation_same_target` function.
2025-01-27 14:31:11 +00:00
Boshen
29417ddc03
feat(minifier): minimize !(a, b) -> a, !b ( #8746 )
2025-01-27 08:24:07 +00:00
renovate[bot]
e00e3abd84
chore(deps): update rust crates (major) ( #8739 )
...
This PR contains the following updates:
| Package | Type | Update | Change |
|---|---|---|---|
| [oxc_resolver](https://redirect.github.com/oxc-project/oxc-resolver ) |
workspace.dependencies | major | `3` -> `4` |
| [ureq](https://redirect.github.com/algesten/ureq ) |
workspace.dependencies | major | `2.12.1` -> `3.0.0` |
---
### Release Notes
<details>
<summary>oxc-project/oxc-resolver (oxc_resolver)</summary>
###
[`v4.0.0`](https://redirect.github.com/oxc-project/oxc-resolver/blob/HEAD/CHANGELOG.md#400---2025-01-20 )
[Compare
Source](https://redirect.github.com/oxc-project/oxc-resolver/compare/oxc_resolver-v3.0.3...oxc_resolver-v4.0.0 )
##### <!-- 0 -->Features
- \[**breaking**] generic fs cache `type Resolver =
ResolverGeneric<FsCache<FileSystemOs>>`
([#​358](https://redirect.github.com/oxc-project/oxc-resolver/issues/358 ))
- \[**breaking**] `PackageJson` and `TsConfig` traits
([#​360](https://redirect.github.com/oxc-project/oxc-resolver/issues/360 ))
##### <!-- 2 -->Performance
- use papaya instead of dashmap
([#​356](https://redirect.github.com/oxc-project/oxc-resolver/issues/356 ))
</details>
<details>
<summary>algesten/ureq (ureq)</summary>
###
[`v3.0.0`](https://redirect.github.com/algesten/ureq/blob/HEAD/CHANGELOG.md#300 )
[Compare
Source](https://redirect.github.com/algesten/ureq/compare/2.12.1...3.0.0 )
- Replace RequestBuilder Deref with explicit wrappers
([#​944](https://redirect.github.com/algesten/ureq/issues/944 ))
- Remove dependency on `url` crate
([#​943](https://redirect.github.com/algesten/ureq/issues/943 ))
- Feature `Config::save_redirect_history`
([#​939](https://redirect.github.com/algesten/ureq/issues/939 ))
</details>
---
### Configuration
📅 **Schedule**: Branch creation - "on monday" in timezone Asia/Shanghai,
Automerge - "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:eyJjcmVhdGVkSW5WZXIiOiIzOS4xMjUuMSIsInVwZGF0ZWRJblZlciI6IjM5LjEyNS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->
---------
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Boshen <boshenc@gmail.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-01-27 12:56:52 +08:00
renovate[bot]
40362dfc01
chore(deps): update npm packages ( #8740 )
2025-01-27 12:10:20 +08:00
sapphi-red
e0117db531
feat(minifier): replace const with let for non-exported read-only variables ( #8733 )
...
Replace `const` with `let` when that value does not have any assignments and not exposed.
2025-01-26 12:44:01 +00:00
sapphi-red
360d49e962
feat(minifier): replace Math.pow with ** ( #8730 )
...
Replaces `Math.pow(a, b)` with `(+a) ** (+b)`. `+` does `ToNumber` and `**` does `Number::exponentiate` when both operands are number.
`+` is not added when `a` or `b` is already a number.
**Reference**
- [Spec of `Math.pow`](https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-math.pow )
- [Spec of `**`](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-exp-operator-runtime-semantics-evaluation )
- [Spec of unary `+`](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-unary-plus-operator-runtime-semantics-evaluation )
2025-01-26 11:24:19 +00:00
Boshen
e9fb5febdf
feat(minifier): dce pure expressions such as new Map() ( #8725 )
2025-01-26 18:08:34 +08:00
branchseer
3e509e1c9b
fix(transformer/typescript): enum merging when same name declared in outer scope ( #8691 )
...
```typescript
var x = 10;
enum Merge { x = Math.random() }
enum Merge {
y = x // <-- refers to Merge.x
}
```
This case wasn't covered in #8543 and by the [babel test
case](e568916ef3/packages/babel-plugin-transform-typescript/test/fixtures/enum/non-constant-member-reference/input.ts ).
To handle it we still have to go through the scope ancestors.
---------
Co-authored-by: Dunqing <dengqing0821@gmail.com>
2025-01-26 09:18:00 +08:00
Dunqing
e7ab96cbb6
fix(transformer/jsx): incorrect isStaticChildren argument for Fragment with multiple children ( #8713 )
...
close : #8650
2025-01-25 16:11:28 +00:00
Boshen
0af0267077
refactor(minifier): side effect detection needs symbols resolution ( #8715 )
2025-01-25 15:01:00 +00:00
翠 / green
6589c3bbb3
feat(mangler): reuse variable names ( #8562 )
...
Changed the mangler to reuse variable names where possible.
This will reduce the code size as shorter variable names can be used in
more places. But requires global information and limits parallelism in a
single file and requires more memory.
---------
Co-authored-by: Boshen <boshenc@gmail.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-01-25 14:00:24 +08:00
Boshen
8587965e45
perf(minifier): normalize undefined to void 0 before everything else ( #8699 )
...
so subsequent code don't need to lookup `undefined`.
2025-01-25 11:50:08 +08:00
Boshen
b7f13e636e
feat(ast): implement utf8 to utf16 span converter ( #8687 )
...
closes #8629
2025-01-24 16:57:44 +00:00
sapphi-red
343690e178
feat(minifier): replace Number.*_SAFE_INTEGER/Number.EPSILON ( #8682 )
...
The value of `Number.*_SAFE_INTEGER`, `Number.EPSILON` are constants as they cannot be changed. This PR replaces them with `2**53-1` / `-(2**53-1)` / `2**-52` for ES2016+. For ES2015, `Number.EPSILON` is not changed but `Number.*_SAFE_INTEGER`s are replaced with `9007199254740991` / `-9007199254740991`.
**Reference**
- Spec of [`Number.MAX_SAFE_INTEGER`](https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-number.max_safe_integer )
- Spec of [`Number.MIN_SAFE_INTEGER`](https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-number.min_safe_integer )
- Spec of [`Number.EPSILON`](https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-number.epsilon )
### Additional Information
- [`Number.MIN_VALUE`](https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-number.min_value ) cannot be replaced as the value depends on the runtime
- [`Number.MAX_VALUE`](https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-number.max_value ) can be replaced but I didn't come up with a shorter representation that does not lack precision
2025-01-24 03:47:52 +00:00
sapphi-red
0c5bb30859
feat(minifier): replace Number.POSITIVE_INFINITY/Number.NEGATIVE_INFINITY/Number.NaN ( #8681 )
...
The value of `Number.POSITIVE_INFINITY`, `Number.NEGATIVE_INFINITY`, `Number.NaN` are constants as they cannot be changed. This PR replaces them with `Infinity`/`-Infinity`/`NaN`.
**Reference**
- Spec of [`Number.POSITIVE_INFINITY`](https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-number.positive_infinity )
- Spec of [`Number.NEGATIVE_INFINITY`](https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-number.positive_infinity )
- Spec of [`Number.NaN`](https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-number.positive_infinity )
2025-01-23 15:26:22 +00:00
Boshen
99607d3f82
feat(codegen): print comments in TSTypeLiteral ( #8679 )
...
fixes #8665
2025-01-23 14:31:55 +00:00
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
ba201a6511
fix(minifier): remove "non esbuild optimizations" which is incorrect ( #8668 )
2025-01-23 03:45:42 +00: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
Boshen
3802d28233
refactor(minifier): clean up try_minimize_conditional ( #8660 )
2025-01-22 15:17:47 +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
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