11import { NonterminalKind } from '@nomicfoundation/slang/cst' ;
22import { isBinaryOperation } from '../slang-utils/is-binary-operation.js' ;
33import { printIndentedGroupOrSpacedDocument } from '../slang-printers/print-indented-group-or-spaced-document.js' ;
4- import { printVariant } from '../slang-printers/print -variant.js' ;
4+ import { extractVariant } from '../slang-utils/extract -variant.js' ;
55import { SlangNode } from './SlangNode.js' ;
66import { Expression } from './Expression.js' ;
77import { TerminalNode } from './TerminalNode.js' ;
@@ -14,31 +14,32 @@ import type { AstNode } from './types.d.ts';
1414export class AssignmentExpression extends SlangNode {
1515 readonly kind = NonterminalKind . AssignmentExpression ;
1616
17- leftOperand : Expression ;
17+ leftOperand : Expression [ 'variant' ] ;
1818
1919 operator : string ;
2020
21- rightOperand : Expression ;
21+ rightOperand : Expression [ 'variant' ] ;
2222
2323 constructor ( ast : ast . AssignmentExpression , options : ParserOptions < AstNode > ) {
2424 super ( ast ) ;
2525
26- this . leftOperand = new Expression ( ast . leftOperand , options ) ;
26+ this . leftOperand = extractVariant ( new Expression ( ast . leftOperand , options ) ) ;
2727 this . operator = ast . operator . unparse ( ) ;
28- this . rightOperand = new Expression ( ast . rightOperand , options ) ;
28+ this . rightOperand = extractVariant (
29+ new Expression ( ast . rightOperand , options )
30+ ) ;
2931
3032 this . updateMetadata ( this . leftOperand , this . rightOperand ) ;
3133 }
3234
3335 print ( path : AstPath < AssignmentExpression > , print : PrintFunction ) : Doc {
34- const rightOperandVariant = this . rightOperand . variant ;
3536 return [
36- path . call ( printVariant ( print ) , 'leftOperand' ) ,
37+ path . call ( print , 'leftOperand' ) ,
3738 ` ${ this . operator } ` ,
3839 printIndentedGroupOrSpacedDocument (
39- path . call ( printVariant ( print ) , 'rightOperand' ) ,
40- ! ( rightOperandVariant instanceof TerminalNode ) &&
41- isBinaryOperation ( rightOperandVariant )
40+ path . call ( print , 'rightOperand' ) ,
41+ ! ( this . rightOperand instanceof TerminalNode ) &&
42+ isBinaryOperation ( this . rightOperand )
4243 )
4344 ] ;
4445 }
0 commit comments