Skip to content

Commit d8dac42

Browse files
committed
ignore --tw-{property} when {property} exists with the same value
This will help with `[font-weight:400]` to `font-normal`, even though `font-normal` is actually implemented as: ```css .font-normal { --tw-font-weight: 400; font-weight: 400; } ```
1 parent 222633c commit d8dac42

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

packages/tailwindcss/src/signatures.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,32 @@ function canonicalizeAst(ast: AstNode[], options: SignatureOptions) {
9999
let { rem, designSystem } = options
100100

101101
walk(ast, {
102-
enter(node) {
102+
enter(node, ctx) {
103103
// Optimize declarations
104104
if (node.kind === 'declaration') {
105105
if (node.value === undefined || node.property === '--tw-sort') {
106106
return WalkAction.Replace([])
107107
}
108108

109+
// Ignore `--tw-{property}` if `{property}` exists with the same value
110+
if (node.property.startsWith('--tw-')) {
111+
let siblings = ctx.parent?.nodes
112+
if (siblings) {
113+
let other = node.property.slice(5)
114+
if (
115+
siblings.some(
116+
(sibling) =>
117+
sibling.kind === 'declaration' &&
118+
sibling.property === other &&
119+
node.value === sibling.value &&
120+
node.important === sibling.important,
121+
)
122+
) {
123+
return WalkAction.Replace([])
124+
}
125+
}
126+
}
127+
109128
if (options.features & SignatureFeatures.ExpandProperties) {
110129
let replacement = expandDeclaration(node, options.features)
111130
if (replacement) return WalkAction.Replace(replacement)

0 commit comments

Comments
 (0)