Skip to content

Commit

Permalink
Simplify printBinaryCastExpression (prettier#15932)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker authored and medikoo committed Feb 17, 2024
1 parent c5e2567 commit a7a6775
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/language-js/print/cast-expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,25 @@ import { group, indent, softline } from "../../document/builders.js";
import { isCallExpression, isMemberExpression } from "../utils/index.js";

function printBinaryCastExpression(path, options, print) {
const { parent, node } = path;
let parts = [];
const { parent, node, key } = path;
const parts = [print("expression")];
switch (node.type) {
case "AsConstExpression":
parts = [print("expression"), " as const"];
parts.push(" as const");
break;
case "AsExpression":
case "TSAsExpression":
parts = [print("expression"), " ", "as", " ", print("typeAnnotation")];
parts.push(" as ", print("typeAnnotation"));
break;
case "SatisfiesExpression":
case "TSSatisfiesExpression":
parts = [
print("expression"),
" ",
"satisfies",
" ",
print("typeAnnotation"),
];
parts.push(" satisfies ", print("typeAnnotation"));
break;
}

if (
(isCallExpression(parent) && parent.callee === node) ||
(isMemberExpression(parent) && parent.object === node)
(key === "callee" && isCallExpression(parent)) ||
(key === "object" && isMemberExpression(parent))
) {
return group([indent([softline, ...parts]), softline]);
}
Expand Down

0 comments on commit a7a6775

Please sign in to comment.