parse-css icon indicating copy to clipboard operation
parse-css copied to clipboard

Throw parse errors instead of just logging them to console

Open jarek-foksa opened this issue 8 years ago • 3 comments

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;
};

jarek-foksa avatar Aug 04 '16 09:08 jarek-foksa

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.

tabatkins avatar Aug 04 '16 19:08 tabatkins

But the parser is already throwing some parse errors, it would make more sense to either throw all parse errors or none at all.

jarek-foksa avatar Aug 26 '16 22:08 jarek-foksa

You're right, I should definitely be consistent between the two.

tabatkins avatar Nov 22 '16 00:11 tabatkins