| 3 | var commentre = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g; |
| 4 | |
| 5 | export function parse(css, options) { |
| 6 | options = options || {}; |
| 7 | |
| 8 | /** |
| 9 | * Positional. |
| 10 | */ |
| 11 | |
| 12 | var lineno = 1; |
| 13 | var column = 1; |
| 14 | |
| 15 | /** |
| 16 | * Update lineno and column based on `str`. |
| 17 | */ |
| 18 | |
| 19 | function updatePosition(str) { |
| 20 | var lines = str.match(/\n/g); |
| 21 | if (lines) lineno += lines.length; |
| 22 | var i = str.lastIndexOf('\n'); |
| 23 | column = ~i ? str.length - i : column + str.length; |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Mark position and patch `node.position`. |
| 28 | */ |
| 29 | |
| 30 | function position() { |
| 31 | var start = { line: lineno, column: column }; |
| 32 | return function (node) { |
| 33 | node.position = new Position(start); |
| 34 | whitespace(); |
| 35 | return node; |
| 36 | }; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Store position information for a node |
| 41 | */ |
| 42 | |
| 43 | function Position(start) { |
| 44 | this.start = start; |
| 45 | this.end = { line: lineno, column: column }; |
| 46 | this.source = options.source; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Non-enumerable source string |
| 51 | */ |
| 52 | |
| 53 | Position.prototype.content = css; |
| 54 | |
| 55 | /** |
| 56 | * Error `msg`. |
| 57 | */ |
| 58 | |
| 59 | var errorsList = []; |
| 60 | |
| 61 | function error(msg) { |
| 62 | var err: any = new Error(options.source + ':' + lineno + ':' + column + ': ' + msg); |