Security update for Core, with self-updated composer
[yaffs-website] / node_modules / uncss / node_modules / postcss / lib / node.js
1 'use strict';
2
3 exports.__esModule = true;
4
5 var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
6
7 var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
8
9 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; };
10
11 var _cssSyntaxError = require('./css-syntax-error');
12
13 var _cssSyntaxError2 = _interopRequireDefault(_cssSyntaxError);
14
15 var _stringifier = require('./stringifier');
16
17 var _stringifier2 = _interopRequireDefault(_stringifier);
18
19 var _stringify = require('./stringify');
20
21 var _stringify2 = _interopRequireDefault(_stringify);
22
23 var _warnOnce = require('./warn-once');
24
25 var _warnOnce2 = _interopRequireDefault(_warnOnce);
26
27 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
28
29 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
30
31 var cloneNode = function cloneNode(obj, parent) {
32     var cloned = new obj.constructor();
33
34     for (var i in obj) {
35         if (!obj.hasOwnProperty(i)) continue;
36         var value = obj[i];
37         var type = typeof value === 'undefined' ? 'undefined' : _typeof(value);
38
39         if (i === 'parent' && type === 'object') {
40             if (parent) cloned[i] = parent;
41         } else if (i === 'source') {
42             cloned[i] = value;
43         } else if (value instanceof Array) {
44             cloned[i] = value.map(function (j) {
45                 return cloneNode(j, cloned);
46             });
47         } else if (i !== 'before' && i !== 'after' && i !== 'between' && i !== 'semicolon') {
48             if (type === 'object' && value !== null) value = cloneNode(value);
49             cloned[i] = value;
50         }
51     }
52
53     return cloned;
54 };
55
56 var Node = function () {
57     function Node() {
58         var defaults = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
59
60         _classCallCheck(this, Node);
61
62         this.raws = {};
63
64         for (var name in defaults) {
65             this[name] = defaults[name];
66         }
67     }
68
69     Node.prototype.error = function error(message) {
70         var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
71
72         if (this.source) {
73             var pos = this.positionBy(opts);
74             return this.source.input.error(message, pos.line, pos.column, opts);
75         } else {
76             return new _cssSyntaxError2.default(message);
77         }
78     };
79
80     Node.prototype.warn = function warn(result, text, opts) {
81         return result.warn(text, _extends({ node: this }, opts));
82     };
83
84     Node.prototype.remove = function remove() {
85         if (this.parent) {
86             this.parent.removeChild(this);
87         }
88         this.parent = undefined;
89         return this;
90     };
91
92     Node.prototype.toString = function toString() {
93         var stringifier = arguments.length <= 0 || arguments[0] === undefined ? _stringify2.default : arguments[0];
94
95         if (stringifier.stringify) stringifier = stringifier.stringify;
96         var result = '';
97         stringifier(this, function (i) {
98             result += i;
99         });
100         return result;
101     };
102
103     Node.prototype.clone = function clone() {
104         var overrides = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
105
106         var cloned = cloneNode(this);
107         for (var name in overrides) {
108             cloned[name] = overrides[name];
109         }
110         return cloned;
111     };
112
113     Node.prototype.cloneBefore = function cloneBefore() {
114         var overrides = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
115
116         var cloned = this.clone(overrides);
117         this.parent.insertBefore(this, cloned);
118         return cloned;
119     };
120
121     Node.prototype.cloneAfter = function cloneAfter() {
122         var overrides = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
123
124         var cloned = this.clone(overrides);
125         this.parent.insertAfter(this, cloned);
126         return cloned;
127     };
128
129     Node.prototype.replaceWith = function replaceWith() {
130         if (this.parent) {
131             for (var _len = arguments.length, nodes = Array(_len), _key = 0; _key < _len; _key++) {
132                 nodes[_key] = arguments[_key];
133             }
134
135             for (var _iterator = nodes, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
136                 var _ref;
137
138                 if (_isArray) {
139                     if (_i >= _iterator.length) break;
140                     _ref = _iterator[_i++];
141                 } else {
142                     _i = _iterator.next();
143                     if (_i.done) break;
144                     _ref = _i.value;
145                 }
146
147                 var node = _ref;
148
149                 this.parent.insertBefore(this, node);
150             }
151
152             this.remove();
153         }
154
155         return this;
156     };
157
158     Node.prototype.moveTo = function moveTo(container) {
159         this.cleanRaws(this.root() === container.root());
160         this.remove();
161         container.append(this);
162         return this;
163     };
164
165     Node.prototype.moveBefore = function moveBefore(node) {
166         this.cleanRaws(this.root() === node.root());
167         this.remove();
168         node.parent.insertBefore(node, this);
169         return this;
170     };
171
172     Node.prototype.moveAfter = function moveAfter(node) {
173         this.cleanRaws(this.root() === node.root());
174         this.remove();
175         node.parent.insertAfter(node, this);
176         return this;
177     };
178
179     Node.prototype.next = function next() {
180         var index = this.parent.index(this);
181         return this.parent.nodes[index + 1];
182     };
183
184     Node.prototype.prev = function prev() {
185         var index = this.parent.index(this);
186         return this.parent.nodes[index - 1];
187     };
188
189     Node.prototype.toJSON = function toJSON() {
190         var fixed = {};
191
192         for (var name in this) {
193             if (!this.hasOwnProperty(name)) continue;
194             if (name === 'parent') continue;
195             var value = this[name];
196
197             if (value instanceof Array) {
198                 fixed[name] = value.map(function (i) {
199                     if ((typeof i === 'undefined' ? 'undefined' : _typeof(i)) === 'object' && i.toJSON) {
200                         return i.toJSON();
201                     } else {
202                         return i;
203                     }
204                 });
205             } else if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && value.toJSON) {
206                 fixed[name] = value.toJSON();
207             } else {
208                 fixed[name] = value;
209             }
210         }
211
212         return fixed;
213     };
214
215     Node.prototype.raw = function raw(own, detect) {
216         var str = new _stringifier2.default();
217         return str.raw(this, own, detect);
218     };
219
220     Node.prototype.root = function root() {
221         var result = this;
222         while (result.parent) {
223             result = result.parent;
224         }return result;
225     };
226
227     Node.prototype.cleanRaws = function cleanRaws(keepBetween) {
228         delete this.raws.before;
229         delete this.raws.after;
230         if (!keepBetween) delete this.raws.between;
231     };
232
233     Node.prototype.positionInside = function positionInside(index) {
234         var string = this.toString();
235         var column = this.source.start.column;
236         var line = this.source.start.line;
237
238         for (var i = 0; i < index; i++) {
239             if (string[i] === '\n') {
240                 column = 1;
241                 line += 1;
242             } else {
243                 column += 1;
244             }
245         }
246
247         return { line: line, column: column };
248     };
249
250     Node.prototype.positionBy = function positionBy(opts) {
251         var pos = this.source.start;
252         if (opts.index) {
253             pos = this.positionInside(opts.index);
254         } else if (opts.word) {
255             var index = this.toString().indexOf(opts.word);
256             if (index !== -1) pos = this.positionInside(index);
257         }
258         return pos;
259     };
260
261     /* istanbul ignore next */
262
263
264     Node.prototype.removeSelf = function removeSelf() {
265         (0, _warnOnce2.default)('Node#removeSelf is deprecated. Use Node#remove.');
266         return this.remove();
267     };
268
269     /* istanbul ignore next */
270
271
272     Node.prototype.replace = function replace(nodes) {
273         (0, _warnOnce2.default)('Node#replace is deprecated. Use Node#replaceWith');
274         return this.replaceWith(nodes);
275     };
276
277     /* istanbul ignore next */
278
279
280     Node.prototype.style = function style(own, detect) {
281         (0, _warnOnce2.default)('Node#style() is deprecated. Use Node#raw()');
282         return this.raw(own, detect);
283     };
284
285     /* istanbul ignore next */
286
287
288     Node.prototype.cleanStyles = function cleanStyles(keepBetween) {
289         (0, _warnOnce2.default)('Node#cleanStyles() is deprecated. Use Node#cleanRaws()');
290         return this.cleanRaws(keepBetween);
291     };
292
293     /* istanbul ignore next */
294
295
296     _createClass(Node, [{
297         key: 'before',
298         get: function get() {
299             (0, _warnOnce2.default)('Node#before is deprecated. Use Node#raws.before');
300             return this.raws.before;
301         }
302
303         /* istanbul ignore next */
304         ,
305         set: function set(val) {
306             (0, _warnOnce2.default)('Node#before is deprecated. Use Node#raws.before');
307             this.raws.before = val;
308         }
309
310         /* istanbul ignore next */
311
312     }, {
313         key: 'between',
314         get: function get() {
315             (0, _warnOnce2.default)('Node#between is deprecated. Use Node#raws.between');
316             return this.raws.between;
317         }
318
319         /* istanbul ignore next */
320         ,
321         set: function set(val) {
322             (0, _warnOnce2.default)('Node#between is deprecated. Use Node#raws.between');
323             this.raws.between = val;
324         }
325     }]);
326
327     return Node;
328 }();
329
330 exports.default = Node;
331 module.exports = exports['default'];