diff --git a/CHANGELOG.md b/CHANGELOG.md index 8106d13895bf..70036c42a1a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -- Nothing yet! +- Add heuristic to skip candidate migrations inside `emit(…)` ([#18330](https://github.com/tailwindlabs/tailwindcss/pull/18330)) ## [4.1.10] - 2025-06-11 diff --git a/packages/@tailwindcss-upgrade/src/codemods/template/is-safe-migration.test.ts b/packages/@tailwindcss-upgrade/src/codemods/template/is-safe-migration.test.ts index b4c9c01246fc..5ade133e06fc 100644 --- a/packages/@tailwindcss-upgrade/src/codemods/template/is-safe-migration.test.ts +++ b/packages/@tailwindcss-upgrade/src/codemods/template/is-safe-migration.test.ts @@ -61,4 +61,8 @@ test('does not replace classes in invalid positions', async () => { // Alpine/Livewire wire:… await shouldNotReplace('', 'blur') + + // Vue 3 events + await shouldNotReplace(`emit('blur', props.modelValue)\n`, 'blur') + await shouldNotReplace(`$emit('blur', props.modelValue)\n`, 'blur') }) diff --git a/packages/@tailwindcss-upgrade/src/codemods/template/is-safe-migration.ts b/packages/@tailwindcss-upgrade/src/codemods/template/is-safe-migration.ts index 27c2e23216ea..7ac24d645fb3 100644 --- a/packages/@tailwindcss-upgrade/src/codemods/template/is-safe-migration.ts +++ b/packages/@tailwindcss-upgrade/src/codemods/template/is-safe-migration.ts @@ -18,6 +18,7 @@ const CONDITIONAL_TEMPLATE_SYNTAX = [ /wire:[^\s]*?$/, ] const NEXT_PLACEHOLDER_PROP = /placeholder=\{?['"]$/ +const VUE_3_EMIT = /\b\$?emit\(['"]$/ export function isSafeMigration( rawCandidate: string, @@ -175,6 +176,11 @@ export function isSafeMigration( return false } + // Heuristic: Disallow replacements inside `emit('…', …)` + if (VUE_3_EMIT.test(currentLineBeforeCandidate)) { + return false + } + return true }