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

Function parseImportParams

packages/tailwindcss/src/at-import.ts:87–148  ·  view source on GitHub ↗
(params: ValueParser.ValueAstNode[])

Source from the content-addressed store, hash-verified

85// Copyright (c) 2014 Maxime Thirouin, Jason Campbell & Kevin Mårtensson
86// Released under the MIT License.
87export function parseImportParams(params: ValueParser.ValueAstNode[]) {
88 let uri
89 let layer: string | null = null
90 let media: string | null = null
91 let supports: string | null = null
92
93 for (let i = 0; i < params.length; i++) {
94 let node = params[i]
95
96 if (node.kind === 'separator') continue
97
98 if (node.kind === 'word' && !uri) {
99 if (!node.value) return null
100 if (node.value[0] !== '"' && node.value[0] !== "'") return null
101
102 uri = node.value.slice(1, -1)
103 continue
104 }
105
106 if (node.kind === 'function' && node.value.toLowerCase() === 'url') {
107 // `@import` with `url(…)` functions are not inlined but skipped and kept
108 // in the final CSS instead.
109 // E.g.: `@import url("https://fonts.google.com")`
110 return null
111 }
112
113 if (!uri) return null
114
115 if (
116 (node.kind === 'word' || node.kind === 'function') &&
117 node.value.toLowerCase() === 'layer'
118 ) {
119 if (layer) return null
120 if (supports) {
121 throw new Error(
122 '`layer(…)` in an `@import` should come before any other functions or conditions',
123 )
124 }
125
126 if ('nodes' in node) {
127 layer = ValueParser.toCss(node.nodes)
128 } else {
129 layer = ''
130 }
131
132 continue
133 }
134
135 if (node.kind === 'function' && node.value.toLowerCase() === 'supports') {
136 if (supports) return null
137 supports = ValueParser.toCss(node.nodes)
138 continue
139 }
140
141 media = ValueParser.toCss(params.slice(i))
142 break
143 }
144

Callers 2

migrateFunction · 0.90
substituteAtImportsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected