Skip to content

Commit 305ae73

Browse files
committed
Add support for transient storage variables
1 parent e0ed5da commit 305ae73

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

src/ASTBuilder.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ export class ASTBuilder
109109
isImmutable = true
110110
}
111111

112+
let isTransient = false
113+
if (ctx.TransientKeyword_list().length > 0) {
114+
isTransient = true
115+
}
116+
112117
const decl: AST.StateVariableDeclarationVariable = {
113118
type: 'VariableDeclaration',
114119
typeName: type,
@@ -120,6 +125,7 @@ export class ASTBuilder
120125
isDeclaredConst,
121126
isIndexed: false,
122127
isImmutable,
128+
isTransient,
123129
override,
124130
storageLocation: null,
125131
}

src/ast-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ export interface VariableDeclaration extends BaseASTNode {
245245
export interface StateVariableDeclarationVariable extends VariableDeclaration {
246246
override: null | UserDefinedTypeName[]
247247
isImmutable: boolean
248+
isTransient: boolean
248249
}
249250
export interface ArrayTypeName extends BaseASTNode {
250251
type: 'ArrayTypeName'

test/ast.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,7 @@ describe('AST', () => {
738738
isDeclaredConst: false,
739739
isIndexed: false,
740740
isImmutable: false,
741+
isTransient: false,
741742
storageLocation: null,
742743
},
743744
],
@@ -769,6 +770,39 @@ describe('AST', () => {
769770
isDeclaredConst: false,
770771
isIndexed: false,
771772
isImmutable: true,
773+
isTransient: false,
774+
storageLocation: null,
775+
},
776+
],
777+
initialValue: null,
778+
})
779+
})
780+
781+
it('StateVariableDeclaration with transient', () => {
782+
const ast: any = parseNode('bool transient locked;')
783+
assert.deepEqual(ast, {
784+
type: 'StateVariableDeclaration',
785+
variables: [
786+
{
787+
type: 'VariableDeclaration',
788+
typeName: {
789+
type: 'ElementaryTypeName',
790+
name: 'bool',
791+
stateMutability: null,
792+
},
793+
name: 'locked',
794+
identifier: {
795+
type: 'Identifier',
796+
name: 'locked',
797+
},
798+
expression: null,
799+
visibility: 'default',
800+
override: null,
801+
isStateVar: true,
802+
isDeclaredConst: false,
803+
isIndexed: false,
804+
isImmutable: false,
805+
isTransient: true,
772806
storageLocation: null,
773807
},
774808
],
@@ -832,6 +866,7 @@ describe('AST', () => {
832866
isDeclaredConst: false,
833867
isIndexed: false,
834868
isImmutable: false,
869+
isTransient: false,
835870
storageLocation: null,
836871
},
837872
],
@@ -905,6 +940,7 @@ describe('AST', () => {
905940
isDeclaredConst: false,
906941
isIndexed: false,
907942
isImmutable: false,
943+
isTransient: false,
908944
storageLocation: null,
909945
},
910946
],
@@ -1490,6 +1526,7 @@ describe('AST', () => {
14901526
isIndexed: false,
14911527
override: null,
14921528
isImmutable: false,
1529+
isTransient: false,
14931530
storageLocation: null,
14941531
})
14951532
})
@@ -2751,6 +2788,7 @@ describe('AST', () => {
27512788
isDeclaredConst: false,
27522789
isIndexed: false,
27532790
isImmutable: false,
2791+
isTransient: false,
27542792
storageLocation: null,
27552793
},
27562794
],

0 commit comments

Comments
 (0)