-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathutils.ts
More file actions
33 lines (28 loc) · 1.16 KB
/
utils.ts
File metadata and controls
33 lines (28 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { assert } from 'chai'
import * as parser from '../src/index'
import { ParseOptions } from '../src/types'
export function parseContract(source: string, options: ParseOptions = {}) {
const ast: any = parser.parse(source, options)
assert.isOk(ast.children[0])
return ast.children[0]
}
export function parseNode(source: string, options = {}) {
const contract = parseContract('contract test { ' + source + ' }', options)
assert.isOk(contract.subNodes[0])
return contract.subNodes[0]
}
export function parseStatement(source: string, options = {}) {
const ast = parseNode('function () { ' + source + ' }', options)
assert.isOk(ast.body.statements[0])
return ast.body.statements[0]
}
export function parseExpression(source: string, options = {}) {
const ast = parseNode('function () { ' + source + '; }', options)
assert.isOk(ast.body.statements[0].expression)
return ast.body.statements[0].expression
}
export function parseAssembly(source: string, options = {}) {
const ast = parseNode('function () { assembly { ' + source + ' } }', options)
assert.isOk(ast.body.statements[0].body.operations[0])
return ast.body.statements[0].body.operations[0]
}