File tree Expand file tree Collapse file tree 4 files changed +40
-1
lines changed Expand file tree Collapse file tree 4 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -939,6 +939,23 @@ const transformAST = {
939939 }
940940 } ,
941941
942+ FileLevelConstant ( ctx ) {
943+ const type = this . visit ( ctx . typeName ( ) )
944+ const iden = ctx . identifier ( )
945+ const name = toText ( iden )
946+
947+ let expression = null
948+ if ( ctx . expression ( ) ) {
949+ expression = this . visit ( ctx . expression ( ) )
950+ }
951+
952+ return {
953+ typeName : type ,
954+ name,
955+ initialValue : expression ,
956+ }
957+ } ,
958+
942959 ForStatement ( ctx ) {
943960 let conditionExpression = this . visit ( ctx . expressionStatement ( ) )
944961 if ( conditionExpression ) {
Original file line number Diff line number Diff line change @@ -719,6 +719,25 @@ describe('AST', () => {
719719 } )
720720 } )
721721
722+ it ( "file-level constants" , function ( ) {
723+ var ast = parser . parse ( "uint constant EXPONENT = 10;" )
724+ var fileLevelConstantNode = ast . children [ 0 ] ;
725+
726+ assert . deepEqual ( fileLevelConstantNode , {
727+ type : "FileLevelConstant" ,
728+ initialValue : {
729+ number : "10" ,
730+ subdenomination : null ,
731+ type : "NumberLiteral"
732+ } ,
733+ name : "EXPONENT" ,
734+ typeName : {
735+ name : "uint" ,
736+ type : "ElementaryTypeName"
737+ }
738+ } )
739+ } )
740+
722741 it ( "ModifierInvocation" , function ( ) {
723742 var ast = parseNode ( "function foo(uint a) onlyOwner {}" )
724743 assert . deepEqual ( ast . modifiers [ 0 ] , {
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ describe("#parse", function() {
2020 it ( "supports tolerant mode" , function ( ) {
2121 var source = "not good"
2222 var root = parser . parse ( source , { tolerant : true } )
23- assert . equal ( root . errors . length , 1 )
23+ assert . isAbove ( root . errors . length , 0 )
2424 } )
2525
2626 it ( "supports loc" , function ( ) {
Original file line number Diff line number Diff line change @@ -708,3 +708,6 @@ contract AssemblySlotNotation {
708708function helper (uint x ) pure returns (uint ) {
709709 return x * 2 ;
710710}
711+
712+ // file-level constant
713+ uint constant topLevelConstantVariable = 3 ;
You can’t perform that action at this time.
0 commit comments