-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutils.js
56 lines (52 loc) · 1.5 KB
/
utils.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
void function(){
module.exports.copy = Copy;
module.exports.dump = Dump;
module.exports.invalidMutate = InvalidMutate;
module.exports.validMutate = ValidMutate;
function ValidMutate(node){
if (node["mutable"] = false){
node["mutable"] = true;
return;
}
for (var key in node) {
if (key == "loc" || key == "insert")
continue;
//console.log(key + ' ' + node[key]);
if ((typeof node[key] == "object")){
ValidMutate(node[key])
}
}
}
function InvalidMutate(node){
for (var key in node) {
if (key == "loc" || key == "insert")
continue;
//console.log(key + ' ' + node[key]);
if ((typeof node[key] == "object")){
node["mutable"] = false;
InvalidMutate(node[key])
}
}
}
function Copy(root){
if (root == null)
return;
var isArray = Array.isArray(root);
let shadow = isArray?[]:{};
for (key in root){
if (key == 'loc')
continue;
if (typeof root[key] == "object"){
shadow[key] = Copy(root[key]);
}
else{
//console.log(key + ' ' + root[key]);
shadow[key] = root[key];
}
}
return shadow;
}
function Dump(root){
return JSON.stringify(root);
}
}.call(this)