File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
packages/@tailwindcss-upgrade/src/codemods/template Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,37 @@ export function isSafeMigration(
2222 location : { contents : string ; start : number ; end : number } ,
2323 designSystem : DesignSystem ,
2424) : boolean {
25+ // Ensure we are not migrating a candidate in a `<style>` block. The heuristic
26+ // would be if the candidate is preceded by a whitespace and followed by a
27+ // colon and whitespace.
28+ //
29+ // E.g.:
30+ // ```vue
31+ // <template>
32+ // <div class="foo"></div>
33+ // </template>
34+ //
35+ //
36+ // <style>
37+ // .foo {
38+ // flex-shrink: 0;
39+ // ^ ^^
40+ // }
41+ // </style>
42+ // ```
43+ if (
44+ // Whitespace before the candidate
45+ location . contents [ location . start - 1 ] ?. match ( / \s / ) &&
46+ // A colon followed by whitespace after the candidate
47+ location . contents . slice ( location . end , location . end + 2 ) ?. match ( / ^ : \s / ) &&
48+ // A `<style` block is present before the candidate
49+ location . contents . slice ( 0 , location . start ) . includes ( '<style' ) &&
50+ // `</style>` is present after the candidate
51+ location . contents . slice ( location . end ) . includes ( '</style>' )
52+ ) {
53+ return false
54+ }
55+
2556 let [ candidate ] = Array . from ( parseCandidate ( rawCandidate , designSystem ) )
2657
2758 // If we can't parse the candidate, then it's not a candidate at all. However,
You can’t perform that action at this time.
0 commit comments