@@ -29,6 +29,8 @@ module.exports = class Parser {
2929 constructor ( input , options ) {
3030 const defaults = { loose : false } ;
3131
32+ // cache needs to be an array for values with more than 1 level of function nesting
33+ this . cache = [ ] ;
3234 this . input = input ;
3335 this . options = Object . assign ( { } , defaults , options ) ;
3436 this . position = 0 ;
@@ -266,7 +268,6 @@ module.exports = class Parser {
266268
267269 if ( last && last . type === 'func' && last . unbalanced < 0 ) {
268270 last . unbalanced = 0 ; // ok we're ready to add parens now
269- this . cache = this . current ;
270271 this . current = last ;
271272 }
272273
@@ -345,7 +346,7 @@ module.exports = class Parser {
345346
346347 this . position ++ ;
347348
348- if ( this . position >= this . tokens . length - 1 ) {
349+ if ( this . position >= this . tokens . length - 1 && ! this . current . unbalanced ) {
349350 return ;
350351 }
351352
@@ -355,9 +356,8 @@ module.exports = class Parser {
355356 this . error ( 'Expected opening parenthesis' , token ) ;
356357 }
357358
358- if ( ! this . current . unbalanced && this . cache ) {
359- this . current = this . cache ;
360- this . cache = null ;
359+ if ( ! this . current . unbalanced && this . cache . length ) {
360+ this . current = this . cache . pop ( ) ;
361361 }
362362 }
363363
@@ -452,6 +452,9 @@ module.exports = class Parser {
452452 node . isHex = / ^ # / . test ( value ) ;
453453 node . isColor = / ^ # ( [ 0 - 9 a - f ] { 3 } | [ 0 - 9 a - f ] { 6 } ) $ / i. test ( value ) ;
454454 }
455+ else {
456+ this . cache . push ( this . current ) ;
457+ }
455458 }
456459
457460 this . newNode ( node ) ;
0 commit comments