3 exports.__esModule = true;
5 var _container = require('./container');
7 var _container2 = _interopRequireDefault(_container);
9 var _warnOnce = require('./warn-once');
11 var _warnOnce2 = _interopRequireDefault(_warnOnce);
13 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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; }
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; }
21 var Root = function (_Container) {
22 _inherits(Root, _Container);
24 function Root(defaults) {
25 _classCallCheck(this, Root);
27 var _this = _possibleConstructorReturn(this, _Container.call(this, defaults));
31 if (!_this.nodes) _this.nodes = [];
35 Root.prototype.removeChild = function removeChild(child) {
36 child = this.index(child);
38 if (child === 0 && this.nodes.length > 1) {
39 this.nodes[1].raws.before = this.nodes[child].raws.before;
42 return _Container.prototype.removeChild.call(this, child);
45 Root.prototype.normalize = function normalize(child, sample, type) {
46 var nodes = _Container.prototype.normalize.call(this, child);
49 if (type === 'prepend') {
50 if (this.nodes.length > 1) {
51 sample.raws.before = this.nodes[1].raws.before;
53 delete sample.raws.before;
55 } else if (this.first !== sample) {
56 for (var _iterator = nodes, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
60 if (_i >= _iterator.length) break;
61 _ref = _iterator[_i++];
63 _i = _iterator.next();
70 node.raws.before = sample.raws.before;
78 Root.prototype.toResult = function toResult() {
79 var opts = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
81 var LazyResult = require('./lazy-result');
82 var Processor = require('./processor');
84 var lazy = new LazyResult(new Processor(), this, opts);
85 return lazy.stringify();
88 /* istanbul ignore next */
91 Root.prototype.remove = function remove(child) {
92 (0, _warnOnce2.default)('Root#remove is deprecated. Use Root#removeChild');
93 this.removeChild(child);
96 /* istanbul ignore next */
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;
105 }(_container2.default);
107 exports.default = Root;
108 module.exports = exports['default'];