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
verify that the migrated class actually exists
When you have something like:
```
if (!duration) {}
```

It could be that we migrate this to:
```
if (duration!) {}
```

Hopefully our safety checks do not do that though. But in the event that
they do, the `!duration` should not be converted to `duration!` because
that class simply doesn't exist.

It wil parse correctly as:
```
[
  {
    "kind": "functional",
    "root": "duration",
    "modifier": null,
    "value": null,
    "variants": [],
    "important": true,
    "raw": "!duration"
  }
]
```

And that's because the `duration-<number>` _does_ work and produces
output. But this on its won won't produce any output at all.

If that's the case, then we can throw away any migrations related to
this and return the original value.
  • Loading branch information
RobinMalfait committed May 14, 2025
commit 754bccb6a1b5cf5bb75bd7e0d1aae2457bbb2f10
10 changes: 10 additions & 0 deletions packages/@tailwindcss-upgrade/src/codemods/template/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { migratePrefix } from './migrate-prefix'
import { migrateSimpleLegacyClasses } from './migrate-simple-legacy-classes'
import { migrateThemeToVar } from './migrate-theme-to-var'
import { migrateVariantOrder } from './migrate-variant-order'
import { computeUtilitySignature } from './signatures'

export type Migration = (
designSystem: DesignSystem,
Expand Down Expand Up @@ -60,9 +61,18 @@ let migrateCached = new DefaultMap<
>((designSystem) => {
return new DefaultMap((userConfig) => {
return new DefaultMap(async (rawCandidate) => {
let original = rawCandidate

for (let migration of DEFAULT_MIGRATIONS) {
rawCandidate = await migration(designSystem, userConfig, rawCandidate)
}

// Verify that the candidate actually makes sense at all. E.g.: `duration`
// is not a valid candidate, but it will parse because `duration-<number>`
// exists.
let signature = computeUtilitySignature.get(designSystem).get(rawCandidate)
if (typeof signature !== 'string') return original

return rawCandidate
})
})
Expand Down
Loading