-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathContractSpecifiers.ts
More file actions
41 lines (30 loc) · 1.47 KB
/
ContractSpecifiers.ts
File metadata and controls
41 lines (30 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { doc } from 'prettier';
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { sortContractSpecifiers } from '../slang-utils/sort-contract-specifiers.js';
import { printSeparatedList } from '../slang-printers/print-separated-list.js';
import { SlangNode } from './SlangNode.js';
import { ContractSpecifier } from './ContractSpecifier.js';
import type * as ast from '@nomicfoundation/slang/ast';
import type { AstPath, Doc, ParserOptions } from 'prettier';
import type { AstNode } from './types.d.ts';
import type { PrintFunction } from '../types.d.ts';
const { group, ifBreak, line, softline } = doc.builders;
export class ContractSpecifiers extends SlangNode {
readonly kind = NonterminalKind.ContractSpecifiers;
items: ContractSpecifier[];
constructor(ast: ast.ContractSpecifiers, options: ParserOptions<AstNode>) {
super(ast, true);
this.items = ast.items.map((item) => new ContractSpecifier(item, options));
this.items = this.items.sort(sortContractSpecifiers);
}
print(path: AstPath<ContractSpecifiers>, print: PrintFunction): Doc {
const [specifier1, specifier2] = path.map(print, 'items');
if (specifier1 === undefined) return '';
if (specifier2 === undefined) return [' ', specifier1];
const groupId = Symbol('Slang.ContractSpecifiers.inheritance');
return printSeparatedList(
[group(specifier1, { id: groupId }), specifier2],
{ firstSeparator: line, separator: ifBreak('', softline, { groupId }) }
);
}
}