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
|
define.class("$system/parse/onejsserialize", function(require){
this.newState = function(){
return {
depth:"",
references:[]
}
}
this.Index = function(node, parent, state){
if(!state.expr || node.index.type !== 'Value') throw new Error("Cannot property bind to dynamic index")
state.expr.unshift(node.index.value)
return this.expand(node.object, node, state) + '[' + node.index.value + ']'
}
this.Key = function(node, parent, state){
var name = node.key.name
if (!name) {
name = node.key.value
}
if(state.expr) state.expr.unshift(name)
else {
state = Object.create(state)
state.expr = [name]
if(parent.type !== 'Call' || parent.fn !== node){
state.references.push(state.expr)
}
}
return this.expand(node.object, node, state) + '.' + name
}
this.This = function(node, parent, state){
if(state.expr) state.expr.unshift('this')
return 'this'
}
this.Id = function(node, parent, state){
if(state.expr) state.expr.unshift(node.name)
return node.name
}
this.Value = function(node, parent, state){
return node.raw
}
})
|