@@ -2,6 +2,7 @@ var resolveProperty = require('css-tree').property;
2
2
var resolveKeyword = require ( 'css-tree' ) . keyword ;
3
3
var walkRulesRight = require ( 'css-tree' ) . walkRulesRight ;
4
4
var translate = require ( 'css-tree' ) . translate ;
5
+ var fingerprintId = 1 ;
5
6
var dontRestructure = {
6
7
'src' : 1 // https://github.com/afelix/csso/issues/50
7
8
} ;
@@ -71,90 +72,108 @@ function getPropertyFingerprint(propertyName, declaration, fingerprints) {
71
72
var fingerprint = fingerprints [ declarationId ] ;
72
73
73
74
if ( ! fingerprint ) {
74
- var vendorId = '' ;
75
- var iehack = '' ;
76
- var special = { } ;
77
-
78
- declaration . value . children . each ( function walk ( node ) {
79
- switch ( node . type ) {
80
- case 'Argument' :
81
- case 'Value' :
82
- case 'Parentheses' :
83
- node . children . each ( walk ) ;
84
- break ;
85
-
86
- case 'Identifier' :
87
- var name = node . name ;
88
-
89
- if ( ! vendorId ) {
90
- vendorId = resolveKeyword ( name ) . vendor ;
91
- }
75
+ switch ( declaration . value . type ) {
76
+ case 'Value' :
77
+ var vendorId = '' ;
78
+ var iehack = '' ;
79
+ var special = { } ;
80
+ var raw = false ;
81
+
82
+ declaration . value . children . each ( function walk ( node ) {
83
+ switch ( node . type ) {
84
+ case 'Value' :
85
+ case 'Brackets' :
86
+ case 'Parentheses' :
87
+ node . children . each ( walk ) ;
88
+ break ;
92
89
93
- if ( / \\ [ 0 9 ] / . test ( name ) ) {
94
- iehack = RegExp . lastMatch ;
95
- }
90
+ case 'Raw' :
91
+ raw = true ;
92
+ break ;
96
93
97
- if ( realName === 'cursor' ) {
98
- if ( CURSOR_SAFE_VALUE . indexOf ( name ) === - 1 ) {
99
- special [ name ] = true ;
100
- }
101
- } else if ( DONT_MIX_VALUE . hasOwnProperty ( realName ) ) {
102
- if ( DONT_MIX_VALUE [ realName ] . test ( name ) ) {
103
- special [ name ] = true ;
104
- }
105
- }
94
+ case 'Identifier' :
95
+ var name = node . name ;
106
96
107
- break ;
97
+ if ( ! vendorId ) {
98
+ vendorId = resolveKeyword ( name ) . vendor ;
99
+ }
108
100
109
- case 'Function' :
110
- var name = node . name ;
101
+ if ( / \\ [ 0 9 ] / . test ( name ) ) {
102
+ iehack = RegExp . lastMatch ;
103
+ }
111
104
112
- if ( ! vendorId ) {
113
- vendorId = resolveKeyword ( name ) . vendor ;
114
- }
105
+ if ( realName === 'cursor' ) {
106
+ if ( CURSOR_SAFE_VALUE . indexOf ( name ) === - 1 ) {
107
+ special [ name ] = true ;
108
+ }
109
+ } else if ( DONT_MIX_VALUE . hasOwnProperty ( realName ) ) {
110
+ if ( DONT_MIX_VALUE [ realName ] . test ( name ) ) {
111
+ special [ name ] = true ;
112
+ }
113
+ }
115
114
116
- if ( name === 'rect' ) {
117
- // there are 2 forms of rect:
118
- // rect(<top>, <right>, <bottom>, <left>) - standart
119
- // rect(<top> <right> <bottom> <left>) – backwards compatible syntax
120
- // only the same form values can be merged
121
- var hasComma = node . children . some ( function ( node ) {
122
- return node . type === 'Operator' && node . value === ',' ;
123
- } ) ;
124
- if ( ! hasComma ) {
125
- name = 'rect-backward' ;
126
- }
127
- }
115
+ break ;
116
+
117
+ case 'Function' :
118
+ var name = node . name ;
128
119
129
- special [ name + '()' ] = true ;
120
+ if ( ! vendorId ) {
121
+ vendorId = resolveKeyword ( name ) . vendor ;
122
+ }
130
123
131
- // check nested tokens too
132
- node . children . each ( walk ) ;
124
+ if ( name === 'rect' ) {
125
+ // there are 2 forms of rect:
126
+ // rect(<top>, <right>, <bottom>, <left>) - standart
127
+ // rect(<top> <right> <bottom> <left>) – backwards compatible syntax
128
+ // only the same form values can be merged
129
+ var hasComma = node . children . some ( function ( node ) {
130
+ return node . type === 'Operator' && node . value === ',' ;
131
+ } ) ;
132
+ if ( ! hasComma ) {
133
+ name = 'rect-backward' ;
134
+ }
135
+ }
133
136
134
- break ;
137
+ special [ name + '()' ] = true ;
135
138
136
- case 'Dimension' :
137
- var unit = node . unit ;
139
+ // check nested tokens too
140
+ node . children . each ( walk ) ;
138
141
139
- switch ( unit ) {
140
- // is not supported until IE11
141
- case 'rem' :
142
+ break ;
142
143
143
- // v* units is too buggy across browsers and better
144
- // don't merge values with those units
145
- case 'vw' :
146
- case 'vh' :
147
- case 'vmin' :
148
- case 'vmax' :
149
- case 'vm' : // IE9 supporting "vm" instead of "vmin".
150
- special [ unit ] = true ;
144
+ case 'Dimension' :
145
+ var unit = node . unit ;
146
+
147
+ switch ( unit ) {
148
+ // is not supported until IE11
149
+ case 'rem' :
150
+
151
+ // v* units is too buggy across browsers and better
152
+ // don't merge values with those units
153
+ case 'vw' :
154
+ case 'vh' :
155
+ case 'vmin' :
156
+ case 'vmax' :
157
+ case 'vm' : // IE9 supporting "vm" instead of "vmin".
158
+ special [ unit ] = true ;
159
+ break ;
160
+ }
151
161
break ;
152
162
}
153
- break ;
154
- }
155
- } ) ;
163
+ } ) ;
156
164
157
- fingerprint = '|' + Object . keys ( special ) . sort ( ) + '|' + iehack + vendorId ;
165
+ fingerprint = raw
166
+ ? '!' + fingerprintId ++
167
+ : '!' + Object . keys ( special ) . sort ( ) + '|' + iehack + vendorId ;
168
+ break ;
169
+
170
+ case 'Raw' :
171
+ fingerprint = '!' + declaration . value . value ;
172
+ break ;
173
+
174
+ default :
175
+ fingerprint = translate ( declaration . value ) ;
176
+ }
158
177
159
178
fingerprints [ declarationId ] = fingerprint ;
160
179
}
0 commit comments