Skip to content

Commit 490cebf

Browse files
committed
dropping backward compatibility in the antlr parser
1 parent e975f76 commit 490cebf

13 files changed

Lines changed: 40 additions & 89 deletions

src/binary-operator-printers/logical.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { shouldGroupOrIndent } from './utils/should-group-or-indent.js';
77
const { indent } = doc.builders;
88

99
const indentIfNecessaryBuilder = (path, options) => (document) => {
10-
let node = path.getNode();
10+
let { node } = path;
1111
for (let i = 0; ; i += 1) {
1212
const parentNode = path.getParentNode(i);
1313
if (notIndentParentTypes.includes(parentNode.type)) return document;

src/binary-operator-printers/printers/create-binary-operation-printer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const rightOperandPrinter = (node, path, print, options) => {
1111

1212
// If it's a single binary operation, avoid having a small right
1313
// operand like - 1 on its own line
14-
const parent = path.getParentNode();
14+
const { parent } = path;
1515
return node.left.type !== 'BinaryOperation' &&
1616
(parent.type !== 'BinaryOperation' || assignment.match(parent.operator))
1717
? group(right)

src/binary-operator-printers/printers/create-group-if-necessary-builder.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ const { group } = doc.builders;
55

66
export const createGroupIfNecessaryBuilder =
77
(shouldIndentMatchers) => (path) => (document) => {
8-
const parentNode = path.getParentNode();
9-
if (shouldGroupOrIndent(parentNode, shouldIndentMatchers))
8+
const { parent } = path;
9+
if (shouldGroupOrIndent(parent, shouldIndentMatchers))
1010
return group(document);
1111
return document;
1212
};

src/binary-operator-printers/printers/create-indent-if-necessary-builder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const notIndentParentTypes = [
1212

1313
export const createIndentIfNecessaryBuilder =
1414
(shouldIndentMatchers) => (path) => (document) => {
15-
let node = path.getNode();
15+
let { node } = path;
1616
for (let i = 0; ; i += 1) {
1717
const parentNode = path.getParentNode(i);
1818
if (notIndentParentTypes.includes(parentNode.type)) return document;

src/comments/handlers/handleContractDefinitionComments.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { util } from 'prettier';
2-
import { getNextNonSpaceNonCommentCharacter } from '../../common/backward-compatibility.js';
32

4-
const { addLeadingComment, addTrailingComment, addDanglingComment } = util;
3+
const {
4+
addLeadingComment,
5+
addTrailingComment,
6+
addDanglingComment,
7+
getNextNonSpaceNonCommentCharacter
8+
} = util;
59

610
function handleContractDefinitionComments({
711
text,
@@ -22,8 +26,7 @@ function handleContractDefinitionComments({
2226
// it is a {}.
2327
const nextCharacter = getNextNonSpaceNonCommentCharacter(
2428
text,
25-
comment,
26-
options.locEnd
29+
options.locEnd(comment)
2730
);
2831

2932
// The comment is behind the start of the Block `{}` or behind a base contract

src/comments/handlers/handleModifierInvocationComments.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { util } from 'prettier';
2-
import { getNextNonSpaceNonCommentCharacter } from '../../common/backward-compatibility.js';
32

4-
const { addLeadingComment, addTrailingComment, addDanglingComment } = util;
3+
const {
4+
addLeadingComment,
5+
addTrailingComment,
6+
addDanglingComment,
7+
getNextNonSpaceNonCommentCharacter
8+
} = util;
59

610
function handleModifierInvocationComments({
711
text,
@@ -21,8 +25,7 @@ function handleModifierInvocationComments({
2125
// it is a ().
2226
const nextCharacter = getNextNonSpaceNonCommentCharacter(
2327
text,
24-
comment,
25-
options.locEnd
28+
options.locEnd(comment)
2629
);
2730

2831
// The comment is behind the start of the Parentheses `()`

src/common/backward-compatibility.js

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/common/printer-helpers.js

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
import { doc } from 'prettier';
2-
import {
3-
isLast,
4-
isNextLineEmpty,
5-
isPrettier2
6-
} from './backward-compatibility.js';
1+
import { doc, util } from 'prettier';
72

83
const { group, indent, join, line, softline, hardline } = doc.builders;
4+
const { isNextLineEmpty } = util;
95

106
export const printComments = (node, path, options, filter = () => true) => {
117
if (!node.comments) return '';
@@ -26,14 +22,7 @@ export const printComments = (node, path, options, filter = () => true) => {
2622
.filter(Boolean)
2723
);
2824

29-
// The following if statement will never be 100% covered in a single run
30-
// since it depends on the version of Prettier being used.
31-
// Mocking the behaviour will introduce a lot of maintenance in the tests.
32-
/* c8 ignore start */
33-
return isPrettier2
34-
? document.parts // Prettier V2
35-
: document; // Prettier V3
36-
/* c8 ignore stop */
25+
return document;
3726
};
3827

3928
export function printPreservingEmptyLines(path, key, options, print) {
@@ -56,7 +45,7 @@ export function printPreservingEmptyLines(path, key, options, print) {
5645

5746
// Only attempt to append an empty line if `node` is not the last item
5847
if (
59-
!isLast(childPath, key, index) &&
48+
!childPath.isLast &&
6049
isNextLineEmpty(options.originalText, options.locEnd(node) + 1)
6150
) {
6251
// Append an empty line if the original text already had an one after

src/nodes/Conditional.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { printSeparatedItem } from '../common/printer-helpers.js';
44
const { group, hardline, ifBreak, indent, line, softline } = doc.builders;
55

66
const experimentalTernaries = (node, path, print, options) => {
7-
const parent = path.getParentNode();
7+
const { parent } = path;
88
const isNested = parent.type === 'Conditional';
99
const isNestedAsTrueExpression = isNested && parent.trueExpression === node;
1010
const falseExpressionIsNested = node.falseExpression.type === 'Conditional';
@@ -68,7 +68,7 @@ const traditionalTernaries = (path, print) =>
6868
indent([
6969
// Nested trueExpression and falseExpression are always printed in a new
7070
// line
71-
path.getParentNode().type === 'Conditional' ? hardline : line,
71+
path.parent.type === 'Conditional' ? hardline : line,
7272
'? ',
7373
path.call(print, 'trueExpression'),
7474
line,

src/nodes/ExpressionStatement.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const ExpressionStatement = {
77
print: ({ node, options, path, print }) => {
88
const parts = [];
99

10-
const parent = path.getParentNode();
10+
const { parent } = path;
1111

1212
if (parent.type === 'IfStatement') {
1313
if (node.comments?.length) {

0 commit comments

Comments
 (0)