Skip to content

Commit 517425f

Browse files
Upgrade: Do not extract class names from functions (e.g. shadow in filter: 'drop-shadow(…)')
1 parent c84acf8 commit 517425f

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
- Fix `inset-shadow-*` suggestions in IntelliSense ([#15471](https://github.com/tailwindlabs/tailwindcss/pull/15471))
1616
- Only compile arbitrary values ending in `]` ([#15503](https://github.com/tailwindlabs/tailwindcss/pull/15503))
1717
- Improve performance and memory usage ([#15529](https://github.com/tailwindlabs/tailwindcss/pull/15529))
18+
- _Upgrade (experimental)_: Do not extract class names from functions (e.g. `shadow` in `filter: 'drop-shadow(…)'`)
1819

1920
### Changed
2021

@@ -782,4 +783,3 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
782783
## [4.0.0-alpha.1] - 2024-03-06
783784

784785
- First 4.0.0-alpha.1 release
785-

integrations/upgrade/js-config.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ test(
137137
'src/test.js': ts`
138138
export default {
139139
'shouldNotMigrate': !border.test + '',
140+
'filter': 'drop-shadow(0 0 0.5rem #000)',
140141
}
141142
`,
142143
'src/index.html': html`
@@ -288,6 +289,7 @@ test(
288289
--- src/test.js ---
289290
export default {
290291
'shouldNotMigrate': !border.test + '',
292+
'filter': 'drop-shadow(0 0 0.5rem #000)',
291293
}
292294
"
293295
`)

packages/@tailwindcss-upgrade/src/template/codemods/legacy-classes.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,33 @@ test.each([
3939

4040
expect(await legacyClasses(designSystem, {}, candidate)).toEqual(result)
4141
})
42+
43+
test('does not match false positives', async () => {
44+
let designSystem = await __unstable__loadDesignSystem('@import "tailwindcss";', {
45+
base: __dirname,
46+
})
47+
48+
async function shouldNotDetect(example: string, candidate = 'shadow') {
49+
expect(
50+
await legacyClasses(designSystem, {}, candidate, {
51+
contents: example,
52+
start: example.indexOf(candidate),
53+
end: example.indexOf(candidate) + candidate.length,
54+
}),
55+
).toEqual('shadow')
56+
}
57+
58+
await shouldNotDetect(`let notShadow = shadow \n`)
59+
await shouldNotDetect(`{ "foo": shadow.something + ""}\n`)
60+
await shouldNotDetect(`<div v-if="something && shadow"></div>\n`)
61+
await shouldNotDetect(`<div v-else-if="something && shadow"></div>\n`)
62+
await shouldNotDetect(`<div v-show="something && shadow"></div>\n`)
63+
await shouldNotDetect(`<div v-if="shadow || shadow"></div>\n`)
64+
await shouldNotDetect(`<div v-else-if="shadow || shadow"></div>\n`)
65+
await shouldNotDetect(`<div v-show="shadow || shadow"></div>\n`)
66+
await shouldNotDetect(`<div v-if="shadow"></div>\n`)
67+
await shouldNotDetect(`<div v-else-if="shadow"></div>\n`)
68+
await shouldNotDetect(`<div v-show="shadow"></div>\n`)
69+
await shouldNotDetect(`<div x-if="shadow"></div>\n`)
70+
await shouldNotDetect(`<div style={{filter: 'drop-shadow(30px 10px 4px #4444dd);'}}\n`)
71+
})

packages/@tailwindcss-upgrade/src/template/is-safe-migration.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ export function isSafeMigration(location: { contents: string; start: number; end
4141
return false
4242
}
4343

44+
// Heuristic 3: Disallow function call expressions immediately following the candidate
45+
if (currentLineAfterCandidate.trim().startsWith('(')) {
46+
return false
47+
}
48+
4449
// Heuristic 3: Disallow logical operators preceding or following the candidate
4550
for (let operator of LOGICAL_OPERATORS) {
4651
if (

0 commit comments

Comments
 (0)