MCPcopy
hub / github.com/tailwindlabs/tailwindcss / parseAtRule

Function parseAtRule

packages/tailwindcss/src/css-parser.ts:596–627  ·  view source on GitHub ↗
(buffer: string, nodes: AstNode[] = [])

Source from the content-addressed store, hash-verified

594}
595
596export function parseAtRule(buffer: string, nodes: AstNode[] = []): AtRule {
597 let name = buffer
598 let params = ''
599
600 // Assumption: The smallest at-rule in CSS right now is `@page`, this means
601 // that we can always skip the first 5 characters and start at the
602 // sixth (at index 5).
603 //
604 // There is a chance someone is using a shorter at-rule, in that case we have
605 // to adjust this number back to 2, e.g.: `@x`.
606 //
607 // This issue can only occur if somebody does the following things:
608 //
609 // 1. Uses a shorter at-rule than `@page`
610 // 2. Disables Lightning CSS from `@tailwindcss/postcss` (because Lightning
611 // CSS doesn't handle custom at-rules properly right now)
612 // 3. Sandwiches the `@tailwindcss/postcss` plugin between two other plugins
613 // that can handle the shorter at-rule
614 //
615 // Let's use the more common case as the default and we can adjust this
616 // behavior if necessary.
617 for (let i = 5 /* '@page'.length */; i < buffer.length; i++) {
618 let currentChar = buffer.charCodeAt(i)
619 if (currentChar === SPACE || currentChar === TAB || currentChar === OPEN_PAREN) {
620 name = buffer.slice(0, i)
621 params = buffer.slice(i)
622 break
623 }
624 }
625
626 return atRule(name.trim(), params.trim(), nodes)
627}
628
629function parseDeclaration(
630 buffer: string,

Callers 2

ruleFunction · 0.90
parseFunction · 0.85

Calls 1

atRuleFunction · 0.90

Tested by

no test coverage detected