Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!--
Please note: This template is not optional. Please fill in all fields and
questions otherwise the issue may be closed. Please provide actual technical
information about errors, if an error has occured.
Please note: This template is *not* optional. Please fill in all fields and
questions, otherwise *the issue may be closed*. Please provide actual technical
information about errors, if an error has occurred.
-->

* Node Version:
Expand Down
3 changes: 3 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<!-- This template is *not* optional. If you remove this template or choose
not to complete it, your PR may be closed without review -->

**Which issue #** if any, does this resolve?

<!-- PRs must be accompanied by related tests -->
Expand Down
13 changes: 8 additions & 5 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ module.exports = class Parser {
constructor (input, options) {
const defaults = { loose: false };

// cache needs to be an array for values with more than 1 level of function nesting
this.cache = [];
this.input = input;
this.options = Object.assign({}, defaults, options);
this.position = 0;
Expand Down Expand Up @@ -266,7 +268,6 @@ module.exports = class Parser {

if (last && last.type === 'func' && last.unbalanced < 0) {
last.unbalanced = 0; // ok we're ready to add parens now
this.cache = this.current;
this.current = last;
}

Expand Down Expand Up @@ -345,7 +346,7 @@ module.exports = class Parser {

this.position ++;

if (this.position >= this.tokens.length - 1) {
if (this.position >= this.tokens.length - 1 && !this.current.unbalanced) {
return;
}

Expand All @@ -355,9 +356,8 @@ module.exports = class Parser {
this.error('Expected opening parenthesis', token);
}

if (!this.current.unbalanced && this.cache) {
this.current = this.cache;
this.cache = null;
if (!this.current.unbalanced && this.cache.length) {
this.current = this.cache.pop();
}
}

Expand Down Expand Up @@ -452,6 +452,9 @@ module.exports = class Parser {
node.isHex = /^#/.test(value);
node.isColor = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(value);
}
else {
this.cache.push(this.current);
}
}

this.newNode(node);
Expand Down