oxc/crates
sapphi-red ec88c68c28
feat(minifier): compress a || (a = b) to a ||= b (#8315)
Compress `a || (a = b)` to `a ||= b` and for other logical operators that are possible to.

I didn't find other minifiers doing this, but this is safe for identifiers. [Quoting MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR_assignment#description):

> Logical OR assignment short-circuits, meaning that `x ||= y` is equivalent to `x || (x = y)`, except that the expression x is only evaluated once.

I actually checked the spec and the only difference was that `Let lRef be ? Evaluation of LeftHandSideExpression` was done twice. Evaluating an IdentifierReference is idempotent so it should be safe to do this compression.

References:

- [Spec of `&&=`](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-assignment-operators:~:text=Return%20r.-,AssignmentExpression,7.%20Return%20rVal.,-AssignmentExpression)
- [Spec of `=`](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#prod-AssignmentExpression:~:text=Runtime%20Semantics%3A%20Evaluation-,AssignmentExpression,6.%20Return%20rVal.,-AssignmentExpression)
- [Spec of `&&`](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-binary-logical-operators:~:text=Runtime%20Semantics%3A%20Evaluation-,LogicalANDExpression,5.%20Return%20%3F%C2%A0GetValue(rRef).,-LogicalORExpression)

I think this is safe for `a.b || (a.b = foo)` as well because the number of `GetValue` and `SetValue` does not change, but I didn't include that in this PR.
2025-01-07 23:19:52 +00:00
..
oxc release(crates): v0.44.0 (#8110) 2024-12-25 21:03:09 +08:00
oxc_allocator feat(minifier): improve StatementFusion (#8194) 2024-12-31 01:13:24 +00:00
oxc_ast refactor(ast)!: no unneccesary trailing underscores on AstBuilder method names (#8283) 2025-01-06 15:09:05 +00:00
oxc_ast_macros release(crates): v0.44.0 (#8110) 2024-12-25 21:03:09 +08:00
oxc_cfg release(crates): v0.44.0 (#8110) 2024-12-25 21:03:09 +08:00
oxc_codegen feat(minifier): minimize do{}while(true) -> do;while(true) (#8311) 2025-01-07 12:55:03 +00:00
oxc_data_structures release(crates): v0.44.0 (#8110) 2024-12-25 21:03:09 +08:00
oxc_diagnostics release(crates): v0.44.0 (#8110) 2024-12-25 21:03:09 +08:00
oxc_ecmascript feat(minifier): fold .toString() (#8308) 2025-01-07 06:33:58 +00:00
oxc_estree release(crates): v0.44.0 (#8110) 2024-12-25 21:03:09 +08:00
oxc_isolated_declarations refactor(ast): simplify get_identifier_reference of TSType and TSTypeName (#8273) 2025-01-06 08:23:53 +00:00
oxc_language_server refactor(linter): refactor LintBuilder to prep for nested configs (#8034) 2025-01-05 04:08:26 +00:00
oxc_linter refactor(ast): simplify get_identifier_reference of TSType and TSTypeName (#8273) 2025-01-06 08:23:53 +00:00
oxc_macros feat(linter)!: remove unmaintained security plugin (#7773) 2024-12-10 14:29:22 +00:00
oxc_mangler release(crates): v0.44.0 (#8110) 2024-12-25 21:03:09 +08:00
oxc_minifier feat(minifier): compress a || (a = b) to a ||= b (#8315) 2025-01-07 23:19:52 +00:00
oxc_napi release(crates): v0.44.0 (#8110) 2024-12-25 21:03:09 +08:00
oxc_parser fix(lexer): Source is not Clone (#8294) 2025-01-07 06:58:26 +00:00
oxc_prettier feat(prettier): Print tagged template literal (#8307) 2025-01-07 14:25:14 +08:00
oxc_regular_expression release(crates): v0.44.0 (#8110) 2024-12-25 21:03:09 +08:00
oxc_semantic chore(deps): update crate-ci/typos action to v1.29.4 (#8265) 2025-01-05 22:13:32 +00:00
oxc_span style(span): reformat code (#8296) 2025-01-06 13:57:58 +00:00
oxc_syntax feat(minifier): compress a || (a = b) to a ||= b (#8315) 2025-01-07 23:19:52 +00:00
oxc_transformer fix(transformer/arrow-functions): _this = this should be inserted after super call expression (#8024) 2025-01-07 13:53:44 +00:00
oxc_traverse release(crates): v0.44.0 (#8110) 2024-12-25 21:03:09 +08:00
oxc_wasm refactor(linter): refactor LintBuilder to prep for nested configs (#8034) 2025-01-05 04:08:26 +00:00