-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathYulStatements.ts
More file actions
45 lines (38 loc) · 1.42 KB
/
YulStatements.ts
File metadata and controls
45 lines (38 loc) · 1.42 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
42
43
44
45
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { doc } from 'prettier';
import { printSeparatedItem } from '../slang-printers/print-separated-item.js';
import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js';
import { extractVariant } from '../slang-utils/extract-variant.js';
import { SlangNode } from './SlangNode.js';
import { YulStatement } from './YulStatement.js';
import type * as ast from '@nomicfoundation/slang/ast';
import type { AstPath, Doc, ParserOptions } from 'prettier';
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';
import type { AstNode } from './types.d.ts';
const { hardline } = doc.builders;
export class YulStatements extends SlangNode {
readonly kind = NonterminalKind.YulStatements;
items: YulStatement['variant'][];
constructor(
ast: ast.YulStatements,
collected: CollectedMetadata,
options: ParserOptions<AstNode>
) {
super(ast, collected, true);
this.items = ast.items.map((item) =>
extractVariant(new YulStatement(item, collected, options))
);
}
print(
path: AstPath<YulStatements>,
print: PrintFunction,
options: ParserOptions<AstNode>
): Doc {
return this.items.length > 0 || (this.comments?.length || 0) > 0
? printSeparatedItem(
printPreservingEmptyLines(this, path, print, options),
{ firstSeparator: hardline }
)
: '';
}
}