-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
62 lines (43 loc) · 1.22 KB
/
index.js
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* @fileoverview Definition of code edit () method and main functionality exporter for solmeister
* @author Raghav Dua <[email protected]>
*/
'use strict';
var solExplore = require ('sol-explore'),
solidityParser = require ('solparse');
module.exports = {
version: require ('./package.json').version,
edit: function (sourceCode, callback) {
var AST, result;
if (!sourceCode) {
return '';
}
if (typeof sourceCode === 'object' && sourceCode.constructor.name === 'Buffer') {
sourceCode = sourceCode.toString ();
}
result = sourceCode.split ('');
AST = solidityParser.parse (sourceCode);
solExplore.traverse (AST, {
enter: function (node, parent) {
node.parent = parent;
node.getSourceCode = function () {
return sourceCode.slice (node.start, node.end);
};
node.transform = function (newSourceCode) {
if (typeof newSourceCode !== 'string') {
throw new Error (
'Expected string argument, received ' + typeof newSourceCode
);
}
result [node.start] = newSourceCode;
for (var i = node.start + 1; i < node.end; i++) {
result [i] = '';
}
}
callback (node);
delete node.parent;
}
});
return result.join ('');
}
};