Use logical assignment operator shorthand

Proprietary

Converts a = a || b and a || (a = b) into the ES2021 logical assignment shorthand a ||= b, and equivalently for &&= and ??=. a = a || b is only rewritten where a is a plain name, since for a property it would change how often a getter or setter runs, and nothing is rewritten inside a with statement, where a name may resolve to such a property. Replicates the autofix of the ESLint rule logical-assignment-operators under its default options.

io.moderne.javascript.cleanup.LogicalAssignmentOperators

Optional

Only change files whose nearest package.json declares an engines.node range that admits no Node.js release older than 15.0.0, the first to parse ||=, &&= and ??=, and TypeScript files, which tsc lowers to the project's target, unless their package.json declares an older Node.js. Other files are left unchanged. Default is false.

mod run . --recipe=io.moderne.javascript.cleanup.LogicalAssignmentOperators

Install it once, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.