1c05eb35b34d0488bc2e8e4f7be9669461fce40f
[yaffs-website] / node_modules / uncss / node_modules / postcss / lib / root.js
1 'use strict';
2
3 exports.__esModule = true;
4
5 var _container = require('./container');
6
7 var _container2 = _interopRequireDefault(_container);
8
9 var _warnOnce = require('./warn-once');
10
11 var _warnOnce2 = _interopRequireDefault(_warnOnce);
12
13 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
15 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
16
17 function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
18
19 function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
20
21 var Root = function (_Container) {
22     _inherits(Root, _Container);
23
24     function Root(defaults) {
25         _classCallCheck(this, Root);
26
27         var _this = _possibleConstructorReturn(this, _Container.call(this, defaults));
28
29         _this.type = 'root';
30
31         if (!_this.nodes) _this.nodes = [];
32         return _this;
33     }
34
35     Root.prototype.removeChild = function removeChild(child) {
36         child = this.index(child);
37
38         if (child === 0 && this.nodes.length > 1) {
39             this.nodes[1].raws.before = this.nodes[child].raws.before;
40         }
41
42         return _Container.prototype.removeChild.call(this, child);
43     };
44
45     Root.prototype.normalize = function normalize(child, sample, type) {
46         var nodes = _Container.prototype.normalize.call(this, child);
47
48         if (sample) {
49             if (type === 'prepend') {
50                 if (this.nodes.length > 1) {
51                     sample.raws.before = this.nodes[1].raws.before;
52                 } else {
53                     delete sample.raws.before;
54                 }
55             } else if (this.first !== sample) {
56                 for (var _iterator = nodes, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
57                     var _ref;
58
59                     if (_isArray) {
60                         if (_i >= _iterator.length) break;
61                         _ref = _iterator[_i++];
62                     } else {
63                         _i = _iterator.next();
64                         if (_i.done) break;
65                         _ref = _i.value;
66                     }
67
68                     var node = _ref;
69
70                     node.raws.before = sample.raws.before;
71                 }
72             }
73         }
74
75         return nodes;
76     };
77
78     Root.prototype.toResult = function toResult() {
79         var opts = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
80
81         var LazyResult = require('./lazy-result');
82         var Processor = require('./processor');
83
84         var lazy = new LazyResult(new Processor(), this, opts);
85         return lazy.stringify();
86     };
87
88     /* istanbul ignore next */
89
90
91     Root.prototype.remove = function remove(child) {
92         (0, _warnOnce2.default)('Root#remove is deprecated. Use Root#removeChild');
93         this.removeChild(child);
94     };
95
96     /* istanbul ignore next */
97
98
99     Root.prototype.prevMap = function prevMap() {
100         (0, _warnOnce2.default)('Root#prevMap is deprecated. Use Root#source.input.map');
101         return this.source.input.map;
102     };
103
104     return Root;
105 }(_container2.default);
106
107 exports.default = Root;
108 module.exports = exports['default'];