Skip to content
Merged
Show file tree
Hide file tree
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
Next Next commit
convert commas to spaces
  • Loading branch information
RobinMalfait committed Nov 9, 2024
commit e73e6b091f1929ceefc4a474d498a952ae2cabb1
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { __unstable__loadDesignSystem } from '@tailwindcss/node'
import { expect, test } from 'vitest'
import { legacyArbitraryValues } from './legacy-arbitrary-values'

test.each([
['grid-cols-[auto,1fr]', 'grid-cols-[auto_1fr]'],
['grid-rows-[auto,1fr]', 'grid-rows-[auto_1fr]'],
['object-[10px,20px]', 'object-[10px_20px]'],
])('%s => %s', async (candidate, result) => {
let designSystem = await __unstable__loadDesignSystem('@import "tailwindcss";', {
base: __dirname,
})

expect(legacyArbitraryValues(designSystem, {}, candidate)).toEqual(result)
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { Config } from 'tailwindcss'
import { parseCandidate } from '../../../../tailwindcss/src/candidate'
import type { DesignSystem } from '../../../../tailwindcss/src/design-system'
import { segment } from '../../../../tailwindcss/src/utils/segment'
import { printCandidate } from '../candidates'

export function legacyArbitraryValues(
designSystem: DesignSystem,
_userConfig: Config,
rawCandidate: string,
): string {
for (let candidate of parseCandidate(rawCandidate, designSystem)) {
let clone = structuredClone(candidate)
let changed = false

// Convert commas to spaces. E.g.: [auto,1fr] to [auto_1fr]
if (
clone.kind === 'functional' &&
clone.value?.kind === 'arbitrary' &&
(clone.root === 'grid-cols' || clone.root == 'grid-rows' || clone.root == 'object')
) {
changed = true
clone.value.value = segment(clone.value.value, ',').join(' ')
}

return changed ? printCandidate(designSystem, clone) : rawCandidate
}

return rawCandidate
}
2 changes: 2 additions & 0 deletions packages/@tailwindcss-upgrade/src/template/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { arbitraryValueToBareValue } from './codemods/arbitrary-value-to-bare-va
import { automaticVarInjection } from './codemods/automatic-var-injection'
import { bgGradient } from './codemods/bg-gradient'
import { important } from './codemods/important'
import { legacyArbitraryValues } from './codemods/legacy-arbitrary-values'
import { maxWidthScreen } from './codemods/max-width-screen'
import { prefix } from './codemods/prefix'
import { simpleLegacyClasses } from './codemods/simple-legacy-classes'
Expand All @@ -31,6 +32,7 @@ export const DEFAULT_MIGRATIONS: Migration[] = [
automaticVarInjection,
bgGradient,
simpleLegacyClasses,
legacyArbitraryValues,
arbitraryValueToBareValue,
maxWidthScreen,
themeToVar,
Expand Down