Skip to content

Commit 9177c68

Browse files
committed
use existing closingBracketStack
We still apply the same rules where we don't really care about special characters such as `{`, `}` or `;` when we are inside of `(` and `)`. We can safely look at the last character in the `closingBracketStack` because when we are in parentheses, we don't update the `closingBracketStack` until we see a closing `)`.
1 parent 809ddad commit 9177c68

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

packages/tailwindcss/src/css-parser.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ export function parse(input: string) {
4242

4343
let buffer = ''
4444
let closingBracketStack = ''
45-
let parenStack = 0
4645

4746
let peekChar
4847

@@ -332,7 +331,10 @@ export function parse(input: string) {
332331
// }
333332
// ```
334333
//
335-
else if (currentChar === SEMICOLON && parenStack <= 0) {
334+
else if (
335+
currentChar === SEMICOLON &&
336+
closingBracketStack[closingBracketStack.length - 1] !== ')'
337+
) {
336338
let declaration = parseDeclaration(buffer)
337339
if (parent) {
338340
parent.nodes.push(declaration)
@@ -344,7 +346,10 @@ export function parse(input: string) {
344346
}
345347

346348
// Start of a block.
347-
else if (currentChar === OPEN_CURLY && parenStack <= 0) {
349+
else if (
350+
currentChar === OPEN_CURLY &&
351+
closingBracketStack[closingBracketStack.length - 1] !== ')'
352+
) {
348353
closingBracketStack += '}'
349354

350355
// At this point `buffer` should resemble a selector or an at-rule.
@@ -369,7 +374,10 @@ export function parse(input: string) {
369374
}
370375

371376
// End of a block.
372-
else if (currentChar === CLOSE_CURLY && parenStack <= 0) {
377+
else if (
378+
currentChar === CLOSE_CURLY &&
379+
closingBracketStack[closingBracketStack.length - 1] !== ')'
380+
) {
373381
if (closingBracketStack === '') {
374382
throw new Error('Missing opening {')
375383
}
@@ -459,17 +467,17 @@ export function parse(input: string) {
459467

460468
// `(`
461469
else if (currentChar === OPEN_PAREN) {
462-
parenStack += 1
470+
closingBracketStack += ')'
463471
buffer += '('
464472
}
465473

466474
// `)`
467475
else if (currentChar === CLOSE_PAREN) {
468-
if (parenStack <= 0) {
476+
if (closingBracketStack[closingBracketStack.length - 1] !== ')') {
469477
throw new Error('Missing opening (')
470478
}
471479

472-
parenStack -= 1
480+
closingBracketStack = closingBracketStack.slice(0, -1)
473481
buffer += ')'
474482
}
475483

0 commit comments

Comments
 (0)