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
7 changes: 4 additions & 3 deletions src/slang-comments/handlers/add-collection-first-comment.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { util } from 'prettier';
import {
addDanglingComment,
addLeadingComment
} from '../../slang-utils/prettier-utils.js';

import type { Comment, StrictCollection } from '../../slang-nodes/types.d.ts';

const { addDanglingComment, addLeadingComment } = util;

export default function addCollectionFirstComment(
node: StrictCollection,
comment: Comment
Expand Down
7 changes: 4 additions & 3 deletions src/slang-comments/handlers/add-collection-last-comment.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { util } from 'prettier';
import {
addDanglingComment,
addTrailingComment
} from '../../slang-utils/prettier-utils.js';

import type { Comment, StrictCollection } from '../../slang-nodes/types.d.ts';

const { addDanglingComment, addTrailingComment } = util;

export default function addCollectionLastComment(
node: StrictCollection,
comment: Comment
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { util } from 'prettier';
import {
addLeadingComment,
addTrailingComment,
getNextNonSpaceNonCommentCharacter
} from '../../slang-utils/prettier-utils.js';
import { locEnd } from '../../slang-utils/loc.js';
import addCollectionLastComment from './add-collection-last-comment.js';

import type { HandlerParams } from './types.d.ts';

const { addLeadingComment, addTrailingComment } = util;

export default function handleContractDefinitionComments({
text,
precedingNode,
Expand All @@ -18,7 +20,7 @@ export default function handleContractDefinitionComments({
return false;
}

const nextCharacter = util.getNextNonSpaceNonCommentCharacter(
const nextCharacter = getNextNonSpaceNonCommentCharacter(
text,
locEnd(comment)
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { util } from 'prettier';
import { addTrailingComment } from '../../slang-utils/prettier-utils.js';
import addCollectionLastComment from './add-collection-last-comment.js';

import type { HandlerParams } from './types.d.ts';

const { addTrailingComment } = util;

export default function handleContractSpecifiersComments({
precedingNode,
enclosingNode,
Expand Down
4 changes: 1 addition & 3 deletions src/slang-comments/handlers/handle-else-branch-comments.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { util } from 'prettier';
import { addLeadingComment } from '../../slang-utils/prettier-utils.js';
import addCollectionFirstComment from './add-collection-first-comment.js';

import type { HandlerParams } from './types.d.ts';

const { addLeadingComment } = util;

export default function handleElseBranchComments({
enclosingNode,
followingNode,
Expand Down
10 changes: 6 additions & 4 deletions src/slang-comments/handlers/handle-if-statement-comments.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { util } from 'prettier';
import {
addLeadingComment,
addTrailingComment,
getNextNonSpaceNonCommentCharacter
} from '../../slang-utils/prettier-utils.js';
import { locEnd } from '../../slang-utils/loc.js';
import addCollectionFirstComment from './add-collection-first-comment.js';

import type { HandlerParams } from './types.d.ts';

const { addLeadingComment, addTrailingComment } = util;

export default function handleIfStatementComments({
text,
precedingNode,
Expand All @@ -23,7 +25,7 @@ export default function handleIfStatementComments({
// if (a /* comment */) {}
// The only workaround I found is to look at the next character to see if
// it is a ).
const nextCharacter = util.getNextNonSpaceNonCommentCharacter(
const nextCharacter = getNextNonSpaceNonCommentCharacter(
text,
locEnd(comment)
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { util } from 'prettier';
import { getNextNonSpaceNonCommentCharacter } from '../../slang-utils/prettier-utils.js';
import { locEnd } from '../../slang-utils/loc.js';
import addCollectionFirstComment from './add-collection-first-comment.js';
import addCollectionLastComment from './add-collection-last-comment.js';
Expand All @@ -17,7 +17,7 @@ export default function handleInterfaceDefinitionComments({
return false;
}

const nextCharacter = util.getNextNonSpaceNonCommentCharacter(
const nextCharacter = getNextNonSpaceNonCommentCharacter(
text,
locEnd(comment)
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { util } from 'prettier';
import { getNextNonSpaceNonCommentCharacter } from '../../slang-utils/prettier-utils.js';
import { locEnd } from '../../slang-utils/loc.js';
import addCollectionFirstComment from './add-collection-first-comment.js';
import addCollectionLastComment from './add-collection-last-comment.js';
Expand All @@ -17,7 +17,7 @@ export default function handleLibraryDefinitionComments({
return false;
}

const nextCharacter = util.getNextNonSpaceNonCommentCharacter(
const nextCharacter = getNextNonSpaceNonCommentCharacter(
text,
locEnd(comment)
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { util } from 'prettier';
import {
addLeadingComment,
addTrailingComment
} from '../../slang-utils/prettier-utils.js';

import type { HandlerParams } from './types.d.ts';

const { addLeadingComment, addTrailingComment } = util;

export default function handleMemberAccessExpressionComments({
precedingNode,
enclosingNode,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { util } from 'prettier';
import {
addTrailingComment,
getNextNonSpaceNonCommentCharacter
} from '../../slang-utils/prettier-utils.js';
import { locEnd } from '../../slang-utils/loc.js';
import addCollectionFirstComment from './add-collection-first-comment.js';

import type { HandlerParams } from './types.d.ts';

const { addTrailingComment } = util;

export default function handleModifierInvocationComments({
text,
precedingNode,
Expand All @@ -18,7 +19,7 @@ export default function handleModifierInvocationComments({
return false;
}

const nextCharacter = util.getNextNonSpaceNonCommentCharacter(
const nextCharacter = getNextNonSpaceNonCommentCharacter(
text,
locEnd(comment)
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { util } from 'prettier';
import { getNextNonSpaceNonCommentCharacter } from '../../slang-utils/prettier-utils.js';
import { locEnd } from '../../slang-utils/loc.js';
import addCollectionFirstComment from './add-collection-first-comment.js';
import addCollectionLastComment from './add-collection-last-comment.js';
Expand All @@ -17,7 +17,7 @@ export default function handleStructDefinitionComments({
return false;
}

const nextCharacter = util.getNextNonSpaceNonCommentCharacter(
const nextCharacter = getNextNonSpaceNonCommentCharacter(
text,
locEnd(comment)
);
Expand Down
10 changes: 6 additions & 4 deletions src/slang-comments/handlers/handle-while-statement-comments.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { util } from 'prettier';
import {
addLeadingComment,
addTrailingComment,
getNextNonSpaceNonCommentCharacter
} from '../../slang-utils/prettier-utils.js';
import { locEnd } from '../../slang-utils/loc.js';
import addCollectionFirstComment from './add-collection-first-comment.js';

import type { HandlerParams } from './types.d.ts';

const { addLeadingComment, addTrailingComment } = util;

export default function handleWhileStatementComments({
text,
precedingNode,
Expand All @@ -23,7 +25,7 @@ export default function handleWhileStatementComments({
// while (a /* comment */) {}
// The only workaround I found is to look at the next character to see if
// it is a ).
const nextCharacter = util.getNextNonSpaceNonCommentCharacter(
const nextCharacter = getNextNonSpaceNonCommentCharacter(
text,
locEnd(comment)
);
Expand Down
7 changes: 4 additions & 3 deletions src/slang-comments/handlers/handle-yul-block-comments.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { util } from 'prettier';
import {
addDanglingComment,
addLeadingComment
} from '../../slang-utils/prettier-utils.js';

import type { HandlerParams } from './types.d.ts';

const { addLeadingComment, addDanglingComment } = util;

export default function handleYulBlockComments({
precedingNode,
enclosingNode,
Expand Down
4 changes: 1 addition & 3 deletions src/slang-nodes/CallOptions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { doc } from 'prettier';
import { line, softline } from '../slang-printers/prettier-builders.js';
import { printSeparatedList } from '../slang-printers/print-separated-list.js';
import { SlangNode } from './SlangNode.js';
import { NamedArgument } from './NamedArgument.js';
Expand All @@ -9,8 +9,6 @@ import type { AstPath, Doc, ParserOptions } from 'prettier';
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';
import type { PrintableNode } from './types.d.ts';

const { line, softline } = doc.builders;

export class CallOptions extends SlangNode {
readonly kind = NonterminalKind.CallOptions;

Expand Down
4 changes: 1 addition & 3 deletions src/slang-nodes/CatchClauseError.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { doc } from 'prettier';
import { group } from '../slang-printers/prettier-builders.js';
import { SlangNode } from './SlangNode.js';
import { TerminalNode } from './TerminalNode.js';
import { ParametersDeclaration } from './ParametersDeclaration.js';
Expand All @@ -8,8 +8,6 @@ import type * as ast from '@nomicfoundation/slang/ast';
import type { Doc } from 'prettier';
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';

const { group } = doc.builders;

export class CatchClauseError extends SlangNode {
readonly kind = NonterminalKind.CatchClauseError;

Expand Down
4 changes: 1 addition & 3 deletions src/slang-nodes/CatchClauses.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { doc } from 'prettier';
import { join } from '../slang-printers/prettier-builders.js';
import { SlangNode } from './SlangNode.js';
import { CatchClause } from './CatchClause.js';

import type * as ast from '@nomicfoundation/slang/ast';
import type { AstPath, Doc } from 'prettier';
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';

const { join } = doc.builders;

export class CatchClauses extends SlangNode {
readonly kind = NonterminalKind.CatchClauses;

Expand Down
10 changes: 7 additions & 3 deletions src/slang-nodes/ConditionalExpression.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { doc } from 'prettier';
import {
group,
hardline,
ifBreak,
indent,
line
} from '../slang-printers/prettier-builders.js';
import { printSeparatedItem } from '../slang-printers/print-separated-item.js';
import { extractVariant } from '../slang-utils/extract-variant.js';
import { SlangNode } from './SlangNode.js';
Expand All @@ -10,8 +16,6 @@ import type { AstPath, Doc, ParserOptions } from 'prettier';
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';
import type { PrintableNode } from './types.d.ts';

const { group, hardline, ifBreak, indent, line } = doc.builders;

function experimentalTernaries(
node: ConditionalExpression,
print: PrintFunction,
Expand Down
4 changes: 1 addition & 3 deletions src/slang-nodes/ConstructorAttributes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { doc } from 'prettier';
import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js';
import { line } from '../slang-printers/prettier-builders.js';
import { extractVariant } from '../slang-utils/extract-variant.js';
import { SlangNode } from './SlangNode.js';
import { ConstructorAttribute } from './ConstructorAttribute.js';
Expand All @@ -9,8 +9,6 @@ import type * as ast from '@nomicfoundation/slang/ast';
import type { AstPath, Doc } from 'prettier';
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';

const { line } = doc.builders;

export class ConstructorAttributes extends SlangNode {
readonly kind = NonterminalKind.ConstructorAttributes;

Expand Down
4 changes: 1 addition & 3 deletions src/slang-nodes/ContractDefinition.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { doc } from 'prettier';
import { satisfies } from 'semver';
import { group, line } from '../slang-printers/prettier-builders.js';
import { SlangNode } from './SlangNode.js';
import { TerminalNode } from './TerminalNode.js';
import { ContractSpecifiers } from './ContractSpecifiers.js';
Expand All @@ -10,8 +10,6 @@ import type * as ast from '@nomicfoundation/slang/ast';
import type { Doc } from 'prettier';
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';

const { group, line } = doc.builders;

export class ContractDefinition extends SlangNode {
readonly kind = NonterminalKind.ContractDefinition;

Expand Down
9 changes: 6 additions & 3 deletions src/slang-nodes/ContractSpecifiers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { doc } from 'prettier';
import {
group,
ifBreak,
line,
softline
} from '../slang-printers/prettier-builders.js';
import { printSeparatedList } from '../slang-printers/print-separated-list.js';
import { extractVariant } from '../slang-utils/extract-variant.js';
import { SlangNode } from './SlangNode.js';
Expand All @@ -9,8 +14,6 @@ import type * as ast from '@nomicfoundation/slang/ast';
import type { AstPath, Doc } from 'prettier';
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';

const { group, ifBreak, line, softline } = doc.builders;

function sortContractSpecifiers(
{ kind: aKind }: ContractSpecifier['variant'],
{ kind: bKind }: ContractSpecifier['variant']
Expand Down
4 changes: 1 addition & 3 deletions src/slang-nodes/DoWhileStatement.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { doc } from 'prettier';
import { line } from '../slang-printers/prettier-builders.js';
import { printSeparatedItem } from '../slang-printers/print-separated-item.js';
import { extractVariant } from '../slang-utils/extract-variant.js';
import { SlangNode } from './SlangNode.js';
Expand All @@ -10,8 +10,6 @@ import type * as ast from '@nomicfoundation/slang/ast';
import type { Doc } from 'prettier';
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';

const { line } = doc.builders;

export class DoWhileStatement extends SlangNode {
readonly kind = NonterminalKind.DoWhileStatement;

Expand Down
4 changes: 1 addition & 3 deletions src/slang-nodes/EnumMembers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { doc } from 'prettier';
import { hardline } from '../slang-printers/prettier-builders.js';
import { printSeparatedList } from '../slang-printers/print-separated-list.js';
import { SlangNode } from './SlangNode.js';
import { TerminalNode } from './TerminalNode.js';
Expand All @@ -8,8 +8,6 @@ import type * as ast from '@nomicfoundation/slang/ast';
import type { AstPath, Doc } from 'prettier';
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';

const { hardline } = doc.builders;

export class EnumMembers extends SlangNode {
readonly kind = NonterminalKind.EnumMembers;

Expand Down
Loading