diff --git a/lib/css/values/validate.js b/lib/css/values/validate.js index bbc83de..c2c47af 100644 --- a/lib/css/values/validate.js +++ b/lib/css/values/validate.js @@ -37,39 +37,45 @@ exports.angle = function () { var a = +matches[1]; var unit = matches[2]; var max = null; - - switch (unit) { - case 'deg': - max = 360; - break; - - case 'grad': - max = 400; - break; - - case 'rad': - max = 2 * Math.PI; - break; - - case 'turn': - max = 1; - break; - - default: - throw new Error('Unhandled angle unit: ' + token.getUnit()); - } - - if (a < 0 || a >= max) { + + if (!unit && a == 0) { var warningToken = token.clone(); - this.addWarning('angle', warningToken); - } - - while (a < 0) { - a += max; - } - - while (a >= max) { - a -= max; + this.addWarning('invalid-value', warningToken); + } + else { + switch (unit) { + case 'deg': + max = 360; + break; + + case 'grad': + max = 400; + break; + + case 'rad': + max = 2 * Math.PI; + break; + + case 'turn': + max = 1; + break; + + default: + throw new Error('Unhandled angle unit: ' + token.getUnit()); + } + + if (a < 0 || a >= max) { + var warningToken = token.clone(); + this.addWarning('angle', warningToken); + } + + while (a < 0) { + a += max; + } + + while (a >= max) { + a -= max; + } } token.content = a.toFixed(10).replace(/\.?0+$/, '') + unit;