@@ -36,6 +36,7 @@ const CANONICALIZATIONS = [
36
36
themeToVar ,
37
37
arbitraryUtilities ,
38
38
bareValueUtilities ,
39
+ deprecatedUtilities ,
39
40
print ,
40
41
]
41
42
@@ -428,6 +429,14 @@ function parseCandidate(designSystem: DesignSystem, input: string) {
428
429
)
429
430
}
430
431
432
+ function printUnprefixedCandidate ( designSystem : DesignSystem , candidate : Candidate ) {
433
+ let candidateString = designSystem . printCandidate ( candidate )
434
+
435
+ return designSystem . theme . prefix && candidateString . startsWith ( `${ designSystem . theme . prefix } :` )
436
+ ? candidateString . slice ( designSystem . theme . prefix . length + 1 )
437
+ : candidateString
438
+ }
439
+
431
440
// ----
432
441
433
442
const baseReplacementsCache = new DefaultMap < DesignSystem , Map < string , Candidate > > (
@@ -811,3 +820,48 @@ function bareValueUtilities(designSystem: DesignSystem, rawCandidate: string): s
811
820
}
812
821
}
813
822
}
823
+
824
+ // ----
825
+
826
+ const DEPRECATION_MAP = new Map ( [ [ 'order-none' , 'order-0' ] ] )
827
+
828
+ function deprecatedUtilities ( designSystem : DesignSystem , rawCandidate : string ) : string {
829
+ let signatures = computeUtilitySignature . get ( designSystem )
830
+
831
+ for ( let readonlyCandidate of designSystem . parseCandidate ( rawCandidate ) ) {
832
+ // The below logic makes use of mutation. Since candidates in the
833
+ // DesignSystem are cached, we can't mutate them directly.
834
+ let candidate = structuredClone ( readonlyCandidate ) as Writable < typeof readonlyCandidate >
835
+
836
+ // Create a basic stripped candidate without variants or important flag. We
837
+ // will re-add those later but they are irrelevant for what we are trying to
838
+ // do here (and will increase cache hits because we only have to deal with
839
+ // the base utility, nothing more).
840
+ let targetCandidate = baseCandidate ( candidate )
841
+ let targetCandidateString = printUnprefixedCandidate ( designSystem , targetCandidate )
842
+
843
+ let replacementString = DEPRECATION_MAP . get ( targetCandidateString ) ?? null
844
+ if ( replacementString === null ) return rawCandidate
845
+
846
+ let legacySignature = signatures . get ( targetCandidateString )
847
+ if ( typeof legacySignature !== 'string' ) return rawCandidate
848
+
849
+ let replacementSignature = signatures . get ( replacementString )
850
+ if ( typeof replacementSignature !== 'string' ) return rawCandidate
851
+
852
+ // Not the same signature, not safe to migrate
853
+ if ( legacySignature !== replacementSignature ) return rawCandidate
854
+
855
+ let [ replacement ] = parseCandidate ( designSystem , replacementString )
856
+
857
+ // Re-add the variants and important flag from the original candidate
858
+ return designSystem . printCandidate (
859
+ Object . assign ( structuredClone ( replacement ) , {
860
+ variants : candidate . variants ,
861
+ important : candidate . important ,
862
+ } ) ,
863
+ )
864
+ }
865
+
866
+ return rawCandidate
867
+ }
0 commit comments