Skip to content

Commit cfdee5c

Browse files
author
Juuso Backman
committed
Merge pull request #345 from varya/fixes/empty-comments
Allow empty single-line comments
2 parents 386e3aa + de23c54 commit cfdee5c

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

lib/modules/variable-parser.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ function setVariables(string, syntax, variables) {
148148
var ast, result, changeVariable;
149149

150150
changeVariable = function(ast, key, value) {
151-
return gonzo.traverse(ast, [{
151+
152+
var visitors = {
153+
sass: {
152154
// Visitor for SASS and SCSS syntaxes
153155
test: function(name, nodes) {
154156
return name === 'declaration' && nodes[1][0] === 'variable' && nodes[1][1].indexOf(key) !== -1;
@@ -158,7 +160,7 @@ function setVariables(string, syntax, variables) {
158160
return node;
159161
}
160162
},
161-
{
163+
less: {
162164
// Visitor for LESS syntax
163165
test: function(name) {
164166
return name === 'atrules';
@@ -191,7 +193,10 @@ function setVariables(string, syntax, variables) {
191193
return node;
192194
}
193195
}
194-
]);
196+
};
197+
visitors.scss = visitors.sass;
198+
199+
return gonzo.traverse(ast, [visitors[syntax]]);
195200
};
196201

197202
ast = gonzales.srcToAST({

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"debug": "~2.1.0",
3636
"event-stream": "^3.1.7",
3737
"express": "^4.10.4",
38-
"gonzales-ast": "0.0.5",
38+
"gonzales-ast": "0.0.6",
3939
"gonzales-pe": "^3.0.0-12",
4040
"gulp": "^3.8.10",
4141
"gulp-concat": "^2.4.2",

test/unit/modules/variable-parser.test.js

+22-2
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,27 @@ describe('Parser', function() {
395395
changed = parser.setVariables(str, 'scss', variables);
396396
expect(changed).eql(result);
397397
});
398-
398+
it('should preserve inline comments', function() {
399+
var str = multiline(function() {
400+
/*
401+
$mycolor: #00ff00;
402+
//
403+
$mypadding: 3px;
404+
*/
405+
}),
406+
variables = [
407+
{name: 'mypadding', value: '0'}
408+
],
409+
result = multiline(function() {
410+
/*
411+
$mycolor: #00ff00;
412+
//
413+
$mypadding: 0;
414+
*/
415+
}),
416+
changed = parser.setVariables(str, 'scss', variables);
417+
expect(changed).eql(result);
418+
});
399419
it('should preserve comments', function() {
400420
var str = '' +
401421
'$mycolor: #00ff00;\n' +
@@ -481,7 +501,7 @@ describe('Parser', function() {
481501
changed = parser.setVariables(str, 'less', variables);
482502
expect(changed).eql(result);
483503
});
484-
it('should preserve comments', function() {
504+
it('should preserve multiline comments', function() {
485505
var str = '' +
486506
'@mycolor: #00ff00;\n' +
487507
'/* Comment */\n' +

0 commit comments

Comments
 (0)