Skip to content

Commit 3d92eea

Browse files
committed
Copy postcss.vendor to own code
1 parent e9c1794 commit 3d92eea

File tree

5 files changed

+68
-9
lines changed

5 files changed

+68
-9
lines changed

lib/__tests__/vendor.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
});

lib/properties-order/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const postcss = require('postcss');
2-
31
const createExpectedPropertiesOrder = require('../createExpectedPropertiesOrder');
42
const getComments = require('../getComments');
53
const getPropertiesOrderData = require('../getPropertiesOrderData');
@@ -8,6 +6,7 @@ const isCustomProperty = require('../isCustomProperty');
86
const isRuleWithNodes = require('../isRuleWithNodes');
97
const isStandardSyntaxProperty = require('../isStandardSyntaxProperty');
108
const sorting = require('../sorting');
9+
const vendor = require('../vendor');
1110

1211
module.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

lib/sorting.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const postcss = require('postcss');
21
const _ = require('lodash');
32
const shorthandData = require('./shorthandData');
3+
const vendor = require('./vendor');
44

55
module.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
}

lib/vendor.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
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"

0 commit comments

Comments
 (0)