Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/tailwindcss/src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,18 @@ export function optimizeAst(

if (nodes.length === 0) return



if (
nodes.length === 1 &&
nodes[0].kind === 'at-rule' &&
(nodes[0].name === '@media' || nodes[0].name === '@supports' || nodes[0].name === '@container' || nodes[0].name === '@scope')
) {
let at = nodes[0]
parent.push(atRule(at.name, at.params, [styleRule(node.selector, at.nodes)]))
return
}

// Rules with `&` as the selector should be flattened
if (node.selector === '&') {
parent.push(...nodes)
Expand Down
42 changes: 42 additions & 0 deletions packages/tailwindcss/src/variants.scope.test.ts
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// 👇 Move your debug log here
console.log('\n\n=== GENERATED CSS ===\n', result, '\n====================\n\n')
🤖 Prompt for AI Agents
In packages/tailwindcss/src/variants.scope.test.ts around lines 34 to 35, there
is a debug console.log that prints generated CSS and creates noisy test output;
remove the console.log statement (and any surrounding leftover blank lines it
introduced) so tests no longer emit the debug output, keeping the rest of the
test intact.


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'))

})