Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
80a90e0
hoist regex
RobinMalfait Sep 26, 2025
33dd0f8
remove async
RobinMalfait Sep 30, 2025
a62d857
tmp: annotate migrations
RobinMalfait Sep 30, 2025
c82bc30
move `printCandidate` normalization tests to core
RobinMalfait Sep 30, 2025
8c6fe35
expose `canonicalizeCandidates` on the design system
RobinMalfait Sep 26, 2025
5d6ea74
canonicalize candidates at the end of upgrading your project
RobinMalfait Sep 30, 2025
44352e8
move `migrate-bg-gradient` to core
RobinMalfait Sep 30, 2025
afa3216
move `migrate-theme-to-var` to core
RobinMalfait Sep 30, 2025
852e288
cache the converter
RobinMalfait Sep 30, 2025
4c722c0
only prefix variable that are not in `--theme(…)`
RobinMalfait Sep 30, 2025
4bf93bf
move types to core
RobinMalfait Sep 30, 2025
5de55bd
move dimensions to core
RobinMalfait Sep 30, 2025
2c9a2c7
move signatures to core
RobinMalfait Sep 30, 2025
34cb8b8
ensure `canonicalizeCandidates` returns a unique list
RobinMalfait Sep 30, 2025
0c3d48e
move `migrate-arbitrary-utilities` to core
RobinMalfait Sep 30, 2025
f088459
move `migrate-bare-utilities` to core
RobinMalfait Sep 30, 2025
ae5909c
move `migrate-deprecated-utilities` to core
RobinMalfait Sep 30, 2025
e5352d3
move `replaceObject` to core
RobinMalfait Sep 30, 2025
2863c60
move `migrate-arbitrary-variants` to core
RobinMalfait Sep 30, 2025
0eaf373
move `migrate-drop-unnecessary-data-types` to core
RobinMalfait Sep 30, 2025
683ffc5
move `migrate-arbitrary-value-to-bare-value` to core
RobinMalfait Sep 30, 2025
1c02690
move `migrate-optimize-modifier` to core
RobinMalfait Sep 30, 2025
760aef8
remove `!` from test case
RobinMalfait Oct 2, 2025
d5ba933
handle `&` and `*` in selector parser as standalone selector
RobinMalfait Oct 3, 2025
80029cd
move parts of `migrate-modernize-arbitrary-values` to core
RobinMalfait Oct 3, 2025
02ba94f
ensure we canonicalize at the end
RobinMalfait Oct 3, 2025
c956b08
big refactor
RobinMalfait Oct 3, 2025
c281426
drop unnecessary calls
RobinMalfait Oct 4, 2025
368eb80
only stringify the value when something changed
RobinMalfait Oct 4, 2025
55cbbaf
remove migration annotations
RobinMalfait Oct 4, 2025
e7ce1ad
move `selector-parser` from `./src/compat` to just `./src`
RobinMalfait Oct 5, 2025
705476c
add attribute selector parser
RobinMalfait Oct 5, 2025
226ae47
use dedicated `AttributeSelectorParser`
RobinMalfait Oct 5, 2025
4441c44
remove intellisense features from `@tailwindcss/browser`
RobinMalfait Oct 6, 2025
5b7fa87
immediately return replacement candidates
RobinMalfait Oct 6, 2025
93b97b1
remove `@property` when computing a signature
RobinMalfait Oct 6, 2025
ce08cba
add note when parsing the attribute selector as a whole
RobinMalfait Oct 7, 2025
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
move migrate-drop-unnecessary-data-types to core
  • Loading branch information
RobinMalfait committed Oct 6, 2025
commit 0eaf373fa109368c62d9e2cd50da7e515556a59b

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { migrateArbitraryValueToBareValue } from './migrate-arbitrary-value-to-b
import { migrateAutomaticVarInjection } from './migrate-automatic-var-injection'
import { migrateCamelcaseInNamedValue } from './migrate-camelcase-in-named-value'
import { migrateCanonicalizeCandidate } from './migrate-canonicalize-candidate'
import { migrateDropUnnecessaryDataTypes } from './migrate-drop-unnecessary-data-types'
import { migrateEmptyArbitraryValues } from './migrate-handle-empty-arbitrary-values'
import { migrateLegacyArbitraryValues } from './migrate-legacy-arbitrary-values'
import { migrateLegacyClasses } from './migrate-legacy-classes'
Expand Down Expand Up @@ -40,7 +39,6 @@ export const DEFAULT_MIGRATIONS: Migration[] = [
migrateAutomaticVarInjection, // sync, v3 → v4
migrateLegacyArbitraryValues, // sync, v3 → v4 (could also consider it a v4 optimization)
migrateModernizeArbitraryValues, // sync, v3 and v4 optimizations, split up?
migrateDropUnnecessaryDataTypes, // sync, v4 (I think this can be dropped?)
migrateArbitraryValueToBareValue, // sync, v4 (optimization)
migrateOptimizeModifier, // sync, v4 (optimization)
]
Expand Down
23 changes: 23 additions & 0 deletions packages/tailwindcss/src/canonicalize-candidates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,29 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s',
await expectCanonicalization(input, candidate, expected)
})
})

describe('drop unnecessary data types', () => {
let input = css`
@import 'tailwindcss';
@theme {
--*: initial;
--color-red-500: red;
}
`

test.each([
// A color value can be inferred from the value
['bg-[color:#008cc]', 'bg-[#008cc]'],

// A color is the default for `bg-*`
['bg-(color:--my-value)', 'bg-(--my-value)'],

// A color with a known theme variable migrates to the full utility
['bg-(color:--color-red-500)', 'bg-red-500'],
])(testName, async (candidate, expected) => {
await expectCanonicalization(input, candidate, expected)
})
})
})

describe('theme to var', () => {
Expand Down
26 changes: 26 additions & 0 deletions packages/tailwindcss/src/canonicalize-candidates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const CANONICALIZATIONS = [
bareValueUtilities,
deprecatedUtilities,
arbitraryVariants,
dropUnnecessaryDataTypes,
print,
]

Expand Down Expand Up @@ -909,3 +910,28 @@ function arbitraryVariants(designSystem: DesignSystem, rawCandidate: string): st

return rawCandidate
}

// ----

function dropUnnecessaryDataTypes(designSystem: DesignSystem, rawCandidate: string): string {
let signatures = computeUtilitySignature.get(designSystem)

for (let candidate of designSystem.parseCandidate(rawCandidate)) {
if (
candidate.kind === 'functional' &&
candidate.value?.kind === 'arbitrary' &&
candidate.value.dataType !== null
) {
let replacement = designSystem.printCandidate({
...candidate,
value: { ...candidate.value, dataType: null },
})

if (signatures.get(rawCandidate) === signatures.get(replacement)) {
return replacement
}
}
}

return rawCandidate
}