Skip to content

Commit 848dec8

Browse files
committed
move migrate-drop-unnecessary-data-types to core
1 parent c9c042f commit 848dec8

File tree

5 files changed

+49
-95
lines changed

5 files changed

+49
-95
lines changed

packages/@tailwindcss-upgrade/src/codemods/template/migrate-drop-unnecessary-data-types.test.ts

Lines changed: 0 additions & 63 deletions
This file was deleted.

packages/@tailwindcss-upgrade/src/codemods/template/migrate-drop-unnecessary-data-types.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.

packages/@tailwindcss-upgrade/src/codemods/template/migrate.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { migrateArbitraryValueToBareValue } from './migrate-arbitrary-value-to-b
1111
import { migrateAutomaticVarInjection } from './migrate-automatic-var-injection'
1212
import { migrateCamelcaseInNamedValue } from './migrate-camelcase-in-named-value'
1313
import { migrateCanonicalizeCandidate } from './migrate-canonicalize-candidate'
14-
import { migrateDropUnnecessaryDataTypes } from './migrate-drop-unnecessary-data-types'
1514
import { migrateEmptyArbitraryValues } from './migrate-handle-empty-arbitrary-values'
1615
import { migrateLegacyArbitraryValues } from './migrate-legacy-arbitrary-values'
1716
import { migrateLegacyClasses } from './migrate-legacy-classes'
@@ -40,7 +39,6 @@ export const DEFAULT_MIGRATIONS: Migration[] = [
4039
migrateAutomaticVarInjection, // sync, v3 → v4
4140
migrateLegacyArbitraryValues, // sync, v3 → v4 (could also consider it a v4 optimization)
4241
migrateModernizeArbitraryValues, // sync, v3 and v4 optimizations, split up?
43-
migrateDropUnnecessaryDataTypes, // sync, v4 (I think this can be dropped?)
4442
migrateArbitraryValueToBareValue, // sync, v4 (optimization)
4543
migrateOptimizeModifier, // sync, v4 (optimization)
4644
]

packages/tailwindcss/src/canonicalize-candidates.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,29 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s',
637637
await expectCanonicalization(input, candidate, expected)
638638
})
639639
})
640+
641+
describe('drop unnecessary data types', () => {
642+
let input = css`
643+
@import 'tailwindcss';
644+
@theme {
645+
--*: initial;
646+
--color-red-500: red;
647+
}
648+
`
649+
650+
test.each([
651+
// A color value can be inferred from the value
652+
['bg-[color:#008cc]', 'bg-[#008cc]'],
653+
654+
// A color is the default for `bg-*`
655+
['bg-(color:--my-value)', 'bg-(--my-value)'],
656+
657+
// A color with a known theme variable migrates to the full utility
658+
['bg-(color:--color-red-500)', 'bg-red-500'],
659+
])(testName, async (candidate, expected) => {
660+
await expectCanonicalization(input, candidate, expected)
661+
})
662+
})
640663
})
641664

642665
describe('theme to var', () => {

packages/tailwindcss/src/canonicalize-candidates.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const CANONICALIZATIONS = [
4444
bareValueUtilities,
4545
deprecatedUtilities,
4646
arbitraryVariants,
47+
dropUnnecessaryDataTypes,
4748
print,
4849
]
4950

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

910911
return rawCandidate
911912
}
913+
914+
// ----
915+
916+
function dropUnnecessaryDataTypes(designSystem: DesignSystem, rawCandidate: string): string {
917+
let signatures = computeUtilitySignature.get(designSystem)
918+
919+
for (let candidate of designSystem.parseCandidate(rawCandidate)) {
920+
if (
921+
candidate.kind === 'functional' &&
922+
candidate.value?.kind === 'arbitrary' &&
923+
candidate.value.dataType !== null
924+
) {
925+
let replacement = designSystem.printCandidate({
926+
...candidate,
927+
value: { ...candidate.value, dataType: null },
928+
})
929+
930+
if (signatures.get(rawCandidate) === signatures.get(replacement)) {
931+
return replacement
932+
}
933+
}
934+
}
935+
936+
return rawCandidate
937+
}

0 commit comments

Comments
 (0)