Skip to content

Commit f4a7896

Browse files
authored
Fix nested funcs (#28)
* fixes #25: many nested functions * asserting issue and pr templates aren't optional
1 parent e099b24 commit f4a7896

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!--
2-
Please note: This template is not optional. Please fill in all fields and
3-
questions otherwise the issue may be closed. Please provide actual technical
4-
information about errors, if an error has occured.
2+
Please note: This template is *not* optional. Please fill in all fields and
3+
questions, otherwise *the issue may be closed*. Please provide actual technical
4+
information about errors, if an error has occurred.
55
-->
66

77
* Node Version:

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
<!-- This template is *not* optional. If you remove this template or choose
2+
not to complete it, your PR may be closed without review -->
3+
14
**Which issue #** if any, does this resolve?
25

36
<!-- PRs must be accompanied by related tests -->

lib/parser.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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-9a-f]{3}|[0-9a-f]{6})$/i.test(value);
454454
}
455+
else {
456+
this.cache.push(this.current);
457+
}
455458
}
456459

457460
this.newNode(node);

0 commit comments

Comments
 (0)