Skip to content

Commit dd79be3

Browse files
thecrypticacetizu69RobinMalfait
authored
Don't show syntax error for *s inside --value and --modifier functions (#1215)
Fixes #1208 Needs infrastructure from #1216 and tests --------- Co-authored-by: tizu69 <[email protected]> Co-authored-by: Robin Malfait <[email protected]>
1 parent 26b004f commit dd79be3

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,13 @@ 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+
76+
// Replace `--some-var-*` with `--some-var-_`
77+
css = css.replace(/--([a-zA-Z0-9]+)-[*]/g, '--$1_')
78+
7179
return css
7280
}

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ defineTest({
218218
@import 'tailwindcss';
219219
@theme {
220220
--color-primary: #333;
221+
--leading-*: initial;
221222
}
222223
`,
223224
})
@@ -234,7 +235,7 @@ defineTest({
234235
uri: '{workspace:default}/file-1.css',
235236
range: {
236237
start: { line: 1, character: 0 },
237-
end: { line: 3, character: 1 },
238+
end: { line: 4, character: 1 },
238239
},
239240
},
240241
},
@@ -351,6 +352,31 @@ defineTest({
351352
},
352353
})
353354

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

packages/vscode-tailwindcss/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
- LSP: Declare capability for handling workspace folder change notifications ([#1223](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1223))
66
- Don't throw when resolving paths containing a `#` character ([#1225](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1225))
77
- Show `@theme` in symbol list in CSS language mode ([#1227](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1227))
8+
- Don't show syntax error when `*` appear inside `—value(…)` and `--modifier(…)` ([#1226](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1226))
9+
- Don't show syntax error for theme namespaces inside `@theme` ([#1226](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1226))
810

911
## 0.14.6
1012

0 commit comments

Comments
 (0)