Skip to content

Commit

Permalink
initial refactoring of Any
Browse files Browse the repository at this point in the history
  • Loading branch information
lahmatiy committed Jan 30, 2017
1 parent 8be98de commit fd8d533
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
3 changes: 2 additions & 1 deletion lib/parser/nodes/Attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var RIGHTSQUAREBRACKET = TYPE.RightSquareBracket;
var CIRCUMFLEXACCENT = TYPE.CircumflexAccent;
var VERTICALLINE = TYPE.VerticalLine;
var TILDE = TYPE.Tilde;
var DISALLOW_VAR = false;

function getAttributeName() {
if (this.scanner.eof) {
Expand Down Expand Up @@ -106,7 +107,7 @@ module.exports = function Attribute() {

value = this.scanner.tokenType === STRING
? this.String()
: this.Identifier(false);
: this.Identifier(DISALLOW_VAR);

this.readSC();
}
Expand Down
3 changes: 2 additions & 1 deletion lib/parser/nodes/Brackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var WHITESPACE = TYPE.Whitespace;
var COMMENT = TYPE.Comment;
var LEFTSQUAREBRACKET = TYPE.LeftSquareBracket;
var RIGHTSQUAREBRACKET = TYPE.RightSquareBracket;
var DISALLOW_VAR = false;

// currently only Grid Layout uses square brackets
// https://drafts.csswg.org/css-grid/#track-sizing
Expand Down Expand Up @@ -35,7 +36,7 @@ module.exports = function Brackets() {
continue;

default:
child = this.Identifier(false);
child = this.Identifier(DISALLOW_VAR);
}

if (wasSpace) {
Expand Down
5 changes: 4 additions & 1 deletion lib/parser/nodes/Function.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ var RIGHTPARENTHESIS = TYPE.RightParenthesis;
var ASTERISK = TYPE.Asterisk;
var COMMA = TYPE.Comma;
var SOLIDUS = TYPE.Solidus;
var DISALLOW_VAR = false;

// ident '(' functionBody ')'
module.exports = function Function(scope, start, name) {
module.exports = function Function(scope) {
// parse special functions
var start = this.scanner.tokenStart;
var name = this.readIdent(DISALLOW_VAR);
var nameLowerCase = name.toLowerCase();

switch (scope) {
Expand Down
2 changes: 1 addition & 1 deletion lib/parser/nodes/Nth.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var DISALLOW_VAR = true;
var DISALLOW_VAR = false;

// https://drafts.csswg.org/css-syntax-3/#the-anb-type
module.exports = function Nth(allowOfClause) {
Expand Down
31 changes: 13 additions & 18 deletions lib/parser/nodes/_Any.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,27 @@ var PERCENTSIGN = TYPE.PercentSign;
var LEFTPARENTHESIS = TYPE.LeftParenthesis;
var PLUSSIGN = TYPE.PlusSign;
var HYPHENMINUS = TYPE.HyphenMinus;
var DISALLOW_VAR = false;

// any = percentage | dimension | number | operator | ident | function
module.exports = function Any(scope) {
switch (this.scanner.tokenType) {
case IDENTIFIER:
break;
if (this.scanner.lookupType(1) === LEFTPARENTHESIS) {
return this.Function(scope);
}

return this.Identifier(DISALLOW_VAR);

case HYPHENMINUS:
var nextType = this.scanner.lookupType(1);
if (nextType === IDENTIFIER || nextType === HYPHENMINUS) {
break;
if (this.scanner.lookupType(1) === IDENTIFIER) {
if (this.scanner.lookupType(2) === LEFTPARENTHESIS) {
return this.Function(scope);
}

return this.Identifier(DISALLOW_VAR);
}

return this.Operator();

case PLUSSIGN:
Expand All @@ -38,18 +47,4 @@ module.exports = function Any(scope) {
default:
this.scanner.error();
}

var start = this.scanner.tokenStart;

this.scanIdent(false);

if (this.scanner.tokenType === LEFTPARENTHESIS) {
return this.Function(scope, start, this.scanner.substrToCursor(start));
}

return {
type: 'Identifier',
loc: this.getLocation(start, this.scanner.tokenStart),
name: this.scanner.substrToCursor(start)
};
};

0 comments on commit fd8d533

Please sign in to comment.