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
10 changes: 9 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import { locEnd, locStart } from './slang-utils/loc.js';
import { hasPrettierIgnore } from './slang-utils/has-prettier-ignore.js';

import type {
AstPath,
Doc,
Parser,
ParserOptions,
Printer,
RequiredOptions,
SupportLanguage
Expand Down Expand Up @@ -77,7 +80,12 @@ const slangPrinter: Printer<PrintableNode | undefined> = {
handleComments,
isBlockComment,
massageAstNode,
print: slangPrint,
print: slangPrint as (
path: AstPath<PrintableNode | undefined>,
options: ParserOptions<PrintableNode | undefined>,
print: (path: AstPath<PrintableNode | undefined>) => Doc,
args?: unknown
) => Doc,
hasPrettierIgnore,
printComment
};
Expand Down
6 changes: 3 additions & 3 deletions src/slang-nodes/AbicoderPragma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js';
import { AbicoderVersion } from './AbicoderVersion.js';

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

export class AbicoderPragma extends SlangNode {
Expand All @@ -19,7 +19,7 @@ export class AbicoderPragma extends SlangNode {
this.updateMetadata(this.version);
}

print(path: AstPath<AbicoderPragma>, print: PrintFunction): Doc {
return ['abicoder ', path.call(print, 'version')];
print(print: PrintFunction): Doc {
return ['abicoder ', print('version')];
}
}
2 changes: 1 addition & 1 deletion src/slang-nodes/AdditiveExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export class AdditiveExpression extends SlangNode {
}

print(
path: AstPath<AdditiveExpression>,
print: PrintFunction,
path: AstPath<AdditiveExpression>,
options: ParserOptions<PrintableNode>
): Doc {
return printAdditiveExpression(this, path, print, options);
Expand Down
2 changes: 1 addition & 1 deletion src/slang-nodes/AndExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export class AndExpression extends SlangNode {
}

print(
path: AstPath<AndExpression>,
print: PrintFunction,
path: AstPath<AndExpression>,
options: ParserOptions<PrintableNode>
): Doc {
return printLogicalOperation(this, path, print, options);
Expand Down
6 changes: 3 additions & 3 deletions src/slang-nodes/ArrayExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js';
import { ArrayValues } from './ArrayValues.js';

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

Expand All @@ -24,7 +24,7 @@ export class ArrayExpression extends SlangNode {
this.updateMetadata(this.items);
}

print(path: AstPath<ArrayExpression>, print: PrintFunction): Doc {
return ['[', path.call(print, 'items'), ']'];
print(print: PrintFunction): Doc {
return ['[', print('items'), ']'];
}
}
6 changes: 3 additions & 3 deletions src/slang-nodes/ArrayTypeName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { TypeName } from './TypeName.js';
import { Expression } from './Expression.js';

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

Expand Down Expand Up @@ -35,7 +35,7 @@ export class ArrayTypeName extends SlangNode {
this.updateMetadata(this.operand, this.index);
}

print(path: AstPath<ArrayTypeName>, print: PrintFunction): Doc {
return [path.call(print, 'operand'), '[', path.call(print, 'index'), ']'];
print(print: PrintFunction): Doc {
return [print('operand'), '[', print('index'), ']'];
}
}
2 changes: 1 addition & 1 deletion src/slang-nodes/ArrayValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class ArrayValues extends SlangNode {
);
}

print(path: AstPath<ArrayValues>, print: PrintFunction): Doc {
print(print: PrintFunction, path: AstPath<ArrayValues>): Doc {
return printSeparatedList(path.map(print, 'items'));
}
}
2 changes: 1 addition & 1 deletion src/slang-nodes/AssemblyFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class AssemblyFlags extends SlangNode {
);
}

print(path: AstPath<AssemblyFlags>, print: PrintFunction): Doc {
print(print: PrintFunction, path: AstPath<AssemblyFlags>): Doc {
return printSeparatedList(path.map(print, 'items'));
}
}
6 changes: 3 additions & 3 deletions src/slang-nodes/AssemblyFlagsDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js';
import { AssemblyFlags } from './AssemblyFlags.js';

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

Expand All @@ -24,7 +24,7 @@ export class AssemblyFlagsDeclaration extends SlangNode {
this.updateMetadata(this.flags);
}

print(path: AstPath<AssemblyFlagsDeclaration>, print: PrintFunction): Doc {
return ['(', path.call(print, 'flags'), ')'];
print(print: PrintFunction): Doc {
return ['(', print('flags'), ')'];
}
}
10 changes: 5 additions & 5 deletions src/slang-nodes/AssemblyStatement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { AssemblyFlagsDeclaration } from './AssemblyFlagsDeclaration.js';
import { YulBlock } from './YulBlock.js';

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

Expand Down Expand Up @@ -37,12 +37,12 @@ export class AssemblyStatement extends SlangNode {
this.updateMetadata(this.label, this.flags, this.body);
}

print(path: AstPath<AssemblyStatement>, print: PrintFunction): Doc {
print(print: PrintFunction): Doc {
return joinExisting(' ', [
'assembly',
path.call(print, 'label'),
path.call(print, 'flags'),
path.call(print, 'body')
print('label'),
print('flags'),
print('body')
]);
}
}
11 changes: 4 additions & 7 deletions src/slang-nodes/AssignmentExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { SlangNode } from './SlangNode.js';
import { Expression } from './Expression.js';

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

Expand Down Expand Up @@ -36,14 +36,11 @@ export class AssignmentExpression extends SlangNode {
this.updateMetadata(this.leftOperand, this.rightOperand);
}

print(path: AstPath<AssignmentExpression>, print: PrintFunction): Doc {
print(print: PrintFunction): Doc {
return [
path.call(print, 'leftOperand'),
print('leftOperand'),
` ${this.operator}`,
printAssignmentRightSide(
path.call(print, 'rightOperand'),
this.rightOperand
)
printAssignmentRightSide(print('rightOperand'), this.rightOperand)
];
}
}
2 changes: 1 addition & 1 deletion src/slang-nodes/BitwiseAndExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export class BitwiseAndExpression extends SlangNode {
}

print(
path: AstPath<BitwiseAndExpression>,
print: PrintFunction,
path: AstPath<BitwiseAndExpression>,
options: ParserOptions<PrintableNode>
): Doc {
return printBitwiseAndExpression(this, path, print, options);
Expand Down
2 changes: 1 addition & 1 deletion src/slang-nodes/BitwiseOrExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ export class BitwiseOrExpression extends SlangNode {
}

print(
path: AstPath<BitwiseOrExpression>,
print: PrintFunction,
path: AstPath<BitwiseOrExpression>,
options: ParserOptions<PrintableNode>
): Doc {
return printBitwiseOrExpression(this, path, print, options);
Expand Down
2 changes: 1 addition & 1 deletion src/slang-nodes/BitwiseXorExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export class BitwiseXorExpression extends SlangNode {
}

print(
path: AstPath<BitwiseXorExpression>,
print: PrintFunction,
path: AstPath<BitwiseXorExpression>,
options: ParserOptions<PrintableNode>
): Doc {
return printBitwiseXorExpression(this, path, print, options);
Expand Down
6 changes: 3 additions & 3 deletions src/slang-nodes/Block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js';
import { Statements } from './Statements.js';

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

Expand All @@ -24,7 +24,7 @@ export class Block extends SlangNode {
this.updateMetadata(this.statements);
}

print(path: AstPath<Block>, print: PrintFunction): Doc {
return ['{', path.call(print, 'statements'), '}'];
print(print: PrintFunction): Doc {
return ['{', print('statements'), '}'];
}
}
2 changes: 1 addition & 1 deletion src/slang-nodes/CallOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export class CallOptions extends SlangNode {
}

print(
path: AstPath<CallOptions>,
print: PrintFunction,
path: AstPath<CallOptions>,
options: ParserOptions<PrintableNode>
): Doc {
return printSeparatedList(path.map(print, 'items'), {
Expand Down
6 changes: 3 additions & 3 deletions src/slang-nodes/CallOptionsExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Expression } from './Expression.js';
import { CallOptions } from './CallOptions.js';

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

Expand All @@ -31,7 +31,7 @@ export class CallOptionsExpression extends SlangNode {
this.updateMetadata(this.operand, this.options);
}

print(path: AstPath<CallOptionsExpression>, print: PrintFunction): Doc {
return [path.call(print, 'operand'), '{', path.call(print, 'options'), '}'];
print(print: PrintFunction): Doc {
return [print('operand'), '{', print('options'), '}'];
}
}
6 changes: 3 additions & 3 deletions src/slang-nodes/CatchClause.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CatchClauseError } from './CatchClauseError.js';
import { Block } from './Block.js';

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

Expand All @@ -30,7 +30,7 @@ export class CatchClause extends SlangNode {
this.updateMetadata(this.error, this.body);
}

print(path: AstPath<CatchClause>, print: PrintFunction): Doc {
return ['catch ', path.call(print, 'error'), path.call(print, 'body')];
print(print: PrintFunction): Doc {
return ['catch ', print('error'), print('body')];
}
}
10 changes: 3 additions & 7 deletions src/slang-nodes/CatchClauseError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { TerminalNode } from './TerminalNode.js';
import { ParametersDeclaration } from './ParametersDeclaration.js';

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

Expand Down Expand Up @@ -37,11 +37,7 @@ export class CatchClauseError extends SlangNode {
this.updateMetadata(this.parameters);
}

print(path: AstPath<CatchClauseError>, print: PrintFunction): Doc {
return [
path.call(print, 'name'),
group(path.call(print, 'parameters')),
' '
];
print(print: PrintFunction): Doc {
return [print('name'), group(print('parameters')), ' '];
}
}
2 changes: 1 addition & 1 deletion src/slang-nodes/CatchClauses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class CatchClauses extends SlangNode {
this.updateMetadata(...this.items);
}

print(path: AstPath<CatchClauses>, print: PrintFunction): Doc {
print(print: PrintFunction, path: AstPath<CatchClauses>): Doc {
return join(' ', path.map(print, 'items'));
}
}
14 changes: 7 additions & 7 deletions src/slang-nodes/ConditionalExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function experimentalTernaries(

// If the `condition` breaks into multiple lines, we add parentheses,
// unless it already is a `TupleExpression`.
const operand = path.call(print, 'operand');
const operand = print('operand');
const operandDoc = group([
node.operand.kind === NonterminalKind.TupleExpression
? operand
Expand All @@ -41,7 +41,7 @@ function experimentalTernaries(
// `trueExpression`.
const trueExpressionDoc = indent([
isNestedAsTrueExpression ? hardline : line,
path.call(print, 'trueExpression')
print('trueExpression')
]);

const groupId = Symbol('Slang.ConditionalExpression.trueExpression');
Expand All @@ -58,7 +58,7 @@ function experimentalTernaries(
? ' '.repeat(tabWidth - 1)
: ' ';

const falseExpression = path.call(print, 'falseExpression');
const falseExpression = print('falseExpression');
const falseExpressionDoc = [
isNested ? hardline : line,
':',
Expand All @@ -81,18 +81,18 @@ function traditionalTernaries(
print: PrintFunction
): Doc {
return group([
path.call(print, 'operand'),
print('operand'),
indent([
// Nested trueExpression and falseExpression are always printed in a new
// line
path.parent!.kind === NonterminalKind.ConditionalExpression
? hardline
: line,
'? ',
path.call(print, 'trueExpression'),
print('trueExpression'),
line,
': ',
path.call(print, 'falseExpression')
print('falseExpression')
])
]);
}
Expand Down Expand Up @@ -156,8 +156,8 @@ export class ConditionalExpression extends SlangNode {
}

print(
path: AstPath<ConditionalExpression>,
print: PrintFunction,
path: AstPath<ConditionalExpression>,
options: ParserOptions<PrintableNode>
): Doc {
return options.experimentalTernaries
Expand Down
Loading