-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathAssignmentExpression.ts
More file actions
49 lines (40 loc) · 1.49 KB
/
AssignmentExpression.ts
File metadata and controls
49 lines (40 loc) · 1.49 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
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { extractVariant } from '../slang-utils/extract-variant.js';
import { printAssignmentRightSide } from '../slang-printers/print-assignment-right-side.js';
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 { CollectedMetadata, PrintFunction } from '../types.d.ts';
import type { PrintableNode } from './types.d.ts';
export class AssignmentExpression extends SlangNode {
readonly kind = NonterminalKind.AssignmentExpression;
leftOperand: Expression['variant'];
operator: string;
rightOperand: Expression['variant'];
constructor(
ast: ast.AssignmentExpression,
collected: CollectedMetadata,
options: ParserOptions<PrintableNode>
) {
super(ast, collected);
this.leftOperand = extractVariant(
new Expression(ast.leftOperand, collected, options)
);
this.operator = ast.operator.unparse();
this.rightOperand = extractVariant(
new Expression(ast.rightOperand, collected, options)
);
this.updateMetadata(this.leftOperand, this.rightOperand);
}
print(path: AstPath<AssignmentExpression>, print: PrintFunction): Doc {
return [
path.call(print, 'leftOperand'),
` ${this.operator}`,
printAssignmentRightSide(
path.call(print, 'rightOperand'),
this.rightOperand
)
];
}
}