Skip to content

Commit 9be754b

Browse files
committed
Gonzales 3.0: Update vendor-prefix-align
1 parent d39942e commit 9be754b

3 files changed

Lines changed: 53 additions & 64 deletions

File tree

lib/options/vendor-prefix-align.js

Lines changed: 41 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
var gonzales = require('gonzales-pe');
2+
13
module.exports = (function() {
24
// Vendor prefixes list:
35
var PREFIXES = [
@@ -73,30 +75,27 @@ module.exports = (function() {
7375
for (var i = nodes.length; i--;) {
7476
node = nodes[i];
7577

76-
if (!Array.isArray(node))
77-
continue;
78-
79-
if (!node[1]) {
78+
if (!node.content) {
8079
crPos = -1;
8180
} else {
82-
crPos = node[1].lastIndexOf('\n');
83-
tabPos = node[1].lastIndexOf('\t');
81+
crPos = node.content.lastIndexOf('\n');
82+
tabPos = node.content.lastIndexOf('\t');
8483
if (tabPos > crPos) crPos = tabPos;
8584
}
8685

8786
if (crPos !== -1)
8887
oneline = false;
8988

90-
if (node[0] === 's') {
91-
result += node[1].length - crPos - 1;
89+
if (node.is('s')) {
90+
result += node.content.length - crPos - 1;
9291
if (crPos !== -1)
9392
break;
9493
}
95-
if (node[0] === 'commentML') {
94+
if (node.is('commentML')) {
9695
if (crPos === -1) {
97-
result += node[1].length + 4 /* comment symbols length */ ;
96+
result += node.content.length + 4 /* comment symbols length */ ;
9897
} else {
99-
result += node[1].length - crPos + 1 /* only last comment symbols length - 1(not count \n)*/;
98+
result += node.content.length - crPos + 1 /* only last comment symbols length - 1(not count \n)*/;
10099
break;
101100
}
102101
}
@@ -114,9 +113,9 @@ module.exports = (function() {
114113
function extraIndentProperty(nodes, i) {
115114
var subset = [];
116115
while (i--) {
117-
if (!nodes[i] || nodes[i][0] === 'declDelim')
116+
if (!nodes.get(i) || nodes.get(i).is('declDelim'))
118117
break;
119-
subset.unshift(nodes[i]);
118+
subset.unshift(nodes.get(i));
120119
}
121120
return extraIndent(subset);
122121
}
@@ -129,15 +128,16 @@ module.exports = (function() {
129128
*/
130129
function extraIndentVal(nodes, i) {
131130
var subset = [];
132-
var declaration = nodes[i];
131+
var declaration = nodes.get(i);
132+
if (!declaration.is('declaration')) return;
133133

134134
for (var x = declaration.length; x--;) {
135-
if (declaration[x][0] !== 'value') continue;
135+
if (!declaration.get(x).is('value')) continue;
136136

137137
x--;
138138

139-
while (declaration[x][0] !== 'propertyDelim') {
140-
subset.push(declaration[x]);
139+
while (!declaration.get(x).is('propertyDelim')) {
140+
subset.push(declaration.get(x));
141141
x--;
142142
}
143143

@@ -161,11 +161,10 @@ module.exports = (function() {
161161
function walk(args) {
162162
args.node.forEach(function(item, i) {
163163
var name = args.selector(item);
164-
var info = name && getPrefixInfo(
165-
name,
166-
args.namespaceSelector && makeNamespace(args.namespaceSelector(item)),
167-
args.getExtraSymbols(args.node, i)
168-
);
164+
var namespace = args.namespaceSelector && makeNamespace(args.namespaceSelector(item));
165+
var extraSymbols = args.getExtraSymbols(args.node, i);
166+
167+
var info = name && getPrefixInfo(name, namespace, extraSymbols);
169168
if (!info) return;
170169
args.payload(info, i);
171170
});
@@ -181,9 +180,9 @@ module.exports = (function() {
181180
* @returns {String|undefined}
182181
*/
183182
function getPropertyName(node) {
184-
if (node[0] !== 'declaration') return;
183+
if (!node.is('declaration')) return;
185184
// TODO: Check that it's not a variable
186-
return node[1][1][1];
185+
return node.get(0).get(0).content;
187186
}
188187

189188
/**
@@ -198,21 +197,11 @@ module.exports = (function() {
198197
* @returns {String|undefined}
199198
*/
200199
function getValName(node) {
201-
if (node[0] !== 'declaration') return;
202-
203-
var valueNode;
204-
var value;
205-
206-
for (var i = node.length; i--;) {
207-
valueNode = node[i];
208-
209-
if (valueNode[0] !== 'value') continue;
200+
if (!node.is('declaration')) return;
210201

211-
value = valueNode[1];
212-
213-
if (value[0] === 'ident') return value[1];
214-
if (value[0] === 'function') return value[1][1];
215-
}
202+
var value = node.first('value');
203+
if (value.get(0).is('ident')) return value.get(0).content;
204+
if (value.get(0).is('function')) return value.get(0).get(0).content;
216205
}
217206

218207
/**
@@ -271,11 +260,10 @@ module.exports = (function() {
271260
/**
272261
* Processes tree node.
273262
*
274-
* @param {String} nodeType
275263
* @param {node} node
276264
*/
277-
process: function(nodeType, node) {
278-
if (nodeType !== 'block') return;
265+
process: function(node) {
266+
if (!node.is('block')) return;
279267
oneline = true;
280268

281269
var dict = {};
@@ -309,16 +297,17 @@ module.exports = (function() {
309297
namespaceSelector: getPropertyName,
310298
getExtraSymbols: extraIndentVal,
311299
payload: function(info, i) {
312-
for (var x = node[i].length; x--;) {
313-
if (node[i][x][0] === 'value') break;
300+
for (var x = node.get(i).length; x--;) {
301+
if (node.get(i).get(x).is('value')) break;
314302
}
315303

316-
if (node[i][x - 1][0] !== 's') {
317-
node[i].splice(x, 0, ['s', '']);
304+
if (!node.get(i).get(x - 1).is('s')) {
305+
var space = gonzales.createNode({ type: 's', content: '' });
306+
node.get(i).insert(x, space);
318307
++x;
319308
}
320309

321-
node[i][x - 1][1] = updateIndent(info, dict, node[i][x - 1][1]);
310+
node.get(i).get(x - 1).content = updateIndent(info, dict, node.get(i).get(x - 1).content);
322311
}
323312
});
324313

@@ -329,15 +318,15 @@ module.exports = (function() {
329318
selector: getPropertyName,
330319
getExtraSymbols: extraIndentProperty,
331320
payload: function(info, i) {
332-
// `node[i - 1]` can be either space or comment:
333-
var whitespaceNode = node[i - 1];
321+
// `node.get(i - 1)` can be either space or comment:
322+
var whitespaceNode = node.get(i - 1);
334323
if (!whitespaceNode) return;
335324
// If it's a comment, insert an empty space node:
336-
if (whitespaceNode[0] !== 's') {
337-
whitespaceNode = ['s', ''];
338-
node.splice(i - 1, 0, whitespaceNode);
325+
if (!whitespaceNode.is('s')) {
326+
whitespaceNode = gonzales.createNode({ type: 's', content: '' });
327+
node.insert(i - 1, whitespaceNode);
339328
}
340-
whitespaceNode[1] = updateIndent(info, dict, whitespaceNode[1]);
329+
whitespaceNode.content = updateIndent(info, dict, whitespaceNode.content);
341330
}
342331
});
343332
},

test/options/vendor-prefix-align-sass/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
describe.skip('options/vendor-prefix-align', function() {
1+
describe('options/vendor-prefix-align', function() {
22
beforeEach(function() {
33
this.comb.configure({ 'vendor-prefix-align': true });
44
});

test/options/vendor-prefix-align/test.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
describe.skip('options/vendor-prefix-align', function() {
1+
describe('options/vendor-prefix-align', function() {
22
beforeEach(function() {
33
this.comb.configure({ 'vendor-prefix-align': true });
44
});
@@ -59,23 +59,23 @@ describe.skip('options/vendor-prefix-align', function() {
5959
this.shouldBeEqual('issue-193.css', 'issue-193.expected.css');
6060
});
6161

62-
it('Issue 241: should not break tabs', function() {
62+
it.skip('Issue 241: should not break tabs', function() {
6363
this.comb.configure({
6464
'block-indent': '\t',
6565
'vendor-prefix-align': true
6666
});
6767
this.shouldBeEqual('issue-241.css', 'issue-241.expected.css');
6868
});
6969

70-
it('Shouldn not detect anything if there are no prefixed groups', function() {
70+
it.skip('Shouldn not detect anything if there are no prefixed groups', function() {
7171
this.shouldDetect(
7272
['vendor-prefix-align'],
7373
'a{ color: red }a{ -webkit-transform: translateZ(0) }',
7474
{}
7575
);
7676
});
7777

78-
it('Shouldn detect vendor-prefix-align as false in properties', function() {
78+
it.skip('Shouldn detect vendor-prefix-align as false in properties', function() {
7979
this.shouldDetect(
8080
['vendor-prefix-align'],
8181
this.readFile('property-align.css'),
@@ -85,7 +85,7 @@ describe.skip('options/vendor-prefix-align', function() {
8585
);
8686
});
8787

88-
it('Shouldn detect vendor-prefix-align as true in properties', function() {
88+
it.skip('Shouldn detect vendor-prefix-align as true in properties', function() {
8989
this.shouldDetect(
9090
['vendor-prefix-align'],
9191
this.readFile('property-align.expected.css'),
@@ -95,7 +95,7 @@ describe.skip('options/vendor-prefix-align', function() {
9595
);
9696
});
9797

98-
it('Shouldn detect vendor-prefix-align as false in values', function() {
98+
it.skip('Shouldn detect vendor-prefix-align as false in values', function() {
9999
this.shouldDetect(
100100
['vendor-prefix-align'],
101101
this.readFile('value-align.css'),
@@ -105,7 +105,7 @@ describe.skip('options/vendor-prefix-align', function() {
105105
);
106106
});
107107

108-
it('Shouldn detect vendor-prefix-align as true in values', function() {
108+
it.skip('Shouldn detect vendor-prefix-align as true in values', function() {
109109
this.shouldDetect(
110110
['vendor-prefix-align'],
111111
this.readFile('value-align.expected.css'),
@@ -115,7 +115,7 @@ describe.skip('options/vendor-prefix-align', function() {
115115
);
116116
});
117117

118-
it('Shouldn detect vendor-prefix-align as true, test 1', function() {
118+
it.skip('Shouldn detect vendor-prefix-align as true, test 1', function() {
119119
this.shouldDetect(
120120
['vendor-prefix-align'],
121121
this.readFile('already-aligned.css'),
@@ -125,7 +125,7 @@ describe.skip('options/vendor-prefix-align', function() {
125125
);
126126
});
127127

128-
it('Shouldn detect vendor-prefix-align as true, test 2', function() {
128+
it.skip('Shouldn detect vendor-prefix-align as true, test 2', function() {
129129
this.shouldDetect(
130130
['vendor-prefix-align'],
131131
this.readFile('complex.expected.css'),
@@ -135,7 +135,7 @@ describe.skip('options/vendor-prefix-align', function() {
135135
);
136136
});
137137

138-
it('Shouldn detect vendor-prefix-align as false', function() {
138+
it.skip('Shouldn detect vendor-prefix-align as false', function() {
139139
this.shouldDetect(
140140
['vendor-prefix-align'],
141141
this.readFile('complex.css'),
@@ -145,7 +145,7 @@ describe.skip('options/vendor-prefix-align', function() {
145145
);
146146
});
147147

148-
it('Should not detect anything in simple case', function() {
148+
it.skip('Should not detect anything in simple case', function() {
149149
this.shouldDetect(
150150
['vendor-prefix-align'],
151151
'a{border:0;}',

0 commit comments

Comments
 (0)