Skip to content

Don't show syntax error for *s inside --value and --modifier functions #1215

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

Merged
merged 4 commits into from
Feb 21, 2025
Merged
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
Next Next commit
Fix —value([*]) syntax error
Co-authored-by: tizu69 <60812901+tizu69@users.noreply.github.com>
  • Loading branch information
thecrypticace and tizu69 committed Feb 21, 2025
commit 2e0fdcdcb8b39ba500b8dbc75f18b2316f693c33
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,30 @@ test('@import', () => {
expect(rewriteCss(input.join('\n'))).toBe(output.join('\n'))
})

test('--value(namespace) / --modifier(namespace)', () => {
let input = [
//
'.foo {',
' color: --value(--color-*)',
' background: --modifier(--color-*)',
' z-index: --value([*])',
' z-index: --modifier([*])',
'}',
]

let output = [
//
'.foo {',
' color: --value(--color-_)',
' background: --modifier(--color-_)',
' z-index: --value([_])',
' z-index: --modifier([_])',
'}',
]

expect(rewriteCss(input.join('\n'))).toBe(output.join('\n'))
})

describe('v3', () => {
test('@screen', () => {
let input = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,10 @@ export function rewriteCss(css: string) {

css = css.replace(/(?<=\b(?:theme|config)\([^)]*)[.[\]]/g, '_')

// Ignore `*` in in --value and --modifier functions
css = css.replace(/--(value|modifier)\((.*?)\)/g, (match) => {
return match.replace(/[*]/g, '_')
})

return css
}
25 changes: 25 additions & 0 deletions packages/tailwindcss-language-server/tests/css/css-server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,31 @@ defineTest({
},
})

defineTest({
name: '--value(namespace) + --modifier(namespace)',
prepare: async ({ root }) => ({
client: await createClient({
server: 'css',
root,
}),
}),
handle: async ({ client }) => {
let doc = await client.open({
lang: 'tailwindcss',
name: 'file-1.css',
text: css`
.foo {
width: --value(--spacing-*);
height: --modifier(--spacing-*);
height: --modifier([*]);
}
`,
})

expect(await doc.diagnostics()).toEqual([])
},
})

// Legacy
defineTest({
name: '@screen',
Expand Down