Skip to content

Add silent option #90

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

Closed
wants to merge 6 commits into from
Closed
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
22 changes: 17 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ module.exports = function(css, options){
*/

function error(msg) {
if (options.silent === true) {
return false;
}

var err = new Error(msg + ' near line ' + lineno + ':' + column);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

insert new line

err.filename = options.source;
err.line = lineno;
Expand Down Expand Up @@ -116,8 +120,10 @@ module.exports = function(css, options){
whitespace();
comments(rules);
while (css.length && css.charAt(0) != '}' && (node = atrule() || rule())) {
rules.push(node);
comments(rules);
if (node !== false) {
rules.push(node);
comments(rules);
}
}
return rules;
}
Expand Down Expand Up @@ -150,7 +156,11 @@ module.exports = function(css, options){
function comments(rules) {
var c;
rules = rules || [];
while (c = comment()) rules.push(c);
while (c = comment()) {
if (c !== false) {
rules.push(c);
}
}
return rules;
}

Expand Down Expand Up @@ -245,8 +255,10 @@ module.exports = function(css, options){
// declarations
var decl;
while (decl = declaration()) {
decls.push(decl);
comments(decls);
if (decl !== false) {
decls.push(decl);
comments(decls);
}
}

if (!close()) return error("missing '}'");
Expand Down
7 changes: 7 additions & 0 deletions test/css-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,11 @@ describe('parse(str)', function(){
parse('p { color:; }');
});
});

it('should not throw with silent option', function () {
assert.doesNotThrow(function(){
parse('thing { color: red; } /* b { color: blue; }',{ silent: true });
});
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the new lines

});