File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree 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-
31const createExpectedPropertiesOrder = require ( '../createExpectedPropertiesOrder' ) ;
42const getComments = require ( '../getComments' ) ;
53const getPropertiesOrderData = require ( '../getPropertiesOrderData' ) ;
@@ -8,6 +6,7 @@ const isCustomProperty = require('../isCustomProperty');
86const isRuleWithNodes = require ( '../isRuleWithNodes' ) ;
97const isStandardSyntaxProperty = require ( '../isStandardSyntaxProperty' ) ;
108const sorting = require ( '../sorting' ) ;
9+ const vendor = require ( '../vendor' ) ;
1110
1211module . exports = function propertiesOrder ( css , opts ) {
1312 const isAlphabetical = opts [ 'properties-order' ] === 'alphabetical' ;
@@ -33,7 +32,7 @@ module.exports = function propertiesOrder(css, opts) {
3332 isStandardSyntaxProperty ( childNode . prop ) &&
3433 ! isCustomProperty ( childNode . prop )
3534 ) {
36- let unprefixedPropName = postcss . vendor . unprefixed ( childNode . prop ) ;
35+ let unprefixedPropName = vendor . unprefixed ( childNode . prop ) ;
3736
3837 // Hack to allow -moz-osx-font-smoothing to be understood
3938 // just like -webkit-font-smoothing
Original file line number Diff line number Diff line change 1- const postcss = require ( 'postcss' ) ;
21const _ = require ( 'lodash' ) ;
32const shorthandData = require ( './shorthandData' ) ;
3+ const vendor = require ( './vendor' ) ;
44
55module . exports = {
66 sortDeclarations,
@@ -12,11 +12,11 @@ function sortDeclarations(a, b) {
1212 // If unprefixed prop names are the same, compare the prefixed versions
1313 if ( a . node . type === 'decl' && b . node . type === 'decl' && a . unprefixedName === b . unprefixedName ) {
1414 // 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 ) {
1616 return 1 ;
1717 }
1818
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 ) {
2020 return - 1 ;
2121 }
2222 }
@@ -84,11 +84,11 @@ function sortDeclarationsAlphabetically(a, b) {
8484 if ( a . unprefixedName === b . unprefixedName ) {
8585 if ( a . node . type === 'decl' && b . node . type === 'decl' ) {
8686 // 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 ) {
8888 return 1 ;
8989 }
9090
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 ) {
9292 return - 1 ;
9393 }
9494 }
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 6161 " ./jest-setup.js"
6262 ],
6363 "testEnvironment" : " node" ,
64- "testRegex" : " __tests__/[a-zA-Z-]+\\ .js$" ,
64+ "testRegex" : " __tests__/[a-zA-Z-. ]+\\ .js$" ,
6565 "watchPlugins" : [
6666 " jest-watch-typeahead/filename" ,
6767 " jest-watch-typeahead/testname"
You can’t perform that action at this time.
0 commit comments