Skip to content

Commit

Permalink
ignore all errors
Browse files Browse the repository at this point in the history
If any of the errors occur, we can bail and keep the `@import` in the
final CSS.

If something went wrong, the browser will let you know that something is
missing.
  • Loading branch information
RobinMalfait committed Nov 22, 2024
1 parent 672f7cb commit 9855d12
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/tailwindcss/src/at-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export function parseImportParams(params: ValueParser.ValueAstNode[]) {
if (node.kind === 'separator') continue

if (node.kind === 'word' && !uri) {
if (!node.value) throw new Error(`Unable to find uri`)
if (node.value[0] !== '"' && node.value[0] !== "'") throw new Error('Unable to find uri')
if (!node.value) return null
if (node.value[0] !== '"' && node.value[0] !== "'") return null

uri = node.value.slice(1, -1)
continue
Expand All @@ -91,17 +91,18 @@ export function parseImportParams(params: ValueParser.ValueAstNode[]) {
return null
}

if (!uri) throw new Error('Unable to find uri')
if (!uri) return null

if (
(node.kind === 'word' || node.kind === 'function') &&
node.value.toLowerCase() === 'layer'
) {
if (layer) throw new Error('Multiple layers')
if (supports)
if (layer) return null
if (supports) {
throw new Error(
'`layer(…)` in an `@import` should come before any other functions or conditions',
)
}

if ('nodes' in node) {
layer = ValueParser.toCss(node.nodes)
Expand All @@ -113,7 +114,7 @@ export function parseImportParams(params: ValueParser.ValueAstNode[]) {
}

if (node.kind === 'function' && node.value.toLowerCase() === 'supports') {
if (supports) throw new Error('Multiple support conditions')
if (supports) return null
supports = ValueParser.toCss(node.nodes)
continue
}
Expand All @@ -122,7 +123,7 @@ export function parseImportParams(params: ValueParser.ValueAstNode[]) {
break
}

if (!uri) throw new Error('Unable to find uri')
if (!uri) return null

return { uri, layer, media, supports }
}
Expand Down

0 comments on commit 9855d12

Please sign in to comment.