Skip to content

Commit

Permalink
update error message
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinMalfait committed Mar 7, 2024
1 parent 37d1198 commit 090727e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
13 changes: 6 additions & 7 deletions packages/tailwindcss/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,14 @@ describe('compiling CSS', () => {
['bg-primary'],
),
).toThrowErrorMatchingInlineSnapshot(`
[Error: Invalid \`@theme\` detected:
[Error: \`@theme\` blocks must only contain custom properties or \`@keyframes\`.
@theme {
/* Only CSS variables are allowed, this is not allowed: */
.foo {
--color-primary: blue;
@theme {
> .foo {
> --color-primary: blue;
> }
}
}
]
]
`)
})

Expand Down
13 changes: 8 additions & 5 deletions packages/tailwindcss/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@ export function compile(css: string, rawCandidates: string[]) {
return
}

let tree = rule('@theme', [
comment(' Only CSS variables are allowed, this is not allowed: '),
node,
])
throw new Error(`Invalid \`@theme\` detected:\n\n${toCss([tree])}`)
let snippet = toCss([rule('@theme', [node])])
.split('\n')
.map((line, idx, all) => `${idx === 0 || idx >= all.length - 2 ? ' ' : '>'} ${line}`)
.join('\n')

throw new Error(
`\`@theme\` blocks must only contain custom properties or \`@keyframes\`.\n\n${snippet}`,
)
})

// Keep a reference to the first `@theme` rule to update with the full theme
Expand Down

0 comments on commit 090727e

Please sign in to comment.