Skip to content

Commit ea9d700

Browse files
Optimize AST before printing for IntelliSense (#15347)
We changed how AST printing worked recently but forgot to update this. Which causes us to print properties with a value of `undefined` in Tailwind Play, Tailwind CSS IntelliSense, and our Language Server (oops). This PR fixes this by optimizing the AST before printing (which is what toCss did previously)
1 parent d0b0375 commit ea9d700

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
- Fix dependency related warnings when using `@tailwindcss/postcss` on Windows ([#15321](https://github.com/tailwindlabs/tailwindcss/pull/15321))
1717
- Skip creating a compiler for CSS files that should not be processed ([#15340](https://github.com/tailwindlabs/tailwindcss/pull/15340))
1818
- Fix missing `shadow-none` suggestion in IntelliSense ([#15342](https://github.com/tailwindlabs/tailwindcss/pull/15342))
19+
- Optimize AST before printing for IntelliSense ([#15347](https://github.com/tailwindlabs/tailwindcss/pull/15347))
1920

2021
## [4.0.0-beta.6] - 2024-12-06
2122

packages/tailwindcss/src/design-system.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { toCss } from './ast'
1+
import { optimizeAst, toCss } from './ast'
22
import { parseCandidate, parseVariant, type Candidate, type Variant } from './candidate'
33
import { compileAstNodes, compileCandidates } from './compile'
44
import { getClassList, getVariants, type ClassEntry, type VariantEntry } from './intellisense'
@@ -60,11 +60,13 @@ export function buildDesignSystem(theme: Theme): DesignSystem {
6060
let wasInvalid = false
6161

6262
let { astNodes } = compileCandidates([className], this, {
63-
onInvalidCandidate(candidate) {
63+
onInvalidCandidate() {
6464
wasInvalid = true
6565
},
6666
})
6767

68+
astNodes = optimizeAst(astNodes)
69+
6870
if (astNodes.length === 0 || wasInvalid) {
6971
result.push(null)
7072
} else {

packages/tailwindcss/src/intellisense.test.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,21 +118,26 @@ test('Can produce CSS per candidate using `candidatesToCss`', () => {
118118
let design = loadDesignSystem()
119119
design.invalidCandidates = new Set(['bg-[#fff]'])
120120

121-
expect(design.candidatesToCss(['underline', 'i-dont-exist', 'bg-[#fff]', 'bg-[#000]']))
121+
expect(design.candidatesToCss(['underline', 'i-dont-exist', 'bg-[#fff]', 'bg-[#000]', 'text-xs']))
122122
.toMatchInlineSnapshot(`
123-
[
124-
".underline {
125-
text-decoration-line: underline;
126-
}
127-
",
128-
null,
129-
null,
130-
".bg-\\[\\#000\\] {
131-
background-color: #000;
132-
}
133-
",
134-
]
135-
`)
123+
[
124+
".underline {
125+
text-decoration-line: underline;
126+
}
127+
",
128+
null,
129+
null,
130+
".bg-\\[\\#000\\] {
131+
background-color: #000;
132+
}
133+
",
134+
".text-xs {
135+
font-size: var(--text-xs);
136+
line-height: var(--tw-leading, var(--text-xs--line-height));
137+
}
138+
",
139+
]
140+
`)
136141
})
137142

138143
test('Utilities do not show wrapping selector in intellisense', async () => {

0 commit comments

Comments
 (0)