Skip to content

Commit e1b7439

Browse files
authored
using the latest print signature (#1500)
* `path.call(print, 'selector')` can be called like `print('selector')` * rearrange Node's `print` signature to delete unneeded `path` parameter * if `print` is called without an argument, it prints the current `path` * small refactor to avoid `const` creation
1 parent 57a1097 commit e1b7439

171 files changed

Lines changed: 467 additions & 587 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ import { locEnd, locStart } from './slang-utils/loc.js';
1212
import { hasPrettierIgnore } from './slang-utils/has-prettier-ignore.js';
1313

1414
import type {
15+
AstPath,
16+
Doc,
1517
Parser,
18+
ParserOptions,
1619
Printer,
1720
RequiredOptions,
1821
SupportLanguage
@@ -77,7 +80,12 @@ const slangPrinter: Printer<PrintableNode | undefined> = {
7780
handleComments,
7881
isBlockComment,
7982
massageAstNode,
80-
print: slangPrint,
83+
print: slangPrint as (
84+
path: AstPath<PrintableNode | undefined>,
85+
options: ParserOptions<PrintableNode | undefined>,
86+
print: (path: AstPath<PrintableNode | undefined>) => Doc,
87+
args?: unknown
88+
) => Doc,
8189
hasPrettierIgnore,
8290
printComment
8391
};

src/slang-nodes/AbicoderPragma.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js';
33
import { AbicoderVersion } from './AbicoderVersion.js';
44

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

99
export class AbicoderPragma extends SlangNode {
@@ -19,7 +19,7 @@ export class AbicoderPragma extends SlangNode {
1919
this.updateMetadata(this.version);
2020
}
2121

22-
print(path: AstPath<AbicoderPragma>, print: PrintFunction): Doc {
23-
return ['abicoder ', path.call(print, 'version')];
22+
print(print: PrintFunction): Doc {
23+
return ['abicoder ', print('version')];
2424
}
2525
}

src/slang-nodes/AdditiveExpression.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ export class AdditiveExpression extends SlangNode {
5757
}
5858

5959
print(
60-
path: AstPath<AdditiveExpression>,
6160
print: PrintFunction,
61+
path: AstPath<AdditiveExpression>,
6262
options: ParserOptions<PrintableNode>
6363
): Doc {
6464
return printAdditiveExpression(this, path, print, options);

src/slang-nodes/AndExpression.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export class AndExpression extends SlangNode {
3737
}
3838

3939
print(
40-
path: AstPath<AndExpression>,
4140
print: PrintFunction,
41+
path: AstPath<AndExpression>,
4242
options: ParserOptions<PrintableNode>
4343
): Doc {
4444
return printLogicalOperation(this, path, print, options);

src/slang-nodes/ArrayExpression.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js';
33
import { ArrayValues } from './ArrayValues.js';
44

55
import type * as ast from '@nomicfoundation/slang/ast';
6-
import type { AstPath, Doc, ParserOptions } from 'prettier';
6+
import type { Doc, ParserOptions } from 'prettier';
77
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';
88
import type { PrintableNode } from './types.d.ts';
99

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

27-
print(path: AstPath<ArrayExpression>, print: PrintFunction): Doc {
28-
return ['[', path.call(print, 'items'), ']'];
27+
print(print: PrintFunction): Doc {
28+
return ['[', print('items'), ']'];
2929
}
3030
}

src/slang-nodes/ArrayTypeName.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { TypeName } from './TypeName.js';
55
import { Expression } from './Expression.js';
66

77
import type * as ast from '@nomicfoundation/slang/ast';
8-
import type { AstPath, Doc, ParserOptions } from 'prettier';
8+
import type { Doc, ParserOptions } from 'prettier';
99
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';
1010
import type { PrintableNode } from './types.d.ts';
1111

@@ -35,7 +35,7 @@ export class ArrayTypeName extends SlangNode {
3535
this.updateMetadata(this.operand, this.index);
3636
}
3737

38-
print(path: AstPath<ArrayTypeName>, print: PrintFunction): Doc {
39-
return [path.call(print, 'operand'), '[', path.call(print, 'index'), ']'];
38+
print(print: PrintFunction): Doc {
39+
return [print('operand'), '[', print('index'), ']'];
4040
}
4141
}

src/slang-nodes/ArrayValues.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class ArrayValues extends SlangNode {
2626
);
2727
}
2828

29-
print(path: AstPath<ArrayValues>, print: PrintFunction): Doc {
29+
print(print: PrintFunction, path: AstPath<ArrayValues>): Doc {
3030
return printSeparatedList(path.map(print, 'items'));
3131
}
3232
}

src/slang-nodes/AssemblyFlags.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class AssemblyFlags extends SlangNode {
2525
);
2626
}
2727

28-
print(path: AstPath<AssemblyFlags>, print: PrintFunction): Doc {
28+
print(print: PrintFunction, path: AstPath<AssemblyFlags>): Doc {
2929
return printSeparatedList(path.map(print, 'items'));
3030
}
3131
}

src/slang-nodes/AssemblyFlagsDeclaration.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { SlangNode } from './SlangNode.js';
33
import { AssemblyFlags } from './AssemblyFlags.js';
44

55
import type * as ast from '@nomicfoundation/slang/ast';
6-
import type { AstPath, Doc, ParserOptions } from 'prettier';
6+
import type { Doc, ParserOptions } from 'prettier';
77
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';
88
import type { PrintableNode } from './types.d.ts';
99

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

27-
print(path: AstPath<AssemblyFlagsDeclaration>, print: PrintFunction): Doc {
28-
return ['(', path.call(print, 'flags'), ')'];
27+
print(print: PrintFunction): Doc {
28+
return ['(', print('flags'), ')'];
2929
}
3030
}

src/slang-nodes/AssemblyStatement.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { AssemblyFlagsDeclaration } from './AssemblyFlagsDeclaration.js';
66
import { YulBlock } from './YulBlock.js';
77

88
import type * as ast from '@nomicfoundation/slang/ast';
9-
import type { AstPath, Doc, ParserOptions } from 'prettier';
9+
import type { Doc, ParserOptions } from 'prettier';
1010
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';
1111
import type { PrintableNode } from './types.d.ts';
1212

@@ -37,12 +37,12 @@ export class AssemblyStatement extends SlangNode {
3737
this.updateMetadata(this.label, this.flags, this.body);
3838
}
3939

40-
print(path: AstPath<AssemblyStatement>, print: PrintFunction): Doc {
40+
print(print: PrintFunction): Doc {
4141
return joinExisting(' ', [
4242
'assembly',
43-
path.call(print, 'label'),
44-
path.call(print, 'flags'),
45-
path.call(print, 'body')
43+
print('label'),
44+
print('flags'),
45+
print('body')
4646
]);
4747
}
4848
}

0 commit comments

Comments
 (0)