Skip to content
Merged
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
Prev Previous commit
Next Next commit
swap constant folding in the signature with new logic
  • Loading branch information
RobinMalfait committed Oct 9, 2025
commit 895c5af725157252e5db59199bc4b6546d8b8889
36 changes: 2 additions & 34 deletions packages/tailwindcss/src/signatures.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { substituteAtApply } from './apply'
import { atRule, styleRule, toCss, walk, type AstNode } from './ast'
import { printArbitraryValue } from './candidate'
import { constantFoldDeclaration } from './constant-fold-declaration'
import { CompileAstFlags, type DesignSystem } from './design-system'
import * as SelectorParser from './selector-parser'
import { ThemeOptions } from './theme'
import { DefaultMap } from './utils/default-map'
import { dimensions } from './utils/dimensions'
import { isValidSpacingMultiplier } from './utils/infer-data-type'
import * as ValueParser from './value-parser'

Expand Down Expand Up @@ -208,39 +208,7 @@ export const computeUtilitySignature = new DefaultMap<
// → `calc(0.25rem * 4)` ← this is the case we will see
// after inlining the variable
// → `1rem`
if (node.value.includes('calc')) {
let folded = false
let valueAst = ValueParser.parse(node.value)
ValueParser.walk(valueAst, (valueNode, { replaceWith }) => {
if (valueNode.kind !== 'function') return
if (valueNode.value !== 'calc') return

// [
// { kind: 'word', value: '0.25rem' }, 0
// { kind: 'separator', value: ' ' }, 1
// { kind: 'word', value: '*' }, 2
// { kind: 'separator', value: ' ' }, 3
// { kind: 'word', value: '256' } 4
// ]
if (valueNode.nodes.length !== 5) return
if (valueNode.nodes[2].kind !== 'word' && valueNode.nodes[2].value !== '*') return

let parsed = dimensions.get(valueNode.nodes[0].value)
if (parsed === null) return

let [value, unit] = parsed

let multiplier = Number(valueNode.nodes[4].value)
if (Number.isNaN(multiplier)) return

folded = true
replaceWith(ValueParser.parse(`${value * multiplier}${unit}`))
})

if (folded) {
node.value = ValueParser.toCss(valueAst)
}
}
node.value = constantFoldDeclaration(node.value)

// We will normalize the `node.value`, this is the same kind of logic
// we use when printing arbitrary values. It will remove unnecessary
Expand Down