1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | var Node = require('./node');
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | var Atrule = module.exports = function Atrule(type){
|
21 | Node.call(this);
|
22 | this.type = type;
|
23 | };
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | Atrule.prototype.__proto__ = Node.prototype;
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | Atrule.prototype.__defineGetter__('hasOnlyProperties', function(){
|
39 | if (!this.block) return false;
|
40 |
|
41 | var nodes = this.block.nodes;
|
42 | for (var i = 0, len = nodes.length; i < len; ++i) {
|
43 | var nodeName = nodes[i].nodeName;
|
44 | switch(nodes[i].nodeName) {
|
45 | case 'property':
|
46 | case 'expression':
|
47 | case 'comment':
|
48 | continue;
|
49 | default:
|
50 | return false;
|
51 | }
|
52 | }
|
53 | return true;
|
54 | });
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 | Atrule.prototype.clone = function(parent){
|
64 | var clone = new Atrule(this.type);
|
65 | if (this.block) clone.block = this.block.clone(parent, clone);
|
66 | clone.segments = this.segments.map(function(node){ return node.clone(parent, clone); });
|
67 | clone.lineno = this.lineno;
|
68 | clone.column = this.column;
|
69 | clone.filename = this.filename;
|
70 | return clone;
|
71 | };
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 | Atrule.prototype.toJSON = function(){
|
81 | var json = {
|
82 | __type: 'Atrule',
|
83 | type: this.type,
|
84 | segments: this.segments,
|
85 | lineno: this.lineno,
|
86 | column: this.column,
|
87 | filename: this.filename
|
88 | };
|
89 | if (this.block) json.block = this.block;
|
90 | return json;
|
91 | };
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 | Atrule.prototype.toString = function(){
|
101 | return '@' + this.type;
|
102 | };
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 | Atrule.prototype.__defineGetter__('hasOutput', function(){
|
112 | return !!this.block && hasOutput(this.block);
|
113 | });
|
114 |
|
115 | function hasOutput(block) {
|
116 | var nodes = block.nodes;
|
117 |
|
118 |
|
119 | if (nodes.every(function(node){
|
120 | return 'group' == node.nodeName && node.hasOnlyPlaceholders;
|
121 | })) return false;
|
122 |
|
123 |
|
124 | return nodes.some(function(node) {
|
125 | switch (node.nodeName) {
|
126 | case 'property':
|
127 | case 'literal':
|
128 | case 'import':
|
129 | return true;
|
130 | case 'block':
|
131 | return hasOutput(node);
|
132 | default:
|
133 | if (node.block) return hasOutput(node.block);
|
134 | }
|
135 | });
|
136 | }
|