Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow empty single-line comments #345

Merged
merged 7 commits into from
Dec 16, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lib/modules/variable-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ function setVariables(string, syntax, variables) {
var ast, result, changeVariable;

changeVariable = function(ast, key, value) {
return gonzo.traverse(ast, [{

var visitors = {
sass: {
// Visitor for SASS and SCSS syntaxes
test: function(name, nodes) {
return name === 'declaration' && nodes[1][0] === 'variable' && nodes[1][1].indexOf(key) !== -1;
Expand All @@ -158,7 +160,7 @@ function setVariables(string, syntax, variables) {
return node;
}
},
{
less: {
// Visitor for LESS syntax
test: function(name) {
return name === 'atrules';
Expand Down Expand Up @@ -191,7 +193,10 @@ function setVariables(string, syntax, variables) {
return node;
}
}
]);
};
visitors.scss = visitors.sass;

return gonzo.traverse(ast, [visitors[syntax]]);
};

ast = gonzales.srcToAST({
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"debug": "~2.1.0",
"event-stream": "^3.1.7",
"express": "^4.10.4",
"gonzales-ast": "0.0.5",
"gonzales-ast": "0.0.6",
"gonzales-pe": "^3.0.0-12",
"gulp": "^3.8.10",
"gulp-concat": "^2.4.2",
Expand Down
24 changes: 22 additions & 2 deletions test/unit/modules/variable-parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,27 @@ describe('Parser', function() {
changed = parser.setVariables(str, 'scss', variables);
expect(changed).eql(result);
});

it('should preserve inline comments', function() {
var str = multiline(function() {
/*
$mycolor: #00ff00;
//
$mypadding: 3px;
*/
}),
variables = [
{name: 'mypadding', value: '0'}
],
result = multiline(function() {
/*
$mycolor: #00ff00;
//
$mypadding: 0;
*/
}),
changed = parser.setVariables(str, 'scss', variables);
expect(changed).eql(result);
});
it('should preserve comments', function() {
var str = '' +
'$mycolor: #00ff00;\n' +
Expand Down Expand Up @@ -481,7 +501,7 @@ describe('Parser', function() {
changed = parser.setVariables(str, 'less', variables);
expect(changed).eql(result);
});
it('should preserve comments', function() {
it('should preserve multiline comments', function() {
var str = '' +
'@mycolor: #00ff00;\n' +
'/* Comment */\n' +
Expand Down