.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / postcss-selector-parser / dist / parser.js
1 'use strict';
2
3 exports.__esModule = true;
4
5 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; }; }();
6
7 var _dotProp = require('dot-prop');
8
9 var _dotProp2 = _interopRequireDefault(_dotProp);
10
11 var _indexesOf = require('indexes-of');
12
13 var _indexesOf2 = _interopRequireDefault(_indexesOf);
14
15 var _uniq = require('uniq');
16
17 var _uniq2 = _interopRequireDefault(_uniq);
18
19 var _root = require('./selectors/root');
20
21 var _root2 = _interopRequireDefault(_root);
22
23 var _selector = require('./selectors/selector');
24
25 var _selector2 = _interopRequireDefault(_selector);
26
27 var _className = require('./selectors/className');
28
29 var _className2 = _interopRequireDefault(_className);
30
31 var _comment = require('./selectors/comment');
32
33 var _comment2 = _interopRequireDefault(_comment);
34
35 var _id = require('./selectors/id');
36
37 var _id2 = _interopRequireDefault(_id);
38
39 var _tag = require('./selectors/tag');
40
41 var _tag2 = _interopRequireDefault(_tag);
42
43 var _string = require('./selectors/string');
44
45 var _string2 = _interopRequireDefault(_string);
46
47 var _pseudo = require('./selectors/pseudo');
48
49 var _pseudo2 = _interopRequireDefault(_pseudo);
50
51 var _attribute = require('./selectors/attribute');
52
53 var _attribute2 = _interopRequireDefault(_attribute);
54
55 var _universal = require('./selectors/universal');
56
57 var _universal2 = _interopRequireDefault(_universal);
58
59 var _combinator = require('./selectors/combinator');
60
61 var _combinator2 = _interopRequireDefault(_combinator);
62
63 var _nesting = require('./selectors/nesting');
64
65 var _nesting2 = _interopRequireDefault(_nesting);
66
67 var _sortAscending = require('./sortAscending');
68
69 var _sortAscending2 = _interopRequireDefault(_sortAscending);
70
71 var _tokenize = require('./tokenize');
72
73 var _tokenize2 = _interopRequireDefault(_tokenize);
74
75 var _tokenTypes = require('./tokenTypes');
76
77 var tokens = _interopRequireWildcard(_tokenTypes);
78
79 var _types = require('./selectors/types');
80
81 var types = _interopRequireWildcard(_types);
82
83 function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
84
85 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
86
87 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
88
89 function getSource(startLine, startColumn, endLine, endColumn) {
90     return {
91         start: {
92             line: startLine,
93             column: startColumn
94         },
95         end: {
96             line: endLine,
97             column: endColumn
98         }
99     };
100 }
101
102 var Parser = function () {
103     function Parser(rule) {
104         var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
105
106         _classCallCheck(this, Parser);
107
108         this.rule = rule;
109         this.options = Object.assign({ lossy: false, safe: false }, options);
110         this.position = 0;
111         this.root = new _root2.default();
112         this.root.errorGenerator = this._errorGenerator();
113
114         var selector = new _selector2.default();
115         this.root.append(selector);
116         this.current = selector;
117
118         this.css = typeof this.rule === 'string' ? this.rule : this.rule.selector;
119
120         if (this.options.lossy) {
121             this.css = this.css.trim();
122         }
123         this.tokens = (0, _tokenize2.default)({
124             css: this.css,
125             error: this._errorGenerator(),
126             safe: this.options.safe
127         });
128
129         this.loop();
130     }
131
132     Parser.prototype._errorGenerator = function _errorGenerator() {
133         var _this = this;
134
135         return function (message, errorOptions) {
136             if (typeof _this.rule === 'string') {
137                 return new Error(message);
138             }
139             return _this.rule.error(message, errorOptions);
140         };
141     };
142
143     Parser.prototype.attribute = function attribute() {
144         var attr = [];
145         var startingToken = this.currToken;
146         this.position++;
147         while (this.position < this.tokens.length && this.currToken[0] !== tokens.closeSquare) {
148             attr.push(this.currToken);
149             this.position++;
150         }
151         if (this.currToken[0] !== tokens.closeSquare) {
152             return this.expected('closing square bracket', this.currToken[5]);
153         }
154
155         var len = attr.length;
156         var node = {
157             source: getSource(startingToken[1], startingToken[2], this.currToken[3], this.currToken[4]),
158             sourceIndex: startingToken[5]
159         };
160
161         if (len === 1 && !~[tokens.word].indexOf(attr[0][0])) {
162             return this.expected('attribute', attr[0][5]);
163         }
164
165         var pos = 0;
166         var spaceBefore = '';
167         var commentBefore = '';
168         var lastAdded = null;
169         var spaceAfterMeaningfulToken = false;
170
171         while (pos < len) {
172             var token = attr[pos];
173             var content = this.content(token);
174             var next = attr[pos + 1];
175
176             switch (token[0]) {
177                 case tokens.space:
178                     if (len === 1 || pos === 0 && this.content(next) === '|') {
179                         return this.expected('attribute', token[5], content);
180                     }
181                     spaceAfterMeaningfulToken = true;
182                     if (this.options.lossy) {
183                         break;
184                     }
185                     if (lastAdded) {
186                         var spaceProp = 'spaces.' + lastAdded + '.after';
187                         _dotProp2.default.set(node, spaceProp, _dotProp2.default.get(node, spaceProp, '') + content);
188                         var commentProp = 'raws.spaces.' + lastAdded + '.after';
189                         var existingComment = _dotProp2.default.get(node, commentProp);
190                         if (existingComment) {
191                             _dotProp2.default.set(node, commentProp, existingComment + content);
192                         }
193                     } else {
194                         spaceBefore = spaceBefore + content;
195                         commentBefore = commentBefore + content;
196                     }
197                     break;
198                 case tokens.asterisk:
199                     if (next[0] === tokens.equals) {
200                         node.operator = content;
201                         lastAdded = 'operator';
202                     } else if ((!node.namespace || lastAdded === "namespace" && !spaceAfterMeaningfulToken) && next) {
203                         if (spaceBefore) {
204                             _dotProp2.default.set(node, 'spaces.attribute.before', spaceBefore);
205                             spaceBefore = '';
206                         }
207                         if (commentBefore) {
208                             _dotProp2.default.set(node, 'raws.spaces.attribute.before', spaceBefore);
209                             commentBefore = '';
210                         }
211                         node.namespace = (node.namespace || "") + content;
212                         var rawValue = _dotProp2.default.get(node, "raws.namespace");
213                         if (rawValue) {
214                             node.raws.namespace += content;
215                         }
216                         lastAdded = 'namespace';
217                     }
218                     spaceAfterMeaningfulToken = false;
219                     break;
220                 case tokens.dollar:
221                 case tokens.caret:
222                     if (next[0] === tokens.equals) {
223                         node.operator = content;
224                         lastAdded = 'operator';
225                     }
226                     spaceAfterMeaningfulToken = false;
227                     break;
228                 case tokens.combinator:
229                     if (content === '~' && next[0] === tokens.equals) {
230                         node.operator = content;
231                         lastAdded = 'operator';
232                     }
233                     if (content !== '|') {
234                         spaceAfterMeaningfulToken = false;
235                         break;
236                     }
237                     if (next[0] === tokens.equals) {
238                         node.operator = content;
239                         lastAdded = 'operator';
240                     } else if (!node.namespace && !node.attribute) {
241                         node.namespace = true;
242                     }
243                     spaceAfterMeaningfulToken = false;
244                     break;
245                 case tokens.word:
246                     if (next && this.content(next) === '|' && attr[pos + 2] && attr[pos + 2][0] !== tokens.equals && // this look-ahead probably fails with comment nodes involved.
247                     !node.operator && !node.namespace) {
248                         node.namespace = content;
249                         lastAdded = 'namespace';
250                     } else if (!node.attribute || lastAdded === "attribute" && !spaceAfterMeaningfulToken) {
251                         if (spaceBefore) {
252                             _dotProp2.default.set(node, 'spaces.attribute.before', spaceBefore);
253                             spaceBefore = '';
254                         }
255                         if (commentBefore) {
256                             _dotProp2.default.set(node, 'raws.spaces.attribute.before', commentBefore);
257                             commentBefore = '';
258                         }
259                         node.attribute = (node.attribute || "") + content;
260                         var _rawValue = _dotProp2.default.get(node, "raws.attribute");
261                         if (_rawValue) {
262                             node.raws.attribute += content;
263                         }
264                         lastAdded = 'attribute';
265                     } else if (!node.value || lastAdded === "value" && !spaceAfterMeaningfulToken) {
266                         node.value = (node.value || "") + content;
267                         var _rawValue2 = _dotProp2.default.get(node, "raws.value");
268                         if (_rawValue2) {
269                             node.raws.value += content;
270                         }
271                         lastAdded = 'value';
272                         _dotProp2.default.set(node, 'raws.unquoted', _dotProp2.default.get(node, 'raws.unquoted', '') + content);
273                     } else if (content === 'i') {
274                         if (node.value && (node.quoted || spaceAfterMeaningfulToken)) {
275                             node.insensitive = true;
276                             lastAdded = 'insensitive';
277                             if (spaceBefore) {
278                                 _dotProp2.default.set(node, 'spaces.insensitive.before', spaceBefore);
279                                 spaceBefore = '';
280                             }
281                             if (commentBefore) {
282                                 _dotProp2.default.set(node, 'raws.spaces.insensitive.before', commentBefore);
283                                 commentBefore = '';
284                             }
285                         } else if (node.value) {
286                             lastAdded = 'value';
287                             node.value += 'i';
288                             if (node.raws.value) {
289                                 node.raws.value += 'i';
290                             }
291                         }
292                     }
293                     spaceAfterMeaningfulToken = false;
294                     break;
295                 case tokens.str:
296                     if (!node.attribute || !node.operator) {
297                         return this.error('Expected an attribute followed by an operator preceding the string.', {
298                             index: token[5]
299                         });
300                     }
301                     node.value = content;
302                     node.quoted = true;
303                     lastAdded = 'value';
304                     _dotProp2.default.set(node, 'raws.unquoted', content.slice(1, -1));
305                     spaceAfterMeaningfulToken = false;
306                     break;
307                 case tokens.equals:
308                     if (!node.attribute) {
309                         return this.expected('attribute', token[5], content);
310                     }
311                     if (node.value) {
312                         return this.error('Unexpected "=" found; an operator was already defined.', { index: token[5] });
313                     }
314                     node.operator = node.operator ? node.operator + content : content;
315                     lastAdded = 'operator';
316                     spaceAfterMeaningfulToken = false;
317                     break;
318                 case tokens.comment:
319                     if (lastAdded) {
320                         if (spaceAfterMeaningfulToken || next && next[0] === tokens.space) {
321                             var lastComment = _dotProp2.default.get(node, 'raws.spaces.' + lastAdded + '.after', _dotProp2.default.get(node, 'spaces.' + lastAdded + '.after', ''));
322                             _dotProp2.default.set(node, 'raws.spaces.' + lastAdded + '.after', lastComment + content);
323                         } else {
324                             var lastValue = _dotProp2.default.get(node, 'raws.' + lastAdded, _dotProp2.default.get(node, lastAdded, ''));
325                             _dotProp2.default.set(node, 'raws.' + lastAdded, lastValue + content);
326                         }
327                     } else {
328                         commentBefore = commentBefore + content;
329                     }
330                     break;
331                 default:
332                     return this.error('Unexpected "' + content + '" found.', { index: token[5] });
333             }
334             pos++;
335         }
336
337         this.newNode(new _attribute2.default(node));
338         this.position++;
339     };
340
341     Parser.prototype.combinator = function combinator() {
342         var current = this.currToken;
343         if (this.content() === '|') {
344             return this.namespace();
345         }
346         var node = new _combinator2.default({
347             value: '',
348             source: getSource(current[1], current[2], current[3], current[4]),
349             sourceIndex: current[5]
350         });
351         while (this.position < this.tokens.length && this.currToken && (this.currToken[0] === tokens.space || this.currToken[0] === tokens.combinator)) {
352             var content = this.content();
353             if (this.nextToken && this.nextToken[0] === tokens.combinator) {
354                 node.spaces.before = this.parseSpace(content);
355                 node.source = getSource(this.nextToken[1], this.nextToken[2], this.nextToken[3], this.nextToken[4]);
356                 node.sourceIndex = this.nextToken[5];
357             } else if (this.prevToken && this.prevToken[0] === tokens.combinator) {
358                 node.spaces.after = this.parseSpace(content);
359             } else if (this.currToken[0] === tokens.combinator) {
360                 node.value = content;
361             } else if (this.currToken[0] === tokens.space) {
362                 node.value = this.parseSpace(content, ' ');
363             }
364             this.position++;
365         }
366         return this.newNode(node);
367     };
368
369     Parser.prototype.comma = function comma() {
370         if (this.position === this.tokens.length - 1) {
371             this.root.trailingComma = true;
372             this.position++;
373             return;
374         }
375         var selector = new _selector2.default();
376         this.current.parent.append(selector);
377         this.current = selector;
378         this.position++;
379     };
380
381     Parser.prototype.comment = function comment() {
382         var current = this.currToken;
383         this.newNode(new _comment2.default({
384             value: this.content(),
385             source: getSource(current[1], current[2], current[3], current[4]),
386             sourceIndex: current[5]
387         }));
388         this.position++;
389     };
390
391     Parser.prototype.error = function error(message, opts) {
392         throw this.root.error(message, opts);
393     };
394
395     Parser.prototype.missingBackslash = function missingBackslash() {
396         return this.error('Expected a backslash preceding the semicolon.', {
397             index: this.currToken[5]
398         });
399     };
400
401     Parser.prototype.missingParenthesis = function missingParenthesis() {
402         return this.expected('opening parenthesis', this.currToken[5]);
403     };
404
405     Parser.prototype.missingSquareBracket = function missingSquareBracket() {
406         return this.expected('opening square bracket', this.currToken[5]);
407     };
408
409     Parser.prototype.namespace = function namespace() {
410         var before = this.prevToken && this.content(this.prevToken) || true;
411         if (this.nextToken[0] === tokens.word) {
412             this.position++;
413             return this.word(before);
414         } else if (this.nextToken[0] === tokens.asterisk) {
415             this.position++;
416             return this.universal(before);
417         }
418     };
419
420     Parser.prototype.nesting = function nesting() {
421         var current = this.currToken;
422         this.newNode(new _nesting2.default({
423             value: this.content(),
424             source: getSource(current[1], current[2], current[3], current[4]),
425             sourceIndex: current[5]
426         }));
427         this.position++;
428     };
429
430     Parser.prototype.parentheses = function parentheses() {
431         var last = this.current.last;
432         var balanced = 1;
433         this.position++;
434         if (last && last.type === types.PSEUDO) {
435             var selector = new _selector2.default();
436             var cache = this.current;
437             last.append(selector);
438             this.current = selector;
439             while (this.position < this.tokens.length && balanced) {
440                 if (this.currToken[0] === tokens.openParenthesis) {
441                     balanced++;
442                 }
443                 if (this.currToken[0] === tokens.closeParenthesis) {
444                     balanced--;
445                 }
446                 if (balanced) {
447                     this.parse();
448                 } else {
449                     selector.parent.source.end.line = this.currToken[3];
450                     selector.parent.source.end.column = this.currToken[4];
451                     this.position++;
452                 }
453             }
454             this.current = cache;
455         } else {
456             last.value += '(';
457             while (this.position < this.tokens.length && balanced) {
458                 if (this.currToken[0] === tokens.openParenthesis) {
459                     balanced++;
460                 }
461                 if (this.currToken[0] === tokens.closeParenthesis) {
462                     balanced--;
463                 }
464                 last.value += this.parseParenthesisToken(this.currToken);
465                 this.position++;
466             }
467         }
468         if (balanced) {
469             return this.expected('closing parenthesis', this.currToken[5]);
470         }
471     };
472
473     Parser.prototype.pseudo = function pseudo() {
474         var _this2 = this;
475
476         var pseudoStr = '';
477         var startingToken = this.currToken;
478         while (this.currToken && this.currToken[0] === tokens.colon) {
479             pseudoStr += this.content();
480             this.position++;
481         }
482         if (!this.currToken) {
483             return this.expected(['pseudo-class', 'pseudo-element'], this.position - 1);
484         }
485         if (this.currToken[0] === tokens.word) {
486             this.splitWord(false, function (first, length) {
487                 pseudoStr += first;
488                 _this2.newNode(new _pseudo2.default({
489                     value: pseudoStr,
490                     source: getSource(startingToken[1], startingToken[2], _this2.currToken[3], _this2.currToken[4]),
491                     sourceIndex: startingToken[5]
492                 }));
493                 if (length > 1 && _this2.nextToken && _this2.nextToken[0] === tokens.openParenthesis) {
494                     _this2.error('Misplaced parenthesis.', {
495                         index: _this2.nextToken[5]
496                     });
497                 }
498             });
499         } else {
500             return this.expected(['pseudo-class', 'pseudo-element'], this.currToken[5]);
501         }
502     };
503
504     Parser.prototype.space = function space() {
505         var content = this.content();
506         // Handle space before and after the selector
507         if (this.position === 0 || this.prevToken[0] === tokens.comma || this.prevToken[0] === tokens.openParenthesis) {
508             this.spaces = this.parseSpace(content);
509             this.position++;
510         } else if (this.position === this.tokens.length - 1 || this.nextToken[0] === tokens.comma || this.nextToken[0] === tokens.closeParenthesis) {
511             this.current.last.spaces.after = this.parseSpace(content);
512             this.position++;
513         } else {
514             this.combinator();
515         }
516     };
517
518     Parser.prototype.string = function string() {
519         var current = this.currToken;
520         this.newNode(new _string2.default({
521             value: this.content(),
522             source: getSource(current[1], current[2], current[3], current[4]),
523             sourceIndex: current[5]
524         }));
525         this.position++;
526     };
527
528     Parser.prototype.universal = function universal(namespace) {
529         var nextToken = this.nextToken;
530         if (nextToken && this.content(nextToken) === '|') {
531             this.position++;
532             return this.namespace();
533         }
534         var current = this.currToken;
535         this.newNode(new _universal2.default({
536             value: this.content(),
537             source: getSource(current[1], current[2], current[3], current[4]),
538             sourceIndex: current[5]
539         }), namespace);
540         this.position++;
541     };
542
543     Parser.prototype.splitWord = function splitWord(namespace, firstCallback) {
544         var _this3 = this;
545
546         var nextToken = this.nextToken;
547         var word = this.content();
548         while (nextToken && ~[tokens.dollar, tokens.caret, tokens.equals, tokens.word].indexOf(nextToken[0])) {
549             this.position++;
550             var current = this.content();
551             word += current;
552             if (current.lastIndexOf('\\') === current.length - 1) {
553                 var next = this.nextToken;
554                 if (next && next[0] === tokens.space) {
555                     word += this.parseSpace(this.content(next), ' ');
556                     this.position++;
557                 }
558             }
559             nextToken = this.nextToken;
560         }
561         var hasClass = (0, _indexesOf2.default)(word, '.');
562         var hasId = (0, _indexesOf2.default)(word, '#');
563         // Eliminate Sass interpolations from the list of id indexes
564         var interpolations = (0, _indexesOf2.default)(word, '#{');
565         if (interpolations.length) {
566             hasId = hasId.filter(function (hashIndex) {
567                 return !~interpolations.indexOf(hashIndex);
568             });
569         }
570         var indices = (0, _sortAscending2.default)((0, _uniq2.default)([0].concat(hasClass, hasId)));
571         indices.forEach(function (ind, i) {
572             var index = indices[i + 1] || word.length;
573             var value = word.slice(ind, index);
574             if (i === 0 && firstCallback) {
575                 return firstCallback.call(_this3, value, indices.length);
576             }
577             var node = void 0;
578             var current = _this3.currToken;
579             var sourceIndex = current[5] + indices[i];
580             var source = getSource(current[1], current[2] + ind, current[3], current[2] + (index - 1));
581             if (~hasClass.indexOf(ind)) {
582                 node = new _className2.default({
583                     value: value.slice(1),
584                     source: source,
585                     sourceIndex: sourceIndex
586                 });
587             } else if (~hasId.indexOf(ind)) {
588                 node = new _id2.default({
589                     value: value.slice(1),
590                     source: source,
591                     sourceIndex: sourceIndex
592                 });
593             } else {
594                 node = new _tag2.default({
595                     value: value,
596                     source: source,
597                     sourceIndex: sourceIndex
598                 });
599             }
600             _this3.newNode(node, namespace);
601             // Ensure that the namespace is used only once
602             namespace = null;
603         });
604         this.position++;
605     };
606
607     Parser.prototype.word = function word(namespace) {
608         var nextToken = this.nextToken;
609         if (nextToken && this.content(nextToken) === '|') {
610             this.position++;
611             return this.namespace();
612         }
613         return this.splitWord(namespace);
614     };
615
616     Parser.prototype.loop = function loop() {
617         while (this.position < this.tokens.length) {
618             this.parse(true);
619         }
620         return this.root;
621     };
622
623     Parser.prototype.parse = function parse(throwOnParenthesis) {
624         switch (this.currToken[0]) {
625             case tokens.space:
626                 this.space();
627                 break;
628             case tokens.comment:
629                 this.comment();
630                 break;
631             case tokens.openParenthesis:
632                 this.parentheses();
633                 break;
634             case tokens.closeParenthesis:
635                 if (throwOnParenthesis) {
636                     this.missingParenthesis();
637                 }
638                 break;
639             case tokens.openSquare:
640                 this.attribute();
641                 break;
642             case tokens.dollar:
643             case tokens.caret:
644             case tokens.equals:
645             case tokens.word:
646                 this.word();
647                 break;
648             case tokens.colon:
649                 this.pseudo();
650                 break;
651             case tokens.comma:
652                 this.comma();
653                 break;
654             case tokens.asterisk:
655                 this.universal();
656                 break;
657             case tokens.ampersand:
658                 this.nesting();
659                 break;
660             case tokens.combinator:
661                 this.combinator();
662                 break;
663             case tokens.str:
664                 this.string();
665                 break;
666             // These cases throw; no break needed.
667             case tokens.closeSquare:
668                 this.missingSquareBracket();
669             case tokens.semicolon:
670                 this.missingBackslash();
671         }
672     };
673
674     /**
675      * Helpers
676      */
677
678     Parser.prototype.expected = function expected(description, index, found) {
679         if (Array.isArray(description)) {
680             var last = description.pop();
681             description = description.join(', ') + ' or ' + last;
682         }
683         var an = /^[aeiou]/.test(description[0]) ? 'an' : 'a';
684         if (!found) {
685             return this.error('Expected ' + an + ' ' + description + '.', { index: index });
686         }
687         return this.error('Expected ' + an + ' ' + description + ', found "' + found + '" instead.', { index: index });
688     };
689
690     Parser.prototype.parseNamespace = function parseNamespace(namespace) {
691         if (this.options.lossy && typeof namespace === 'string') {
692             var trimmed = namespace.trim();
693             if (!trimmed.length) {
694                 return true;
695             }
696
697             return trimmed;
698         }
699
700         return namespace;
701     };
702
703     Parser.prototype.parseSpace = function parseSpace(space) {
704         var replacement = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
705
706         return this.options.lossy ? replacement : space;
707     };
708
709     Parser.prototype.parseValue = function parseValue(value) {
710         if (!this.options.lossy || !value || typeof value !== 'string') {
711             return value;
712         }
713         return value.trim();
714     };
715
716     Parser.prototype.parseParenthesisToken = function parseParenthesisToken(token) {
717         var content = this.content(token);
718         if (!this.options.lossy) {
719             return content;
720         }
721
722         if (token[0] === tokens.space) {
723             return this.parseSpace(content, ' ');
724         }
725
726         return this.parseValue(content);
727     };
728
729     Parser.prototype.newNode = function newNode(node, namespace) {
730         if (namespace) {
731             node.namespace = this.parseNamespace(namespace);
732         }
733         if (this.spaces) {
734             node.spaces.before = this.spaces;
735             this.spaces = '';
736         }
737         return this.current.append(node);
738     };
739
740     Parser.prototype.content = function content() {
741         var token = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.currToken;
742
743         return this.css.slice(token[5], token[6]);
744     };
745
746     _createClass(Parser, [{
747         key: 'currToken',
748         get: function get() {
749             return this.tokens[this.position];
750         }
751     }, {
752         key: 'nextToken',
753         get: function get() {
754             return this.tokens[this.position + 1];
755         }
756     }, {
757         key: 'prevToken',
758         get: function get() {
759             return this.tokens[this.position - 1];
760         }
761     }]);
762
763     return Parser;
764 }();
765
766 exports.default = Parser;
767 module.exports = exports['default'];