@@ -347,7 +347,7 @@ describe('AST', () => {
347347 isDeclaredConst : false ,
348348 isIndexed : false ,
349349 isImmutable : false ,
350- storageLocation : null
350+ storageLocation : null ,
351351 } ,
352352 ] ,
353353 initialValue : null ,
@@ -374,7 +374,7 @@ describe('AST', () => {
374374 isDeclaredConst : false ,
375375 isIndexed : false ,
376376 isImmutable : true ,
377- storageLocation : null
377+ storageLocation : null ,
378378 } ,
379379 ] ,
380380 initialValue : null ,
@@ -433,7 +433,7 @@ describe('AST', () => {
433433 isDeclaredConst : false ,
434434 isIndexed : false ,
435435 isImmutable : false ,
436- storageLocation : null
436+ storageLocation : null ,
437437 } ,
438438 ] ,
439439 initialValue : null ,
@@ -502,7 +502,7 @@ describe('AST', () => {
502502 isDeclaredConst : false ,
503503 isIndexed : false ,
504504 isImmutable : false ,
505- storageLocation : null
505+ storageLocation : null ,
506506 } ,
507507 ] ,
508508 initialValue : null ,
@@ -2254,7 +2254,7 @@ describe('AST', () => {
22542254 type : 'DecimalNumber' ,
22552255 value : '0' ,
22562256 } ,
2257- default : false
2257+ default : false ,
22582258 } ,
22592259 {
22602260 type : 'AssemblyCase' ,
@@ -2895,4 +2895,142 @@ describe('AST', () => {
28952895 } ,
28962896 } )
28972897 } )
2898+
2899+ it ( 'should support top-level custom errors' , function ( ) {
2900+ let ast : any = parser . parse ( 'error MyCustomError();' )
2901+ assert . deepEqual ( ast . children [ 0 ] , {
2902+ type : 'CustomErrorDefinition' ,
2903+ name : 'MyCustomError' ,
2904+ parameters : [ ] ,
2905+ } )
2906+
2907+ ast = parser . parse ( 'error MyCustomError(uint a);' )
2908+ assert . deepEqual ( ast . children [ 0 ] , {
2909+ type : 'CustomErrorDefinition' ,
2910+ name : 'MyCustomError' ,
2911+ parameters : [
2912+ {
2913+ type : 'VariableDeclaration' ,
2914+ typeName : {
2915+ type : 'ElementaryTypeName' ,
2916+ name : 'uint' ,
2917+ stateMutability : null ,
2918+ } ,
2919+ name : 'a' ,
2920+ isStateVar : false ,
2921+ isIndexed : false ,
2922+ expression : null ,
2923+ storageLocation : null ,
2924+ } ,
2925+ ] ,
2926+ } )
2927+
2928+ ast = parser . parse ( 'error MyCustomError(string);' )
2929+ assert . deepEqual ( ast . children [ 0 ] , {
2930+ type : 'CustomErrorDefinition' ,
2931+ name : 'MyCustomError' ,
2932+ parameters : [
2933+ {
2934+ type : 'VariableDeclaration' ,
2935+ typeName : {
2936+ type : 'ElementaryTypeName' ,
2937+ name : 'string' ,
2938+ stateMutability : null ,
2939+ } ,
2940+ name : null ,
2941+ isStateVar : false ,
2942+ isIndexed : false ,
2943+ expression : null ,
2944+ storageLocation : null ,
2945+ } ,
2946+ ] ,
2947+ } )
2948+ } )
2949+
2950+ it ( 'should support contract-level custom errors' , function ( ) {
2951+ let ast : any = parseNode ( 'error MyCustomError();' )
2952+ assert . deepEqual ( ast , {
2953+ type : 'CustomErrorDefinition' ,
2954+ name : 'MyCustomError' ,
2955+ parameters : [ ] ,
2956+ } )
2957+
2958+ ast = parseNode ( 'error MyCustomError(uint a);' )
2959+ assert . deepEqual ( ast , {
2960+ type : 'CustomErrorDefinition' ,
2961+ name : 'MyCustomError' ,
2962+ parameters : [
2963+ {
2964+ type : 'VariableDeclaration' ,
2965+ typeName : {
2966+ type : 'ElementaryTypeName' ,
2967+ name : 'uint' ,
2968+ stateMutability : null ,
2969+ } ,
2970+ name : 'a' ,
2971+ isStateVar : false ,
2972+ isIndexed : false ,
2973+ expression : null ,
2974+ storageLocation : null ,
2975+ } ,
2976+ ] ,
2977+ } )
2978+
2979+ ast = parseNode ( 'error MyCustomError(string);' )
2980+ assert . deepEqual ( ast , {
2981+ type : 'CustomErrorDefinition' ,
2982+ name : 'MyCustomError' ,
2983+ parameters : [
2984+ {
2985+ type : 'VariableDeclaration' ,
2986+ typeName : {
2987+ type : 'ElementaryTypeName' ,
2988+ name : 'string' ,
2989+ stateMutability : null ,
2990+ } ,
2991+ name : null ,
2992+ isStateVar : false ,
2993+ isIndexed : false ,
2994+ expression : null ,
2995+ storageLocation : null ,
2996+ } ,
2997+ ] ,
2998+ } )
2999+ } )
3000+
3001+ it ( 'should support revert statements' , function ( ) {
3002+ let ast : any = parseStatement ( 'revert MyCustomError();' )
3003+ assert . deepEqual ( ast , {
3004+ type : 'RevertStatement' ,
3005+ revertCall : {
3006+ arguments : [ ] ,
3007+ expression : {
3008+ name : 'MyCustomError' ,
3009+ type : 'Identifier' ,
3010+ } ,
3011+ names : [ ] ,
3012+ type : 'FunctionCall' ,
3013+ } ,
3014+ } )
3015+
3016+ ast = parseStatement ( 'revert MyCustomError(3);' )
3017+ assert . deepEqual ( ast , {
3018+ type : 'RevertStatement' ,
3019+ revertCall : {
3020+ arguments : [
3021+ {
3022+ number : '3' ,
3023+ subdenomination : null ,
3024+ type : 'NumberLiteral' ,
3025+ } ,
3026+ ] ,
3027+ expression : {
3028+ name : 'MyCustomError' ,
3029+ type : 'Identifier' ,
3030+ } ,
3031+ names : [ ] ,
3032+ type : 'FunctionCall' ,
3033+ } ,
3034+ } )
3035+ } )
28983036} )
0 commit comments