Home / File/ migrate-modernize-arbitrary-values.test.ts — tailwindcss Source File

migrate-modernize-arbitrary-values.test.ts — tailwindcss Source File

Architecture documentation for migrate-modernize-arbitrary-values.test.ts, a typescript file in the tailwindcss codebase. 13 imports, 0 dependents.

File typescript UpgradeToolkit Codemods 13 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  ee1d35bf_4335_a131_a900_1f9f4b90a0e1["migrate-modernize-arbitrary-values.test.ts"]
  c1272aed_91bb_73df_0746_d55fa9b302fd["types.ts"]
  ee1d35bf_4335_a131_a900_1f9f4b90a0e1 --> c1272aed_91bb_73df_0746_d55fa9b302fd
  7fd72d4c_e95c_d849_1002_1e1c9d8aca1a["design-system.ts"]
  ee1d35bf_4335_a131_a900_1f9f4b90a0e1 --> 7fd72d4c_e95c_d849_1002_1e1c9d8aca1a
  fff09679_e13c_392d_23bb_cebc04ddb008["version.ts"]
  ee1d35bf_4335_a131_a900_1f9f4b90a0e1 --> fff09679_e13c_392d_23bb_cebc04ddb008
  dfcf938d_abe9_684f_720a_29a0a1797759["migrate-arbitrary-variants.ts"]
  ee1d35bf_4335_a131_a900_1f9f4b90a0e1 --> dfcf938d_abe9_684f_720a_29a0a1797759
  bc19ae8d_4f83_e280_be05_e35eee14b3e7["migrateArbitraryVariants"]
  ee1d35bf_4335_a131_a900_1f9f4b90a0e1 --> bc19ae8d_4f83_e280_be05_e35eee14b3e7
  b2513b9e_5a88_8d31_01d5_feda722b6dae["migrate-handle-empty-arbitrary-values.ts"]
  ee1d35bf_4335_a131_a900_1f9f4b90a0e1 --> b2513b9e_5a88_8d31_01d5_feda722b6dae
  7ea9e5e1_61ed_234e_08e0_af2f43645d35["migrateEmptyArbitraryValues"]
  ee1d35bf_4335_a131_a900_1f9f4b90a0e1 --> 7ea9e5e1_61ed_234e_08e0_af2f43645d35
  01bf11c3_0faa_9a23_ba13_a455d9c3e825["migrate-modernize-arbitrary-values.ts"]
  ee1d35bf_4335_a131_a900_1f9f4b90a0e1 --> 01bf11c3_0faa_9a23_ba13_a455d9c3e825
  9f73b711_0f71_129f_7fdb_764a3c0df282["migrateModernizeArbitraryValues"]
  ee1d35bf_4335_a131_a900_1f9f4b90a0e1 --> 9f73b711_0f71_129f_7fdb_764a3c0df282
  d13948d4_4434_bf78_9916_1ba327123c94["migrate-prefix.ts"]
  ee1d35bf_4335_a131_a900_1f9f4b90a0e1 --> d13948d4_4434_bf78_9916_1ba327123c94
  087d2224_9aa6_c6e5_3a75_d99cf251cb04["migratePrefix"]
  ee1d35bf_4335_a131_a900_1f9f4b90a0e1 --> 087d2224_9aa6_c6e5_3a75_d99cf251cb04
  92f2d961_72a4_d195_92d7_2e66972f8894["node"]
  ee1d35bf_4335_a131_a900_1f9f4b90a0e1 --> 92f2d961_72a4_d195_92d7_2e66972f8894
  696bd648_5f24_1b59_8e8b_7a97a692869e["vitest"]
  ee1d35bf_4335_a131_a900_1f9f4b90a0e1 --> 696bd648_5f24_1b59_8e8b_7a97a692869e
  style ee1d35bf_4335_a131_a900_1f9f4b90a0e1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { __unstable__loadDesignSystem } from '@tailwindcss/node'
import { expect, test, vi } from 'vitest'
import type { UserConfig } from '../../../../tailwindcss/src/compat/config/types'
import type { DesignSystem } from '../../../../tailwindcss/src/design-system'
import * as versions from '../../utils/version'
import { migrateArbitraryVariants } from './migrate-arbitrary-variants'
import { migrateEmptyArbitraryValues } from './migrate-handle-empty-arbitrary-values'
import { migrateModernizeArbitraryValues } from './migrate-modernize-arbitrary-values'
import { migratePrefix } from './migrate-prefix'
vi.spyOn(versions, 'isMajor').mockReturnValue(true)

const css = String.raw

function migrate(designSystem: DesignSystem, userConfig: UserConfig | null, rawCandidate: string) {
  for (let migration of [
    migrateEmptyArbitraryValues,
    migratePrefix,
    migrateModernizeArbitraryValues,
    migrateArbitraryVariants,
    (designSystem: DesignSystem, _: UserConfig | null, rawCandidate: string) => {
      return designSystem.canonicalizeCandidates([rawCandidate]).pop() ?? rawCandidate
    },
  ]) {
    rawCandidate = migration(designSystem, userConfig, rawCandidate)
  }
  return rawCandidate
}

test.each([
  // Some extreme examples of what happens in the wild:
  ['group-[]:flex', 'in-[.group]:flex'],
  ['group-[]/name:flex', 'in-[.group\\/name]:flex'],

  // Migrate `peer-[]` to a parsable `peer-[&]` instead:
  ['peer-[]:flex', 'peer-[&]:flex'],
  ['peer-[]/name:flex', 'peer-[&]/name:flex'],

  // These shouldn't happen in the real world (because compound variants are
  // new). But this could happen once we allow codemods to run in v4+ projects.
  ['has-group-[]:flex', 'has-in-[.group]:flex'],
  ['has-group-[]/name:flex', 'has-in-[.group\\/name]:flex'],
  ['not-group-[]:flex', 'not-in-[.group]:flex'],
  ['not-group-[]/name:flex', 'not-in-[.group\\/name]:flex'],
])('%s => %s (%#)', async (candidate, result) => {
  let designSystem = await __unstable__loadDesignSystem(
    css`
      @import 'tailwindcss';
      @theme {
        --*: initial;
      }
    `,
    { base: __dirname },
  )

  expect(migrate(designSystem, {}, candidate)).toEqual(result)
})

test.each([
  // Should not prefix classes in arbitrary values
  ['[.foo_&]:tw-flex', 'tw:in-[.foo]:flex'],

  // Should migrate `.group` classes
  ['group-[]:tw-flex', 'tw:in-[.tw\\:group]:flex'],
  ['group-[]/name:tw-flex', 'tw:in-[.tw\\:group\\/name]:flex'],

  // Migrate `peer-[]` to a parsable `peer-[&]` instead:
  ['peer-[]:tw-flex', 'tw:peer-[&]:flex'],
  ['peer-[]/name:tw-flex', 'tw:peer-[&]/name:flex'],

  // However, `.group` inside of an arbitrary variant should not be prefixed:
  ['[.group_&]:tw-flex', 'tw:in-[.group]:flex'],

  // These shouldn't happen in the real world (because compound variants are
  // new). But this could happen once we allow codemods to run in v4+ projects.
  ['has-group-[]:tw-flex', 'tw:has-in-[.tw\\:group]:flex'],
  ['has-group-[]/name:tw-flex', 'tw:has-in-[.tw\\:group\\/name]:flex'],
  ['not-group-[]:tw-flex', 'tw:not-in-[.tw\\:group]:flex'],
  ['not-group-[]/name:tw-flex', 'tw:not-in-[.tw\\:group\\/name]:flex'],
])('%s => %s (%#)', async (candidate, result) => {
  let designSystem = await __unstable__loadDesignSystem(
    css`
      @import 'tailwindcss' prefix(tw);
      @theme {
        --*: initial;
      }
    `,
    { base: __dirname },
  )

  expect(migrate(designSystem, { prefix: 'tw-' }, candidate)).toEqual(result)
})

Subdomains

Functions

Frequently Asked Questions

What does migrate-modernize-arbitrary-values.test.ts do?
migrate-modernize-arbitrary-values.test.ts is a source file in the tailwindcss codebase, written in typescript. It belongs to the UpgradeToolkit domain, Codemods subdomain.
What functions are defined in migrate-modernize-arbitrary-values.test.ts?
migrate-modernize-arbitrary-values.test.ts defines 1 function(s): migrate.
What does migrate-modernize-arbitrary-values.test.ts depend on?
migrate-modernize-arbitrary-values.test.ts imports 13 module(s): design-system.ts, migrate-arbitrary-variants.ts, migrate-handle-empty-arbitrary-values.ts, migrate-modernize-arbitrary-values.ts, migrate-prefix.ts, migrateArbitraryVariants, migrateEmptyArbitraryValues, migrateModernizeArbitraryValues, and 5 more.
Where is migrate-modernize-arbitrary-values.test.ts in the architecture?
migrate-modernize-arbitrary-values.test.ts is located at packages/@tailwindcss-upgrade/src/codemods/template/migrate-modernize-arbitrary-values.test.ts (domain: UpgradeToolkit, subdomain: Codemods, directory: packages/@tailwindcss-upgrade/src/codemods/template).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free