Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: CSSLint/parser-lib
base: a2aed01e68
...
head fork: CSSLint/parser-lib
compare: 8ca2d38b0c
  • 4 commits
  • 5 files changed
  • 0 commit comments
  • 3 contributors
Commits on Nov 14, 2012
@fracmak fracmak added support for calc wherever <length> is expected 1845473
@fracmak fracmak added support for + operator for calc functions e0be226
@fracmak fracmak _operator is used for seperating multiple values for a property (ie. …
…box-shadow: 10px 10px 0, 2px 2px 0) as well as for mathematical operators inside functions. Since functions are the only place mathematical operators are allowed, we now pass in a boolean to distinguish which token is acceptable to not accidentally treat -10px -10px as an equation
ebf3f4a
Commits on Nov 16, 2012
@nzakas nzakas Merge pull request #35 from fracmak/calc_support
added support for calc wherever <length> is expected
8ca2d38
View
17 src/css/Parser.js
@@ -708,18 +708,21 @@ Parser.prototype = function(){
});
},
- _operator: function(){
+ _operator: function(inFunction){
/*
- * operator
+ * operator (outside function)
* : '/' S* | ',' S* | /( empty )/
+ * operator (inside function)
+ * : '/' S* | '+' S* | '*' S* | '-' S* /( empty )/
* ;
*/
var tokenStream = this._tokenStream,
token = null;
- if (tokenStream.match([Tokens.SLASH, Tokens.COMMA])){
+ if (tokenStream.match([Tokens.SLASH, Tokens.COMMA]) ||
+ (inFunction && tokenStream.match([Tokens.PLUS, Tokens.STAR, Tokens.MINUS]))){
token = tokenStream.token();
this._readWhitespace();
}
@@ -1506,7 +1509,7 @@ Parser.prototype = function(){
return result;
},
- _expr: function(){
+ _expr: function(inFunction){
/*
* expr
* : term [ operator term ]*
@@ -1525,8 +1528,8 @@ Parser.prototype = function(){
values.push(value);
do {
- operator = this._operator();
-
+ operator = this._operator(inFunction);
+
//if there's an operator, keep building up the value parts
if (operator){
values.push(operator);
@@ -1662,7 +1665,7 @@ Parser.prototype = function(){
if (tokenStream.match(Tokens.FUNCTION)){
functionText = tokenStream.token().value;
this._readWhitespace();
- expr = this._expr();
+ expr = this._expr(true);
functionText += expr;
//START: Horrible hack in case it's an IE filter
View
6 src/css/ValidationTypes.js
@@ -121,7 +121,11 @@ var ValidationTypes = {
},
"<length>": function(part){
- return part.type == "length" || part.type == "number" || part.type == "integer" || part == "0";
+ if (part.type == "function" && /^(?:\-(?:ms|moz|o|webkit)\-)?calc/i.test(part)){
+ return true;
+ }else{
+ return part.type == "length" || part.type == "number" || part.type == "integer" || part == "0";
+ }
},
"<color>": function(part){
View
1  tests/css/CSSTokensTests.htm
@@ -420,6 +420,7 @@
//regular CSS functions
"rgb(255,0,1)" : [CSSTokens.FUNCTION, CSSTokens.NUMBER, CSSTokens.COMMA, CSSTokens.NUMBER, CSSTokens.COMMA, CSSTokens.NUMBER, CSSTokens.RPAREN],
"counter(par-num,upper-roman)" : [CSSTokens.FUNCTION, CSSTokens.IDENT, CSSTokens.COMMA, CSSTokens.IDENT, CSSTokens.RPAREN],
+ "calc(100% - 5px)" : [CSSTokens.FUNCTION, CSSTokens.PERCENTAGE, CSSTokens.S, CSSTokens.MINUS, CSSTokens.S, CSSTokens.LENGTH, CSSTokens.RPAREN],
//old-style IE filters - interpreted as bunch of tokens
"alpha(opacity=50)" : [CSSTokens.FUNCTION, CSSTokens.IDENT, CSSTokens.EQUALS, CSSTokens.NUMBER, CSSTokens.RPAREN],
View
1  tests/css/TokenStream.js
@@ -405,6 +405,7 @@
//regular CSS functions
"rgb(255,0,1)" : [CSSTokens.FUNCTION, CSSTokens.NUMBER, CSSTokens.COMMA, CSSTokens.NUMBER, CSSTokens.COMMA, CSSTokens.NUMBER, CSSTokens.RPAREN],
"counter(par-num,upper-roman)" : [CSSTokens.FUNCTION, CSSTokens.IDENT, CSSTokens.COMMA, CSSTokens.IDENT, CSSTokens.RPAREN],
+ "calc(100% - 5px)" : [CSSTokens.FUNCTION, CSSTokens.PERCENTAGE, CSSTokens.S, CSSTokens.MINUS, CSSTokens.S, CSSTokens.LENGTH, CSSTokens.RPAREN],
//old-style IE filters - interpreted as bunch of tokens
"alpha(opacity=50)" : [CSSTokens.FUNCTION, CSSTokens.IDENT, CSSTokens.EQUALS, CSSTokens.NUMBER, CSSTokens.RPAREN],
View
4 tests/css/Validation.js
@@ -492,6 +492,10 @@
valid: [
"1px",
"1%",
+ "calc(100% - 5px)",
+ "calc(100% + 1em)",
+ "calc(100%/6)",
+ "calc(10%*6)",
"inherit"
],

No commit comments for this range

Something went wrong with that request. Please try again.