Skip to content

Commit d27ea8b

Browse files
thecrypticacetizu69
andcommitted
Fix —value([*]) syntax error
Co-authored-by: tizu69 <[email protected]>
1 parent 1d1ca3d commit d27ea8b

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

packages/tailwindcss-language-server/src/language/rewriting.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,30 @@ test('@import', () => {
177177
expect(rewriteCss(input.join('\n'))).toBe(output.join('\n'))
178178
})
179179

180+
test('--value(namespace) / --modifier(namespace)', () => {
181+
let input = [
182+
//
183+
'.foo {',
184+
' color: --value(--color-*)',
185+
' background: --modifier(--color-*)',
186+
' z-index: --value([*])',
187+
' z-index: --modifier([*])',
188+
'}',
189+
]
190+
191+
let output = [
192+
//
193+
'.foo {',
194+
' color: --value(--color-_)',
195+
' background: --modifier(--color-_)',
196+
' z-index: --value([_])',
197+
' z-index: --modifier([_])',
198+
'}',
199+
]
200+
201+
expect(rewriteCss(input.join('\n'))).toBe(output.join('\n'))
202+
})
203+
180204
describe('v3', () => {
181205
test('@screen', () => {
182206
let input = [

packages/tailwindcss-language-server/src/language/rewriting.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,10 @@ export function rewriteCss(css: string) {
6868

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

71+
// Ignore `*` in in --value and --modifier functions
72+
css = css.replace(/--(value|modifier)\((.*?)\)/g, (match) => {
73+
return match.replace(/[*]/g, '_')
74+
})
75+
7176
return css
7277
}

packages/tailwindcss-language-server/tests/css/css-server.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,31 @@ defineTest({
351351
},
352352
})
353353

354+
defineTest({
355+
name: '--value(namespace) + --modifier(namespace)',
356+
prepare: async ({ root }) => ({
357+
client: await createClient({
358+
server: 'css',
359+
root,
360+
}),
361+
}),
362+
handle: async ({ client }) => {
363+
let doc = await client.open({
364+
lang: 'tailwindcss',
365+
name: 'file-1.css',
366+
text: css`
367+
.foo {
368+
width: --value(--spacing-*);
369+
height: --modifier(--spacing-*);
370+
height: --modifier([*]);
371+
}
372+
`,
373+
})
374+
375+
expect(await doc.diagnostics()).toEqual([])
376+
},
377+
})
378+
354379
// Legacy
355380
defineTest({
356381
name: '@screen',

0 commit comments

Comments
 (0)