11import { doc } from 'prettier' ;
2- import coerce from 'semver/functions/coerce.js' ;
3- import satisfies from 'semver/functions/satisfies.js' ;
42import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js' ;
53import { createBinaryOperationPrinter } from '../slang-printers/create-binary-operation-printer.js' ;
64import { createHugFunction } from '../slang-utils/create-hug-function.js' ;
75import { getNodeMetadata , updateMetadata } from '../slang-utils/metadata.js' ;
86import { Expression } from './Expression.js' ;
9- import { TupleExpression } from './TupleExpression.js' ;
10- import { TupleValues } from './TupleValues.js' ;
11- import { TupleValue } from './TupleValue.js' ;
127
138import type * as ast from '@nomicfoundation/slang/ast' ;
149import type { AstPath , Doc , ParserOptions } from 'prettier' ;
@@ -28,12 +23,6 @@ const printExponentiationExpression = createBinaryOperationPrinter(
2823 indent ( document ) // always indent
2924) ;
3025
31- const objectConfig = {
32- writable : true ,
33- enumerable : true ,
34- configurable : true
35- } ;
36-
3726export class ExponentiationExpression implements SlangNode {
3827 readonly kind = NonterminalKind . ExponentiationExpression ;
3928
@@ -64,113 +53,8 @@ export class ExponentiationExpression implements SlangNode {
6453 this . comments = metadata . comments ;
6554 this . loc = metadata . loc ;
6655
67- const compiler = coerce ( options . compiler ) ;
68- if ( compiler ) {
69- if ( satisfies ( compiler , '>=0.8.0' ) ) {
70- this . rightOperand = tryToHug ( this . rightOperand ) ;
71- } else {
72- // Currently the parser considers exponentiation as having left
73- // association from 0.6.0.
74- // in reality solidity fixed this from 0.8.0.
75- // TODO: remove this once the parser has fixed this.
76- // https://github.com/NomicFoundation/slang/issues/1031
77- if (
78- typeof this . rightOperand . variant !== 'string' &&
79- this . rightOperand . variant . kind ===
80- NonterminalKind . ExponentiationExpression
81- ) {
82- const leftLoc = {
83- leadingOffset : this . leftOperand . loc . leadingOffset ,
84- start : this . leftOperand . loc . start ,
85- trailingOffset :
86- this . rightOperand . variant . leftOperand . loc . trailingOffset ,
87- end : this . rightOperand . variant . leftOperand . loc . end
88- } ;
89- this . leftOperand = Object . create ( Expression . prototype , {
90- kind : { value : NonterminalKind . Expression , ...objectConfig } ,
91- loc : { value : { ...leftLoc } , ...objectConfig } ,
92- comments : { value : [ ] , ...objectConfig } ,
93- variant : {
94- value : Object . create ( TupleExpression . prototype , {
95- kind : {
96- value : NonterminalKind . TupleExpression ,
97- ...objectConfig
98- } ,
99- loc : { value : { ...leftLoc } , ...objectConfig } ,
100- comments : { value : [ ] , ...objectConfig } ,
101- items : {
102- value : Object . create ( TupleValues . prototype , {
103- kind : {
104- value : NonterminalKind . TupleValues ,
105- ...objectConfig
106- } ,
107- loc : { value : { ...leftLoc } , ...objectConfig } ,
108- comments : { value : [ ] , ...objectConfig } ,
109- items : {
110- value : [
111- Object . create ( TupleValue . prototype , {
112- kind : {
113- value : NonterminalKind . TupleValue ,
114- ...objectConfig
115- } ,
116- loc : { value : { ...leftLoc } , ...objectConfig } ,
117- comments : { value : [ ] , ...objectConfig } ,
118- expression : {
119- value : Object . create ( Expression . prototype , {
120- kind : {
121- value : NonterminalKind . Expression ,
122- ...objectConfig
123- } ,
124- loc : { value : { ...leftLoc } , ...objectConfig } ,
125- comments : { value : [ ] , ...objectConfig } ,
126- variant : {
127- value : Object . create (
128- ExponentiationExpression . prototype ,
129- {
130- kind : {
131- value :
132- NonterminalKind . ExponentiationExpression ,
133- ...objectConfig
134- } ,
135- loc : {
136- value : { ...leftLoc } ,
137- ...objectConfig
138- } ,
139- comments : { value : [ ] , ...objectConfig } ,
140- leftOperand : {
141- value : this . leftOperand ,
142- ...objectConfig
143- } ,
144- operator : { value : '**' , ...objectConfig } ,
145- rightOperand : {
146- value :
147- this . rightOperand . variant . leftOperand ,
148- ...objectConfig
149- }
150- }
151- ) as ExponentiationExpression ,
152- ...objectConfig
153- }
154- } ) as Expression ,
155- ...objectConfig
156- }
157- } ) as TupleValue
158- ] ,
159- ...objectConfig
160- } ,
161- separators : { value : [ ] , ...objectConfig }
162- } ) as TupleValues ,
163- ...objectConfig
164- }
165- } ) as TupleExpression ,
166- ...objectConfig
167- }
168- } ) as Expression ;
169- this . rightOperand = this . rightOperand . variant . rightOperand ;
170- }
171- this . leftOperand = tryToHug ( this . leftOperand ) ;
172- }
173- }
56+ this . rightOperand = tryToHug ( this . rightOperand ) ;
57+ this . leftOperand = tryToHug ( this . leftOperand ) ;
17458 }
17559
17660 print (
0 commit comments