-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathStateVariableDefinition.ts
More file actions
69 lines (54 loc) · 1.97 KB
/
StateVariableDefinition.ts
File metadata and controls
69 lines (54 loc) · 1.97 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { doc } from 'prettier';
import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js';
import { TypeName } from './TypeName.js';
import { StateVariableAttributes } from './StateVariableAttributes.js';
import { Identifier } from './Identifier.js';
import { StateVariableDefinitionValue } from './StateVariableDefinitionValue.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, SlangNode } from '../types.d.ts';
const { group, indent, indentIfBreak } = doc.builders;
export class StateVariableDefinition implements SlangNode {
readonly kind = NonterminalKind.StateVariableDefinition;
comments;
loc;
typeName: TypeName;
attributes: StateVariableAttributes;
name: Identifier;
value?: StateVariableDefinitionValue;
constructor(
ast: ast.StateVariableDefinition,
options: ParserOptions<AstNode>
) {
let metadata = getNodeMetadata(ast);
this.typeName = new TypeName(ast.typeName, options);
this.attributes = new StateVariableAttributes(ast.attributes);
this.name = new Identifier(ast.name);
if (ast.value) {
this.value = new StateVariableDefinitionValue(ast.value, options);
}
metadata = updateMetadata(metadata, [
this.typeName,
this.attributes,
this.value
]);
this.comments = metadata.comments;
this.loc = metadata.loc;
}
print(path: AstPath<StateVariableDefinition>, print: PrintFunction): Doc {
const groupId = Symbol('Slang.StateVariableDefinition.attributes');
const attributesDoc = group(indent(path.call(print, 'attributes')), {
id: groupId
});
return [
path.call(print, 'typeName'),
attributesDoc,
' ',
path.call(print, 'name'),
this.value ? indentIfBreak(path.call(print, 'value'), { groupId }) : '',
';'
];
}
}