.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / autoprefixer / lib / brackets.js
1 'use strict';
2
3 var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
4
5 var last = function last(array) {
6     return array[array.length - 1];
7 };
8
9 var brackets = {
10
11     /**
12      * Parse string to nodes tree
13      */
14     parse: function parse(str) {
15         var current = [''];
16         var stack = [current];
17
18         for (var i = 0; i < str.length; i++) {
19             var sym = str[i];
20             if (sym === '(') {
21                 current = [''];
22                 last(stack).push(current);
23                 stack.push(current);
24                 continue;
25             }
26
27             if (sym === ')') {
28                 stack.pop();
29                 current = last(stack);
30                 current.push('');
31                 continue;
32             }
33
34             current[current.length - 1] += sym;
35         }
36
37         return stack[0];
38     },
39
40
41     /**
42      * Generate output string by nodes tree
43      */
44     stringify: function stringify(ast) {
45         var result = '';
46         for (var _iterator = ast, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
47             var _ref;
48
49             if (_isArray) {
50                 if (_i >= _iterator.length) break;
51                 _ref = _iterator[_i++];
52             } else {
53                 _i = _iterator.next();
54                 if (_i.done) break;
55                 _ref = _i.value;
56             }
57
58             var i = _ref;
59
60             if ((typeof i === 'undefined' ? 'undefined' : _typeof(i)) === 'object') {
61                 result += '(' + brackets.stringify(i) + ')';
62                 continue;
63             }
64
65             result += i;
66         }
67         return result;
68     }
69 };
70
71 module.exports = brackets;