1- import postcss , { Rule , Node , Declaration , Comment , vendor } from 'postcss' ;
1+ import postcss , {
2+ Rule ,
3+ Node ,
4+ Declaration ,
5+ Comment ,
6+ vendor
7+ } from 'postcss' ;
28import rtlcss from 'rtlcss' ;
3- import { Mode , Autorename , ControlDirective } from '@types' ;
9+ import {
10+ Mode ,
11+ Autorename ,
12+ ControlDirective ,
13+ DeclarationHashMapProp
14+ } from '@types' ;
415import {
516 DECLARATION_TYPE ,
617 FLIP_PROPERTY_REGEXP ,
@@ -19,7 +30,9 @@ import {
1930 allDeclarations ,
2031 initialValues ,
2132 appendDeclarationToRule ,
22- hasIgnoreDirectiveInRaws
33+ hasIgnoreDirectiveInRaws ,
34+ hasSameUpcomingDeclaration ,
35+ hasMirrorDeclaration
2336} from '@utilities/declarations' ;
2437import { walkContainer } from '@utilities/containers' ;
2538import {
@@ -52,10 +65,15 @@ export const parseDeclarations = (
5265 const ruleBoth = ruleFlipped . clone ( ) ;
5366 const ruleSafe = ruleFlipped . clone ( ) ;
5467
55- const declarationHashMap = Array . prototype . reduce . call ( rule . nodes , ( obj : Record < string , string > , node : Node ) : Record < string , string > => {
68+ const declarationHashMap = Array . prototype . reduce . call ( rule . nodes , ( obj : DeclarationHashMapProp , node : Node ) : DeclarationHashMapProp => {
5669 if ( node . type === DECLARATION_TYPE ) {
5770 const decl = node as Declaration ;
58- obj [ decl . prop ] = decl . value . trim ( ) ;
71+ const index = rule . index ( decl ) ;
72+ obj [ decl . prop ] = obj [ decl . prop ] || { } ;
73+ obj [ decl . prop ] [ index ] = {
74+ decl,
75+ value : decl . value . trim ( )
76+ } ;
5977 }
6078 return obj ;
6179 } , { } ) ;
@@ -168,6 +186,10 @@ export const parseDeclarations = (
168186 ) {
169187 return ;
170188 }
189+
190+ if ( hasSameUpcomingDeclaration ( rule , decl , declarationHashMap ) ) {
191+ return ;
192+ }
171193
172194 if ( isAnimation ) {
173195
@@ -237,7 +259,7 @@ export const parseDeclarations = (
237259 deleteDeclarations . push ( decl ) ;
238260 }
239261 return ;
240- } else if ( declarationHashMap [ declFlipped . prop ] === declFlippedValue ) {
262+ } else if ( hasMirrorDeclaration ( rule , declFlipped , declarationHashMap ) ) {
241263 simetricRules = true ;
242264 if ( isConflictedDeclaration && ! hasIgnoreDirectiveInRaws ( decl ) ) {
243265 appendDeclarationToRule ( decl , ruleSafe ) ;
0 commit comments