1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | var Node = require('./node');
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | var Property = module.exports = function Property(segs, expr){
|
23 | Node.call(this);
|
24 | this.segments = segs;
|
25 | this.expr = expr;
|
26 | };
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | Property.prototype.__proto__ = Node.prototype;
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | Property.prototype.clone = function(parent){
|
42 | var clone = new Property(this.segments);
|
43 | clone.name = this.name;
|
44 | if (this.literal) clone.literal = this.literal;
|
45 | clone.lineno = this.lineno;
|
46 | clone.column = this.column;
|
47 | clone.filename = this.filename;
|
48 | clone.segments = this.segments.map(function(node){ return node.clone(parent, clone); });
|
49 | if (this.expr) clone.expr = this.expr.clone(parent, clone);
|
50 | return clone;
|
51 | };
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | Property.prototype.toJSON = function(){
|
61 | var json = {
|
62 | __type: 'Property',
|
63 | segments: this.segments,
|
64 | name: this.name,
|
65 | lineno: this.lineno,
|
66 | column: this.column,
|
67 | filename: this.filename
|
68 | };
|
69 | if (this.expr) json.expr = this.expr;
|
70 | if (this.literal) json.literal = this.literal;
|
71 | return json;
|
72 | };
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 | Property.prototype.toString = function(){
|
82 | return 'property(' + this.segments.join('') + ', ' + this.expr + ')';
|
83 | };
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | Property.prototype.operate = function(op, right, val){
|
95 | return this.expr.operate(op, right, val);
|
96 | };
|