3b0d07c509abb6e6589b5a92f17f99b54f42d62d
[yaffs-website] / node_modules / uncss / node_modules / postcss / lib / processor.js
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 _lazyResult = require('./lazy-result');
8
9 var _lazyResult2 = _interopRequireDefault(_lazyResult);
10
11 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
13 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
14
15 var Processor = function () {
16     function Processor() {
17         var plugins = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0];
18
19         _classCallCheck(this, Processor);
20
21         this.version = '5.0.14';
22
23         this.plugins = this.normalize(plugins);
24     }
25
26     Processor.prototype.use = function use(plugin) {
27         this.plugins = this.plugins.concat(this.normalize([plugin]));
28         return this;
29     };
30
31     Processor.prototype.process = function process(css) {
32         var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
33
34         return new _lazyResult2.default(this, css, opts);
35     };
36
37     Processor.prototype.normalize = function normalize(plugins) {
38         var normalized = [];
39         for (var _iterator = plugins, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
40             var _ref;
41
42             if (_isArray) {
43                 if (_i >= _iterator.length) break;
44                 _ref = _iterator[_i++];
45             } else {
46                 _i = _iterator.next();
47                 if (_i.done) break;
48                 _ref = _i.value;
49             }
50
51             var i = _ref;
52
53             if (i.postcss) i = i.postcss;
54
55             if ((typeof i === 'undefined' ? 'undefined' : _typeof(i)) === 'object' && Array.isArray(i.plugins)) {
56                 normalized = normalized.concat(i.plugins);
57             } else if (typeof i === 'function') {
58                 normalized.push(i);
59             } else {
60                 throw new Error(i + ' is not a PostCSS plugin');
61             }
62         }
63         return normalized;
64     };
65
66     return Processor;
67 }();
68
69 exports.default = Processor;
70 module.exports = exports['default'];