Skip to content

Commit f7ddae9

Browse files
committed
Fix bracket parser
1 parent 10ea5e7 commit f7ddae9

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

lib/brackets.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@ let brackets = {
1919
}
2020

2121
if (sym === ')') {
22-
stack.pop()
23-
current = last(stack)
24-
current.push('')
22+
if (stack.length > 1) {
23+
stack.pop()
24+
current = last(stack)
25+
current.push('')
26+
} else {
27+
current[current.length - 1] += sym
28+
}
2529
continue
2630
}
2731

test/brackets.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ test('parses errors', () => {
1919
equal(brackets.parse('a (b ('), ['a ', ['b ', ['']]])
2020
})
2121

22+
test('parses unmatched closing bracket', () => {
23+
equal(brackets.parse('@supports ) {}'), ['@supports ) {}'])
24+
equal(brackets.parse('@supports (display:flex)) {}'), [
25+
'@supports ',
26+
['display:flex'],
27+
') {}'
28+
])
29+
equal(brackets.parse('@supports not (a:b)) {}'), [
30+
'@supports not ',
31+
['a:b'],
32+
') {}'
33+
])
34+
})
35+
2236
test('stringifies simple string', () => {
2337
equal(brackets.stringify(['test']), 'test')
2438
})

0 commit comments

Comments
 (0)