MCPcopy
hub / github.com/prettier/prettier / printBinaryishExpression

Function printBinaryishExpression

src/language-js/print/binaryish.js:41–185  ·  view source on GitHub ↗
(path, options, print)

Source from the content-addressed store, hash-verified

39- `NGPipeExpression`(Angular)
40*/
41function printBinaryishExpression(path, options, print) {
42 const { node, parent, grandparent, key } = path;
43 const isInsideParenthesis =
44 key !== "body" &&
45 (parent.type === "IfStatement" ||
46 parent.type === "WhileStatement" ||
47 parent.type === "SwitchStatement" ||
48 parent.type === "DoWhileStatement");
49 const isHackPipeline =
50 node.operator === "|>" && path.root.extra?.__isUsingHackPipeline;
51
52 const parts = printBinaryishExpressions(
53 path,
54 options,
55 print,
56 /* isNested */ false,
57 isInsideParenthesis,
58 );
59
60 // if (
61 // this.hasPlugin("dynamicImports") && this.lookahead().type === tt.parenLeft
62 // ) {
63 //
64 // looks super weird, we want to break the children if the parent breaks
65 //
66 // if (
67 // this.hasPlugin("dynamicImports") &&
68 // this.lookahead().type === tt.parenLeft
69 // ) {
70 if (isInsideParenthesis) {
71 return parts;
72 }
73
74 if (isHackPipeline) {
75 return group(parts);
76 }
77
78 // Break between the parens in
79 // unaries or in a member or specific call expression, i.e.
80 //
81 // (
82 // a &&
83 // b &&
84 // c
85 // ).call()
86 if (
87 (key === "callee" && isCallOrNewExpression(parent)) ||
88 // `UnaryExpression` adds parentheses and indention when argument has comment
89 (parent.type === "UnaryExpression" && !hasComment(node)) ||
90 (isMemberExpression(parent) && !parent.computed)
91 ) {
92 return group([indent([softline, ...parts]), softline]);
93 }
94
95 // Avoid indenting sub-expressions in some cases where the first sub-expression is already
96 // indented accordingly. We should indent sub-expressions where the first case isn't indented.
97 const shouldNotIndent =
98 isReturnOrThrowStatement(parent) ||

Callers 2

printAngularFunction · 0.90
printEstreeFunction · 0.90

Calls 10

groupFunction · 0.90
hasCommentFunction · 0.90
indentFunction · 0.90
isBooleanTypeCoercionFunction · 0.90
isObjectPropertyFunction · 0.90
shouldFlattenFunction · 0.90
indentIfBreakFunction · 0.90
atMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…