File tree Expand file tree Collapse file tree 5 files changed +68
-9
lines changed Expand file tree Collapse file tree 5 files changed +68
-9
lines changed Original file line number Diff line number Diff line change
1
+ let vendor = require ( '../vendor' ) ;
2
+
3
+ const VALUE = '-1px -1px 1px rgba(0, 0, 0, 0.2) inset' ;
4
+
5
+ it ( 'returns prefix' , ( ) => {
6
+ expect ( vendor . prefix ( '-moz-color' ) ) . toEqual ( '-moz-' ) ;
7
+ expect ( vendor . prefix ( 'color' ) ) . toEqual ( '' ) ;
8
+ expect ( vendor . prefix ( VALUE ) ) . toEqual ( '' ) ;
9
+ } ) ;
10
+
11
+ it ( 'returns unprefixed version' , ( ) => {
12
+ expect ( vendor . unprefixed ( '-moz-color' ) ) . toEqual ( 'color' ) ;
13
+ expect ( vendor . unprefixed ( 'color' ) ) . toEqual ( 'color' ) ;
14
+ expect ( vendor . unprefixed ( VALUE ) ) . toEqual ( VALUE ) ;
15
+ } ) ;
Original file line number Diff line number Diff line change 1
- const postcss = require ( 'postcss' ) ;
2
-
3
1
const createExpectedPropertiesOrder = require ( '../createExpectedPropertiesOrder' ) ;
4
2
const getComments = require ( '../getComments' ) ;
5
3
const getPropertiesOrderData = require ( '../getPropertiesOrderData' ) ;
@@ -8,6 +6,7 @@ const isCustomProperty = require('../isCustomProperty');
8
6
const isRuleWithNodes = require ( '../isRuleWithNodes' ) ;
9
7
const isStandardSyntaxProperty = require ( '../isStandardSyntaxProperty' ) ;
10
8
const sorting = require ( '../sorting' ) ;
9
+ const vendor = require ( '../vendor' ) ;
11
10
12
11
module . exports = function propertiesOrder ( css , opts ) {
13
12
const isAlphabetical = opts [ 'properties-order' ] === 'alphabetical' ;
@@ -33,7 +32,7 @@ module.exports = function propertiesOrder(css, opts) {
33
32
isStandardSyntaxProperty ( childNode . prop ) &&
34
33
! isCustomProperty ( childNode . prop )
35
34
) {
36
- let unprefixedPropName = postcss . vendor . unprefixed ( childNode . prop ) ;
35
+ let unprefixedPropName = vendor . unprefixed ( childNode . prop ) ;
37
36
38
37
// Hack to allow -moz-osx-font-smoothing to be understood
39
38
// just like -webkit-font-smoothing
Original file line number Diff line number Diff line change 1
- const postcss = require ( 'postcss' ) ;
2
1
const _ = require ( 'lodash' ) ;
3
2
const shorthandData = require ( './shorthandData' ) ;
3
+ const vendor = require ( './vendor' ) ;
4
4
5
5
module . exports = {
6
6
sortDeclarations,
@@ -12,11 +12,11 @@ function sortDeclarations(a, b) {
12
12
// If unprefixed prop names are the same, compare the prefixed versions
13
13
if ( a . node . type === 'decl' && b . node . type === 'decl' && a . unprefixedName === b . unprefixedName ) {
14
14
// If first property has no prefix and second property has prefix
15
- if ( ! postcss . vendor . prefix ( a . name ) . length && postcss . vendor . prefix ( b . name ) . length ) {
15
+ if ( ! vendor . prefix ( a . name ) . length && vendor . prefix ( b . name ) . length ) {
16
16
return 1 ;
17
17
}
18
18
19
- if ( postcss . vendor . prefix ( a . name ) . length && ! postcss . vendor . prefix ( b . name ) . length ) {
19
+ if ( vendor . prefix ( a . name ) . length && ! vendor . prefix ( b . name ) . length ) {
20
20
return - 1 ;
21
21
}
22
22
}
@@ -84,11 +84,11 @@ function sortDeclarationsAlphabetically(a, b) {
84
84
if ( a . unprefixedName === b . unprefixedName ) {
85
85
if ( a . node . type === 'decl' && b . node . type === 'decl' ) {
86
86
// If first property has no prefix and second property has prefix
87
- if ( ! postcss . vendor . prefix ( a . name ) . length && postcss . vendor . prefix ( b . name ) . length ) {
87
+ if ( ! vendor . prefix ( a . name ) . length && vendor . prefix ( b . name ) . length ) {
88
88
return 1 ;
89
89
}
90
90
91
- if ( postcss . vendor . prefix ( a . name ) . length && ! postcss . vendor . prefix ( b . name ) . length ) {
91
+ if ( vendor . prefix ( a . name ) . length && ! vendor . prefix ( b . name ) . length ) {
92
92
return - 1 ;
93
93
}
94
94
}
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Contains helpers for working with vendor prefixes.
3
+ *
4
+ * Copied from https://github.com/postcss/postcss/commit/777c55b5d2a10605313a4972888f4f32005f5ac2
5
+ *
6
+ * @namespace vendor
7
+ */
8
+ let vendor = {
9
+ /**
10
+ * Returns the vendor prefix extracted from an input string.
11
+ *
12
+ * @param {string } prop String with or without vendor prefix.
13
+ *
14
+ * @return {string } vendor prefix or empty string
15
+ *
16
+ * @example
17
+ * vendor.prefix('-moz-tab-size') //=> '-moz-'
18
+ * vendor.prefix('tab-size') //=> ''
19
+ */
20
+ prefix ( prop ) {
21
+ let match = prop . match ( / ^ ( - \w + - ) / ) ;
22
+
23
+ if ( match ) {
24
+ return match [ 0 ] ;
25
+ }
26
+
27
+ return '' ;
28
+ } ,
29
+
30
+ /**
31
+ * Returns the input string stripped of its vendor prefix.
32
+ *
33
+ * @param {string } prop String with or without vendor prefix.
34
+ *
35
+ * @return {string } String name without vendor prefixes.
36
+ *
37
+ * @example
38
+ * vendor.unprefixed('-moz-tab-size') //=> 'tab-size'
39
+ */
40
+ unprefixed ( prop ) {
41
+ return prop . replace ( / ^ - \w + - / , '' ) ;
42
+ } ,
43
+ } ;
44
+
45
+ module . exports = vendor ;
Original file line number Diff line number Diff line change 61
61
" ./jest-setup.js"
62
62
],
63
63
"testEnvironment" : " node" ,
64
- "testRegex" : " __tests__/[a-zA-Z-]+\\ .js$" ,
64
+ "testRegex" : " __tests__/[a-zA-Z-. ]+\\ .js$" ,
65
65
"watchPlugins" : [
66
66
" jest-watch-typeahead/filename" ,
67
67
" jest-watch-typeahead/testname"
You can’t perform that action at this time.
0 commit comments