Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/binary-operator-printers/logical.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@ import { shouldGroupOrIndent } from './utils/should-group-or-indent.js';

const { indent } = doc.builders;

const indentIfNecessaryBuilder = (path, options) => (document) => {
const indentIfNecessaryBuilder = (path) => (document) => {
for (let i = 0, { node } = path; ; i += 1) {
const parentNode = path.getParentNode(i);
if (notIndentParentTypes.includes(parentNode.type)) return document;
if (
options.experimentalTernaries &&
parentNode.type === 'Conditional' &&
parentNode.condition === node
)
if (parentNode.type === 'Conditional' && parentNode.condition === node)
return document;
if (shouldGroupOrIndent(parentNode, [])) return indent(document);
if (node === parentNode.right) return document;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const createBinaryOperationPrinter =
(groupIfNecessaryBuilder, indentIfNecessaryBuilder) =>
(node, path, print, options) => {
const groupIfNecessary = groupIfNecessaryBuilder(path);
const indentIfNecessary = indentIfNecessaryBuilder(path, options);
const indentIfNecessary = indentIfNecessaryBuilder(path);

return groupIfNecessary([
path.call(print, 'left'),
Expand Down
5 changes: 2 additions & 3 deletions src/slang-printers/create-binary-operation-printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ export const createBinaryOperationPrinter =
path: AstPath<BinaryOperation>
) => (document: Doc) => Doc,
indentRulesBuilder: (
path: AstPath<BinaryOperation>,
options: ParserOptions<AstNode>
path: AstPath<BinaryOperation>
) => (document: Doc) => Doc
) =>
(
Expand All @@ -53,7 +52,7 @@ export const createBinaryOperationPrinter =
options: ParserOptions<AstNode>
): Doc => {
const groupRules = groupRulesBuilder(path);
const indentRules = indentRulesBuilder(path, options);
const indentRules = indentRulesBuilder(path);

return groupRules([
path.call(print, 'leftOperand'),
Expand Down
11 changes: 3 additions & 8 deletions src/slang-printers/print-logical-operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,20 @@ import {
shouldNotIndent
} from './print-binary-operation.js';

import type { AstPath, Doc, ParserOptions } from 'prettier';
import type {
AstNode,
BinaryOperation,
StrictAstNode
} from '../slang-nodes/types.d.ts';
import type { AstPath, Doc } from 'prettier';
import type { BinaryOperation, StrictAstNode } from '../slang-nodes/types.d.ts';

const { indent } = doc.builders;

const logicalGroupRulesBuilder = binaryGroupRulesBuilder(() => false);

const logicalIndentRulesBuilder =
(path: AstPath<BinaryOperation>, options: ParserOptions<AstNode>) =>
(path: AstPath<BinaryOperation>) =>
(document: Doc): Doc => {
for (let i = 1, node = path.node; ; i++) {
const parent = path.getNode(i) as StrictAstNode;
if (shouldNotIndent(parent, path, i)) break;
if (
options.experimentalTernaries &&
parent.kind === NonterminalKind.ConditionalExpression &&
parent.operand === node
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ contract ComparisonOperators {
>= veryVeryVeryVeryVeryLongVariableCalledA;
a +=
veryVeryVeryVeryVeryLongVariableCalledA
|| veryVeryVeryVeryVeryLongVariableCalledB
|| veryVeryVeryVeryVeryLongVariableCalledB
? 1
: 2
) {}
Expand Down Expand Up @@ -638,7 +638,7 @@ contract LogicalOperators {
a <= veryVeryVeryVeryVeryLongVariableCalledA;
a +=
veryVeryVeryVeryVeryLongVariableCalledA
|| veryVeryVeryVeryVeryLongVariableCalledB
|| veryVeryVeryVeryVeryLongVariableCalledB
? 1
: 2
) {}
Expand Down Expand Up @@ -1167,7 +1167,7 @@ contract ComparisonOperators {
veryVeryVeryVeryVeryLongVariableCalledA;
a +=
veryVeryVeryVeryVeryLongVariableCalledA ||
veryVeryVeryVeryVeryLongVariableCalledB
veryVeryVeryVeryVeryLongVariableCalledB
? 1
: 2
) {}
Expand Down Expand Up @@ -1321,7 +1321,7 @@ contract LogicalOperators {
a <= veryVeryVeryVeryVeryLongVariableCalledA;
a +=
veryVeryVeryVeryVeryLongVariableCalledA ||
veryVeryVeryVeryVeryLongVariableCalledB
veryVeryVeryVeryVeryLongVariableCalledB
? 1
: 2
) {}
Expand Down