Skip to content

Commit 8abbc77

Browse files
Apply suggestions from code review
Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
1 parent 6dd2a58 commit 8abbc77

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Fixed
1111

1212
- Ensure individual logical property utilities are sorted later than left/right pair utilities ([#14777](https://github.com/tailwindlabs/tailwindcss/pull/14777))
13-
- Don't migrate important modifiers when these are used inside conditionals of certain template languages (e.g. `<div v-if="!border"/>`) ([#14774](https://github.com/tailwindlabs/tailwindcss/pull/14774))
13+
- Don't migrate important modifiers inside conditional statements in Vue and Alpine (e.g. `<div v-if="!border" />`) ([#14774](https://github.com/tailwindlabs/tailwindcss/pull/14774))
1414
- _Upgrade (experimental)_: Ensure `@import` statements for relative CSS files are actually migrated to use relative path syntax ([#14769](https://github.com/tailwindlabs/tailwindcss/pull/14769))
1515

1616
## [4.0.0-alpha.29] - 2024-10-23

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,13 @@ test('does not match false positives', async () => {
5656
shouldNotDetect(`let notBorder = !border \n`)
5757
shouldNotDetect(`{ "foo": !border.something + ""}\n`)
5858
shouldNotDetect(`<div v-if="something && !border"></div>\n`)
59+
shouldNotDetect(`<div v-else-if="something && !border"></div>\n`)
5960
shouldNotDetect(`<div v-show="something && !border"></div>\n`)
6061
shouldNotDetect(`<div v-if="!border || !border"></div>\n`)
62+
shouldNotDetect(`<div v-else-if="!border || !border"></div>\n`)
6163
shouldNotDetect(`<div v-show="!border || !border"></div>\n`)
6264
shouldNotDetect(`<div v-if="!border"></div>\n`)
65+
shouldNotDetect(`<div v-else-if="!border"></div>\n`)
6366
shouldNotDetect(`<div v-show="!border"></div>\n`)
6467
shouldNotDetect(`<div x-if="!border"></div>\n`)
6568
})

packages/@tailwindcss-upgrade/src/template/codemods/important.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ const QUOTES = ['"', "'", '`']
77
const LOGICAL_OPERATORS = ['&&', '||', '===', '==', '!=', '!==', '>', '>=', '<', '<=']
88
const CONDITIONAL_TEMPLATE_SYNTAX = [
99
// Vue
10+
/v-else-if=['"]$/,
1011
/v-if=['"]$/,
1112
/v-show=['"]$/,
1213

1314
// Alpine
14-
/x-show=['"]$/,
1515
/x-if=['"]$/,
16+
/x-show=['"]$/,
1617
]
1718

1819
// In v3 the important modifier `!` sits in front of the utility itself, not
@@ -63,7 +64,7 @@ export function important(
6364
currentLineAfterCandidate += char
6465
}
6566

66-
// Heuristics 1: Require the candidate to be inside quotes
67+
// Heuristic 1: Require the candidate to be inside quotes
6768
let isQuoteBeforeCandidate = QUOTES.some((quote) =>
6869
currentLineBeforeCandidate.includes(quote),
6970
)
@@ -74,12 +75,12 @@ export function important(
7475
continue nextCandidate
7576
}
7677

77-
// Heuristics 2: Disallow object access immediately following the candidate
78+
// Heuristic 2: Disallow object access immediately following the candidate
7879
if (currentLineAfterCandidate[0] === '.') {
7980
continue nextCandidate
8081
}
8182

82-
// Heuristics 3: Disallow logical operators proceeding or following the candidate
83+
// Heuristic 3: Disallow logical operators preceding or following the candidate
8384
for (let operator of LOGICAL_OPERATORS) {
8485
if (
8586
currentLineAfterCandidate.trim().startsWith(operator) ||
@@ -89,7 +90,7 @@ export function important(
8990
}
9091
}
9192

92-
// Heuristics 4: Disallow conditional template syntax
93+
// Heuristic 4: Disallow conditional template syntax
9394
for (let rule of CONDITIONAL_TEMPLATE_SYNTAX) {
9495
if (rule.test(currentLineBeforeCandidate)) {
9596
continue nextCandidate

0 commit comments

Comments
 (0)