postcss-merge-idents 2.1.3 → 2.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ # 2.1.7
2
+
3
+ * Replaced the `has-own` module with `has`.
4
+
5
+ # 2.1.6
6
+
7
+ * Fixes an issue where the module would discard at-rules that were defined in
8
+ `@media` & `@supports` rules as well as the root. As this is legal to do in
9
+ CSS, the module now checks to see if the candidate rule has the same parent
10
+ as the cached rule. If it does, the rules are merged.
11
+
12
+ # 2.1.5
13
+
14
+ * Now compiled with babel 6.
15
+
16
+ # 2.1.4
17
+
18
+ * Fixed a range error which happened when duplicated at rules were found
19
+ in the stylesheet.
20
+
1
21
  # 2.1.3
2
22
 
3
23
  * Fixed an infinite loop regression in the last patch.
package/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  > Merge keyframe and counter style identifiers.
4
4
 
5
+
5
6
  ## Install
6
7
 
7
8
  With [npm](https://npmjs.org/package/postcss-merge-idents) do:
@@ -10,6 +11,7 @@ With [npm](https://npmjs.org/package/postcss-merge-idents) do:
10
11
  npm install postcss-merge-idents --save
11
12
  ```
12
13
 
14
+
13
15
  ## Example
14
16
 
15
17
  This module will merge identifiers such as `@keyframes` and `@counter-style`,
@@ -55,20 +57,24 @@ depend on the duplicated property.
55
57
  }
56
58
  ```
57
59
 
60
+
58
61
  ## Usage
59
62
 
60
63
  See the [PostCSS documentation](https://github.com/postcss/postcss#usage) for
61
64
  examples for your environment.
62
65
 
66
+
63
67
  ## Contributing
64
68
 
65
69
  Pull requests are welcome. If you add functionality, then please add unit tests
66
70
  to cover it.
67
71
 
72
+
68
73
  ## License
69
74
 
70
75
  MIT © [Ben Briggs](http://beneb.info)
71
76
 
77
+
72
78
  [ci]: https://travis-ci.org/ben-eb/postcss-merge-idents
73
79
  [deps]: https://gemnasium.com/ben-eb/postcss-merge-idents
74
80
  [npm]: http://badge.fury.io/js/postcss-merge-idents
package/dist/index.js ADDED
@@ -0,0 +1,116 @@
1
+ 'use strict';
2
+
3
+ exports.__esModule = true;
4
+
5
+ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
6
+
7
+ var _has = require('has');
8
+
9
+ var _has2 = _interopRequireDefault(_has);
10
+
11
+ var _postcss = require('postcss');
12
+
13
+ var _postcssValueParser = require('postcss-value-parser');
14
+
15
+ var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser);
16
+
17
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
+
19
+ function canonical(obj) {
20
+ return function recurse(key) {
21
+ if ((0, _has2.default)(obj, key) && obj[key] !== key) {
22
+ return recurse(obj[key]);
23
+ }
24
+ return key;
25
+ };
26
+ }
27
+
28
+ function sameParent(ruleA, ruleB) {
29
+ var hasParent = ruleA.parent && ruleB.parent;
30
+ var sameType = hasParent && ruleA.parent.type === ruleB.parent.type;
31
+ // If an at rule, ensure that the parameters are the same
32
+ if (hasParent && ruleA.parent.type !== 'root' && ruleB.parent.type !== 'root') {
33
+ sameType = sameType && ruleA.parent.params === ruleB.parent.params && ruleA.parent.name === ruleB.parent.name;
34
+ }
35
+ return hasParent ? sameType : true;
36
+ }
37
+
38
+ function mergeAtRules(css, pairs) {
39
+ pairs.forEach(function (pair) {
40
+ pair.cache = [];
41
+ pair.replacements = [];
42
+ pair.decls = [];
43
+ });
44
+
45
+ var relevant = void 0;
46
+
47
+ css.walk(function (node) {
48
+ if (node.type === 'atrule') {
49
+ relevant = pairs.filter(function (pair) {
50
+ return pair.atrule.test(node.name);
51
+ })[0];
52
+ if (!relevant) {
53
+ return;
54
+ }
55
+ if (relevant.cache.length < 1) {
56
+ relevant.cache.push(node);
57
+ return;
58
+ } else {
59
+ var _ret = function () {
60
+ var toString = node.nodes.toString();
61
+ relevant.cache.forEach(function (cached) {
62
+ if (cached.name === node.name && sameParent(cached, node) && cached.nodes.toString() === toString) {
63
+ cached.remove();
64
+ relevant.replacements[cached.params] = node.params;
65
+ }
66
+ });
67
+ relevant.cache.push(node);
68
+ return {
69
+ v: void 0
70
+ };
71
+ }();
72
+
73
+ if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v;
74
+ }
75
+ }
76
+ if (node.type === 'decl') {
77
+ relevant = pairs.filter(function (pair) {
78
+ return pair.decl.test(node.prop);
79
+ })[0];
80
+ if (!relevant) {
81
+ return;
82
+ }
83
+ relevant.decls.push(node);
84
+ }
85
+ });
86
+
87
+ pairs.forEach(function (pair) {
88
+ var canon = canonical(pair.replacements);
89
+ pair.decls.forEach(function (decl) {
90
+ decl.value = (0, _postcssValueParser2.default)(decl.value).walk(function (node) {
91
+ if (node.type === 'word') {
92
+ node.value = canon(node.value);
93
+ }
94
+ if (node.type === 'space') {
95
+ node.value = ' ';
96
+ }
97
+ if (node.type === 'div') {
98
+ node.before = node.after = '';
99
+ }
100
+ }).toString();
101
+ });
102
+ });
103
+ }
104
+
105
+ exports.default = (0, _postcss.plugin)('postcss-merge-idents', function () {
106
+ return function (css) {
107
+ mergeAtRules(css, [{
108
+ atrule: /keyframes/,
109
+ decl: /animation/
110
+ }, {
111
+ atrule: /counter-style/,
112
+ decl: /(list-style|system)/
113
+ }]);
114
+ };
115
+ });
116
+ module.exports = exports['default'];
package/package.json CHANGED
@@ -1,14 +1,17 @@
1
1
  {
2
2
  "name": "postcss-merge-idents",
3
- "version": "2.1.3",
3
+ "version": "2.1.7",
4
4
  "description": "Merge keyframe and counter style identifiers.",
5
- "main": "index.js",
5
+ "main": "dist/index.js",
6
6
  "files": [
7
- "index.js",
7
+ "dist",
8
8
  "LICENSE-MIT"
9
9
  ],
10
10
  "scripts": {
11
- "test": "tape test.js | tap-spec"
11
+ "pretest": "eslint src",
12
+ "prepublish": "del-cli dist && BABEL_ENV=publish babel src --out-dir dist --ignore /__tests__/",
13
+ "test": "ava src/__tests__",
14
+ "test-012": "ava src/__tests__"
12
15
  },
13
16
  "keywords": [
14
17
  "css",
@@ -18,8 +21,19 @@
18
21
  ],
19
22
  "license": "MIT",
20
23
  "devDependencies": {
21
- "tap-spec": "^4.1.0",
22
- "tape": "^4.2.2"
24
+ "ava": "^0.16.0",
25
+ "babel-cli": "^6.3.17",
26
+ "babel-core": "^6.3.26",
27
+ "babel-plugin-add-module-exports": "^0.2.1",
28
+ "babel-preset-es2015": "^6.3.13",
29
+ "babel-preset-es2015-loose": "^7.0.0",
30
+ "babel-preset-stage-0": "^6.3.13",
31
+ "babel-register": "^6.9.0",
32
+ "del-cli": "^0.2.0",
33
+ "eslint": "^3.0.0",
34
+ "eslint-config-cssnano": "^3.0.0",
35
+ "eslint-plugin-babel": "^3.3.0",
36
+ "eslint-plugin-import": "^1.10.2"
23
37
  },
24
38
  "homepage": "https://github.com/ben-eb/postcss-merge-idents",
25
39
  "author": {
@@ -29,8 +43,14 @@
29
43
  },
30
44
  "repository": "ben-eb/postcss-merge-idents",
31
45
  "dependencies": {
32
- "has-own": "^1.0.0",
46
+ "has": "^1.0.1",
33
47
  "postcss": "^5.0.10",
34
48
  "postcss-value-parser": "^3.1.1"
49
+ },
50
+ "ava": {
51
+ "require": "babel-register"
52
+ },
53
+ "eslintConfig": {
54
+ "extends": "cssnano"
35
55
  }
36
56
  }
package/index.js DELETED
@@ -1,80 +0,0 @@
1
- 'use strict';
2
-
3
- var hasOwn = require('has-own');
4
- var postcss = require('postcss');
5
- var valueParser = require('postcss-value-parser');
6
-
7
- function canonical (obj) {
8
- return function recurse (key) {
9
- if (hasOwn(key, obj) && obj[key] !== key) {
10
- return recurse(obj[key]);
11
- }
12
- return key;
13
- };
14
- }
15
-
16
- function mergeAtRules (css, pairs) {
17
- pairs.forEach(function (pair) {
18
- pair.cache = [];
19
- pair.replacements = [];
20
- pair.decls = [];
21
- });
22
-
23
- var relevant;
24
-
25
- css.walk(function (node) {
26
- if (node.type === 'atrule') {
27
- relevant = pairs.filter(function (pair) {
28
- return pair.atrule.test(node.name);
29
- })[0];
30
- if (!relevant) { return; }
31
- var toString = node.nodes.toString();
32
- var cached = relevant.cache.filter(function (c) {
33
- return c.name === node.name && String(c.nodes) === toString;
34
- });
35
- var cache = relevant.cache;
36
- if (cached.length) {
37
- relevant.replacements[cached[0].params] = node.params;
38
- cached[0].remove();
39
- relevant.cache = cache.splice(cache.indexOf(cached[0]) + 1, 1);
40
- }
41
- relevant.cache.push(node);
42
- }
43
- if (node.type === 'decl') {
44
- relevant = pairs.filter(function (pair) {
45
- return pair.decl.test(node.prop);
46
- })[0];
47
- if (!relevant) { return; }
48
- relevant.decls.push(node);
49
- }
50
- });
51
-
52
- pairs.forEach(function (pair) {
53
- var canon = canonical(pair.replacements);
54
- pair.decls.forEach(function (decl) {
55
- decl.value = valueParser(decl.value).walk(function (node) {
56
- if (node.type === 'word') {
57
- node.value = canon(node.value);
58
- }
59
- if (node.type === 'space') {
60
- node.value = ' ';
61
- }
62
- if (node.type === 'div') {
63
- node.before = node.after = '';
64
- }
65
- }).toString();
66
- });
67
- });
68
- }
69
-
70
- module.exports = postcss.plugin('postcss-merge-idents', function () {
71
- return function (css) {
72
- mergeAtRules(css, [{
73
- atrule: /keyframes/,
74
- decl: /animation/
75
- }, {
76
- atrule: /counter-style/,
77
- decl: /(list-style|system)/
78
- }]);
79
- };
80
- });