Skip to content

Commit 39cd1d8

Browse files
committed
Update gonzales to v2.0.0-rc0
– Use new method names – Allow processing of *.scss files – Check syntax name (css or scss) - Use one `include` node for both `@include` and `@extend` – Update tests
1 parent 0044263 commit 39cd1d8

7 files changed

Lines changed: 297 additions & 348 deletions

File tree

.jshint-groups.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = {
2727
test: {
2828
options: {
2929
node: true,
30-
predef: ['describe', 'beforeEach', 'it']
30+
predef: ['describe', 'beforeEach', 'afterEach', 'it']
3131
},
3232
includes: ['test/*.js']
3333
}

lib/csscomb.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,22 +103,23 @@ Comb.prototype = {
103103
/**
104104
* Process file provided with a string.
105105
* @param {String} text
106+
* @param {String} [syntax] Syntax name (e.g. `scss`)
106107
* @param {String} [filename]
107108
*/
108-
processString: function(text, filename) {
109+
processString: function(text, syntax, filename) {
109110
if (!text) return text;
110111
var tree;
111112
var string = JSON.stringify;
112113
try {
113-
tree = gonzales.srcToCSSP(text);
114+
tree = gonzales.cssToAST({ syntax: syntax, css: text });
114115
} catch (e) {
115116
throw new Error('Parsing error at ' + filename + ': ' + e.message);
116117
}
117118
if (typeof tree === 'undefined') {
118119
throw new Error('Undefined tree at ' + filename + ': ' + string(text) + ' => ' + string(tree));
119120
}
120121
tree = this.processTree(tree);
121-
return gonzales.csspToSrc(tree);
122+
return gonzales.astToCSS({ syntax: syntax, ast: tree });
122123
},
123124

124125
/**
@@ -129,9 +130,11 @@ Comb.prototype = {
129130
*/
130131
processFile: function(path) {
131132
var _this = this;
132-
if (this._shouldProcess(path) && path.match(/\.css$/)) {
133+
// TODO: Move extension check into `_shouldProcess` method
134+
if (this._shouldProcess(path) && path.match(/\.[css, scss]$/)) {
133135
return vfs.read(path, 'utf8').then(function(data) {
134-
var processedData = _this.processString(data, path);
136+
var syntax = path.split('.').pop();
137+
var processedData = _this.processString(data, syntax, path);
135138
var changed = data !== processedData;
136139
var lint = _this._lint;
137140

lib/options/always-semicolon.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module.exports = {
2929
if (type === 'declaration') {
3030
var space = [];
3131
for (var j = value.length; j--;) {
32-
if (value[j][0] !== 's' && value[j][0] !== 'comment') break;
32+
if (['s', 'commentML', 'commentSL'].indexOf(value[j][0]) === -1) break;
3333
space.unshift(value.splice(j)[0]);
3434
}
3535
node.splice.apply(node, [i + 1, 0, ['decldelim']].concat(space));

lib/options/remove-empty-rulesets.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ module.exports = {
6767
},
6868

6969
_isDeclarationOrComment: function(node) {
70-
return node[0] === 'declaration' || node[0] === 'comment';
70+
return ['declaration', 'commentML', 'commentSL'].indexOf(node[0]) > -1;
7171
},
7272

7373
_isRuleset: function(node) {

lib/options/sort-order.js

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@ module.exports = {
2626
*/
2727
process: function(nodeType, node) {
2828
// Types of nodes that can be sorted:
29-
var NODES = ['atruleb', 'atruler', 'atrules', 'comment', 'declaration', 's'];
30-
// Special @-rules that can be sorted:
31-
var ATRULES = ['extend', 'import', 'include'];
29+
var NODES = ['atruleb', 'atruler', 'atrules', 'commentML', 'commentSL',
30+
'declaration', 's', 'include'];
3231
// Spaces and comments:
33-
var SC = ['comment', 's'];
32+
var SC = ['commentML', 'commentSL', 's'];
3433

3534
var currentNode;
3635
// Sort order of properties:
@@ -64,10 +63,9 @@ module.exports = {
6463

6564
for (; i < l; i++) {
6665
currentNode = node[i];
67-
// If there is no node, or it is nor spaces neither comment,
66+
// If there is no node left,
6867
// stop and do nothing with previously found spaces/comments:
69-
if (!currentNode ||
70-
NODES.indexOf(currentNode[0]) === -1) {
68+
if (!currentNode) {
7169
return false;
7270
}
7371

@@ -104,7 +102,7 @@ module.exports = {
104102
// If there is no node, or it is nor spaces neither comment, stop:
105103
if (!currentNode || SC.indexOf(currentNode[0]) === -1) break;
106104

107-
if (currentNode[0] === 'comment') {
105+
if (['commentML', 'commentSL'].indexOf(currentNode[0]) > -1) {
108106
sc.push(currentNode);
109107
d.push(i + 1);
110108
continue;
@@ -166,15 +164,15 @@ module.exports = {
166164

167165
// If there is `;` right after the declaration, save it with the
168166
// declaration and mark it for removing from parent node:
169-
if (currentNode && nextNode[0] === 'decldelim') {
167+
if (currentNode && nextNode && nextNode[0] === 'decldelim') {
170168
extendedNode.delim.push(nextNode);
171169
deleted.push(i + 1);
172170
i++;
173171
}
174172

175173
// Save spaces and comments which follow right after the declaration
176174
// and mark them for removing from parent node:
177-
extendedNode.sc1 = checkSC1(i);
175+
extendedNode.sc1 = checkSC1();
178176

179177
return extendedNode;
180178
};
@@ -207,17 +205,21 @@ module.exports = {
207205
// with a valid property (e.g. `color` or `$width`).
208206
// If not, proceed with the next node:
209207
propertyName = null;
210-
for (j = 1, nl = node[i].length; j < nl; j++) {
211-
currentNode = node[i][j];
212-
if (currentNode[0] === 'property') {
213-
propertyName = currentNode[1][0] === 'variable' ?
214-
'$variable' : currentNode[1][1];
215-
break;
216-
} else if (currentNode[0] === 'atkeyword') {
217-
if (ATRULES.indexOf(currentNode[1][1]) > -1) {
218-
propertyName = '$' + currentNode[1][1];
208+
// Look for includes:
209+
if (node[i][0] === 'include') {
210+
propertyName = '$include';
211+
} else {
212+
for (j = 1, nl = node[i].length; j < nl; j++) {
213+
currentNode = node[i][j];
214+
if (currentNode[0] === 'property') {
215+
propertyName = currentNode[1][0] === 'variable' ?
216+
'$variable' : currentNode[1][1];
217+
break;
218+
} else if (currentNode[0] === 'atkeyword' &&
219+
currentNode[1][1] === 'import') { // Look for imports
220+
propertyName = '$import';
221+
break;
219222
}
220-
break;
221223
}
222224
}
223225

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
},
4141
"dependencies": {
4242
"commander": "2.0.0",
43-
"gonzales": "1.0.7",
43+
"gonzales-pe": "2.0.0-rc0",
4444
"minimatch": "0.2.12",
4545
"vow": "0.3.11",
4646
"vow-fs": "0.2.3"

0 commit comments

Comments
 (0)