-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Fix @scope variant output and add test for scoped variant #19299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,42 @@ | ||||||
| import { test, expect } from 'vitest' | ||||||
| import { compile } from '.' | ||||||
| import type { PluginAPI } from './compat/plugin-api' | ||||||
|
|
||||||
| const css = String.raw | ||||||
|
|
||||||
| test('custom variants using @scope should wrap correctly', async () => { | ||||||
| let compiler = await compile( | ||||||
| css` | ||||||
| @theme { | ||||||
| --color-red-500: #ef4444; | ||||||
| } | ||||||
| @tailwind utilities; | ||||||
| @plugin 'my-plugin'; | ||||||
| `, | ||||||
| { | ||||||
| loadModule: async (id) => { | ||||||
| if (id === 'my-plugin') { | ||||||
| return { | ||||||
| path: '', | ||||||
| base: '', | ||||||
| module: ({ addVariant }: PluginAPI) => { | ||||||
| addVariant('scoped', '@scope (.theme) { & }') | ||||||
| }, | ||||||
| } | ||||||
| } | ||||||
| return { path: '', base: '', module: () => {} } | ||||||
| }, | ||||||
| }, | ||||||
| ) | ||||||
|
|
||||||
| let result = compiler.build(['scoped:bg-red-500']) | ||||||
|
|
||||||
| // 👇 Move your debug log here | ||||||
| console.log('\n\n=== GENERATED CSS ===\n', result, '\n====================\n\n') | ||||||
|
Comment on lines
+34
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove debug console.log. The console.log statement on line 35 creates noisy test output and should be removed before merging. Apply this diff: - // 👇 Move your debug log here
- console.log('\n\n=== GENERATED CSS ===\n', result, '\n====================\n\n')
-📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
|
|
||||||
| expect(result).toContain('@scope (.theme)') | ||||||
| expect(result).toContain('.scoped\\:bg-red-500') | ||||||
| // The @scope at-rule should wrap the selector: @scope { .selector { ... } } | ||||||
| expect(result.indexOf('@scope')).toBeLessThan(result.indexOf('.scoped\\:bg-red-500')) | ||||||
|
|
||||||
| }) | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don’t gate the at-rule collapse on
isBlock.isBlockonly returns true when the raw variant string literally ends with}. As soon as someone writes a scoped variant with a trailing comment or other postfix (e.g.addVariant('scoped', '@scope (&) { @slot } /* note */')), the condition fails, we skip thebody[0]return, and the compiler falls back to emitting.selector { @scope … }—the exact invalid structure this PR is meant to fix. Please decide purely from the parsed AST (e.g.if (body.length === 1 && body[0].kind === 'at-rule')) so single at-rule variants are collapsed regardless of formatting. This keeps the fix from regressing in common “annotated” plugin variants.🤖 Prompt for AI Agents