Skip to content

Commit 722779e

Browse files
committed
Gonzales 3.0: Update space-between-declarations
1 parent ced8b94 commit 722779e

2 files changed

Lines changed: 24 additions & 24 deletions

File tree

lib/options/space-between-declarations.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,39 @@
1+
var gonzales = require('gonzales-pe');
2+
13
module.exports = (function() {
24
function getDeclarationEnd(node, i) {
35
for (;i < node.length; i++) {
4-
if (!node[i + 1]) {
6+
if (!node.get(i + 1) || typeof node.get(i + 1) === 'string') {
57
return 0;
6-
} else if (node[i + 1][0] === 's') {
7-
if (node[i + 1][1].indexOf('\n') > -1) {
8-
if (node[i + 2] && node[i + 2][0] === 'declaration') {
8+
} else if (node.get(i + 1).is('s')) {
9+
if (node.get(i + 1).content.indexOf('\n') > -1) {
10+
if (node.get(i + 2) && node.get(i + 2).is('declaration')) {
911
return i;
1012
} else {
1113
return 0;
1214
}
13-
} else if (node[i + 2] && node[i + 2][0] === 'commentML') {
14-
if (node[i + 3] && node[i + 3][0] === 'declaration') {
15+
} else if (node.get(i + 2) && node.get(i + 2).is('commentML')) {
16+
if (node.get(i + 3) && node.get(i + 3).is('declaration')) {
1517
return i + 2;
16-
} else if (node[i + 3] && node[i + 3][0] === 's') {
17-
if (node[i + 4] && node[i + 4][0] === 'declaration') {
18+
} else if (node.get(i + 3) && node.get(i + 3).is('s')) {
19+
if (node.get(i + 4) && node.get(i + 4).is('declaration')) {
1820
return i + 2;
1921
} else {
2022
return 0;
2123
}
2224
} else {
2325
return 0;
2426
}
25-
} else if (node[i + 2] && node[i + 2][0] === 'declaration') {
27+
} else if (node.get(i + 2) && node.get(i + 2).is('declaration')) {
2628
return i;
2729
}
28-
} else if (node[i + 1][0] === 'declaration') {
30+
} else if (node.get(i + 1).is('declaration')) {
2931
return i;
30-
} else if (node[i + 1][0] === 'commentML') {
31-
if (node[i + 2] && node[i + 2][0] === 'declaration') {
32+
} else if (node.get(i + 1).is('commentML')) {
33+
if (node.get(i + 2) && node.get(i + 2).is('declaration')) {
3234
return i + 1;
33-
} else if (node[i + 2] && node[i + 2][0] === 's') {
34-
if (node[i + 3] && node[i + 3][0] === 'declaration') {
35+
} else if (node.get(i + 2) && node.get(i + 2).is('s')) {
36+
if (node.get(i + 3) && node.get(i + 3).is('declaration')) {
3537
return i + 1;
3638
}
3739
} else {
@@ -58,18 +60,15 @@ module.exports = (function() {
5860
/**
5961
* Processes tree node.
6062
*
61-
* @param {String} nodeType
6263
* @param {node} node
6364
*/
64-
process: function(nodeType, node) {
65+
process: function(node) {
6566
var value = this.getValue('space-between-declarations');
6667

6768
// TODO: Limit nodes to blocks, stylesheet, etc.
6869

6970
for (var i = 0, l = node.length; i < l; i++) {
70-
var currentNode = node[i];
71-
72-
if (currentNode[0] !== 'declDelim') continue;
71+
if (!node.get(i) || !node.get(i).is('declDelim')) continue;
7372

7473
// Grom user's point of view "declaration" includes semicolons
7574
// and comments placed on the same line.
@@ -81,13 +80,14 @@ module.exports = (function() {
8180
i = declarationEnd;
8281
}
8382

84-
var nextNode = node[i + 1];
85-
if (nextNode[0] === 's') {
86-
nextNode[1] = value;
83+
var nextNode = node.get(i + 1);
84+
if (nextNode.is('s')) {
85+
nextNode.content = value;
8786
} else {
8887
i++;
8988
l++;
90-
node.splice(i, 0, ['s', value]);
89+
var space = gonzales.createNode({ type: 's', content: value });
90+
node.insert(i, space);
9191
}
9292
}
9393
}

test/options/space-between-declarations/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
describe.skip('options/space-between-declarations:', function() {
1+
describe('options/space-between-declarations:', function() {
22
it('Array value => should not change anything', function() {
33
this.comb.configure({ 'space-between-declarations': ['', ' '] });
44
this.shouldBeEqual('test.css');

0 commit comments

Comments
 (0)