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
25 changes: 13 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,16 @@
"@eslint/js": "^9.28.0",
"@types/jest": "^29.5.14",
"@types/semver": "^7.7.0",
"@typescript-eslint/eslint-plugin": "^8.33.1",
"@typescript-eslint/parser": "^8.33.1",
"@typescript-eslint/eslint-plugin": "^8.34.0",
"@typescript-eslint/parser": "^8.34.0",
"c8": "^10.1.3",
"cross-env": "^7.0.3",
"eslint": "^9.28.0",
"eslint-config-prettier": "^10.1.5",
"esm-utils": "^4.4.2",
"globals": "^16.2.0",
"jest": "^29.7.0",
"jest-light-runner": "^0.7.8",
"jest-light-runner": "^0.7.9",
"jest-snapshot-serializer-ansi": "^2.2.1",
"jest-snapshot-serializer-raw": "^2.0.0",
"jest-watch-typeahead": "^2.2.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import { assignment } from '../assignment.js';

const { group, line } = doc.builders;

const rightOperandPrinter = (node, path, print) => {
const right = [' ', node.operator, line, path.call(print, 'right')];
const rightOperandPrinter = (node, path, print, options) => {
const right =
options.experimentalOperatorPosition === 'end'
? [' ', node.operator, line, path.call(print, 'right')]
: [line, node.operator, ' ', path.call(print, 'right')];

// If it's a single binary operation, avoid having a small right
// operand like - 1 on its own line
Expand All @@ -23,6 +26,6 @@ export const createBinaryOperationPrinter =

return groupIfNecessary([
path.call(print, 'left'),
indentIfNecessary(rightOperandPrinter(node, path, print))
indentIfNecessary(rightOperandPrinter(node, path, print, options))
]);
};
16 changes: 16 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ const options: SupportOptions = {
oppositeDescription:
'Default behavior of ternaries; keep question marks on the same line as the consequent.'
},
experimentalOperatorPosition: {
category: CATEGORY_JAVASCRIPT,
type: 'choice',
default: 'end',
description: 'Where to print operators when binary expressions wrap lines.',
choices: [
{
value: 'start',
description: 'Print operators at the start of new lines.'
},
{
value: 'end',
description: 'Print operators at the end of previous lines.'
}
]
},
compiler: {
category: CATEGORY_SOLIDITY,
type: 'string',
Expand Down
15 changes: 8 additions & 7 deletions src/slang-printers/create-binary-operation-printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ const { group, line } = doc.builders;
function rightOperandPrint(
node: BinaryOperation,
path: AstPath<BinaryOperation>,
print: PrintFunction
print: PrintFunction,
options: ParserOptions<AstNode>
): Doc {
const rightOperand = [
` ${node.operator}`,
line,
path.call(print, 'rightOperand')
];
const rightOperand =
options.experimentalOperatorPosition === 'end'
? [` ${node.operator}`, line, path.call(print, 'rightOperand')]
: [line, `${node.operator} `, path.call(print, 'rightOperand')];

// If it's a single binary operation, avoid having a small right
// operand like - 1 on its own line
const leftOperand = node.leftOperand.variant;
Expand Down Expand Up @@ -58,6 +59,6 @@ export const createBinaryOperationPrinter =

return groupRules([
path.call(print, 'leftOperand'),
indentRules(rightOperandPrint(node, path, print))
indentRules(rightOperandPrint(node, path, print, options))
]);
};
Loading