parse-css
parse-css copied to clipboard
Throw parse errors instead of just logging them to console
This way the parser could be used to validate properties and attributes, e.g.:
let isValidStyleAttributeValue = (value) => {
try {
CSSParser.parseAListOfDeclarations(value.trim());
}
catch (error) {
return false;
}
return true;
};
I wouldn't want to do that in general - one of CSS's nice features is that it'll parse any byte sequence you throw at it. But yeah, having some way to indicate that there was indeed a parse error would be nice for validation purposes.
But the parser is already throwing some parse errors, it would make more sense to either throw all parse errors or none at all.
You're right, I should definitely be consistent between the two.