Co-authored-by: Alexander Kachkaev <alexander@kachkaev.ru>
1.4 KiB
1.4 KiB
Improve logical not expression print (#18397, #18401 by @fisker)
- Fixed inner logical expression can be double parenthesized in some case.
- Inline the expression in
if/while/do..whilecondition, to reduce diff when changing condition to negated value.
// Input
if (!(
// `import("foo")`
node.type === "ImportExpression" ||
// `type foo = import("foo")`
node.type === "TSImportType"
)) {
} else if (
// `import("foo")`
node.type === "ImportExpression" ||
// `type foo = import("foo")`
node.type === "TSImportType"
) {
}
// Prettier stable
if (
!(
// `import("foo")`
(
node.type === "ImportExpression" ||
// `type foo = import("foo")`
node.type === "TSImportType"
)
)
) {
} else if (
// `import("foo")`
node.type === "ImportExpression" ||
// `type foo = import("foo")`
node.type === "TSImportType"
) {
}
// Prettier main
if (!(
// `import("foo")`
node.type === "ImportExpression" ||
// `type foo = import("foo")`
node.type === "TSImportType"
)) {
} else if (
// `import("foo")`
node.type === "ImportExpression" ||
// `type foo = import("foo")`
node.type === "TSImportType"
) {
}
This code example above is a real world case right here in the Prettier codebase