| OLD | NEW |
| 1 (function webpackUniversalModuleDefinition(root, factory) { | 1 (function webpackUniversalModuleDefinition(root, factory) { |
| 2 if(typeof exports === 'object' && typeof module === 'object') | 2 if(typeof exports === 'object' && typeof module === 'object') |
| 3 module.exports = factory(); | 3 module.exports = factory(); |
| 4 else if(typeof define === 'function' && define.amd) | 4 else if(typeof define === 'function' && define.amd) |
| 5 define([], factory); | 5 define([], factory); |
| 6 else if(typeof exports === 'object') | 6 else if(typeof exports === 'object') |
| 7 exports["gonzales"] = factory(); | 7 exports["gonzales"] = factory(); |
| 8 else | 8 else |
| 9 root["gonzales"] = factory(); | 9 root["gonzales"] = factory(); |
| 10 })(this, function() { | 10 })(this, function() { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 /******/ ([ | 53 /******/ ([ |
| 54 /* 0 */ | 54 /* 0 */ |
| 55 /***/ function(module, exports, __webpack_require__) { | 55 /***/ function(module, exports, __webpack_require__) { |
| 56 | 56 |
| 57 'use strict'; | 57 'use strict'; |
| 58 | 58 |
| 59 var Node = __webpack_require__(1); | 59 var Node = __webpack_require__(1); |
| 60 var parse = __webpack_require__(7); | 60 var parse = __webpack_require__(7); |
| 61 | 61 |
| 62 module.exports = { | 62 module.exports = { |
| 63 » createNode: function (options) { | 63 » createNode: function createNode(options) { |
| 64 return new Node(options); | 64 return new Node(options); |
| 65 }, | 65 }, |
| 66 parse: parse | 66 parse: parse |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 /***/ }, | 69 /***/ }, |
| 70 /* 1 */ | 70 /* 1 */ |
| 71 /***/ function(module, exports, __webpack_require__) { | 71 /***/ function(module, exports, __webpack_require__) { |
| 72 | 72 |
| 73 'use strict'; | 73 'use strict'; |
| 74 | 74 |
| 75 /** | 75 /** |
| 76 * @param {string} type | 76 * @param {string} type |
| 77 * @param {array|string} content | 77 * @param {array|string} content |
| 78 * @param {number} line | 78 * @param {number} line |
| 79 * @param {number} column | 79 * @param {number} column |
| 80 * @constructor | 80 * @constructor |
| 81 */ | 81 */ |
| 82 | 82 |
| 83 » var _createClass = (function () { function defineProperties(target, prop
s) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descrip
tor.enumerable = descriptor.enumerable || false; descriptor.configurable = true;
if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(ta
rget, descriptor.key, descriptor); } } return function (Constructor, protoProps,
staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoPro
ps); if (staticProps) defineProperties(Constructor, staticProps); return Constru
ctor; }; })(); | 83 » var _createClass = function () { function defineProperties(target, props
) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descript
or.enumerable = descriptor.enumerable || false; descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(tar
get, descriptor.key, descriptor); } } return function (Constructor, protoProps,
staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProp
s); if (staticProps) defineProperties(Constructor, staticProps); return Construc
tor; }; }(); |
| 84 | 84 |
| 85 » function _classCallCheck(instance, Constructor) { if (!(instance instanc
eof Constructor)) { throw new TypeError('Cannot call a class as a function'); }
} | 85 » function _classCallCheck(instance, Constructor) { if (!(instance instanc
eof Constructor)) { throw new TypeError("Cannot call a class as a function"); }
} |
| 86 | 86 |
| 87 » var Node = (function () { | 87 » var Node = function () { |
| 88 function Node(options) { | 88 function Node(options) { |
| 89 _classCallCheck(this, Node); | 89 _classCallCheck(this, Node); |
| 90 | 90 |
| 91 this.type = options.type; | 91 this.type = options.type; |
| 92 this.content = options.content; | 92 this.content = options.content; |
| 93 this.syntax = options.syntax; | 93 this.syntax = options.syntax; |
| 94 | 94 |
| 95 if (options.start) this.start = options.start; | 95 if (options.start) this.start = options.start; |
| 96 if (options.end) this.end = options.end; | 96 if (options.end) this.end = options.end; |
| 97 } | 97 } |
| 98 | 98 |
| 99 /** | 99 /** |
| 100 * @param {String} type Node type | 100 * @param {String} type Node type |
| 101 * @return {Boolean} Whether there is a child node of given type | 101 * @return {Boolean} Whether there is a child node of given type |
| 102 */ | 102 */ |
| 103 | 103 |
| 104 |
| 104 Node.prototype.contains = function contains(type) { | 105 Node.prototype.contains = function contains(type) { |
| 105 return this.content.some(function (node) { | 106 return this.content.some(function (node) { |
| 106 return node.type === type; | 107 return node.type === type; |
| 107 }); | 108 }); |
| 108 }; | 109 }; |
| 109 | 110 |
| 110 /** | 111 /** |
| 111 * @param {String} type Node type | 112 * @param {String} type Node type |
| 112 * @param {Function} callback Function to call for every found node | 113 * @param {Function} callback Function to call for every found node |
| 113 */ | 114 */ |
| 114 | 115 |
| 116 |
| 115 Node.prototype.eachFor = function eachFor(type, callback) { | 117 Node.prototype.eachFor = function eachFor(type, callback) { |
| 116 if (!Array.isArray(this.content)) return; | 118 if (!Array.isArray(this.content)) return; |
| 117 | 119 |
| 118 if (typeof type !== 'string') { | 120 if (typeof type !== 'string') { |
| 119 callback = type; | 121 callback = type; |
| 120 type = null; | 122 type = null; |
| 121 } | 123 } |
| 122 | 124 |
| 123 var l = this.content.length; | 125 var l = this.content.length; |
| 124 var breakLoop; | 126 var breakLoop; |
| 125 | 127 |
| 126 for (var i = l; i--;) { | 128 for (var i = l; i--;) { |
| 127 if (breakLoop === null) break; | 129 if (breakLoop === null) break; |
| 128 | 130 |
| 129 if (!type || this.content[i] && this.content[i].type === type) bre
akLoop = callback(this.content[i], i, this); | 131 if (!type || this.content[i] && this.content[i].type === type) bre
akLoop = callback(this.content[i], i, this); |
| 130 } | 132 } |
| 131 | 133 |
| 132 if (breakLoop === null) return null; | 134 if (breakLoop === null) return null; |
| 133 }; | 135 }; |
| 134 | 136 |
| 135 /** | 137 /** |
| 136 * @param {String} type | 138 * @param {String} type |
| 137 * @return {?Node} First child node or `null` if nothing's been found. | 139 * @return {?Node} First child node or `null` if nothing's been found. |
| 138 */ | 140 */ |
| 139 | 141 |
| 142 |
| 140 Node.prototype.first = function first(type) { | 143 Node.prototype.first = function first(type) { |
| 141 if (!Array.isArray(this.content)) return null; | 144 if (!Array.isArray(this.content)) return null; |
| 142 | 145 |
| 143 if (!type) return this.content[0]; | 146 if (!type) return this.content[0]; |
| 144 | 147 |
| 145 var i = 0; | 148 var i = 0; |
| 146 var l = this.content.length; | 149 var l = this.content.length; |
| 147 | 150 |
| 148 for (; i < l; i++) { | 151 for (; i < l; i++) { |
| 149 if (this.content[i].type === type) return this.content[i]; | 152 if (this.content[i].type === type) return this.content[i]; |
| 150 } | 153 } |
| 151 | 154 |
| 152 return null; | 155 return null; |
| 153 }; | 156 }; |
| 154 | 157 |
| 155 /** | 158 /** |
| 156 * @param {String} type Node type | 159 * @param {String} type Node type |
| 157 * @param {Function} callback Function to call for every found node | 160 * @param {Function} callback Function to call for every found node |
| 158 */ | 161 */ |
| 159 | 162 |
| 163 |
| 160 Node.prototype.forEach = function forEach(type, callback) { | 164 Node.prototype.forEach = function forEach(type, callback) { |
| 161 if (!Array.isArray(this.content)) return; | 165 if (!Array.isArray(this.content)) return; |
| 162 | 166 |
| 163 if (typeof type !== 'string') { | 167 if (typeof type !== 'string') { |
| 164 callback = type; | 168 callback = type; |
| 165 type = null; | 169 type = null; |
| 166 } | 170 } |
| 167 | 171 |
| 168 var i = 0; | 172 var i = 0; |
| 169 var l = this.content.length; | 173 var l = this.content.length; |
| 170 var breakLoop; | 174 var breakLoop; |
| 171 | 175 |
| 172 for (; i < l; i++) { | 176 for (; i < l; i++) { |
| 173 if (breakLoop === null) break; | 177 if (breakLoop === null) break; |
| 174 | 178 |
| 175 if (!type || this.content[i] && this.content[i].type === type) bre
akLoop = callback(this.content[i], i, this); | 179 if (!type || this.content[i] && this.content[i].type === type) bre
akLoop = callback(this.content[i], i, this); |
| 176 } | 180 } |
| 177 | 181 |
| 178 if (breakLoop === null) return null; | 182 if (breakLoop === null) return null; |
| 179 }; | 183 }; |
| 180 | 184 |
| 181 /** | 185 /** |
| 182 * @param {Number} index | 186 * @param {Number} index |
| 183 * @return {?Node} | 187 * @return {?Node} |
| 184 */ | 188 */ |
| 185 | 189 |
| 190 |
| 186 Node.prototype.get = function get(index) { | 191 Node.prototype.get = function get(index) { |
| 187 if (!Array.isArray(this.content)) return null; | 192 if (!Array.isArray(this.content)) return null; |
| 188 | 193 |
| 189 var node = this.content[index]; | 194 var node = this.content[index]; |
| 190 return node ? node : null; | 195 return node ? node : null; |
| 191 }; | 196 }; |
| 192 | 197 |
| 193 /** | 198 /** |
| 194 * @param {Number} index | 199 * @param {Number} index |
| 195 * @param {Node} node | 200 * @param {Node} node |
| 196 */ | 201 */ |
| 197 | 202 |
| 203 |
| 198 Node.prototype.insert = function insert(index, node) { | 204 Node.prototype.insert = function insert(index, node) { |
| 199 if (!Array.isArray(this.content)) return; | 205 if (!Array.isArray(this.content)) return; |
| 200 | 206 |
| 201 this.content.splice(index, 0, node); | 207 this.content.splice(index, 0, node); |
| 202 }; | 208 }; |
| 203 | 209 |
| 204 /** | 210 /** |
| 205 * @param {String} type | 211 * @param {String} type |
| 206 * @return {Boolean} Whether the node is of given type | 212 * @return {Boolean} Whether the node is of given type |
| 207 */ | 213 */ |
| 208 | 214 |
| 215 |
| 209 Node.prototype.is = function is(type) { | 216 Node.prototype.is = function is(type) { |
| 210 return this.type === type; | 217 return this.type === type; |
| 211 }; | 218 }; |
| 212 | 219 |
| 213 /** | 220 /** |
| 214 * @param {String} type | 221 * @param {String} type |
| 215 * @return {?Node} Last child node or `null` if nothing's been found. | 222 * @return {?Node} Last child node or `null` if nothing's been found. |
| 216 */ | 223 */ |
| 217 | 224 |
| 225 |
| 218 Node.prototype.last = function last(type) { | 226 Node.prototype.last = function last(type) { |
| 219 if (!Array.isArray(this.content)) return null; | 227 if (!Array.isArray(this.content)) return null; |
| 220 | 228 |
| 221 » var i = this.content.length - 1; | 229 » var i = this.content.length; |
| 222 » if (!type) return this.content[i]; | 230 » if (!type) return this.content[i - 1]; |
| 223 | 231 |
| 224 » for (;; i--) { | 232 » for (; i--;) { |
| 225 if (this.content[i].type === type) return this.content[i]; | 233 if (this.content[i].type === type) return this.content[i]; |
| 226 } | 234 } |
| 227 | 235 |
| 228 return null; | 236 return null; |
| 229 }; | 237 }; |
| 230 | 238 |
| 231 /** | 239 /** |
| 232 * Number of child nodes. | 240 * Number of child nodes. |
| 233 * @type {number} | 241 * @type {number} |
| 234 */ | 242 */ |
| 235 | 243 |
| 244 |
| 236 /** | 245 /** |
| 237 * @param {Number} index | 246 * @param {Number} index |
| 238 * @return {Node} | 247 * @return {Node} |
| 239 */ | 248 */ |
| 240 | |
| 241 Node.prototype.removeChild = function removeChild(index) { | 249 Node.prototype.removeChild = function removeChild(index) { |
| 242 if (!Array.isArray(this.content)) return; | 250 if (!Array.isArray(this.content)) return; |
| 243 | 251 |
| 244 var removedChild = this.content.splice(index, 1); | 252 var removedChild = this.content.splice(index, 1); |
| 245 | 253 |
| 246 return removedChild; | 254 return removedChild; |
| 247 }; | 255 }; |
| 248 | 256 |
| 249 Node.prototype.toJson = function toJson() { | 257 Node.prototype.toJson = function toJson() { |
| 250 return JSON.stringify(this, false, 2); | 258 return JSON.stringify(this, false, 2); |
| 251 }; | 259 }; |
| 252 | 260 |
| 253 Node.prototype.toString = function toString() { | 261 Node.prototype.toString = function toString() { |
| 254 » var stringify = undefined; | 262 » var stringify = void 0; |
| 255 | 263 |
| 256 try { | 264 try { |
| 257 stringify = __webpack_require__(2)("./" + this.syntax + '/stringif
y'); | 265 stringify = __webpack_require__(2)("./" + this.syntax + '/stringif
y'); |
| 258 } catch (e) { | 266 } catch (e) { |
| 259 var message = 'Syntax "' + this.syntax + '" is not supported yet,
sorry'; | 267 var message = 'Syntax "' + this.syntax + '" is not supported yet,
sorry'; |
| 260 return console.error(message); | 268 return console.error(message); |
| 261 } | 269 } |
| 262 | 270 |
| 263 return stringify(this); | 271 return stringify(this); |
| 264 }; | 272 }; |
| 265 | 273 |
| 266 /** | 274 /** |
| 267 * @param {Function} callback | 275 * @param {Function} callback |
| 268 */ | 276 */ |
| 269 | 277 |
| 278 |
| 270 Node.prototype.traverse = function traverse(callback, index) { | 279 Node.prototype.traverse = function traverse(callback, index) { |
| 271 » var level = arguments.length <= 2 || arguments[2] === undefined ? 0
: arguments[2]; | 280 » var level = arguments.length > 2 && arguments[2] !== undefined ? arg
uments[2] : 0; |
| 272 » var parent = arguments.length <= 3 || arguments[3] === undefined ? n
ull : arguments[3]; | 281 » var parent = arguments.length > 3 && arguments[3] !== undefined ? ar
guments[3] : null; |
| 273 | 282 |
| 274 var breakLoop; | 283 var breakLoop; |
| 275 var x; | 284 var x; |
| 276 | 285 |
| 277 level++; | 286 level++; |
| 278 | 287 |
| 279 callback(this, index, parent, level); | 288 callback(this, index, parent, level); |
| 280 | 289 |
| 281 if (!Array.isArray(this.content)) return; | 290 if (!Array.isArray(this.content)) return; |
| 282 | 291 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 301 }; | 310 }; |
| 302 | 311 |
| 303 Node.prototype.traverseByTypes = function traverseByTypes(types, callb
ack) { | 312 Node.prototype.traverseByTypes = function traverseByTypes(types, callb
ack) { |
| 304 this.traverse(function (node) { | 313 this.traverse(function (node) { |
| 305 if (types.indexOf(node.type) !== -1) callback.apply(node, argument
s); | 314 if (types.indexOf(node.type) !== -1) callback.apply(node, argument
s); |
| 306 }); | 315 }); |
| 307 }; | 316 }; |
| 308 | 317 |
| 309 _createClass(Node, [{ | 318 _createClass(Node, [{ |
| 310 key: 'length', | 319 key: 'length', |
| 311 » get: function () { | 320 » get: function get() { |
| 312 if (!Array.isArray(this.content)) return 0; | 321 if (!Array.isArray(this.content)) return 0; |
| 313 return this.content.length; | 322 return this.content.length; |
| 314 } | 323 } |
| 315 }]); | 324 }]); |
| 316 | 325 |
| 317 return Node; | 326 return Node; |
| 318 » })(); | 327 » }(); |
| 319 | 328 |
| 320 module.exports = Node; | 329 module.exports = Node; |
| 321 | 330 |
| 322 /***/ }, | 331 /***/ }, |
| 323 /* 2 */ | 332 /* 2 */ |
| 324 /***/ function(module, exports, __webpack_require__) { | 333 /***/ function(module, exports, __webpack_require__) { |
| 325 | 334 |
| 326 var map = { | 335 var map = { |
| 327 "./css/stringify": 3, | 336 "./css/stringify": 3, |
| 328 "./less/stringify": 4, | 337 "./less/stringify": 4, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 340 }; | 349 }; |
| 341 webpackContext.resolve = webpackContextResolve; | 350 webpackContext.resolve = webpackContextResolve; |
| 342 module.exports = webpackContext; | 351 module.exports = webpackContext; |
| 343 webpackContext.id = 2; | 352 webpackContext.id = 2; |
| 344 | 353 |
| 345 | 354 |
| 346 /***/ }, | 355 /***/ }, |
| 347 /* 3 */ | 356 /* 3 */ |
| 348 /***/ function(module, exports) { | 357 /***/ function(module, exports) { |
| 349 | 358 |
| 350 // jscs:disable maximumLineLength | |
| 351 | |
| 352 'use strict'; | 359 'use strict'; |
| 353 | 360 |
| 354 module.exports = function stringify(tree) { | 361 module.exports = function stringify(tree) { |
| 355 // TODO: Better error message | 362 // TODO: Better error message |
| 356 if (!tree) throw new Error('We need tree to translate'); | 363 if (!tree) throw new Error('We need tree to translate'); |
| 357 | 364 |
| 358 function _t(tree) { | 365 function _t(tree) { |
| 359 var type = tree.type; | 366 var type = tree.type; |
| 360 if (_unique[type]) return _unique[type](tree); | 367 if (_unique[type]) return _unique[type](tree); |
| 361 if (typeof tree.content === 'string') return tree.content; | 368 if (typeof tree.content === 'string') return tree.content; |
| 362 if (Array.isArray(tree.content)) return _composite(tree.content); | 369 if (Array.isArray(tree.content)) return _composite(tree.content); |
| 363 return ''; | 370 return ''; |
| 364 } | 371 } |
| 365 | 372 |
| 366 function _composite(t, i) { | 373 function _composite(t, i) { |
| 367 if (!t) return ''; | 374 if (!t) return ''; |
| 368 | 375 |
| 369 var s = ''; | 376 var s = ''; |
| 370 i = i || 0; | 377 i = i || 0; |
| 371 » for (; i < t.length; i++) s += _t(t[i]); | 378 » for (; i < t.length; i++) { |
| 372 » return s; | 379 » s += _t(t[i]); |
| 380 » }return s; |
| 373 } | 381 } |
| 374 | 382 |
| 375 var _unique = { | 383 var _unique = { |
| 376 » 'arguments': function (t) { | 384 » 'arguments': function _arguments(t) { |
| 377 return '(' + _composite(t.content) + ')'; | 385 return '(' + _composite(t.content) + ')'; |
| 378 }, | 386 }, |
| 379 » 'atkeyword': function (t) { | 387 » 'atkeyword': function atkeyword(t) { |
| 380 return '@' + _composite(t.content); | 388 return '@' + _composite(t.content); |
| 381 }, | 389 }, |
| 382 » 'attributeSelector': function (t) { | 390 » 'attributeSelector': function attributeSelector(t) { |
| 383 return '[' + _composite(t.content) + ']'; | 391 return '[' + _composite(t.content) + ']'; |
| 384 }, | 392 }, |
| 385 » 'block': function (t) { | 393 » 'block': function block(t) { |
| 386 return '{' + _composite(t.content) + '}'; | 394 return '{' + _composite(t.content) + '}'; |
| 387 }, | 395 }, |
| 388 » 'brackets': function (t) { | 396 » 'brackets': function brackets(t) { |
| 389 return '[' + _composite(t.content) + ']'; | 397 return '[' + _composite(t.content) + ']'; |
| 390 }, | 398 }, |
| 391 » 'class': function (t) { | 399 » 'class': function _class(t) { |
| 392 return '.' + _composite(t.content); | 400 return '.' + _composite(t.content); |
| 393 }, | 401 }, |
| 394 » 'color': function (t) { | 402 » 'color': function color(t) { |
| 395 return '#' + t.content; | 403 return '#' + t.content; |
| 396 }, | 404 }, |
| 397 » 'expression': function (t) { | 405 » 'expression': function expression(t) { |
| 398 return 'expression(' + t.content + ')'; | 406 return 'expression(' + t.content + ')'; |
| 399 }, | 407 }, |
| 400 » 'id': function (t) { | 408 » 'id': function id(t) { |
| 401 return '#' + _composite(t.content); | 409 return '#' + _composite(t.content); |
| 402 }, | 410 }, |
| 403 » 'multilineComment': function (t) { | 411 » 'multilineComment': function multilineComment(t) { |
| 404 return '/*' + t.content + '*/'; | 412 return '/*' + t.content + '*/'; |
| 405 }, | 413 }, |
| 406 » 'nthSelector': function (t) { | 414 » 'nthSelector': function nthSelector(t) { |
| 407 return ':' + _t(t.content[0]) + '(' + _composite(t.content.slice(1
)) + ')'; | 415 return ':' + _t(t.content[0]) + '(' + _composite(t.content.slice(1
)) + ')'; |
| 408 }, | 416 }, |
| 409 » 'parentheses': function (t) { | 417 » 'parentheses': function parentheses(t) { |
| 410 return '(' + _composite(t.content) + ')'; | 418 return '(' + _composite(t.content) + ')'; |
| 411 }, | 419 }, |
| 412 » 'percentage': function (t) { | 420 » 'percentage': function percentage(t) { |
| 413 return _composite(t.content) + '%'; | 421 return _composite(t.content) + '%'; |
| 414 }, | 422 }, |
| 415 » 'pseudoClass': function (t) { | 423 » 'pseudoClass': function pseudoClass(t) { |
| 416 return ':' + _composite(t.content); | 424 return ':' + _composite(t.content); |
| 417 }, | 425 }, |
| 418 » 'pseudoElement': function (t) { | 426 » 'pseudoElement': function pseudoElement(t) { |
| 419 return '::' + _composite(t.content); | 427 return '::' + _composite(t.content); |
| 420 }, | 428 }, |
| 421 » 'uri': function (t) { | 429 » 'universalSelector': function universalSelector(t) { |
| 430 » return _composite(t.content) + '*'; |
| 431 » }, |
| 432 » 'uri': function uri(t) { |
| 422 return 'url(' + _composite(t.content) + ')'; | 433 return 'url(' + _composite(t.content) + ')'; |
| 423 } | 434 } |
| 424 }; | 435 }; |
| 425 | 436 |
| 426 return _t(tree); | 437 return _t(tree); |
| 427 }; | 438 }; |
| 428 | 439 |
| 429 /***/ }, | 440 /***/ }, |
| 430 /* 4 */ | 441 /* 4 */ |
| 431 /***/ function(module, exports) { | 442 /***/ function(module, exports) { |
| 432 | 443 |
| 433 // jscs:disable maximumLineLength | |
| 434 | |
| 435 'use strict'; | 444 'use strict'; |
| 436 | 445 |
| 437 module.exports = function stringify(tree) { | 446 module.exports = function stringify(tree) { |
| 438 // TODO: Better error message | 447 // TODO: Better error message |
| 439 if (!tree) throw new Error('We need tree to translate'); | 448 if (!tree) throw new Error('We need tree to translate'); |
| 440 | 449 |
| 441 function _t(tree) { | 450 function _t(tree) { |
| 442 var type = tree.type; | 451 var type = tree.type; |
| 443 if (_unique[type]) return _unique[type](tree); | 452 if (_unique[type]) return _unique[type](tree); |
| 444 if (typeof tree.content === 'string') return tree.content; | 453 if (typeof tree.content === 'string') return tree.content; |
| 445 if (Array.isArray(tree.content)) return _composite(tree.content); | 454 if (Array.isArray(tree.content)) return _composite(tree.content); |
| 446 return ''; | 455 return ''; |
| 447 } | 456 } |
| 448 | 457 |
| 449 function _composite(t, i) { | 458 function _composite(t, i) { |
| 450 if (!t) return ''; | 459 if (!t) return ''; |
| 451 | 460 |
| 452 var s = ''; | 461 var s = ''; |
| 453 i = i || 0; | 462 i = i || 0; |
| 454 » for (; i < t.length; i++) s += _t(t[i]); | 463 » for (; i < t.length; i++) { |
| 455 » return s; | 464 » s += _t(t[i]); |
| 465 » }return s; |
| 456 } | 466 } |
| 457 | 467 |
| 458 var _unique = { | 468 var _unique = { |
| 459 » 'arguments': function (t) { | 469 » 'arguments': function _arguments(t) { |
| 460 return '(' + _composite(t.content) + ')'; | 470 return '(' + _composite(t.content) + ')'; |
| 461 }, | 471 }, |
| 462 » 'atkeyword': function (t) { | 472 » 'atkeyword': function atkeyword(t) { |
| 463 return '@' + _composite(t.content); | 473 return '@' + _composite(t.content); |
| 464 }, | 474 }, |
| 465 » 'attributeSelector': function (t) { | 475 » 'attributeSelector': function attributeSelector(t) { |
| 466 return '[' + _composite(t.content) + ']'; | 476 return '[' + _composite(t.content) + ']'; |
| 467 }, | 477 }, |
| 468 » 'block': function (t) { | 478 » 'block': function block(t) { |
| 469 return '{' + _composite(t.content) + '}'; | 479 return '{' + _composite(t.content) + '}'; |
| 470 }, | 480 }, |
| 471 » 'brackets': function (t) { | 481 » 'brackets': function brackets(t) { |
| 472 return '[' + _composite(t.content) + ']'; | 482 return '[' + _composite(t.content) + ']'; |
| 473 }, | 483 }, |
| 474 » 'class': function (t) { | 484 » 'class': function _class(t) { |
| 475 return '.' + _composite(t.content); | 485 return '.' + _composite(t.content); |
| 476 }, | 486 }, |
| 477 » 'color': function (t) { | 487 » 'color': function color(t) { |
| 478 return '#' + t.content; | 488 return '#' + t.content; |
| 479 }, | 489 }, |
| 480 » 'escapedString': function (t) { | 490 » 'escapedString': function escapedString(t) { |
| 481 return '~' + t.content; | 491 return '~' + t.content; |
| 482 }, | 492 }, |
| 483 » 'expression': function (t) { | 493 » 'expression': function expression(t) { |
| 484 return 'expression(' + t.content + ')'; | 494 return 'expression(' + t.content + ')'; |
| 485 }, | 495 }, |
| 486 » 'id': function (t) { | 496 » 'id': function id(t) { |
| 487 return '#' + _composite(t.content); | 497 return '#' + _composite(t.content); |
| 488 }, | 498 }, |
| 489 » 'interpolatedVariable': function (t) { | 499 » 'interpolatedVariable': function interpolatedVariable(t) { |
| 490 return '@{' + _composite(t.content) + '}'; | 500 return '@{' + _composite(t.content) + '}'; |
| 491 }, | 501 }, |
| 492 » 'multilineComment': function (t) { | 502 » 'multilineComment': function multilineComment(t) { |
| 493 return '/*' + t.content + '*/'; | 503 return '/*' + t.content + '*/'; |
| 494 }, | 504 }, |
| 495 » 'nthSelector': function (t) { | 505 » 'nthSelector': function nthSelector(t) { |
| 496 return ':' + _t(t.content[0]) + '(' + _composite(t.content.slice(1
)) + ')'; | 506 return ':' + _t(t.content[0]) + '(' + _composite(t.content.slice(1
)) + ')'; |
| 497 }, | 507 }, |
| 498 » 'parentheses': function (t) { | 508 » 'parentheses': function parentheses(t) { |
| 499 return '(' + _composite(t.content) + ')'; | 509 return '(' + _composite(t.content) + ')'; |
| 500 }, | 510 }, |
| 501 » 'percentage': function (t) { | 511 » 'percentage': function percentage(t) { |
| 502 return _composite(t.content) + '%'; | 512 return _composite(t.content) + '%'; |
| 503 }, | 513 }, |
| 504 » 'pseudoClass': function (t) { | 514 » 'pseudoClass': function pseudoClass(t) { |
| 505 return ':' + _composite(t.content); | 515 return ':' + _composite(t.content); |
| 506 }, | 516 }, |
| 507 » 'pseudoElement': function (t) { | 517 » 'pseudoElement': function pseudoElement(t) { |
| 508 return '::' + _composite(t.content); | 518 return '::' + _composite(t.content); |
| 509 }, | 519 }, |
| 510 » 'singlelineComment': function (t) { | 520 » 'singlelineComment': function singlelineComment(t) { |
| 511 return '/' + '/' + t.content; | 521 return '/' + '/' + t.content; |
| 512 }, | 522 }, |
| 513 » 'uri': function (t) { | 523 » 'universalSelector': function universalSelector(t) { |
| 524 » return _composite(t.content) + '*'; |
| 525 » }, |
| 526 » 'uri': function uri(t) { |
| 514 return 'url(' + _composite(t.content) + ')'; | 527 return 'url(' + _composite(t.content) + ')'; |
| 515 }, | 528 }, |
| 516 » 'variable': function (t) { | 529 » 'variable': function variable(t) { |
| 517 return '@' + _composite(t.content); | 530 return '@' + _composite(t.content); |
| 518 }, | 531 }, |
| 519 » 'variablesList': function (t) { | 532 » 'variablesList': function variablesList(t) { |
| 520 return _composite(t.content) + '...'; | 533 return _composite(t.content) + '...'; |
| 521 } | 534 } |
| 522 }; | 535 }; |
| 523 | 536 |
| 524 return _t(tree); | 537 return _t(tree); |
| 525 }; | 538 }; |
| 526 | 539 |
| 527 /***/ }, | 540 /***/ }, |
| 528 /* 5 */ | 541 /* 5 */ |
| 529 /***/ function(module, exports) { | 542 /***/ function(module, exports) { |
| 530 | 543 |
| 531 // jscs:disable maximumLineLength | |
| 532 | |
| 533 'use strict'; | 544 'use strict'; |
| 534 | 545 |
| 535 module.exports = function stringify(tree) { | 546 module.exports = function stringify(tree) { |
| 536 // TODO: Better error message | 547 // TODO: Better error message |
| 537 if (!tree) throw new Error('We need tree to translate'); | 548 if (!tree) throw new Error('We need tree to translate'); |
| 538 | 549 |
| 539 function _t(tree) { | 550 function _t(tree) { |
| 540 var type = tree.type; | 551 var type = tree.type; |
| 541 if (_unique[type]) return _unique[type](tree); | 552 if (_unique[type]) return _unique[type](tree); |
| 542 if (typeof tree.content === 'string') return tree.content; | 553 if (typeof tree.content === 'string') return tree.content; |
| 543 if (Array.isArray(tree.content)) return _composite(tree.content); | 554 if (Array.isArray(tree.content)) return _composite(tree.content); |
| 544 return ''; | 555 return ''; |
| 545 } | 556 } |
| 546 | 557 |
| 547 function _composite(t, i) { | 558 function _composite(t, i) { |
| 548 if (!t) return ''; | 559 if (!t) return ''; |
| 549 | 560 |
| 550 var s = ''; | 561 var s = ''; |
| 551 i = i || 0; | 562 i = i || 0; |
| 552 » for (; i < t.length; i++) s += _t(t[i]); | 563 » for (; i < t.length; i++) { |
| 553 » return s; | 564 » s += _t(t[i]); |
| 565 » }return s; |
| 554 } | 566 } |
| 555 | 567 |
| 556 var _unique = { | 568 var _unique = { |
| 557 » 'arguments': function (t) { | 569 » 'arguments': function _arguments(t) { |
| 558 return '(' + _composite(t.content) + ')'; | 570 return '(' + _composite(t.content) + ')'; |
| 559 }, | 571 }, |
| 560 » 'atkeyword': function (t) { | 572 » 'atkeyword': function atkeyword(t) { |
| 561 return '@' + _composite(t.content); | 573 return '@' + _composite(t.content); |
| 562 }, | 574 }, |
| 563 » 'attributeSelector': function (t) { | 575 » 'attributeSelector': function attributeSelector(t) { |
| 564 return '[' + _composite(t.content) + ']'; | 576 return '[' + _composite(t.content) + ']'; |
| 565 }, | 577 }, |
| 566 » 'block': function (t) { | 578 » 'block': function block(t) { |
| 567 return _composite(t.content); | 579 return _composite(t.content); |
| 568 }, | 580 }, |
| 569 » 'brackets': function (t) { | 581 » 'brackets': function brackets(t) { |
| 570 return '[' + _composite(t.content) + ']'; | 582 return '[' + _composite(t.content) + ']'; |
| 571 }, | 583 }, |
| 572 » 'class': function (t) { | 584 » 'class': function _class(t) { |
| 573 return '.' + _composite(t.content); | 585 return '.' + _composite(t.content); |
| 574 }, | 586 }, |
| 575 » 'color': function (t) { | 587 » 'color': function color(t) { |
| 576 return '#' + t.content; | 588 return '#' + t.content; |
| 577 }, | 589 }, |
| 578 » 'expression': function (t) { | 590 » 'expression': function expression(t) { |
| 579 return 'expression(' + t.content + ')'; | 591 return 'expression(' + t.content + ')'; |
| 580 }, | 592 }, |
| 581 » 'id': function (t) { | 593 » 'id': function id(t) { |
| 582 return '#' + _composite(t.content); | 594 return '#' + _composite(t.content); |
| 583 }, | 595 }, |
| 584 » 'interpolation': function (t) { | 596 » 'interpolation': function interpolation(t) { |
| 585 return '#{' + _composite(t.content) + '}'; | 597 return '#{' + _composite(t.content) + '}'; |
| 586 }, | 598 }, |
| 587 » 'multilineComment': function (t) { | 599 » 'multilineComment': function multilineComment(t) { |
| 588 » return '/*' + t.content; | 600 » var lines = t.content.split('\n'); |
| 601 » var close = ''; |
| 602 |
| 603 » if (lines.length > 1) { |
| 604 » var lastLine = lines[lines.length - 1]; |
| 605 » if (lastLine.length < t.end.column) { |
| 606 » close = '*/'; |
| 607 » } |
| 608 » } else if (t.content.length + 4 === t.end.column - t.start.column
+ 1) { |
| 609 » close = '*/'; |
| 610 » } |
| 611 |
| 612 » return '/*' + t.content + close; |
| 589 }, | 613 }, |
| 590 » 'nthSelector': function (t) { | 614 » 'nthSelector': function nthSelector(t) { |
| 591 return ':' + _t(t.content[0]) + '(' + _composite(t.content.slice(1
)) + ')'; | 615 return ':' + _t(t.content[0]) + '(' + _composite(t.content.slice(1
)) + ')'; |
| 592 }, | 616 }, |
| 593 » 'parentheses': function (t) { | 617 » 'parentheses': function parentheses(t) { |
| 594 return '(' + _composite(t.content) + ')'; | 618 return '(' + _composite(t.content) + ')'; |
| 595 }, | 619 }, |
| 596 » 'percentage': function (t) { | 620 » 'percentage': function percentage(t) { |
| 597 return _composite(t.content) + '%'; | 621 return _composite(t.content) + '%'; |
| 598 }, | 622 }, |
| 599 » 'placeholder': function (t) { | 623 » 'placeholder': function placeholder(t) { |
| 600 return '%' + _composite(t.content); | 624 return '%' + _composite(t.content); |
| 601 }, | 625 }, |
| 602 » 'pseudoClass': function (t) { | 626 » 'pseudoClass': function pseudoClass(t) { |
| 603 return ':' + _composite(t.content); | 627 return ':' + _composite(t.content); |
| 604 }, | 628 }, |
| 605 » 'pseudoElement': function (t) { | 629 » 'pseudoElement': function pseudoElement(t) { |
| 606 return '::' + _composite(t.content); | 630 return '::' + _composite(t.content); |
| 607 }, | 631 }, |
| 608 » 'singlelineComment': function (t) { | 632 » 'singlelineComment': function singlelineComment(t) { |
| 609 return '/' + '/' + t.content; | 633 return '/' + '/' + t.content; |
| 610 }, | 634 }, |
| 611 » 'uri': function (t) { | 635 » 'universalSelector': function universalSelector(t) { |
| 636 » return _composite(t.content) + '*'; |
| 637 » }, |
| 638 » 'uri': function uri(t) { |
| 612 return 'url(' + _composite(t.content) + ')'; | 639 return 'url(' + _composite(t.content) + ')'; |
| 613 }, | 640 }, |
| 614 » 'variable': function (t) { | 641 » 'variable': function variable(t) { |
| 615 return '$' + _composite(t.content); | 642 return '$' + _composite(t.content); |
| 616 }, | 643 }, |
| 617 » 'variablesList': function (t) { | 644 » 'variablesList': function variablesList(t) { |
| 618 return _composite(t.content) + '...'; | 645 return _composite(t.content) + '...'; |
| 619 } | 646 } |
| 620 }; | 647 }; |
| 621 | 648 |
| 622 return _t(tree); | 649 return _t(tree); |
| 623 }; | 650 }; |
| 624 | 651 |
| 625 /***/ }, | 652 /***/ }, |
| 626 /* 6 */ | 653 /* 6 */ |
| 627 /***/ function(module, exports) { | 654 /***/ function(module, exports) { |
| 628 | 655 |
| 629 // jscs:disable maximumLineLength | |
| 630 | |
| 631 'use strict'; | 656 'use strict'; |
| 632 | 657 |
| 633 module.exports = function stringify(tree) { | 658 module.exports = function stringify(tree) { |
| 634 // TODO: Better error message | 659 // TODO: Better error message |
| 635 if (!tree) throw new Error('We need tree to translate'); | 660 if (!tree) throw new Error('We need tree to translate'); |
| 636 | 661 |
| 637 function _t(tree) { | 662 function _t(tree) { |
| 638 var type = tree.type; | 663 var type = tree.type; |
| 639 if (_unique[type]) return _unique[type](tree); | 664 if (_unique[type]) return _unique[type](tree); |
| 640 if (typeof tree.content === 'string') return tree.content; | 665 if (typeof tree.content === 'string') return tree.content; |
| 641 if (Array.isArray(tree.content)) return _composite(tree.content); | 666 if (Array.isArray(tree.content)) return _composite(tree.content); |
| 642 return ''; | 667 return ''; |
| 643 } | 668 } |
| 644 | 669 |
| 645 function _composite(t, i) { | 670 function _composite(t, i) { |
| 646 if (!t) return ''; | 671 if (!t) return ''; |
| 647 | 672 |
| 648 var s = ''; | 673 var s = ''; |
| 649 i = i || 0; | 674 i = i || 0; |
| 650 » for (; i < t.length; i++) s += _t(t[i]); | 675 » for (; i < t.length; i++) { |
| 651 » return s; | 676 » s += _t(t[i]); |
| 677 » }return s; |
| 652 } | 678 } |
| 653 | 679 |
| 654 var _unique = { | 680 var _unique = { |
| 655 » 'arguments': function (t) { | 681 » 'arguments': function _arguments(t) { |
| 656 return '(' + _composite(t.content) + ')'; | 682 return '(' + _composite(t.content) + ')'; |
| 657 }, | 683 }, |
| 658 » 'atkeyword': function (t) { | 684 » 'atkeyword': function atkeyword(t) { |
| 659 return '@' + _composite(t.content); | 685 return '@' + _composite(t.content); |
| 660 }, | 686 }, |
| 661 » 'attributeSelector': function (t) { | 687 » 'attributeSelector': function attributeSelector(t) { |
| 662 return '[' + _composite(t.content) + ']'; | 688 return '[' + _composite(t.content) + ']'; |
| 663 }, | 689 }, |
| 664 » 'block': function (t) { | 690 » 'block': function block(t) { |
| 665 return '{' + _composite(t.content) + '}'; | 691 return '{' + _composite(t.content) + '}'; |
| 666 }, | 692 }, |
| 667 » 'brackets': function (t) { | 693 » 'brackets': function brackets(t) { |
| 668 return '[' + _composite(t.content) + ']'; | 694 return '[' + _composite(t.content) + ']'; |
| 669 }, | 695 }, |
| 670 » 'class': function (t) { | 696 » 'class': function _class(t) { |
| 671 return '.' + _composite(t.content); | 697 return '.' + _composite(t.content); |
| 672 }, | 698 }, |
| 673 » 'color': function (t) { | 699 » 'color': function color(t) { |
| 674 return '#' + t.content; | 700 return '#' + t.content; |
| 675 }, | 701 }, |
| 676 » 'expression': function (t) { | 702 » 'expression': function expression(t) { |
| 677 return 'expression(' + t.content + ')'; | 703 return 'expression(' + t.content + ')'; |
| 678 }, | 704 }, |
| 679 » 'id': function (t) { | 705 » 'id': function id(t) { |
| 680 return '#' + _composite(t.content); | 706 return '#' + _composite(t.content); |
| 681 }, | 707 }, |
| 682 » 'interpolation': function (t) { | 708 » 'interpolation': function interpolation(t) { |
| 683 return '#{' + _composite(t.content) + '}'; | 709 return '#{' + _composite(t.content) + '}'; |
| 684 }, | 710 }, |
| 685 » 'multilineComment': function (t) { | 711 » 'multilineComment': function multilineComment(t) { |
| 686 return '/*' + t.content + '*/'; | 712 return '/*' + t.content + '*/'; |
| 687 }, | 713 }, |
| 688 » 'nthSelector': function (t) { | 714 » 'nthSelector': function nthSelector(t) { |
| 689 return ':' + _t(t.content[0]) + '(' + _composite(t.content.slice(1
)) + ')'; | 715 return ':' + _t(t.content[0]) + '(' + _composite(t.content.slice(1
)) + ')'; |
| 690 }, | 716 }, |
| 691 » 'parentheses': function (t) { | 717 » 'parentheses': function parentheses(t) { |
| 692 return '(' + _composite(t.content) + ')'; | 718 return '(' + _composite(t.content) + ')'; |
| 693 }, | 719 }, |
| 694 » 'percentage': function (t) { | 720 » 'percentage': function percentage(t) { |
| 695 return _composite(t.content) + '%'; | 721 return _composite(t.content) + '%'; |
| 696 }, | 722 }, |
| 697 » 'placeholder': function (t) { | 723 » 'placeholder': function placeholder(t) { |
| 698 return '%' + _composite(t.content); | 724 return '%' + _composite(t.content); |
| 699 }, | 725 }, |
| 700 » 'pseudoClass': function (t) { | 726 » 'pseudoClass': function pseudoClass(t) { |
| 701 return ':' + _composite(t.content); | 727 return ':' + _composite(t.content); |
| 702 }, | 728 }, |
| 703 » 'pseudoElement': function (t) { | 729 » 'pseudoElement': function pseudoElement(t) { |
| 704 return '::' + _composite(t.content); | 730 return '::' + _composite(t.content); |
| 705 }, | 731 }, |
| 706 » 'singlelineComment': function (t) { | 732 » 'singlelineComment': function singlelineComment(t) { |
| 707 return '/' + '/' + t.content; | 733 return '/' + '/' + t.content; |
| 708 }, | 734 }, |
| 709 » 'uri': function (t) { | 735 » 'universalSelector': function universalSelector(t) { |
| 736 » return _composite(t.content) + '*'; |
| 737 » }, |
| 738 » 'uri': function uri(t) { |
| 710 return 'url(' + _composite(t.content) + ')'; | 739 return 'url(' + _composite(t.content) + ')'; |
| 711 }, | 740 }, |
| 712 » 'variable': function (t) { | 741 » 'variable': function variable(t) { |
| 713 return '$' + _composite(t.content); | 742 return '$' + _composite(t.content); |
| 714 }, | 743 }, |
| 715 » 'variablesList': function (t) { | 744 » 'variablesList': function variablesList(t) { |
| 716 return _composite(t.content) + '...'; | 745 return _composite(t.content) + '...'; |
| 717 } | 746 } |
| 718 }; | 747 }; |
| 719 | 748 |
| 720 return _t(tree); | 749 return _t(tree); |
| 721 }; | 750 }; |
| 722 | 751 |
| 723 /***/ }, | 752 /***/ }, |
| 724 /* 7 */ | 753 /* 7 */ |
| 725 /***/ function(module, exports, __webpack_require__) { | 754 /***/ function(module, exports, __webpack_require__) { |
| 726 | 755 |
| 727 'use strict'; | 756 'use strict'; |
| 728 | 757 |
| 729 var ParsingError = __webpack_require__(8); | 758 var ParsingError = __webpack_require__(8); |
| 730 var syntaxes = __webpack_require__(10); | 759 var syntaxes = __webpack_require__(10); |
| 731 | 760 |
| 732 var isInteger = Number.isInteger || function (value) { | 761 var isInteger = Number.isInteger || function (value) { |
| 733 return typeof value === 'number' && Math.floor(value) === value; | 762 return typeof value === 'number' && Math.floor(value) === value; |
| 734 }; | 763 }; |
| 735 | 764 |
| 736 /** | 765 /** |
| 737 * @param {String} css | 766 * @param {String} css |
| 738 * @param {Object} options | 767 * @param {Object} options |
| 739 * @return {Object} AST | 768 * @return {Object} AST |
| 740 */ | 769 */ |
| 741 function parser(css, options) { | 770 function parser(css, options) { |
| 742 » if (typeof css !== 'string') throw new Error('Please, pass a string to
parse');else if (!css) return __webpack_require__(16)(); | 771 » if (typeof css !== 'string') throw new Error('Please, pass a string to
parse');else if (!css) return __webpack_require__(21)(); |
| 743 | 772 |
| 744 var syntax = options && options.syntax || 'css'; | 773 var syntax = options && options.syntax || 'css'; |
| 745 var context = options && options.context || 'stylesheet'; | 774 var context = options && options.context || 'stylesheet'; |
| 746 var tabSize = options && options.tabSize; | 775 var tabSize = options && options.tabSize; |
| 747 if (!isInteger(tabSize) || tabSize < 1) tabSize = 1; | 776 if (!isInteger(tabSize) || tabSize < 1) tabSize = 1; |
| 748 | 777 |
| 749 » var syntaxParser = undefined; | 778 » var syntaxParser = syntaxes[syntax]; |
| 750 » if (syntaxes[syntax]) { | |
| 751 » syntaxParser = syntaxes[syntax]; | |
| 752 » } else { | |
| 753 » syntaxParser = syntaxes; | |
| 754 » } | |
| 755 | 779 |
| 756 if (!syntaxParser) { | 780 if (!syntaxParser) { |
| 757 var message = 'Syntax "' + syntax + '" is not supported yet, sorry'; | 781 var message = 'Syntax "' + syntax + '" is not supported yet, sorry'; |
| 758 return console.error(message); | 782 return console.error(message); |
| 759 } | 783 } |
| 760 | 784 |
| 761 var getTokens = syntaxParser.tokenizer; | 785 var getTokens = syntaxParser.tokenizer; |
| 762 var mark = syntaxParser.mark; | 786 var mark = syntaxParser.mark; |
| 763 var parse = syntaxParser.parse; | 787 var parse = syntaxParser.parse; |
| 764 | 788 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 789 /** | 813 /** |
| 790 * @param {Error} e | 814 * @param {Error} e |
| 791 * @param {String} css | 815 * @param {String} css |
| 792 */ | 816 */ |
| 793 function ParsingError(e, css) { | 817 function ParsingError(e, css) { |
| 794 this.line = e.line; | 818 this.line = e.line; |
| 795 this.syntax = e.syntax; | 819 this.syntax = e.syntax; |
| 796 this.css_ = css; | 820 this.css_ = css; |
| 797 } | 821 } |
| 798 | 822 |
| 799 » ParsingError.prototype = Object.defineProperties({ | 823 » ParsingError.prototype = { |
| 800 /** | 824 /** |
| 801 * @type {String} | 825 * @type {String} |
| 802 * @private | 826 * @private |
| 803 */ | 827 */ |
| 804 customMessage_: '', | 828 customMessage_: '', |
| 805 | 829 |
| 806 /** | 830 /** |
| 807 * @type {Number} | 831 * @type {Number} |
| 808 */ | 832 */ |
| 809 line: null, | 833 line: null, |
| 810 | 834 |
| 811 /** | 835 /** |
| 812 * @type {String} | 836 * @type {String} |
| 813 */ | 837 */ |
| 814 name: 'Parsing error', | 838 name: 'Parsing error', |
| 815 | 839 |
| 816 /** | 840 /** |
| 817 * @type {String} | 841 * @type {String} |
| 818 */ | 842 */ |
| 819 syntax: null, | 843 syntax: null, |
| 820 | 844 |
| 821 /** | 845 /** |
| 822 * @type {String} | 846 * @type {String} |
| 823 */ | 847 */ |
| 824 version: parserPackage.version, | 848 version: parserPackage.version, |
| 825 | 849 |
| 826 /** | 850 /** |
| 851 * @type {String} |
| 852 */ |
| 853 get context() { |
| 854 var LINES_AROUND = 2; |
| 855 |
| 856 var result = []; |
| 857 var currentLineNumber = this.line; |
| 858 var start = currentLineNumber - 1 - LINES_AROUND; |
| 859 var end = currentLineNumber + LINES_AROUND; |
| 860 var lines = this.css_.split(/\r\n|\r|\n/); |
| 861 |
| 862 for (var i = start; i < end; i++) { |
| 863 var line = lines[i]; |
| 864 if (!line) continue; |
| 865 var ln = i + 1; |
| 866 var mark = ln === currentLineNumber ? '*' : ' '; |
| 867 result.push(ln + mark + '| ' + line); |
| 868 } |
| 869 |
| 870 return result.join('\n'); |
| 871 }, |
| 872 |
| 873 /** |
| 874 * @type {String} |
| 875 */ |
| 876 get message() { |
| 877 if (this.customMessage_) { |
| 878 return this.customMessage_; |
| 879 } else { |
| 880 var message = 'Please check validity of the block'; |
| 881 if (typeof this.line === 'number') message += ' starting from line
#' + this.line; |
| 882 return message; |
| 883 } |
| 884 }, |
| 885 |
| 886 set message(message) { |
| 887 this.customMessage_ = message; |
| 888 }, |
| 889 |
| 890 /** |
| 827 * @return {String} | 891 * @return {String} |
| 828 */ | 892 */ |
| 829 » toString: function () { | 893 » toString: function toString() { |
| 830 return [this.name + ': ' + this.message, '', this.context, '', 'Synt
ax: ' + this.syntax, 'Gonzales PE version: ' + this.version].join('\n'); | 894 return [this.name + ': ' + this.message, '', this.context, '', 'Synt
ax: ' + this.syntax, 'Gonzales PE version: ' + this.version].join('\n'); |
| 831 } | 895 } |
| 832 » }, { | 896 » }; |
| 833 » context: { /** | |
| 834 » * @type {String} | |
| 835 » */ | |
| 836 | |
| 837 » get: function () { | |
| 838 » var LINES_AROUND = 2; | |
| 839 | |
| 840 » var result = []; | |
| 841 » var currentLineNumber = this.line; | |
| 842 » var start = currentLineNumber - 1 - LINES_AROUND; | |
| 843 » var end = currentLineNumber + LINES_AROUND; | |
| 844 » var lines = this.css_.split(/\r\n|\r|\n/); | |
| 845 | |
| 846 » for (var i = start; i < end; i++) { | |
| 847 » var line = lines[i]; | |
| 848 » if (!line) continue; | |
| 849 » var ln = i + 1; | |
| 850 » var mark = ln === currentLineNumber ? '*' : ' '; | |
| 851 » result.push(ln + mark + '| ' + line); | |
| 852 » } | |
| 853 | |
| 854 » return result.join('\n'); | |
| 855 » }, | |
| 856 » configurable: true, | |
| 857 » enumerable: true | |
| 858 » }, | |
| 859 » message: { | |
| 860 | |
| 861 » /** | |
| 862 » * @type {String} | |
| 863 » */ | |
| 864 | |
| 865 » get: function () { | |
| 866 » if (this.customMessage_) { | |
| 867 » return this.customMessage_; | |
| 868 » } else { | |
| 869 » var message = 'Please check validity of the block'; | |
| 870 » if (typeof this.line === 'number') message += ' starting from li
ne #' + this.line; | |
| 871 » return message; | |
| 872 » } | |
| 873 » }, | |
| 874 » set: function (message) { | |
| 875 » this.customMessage_ = message; | |
| 876 » }, | |
| 877 » configurable: true, | |
| 878 » enumerable: true | |
| 879 » } | |
| 880 » }); | |
| 881 | 897 |
| 882 module.exports = ParsingError; | 898 module.exports = ParsingError; |
| 883 | 899 |
| 884 /***/ }, | 900 /***/ }, |
| 885 /* 9 */ | 901 /* 9 */ |
| 886 /***/ function(module, exports) { | 902 /***/ function(module, exports) { |
| 887 | 903 |
| 888 module.exports = { | 904 module.exports = { |
| 889 "name": "gonzales-pe", | 905 "name": "gonzales-pe", |
| 890 "description": "Gonzales Preprocessor Edition (fast CSS parser)"
, | 906 "description": "Gonzales Preprocessor Edition (fast CSS parser)"
, |
| 891 » » "version": "3.3.1", | 907 » » "version": "4.0.3", |
| 892 "homepage": "http://github.com/tonyganch/gonzales-pe", | 908 "homepage": "http://github.com/tonyganch/gonzales-pe", |
| 893 "bugs": "http://github.com/tonyganch/gonzales-pe/issues", | 909 "bugs": "http://github.com/tonyganch/gonzales-pe/issues", |
| 894 "license": "MIT", | 910 "license": "MIT", |
| 895 "author": { | 911 "author": { |
| 896 "name": "Tony Ganch", | 912 "name": "Tony Ganch", |
| 897 "email": "tonyganch+github@gmail.com", | 913 "email": "tonyganch+github@gmail.com", |
| 898 "url": "http://tonyganch.com" | 914 "url": "http://tonyganch.com" |
| 899 }, | 915 }, |
| 900 "main": "./lib/gonzales", | 916 "main": "./lib/gonzales", |
| 901 "repository": { | 917 "repository": { |
| 902 "type": "git", | 918 "type": "git", |
| 903 "url": "http://github.com/tonyganch/gonzales-pe.git" | 919 "url": "http://github.com/tonyganch/gonzales-pe.git" |
| 904 }, | 920 }, |
| 905 "scripts": { | 921 "scripts": { |
| 906 "autofix-tests": "bash ./scripts/build.sh && bash ./scri
pts/autofix-tests.sh", | 922 "autofix-tests": "bash ./scripts/build.sh && bash ./scri
pts/autofix-tests.sh", |
| 907 "build": "bash ./scripts/build.sh", | 923 "build": "bash ./scripts/build.sh", |
| 908 "init": "bash ./scripts/init.sh", | 924 "init": "bash ./scripts/init.sh", |
| 925 "lint": "bash ./scripts/lint.sh", |
| 909 "log": "bash ./scripts/log.sh", | 926 "log": "bash ./scripts/log.sh", |
| 910 "prepublish": "bash ./scripts/prepublish.sh", | 927 "prepublish": "bash ./scripts/prepublish.sh", |
| 911 "postpublish": "bash ./scripts/postpublish.sh", | 928 "postpublish": "bash ./scripts/postpublish.sh", |
| 912 » » » "test": "bash ./scripts/build.sh && bash ./scripts/test.
sh", | 929 » » » "test": "bash ./scripts/test.sh", |
| 913 "watch": "bash ./scripts/watch.sh" | 930 "watch": "bash ./scripts/watch.sh" |
| 914 }, | 931 }, |
| 915 "bin": { | 932 "bin": { |
| 916 "gonzales": "./bin/gonzales.js" | 933 "gonzales": "./bin/gonzales.js" |
| 917 }, | 934 }, |
| 918 "dependencies": { | 935 "dependencies": { |
| 919 "minimist": "1.1.x" | 936 "minimist": "1.1.x" |
| 920 }, | 937 }, |
| 921 "devDependencies": { | 938 "devDependencies": { |
| 922 » » » "babel-loader": "^5.3.2", | 939 » » » "babel-core": "^6.18.2", |
| 940 » » » "babel-loader": "^6.2.7", |
| 941 » » » "babel-plugin-add-module-exports": "^0.2.1", |
| 942 » » » "babel-preset-es2015": "^6.18.0", |
| 923 "coffee-script": "~1.7.1", | 943 "coffee-script": "~1.7.1", |
| 944 "eslint": "^3.0.0", |
| 924 "jscs": "2.1.0", | 945 "jscs": "2.1.0", |
| 925 "jshint": "2.8.0", | 946 "jshint": "2.8.0", |
| 926 "json-loader": "^0.5.3", | 947 "json-loader": "^0.5.3", |
| 927 "mocha": "2.2.x", | 948 "mocha": "2.2.x", |
| 928 » » » "webpack": "^1.12.2" | 949 » » » "webpack": "^1.12.2", |
| 950 » » » "webpack-closure-compiler": "^2.0.2" |
| 929 }, | 951 }, |
| 930 "engines": { | 952 "engines": { |
| 931 "node": ">=0.6.0" | 953 "node": ">=0.6.0" |
| 932 } | 954 } |
| 933 }; | 955 }; |
| 934 | 956 |
| 935 /***/ }, | 957 /***/ }, |
| 936 /* 10 */ | 958 /* 10 */ |
| 937 /***/ function(module, exports, __webpack_require__) { | 959 /***/ function(module, exports, __webpack_require__) { |
| 938 | 960 |
| 939 'use strict'; | 961 'use strict'; |
| 940 | 962 |
| 941 » exports.__esModule = true; | 963 » module.exports = { |
| 942 » exports['default'] = { | 964 » css: __webpack_require__(11), |
| 943 » mark: __webpack_require__(11), | 965 » scss: __webpack_require__(17) |
| 944 » parse: __webpack_require__(13), | |
| 945 » stringify: __webpack_require__(6), | |
| 946 » tokenizer: __webpack_require__(15) | |
| 947 }; | 966 }; |
| 948 module.exports = exports['default']; | |
| 949 | 967 |
| 950 /***/ }, | 968 /***/ }, |
| 951 /* 11 */ | 969 /* 11 */ |
| 952 /***/ function(module, exports, __webpack_require__) { | 970 /***/ function(module, exports, __webpack_require__) { |
| 953 | 971 |
| 954 'use strict'; | 972 'use strict'; |
| 955 | 973 |
| 956 » var TokenType = __webpack_require__(12); | 974 » exports.__esModule = true; |
| 975 » exports.default = { |
| 976 » mark: __webpack_require__(12), |
| 977 » parse: __webpack_require__(14), |
| 978 » stringify: __webpack_require__(3), |
| 979 » tokenizer: __webpack_require__(16) |
| 980 » }; |
| 981 » module.exports = exports['default']; |
| 957 | 982 |
| 958 » module.exports = (function () { | 983 /***/ }, |
| 959 » /** | 984 /* 12 */ |
| 960 » * Mark whitespaces and comments | 985 /***/ function(module, exports, __webpack_require__) { |
| 961 » */ | |
| 962 » function markSC(tokens) { | |
| 963 » var tokensLength = tokens.length; | |
| 964 » var ws = -1; // Flag for whitespaces | |
| 965 » var sc = -1; // Flag for whitespaces and comments | |
| 966 » var t = undefined; // Current token | |
| 967 | 986 |
| 968 » // For every token in the token list, mark spaces and line breaks | 987 » 'use strict'; |
| 969 » // as spaces (set both `ws` and `sc` flags). Mark multiline comments | |
| 970 » // with `sc` flag. | |
| 971 » // If there are several spaces or tabs or line breaks or multiline | |
| 972 » // comments in a row, group them: take the last one's index number | |
| 973 » // and save it to the first token in the group as a reference: | |
| 974 » // e.g., `ws_last = 7` for a group of whitespaces or `sc_last = 9` | |
| 975 » // for a group of whitespaces and comments. | |
| 976 » for (var i = 0; i < tokensLength; i++) { | |
| 977 » t = tokens[i]; | |
| 978 » switch (t.type) { | |
| 979 » case TokenType.Space: | |
| 980 » case TokenType.Tab: | |
| 981 » case TokenType.Newline: | |
| 982 » t.ws = true; | |
| 983 » t.sc = true; | |
| 984 | 988 |
| 985 » if (ws === -1) ws = i; | 989 » var TokenType = __webpack_require__(13); |
| 986 » if (sc === -1) sc = i; | |
| 987 | 990 |
| 988 » break; | 991 » /** |
| 989 » case TokenType.CommentML: | 992 » * Mark whitespaces and comments |
| 990 » case TokenType.CommentSL: | 993 » * @param {Array} tokens |
| 991 » if (ws !== -1) { | 994 » */ |
| 992 » tokens[ws].ws_last = i - 1; | 995 » function markSpacesAndComments(tokens) { |
| 993 » ws = -1; | 996 » var tokensLength = tokens.length; |
| 994 » } | 997 » var spaces = [-1, -1]; |
| 998 » var type; // Current token's type |
| 995 | 999 |
| 996 » t.sc = true; | 1000 » // For every token in the token list, mark spaces and line breaks |
| 1001 » // as spaces (set both `ws` and `sc` flags). Mark multiline comments |
| 1002 » // with `sc` flag. |
| 1003 » // If there are several spaces or tabs or line breaks or multiline |
| 1004 » // comments in a row, group them: take the last one's index number |
| 1005 » // and save it to the first token in the group as a reference: |
| 1006 » // e.g., `ws_last = 7` for a group of whitespaces or `sc_last = 9` |
| 1007 » // for a group of whitespaces and comments. |
| 1008 » for (var i = 0; i < tokensLength; i++) { |
| 1009 » type = tokens[i].type; |
| 997 | 1010 |
| 998 » break; | 1011 » if (type === TokenType.Space || type === TokenType.Tab || type === T
okenType.Newline) { |
| 999 » default: | 1012 » markSpace(tokens, i, spaces); |
| 1000 » if (ws !== -1) { | 1013 » } else if (type === TokenType.CommentML) { |
| 1001 » tokens[ws].ws_last = i - 1; | 1014 » markComment(tokens, i, spaces); |
| 1002 » ws = -1; | 1015 » } else { |
| 1003 » } | 1016 » markEndOfSpacesAndComments(tokens, i, spaces); |
| 1004 | |
| 1005 » if (sc !== -1) { | |
| 1006 » tokens[sc].sc_last = i - 1; | |
| 1007 » sc = -1; | |
| 1008 » } | |
| 1009 » } | |
| 1010 } | 1017 } |
| 1011 | |
| 1012 if (ws !== -1) tokens[ws].ws_last = i - 1; | |
| 1013 if (sc !== -1) tokens[sc].sc_last = i - 1; | |
| 1014 } | 1018 } |
| 1015 | 1019 |
| 1016 » /** | 1020 » markEndOfSpacesAndComments(tokens, i, spaces); |
| 1017 » * Pair brackets | 1021 » } |
| 1018 » */ | |
| 1019 » function markBrackets(tokens) { | |
| 1020 » var tokensLength = tokens.length; | |
| 1021 » var ps = []; // Parentheses | |
| 1022 » var sbs = []; // Square brackets | |
| 1023 » var cbs = []; // Curly brackets | |
| 1024 » var t = undefined; // Current token | |
| 1025 | 1022 |
| 1026 » // For every token in the token list, if we meet an opening (left) | 1023 » function markSpace(tokens, i, spaces) { |
| 1027 » // bracket, push its index number to a corresponding array. | 1024 » var token = tokens[i]; |
| 1028 » // If we then meet a closing (right) bracket, look at the correspond
ing | 1025 » token.ws = true; |
| 1029 » // array. If there are any elements (records about previously met | 1026 » token.sc = true; |
| 1030 » // left brackets), take a token of the last left bracket (take | 1027 |
| 1031 » // the last index number from the array and find a token with | 1028 » if (spaces[0] === -1) spaces[0] = i; |
| 1032 » // this index number) and save right bracket's index as a reference: | 1029 » if (spaces[1] === -1) spaces[1] = i; |
| 1033 » for (var i = 0; i < tokensLength; i++) { | 1030 » } |
| 1034 » t = tokens[i]; | 1031 |
| 1035 » switch (t.type) { | 1032 » function markComment(tokens, i, spaces) { |
| 1036 » case TokenType.LeftParenthesis: | 1033 » var ws = spaces[0]; |
| 1037 » ps.push(i); | 1034 » tokens[i].sc = true; |
| 1038 » break; | 1035 |
| 1039 » case TokenType.RightParenthesis: | 1036 » if (ws !== -1) { |
| 1040 » if (ps.length) { | 1037 » tokens[ws].ws_last = i - 1; |
| 1041 » t.left = ps.pop(); | 1038 » spaces[0] = -1; |
| 1042 » tokens[t.left].right = i; | 1039 » } |
| 1043 » } | 1040 » } |
| 1044 » break; | 1041 |
| 1045 » case TokenType.LeftSquareBracket: | 1042 » function markEndOfSpacesAndComments(tokens, i, spaces) { |
| 1046 » sbs.push(i); | 1043 » var ws = spaces[0]; |
| 1047 » break; | 1044 » var sc = spaces[1]; |
| 1048 » case TokenType.RightSquareBracket: | 1045 » if (ws !== -1) { |
| 1049 » if (sbs.length) { | 1046 » tokens[ws].ws_last = i - 1; |
| 1050 » t.left = sbs.pop(); | 1047 » spaces[0] = -1; |
| 1051 » tokens[t.left].right = i; | 1048 » } |
| 1052 » } | 1049 » if (sc !== -1) { |
| 1053 » break; | 1050 » tokens[sc].sc_last = i - 1; |
| 1054 » case TokenType.LeftCurlyBracket: | 1051 » spaces[1] = -1; |
| 1055 » cbs.push(i); | 1052 » } |
| 1056 » break; | 1053 » } |
| 1057 » case TokenType.RightCurlyBracket: | 1054 |
| 1058 » if (cbs.length) { | 1055 » /** |
| 1059 » t.left = cbs.pop(); | 1056 » * Pair brackets |
| 1060 » tokens[t.left].right = i; | 1057 » * @param {Array} tokens |
| 1061 » } | 1058 » */ |
| 1062 » break; | 1059 » function markBrackets(tokens) { |
| 1060 » var tokensLength = tokens.length; |
| 1061 » var ps = []; // Parentheses |
| 1062 » var sbs = []; // Square brackets |
| 1063 » var cbs = []; // Curly brackets |
| 1064 » var t = void 0; // Current token |
| 1065 |
| 1066 » // For every token in the token list, if we meet an opening (left) |
| 1067 » // bracket, push its index number to a corresponding array. |
| 1068 » // If we then meet a closing (right) bracket, look at the correspondin
g |
| 1069 » // array. If there are any elements (records about previously met |
| 1070 » // left brackets), take a token of the last left bracket (take |
| 1071 » // the last index number from the array and find a token with |
| 1072 » // this index number) and save right bracket's index as a reference: |
| 1073 » for (var i = 0; i < tokensLength; i++) { |
| 1074 » t = tokens[i]; |
| 1075 » var type = t.type; |
| 1076 |
| 1077 » if (type === TokenType.LeftParenthesis) { |
| 1078 » ps.push(i); |
| 1079 » } else if (type === TokenType.RightParenthesis) { |
| 1080 » if (ps.length) { |
| 1081 » t.left = ps.pop(); |
| 1082 » tokens[t.left].right = i; |
| 1083 » } |
| 1084 » } else if (type === TokenType.LeftSquareBracket) { |
| 1085 » sbs.push(i); |
| 1086 » } else if (type === TokenType.RightSquareBracket) { |
| 1087 » if (sbs.length) { |
| 1088 » t.left = sbs.pop(); |
| 1089 » tokens[t.left].right = i; |
| 1090 » } |
| 1091 » } else if (type === TokenType.LeftCurlyBracket) { |
| 1092 » cbs.push(i); |
| 1093 » } else if (type === TokenType.RightCurlyBracket) { |
| 1094 » if (cbs.length) { |
| 1095 » t.left = cbs.pop(); |
| 1096 » tokens[t.left].right = i; |
| 1063 } | 1097 } |
| 1064 } | 1098 } |
| 1065 } | 1099 } |
| 1100 } |
| 1066 | 1101 |
| 1067 » return function (tokens) { | 1102 » /** |
| 1068 » markBrackets(tokens); | 1103 » * @param {Array} tokens |
| 1069 » markSC(tokens); | 1104 » */ |
| 1070 » }; | 1105 » function markTokens(tokens) { |
| 1071 » })(); | 1106 » // Mark paired brackets: |
| 1107 » markBrackets(tokens); |
| 1108 » // Mark whitespaces and comments: |
| 1109 » markSpacesAndComments(tokens); |
| 1110 » } |
| 1111 |
| 1112 » module.exports = markTokens; |
| 1072 | 1113 |
| 1073 /***/ }, | 1114 /***/ }, |
| 1074 /* 12 */ | 1115 /* 13 */ |
| 1075 /***/ function(module, exports) { | 1116 /***/ function(module, exports) { |
| 1076 | 1117 |
| 1077 // jscs:disable | 1118 // jscs:disable |
| 1078 | 1119 |
| 1079 'use strict'; | 1120 'use strict'; |
| 1080 | 1121 |
| 1081 module.exports = { | 1122 module.exports = { |
| 1082 StringSQ: 'StringSQ', | 1123 StringSQ: 'StringSQ', |
| 1083 StringDQ: 'StringDQ', | 1124 StringDQ: 'StringDQ', |
| 1084 CommentML: 'CommentML', | 1125 CommentML: 'CommentML', |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1120 LeftCurlyBracket: 'LeftCurlyBracket', // { | 1161 LeftCurlyBracket: 'LeftCurlyBracket', // { |
| 1121 VerticalLine: 'VerticalLine', // | | 1162 VerticalLine: 'VerticalLine', // | |
| 1122 RightCurlyBracket: 'RightCurlyBracket', // } | 1163 RightCurlyBracket: 'RightCurlyBracket', // } |
| 1123 Tilde: 'Tilde', // ~ | 1164 Tilde: 'Tilde', // ~ |
| 1124 | 1165 |
| 1125 Identifier: 'Identifier', | 1166 Identifier: 'Identifier', |
| 1126 DecimalNumber: 'DecimalNumber' | 1167 DecimalNumber: 'DecimalNumber' |
| 1127 }; | 1168 }; |
| 1128 | 1169 |
| 1129 /***/ }, | 1170 /***/ }, |
| 1130 /* 13 */ | 1171 /* 14 */ |
| 1131 /***/ function(module, exports, __webpack_require__) { | 1172 /***/ function(module, exports, __webpack_require__) { |
| 1132 | 1173 |
| 1133 // jscs:disable maximumLineLength | 1174 'use strict'; |
| 1134 'use strict';var Node=__webpack_require__(1);var NodeType=__webpack_requ
ire__(14);var TokenType=__webpack_require__(12);var tokens=undefined;var tokensL
ength=undefined;var pos=undefined;var contexts={'arguments':function(){return ch
eckArguments(pos) && getArguments();},'atkeyword':function(){return checkAtkeywo
rd(pos) && getAtkeyword();},'atrule':function(){return checkAtrule(pos) && getAt
rule();},'block':function(){return checkBlock(pos) && getBlock();},'brackets':fu
nction(){return checkBrackets(pos) && getBrackets();},'class':function(){return
checkClass(pos) && getClass();},'combinator':function(){return checkCombinator(p
os) && getCombinator();},'commentML':function(){return checkCommentML(pos) && ge
tCommentML();},'commentSL':function(){return checkCommentSL(pos) && getCommentSL
();},'condition':function(){return checkCondition(pos) && getCondition();},'cond
itionalStatement':function(){return checkConditionalStatement(pos) && getConditi
onalStatement();},'declaration':function(){return checkDeclaration(pos) && getDe
claration();},'declDelim':function(){return checkDeclDelim(pos) && getDeclDelim(
);},'default':function(){return checkDefault(pos) && getDefault();},'delim':func
tion(){return checkDelim(pos) && getDelim();},'dimension':function(){return chec
kDimension(pos) && getDimension();},'expression':function(){return checkExpressi
on(pos) && getExpression();},'extend':function(){return checkExtend(pos) && getE
xtend();},'function':function(){return checkFunction(pos) && getFunction();},'gl
obal':function(){return checkGlobal(pos) && getGlobal();},'ident':function(){ret
urn checkIdent(pos) && getIdent();},'important':function(){return checkImportant
(pos) && getImportant();},'include':function(){return checkInclude(pos) && getIn
clude();},'interpolation':function(){return checkInterpolation(pos) && getInterp
olation();},'loop':function(){return checkLoop(pos) && getLoop();},'mixin':funct
ion(){return checkMixin(pos) && getMixin();},'namespace':function(){return check
Namespace(pos) && getNamespace();},'number':function(){return checkNumber(pos) &
& getNumber();},'operator':function(){return checkOperator(pos) && getOperator()
;},'optional':function(){return checkOptional(pos) && getOptional();},'parenthes
es':function(){return checkParentheses(pos) && getParentheses();},'parentselecto
r':function(){return checkParentSelector(pos) && getParentSelector();},'percenta
ge':function(){return checkPercentage(pos) && getPercentage();},'placeholder':fu
nction(){return checkPlaceholder(pos) && getPlaceholder();},'progid':function(){
return checkProgid(pos) && getProgid();},'property':function(){return checkPrope
rty(pos) && getProperty();},'propertyDelim':function(){return checkPropertyDelim
(pos) && getPropertyDelim();},'pseudoc':function(){return checkPseudoc(pos) && g
etPseudoc();},'pseudoe':function(){return checkPseudoe(pos) && getPseudoe();},'r
uleset':function(){return checkRuleset(pos) && getRuleset();},'s':function(){ret
urn checkS(pos) && getS();},'selector':function(){return checkSelector(pos) && g
etSelector();},'shash':function(){return checkShash(pos) && getShash();},'string
':function(){return checkString(pos) && getString();},'stylesheet':function(){re
turn checkStylesheet(pos) && getStylesheet();},'unary':function(){return checkUn
ary(pos) && getUnary();},'uri':function(){return checkUri(pos) && getUri();},'va
lue':function(){return checkValue(pos) && getValue();},'variable':function(){ret
urn checkVariable(pos) && getVariable();},'variableslist':function(){return chec
kVariablesList(pos) && getVariablesList();},'vhash':function(){return checkVhash
(pos) && getVhash();}}; /** | 1175 |
| 1176 var Node = __webpack_require__(1); |
| 1177 var NodeType = __webpack_require__(15); |
| 1178 var TokenType = __webpack_require__(13); |
| 1179 |
| 1180 /** |
| 1181 * @type {Array} |
| 1182 */ |
| 1183 var tokens; |
| 1184 |
| 1185 /** |
| 1186 * @type {Number} |
| 1187 */ |
| 1188 var tokensLength; |
| 1189 |
| 1190 /** |
| 1191 * @type {Number} |
| 1192 */ |
| 1193 var pos; |
| 1194 |
| 1195 var contexts = { |
| 1196 'atkeyword': function atkeyword() { |
| 1197 return checkAtkeyword(pos) && getAtkeyword(); |
| 1198 }, |
| 1199 'atrule': function atrule() { |
| 1200 return checkAtrule(pos) && getAtrule(); |
| 1201 }, |
| 1202 'block': function block() { |
| 1203 return checkBlock(pos) && getBlock(); |
| 1204 }, |
| 1205 'brackets': function brackets() { |
| 1206 return checkBrackets(pos) && getBrackets(); |
| 1207 }, |
| 1208 'class': function _class() { |
| 1209 return checkClass(pos) && getClass(); |
| 1210 }, |
| 1211 'combinator': function combinator() { |
| 1212 return checkCombinator(pos) && getCombinator(); |
| 1213 }, |
| 1214 'commentML': function commentML() { |
| 1215 return checkCommentML(pos) && getCommentML(); |
| 1216 }, |
| 1217 'declaration': function declaration() { |
| 1218 return checkDeclaration(pos) && getDeclaration(); |
| 1219 }, |
| 1220 'declDelim': function declDelim() { |
| 1221 return checkDeclDelim(pos) && getDeclDelim(); |
| 1222 }, |
| 1223 'delim': function delim() { |
| 1224 return checkDelim(pos) && getDelim(); |
| 1225 }, |
| 1226 'dimension': function dimension() { |
| 1227 return checkDimension(pos) && getDimension(); |
| 1228 }, |
| 1229 'expression': function expression() { |
| 1230 return checkExpression(pos) && getExpression(); |
| 1231 }, |
| 1232 'function': function _function() { |
| 1233 return checkFunction(pos) && getFunction(); |
| 1234 }, |
| 1235 'ident': function ident() { |
| 1236 return checkIdent(pos) && getIdent(); |
| 1237 }, |
| 1238 'important': function important() { |
| 1239 return checkImportant(pos) && getImportant(); |
| 1240 }, |
| 1241 'namespace': function namespace() { |
| 1242 return checkNamespace(pos) && getNamespace(); |
| 1243 }, |
| 1244 'number': function number() { |
| 1245 return checkNumber(pos) && getNumber(); |
| 1246 }, |
| 1247 'operator': function operator() { |
| 1248 return checkOperator(pos) && getOperator(); |
| 1249 }, |
| 1250 'parentheses': function parentheses() { |
| 1251 return checkParentheses(pos) && getParentheses(); |
| 1252 }, |
| 1253 'percentage': function percentage() { |
| 1254 return checkPercentage(pos) && getPercentage(); |
| 1255 }, |
| 1256 'progid': function progid() { |
| 1257 return checkProgid(pos) && getProgid(); |
| 1258 }, |
| 1259 'property': function property() { |
| 1260 return checkProperty(pos) && getProperty(); |
| 1261 }, |
| 1262 'propertyDelim': function propertyDelim() { |
| 1263 return checkPropertyDelim(pos) && getPropertyDelim(); |
| 1264 }, |
| 1265 'pseudoc': function pseudoc() { |
| 1266 return checkPseudoc(pos) && getPseudoc(); |
| 1267 }, |
| 1268 'pseudoe': function pseudoe() { |
| 1269 return checkPseudoe(pos) && getPseudoe(); |
| 1270 }, |
| 1271 'ruleset': function ruleset() { |
| 1272 return checkRuleset(pos) && getRuleset(); |
| 1273 }, |
| 1274 's': function s() { |
| 1275 return checkS(pos) && getS(); |
| 1276 }, |
| 1277 'selector': function selector() { |
| 1278 return checkSelector(pos) && getSelector(); |
| 1279 }, |
| 1280 'shash': function shash() { |
| 1281 return checkShash(pos) && getShash(); |
| 1282 }, |
| 1283 'string': function string() { |
| 1284 return checkString(pos) && getString(); |
| 1285 }, |
| 1286 'stylesheet': function stylesheet() { |
| 1287 return checkStylesheet(pos) && getStylesheet(); |
| 1288 }, |
| 1289 'unary': function unary() { |
| 1290 return checkUnary(pos) && getUnary(); |
| 1291 }, |
| 1292 'unicodeRange': function unicodeRange() { |
| 1293 return checkUnicodeRange(pos) && getUnicodeRange(); |
| 1294 }, |
| 1295 'universalSelector': function universalSelector() { |
| 1296 return checkUniversalSelector(pos) && getUniversalSelector(); |
| 1297 }, |
| 1298 'urange': function urange() { |
| 1299 return checkUrange(pos) && getUrange(); |
| 1300 }, |
| 1301 'uri': function uri() { |
| 1302 return checkUri(pos) && getUri(); |
| 1303 }, |
| 1304 'value': function value() { |
| 1305 return checkValue(pos) && getValue(); |
| 1306 }, |
| 1307 'vhash': function vhash() { |
| 1308 return checkVhash(pos) && getVhash(); |
| 1309 } |
| 1310 }; |
| 1311 |
| 1312 /** |
| 1313 * Stop parsing and display error. |
| 1314 * @param {Number=} i Token's index number |
| 1315 */ |
| 1316 function throwError(i) { |
| 1317 var ln = tokens[i].ln; |
| 1318 |
| 1319 throw { line: ln, syntax: 'css' }; |
| 1320 } |
| 1321 |
| 1322 /** |
| 1323 * @param {Object} exclude |
| 1324 * @param {Number} i Token's index number |
| 1325 * @return {Number} |
| 1326 */ |
| 1327 function checkExcluding(exclude, i) { |
| 1328 var start = i; |
| 1329 |
| 1330 while (i < tokensLength) { |
| 1331 if (exclude[tokens[i++].type]) break; |
| 1332 } |
| 1333 |
| 1334 return i - start - 2; |
| 1335 } |
| 1336 |
| 1337 /** |
| 1338 * @param {Number} start |
| 1339 * @param {Number} finish |
| 1340 * @return {String} |
| 1341 */ |
| 1342 function joinValues(start, finish) { |
| 1343 var s = ''; |
| 1344 |
| 1345 for (var i = start; i < finish + 1; i++) { |
| 1346 s += tokens[i].value; |
| 1347 } |
| 1348 |
| 1349 return s; |
| 1350 } |
| 1351 |
| 1352 /** |
| 1353 * @param {Number} start |
| 1354 * @param {Number} num |
| 1355 * @return {String} |
| 1356 */ |
| 1357 function joinValues2(start, num) { |
| 1358 if (start + num - 1 >= tokensLength) return; |
| 1359 |
| 1360 var s = ''; |
| 1361 |
| 1362 for (var i = 0; i < num; i++) { |
| 1363 s += tokens[start + i].value; |
| 1364 } |
| 1365 |
| 1366 return s; |
| 1367 } |
| 1368 |
| 1369 function getLastPosition(content, line, column, colOffset) { |
| 1370 return typeof content === 'string' ? getLastPositionForString(content,
line, column, colOffset) : getLastPositionForArray(content, line, column, colOf
fset); |
| 1371 } |
| 1372 |
| 1373 function getLastPositionForString(content, line, column, colOffset) { |
| 1374 var position = []; |
| 1375 |
| 1376 if (!content) { |
| 1377 position = [line, column]; |
| 1378 if (colOffset) position[1] += colOffset - 1; |
| 1379 return position; |
| 1380 } |
| 1381 |
| 1382 var lastLinebreak = content.lastIndexOf('\n'); |
| 1383 var endsWithLinebreak = lastLinebreak === content.length - 1; |
| 1384 var splitContent = content.split('\n'); |
| 1385 var linebreaksCount = splitContent.length - 1; |
| 1386 var prevLinebreak = linebreaksCount === 0 || linebreaksCount === 1 ? -
1 : content.length - splitContent[linebreaksCount - 1].length - 2; |
| 1387 |
| 1388 // Line: |
| 1389 var offset = endsWithLinebreak ? linebreaksCount - 1 : linebreaksCount
; |
| 1390 position[0] = line + offset; |
| 1391 |
| 1392 // Column: |
| 1393 if (endsWithLinebreak) { |
| 1394 offset = prevLinebreak !== -1 ? content.length - prevLinebreak : con
tent.length - 1; |
| 1395 } else { |
| 1396 offset = linebreaksCount !== 0 ? content.length - lastLinebreak - co
lumn - 1 : content.length - 1; |
| 1397 } |
| 1398 position[1] = column + offset; |
| 1399 |
| 1400 if (!colOffset) return position; |
| 1401 |
| 1402 if (endsWithLinebreak) { |
| 1403 position[0]++; |
| 1404 position[1] = colOffset; |
| 1405 } else { |
| 1406 position[1] += colOffset; |
| 1407 } |
| 1408 |
| 1409 return position; |
| 1410 } |
| 1411 |
| 1412 function getLastPositionForArray(content, line, column, colOffset) { |
| 1413 var position; |
| 1414 |
| 1415 if (content.length === 0) { |
| 1416 position = [line, column]; |
| 1417 } else { |
| 1418 var c = content[content.length - 1]; |
| 1419 if (c.hasOwnProperty('end')) { |
| 1420 position = [c.end.line, c.end.column]; |
| 1421 } else { |
| 1422 position = getLastPosition(c.content, line, column); |
| 1423 } |
| 1424 } |
| 1425 |
| 1426 if (!colOffset) return position; |
| 1427 |
| 1428 if (tokens[pos - 1] && tokens[pos - 1].type !== 'Newline') { |
| 1429 position[1] += colOffset; |
| 1430 } else { |
| 1431 position[0]++; |
| 1432 position[1] = 1; |
| 1433 } |
| 1434 |
| 1435 return position; |
| 1436 } |
| 1437 |
| 1438 function newNode(type, content, line, column, end) { |
| 1439 if (!end) end = getLastPosition(content, line, column); |
| 1440 return new Node({ |
| 1441 type: type, |
| 1442 content: content, |
| 1443 start: { |
| 1444 line: line, |
| 1445 column: column |
| 1446 }, |
| 1447 end: { |
| 1448 line: end[0], |
| 1449 column: end[1] |
| 1450 }, |
| 1451 syntax: 'css' |
| 1452 }); |
| 1453 } |
| 1454 |
| 1455 /** |
| 1456 * @param {Number} i Token's index number |
| 1457 * @return {Number} |
| 1458 */ |
| 1459 function checkAny(i) { |
| 1460 var l; |
| 1461 |
| 1462 if (l = checkBrackets(i)) tokens[i].any_child = 1;else if (l = checkPa
rentheses(i)) tokens[i].any_child = 2;else if (l = checkString(i)) tokens[i].any
_child = 3;else if (l = checkPercentage(i)) tokens[i].any_child = 4;else if (l =
checkDimension(i)) tokens[i].any_child = 5;else if (l = checkUnicodeRange(i)) t
okens[i].any_child = 13;else if (l = checkNumber(i)) tokens[i].any_child = 6;els
e if (l = checkUri(i)) tokens[i].any_child = 7;else if (l = checkExpression(i))
tokens[i].any_child = 8;else if (l = checkFunction(i)) tokens[i].any_child = 9;e
lse if (l = checkIdent(i)) tokens[i].any_child = 10;else if (l = checkClass(i))
tokens[i].any_child = 11;else if (l = checkUnary(i)) tokens[i].any_child = 12; |
| 1463 |
| 1464 return l; |
| 1465 } |
| 1466 |
| 1467 /** |
| 1468 * @return {Node} |
| 1469 */ |
| 1470 function getAny() { |
| 1471 var childType = tokens[pos].any_child; |
| 1472 |
| 1473 if (childType === 1) return getBrackets();else if (childType === 2) re
turn getParentheses();else if (childType === 3) return getString();else if (chil
dType === 4) return getPercentage();else if (childType === 5) return getDimensio
n();else if (childType === 13) return getUnicodeRange();else if (childType === 6
) return getNumber();else if (childType === 7) return getUri();else if (childTyp
e === 8) return getExpression();else if (childType === 9) return getFunction();e
lse if (childType === 10) return getIdent();else if (childType === 11) return ge
tClass();else if (childType === 12) return getUnary(); |
| 1474 } |
| 1475 |
| 1476 /** |
| 1477 * Check if token is part of an @-word (e.g. `@import`, `@include`) |
| 1478 * @param {Number} i Token's index number |
| 1479 * @return {Number} |
| 1480 */ |
| 1481 function checkAtkeyword(i) { |
| 1482 var l; |
| 1483 |
| 1484 // Check that token is `@`: |
| 1485 if (i >= tokensLength || tokens[i++].type !== TokenType.CommercialAt)
return 0; |
| 1486 |
| 1487 return (l = checkIdent(i)) ? l + 1 : 0; |
| 1488 } |
| 1489 |
| 1490 /** |
| 1491 * Get node with @-word |
| 1492 * @return {Node} |
| 1493 */ |
| 1494 function getAtkeyword() { |
| 1495 var type = NodeType.AtkeywordType; |
| 1496 var token = tokens[pos]; |
| 1497 var line = token.ln; |
| 1498 var column = token.col; |
| 1499 var content = []; |
| 1500 |
| 1501 pos++; |
| 1502 |
| 1503 content.push(getIdent()); |
| 1504 |
| 1505 return newNode(type, content, line, column); |
| 1506 } |
| 1507 |
| 1508 /** |
| 1509 * Check if token is a part of an @-rule |
| 1510 * @param {Number} i Token's index number |
| 1511 * @return {Number} Length of @-rule |
| 1512 */ |
| 1513 function checkAtrule(i) { |
| 1514 var l; |
| 1515 |
| 1516 if (i >= tokensLength) return 0; |
| 1517 |
| 1518 // If token already has a record of being part of an @-rule, |
| 1519 // return the @-rule's length: |
| 1520 if (tokens[i].atrule_l !== undefined) return tokens[i].atrule_l; |
| 1521 |
| 1522 // If token is part of an @-rule, save the rule's type to token. |
| 1523 // @keyframes: |
| 1524 if (l = checkKeyframesRule(i)) tokens[i].atrule_type = 4; |
| 1525 // @-rule with ruleset: |
| 1526 else if (l = checkAtruler(i)) tokens[i].atrule_type = 1; |
| 1527 // Block @-rule: |
| 1528 else if (l = checkAtruleb(i)) tokens[i].atrule_type = 2; |
| 1529 // Single-line @-rule: |
| 1530 else if (l = checkAtrules(i)) tokens[i].atrule_type = 3;else retur
n 0; |
| 1531 |
| 1532 // If token is part of an @-rule, save the rule's length to token: |
| 1533 tokens[i].atrule_l = l; |
| 1534 |
| 1535 return l; |
| 1536 } |
| 1537 |
| 1538 /** |
| 1539 * Get node with @-rule |
| 1540 * @return {Node} |
| 1541 */ |
| 1542 function getAtrule() { |
| 1543 switch (tokens[pos].atrule_type) { |
| 1544 case 1: |
| 1545 return getAtruler(); // @-rule with ruleset |
| 1546 case 2: |
| 1547 return getAtruleb(); // Block @-rule |
| 1548 case 3: |
| 1549 return getAtrules(); // Single-line @-rule |
| 1550 case 4: |
| 1551 return getKeyframesRule(); |
| 1552 } |
| 1553 } |
| 1554 |
| 1555 /** |
| 1556 * Check if token is part of a block @-rule |
| 1557 * @param {Number} i Token's index number |
| 1558 * @return {Number} Length of the @-rule |
| 1559 */ |
| 1560 function checkAtruleb(i) { |
| 1561 var start = i; |
| 1562 var l = void 0; |
| 1563 |
| 1564 if (i >= tokensLength) return 0; |
| 1565 |
| 1566 if (l = checkAtkeyword(i)) i += l;else return 0; |
| 1567 |
| 1568 if (l = checkTsets(i)) i += l; |
| 1569 |
| 1570 if (l = checkBlock(i)) i += l;else return 0; |
| 1571 |
| 1572 return i - start; |
| 1573 } |
| 1574 |
| 1575 /** |
| 1576 * Get node with a block @-rule |
| 1577 * @return {Node} |
| 1578 */ |
| 1579 function getAtruleb() { |
| 1580 var type = NodeType.AtruleType; |
| 1581 var token = tokens[pos]; |
| 1582 var line = token.ln; |
| 1583 var column = token.col; |
| 1584 var content = [getAtkeyword()].concat(getTsets()).concat([getBlock()])
; |
| 1585 |
| 1586 return newNode(type, content, line, column); |
| 1587 } |
| 1588 |
| 1589 /** |
| 1590 * Check if token is part of an @-rule with ruleset |
| 1591 * @param {Number} i Token's index number |
| 1592 * @return {Number} Length of the @-rule |
| 1593 */ |
| 1594 function checkAtruler(i) { |
| 1595 var start = i; |
| 1596 var l = void 0; |
| 1597 |
| 1598 if (i >= tokensLength) return 0; |
| 1599 |
| 1600 if (l = checkAtkeyword(i)) i += l;else return 0; |
| 1601 |
| 1602 if (l = checkTsets(i)) i += l; |
| 1603 |
| 1604 if (i < tokensLength && tokens[i].type === TokenType.LeftCurlyBracket)
i++;else return 0; |
| 1605 |
| 1606 if (l = checkAtrulers(i)) i += l; |
| 1607 |
| 1608 if (i < tokensLength && tokens[i].type === TokenType.RightCurlyBracket
) i++;else return 0; |
| 1609 |
| 1610 return i - start; |
| 1611 } |
| 1612 |
| 1613 /** |
| 1614 * Get node with an @-rule with ruleset |
| 1615 * @return {Node} |
| 1616 */ |
| 1617 function getAtruler() { |
| 1618 var type = NodeType.AtruleType; |
| 1619 var token = tokens[pos]; |
| 1620 var line = token.ln; |
| 1621 var column = token.col; |
| 1622 var content = [getAtkeyword()]; |
| 1623 |
| 1624 content = content.concat(getTsets()); |
| 1625 |
| 1626 content.push(getAtrulers()); |
| 1627 |
| 1628 return newNode(type, content, line, column); |
| 1629 } |
| 1630 |
| 1631 /** |
| 1632 * @param {Number} i Token's index number |
| 1633 * @return {Number} |
| 1634 */ |
| 1635 function checkAtrulers(i) { |
| 1636 var start = i; |
| 1637 var l = void 0; |
| 1638 |
| 1639 if (i >= tokensLength) return 0; |
| 1640 |
| 1641 if (l = checkSC(i)) i += l; |
| 1642 |
| 1643 while (i < tokensLength) { |
| 1644 if (l = checkSC(i)) tokens[i].atrulers_child = 1;else if (l = checkA
trule(i)) tokens[i].atrulers_child = 2;else if (l = checkRuleset(i)) tokens[i].a
trulers_child = 3;else break; |
| 1645 i += l; |
| 1646 } |
| 1647 |
| 1648 tokens[i].atrulers_end = 1; |
| 1649 |
| 1650 if (l = checkSC(i)) i += l; |
| 1651 |
| 1652 return i - start; |
| 1653 } |
| 1654 |
| 1655 /** |
| 1656 * @return {Node} |
| 1657 */ |
| 1658 function getAtrulers() { |
| 1659 var type = NodeType.BlockType; |
| 1660 var token = tokens[pos++]; |
| 1661 var line = token.ln; |
| 1662 var column = token.col; |
| 1663 var content = getSC(); |
| 1664 |
| 1665 while (!tokens[pos].atrulers_end) { |
| 1666 var childType = tokens[pos].atrulers_child; |
| 1667 if (childType === 1) content = content.concat(getSC());else if (chil
dType === 2) content.push(getAtrule());else if (childType === 3) content.push(ge
tRuleset()); |
| 1668 } |
| 1669 |
| 1670 content = content.concat(getSC()); |
| 1671 |
| 1672 var end = getLastPosition(content, line, column, 1); |
| 1673 pos++; |
| 1674 |
| 1675 return newNode(type, content, line, column, end); |
| 1676 } |
| 1677 |
| 1678 /** |
| 1679 * @param {Number} i Token's index number |
| 1680 * @return {Number} |
| 1681 */ |
| 1682 function checkAtrules(i) { |
| 1683 var start = i; |
| 1684 var l = void 0; |
| 1685 |
| 1686 if (i >= tokensLength) return 0; |
| 1687 |
| 1688 if (l = checkAtkeyword(i)) i += l;else return 0; |
| 1689 |
| 1690 if (l = checkTsets(i)) i += l; |
| 1691 |
| 1692 return i - start; |
| 1693 } |
| 1694 |
| 1695 /** |
| 1696 * @return {Node} |
| 1697 */ |
| 1698 function getAtrules() { |
| 1699 var type = NodeType.AtruleType; |
| 1700 var token = tokens[pos]; |
| 1701 var line = token.ln; |
| 1702 var column = token.col; |
| 1703 var content = [getAtkeyword()].concat(getTsets()); |
| 1704 |
| 1705 return newNode(type, content, line, column); |
| 1706 } |
| 1707 |
| 1708 /** |
| 1709 * Check if token is part of a block (e.g. `{...}`). |
| 1710 * @param {Number} i Token's index number |
| 1711 * @return {Number} Length of the block |
| 1712 */ |
| 1713 function checkBlock(i) { |
| 1714 return i < tokensLength && tokens[i].type === TokenType.LeftCurlyBrack
et ? tokens[i].right - i + 1 : 0; |
| 1715 } |
| 1716 |
| 1717 /** |
| 1718 * Get node with a block |
| 1719 * @return {Node} |
| 1720 */ |
| 1721 function getBlock() { |
| 1722 var type = NodeType.BlockType; |
| 1723 var token = tokens[pos]; |
| 1724 var line = token.ln; |
| 1725 var column = token.col; |
| 1726 var end = tokens[pos++].right; |
| 1727 var content = []; |
| 1728 |
| 1729 while (pos < end) { |
| 1730 if (checkBlockdecl(pos)) content = content.concat(getBlockdecl());el
se throwError(pos); |
| 1731 } |
| 1732 |
| 1733 var end_ = getLastPosition(content, line, column, 1); |
| 1734 pos = end + 1; |
| 1735 |
| 1736 return newNode(type, content, line, column, end_); |
| 1737 } |
| 1738 |
| 1739 /** |
| 1740 * Check if token is part of a declaration (property-value pair) |
| 1741 * @param {Number} i Token's index number |
| 1742 * @return {Number} Length of the declaration |
| 1743 */ |
| 1744 function checkBlockdecl(i) { |
| 1745 var l; |
| 1746 |
| 1747 if (i >= tokensLength) return 0; |
| 1748 |
| 1749 if (l = checkBlockdecl1(i)) tokens[i].bd_type = 1;else if (l = checkBl
ockdecl2(i)) tokens[i].bd_type = 2;else if (l = checkBlockdecl3(i)) tokens[i].bd
_type = 3;else if (l = checkBlockdecl4(i)) tokens[i].bd_type = 4;else return 0; |
| 1750 |
| 1751 return l; |
| 1752 } |
| 1753 |
| 1754 /** |
| 1755 * @return {Array} |
| 1756 */ |
| 1757 function getBlockdecl() { |
| 1758 switch (tokens[pos].bd_type) { |
| 1759 case 1: |
| 1760 return getBlockdecl1(); |
| 1761 case 2: |
| 1762 return getBlockdecl2(); |
| 1763 case 3: |
| 1764 return getBlockdecl3(); |
| 1765 case 4: |
| 1766 return getBlockdecl4(); |
| 1767 } |
| 1768 } |
| 1769 |
| 1770 /** |
| 1771 * @param {Number} i Token's index number |
| 1772 * @return {Number} |
| 1773 */ |
| 1774 function checkBlockdecl1(i) { |
| 1775 var start = i; |
| 1776 var l = void 0; |
| 1777 |
| 1778 if (l = checkSC(i)) i += l; |
| 1779 |
| 1780 if (l = checkDeclaration(i)) tokens[i].bd_kind = 1;else if (l = checkA
trule(i)) tokens[i].bd_kind = 2;else return 0; |
| 1781 |
| 1782 i += l; |
| 1783 |
| 1784 if (l = checkSC(i)) i += l; |
| 1785 |
| 1786 if (i < tokensLength && (l = checkDeclDelim(i))) i += l;else return 0; |
| 1787 |
| 1788 if (l = checkSC(i)) i += l;else return 0; |
| 1789 |
| 1790 return i - start; |
| 1791 } |
| 1792 |
| 1793 /** |
| 1794 * @return {Array} |
| 1795 */ |
| 1796 function getBlockdecl1() { |
| 1797 var sc = getSC(); |
| 1798 var x = void 0; |
| 1799 |
| 1800 switch (tokens[pos].bd_kind) { |
| 1801 case 1: |
| 1802 x = getDeclaration(); |
| 1803 break; |
| 1804 case 2: |
| 1805 x = getAtrule(); |
| 1806 break; |
| 1807 } |
| 1808 |
| 1809 return sc.concat([x]).concat(getSC()).concat([getDeclDelim()]).concat(
getSC()); |
| 1810 } |
| 1811 |
| 1812 /** |
| 1813 * @param {Number} i Token's index number |
| 1814 * @return {Number} |
| 1815 */ |
| 1816 function checkBlockdecl2(i) { |
| 1817 var start = i; |
| 1818 var l = void 0; |
| 1819 |
| 1820 if (l = checkSC(i)) i += l; |
| 1821 |
| 1822 if (l = checkDeclaration(i)) tokens[i].bd_kind = 1;else if (l = checkA
trule(i)) tokens[i].bd_kind = 2;else return 0; |
| 1823 |
| 1824 i += l; |
| 1825 |
| 1826 if (l = checkSC(i)) i += l; |
| 1827 |
| 1828 return i - start; |
| 1829 } |
| 1830 |
| 1831 /** |
| 1832 * @return {Array} |
| 1833 */ |
| 1834 function getBlockdecl2() { |
| 1835 var sc = getSC(); |
| 1836 var x = void 0; |
| 1837 |
| 1838 switch (tokens[pos].bd_kind) { |
| 1839 case 1: |
| 1840 x = getDeclaration(); |
| 1841 break; |
| 1842 case 2: |
| 1843 x = getAtrule(); |
| 1844 break; |
| 1845 } |
| 1846 |
| 1847 return sc.concat([x]).concat(getSC()); |
| 1848 } |
| 1849 |
| 1850 /** |
| 1851 * @param {Number} i Token's index number |
| 1852 * @return {Number} |
| 1853 */ |
| 1854 function checkBlockdecl3(i) { |
| 1855 var start = i; |
| 1856 var l = void 0; |
| 1857 |
| 1858 if (l = checkSC(i)) i += l; |
| 1859 |
| 1860 if (l = checkDeclDelim(i)) i += l;else return 0; |
| 1861 |
| 1862 if (l = checkSC(i)) i += l; |
| 1863 |
| 1864 return i - start; |
| 1865 } |
| 1866 |
| 1867 /** |
| 1868 * @return {Array} |
| 1869 */ |
| 1870 function getBlockdecl3() { |
| 1871 return getSC().concat([getDeclDelim()]).concat(getSC()); |
| 1872 } |
| 1873 |
| 1874 /** |
| 1875 * @param {Number} i Token's index number |
| 1876 * @return {Number} |
| 1877 */ |
| 1878 function checkBlockdecl4(i) { |
| 1879 return checkSC(i); |
| 1880 } |
| 1881 |
| 1882 /** |
| 1883 * @return {Array} |
| 1884 */ |
| 1885 function getBlockdecl4() { |
| 1886 return getSC(); |
| 1887 } |
| 1888 |
| 1889 /** |
| 1890 * Check if token is part of text inside square brackets, e.g. `[1]` |
| 1891 * @param {Number} i Token's index number |
| 1892 * @return {Number} |
| 1893 */ |
| 1894 function checkBrackets(i) { |
| 1895 if (i >= tokensLength) return 0; |
| 1896 |
| 1897 var start = i; |
| 1898 |
| 1899 if (tokens[i].type === TokenType.LeftSquareBracket) i++;else return 0; |
| 1900 |
| 1901 if (i < tokens[start].right) { |
| 1902 var l = checkTsets(i); |
| 1903 if (l) i += l;else return 0; |
| 1904 } |
| 1905 |
| 1906 i++; |
| 1907 |
| 1908 return i - start; |
| 1909 } |
| 1910 |
| 1911 /** |
| 1912 * Get node with text inside square brackets, e.g. `[1]` |
| 1913 * @return {Node} |
| 1914 */ |
| 1915 function getBrackets() { |
| 1916 var type = NodeType.BracketsType; |
| 1917 var token = tokens[pos]; |
| 1918 var line = token.ln; |
| 1919 var column = token.col; |
| 1920 |
| 1921 var tsets = []; |
| 1922 var right = token.right; |
| 1923 |
| 1924 pos++; |
| 1925 |
| 1926 if (pos < right) { |
| 1927 tsets = getTsets(); |
| 1928 } |
| 1929 |
| 1930 var end = getLastPosition(tsets, line, column, 1); |
| 1931 pos++; |
| 1932 |
| 1933 return newNode(type, tsets, line, column, end); |
| 1934 } |
| 1935 |
| 1936 /** |
| 1937 * Check if token is part of a class selector (e.g. `.abc`) |
| 1938 * @param {Number} i Token's index number |
| 1939 * @return {Number} Length of the class selector |
| 1940 */ |
| 1941 function checkClass(i) { |
| 1942 var l; |
| 1943 |
| 1944 if (i >= tokensLength) return 0; |
| 1945 |
| 1946 if (tokens[i].class_l) return tokens[i].class_l; |
| 1947 |
| 1948 if (tokens[i++].type === TokenType.FullStop && (l = checkIdent(i))) { |
| 1949 tokens[i].class_l = l + 1; |
| 1950 return l + 1; |
| 1951 } |
| 1952 |
| 1953 return 0; |
| 1954 } |
| 1955 |
| 1956 /** |
| 1957 * Get node with a class selector |
| 1958 * @return {Node} |
| 1959 */ |
| 1960 function getClass() { |
| 1961 var type = NodeType.ClassType; |
| 1962 var token = tokens[pos++]; |
| 1963 var line = token.ln; |
| 1964 var column = token.col; |
| 1965 var content = [getIdent()]; |
| 1966 |
| 1967 return newNode(type, content, line, column); |
| 1968 } |
| 1969 |
| 1970 function checkCombinator(i) { |
| 1971 if (i >= tokensLength) return 0; |
| 1972 |
| 1973 var l = void 0; |
| 1974 if (l = checkCombinator1(i)) tokens[i].combinatorType = 1;else if (l =
checkCombinator2(i)) tokens[i].combinatorType = 2;else if (l = checkCombinator3
(i)) tokens[i].combinatorType = 3; |
| 1975 |
| 1976 return l; |
| 1977 } |
| 1978 |
| 1979 function getCombinator() { |
| 1980 var type = tokens[pos].combinatorType; |
| 1981 if (type === 1) return getCombinator1(); |
| 1982 if (type === 2) return getCombinator2(); |
| 1983 if (type === 3) return getCombinator3(); |
| 1984 } |
| 1985 /** |
| 1986 * (1) `||` |
| 1987 */ |
| 1988 function checkCombinator1(i) { |
| 1989 if (tokens[i].type === TokenType.VerticalLine && tokens[i + 1].type ==
= TokenType.VerticalLine) return 2;else return 0; |
| 1990 } |
| 1991 |
| 1992 function getCombinator1() { |
| 1993 var type = NodeType.CombinatorType; |
| 1994 var token = tokens[pos]; |
| 1995 var line = token.ln; |
| 1996 var column = token.col; |
| 1997 var content = '||'; |
| 1998 |
| 1999 pos += 2; |
| 2000 return newNode(type, content, line, column); |
| 2001 } |
| 2002 |
| 2003 /** |
| 2004 * (1) `>` |
| 2005 * (2) `+` |
| 2006 * (3) `~` |
| 2007 */ |
| 2008 function checkCombinator2(i) { |
| 2009 var type = tokens[i].type; |
| 2010 if (type === TokenType.PlusSign || type === TokenType.GreaterThanSign
|| type === TokenType.Tilde) return 1;else return 0; |
| 2011 } |
| 2012 |
| 2013 function getCombinator2() { |
| 2014 var type = NodeType.CombinatorType; |
| 2015 var token = tokens[pos]; |
| 2016 var line = token.ln; |
| 2017 var column = token.col; |
| 2018 var content = tokens[pos++].value; |
| 2019 |
| 2020 return newNode(type, content, line, column); |
| 2021 } |
| 2022 |
| 2023 /** |
| 2024 * (1) `/panda/` |
| 2025 */ |
| 2026 function checkCombinator3(i) { |
| 2027 var start = i; |
| 2028 |
| 2029 if (tokens[i].type === TokenType.Solidus) i++;else return 0; |
| 2030 |
| 2031 var l = void 0; |
| 2032 if (l = checkIdent(i)) i += l;else return 0; |
| 2033 |
| 2034 if (tokens[i].type === TokenType.Solidus) i++;else return 0; |
| 2035 |
| 2036 return i - start; |
| 2037 } |
| 2038 |
| 2039 function getCombinator3() { |
| 2040 var type = NodeType.CombinatorType; |
| 2041 var token = tokens[pos]; |
| 2042 var line = token.ln; |
| 2043 var column = token.col; |
| 2044 |
| 2045 // Skip `/`. |
| 2046 pos++; |
| 2047 var ident = getIdent(); |
| 2048 |
| 2049 // Skip `/`. |
| 2050 pos++; |
| 2051 |
| 2052 var content = '/' + ident.content + '/'; |
| 2053 |
| 2054 return newNode(type, content, line, column); |
| 2055 } |
| 2056 |
| 2057 /** |
| 2058 * Check if token is a multiline comment. |
| 2059 * @param {Number} i Token's index number |
| 2060 * @return {Number} `1` if token is a multiline comment, otherwise `0` |
| 2061 */ |
| 2062 function checkCommentML(i) { |
| 2063 return i < tokensLength && tokens[i].type === TokenType.CommentML ? 1
: 0; |
| 2064 } |
| 2065 |
| 2066 /** |
| 2067 * Get node with a multiline comment |
| 2068 * @return {Node} |
| 2069 */ |
| 2070 function getCommentML() { |
| 2071 var type = NodeType.CommentMLType; |
| 2072 var token = tokens[pos]; |
| 2073 var line = token.ln; |
| 2074 var column = token.col; |
| 2075 var content = tokens[pos].value.substring(2); |
| 2076 var l = content.length; |
| 2077 |
| 2078 if (content.charAt(l - 2) === '*' && content.charAt(l - 1) === '/') co
ntent = content.substring(0, l - 2); |
| 2079 |
| 2080 var end = getLastPosition(content, line, column, 2); |
| 2081 if (end[0] === line) end[1] += 2; |
| 2082 pos++; |
| 2083 |
| 2084 return newNode(type, content, line, column, end); |
| 2085 } |
| 2086 |
| 2087 /** |
| 2088 * Check if token is part of a declaration (property-value pair) |
| 2089 * @param {Number} i Token's index number |
| 2090 * @return {Number} Length of the declaration |
| 2091 */ |
| 2092 function checkDeclaration(i) { |
| 2093 var start = i; |
| 2094 var l = void 0; |
| 2095 |
| 2096 if (i >= tokensLength) return 0; |
| 2097 |
| 2098 if (l = checkProperty(i)) i += l;else return 0; |
| 2099 |
| 2100 if (l = checkSC(i)) i += l; |
| 2101 |
| 2102 if (l = checkPropertyDelim(i)) i++;else return 0; |
| 2103 |
| 2104 if (l = checkSC(i)) i += l; |
| 2105 |
| 2106 if (l = checkValue(i)) i += l;else return 0; |
| 2107 |
| 2108 return i - start; |
| 2109 } |
| 2110 |
| 2111 /** |
| 2112 * Get node with a declaration |
| 2113 * @return {Node} |
| 2114 */ |
| 2115 function getDeclaration() { |
| 2116 var type = NodeType.DeclarationType; |
| 2117 var token = tokens[pos]; |
| 2118 var line = token.ln; |
| 2119 var column = token.col; |
| 2120 |
| 2121 var content = [getProperty()].concat(getSC()).concat([getPropertyDelim
()]).concat(getSC()).concat([getValue()]); |
| 2122 |
| 2123 return newNode(type, content, line, column); |
| 2124 } |
| 2125 |
| 2126 /** |
| 2127 * Check if token is a semicolon |
| 2128 * @param {Number} i Token's index number |
| 2129 * @return {Number} `1` if token is a semicolon, otherwise `0` |
| 2130 */ |
| 2131 function checkDeclDelim(i) { |
| 2132 return i < tokensLength && tokens[i].type === TokenType.Semicolon ? 1
: 0; |
| 2133 } |
| 2134 |
| 2135 /** |
| 2136 * Get node with a semicolon |
| 2137 * @return {Node} |
| 2138 */ |
| 2139 function getDeclDelim() { |
| 2140 var type = NodeType.DeclDelimType; |
| 2141 var token = tokens[pos]; |
| 2142 var line = token.ln; |
| 2143 var column = token.col; |
| 2144 var content = ';'; |
| 2145 |
| 2146 pos++; |
| 2147 |
| 2148 return newNode(type, content, line, column); |
| 2149 } |
| 2150 |
| 2151 /** |
| 2152 * Check if token is a comma |
| 2153 * @param {Number} i Token's index number |
| 2154 * @return {Number} `1` if token is a comma, otherwise `0` |
| 2155 */ |
| 2156 function checkDelim(i) { |
| 2157 return i < tokensLength && tokens[i].type === TokenType.Comma ? 1 : 0; |
| 2158 } |
| 2159 |
| 2160 /** |
| 2161 * Get node with a comma |
| 2162 * @return {Node} |
| 2163 */ |
| 2164 function getDelim() { |
| 2165 var type = NodeType.DelimType; |
| 2166 var token = tokens[pos]; |
| 2167 var line = token.ln; |
| 2168 var column = token.col; |
| 2169 var content = ','; |
| 2170 |
| 2171 pos++; |
| 2172 |
| 2173 return newNode(type, content, line, column); |
| 2174 } |
| 2175 |
| 2176 /** |
| 2177 * Check if token is part of a number with dimension unit (e.g. `10px`) |
| 2178 * @param {Number} i Token's index number |
| 2179 * @return {Number} |
| 2180 */ |
| 2181 function checkDimension(i) { |
| 2182 var ln = checkNumber(i); |
| 2183 var li = void 0; |
| 2184 |
| 2185 if (i >= tokensLength || !ln || i + ln >= tokensLength) return 0; |
| 2186 |
| 2187 return (li = checkUnit(i + ln)) ? ln + li : 0; |
| 2188 } |
| 2189 |
| 2190 /** |
| 2191 * Get node of a number with dimension unit |
| 2192 * @return {Node} |
| 2193 */ |
| 2194 function getDimension() { |
| 2195 var type = NodeType.DimensionType; |
| 2196 var token = tokens[pos]; |
| 2197 var line = token.ln; |
| 2198 var column = token.col; |
| 2199 var content = [getNumber(), getUnit()]; |
| 2200 |
| 2201 return newNode(type, content, line, column); |
| 2202 } |
| 2203 |
| 2204 /** |
| 2205 * Check if token is unit |
| 2206 * @param {Number} i Token's index number |
| 2207 * @return {Number} |
| 2208 */ |
| 2209 function checkUnit(i) { |
| 2210 var units = ['em', 'ex', 'ch', 'rem', 'vh', 'vw', 'vmin', 'vmax', 'px'
, 'mm', 'q', 'cm', 'in', 'pt', 'pc', 'deg', 'grad', 'rad', 'turn', 's', 'ms', 'H
z', 'kHz', 'dpi', 'dpcm', 'dppx']; |
| 2211 |
| 2212 return units.indexOf(tokens[i].value) !== -1 ? 1 : 0; |
| 2213 } |
| 2214 |
| 2215 /** |
| 2216 * Get unit node of type ident |
| 2217 * @return {Node} An ident node containing the unit value |
| 2218 */ |
| 2219 function getUnit() { |
| 2220 var type = NodeType.IdentType; |
| 2221 var token = tokens[pos]; |
| 2222 var line = token.ln; |
| 2223 var column = token.col; |
| 2224 var content = token.value; |
| 2225 |
| 2226 pos++; |
| 2227 |
| 2228 return newNode(type, content, line, column); |
| 2229 } |
| 2230 |
| 2231 /** |
| 2232 * @param {Number} i Token's index number |
| 2233 * @return {Number} |
| 2234 */ |
| 2235 function checkExpression(i) { |
| 2236 var start = i; |
| 2237 |
| 2238 if (i >= tokensLength || tokens[i++].value !== 'expression' || i >= to
kensLength || tokens[i].type !== TokenType.LeftParenthesis) { |
| 2239 return 0; |
| 2240 } |
| 2241 |
| 2242 return tokens[i].right - start + 1; |
| 2243 } |
| 2244 |
| 2245 /** |
| 2246 * @return {Node} |
| 2247 */ |
| 2248 function getExpression() { |
| 2249 var type = NodeType.ExpressionType; |
| 2250 var token = tokens[pos]; |
| 2251 var line = token.ln; |
| 2252 var column = token.col; |
| 2253 |
| 2254 pos++; |
| 2255 |
| 2256 var content = joinValues(pos + 1, tokens[pos].right - 1); |
| 2257 var end = getLastPosition(content, line, column, 1); |
| 2258 if (end[0] === line) end[1] += 11; |
| 2259 pos = tokens[pos].right + 1; |
| 2260 |
| 2261 return newNode(type, content, line, column, end); |
| 2262 } |
| 2263 |
| 2264 /** |
| 2265 * @param {Number} i Token's index number |
| 2266 * @return {Number} |
| 2267 */ |
| 2268 function checkFunction(i) { |
| 2269 var start = i; |
| 2270 var l = void 0; |
| 2271 |
| 2272 if (i >= tokensLength) return 0; |
| 2273 |
| 2274 if (l = checkIdent(i)) i += l;else return 0; |
| 2275 |
| 2276 return i < tokensLength && tokens[i].type === TokenType.LeftParenthesi
s ? tokens[i].right - start + 1 : 0; |
| 2277 } |
| 2278 |
| 2279 /** |
| 2280 * @return {Node} |
| 2281 */ |
| 2282 function getFunction() { |
| 2283 var type = NodeType.FunctionType; |
| 2284 var token = tokens[pos]; |
| 2285 var line = token.ln; |
| 2286 var column = token.col; |
| 2287 var ident = getIdent(); |
| 2288 var content = [ident]; |
| 2289 |
| 2290 content.push(getArguments()); |
| 2291 |
| 2292 return newNode(type, content, line, column); |
| 2293 } |
| 2294 |
| 2295 /** |
| 2296 * @return {Node} |
| 2297 */ |
| 2298 function getArguments() { |
| 2299 var type = NodeType.ArgumentsType; |
| 2300 var token = tokens[pos]; |
| 2301 var line = token.ln; |
| 2302 var column = token.col; |
| 2303 var content = []; |
| 2304 var body = void 0; |
| 2305 |
| 2306 pos++; |
| 2307 |
| 2308 while (pos < tokensLength && tokens[pos].type !== TokenType.RightParen
thesis) { |
| 2309 if (checkDeclaration(pos)) content.push(getDeclaration());else if (c
heckArgument(pos)) { |
| 2310 body = getArgument(); |
| 2311 if (typeof body.content === 'string') content.push(body);else cont
ent = content.concat(body); |
| 2312 } else if (checkClass(pos)) content.push(getClass());else throwError
(pos); |
| 2313 } |
| 2314 |
| 2315 var end = getLastPosition(content, line, column, 1); |
| 2316 pos++; |
| 2317 |
| 2318 return newNode(type, content, line, column, end); |
| 2319 } |
| 2320 |
| 2321 /** |
| 2322 * @param {Number} i Token's index number |
| 2323 * @return {Number} |
| 2324 */ |
| 2325 function checkArgument(i) { |
| 2326 var l; |
| 2327 |
| 2328 if (l = checkVhash(i)) tokens[i].argument_child = 1;else if (l = check
Any(i)) tokens[i].argument_child = 2;else if (l = checkSC(i)) tokens[i].argument
_child = 3;else if (l = checkOperator(i)) tokens[i].argument_child = 4; |
| 2329 |
| 2330 return l; |
| 2331 } |
| 2332 |
| 2333 /** |
| 2334 * @return {Node} |
| 2335 */ |
| 2336 function getArgument() { |
| 2337 var childType = tokens[pos].argument_child; |
| 2338 if (childType === 1) return getVhash();else if (childType === 2) retur
n getAny();else if (childType === 3) return getSC();else if (childType === 4) re
turn getOperator(); |
| 2339 } |
| 2340 |
| 2341 /** |
| 2342 * Check if token is part of an identifierÑŽ |
| 2343 * Grammar from CSS spec: |
| 2344 * h [0-9a-f] |
| 2345 * nonascii [\240-\377] |
| 2346 * unicode \\{h}{1,6}(\r\n|[ \t\r\n\f])? |
| 2347 * escape {unicode}|\\[^\r\n\f0-9a-f] |
| 2348 * nmstart [_a-z]|{nonascii}|{escape} |
| 2349 * nmchar [_a-z0-9-]|{nonascii}|{escape} |
| 2350 * ident -?{nmstart}{nmchar}* |
| 2351 * |
| 2352 * @param {number} i Token's index number |
| 2353 * @return {number} Length of the identifier |
| 2354 */ |
| 2355 function checkIdent(i) { |
| 2356 var start = i; |
| 2357 |
| 2358 if (i >= tokensLength) return 0; |
| 2359 |
| 2360 if (tokens[i].type === TokenType.HyphenMinus) i++; |
| 2361 |
| 2362 if (tokens[i].type === TokenType.LowLine || tokens[i].type === TokenTy
pe.Identifier) i++;else return 0; |
| 2363 |
| 2364 for (; i < tokensLength; i++) { |
| 2365 if (tokens[i].type !== TokenType.HyphenMinus && tokens[i].type !== T
okenType.LowLine && tokens[i].type !== TokenType.Identifier && tokens[i].type !=
= TokenType.DecimalNumber) break; |
| 2366 } |
| 2367 |
| 2368 tokens[start].ident_last = i - 1; |
| 2369 |
| 2370 return i - start; |
| 2371 } |
| 2372 |
| 2373 /** |
| 2374 * Get node with an identifier |
| 2375 * @return {Node} |
| 2376 */ |
| 2377 function getIdent() { |
| 2378 var type = NodeType.IdentType; |
| 2379 var token = tokens[pos]; |
| 2380 var line = token.ln; |
| 2381 var column = token.col; |
| 2382 var content = joinValues(pos, tokens[pos].ident_last); |
| 2383 |
| 2384 pos = tokens[pos].ident_last + 1; |
| 2385 |
| 2386 return newNode(type, content, line, column); |
| 2387 } |
| 2388 |
| 2389 /** |
| 2390 * Check if token is part of `!important` word |
| 2391 * @param {Number} i Token's index number |
| 2392 * @return {Number} |
| 2393 */ |
| 2394 function checkImportant(i) { |
| 2395 var start = i; |
| 2396 var l = void 0; |
| 2397 |
| 2398 if (i >= tokensLength || tokens[i++].type !== TokenType.ExclamationMar
k) return 0; |
| 2399 |
| 2400 if (l = checkSC(i)) i += l; |
| 2401 |
| 2402 if (tokens[i].value === 'important') { |
| 2403 tokens[start].importantEnd = i; |
| 2404 return i - start + 1; |
| 2405 } else { |
| 2406 return 0; |
| 2407 } |
| 2408 } |
| 2409 |
| 2410 /** |
| 2411 * Get node with `!important` word |
| 2412 * @return {Node} |
| 2413 */ |
| 2414 function getImportant() { |
| 2415 var type = NodeType.ImportantType; |
| 2416 var token = tokens[pos]; |
| 2417 var line = token.ln; |
| 2418 var column = token.col; |
| 2419 var content = joinValues(pos, token.importantEnd); |
| 2420 |
| 2421 pos = token.importantEnd + 1; |
| 2422 |
| 2423 return newNode(type, content, line, column); |
| 2424 } |
| 2425 |
| 2426 /** |
| 2427 * Check a single keyframe block - `5% {}` |
| 2428 * @param {Number} i |
| 2429 * @returns {Number} |
| 2430 */ |
| 2431 function checkKeyframesBlock(i) { |
| 2432 var start = i; |
| 2433 var l = void 0; |
| 2434 |
| 2435 if (i >= tokensLength) return 0; |
| 2436 |
| 2437 if (l = checkKeyframesSelectorsGroup(i)) i += l;else return 0; |
| 2438 |
| 2439 if (l = checkSC(i)) i += l; |
| 2440 |
| 2441 if (l = checkBlock(i)) i += l;else return 0; |
| 2442 |
| 2443 return i - start; |
| 2444 } |
| 2445 |
| 2446 /** |
| 2447 * Get a single keyframe block - `5% {}` |
| 2448 * @returns {Node} |
| 2449 */ |
| 2450 function getKeyframesBlock() { |
| 2451 var type = NodeType.RulesetType; |
| 2452 var token = tokens[pos]; |
| 2453 var line = token.ln; |
| 2454 var column = token.col; |
| 2455 var content = [].concat(getKeyframesSelectorsGroup(), getSC(), [getBlo
ck()]); |
| 2456 |
| 2457 return newNode(type, content, line, column); |
| 2458 } |
| 2459 |
| 2460 /** |
| 2461 * Check all keyframe blocks - `5% {} 100% {}` |
| 2462 * @param {Number} i |
| 2463 * @returns {Number} |
| 2464 */ |
| 2465 function checkKeyframesBlocks(i) { |
| 2466 var start = i; |
| 2467 var l = void 0; |
| 2468 |
| 2469 if (i < tokensLength && tokens[i].type === TokenType.LeftCurlyBracket)
i++;else return 0; |
| 2470 |
| 2471 if (l = checkSC(i)) i += l; |
| 2472 |
| 2473 if (l = checkKeyframesBlock(i)) i += l;else return 0; |
| 2474 |
| 2475 while (tokens[i].type !== TokenType.RightCurlyBracket) { |
| 2476 if (l = checkSC(i)) i += l;else if (l = checkKeyframesBlock(i)) i +=
l;else break; |
| 2477 } |
| 2478 |
| 2479 if (i < tokensLength && tokens[i].type === TokenType.RightCurlyBracket
) i++;else return 0; |
| 2480 |
| 2481 return i - start; |
| 2482 } |
| 2483 |
| 2484 /** |
| 2485 * Get all keyframe blocks - `5% {} 100% {}` |
| 2486 * @returns {Node} |
| 2487 */ |
| 2488 function getKeyframesBlocks() { |
| 2489 var type = NodeType.BlockType; |
| 2490 var token = tokens[pos]; |
| 2491 var line = token.ln; |
| 2492 var column = token.col; |
| 2493 var content = []; |
| 2494 var keyframesBlocksEnd = token.right; |
| 2495 |
| 2496 // Skip `{`. |
| 2497 pos++; |
| 2498 |
| 2499 while (pos < keyframesBlocksEnd) { |
| 2500 if (checkSC(pos)) content = content.concat(getSC());else if (checkKe
yframesBlock(pos)) content.push(getKeyframesBlock()); |
| 2501 } |
| 2502 |
| 2503 var end = getLastPosition(content, line, column, 1); |
| 2504 |
| 2505 // Skip `}`. |
| 2506 pos++; |
| 2507 |
| 2508 return newNode(type, content, line, column, end); |
| 2509 } |
| 2510 |
| 2511 /** |
| 2512 * Check if token is part of a @keyframes rule. |
| 2513 * @param {Number} i Token's index number |
| 2514 * @return {Number} Length of the @keyframes rule |
| 2515 */ |
| 2516 function checkKeyframesRule(i) { |
| 2517 var start = i; |
| 2518 var l = void 0; |
| 2519 |
| 2520 if (i >= tokensLength) return 0; |
| 2521 |
| 2522 if (l = checkAtkeyword(i)) i += l;else return 0; |
| 2523 |
| 2524 var atruleName = joinValues2(i - l, l); |
| 2525 if (atruleName.indexOf('keyframes') === -1) return 0; |
| 2526 |
| 2527 if (l = checkSC(i)) i += l;else return 0; |
| 2528 |
| 2529 if (l = checkIdent(i)) i += l;else return 0; |
| 2530 |
| 2531 if (l = checkSC(i)) i += l; |
| 2532 |
| 2533 if (l = checkKeyframesBlocks(i)) i += l;else return 0; |
| 2534 |
| 2535 return i - start; |
| 2536 } |
| 2537 |
| 2538 /** |
| 2539 * @return {Node} |
| 2540 */ |
| 2541 function getKeyframesRule() { |
| 2542 var type = NodeType.AtruleType; |
| 2543 var token = tokens[pos]; |
| 2544 var line = token.ln; |
| 2545 var column = token.col; |
| 2546 var content = [].concat([getAtkeyword()], getSC(), [getIdent()], getSC
(), [getKeyframesBlocks()]); |
| 2547 |
| 2548 return newNode(type, content, line, column); |
| 2549 } |
| 2550 |
| 2551 /** |
| 2552 * Check a single keyframe selector - `5%`, `from` etc |
| 2553 * @param {Number} i |
| 2554 * @returns {Number} |
| 2555 */ |
| 2556 function checkKeyframesSelector(i) { |
| 2557 var start = i; |
| 2558 var l = void 0; |
| 2559 |
| 2560 if (i >= tokensLength) return 0; |
| 2561 |
| 2562 if (l = checkIdent(i)) { |
| 2563 // Valid selectors are only `from` and `to`. |
| 2564 var selector = joinValues2(i, l); |
| 2565 if (selector !== 'from' && selector !== 'to') return 0; |
| 2566 |
| 2567 i += l; |
| 2568 tokens[start].keyframesSelectorType = 1; |
| 2569 } else if (l = checkPercentage(i)) { |
| 2570 i += l; |
| 2571 tokens[start].keyframesSelectorType = 2; |
| 2572 } else { |
| 2573 return 0; |
| 2574 } |
| 2575 |
| 2576 return i - start; |
| 2577 } |
| 2578 |
| 2579 /** |
| 2580 * Get a single keyframe selector |
| 2581 * @returns {Node} |
| 2582 */ |
| 2583 function getKeyframesSelector() { |
| 2584 var keyframesSelectorType = NodeType.KeyframesSelectorType; |
| 2585 var selectorType = NodeType.SelectorType; |
| 2586 |
| 2587 var token = tokens[pos]; |
| 2588 var line = token.ln; |
| 2589 var column = token.col; |
| 2590 var content = []; |
| 2591 |
| 2592 if (token.keyframesSelectorType === 1) { |
| 2593 content.push(getIdent()); |
| 2594 } else { |
| 2595 content.push(getPercentage()); |
| 2596 } |
| 2597 |
| 2598 var keyframesSelector = newNode(keyframesSelectorType, content, line,
column); |
| 2599 return newNode(selectorType, [keyframesSelector], line, column); |
| 2600 } |
| 2601 |
| 2602 /** |
| 2603 * Check the keyframe's selector groups |
| 2604 * @param {Number} i |
| 2605 * @returns {Number} |
| 2606 */ |
| 2607 function checkKeyframesSelectorsGroup(i) { |
| 2608 var start = i; |
| 2609 var l = void 0; |
| 2610 |
| 2611 if (l = checkKeyframesSelector(i)) i += l;else return 0; |
| 2612 |
| 2613 while (i < tokensLength) { |
| 2614 var sb = checkSC(i); |
| 2615 var c = checkDelim(i + sb); |
| 2616 if (!c) break; |
| 2617 var sa = checkSC(i + sb + c); |
| 2618 if (l = checkKeyframesSelector(i + sb + c + sa)) i += sb + c + sa +
l;else break; |
| 2619 } |
| 2620 |
| 2621 tokens[start].selectorsGroupEnd = i; |
| 2622 |
| 2623 return i - start; |
| 2624 } |
| 2625 |
| 2626 /** |
| 2627 * Get the keyframe's selector groups |
| 2628 * @returns {Array} An array of keyframe selectors |
| 2629 */ |
| 2630 function getKeyframesSelectorsGroup() { |
| 2631 var selectorsGroup = []; |
| 2632 var selectorsGroupEnd = tokens[pos].selectorsGroupEnd; |
| 2633 |
| 2634 selectorsGroup.push(getKeyframesSelector()); |
| 2635 |
| 2636 while (pos < selectorsGroupEnd) { |
| 2637 selectorsGroup = selectorsGroup.concat(getSC()); |
| 2638 selectorsGroup.push(getDelim()); |
| 2639 selectorsGroup = selectorsGroup.concat(getSC()); |
| 2640 selectorsGroup.push(getKeyframesSelector()); |
| 2641 } |
| 2642 |
| 2643 return selectorsGroup; |
| 2644 } |
| 2645 |
| 2646 /** |
| 2647 * Check if token is a namespace sign (`|`) |
| 2648 * @param {Number} i Token's index number |
| 2649 * @return {Number} `1` if token is `|`, `0` if not |
| 2650 */ |
| 2651 function checkNamespace(i) { |
| 2652 return i < tokensLength && tokens[i].type === TokenType.VerticalLine ?
1 : 0; |
| 2653 } |
| 2654 |
| 2655 /** |
| 2656 * Get node with a namespace sign |
| 2657 * @return {Node} |
| 2658 */ |
| 2659 function getNamespace() { |
| 2660 var type = NodeType.NamespaceType; |
| 2661 var token = tokens[pos++]; |
| 2662 var line = token.ln; |
| 2663 var column = token.col; |
| 2664 var content = '|'; |
| 2665 |
| 2666 return newNode(type, content, line, column); |
| 2667 } |
| 2668 |
| 2669 /** |
| 2670 * @param {Number} i Token's index number |
| 2671 * @return {Number} |
| 2672 */ |
| 2673 function checkNmName2(i) { |
| 2674 if (tokens[i].type === TokenType.Identifier) return 1;else if (tokens[
i].type !== TokenType.DecimalNumber) return 0; |
| 2675 |
| 2676 i++; |
| 2677 |
| 2678 return i < tokensLength && tokens[i].type === TokenType.Identifier ? 2
: 1; |
| 2679 } |
| 2680 |
| 2681 /** |
| 2682 * @return {String} |
| 2683 */ |
| 2684 function getNmName2() { |
| 2685 var s = tokens[pos].value; |
| 2686 |
| 2687 if (tokens[pos++].type === TokenType.DecimalNumber && pos < tokensLeng
th && tokens[pos].type === TokenType.Identifier) s += tokens[pos++].value; |
| 2688 |
| 2689 return s; |
| 2690 } |
| 2691 |
| 2692 /** |
| 2693 * Check if token is part of a number |
| 2694 * @param {Number} i Token's index number |
| 2695 * @return {Number} Length of number |
| 2696 */ |
| 2697 function checkNumber(i) { |
| 2698 if (i >= tokensLength) return 0; |
| 2699 |
| 2700 if (tokens[i].number_l) return tokens[i].number_l; |
| 2701 |
| 2702 // `10`: |
| 2703 if (i < tokensLength && tokens[i].type === TokenType.DecimalNumber &&
(!tokens[i + 1] || tokens[i + 1] && tokens[i + 1].type !== TokenType.FullStop))
{ |
| 2704 tokens[i].number_l = 1; |
| 2705 return 1; |
| 2706 } |
| 2707 |
| 2708 // `10.`: |
| 2709 if (i < tokensLength && tokens[i].type === TokenType.DecimalNumber &&
tokens[i + 1] && tokens[i + 1].type === TokenType.FullStop && (!tokens[i + 2] ||
tokens[i + 2].type !== TokenType.DecimalNumber)) { |
| 2710 tokens[i].number_l = 2; |
| 2711 return 2; |
| 2712 } |
| 2713 |
| 2714 // `.10`: |
| 2715 if (i < tokensLength && tokens[i].type === TokenType.FullStop && token
s[i + 1].type === TokenType.DecimalNumber) { |
| 2716 tokens[i].number_l = 2; |
| 2717 return 2; |
| 2718 } |
| 2719 |
| 2720 // `10.10`: |
| 2721 if (i < tokensLength && tokens[i].type === TokenType.DecimalNumber &&
tokens[i + 1] && tokens[i + 1].type === TokenType.FullStop && tokens[i + 2] && t
okens[i + 2].type === TokenType.DecimalNumber) { |
| 2722 tokens[i].number_l = 3; |
| 2723 return 3; |
| 2724 } |
| 2725 |
| 2726 return 0; |
| 2727 } |
| 2728 |
| 2729 /** |
| 2730 * Get node with number |
| 2731 * @return {Node} |
| 2732 */ |
| 2733 function getNumber() { |
| 2734 var type = NodeType.NumberType; |
| 2735 var token = tokens[pos]; |
| 2736 var line = token.ln; |
| 2737 var column = token.col; |
| 2738 var content = ''; |
| 2739 var l = tokens[pos].number_l; |
| 2740 |
| 2741 for (var j = 0; j < l; j++) { |
| 2742 content += tokens[pos + j].value; |
| 2743 } |
| 2744 |
| 2745 pos += l; |
| 2746 |
| 2747 return newNode(type, content, line, column); |
| 2748 } |
| 2749 |
| 2750 /** |
| 2751 * Check if token is an operator (`/`, `,`, `:` or `=`). |
| 2752 * @param {Number} i Token's index number |
| 2753 * @return {Number} `1` if token is an operator, otherwise `0` |
| 2754 */ |
| 2755 function checkOperator(i) { |
| 2756 if (i >= tokensLength) return 0; |
| 2757 |
| 2758 switch (tokens[i].type) { |
| 2759 case TokenType.Solidus: |
| 2760 case TokenType.Comma: |
| 2761 case TokenType.Colon: |
| 2762 case TokenType.EqualsSign: |
| 2763 return 1; |
| 2764 } |
| 2765 |
| 2766 return 0; |
| 2767 } |
| 2768 |
| 2769 /** |
| 2770 * Get node with an operator |
| 2771 * @return {Node} |
| 2772 */ |
| 2773 function getOperator() { |
| 2774 var type = NodeType.OperatorType; |
| 2775 var token = tokens[pos]; |
| 2776 var line = token.ln; |
| 2777 var column = token.col; |
| 2778 var content = token.value; |
| 2779 |
| 2780 pos++; |
| 2781 |
| 2782 return newNode(type, content, line, column); |
| 2783 } |
| 2784 |
| 2785 /** |
| 2786 * Check if token is part of text inside parentheses, e.g. `(1)` |
| 2787 * @param {Number} i Token's index number |
| 2788 * @return {Number} |
| 2789 */ |
| 2790 function checkParentheses(i) { |
| 2791 if (i >= tokensLength) return 0; |
| 2792 |
| 2793 var start = i; |
| 2794 var right = tokens[i].right; |
| 2795 |
| 2796 if (tokens[i].type === TokenType.LeftParenthesis) i++;else return 0; |
| 2797 |
| 2798 if (i < right) { |
| 2799 var l = checkTsets(i); |
| 2800 if (l) i += l;else return 0; |
| 2801 } |
| 2802 |
| 2803 i++; |
| 2804 |
| 2805 return i - start; |
| 2806 } |
| 2807 |
| 2808 /** |
| 2809 * Get node with text inside parentheses, e.g. `(1)` |
| 2810 * @return {Node} |
| 2811 */ |
| 2812 function getParentheses() { |
| 2813 var type = NodeType.ParenthesesType; |
| 2814 var token = tokens[pos]; |
| 2815 var line = token.ln; |
| 2816 var column = token.col; |
| 2817 var tsets = []; |
| 2818 var right = token.right; |
| 2819 |
| 2820 pos++; |
| 2821 |
| 2822 if (pos < right) { |
| 2823 tsets = getTsets(); |
| 2824 } |
| 2825 |
| 2826 var end = getLastPosition(tsets, line, column, 1); |
| 2827 pos++; |
| 2828 |
| 2829 return newNode(type, tsets, line, column, end); |
| 2830 } |
| 2831 |
| 2832 /** |
| 2833 * Check if token is part of a number with percent sign (e.g. `10%`) |
| 2834 * @param {Number} i Token's index number |
| 2835 * @return {Number} |
| 2836 */ |
| 2837 function checkPercentage(i) { |
| 2838 var x; |
| 2839 |
| 2840 if (i >= tokensLength) return 0; |
| 2841 |
| 2842 x = checkNumber(i); |
| 2843 |
| 2844 if (!x || i + x >= tokensLength) return 0; |
| 2845 |
| 2846 return tokens[i + x].type === TokenType.PercentSign ? x + 1 : 0; |
| 2847 } |
| 2848 |
| 2849 /** |
| 2850 * Get node of number with percent sign |
| 2851 * @return {Node} |
| 2852 */ |
| 2853 function getPercentage() { |
| 2854 var type = NodeType.PercentageType; |
| 2855 var token = tokens[pos]; |
| 2856 var line = token.ln; |
| 2857 var column = token.col; |
| 2858 var content = [getNumber()]; |
| 2859 |
| 2860 var end = getLastPosition(content, line, column, 1); |
| 2861 pos++; |
| 2862 |
| 2863 return newNode(type, content, line, column, end); |
| 2864 } |
| 2865 |
| 2866 /** |
| 2867 * @param {Number} i Token's index number |
| 2868 * @return {Number} |
| 2869 */ |
| 2870 function checkProgid(i) { |
| 2871 var start = i; |
| 2872 var l = void 0; |
| 2873 |
| 2874 if (i >= tokensLength) return 0; |
| 2875 |
| 2876 if (joinValues2(i, 6) === 'progid:DXImageTransform.Microsoft.') i += 6
;else return 0; |
| 2877 |
| 2878 if (l = checkIdent(i)) i += l;else return 0; |
| 2879 |
| 2880 if (l = checkSC(i)) i += l; |
| 2881 |
| 2882 if (tokens[i].type === TokenType.LeftParenthesis) { |
| 2883 tokens[start].progid_end = tokens[i].right; |
| 2884 i = tokens[i].right + 1; |
| 2885 } else return 0; |
| 2886 |
| 2887 return i - start; |
| 2888 } |
| 2889 |
| 2890 /** |
| 2891 * @return {Node} |
| 2892 */ |
| 2893 function getProgid() { |
| 2894 var type = NodeType.ProgidType; |
| 2895 var token = tokens[pos]; |
| 2896 var line = token.ln; |
| 2897 var column = token.col; |
| 2898 var progid_end = token.progid_end; |
| 2899 var content = joinValues(pos, progid_end); |
| 2900 |
| 2901 pos = progid_end + 1; |
| 2902 |
| 2903 return newNode(type, content, line, column); |
| 2904 } |
| 2905 |
| 2906 /** |
| 2907 * Check if token is part of a property |
| 2908 * @param {Number} i Token's index number |
| 2909 * @return {Number} Length of the property |
| 2910 */ |
| 2911 function checkProperty(i) { |
| 2912 var start = i; |
| 2913 var l = void 0; |
| 2914 |
| 2915 if (i >= tokensLength) return 0; |
| 2916 |
| 2917 if (l = checkIdent(i)) i += l;else return 0; |
| 2918 |
| 2919 return i - start; |
| 2920 } |
| 2921 |
| 2922 /** |
| 2923 * Get node with a property |
| 2924 * @return {Node} |
| 2925 */ |
| 2926 function getProperty() { |
| 2927 var type = NodeType.PropertyType; |
| 2928 var token = tokens[pos]; |
| 2929 var line = token.ln; |
| 2930 var column = token.col; |
| 2931 var content = [getIdent()]; |
| 2932 |
| 2933 return newNode(type, content, line, column); |
| 2934 } |
| 2935 |
| 2936 /** |
| 2937 * Check if token is a colon |
| 2938 * @param {Number} i Token's index number |
| 2939 * @return {Number} `1` if token is a colon, otherwise `0` |
| 2940 */ |
| 2941 function checkPropertyDelim(i) { |
| 2942 return i < tokensLength && tokens[i].type === TokenType.Colon ? 1 : 0; |
| 2943 } |
| 2944 |
| 2945 /** |
| 2946 * Get node with a colon |
| 2947 * @return {Node} |
| 2948 */ |
| 2949 function getPropertyDelim() { |
| 2950 var type = NodeType.PropertyDelimType; |
| 2951 var token = tokens[pos++]; |
| 2952 var line = token.ln; |
| 2953 var column = token.col; |
| 2954 var content = ':'; |
| 2955 |
| 2956 return newNode(type, content, line, column); |
| 2957 } |
| 2958 |
| 2959 /** |
| 2960 * @param {Number} i Token's index number |
| 2961 * @return {Number} |
| 2962 */ |
| 2963 function checkPseudo(i) { |
| 2964 return checkPseudoe(i) || checkPseudoc(i); |
| 2965 } |
| 2966 |
| 2967 /** |
| 2968 * @return {Node} |
| 2969 */ |
| 2970 function getPseudo() { |
| 2971 if (checkPseudoe(pos)) return getPseudoe(); |
| 2972 if (checkPseudoc(pos)) return getPseudoc(); |
| 2973 } |
| 2974 |
| 2975 /** |
| 2976 * @param {Number} i Token's index number |
| 2977 * @return {Number} |
| 2978 */ |
| 2979 function checkPseudoe(i) { |
| 2980 var l; |
| 2981 |
| 2982 if (i >= tokensLength || tokens[i++].type !== TokenType.Colon || i >=
tokensLength || tokens[i++].type !== TokenType.Colon) return 0; |
| 2983 |
| 2984 return (l = checkIdent(i)) ? l + 2 : 0; |
| 2985 } |
| 2986 |
| 2987 /** |
| 2988 * @return {Node} |
| 2989 */ |
| 2990 function getPseudoe() { |
| 2991 var type = NodeType.PseudoeType; |
| 2992 var token = tokens[pos]; |
| 2993 var line = token.ln; |
| 2994 var column = token.col; |
| 2995 var content = []; |
| 2996 |
| 2997 pos += 2; |
| 2998 |
| 2999 content.push(getIdent()); |
| 3000 |
| 3001 return newNode(type, content, line, column); |
| 3002 } |
| 3003 |
| 3004 /** |
| 3005 * @param {Number} i Token's index number |
| 3006 * @return {Number} |
| 3007 */ |
| 3008 function checkPseudoc(i) { |
| 3009 var l; |
| 3010 |
| 3011 if (i >= tokensLength || tokens[i].type !== TokenType.Colon) return 0; |
| 3012 |
| 3013 if (l = checkPseudoClass1(i)) tokens[i].pseudoClassType = 1;else if (l
= checkPseudoClass2(i)) tokens[i].pseudoClassType = 2;else if (l = checkPseudoC
lass3(i)) tokens[i].pseudoClassType = 3;else if (l = checkPseudoClass4(i)) token
s[i].pseudoClassType = 4;else if (l = checkPseudoClass5(i)) tokens[i].pseudoClas
sType = 5;else if (l = checkPseudoClass6(i)) tokens[i].pseudoClassType = 6;else
return 0; |
| 3014 |
| 3015 return l; |
| 3016 } |
| 3017 |
| 3018 /** |
| 3019 * @return {Node} |
| 3020 */ |
| 3021 function getPseudoc() { |
| 3022 var childType = tokens[pos].pseudoClassType; |
| 3023 if (childType === 1) return getPseudoClass1(); |
| 3024 if (childType === 2) return getPseudoClass2(); |
| 3025 if (childType === 3) return getPseudoClass3(); |
| 3026 if (childType === 4) return getPseudoClass4(); |
| 3027 if (childType === 5) return getPseudoClass5(); |
| 3028 if (childType === 6) return getPseudoClass6(); |
| 3029 } |
| 3030 |
| 3031 /** |
| 3032 * (1) `:panda(selector)` |
| 3033 * (2) `:panda(selector, selector)` |
| 3034 */ |
| 3035 function checkPseudoClass1(i) { |
| 3036 var start = i; |
| 3037 |
| 3038 // Skip `:`. |
| 3039 i++; |
| 3040 |
| 3041 var l = void 0; |
| 3042 if (l = checkIdent(i)) i += l;else return 0; |
| 3043 |
| 3044 if (i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis)
return 0; |
| 3045 |
| 3046 var right = tokens[i].right; |
| 3047 |
| 3048 // Skip `(`. |
| 3049 i++; |
| 3050 |
| 3051 if (l = checkSelectorsGroup(i)) i += l;else return 0; |
| 3052 |
| 3053 if (i !== right) return 0; |
| 3054 |
| 3055 return i - start + 1; |
| 3056 } |
| 3057 |
| 3058 /** |
| 3059 * (-) `:not(panda)` |
| 3060 */ |
| 3061 function getPseudoClass1() { |
| 3062 var type = NodeType.PseudocType; |
| 3063 var token = tokens[pos]; |
| 3064 var line = token.ln; |
| 3065 var column = token.col; |
| 3066 var content = []; |
| 3067 |
| 3068 // Skip `:`. |
| 3069 pos++; |
| 3070 |
| 3071 content.push(getIdent()); |
| 3072 |
| 3073 { |
| 3074 var _type = NodeType.ArgumentsType; |
| 3075 var _token = tokens[pos]; |
| 3076 var _line = _token.ln; |
| 3077 var _column = _token.col; |
| 3078 |
| 3079 // Skip `(`. |
| 3080 pos++; |
| 3081 |
| 3082 var selectors = getSelectorsGroup(); |
| 3083 var end = getLastPosition(selectors, _line, _column, 1); |
| 3084 var args = newNode(_type, selectors, _line, _column, end); |
| 3085 content.push(args); |
| 3086 |
| 3087 // Skip `)`. |
| 3088 pos++; |
| 3089 } |
| 3090 |
| 3091 return newNode(type, content, line, column); |
| 3092 } |
| 3093 |
| 3094 /** |
| 3095 * (1) `:nth-child(odd)` |
| 3096 * (2) `:nth-child(even)` |
| 3097 * (3) `:lang(de-DE)` |
| 3098 */ |
| 3099 function checkPseudoClass2(i) { |
| 3100 var start = i; |
| 3101 var l = 0; |
| 3102 |
| 3103 // Skip `:`. |
| 3104 i++; |
| 3105 |
| 3106 if (i >= tokensLength) return 0; |
| 3107 |
| 3108 if (l = checkIdent(i)) i += l;else return 0; |
| 3109 |
| 3110 if (i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis)
return 0; |
| 3111 |
| 3112 var right = tokens[i].right; |
| 3113 |
| 3114 // Skip `(`. |
| 3115 i++; |
| 3116 |
| 3117 if (l = checkSC(i)) i += l; |
| 3118 |
| 3119 if (l = checkIdent(i)) i += l;else return 0; |
| 3120 |
| 3121 if (l = checkSC(i)) i += l; |
| 3122 |
| 3123 if (i !== right) return 0; |
| 3124 |
| 3125 return i - start + 1; |
| 3126 } |
| 3127 |
| 3128 function getPseudoClass2() { |
| 3129 var type = NodeType.PseudocType; |
| 3130 var token = tokens[pos]; |
| 3131 var line = token.ln; |
| 3132 var column = token.col; |
| 3133 var content = []; |
| 3134 |
| 3135 // Skip `:`. |
| 3136 pos++; |
| 3137 |
| 3138 var ident = getIdent(); |
| 3139 content.push(ident); |
| 3140 |
| 3141 // Skip `(`. |
| 3142 pos++; |
| 3143 |
| 3144 var l = tokens[pos].ln; |
| 3145 var c = tokens[pos].col; |
| 3146 var value = []; |
| 3147 |
| 3148 value = value.concat(getSC()); |
| 3149 value.push(getIdent()); |
| 3150 value = value.concat(getSC()); |
| 3151 |
| 3152 var end = getLastPosition(value, l, c, 1); |
| 3153 var args = newNode(NodeType.ArgumentsType, value, l, c, end); |
| 3154 content.push(args); |
| 3155 |
| 3156 // Skip `)`. |
| 3157 pos++; |
| 3158 |
| 3159 return newNode(type, content, line, column); |
| 3160 } |
| 3161 |
| 3162 /** |
| 3163 * (-) `:nth-child(-3n + 2)` |
| 3164 */ |
| 3165 function checkPseudoClass3(i) { |
| 3166 var start = i; |
| 3167 var l = 0; |
| 3168 |
| 3169 // Skip `:`. |
| 3170 i++; |
| 3171 |
| 3172 if (i >= tokensLength) return 0; |
| 3173 |
| 3174 if (l = checkIdent(i)) i += l;else return 0; |
| 3175 |
| 3176 if (i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis)
return 0; |
| 3177 |
| 3178 var right = tokens[i].right; |
| 3179 |
| 3180 // Skip `(`. |
| 3181 i++; |
| 3182 |
| 3183 if (l = checkSC(i)) i += l; |
| 3184 |
| 3185 if (l = checkUnary(i)) i += l; |
| 3186 if (i >= tokensLength) return 0; |
| 3187 if (tokens[i].type === TokenType.DecimalNumber) i++; |
| 3188 |
| 3189 if (i >= tokensLength) return 0; |
| 3190 if (tokens[i].value === 'n') i++;else return 0; |
| 3191 |
| 3192 if (l = checkSC(i)) i += l; |
| 3193 |
| 3194 if (i >= tokensLength) return 0; |
| 3195 if (tokens[i].value === '+' || tokens[i].value === '-') i++;else retur
n 0; |
| 3196 |
| 3197 if (l = checkSC(i)) i += l; |
| 3198 |
| 3199 if (tokens[i].type === TokenType.DecimalNumber) i++;else return 0; |
| 3200 |
| 3201 if (l = checkSC(i)) i += l; |
| 3202 |
| 3203 if (i !== right) return 0; |
| 3204 |
| 3205 return i - start + 1; |
| 3206 } |
| 3207 |
| 3208 function getPseudoClass3() { |
| 3209 var type = NodeType.PseudocType; |
| 3210 var token = tokens[pos]; |
| 3211 var line = token.ln; |
| 3212 var column = token.col; |
| 3213 var content = []; |
| 3214 |
| 3215 // Skip `:`. |
| 3216 pos++; |
| 3217 |
| 3218 var ident = getIdent(); |
| 3219 content.push(ident); |
| 3220 |
| 3221 var l = tokens[pos].ln; |
| 3222 var c = tokens[pos].col; |
| 3223 var value = []; |
| 3224 |
| 3225 // Skip `(`. |
| 3226 pos++; |
| 3227 |
| 3228 if (checkUnary(pos)) value.push(getUnary()); |
| 3229 if (checkNumber(pos)) value.push(getNumber()); |
| 3230 |
| 3231 { |
| 3232 var _l = tokens[pos].ln; |
| 3233 var _c = tokens[pos].col; |
| 3234 var _content = tokens[pos].value; |
| 3235 var _ident = newNode(NodeType.IdentType, _content, _l, _c); |
| 3236 value.push(_ident); |
| 3237 pos++; |
| 3238 } |
| 3239 |
| 3240 value = value.concat(getSC()); |
| 3241 if (checkUnary(pos)) value.push(getUnary()); |
| 3242 value = value.concat(getSC()); |
| 3243 if (checkNumber(pos)) value.push(getNumber()); |
| 3244 value = value.concat(getSC()); |
| 3245 |
| 3246 var end = getLastPosition(value, l, c, 1); |
| 3247 var args = newNode(NodeType.ArgumentsType, value, l, c, end); |
| 3248 content.push(args); |
| 3249 |
| 3250 // Skip `)`. |
| 3251 pos++; |
| 3252 |
| 3253 return newNode(type, content, line, column); |
| 3254 } |
| 3255 |
| 3256 /** |
| 3257 * (-) `:nth-child(-3n)` |
| 3258 */ |
| 3259 function checkPseudoClass4(i) { |
| 3260 var start = i; |
| 3261 var l = 0; |
| 3262 |
| 3263 // Skip `:`. |
| 3264 i++; |
| 3265 |
| 3266 if (i >= tokensLength) return 0; |
| 3267 |
| 3268 if (l = checkIdent(i)) i += l;else return 0; |
| 3269 |
| 3270 if (i >= tokensLength) return 0; |
| 3271 if (tokens[i].type !== TokenType.LeftParenthesis) return 0; |
| 3272 |
| 3273 var right = tokens[i].right; |
| 3274 |
| 3275 // Skip `(`. |
| 3276 i++; |
| 3277 |
| 3278 if (l = checkSC(i)) i += l; |
| 3279 |
| 3280 if (l = checkUnary(i)) i += l; |
| 3281 if (tokens[i].type === TokenType.DecimalNumber) i++; |
| 3282 |
| 3283 if (tokens[i].value === 'n') i++;else return 0; |
| 3284 |
| 3285 if (l = checkSC(i)) i += l; |
| 3286 |
| 3287 if (i !== right) return 0; |
| 3288 |
| 3289 return i - start + 1; |
| 3290 } |
| 3291 |
| 3292 function getPseudoClass4() { |
| 3293 var type = NodeType.PseudocType; |
| 3294 var token = tokens[pos]; |
| 3295 var line = token.ln; |
| 3296 var column = token.col; |
| 3297 var content = []; |
| 3298 |
| 3299 // Skip `:`. |
| 3300 pos++; |
| 3301 |
| 3302 var ident = getIdent(); |
| 3303 content.push(ident); |
| 3304 |
| 3305 // Skip `(`. |
| 3306 pos++; |
| 3307 |
| 3308 var l = tokens[pos].ln; |
| 3309 var c = tokens[pos].col; |
| 3310 var value = []; |
| 3311 |
| 3312 if (checkUnary(pos)) value.push(getUnary()); |
| 3313 if (checkNumber(pos)) value.push(getNumber()); |
| 3314 if (checkIdent(pos)) value.push(getIdent()); |
| 3315 value = value.concat(getSC()); |
| 3316 |
| 3317 var end = getLastPosition(value, l, c, 1); |
| 3318 var args = newNode(NodeType.ArgumentsType, value, l, c, end); |
| 3319 content.push(args); |
| 3320 |
| 3321 // Skip `)`. |
| 3322 pos++; |
| 3323 |
| 3324 return newNode(type, content, line, column); |
| 3325 } |
| 3326 |
| 3327 /** |
| 3328 * (-) `:nth-child(+8)` |
| 3329 */ |
| 3330 function checkPseudoClass5(i) { |
| 3331 var start = i; |
| 3332 var l = 0; |
| 3333 |
| 3334 // Skip `:`. |
| 3335 i++; |
| 3336 |
| 3337 if (i >= tokensLength) return 0; |
| 3338 |
| 3339 if (l = checkIdent(i)) i += l;else return 0; |
| 3340 |
| 3341 if (i >= tokensLength) return 0; |
| 3342 if (tokens[i].type !== TokenType.LeftParenthesis) return 0; |
| 3343 |
| 3344 var right = tokens[i].right; |
| 3345 |
| 3346 // Skip `(`. |
| 3347 i++; |
| 3348 |
| 3349 if (l = checkSC(i)) i += l; |
| 3350 |
| 3351 if (l = checkUnary(i)) i += l; |
| 3352 if (tokens[i].type === TokenType.DecimalNumber) i++;else return 0; |
| 3353 |
| 3354 if (l = checkSC(i)) i += l; |
| 3355 |
| 3356 if (i !== right) return 0; |
| 3357 |
| 3358 return i - start + 1; |
| 3359 } |
| 3360 |
| 3361 function getPseudoClass5() { |
| 3362 var type = NodeType.PseudocType; |
| 3363 var token = tokens[pos]; |
| 3364 var line = token.ln; |
| 3365 var column = token.col; |
| 3366 var content = []; |
| 3367 |
| 3368 // Skip `:`. |
| 3369 pos++; |
| 3370 |
| 3371 var ident = getIdent(); |
| 3372 content.push(ident); |
| 3373 |
| 3374 // Skip `(`. |
| 3375 pos++; |
| 3376 |
| 3377 var l = tokens[pos].ln; |
| 3378 var c = tokens[pos].col; |
| 3379 var value = []; |
| 3380 |
| 3381 if (checkUnary(pos)) value.push(getUnary()); |
| 3382 if (checkNumber(pos)) value.push(getNumber()); |
| 3383 value = value.concat(getSC()); |
| 3384 |
| 3385 var end = getLastPosition(value, l, c, 1); |
| 3386 var args = newNode(NodeType.ArgumentsType, value, l, c, end); |
| 3387 content.push(args); |
| 3388 |
| 3389 // Skip `)`. |
| 3390 pos++; |
| 3391 |
| 3392 return newNode(type, content, line, column); |
| 3393 } |
| 3394 |
| 3395 /** |
| 3396 * (-) `:checked` |
| 3397 */ |
| 3398 function checkPseudoClass6(i) { |
| 3399 var start = i; |
| 3400 var l = 0; |
| 3401 |
| 3402 // Skip `:`. |
| 3403 i++; |
| 3404 |
| 3405 if (i >= tokensLength) return 0; |
| 3406 |
| 3407 if (l = checkIdent(i)) i += l;else return 0; |
| 3408 |
| 3409 return i - start; |
| 3410 } |
| 3411 |
| 3412 function getPseudoClass6() { |
| 3413 var type = NodeType.PseudocType; |
| 3414 var token = tokens[pos]; |
| 3415 var line = token.ln; |
| 3416 var column = token.col; |
| 3417 var content = []; |
| 3418 |
| 3419 // Skip `:`. |
| 3420 pos++; |
| 3421 |
| 3422 var ident = getIdent(); |
| 3423 content.push(ident); |
| 3424 |
| 3425 return newNode(type, content, line, column); |
| 3426 } |
| 3427 |
| 3428 /** |
| 3429 * @param {Number} i Token's index number |
| 3430 * @return {Number} |
| 3431 */ |
| 3432 function checkRuleset(i) { |
| 3433 var start = i; |
| 3434 var l = void 0; |
| 3435 |
| 3436 if (i >= tokensLength) return 0; |
| 3437 |
| 3438 if (l = checkSelectorsGroup(i)) i += l;else return 0; |
| 3439 |
| 3440 if (l = checkSC(i)) i += l; |
| 3441 |
| 3442 if (l = checkBlock(i)) i += l;else return 0; |
| 3443 |
| 3444 return i - start; |
| 3445 } |
| 3446 |
| 3447 /** |
| 3448 * @return {Node} |
| 3449 */ |
| 3450 function getRuleset() { |
| 3451 var type = NodeType.RulesetType; |
| 3452 var token = tokens[pos]; |
| 3453 var line = token.ln; |
| 3454 var column = token.col; |
| 3455 var content = []; |
| 3456 |
| 3457 content = content.concat(getSelectorsGroup()); |
| 3458 content = content.concat(getSC()); |
| 3459 content.push(getBlock()); |
| 3460 |
| 3461 return newNode(type, content, line, column); |
| 3462 } |
| 3463 |
| 3464 /** |
| 3465 * Check if token is marked as a space (if it's a space or a tab |
| 3466 * or a line break). |
| 3467 * @param {Number} i |
| 3468 * @return {Number} Number of spaces in a row starting with the given to
ken. |
| 3469 */ |
| 3470 function checkS(i) { |
| 3471 return i < tokensLength && tokens[i].ws ? tokens[i].ws_last - i + 1 :
0; |
| 3472 } |
| 3473 |
| 3474 /** |
| 3475 * Get node with spaces |
| 3476 * @return {Node} |
| 3477 */ |
| 3478 function getS() { |
| 3479 var type = NodeType.SType; |
| 3480 var token = tokens[pos]; |
| 3481 var line = token.ln; |
| 3482 var column = token.col; |
| 3483 var content = joinValues(pos, tokens[pos].ws_last); |
| 3484 |
| 3485 pos = tokens[pos].ws_last + 1; |
| 3486 |
| 3487 return newNode(type, content, line, column); |
| 3488 } |
| 3489 |
| 3490 /** |
| 3491 * Check if token is a space or a comment. |
| 3492 * @param {Number} i Token's index number |
| 3493 * @return {Number} Number of similar (space or comment) tokens |
| 3494 * in a row starting with the given token. |
| 3495 */ |
| 3496 function checkSC(i) { |
| 3497 var l = void 0; |
| 3498 var lsc = 0; |
| 3499 |
| 3500 while (i < tokensLength) { |
| 3501 if (l = checkS(i)) tokens[i].sc_child = 1;else if (l = checkCommentM
L(i)) tokens[i].sc_child = 2;else break; |
| 3502 i += l; |
| 3503 lsc += l; |
| 3504 } |
| 3505 |
| 3506 return lsc || 0; |
| 3507 } |
| 3508 |
| 3509 /** |
| 3510 * Get node with spaces and comments |
| 3511 * @return {Array} |
| 3512 */ |
| 3513 function getSC() { |
| 3514 var sc = []; |
| 3515 |
| 3516 if (pos >= tokensLength) return sc; |
| 3517 |
| 3518 while (pos < tokensLength) { |
| 3519 var childType = tokens[pos].sc_child; |
| 3520 if (childType === 1) sc.push(getS());else if (childType === 2) sc.pu
sh(getCommentML());else break; |
| 3521 } |
| 3522 |
| 3523 return sc; |
| 3524 } |
| 3525 |
| 3526 /** |
| 3527 * Check if token is part of a hexadecimal number (e.g. `#fff`) inside |
| 3528 * a simple selector |
| 3529 * @param {Number} i Token's index number |
| 3530 * @return {Number} |
| 3531 */ |
| 3532 function checkShash(i) { |
| 3533 var l; |
| 3534 |
| 3535 if (i >= tokensLength || tokens[i].type !== TokenType.NumberSign) retu
rn 0; |
| 3536 |
| 3537 return (l = checkIdent(i + 1)) ? l + 1 : 0; |
| 3538 } |
| 3539 |
| 3540 /** |
| 3541 * Get node with a hexadecimal number (e.g. `#fff`) inside a simple |
| 3542 * selector |
| 3543 * @return {Node} |
| 3544 */ |
| 3545 function getShash() { |
| 3546 var type = NodeType.ShashType; |
| 3547 var token = tokens[pos]; |
| 3548 var line = token.ln; |
| 3549 var column = token.col; |
| 3550 var content = []; |
| 3551 |
| 3552 pos++; |
| 3553 |
| 3554 var ident = getIdent(); |
| 3555 content.push(ident); |
| 3556 |
| 3557 return newNode(type, content, line, column); |
| 3558 } |
| 3559 |
| 3560 /** |
| 3561 * Check if token is part of a string (text wrapped in quotes) |
| 3562 * @param {Number} i Token's index number |
| 3563 * @return {Number} `1` if token is part of a string, `0` if not |
| 3564 */ |
| 3565 function checkString(i) { |
| 3566 if (i >= tokensLength) { |
| 3567 return 0; |
| 3568 } |
| 3569 |
| 3570 if (tokens[i].type === TokenType.StringSQ || tokens[i].type === TokenT
ype.StringDQ) { |
| 3571 return 1; |
| 3572 } |
| 3573 |
| 3574 return 0; |
| 3575 } |
| 3576 |
| 3577 /** |
| 3578 * Get string's node |
| 3579 * @return {Array} `['string', x]` where `x` is a string (including |
| 3580 * quotes). |
| 3581 */ |
| 3582 function getString() { |
| 3583 var type = NodeType.StringType; |
| 3584 var token = tokens[pos]; |
| 3585 var line = token.ln; |
| 3586 var column = token.col; |
| 3587 var content = token.value; |
| 3588 |
| 3589 pos++; |
| 3590 |
| 3591 return newNode(type, content, line, column); |
| 3592 } |
| 3593 |
| 3594 /** |
| 3595 * Validate stylesheet: it should consist of any number (0 or more) of |
| 3596 * rulesets (sets of rules with selectors), @-rules, whitespaces or |
| 3597 * comments. |
| 3598 * @param {Number} i Token's index number |
| 3599 * @return {Number} |
| 3600 */ |
| 3601 function checkStylesheet(i) { |
| 3602 var start = i; |
| 3603 var l = void 0; |
| 3604 |
| 3605 // Check every token: |
| 3606 while (i < tokensLength) { |
| 3607 if (l = checkSC(i)) tokens[i].stylesheet_child = 1;else if (l = chec
kRuleset(i)) tokens[i].stylesheet_child = 2;else if (l = checkAtrule(i)) tokens[
i].stylesheet_child = 3;else if (l = checkDeclDelim(i)) tokens[i].stylesheet_chi
ld = 4;else throwError(i); |
| 3608 |
| 3609 i += l; |
| 3610 } |
| 3611 |
| 3612 return i - start; |
| 3613 } |
| 3614 |
| 3615 /** |
| 3616 * @return {Array} `['stylesheet', x]` where `x` is all stylesheet's |
| 3617 * nodes. |
| 3618 */ |
| 3619 function getStylesheet() { |
| 3620 var type = NodeType.StylesheetType; |
| 3621 var token = tokens[pos]; |
| 3622 var line = token.ln; |
| 3623 var column = token.col; |
| 3624 var content = []; |
| 3625 var childType = void 0; |
| 3626 |
| 3627 while (pos < tokensLength) { |
| 3628 childType = tokens[pos].stylesheet_child; |
| 3629 if (childType === 1) content = content.concat(getSC());else if (chil
dType === 2) content.push(getRuleset());else if (childType === 3) content.push(g
etAtrule());else if (childType === 4) content.push(getDeclDelim()); |
| 3630 } |
| 3631 |
| 3632 return newNode(type, content, line, column); |
| 3633 } |
| 3634 |
| 3635 /** |
| 3636 * @param {Number} i Token's index number |
| 3637 * @return {Number} |
| 3638 */ |
| 3639 function checkTset(i) { |
| 3640 var l; |
| 3641 |
| 3642 if (l = checkVhash(i)) tokens[i].tset_child = 1;else if (l = checkAny(
i)) tokens[i].tset_child = 2;else if (l = checkSC(i)) tokens[i].tset_child = 3;e
lse if (l = checkOperator(i)) tokens[i].tset_child = 4; |
| 3643 |
| 3644 return l; |
| 3645 } |
| 3646 |
| 3647 /** |
| 3648 * @return {Array} |
| 3649 */ |
| 3650 function getTset() { |
| 3651 var childType = tokens[pos].tset_child; |
| 3652 if (childType === 1) return getVhash();else if (childType === 2) retur
n getAny();else if (childType === 3) return getSC();else if (childType === 4) re
turn getOperator(); |
| 3653 } |
| 3654 |
| 3655 /** |
| 3656 * @param {Number} i Token's index number |
| 3657 * @return {Number} |
| 3658 */ |
| 3659 function checkTsets(i) { |
| 3660 var start = i; |
| 3661 var l = void 0; |
| 3662 |
| 3663 if (i >= tokensLength) return 0; |
| 3664 |
| 3665 while (l = checkTset(i)) { |
| 3666 i += l; |
| 3667 } |
| 3668 |
| 3669 return i - start; |
| 3670 } |
| 3671 |
| 3672 /** |
| 3673 * @return {Array} |
| 3674 */ |
| 3675 function getTsets() { |
| 3676 var x = []; |
| 3677 var t = void 0; |
| 3678 |
| 3679 while (checkTset(pos)) { |
| 3680 t = getTset(); |
| 3681 if (typeof t.content === 'string') x.push(t);else x = x.concat(t); |
| 3682 } |
| 3683 |
| 3684 return x; |
| 3685 } |
| 3686 |
| 3687 /** |
| 3688 * Check if token is an unary (arithmetical) sign (`+` or `-`) |
| 3689 * @param {Number} i Token's index number |
| 3690 * @return {Number} `1` if token is an unary sign, `0` if not |
| 3691 */ |
| 3692 function checkUnary(i) { |
| 3693 if (i >= tokensLength) { |
| 3694 return 0; |
| 3695 } |
| 3696 |
| 3697 if (tokens[i].type === TokenType.HyphenMinus || tokens[i].type === Tok
enType.PlusSign) { |
| 3698 return 1; |
| 3699 } |
| 3700 |
| 3701 return 0; |
| 3702 } |
| 3703 |
| 3704 /** |
| 3705 * Get node with an unary (arithmetical) sign (`+` or `-`) |
| 3706 * @return {Array} `['unary', x]` where `x` is an unary sign |
| 3707 * converted to string. |
| 3708 */ |
| 3709 function getUnary() { |
| 3710 var type = NodeType.OperatorType; |
| 3711 var token = tokens[pos]; |
| 3712 var line = token.ln; |
| 3713 var column = token.col; |
| 3714 var content = token.value; |
| 3715 |
| 3716 pos++; |
| 3717 |
| 3718 return newNode(type, content, line, column); |
| 3719 } |
| 3720 |
| 3721 /** |
| 3722 * Check if token is a unicode range (single or multiple <urange> nodes) |
| 3723 * @param {number} i Token's index |
| 3724 * @return {number} Unicode range node's length |
| 3725 */ |
| 3726 function checkUnicodeRange(i) { |
| 3727 var start = i; |
| 3728 var l = void 0; |
| 3729 |
| 3730 if (i >= tokensLength) return 0; |
| 3731 |
| 3732 if (l = checkUrange(i)) i += l;else return 0; |
| 3733 |
| 3734 while (i < tokensLength) { |
| 3735 var spaceBefore = checkSC(i); |
| 3736 var comma = checkDelim(i + spaceBefore); |
| 3737 if (!comma) break; |
| 3738 |
| 3739 var spaceAfter = checkSC(i + spaceBefore + comma); |
| 3740 if (l = checkUrange(i + spaceBefore + comma + spaceAfter)) { |
| 3741 i += spaceBefore + comma + spaceAfter + l; |
| 3742 } else break; |
| 3743 } |
| 3744 |
| 3745 return i - start; |
| 3746 } |
| 3747 |
| 3748 /** |
| 3749 * Get a unicode range node |
| 3750 * @return {Node} |
| 3751 */ |
| 3752 function getUnicodeRange() { |
| 3753 var type = NodeType.UnicodeRangeType; |
| 3754 var token = tokens[pos]; |
| 3755 var line = token.ln; |
| 3756 var column = token.col; |
| 3757 var content = []; |
| 3758 |
| 3759 while (pos < tokensLength) { |
| 3760 if (checkSC(pos)) content = content.concat(getSC());else if (checkDe
lim(pos)) content.push(getDelim());else if (checkUrange(pos)) content.push(getUr
ange());else break; |
| 3761 } |
| 3762 |
| 3763 return newNode(type, content, line, column); |
| 3764 } |
| 3765 |
| 3766 /** |
| 3767 * Check if token is a u-range (part of a unicode-range) |
| 3768 * (1) `U+416` |
| 3769 * (2) `U+400-4ff` |
| 3770 * (3) `U+4??` |
| 3771 * @param {number} i Token's index |
| 3772 * @return {number} Urange node's length |
| 3773 */ |
| 3774 function checkUrange(i) { |
| 3775 var start = i; |
| 3776 var l = void 0; |
| 3777 |
| 3778 if (i >= tokensLength) return 0; |
| 3779 |
| 3780 // Check for unicode prefix (u+ or U+) |
| 3781 if (tokens[i].value === 'U' || tokens[i].value === 'u') i += 1;else re
turn 0; |
| 3782 |
| 3783 if (i >= tokensLength) return 0; |
| 3784 |
| 3785 if (tokens[i].value === '+') i += 1;else return 0; |
| 3786 |
| 3787 while (i < tokensLength) { |
| 3788 if (l = checkIdent(i)) i += l;else if (l = checkNumber(i)) i += l;el
se if (l = checkUnary(i)) i += l;else if (l = _checkUnicodeWildcard(i)) i += l;e
lse break; |
| 3789 } |
| 3790 |
| 3791 tokens[start].urangeEnd = i - 1; |
| 3792 |
| 3793 return i - start; |
| 3794 } |
| 3795 |
| 3796 /** |
| 3797 * Get a u-range node (part of a unicode-range) |
| 3798 * @return {Node} |
| 3799 */ |
| 3800 function getUrange() { |
| 3801 var startPos = pos; |
| 3802 var type = NodeType.UrangeType; |
| 3803 var token = tokens[pos]; |
| 3804 var line = token.ln; |
| 3805 var column = token.col; |
| 3806 var content = []; |
| 3807 |
| 3808 content = joinValues(startPos, tokens[startPos].urangeEnd); |
| 3809 pos = tokens[startPos].urangeEnd + 1; |
| 3810 |
| 3811 return newNode(type, content, line, column); |
| 3812 } |
| 3813 |
| 3814 /** |
| 3815 * Check for unicode wildcard characters `?` |
| 3816 * @param {number} i Token's index |
| 3817 * @return {number} Wildcard length |
| 3818 */ |
| 3819 function _checkUnicodeWildcard(i) { |
| 3820 var start = i; |
| 3821 |
| 3822 if (i >= tokensLength) return 0; |
| 3823 |
| 3824 while (i < tokensLength) { |
| 3825 if (tokens[i].type === TokenType.QuestionMark) i += 1;else break; |
| 3826 } |
| 3827 |
| 3828 return i - start; |
| 3829 } |
| 3830 |
| 3831 /** |
| 3832 * Check if token is part of URI (e.g. `url('/css/styles.css')`) |
| 3833 * @param {Number} i Token's index number |
| 3834 * @return {Number} Length of URI |
| 3835 */ |
| 3836 function checkUri(i) { |
| 3837 var start = i; |
| 3838 |
| 3839 if (i >= tokensLength || tokens[i].value !== 'url') return 0; |
| 3840 i += 1; |
| 3841 if (i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis)
return 0; |
| 3842 |
| 3843 return tokens[i].right - start + 1; |
| 3844 } |
| 3845 |
| 3846 /** |
| 3847 * Get node with URI |
| 3848 * @return {Array} `['uri', x]` where `x` is URI's nodes (without `url` |
| 3849 * and braces, e.g. `['string', ''/css/styles.css'']`). |
| 3850 */ |
| 3851 function getUri() { |
| 3852 var startPos = pos; |
| 3853 var uriExcluding = {}; |
| 3854 var uri = void 0; |
| 3855 var l = void 0; |
| 3856 var raw = void 0; |
| 3857 |
| 3858 var rawContent = void 0; |
| 3859 var t = void 0; |
| 3860 |
| 3861 pos += 2; |
| 3862 |
| 3863 uriExcluding[TokenType.Space] = 1; |
| 3864 uriExcluding[TokenType.Tab] = 1; |
| 3865 uriExcluding[TokenType.Newline] = 1; |
| 3866 uriExcluding[TokenType.LeftParenthesis] = 1; |
| 3867 uriExcluding[TokenType.RightParenthesis] = 1; |
| 3868 |
| 3869 if (checkUri1(pos)) { |
| 3870 uri = [].concat(getSC()).concat([getString()]).concat(getSC()); |
| 3871 } else { |
| 3872 uri = checkSC(pos) ? getSC() : []; |
| 3873 l = checkExcluding(uriExcluding, pos); |
| 3874 rawContent = joinValues(pos, pos + l); |
| 3875 t = tokens[pos]; |
| 3876 raw = newNode(NodeType.RawType, rawContent, t.ln, t.col); |
| 3877 |
| 3878 uri.push(raw); |
| 3879 |
| 3880 pos += l + 1; |
| 3881 |
| 3882 if (checkSC(pos)) uri = uri.concat(getSC()); |
| 3883 } |
| 3884 |
| 3885 t = tokens[startPos]; |
| 3886 var line = t.ln; |
| 3887 var column = t.col; |
| 3888 var end = getLastPosition(uri, line, column, 1); |
| 3889 pos++; |
| 3890 |
| 3891 return newNode(NodeType.UriType, uri, line, column, end); |
| 3892 } |
| 3893 |
| 3894 /** |
| 3895 * @param {Number} i Token's index number |
| 3896 * @return {Number} |
| 3897 */ |
| 3898 function checkUri1(i) { |
| 3899 var start = i; |
| 3900 var l = void 0; |
| 3901 |
| 3902 if (i >= tokensLength) return 0; |
| 3903 |
| 3904 if (l = checkSC(i)) i += l; |
| 3905 |
| 3906 if (tokens[i].type !== TokenType.StringDQ && tokens[i].type !== TokenT
ype.StringSQ) return 0; |
| 3907 |
| 3908 i++; |
| 3909 |
| 3910 if (l = checkSC(i)) i += l; |
| 3911 |
| 3912 return i - start; |
| 3913 } |
| 3914 |
| 3915 /** |
| 3916 * Check if token is part of a value |
| 3917 * @param {Number} i Token's index number |
| 3918 * @return {Number} Length of the value |
| 3919 */ |
| 3920 function checkValue(i) { |
| 3921 var start = i; |
| 3922 var l = void 0; |
| 3923 var s = void 0; |
| 3924 var _i = void 0; |
| 3925 |
| 3926 while (i < tokensLength) { |
| 3927 s = checkSC(i); |
| 3928 _i = i + s; |
| 3929 |
| 3930 if (l = _checkValue(_i)) i += l + s;else break; |
| 3931 } |
| 3932 |
| 3933 tokens[start].value_end = i; |
| 3934 return i - start; |
| 3935 } |
| 3936 |
| 3937 /** |
| 3938 * @return {Array} |
| 3939 */ |
| 3940 function getValue() { |
| 3941 var startPos = pos; |
| 3942 var end = tokens[pos].value_end; |
| 3943 var x = []; |
| 3944 |
| 3945 while (pos < end) { |
| 3946 if (tokens[pos].value_child) x.push(_getValue());else x = x.concat(g
etSC()); |
| 3947 } |
| 3948 |
| 3949 var t = tokens[startPos]; |
| 3950 return newNode(NodeType.ValueType, x, t.ln, t.col); |
| 3951 } |
| 3952 |
| 3953 /** |
| 3954 * @param {Number} i Token's index number |
| 3955 * @return {Number} |
| 3956 */ |
| 3957 function _checkValue(i) { |
| 3958 var l; |
| 3959 |
| 3960 if (l = checkProgid(i)) tokens[i].value_child = 1;else if (l = checkVh
ash(i)) tokens[i].value_child = 2;else if (l = checkAny(i)) tokens[i].value_chil
d = 3;else if (l = checkOperator(i)) tokens[i].value_child = 4;else if (l = chec
kImportant(i)) tokens[i].value_child = 5; |
| 3961 |
| 3962 return l; |
| 3963 } |
| 3964 |
| 3965 /** |
| 3966 * @return {Array} |
| 3967 */ |
| 3968 function _getValue() { |
| 3969 var childType = tokens[pos].value_child; |
| 3970 if (childType === 1) return getProgid();else if (childType === 2) retu
rn getVhash();else if (childType === 3) return getAny();else if (childType === 4
) return getOperator();else if (childType === 5) return getImportant(); |
| 3971 } |
| 3972 |
| 3973 /** |
| 3974 * Check if token is part of a hexadecimal number (e.g. `#fff`) inside |
| 3975 * some value |
| 3976 * @param {Number} i Token's index number |
| 3977 * @return {Number} |
| 3978 */ |
| 3979 function checkVhash(i) { |
| 3980 var l; |
| 3981 |
| 3982 if (i >= tokensLength || tokens[i].type !== TokenType.NumberSign) retu
rn 0; |
| 3983 |
| 3984 return (l = checkNmName2(i + 1)) ? l + 1 : 0; |
| 3985 } |
| 3986 |
| 3987 /** |
| 3988 * Get node with a hexadecimal number (e.g. `#fff`) inside some value |
| 3989 * @return {Array} `['vhash', x]` where `x` is a hexadecimal number |
| 3990 * converted to string (without `#`, e.g. `'fff'`). |
| 3991 */ |
| 3992 function getVhash() { |
| 3993 var type = NodeType.VhashType; |
| 3994 var token = tokens[pos]; |
| 3995 var line = token.ln; |
| 3996 var column = token.col; |
| 3997 var content = void 0; |
| 3998 |
| 3999 pos++; |
| 4000 |
| 4001 content = getNmName2(); |
| 4002 var end = getLastPosition(content, line, column + 1); |
| 4003 return newNode(type, content, line, column, end); |
| 4004 } |
| 4005 |
| 4006 function checkSelectorsGroup(i) { |
| 4007 if (i >= tokensLength) return 0; |
| 4008 |
| 4009 var start = i; |
| 4010 var l = void 0; |
| 4011 |
| 4012 if (l = checkSelector(i)) i += l;else return 0; |
| 4013 |
| 4014 while (i < tokensLength) { |
| 4015 var sb = checkSC(i); |
| 4016 var c = checkDelim(i + sb); |
| 4017 if (!c) break; |
| 4018 var sa = checkSC(i + sb + c); |
| 4019 if (l = checkSelector(i + sb + c + sa)) i += sb + c + sa + l;else br
eak; |
| 4020 } |
| 4021 |
| 4022 tokens[start].selectorsGroupEnd = i; |
| 4023 return i - start; |
| 4024 } |
| 4025 |
| 4026 function getSelectorsGroup() { |
| 4027 var selectorsGroup = []; |
| 4028 var selectorsGroupEnd = tokens[pos].selectorsGroupEnd; |
| 4029 |
| 4030 selectorsGroup.push(getSelector()); |
| 4031 |
| 4032 while (pos < selectorsGroupEnd) { |
| 4033 selectorsGroup = selectorsGroup.concat(getSC()); |
| 4034 selectorsGroup.push(getDelim()); |
| 4035 selectorsGroup = selectorsGroup.concat(getSC()); |
| 4036 selectorsGroup.push(getSelector()); |
| 4037 } |
| 4038 |
| 4039 return selectorsGroup; |
| 4040 } |
| 4041 |
| 4042 function checkSelector(i) { |
| 4043 if (i >= tokensLength) return 0; |
| 4044 |
| 4045 var start = i; |
| 4046 var l = void 0; |
| 4047 |
| 4048 if (l = checkCompoundSelector(i)) i += l;else return 0; |
| 4049 |
| 4050 while (i < tokensLength) { |
| 4051 var sb = checkSC(i); |
| 4052 var c = checkCombinator(i + sb); |
| 4053 if (!sb && !c) break; |
| 4054 var sa = checkSC(i + sb + c); |
| 4055 if (l = checkCompoundSelector(i + sb + c + sa)) i += sb + c + sa + l
;else break; |
| 4056 } |
| 4057 |
| 4058 tokens[start].selectorEnd = i; |
| 4059 return i - start; |
| 4060 } |
| 4061 |
| 4062 function getSelector() { |
| 4063 var type = NodeType.SelectorType; |
| 4064 var token = tokens[pos]; |
| 4065 var line = token.ln; |
| 4066 var column = token.col; |
| 4067 var selectorEnd = token.selectorEnd; |
| 4068 var content = void 0; |
| 4069 |
| 4070 content = getCompoundSelector(); |
| 4071 |
| 4072 while (pos < selectorEnd) { |
| 4073 content = content.concat(getSC()); |
| 4074 if (checkCombinator(pos)) content.push(getCombinator()); |
| 4075 content = content.concat(getSC()); |
| 4076 content = content.concat(getCompoundSelector()); |
| 4077 } |
| 4078 |
| 4079 return newNode(type, content, line, column); |
| 4080 } |
| 4081 |
| 4082 function checkCompoundSelector(i) { |
| 4083 var l = void 0; |
| 4084 |
| 4085 if (l = checkCompoundSelector1(i)) { |
| 4086 tokens[i].compoundSelectorType = 1; |
| 4087 } else if (l = checkCompoundSelector2(i)) { |
| 4088 tokens[i].compoundSelectorType = 2; |
| 4089 } |
| 4090 |
| 4091 return l; |
| 4092 } |
| 4093 |
| 4094 function getCompoundSelector() { |
| 4095 var type = tokens[pos].compoundSelectorType; |
| 4096 if (type === 1) return getCompoundSelector1(); |
| 4097 if (type === 2) return getCompoundSelector2(); |
| 4098 } |
| 4099 |
| 4100 function checkCompoundSelector1(i) { |
| 4101 if (i >= tokensLength) return 0; |
| 4102 |
| 4103 var start = i; |
| 4104 |
| 4105 var l = void 0; |
| 4106 if (l = checkUniversalSelector(i) || checkTypeSelector(i)) i += l;else
return 0; |
| 4107 |
| 4108 while (i < tokensLength) { |
| 4109 var _l2 = checkShash(i) || checkClass(i) || checkAttributeSelector(i
) || checkPseudo(i); |
| 4110 if (_l2) i += _l2;else break; |
| 4111 } |
| 4112 |
| 4113 tokens[start].compoundSelectorEnd = i; |
| 4114 |
| 4115 return i - start; |
| 4116 } |
| 4117 |
| 4118 function getCompoundSelector1() { |
| 4119 var sequence = []; |
| 4120 var compoundSelectorEnd = tokens[pos].compoundSelectorEnd; |
| 4121 |
| 4122 if (checkUniversalSelector(pos)) sequence.push(getUniversalSelector())
;else sequence.push(getTypeSelector()); |
| 4123 |
| 4124 while (pos < compoundSelectorEnd) { |
| 4125 if (checkShash(pos)) sequence.push(getShash());else if (checkClass(p
os)) sequence.push(getClass());else if (checkAttributeSelector(pos)) sequence.pu
sh(getAttributeSelector());else if (checkPseudo(pos)) sequence.push(getPseudo())
; |
| 4126 } |
| 4127 |
| 4128 return sequence; |
| 4129 } |
| 4130 |
| 4131 function checkCompoundSelector2(i) { |
| 4132 if (i >= tokensLength) return 0; |
| 4133 |
| 4134 var start = i; |
| 4135 |
| 4136 while (i < tokensLength) { |
| 4137 var l = checkShash(i) || checkClass(i) || checkAttributeSelector(i)
|| checkPseudo(i); |
| 4138 if (l) i += l;else break; |
| 4139 } |
| 4140 |
| 4141 tokens[start].compoundSelectorEnd = i; |
| 4142 |
| 4143 return i - start; |
| 4144 } |
| 4145 |
| 4146 function getCompoundSelector2() { |
| 4147 var sequence = []; |
| 4148 var compoundSelectorEnd = tokens[pos].compoundSelectorEnd; |
| 4149 |
| 4150 while (pos < compoundSelectorEnd) { |
| 4151 if (checkShash(pos)) sequence.push(getShash());else if (checkClass(p
os)) sequence.push(getClass());else if (checkAttributeSelector(pos)) sequence.pu
sh(getAttributeSelector());else if (checkPseudo(pos)) sequence.push(getPseudo())
; |
| 4152 } |
| 4153 |
| 4154 return sequence; |
| 4155 } |
| 4156 |
| 4157 function checkUniversalSelector(i) { |
| 4158 if (i >= tokensLength) return 0; |
| 4159 |
| 4160 var start = i; |
| 4161 var l = void 0; |
| 4162 |
| 4163 if (l = checkNamePrefix(i)) i += l; |
| 4164 |
| 4165 if (tokens[i].type === TokenType.Asterisk) i++;else return 0; |
| 4166 |
| 4167 return i - start; |
| 4168 } |
| 4169 |
| 4170 function getUniversalSelector() { |
| 4171 var type = NodeType.UniversalSelectorType; |
| 4172 var token = tokens[pos]; |
| 4173 var line = token.ln; |
| 4174 var column = token.col; |
| 4175 var content = []; |
| 4176 var end = void 0; |
| 4177 |
| 4178 if (checkNamePrefix(pos)) { |
| 4179 content.push(getNamePrefix()); |
| 4180 end = getLastPosition(content, line, column, 1); |
| 4181 } |
| 4182 |
| 4183 pos++; |
| 4184 |
| 4185 return newNode(type, content, line, column, end); |
| 4186 } |
| 4187 |
| 4188 function checkTypeSelector(i) { |
| 4189 if (i >= tokensLength) return 0; |
| 4190 |
| 4191 var start = i; |
| 4192 var l = void 0; |
| 4193 |
| 4194 if (l = checkNamePrefix(i)) i += l; |
| 4195 |
| 4196 if (l = checkIdent(i)) i += l;else return 0; |
| 4197 |
| 4198 return i - start; |
| 4199 } |
| 4200 |
| 4201 function getTypeSelector() { |
| 4202 var type = NodeType.TypeSelectorType; |
| 4203 var token = tokens[pos]; |
| 4204 var line = token.ln; |
| 4205 var column = token.col; |
| 4206 var content = []; |
| 4207 |
| 4208 if (checkNamePrefix(pos)) content.push(getNamePrefix()); |
| 4209 |
| 4210 content.push(getIdent()); |
| 4211 |
| 4212 return newNode(type, content, line, column); |
| 4213 } |
| 4214 |
| 4215 function checkAttributeSelector(i) { |
| 4216 var l = void 0; |
| 4217 if (l = checkAttributeSelector1(i)) tokens[i].attributeSelectorType =
1;else if (l = checkAttributeSelector2(i)) tokens[i].attributeSelectorType = 2; |
| 4218 |
| 4219 return l; |
| 4220 } |
| 4221 |
| 4222 function getAttributeSelector() { |
| 4223 var type = tokens[pos].attributeSelectorType; |
| 4224 if (type === 1) return getAttributeSelector1();else return getAttribut
eSelector2(); |
| 4225 } |
| 4226 |
| 4227 /** |
| 4228 * (1) `[panda=nani]` |
| 4229 * (2) `[panda='nani']` |
| 4230 * (3) `[panda='nani' i]` |
| 4231 * |
| 4232 */ |
| 4233 function checkAttributeSelector1(i) { |
| 4234 var start = i; |
| 4235 |
| 4236 if (tokens[i].type === TokenType.LeftSquareBracket) i++;else return 0; |
| 4237 |
| 4238 var l = void 0; |
| 4239 if (l = checkSC(i)) i += l; |
| 4240 |
| 4241 if (l = checkAttributeName(i)) i += l;else return 0; |
| 4242 |
| 4243 if (l = checkSC(i)) i += l; |
| 4244 |
| 4245 if (l = checkAttributeMatch(i)) i += l;else return 0; |
| 4246 |
| 4247 if (l = checkSC(i)) i += l; |
| 4248 |
| 4249 if (l = checkAttributeValue(i)) i += l;else return 0; |
| 4250 |
| 4251 if (l = checkSC(i)) i += l; |
| 4252 |
| 4253 if (l = checkAttributeFlags(i)) { |
| 4254 i += l; |
| 4255 if (l = checkSC(i)) i += l; |
| 4256 } |
| 4257 |
| 4258 if (tokens[i].type === TokenType.RightSquareBracket) i++;else return 0
; |
| 4259 |
| 4260 return i - start; |
| 4261 } |
| 4262 |
| 4263 function getAttributeSelector1() { |
| 4264 var type = NodeType.AttributeSelectorType; |
| 4265 var token = tokens[pos]; |
| 4266 var line = token.ln; |
| 4267 var column = token.col; |
| 4268 var content = []; |
| 4269 |
| 4270 // Skip `[`. |
| 4271 pos++; |
| 4272 |
| 4273 content = content.concat(getSC()); |
| 4274 content.push(getAttributeName()); |
| 4275 content = content.concat(getSC()); |
| 4276 content.push(getAttributeMatch()); |
| 4277 content = content.concat(getSC()); |
| 4278 content.push(getAttributeValue()); |
| 4279 content = content.concat(getSC()); |
| 4280 |
| 4281 if (checkAttributeFlags(pos)) { |
| 4282 content.push(getAttributeFlags()); |
| 4283 content = content.concat(getSC()); |
| 4284 } |
| 4285 |
| 4286 // Skip `]`. |
| 4287 pos++; |
| 4288 |
| 4289 var end = getLastPosition(content, line, column, 1); |
| 4290 return newNode(type, content, line, column, end); |
| 4291 } |
| 4292 |
| 4293 /** |
| 4294 * (1) `[panda]` |
| 4295 */ |
| 4296 function checkAttributeSelector2(i) { |
| 4297 var start = i; |
| 4298 |
| 4299 if (tokens[i].type === TokenType.LeftSquareBracket) i++;else return 0; |
| 4300 |
| 4301 var l = void 0; |
| 4302 if (l = checkSC(i)) i += l; |
| 4303 |
| 4304 if (l = checkAttributeName(i)) i += l;else return 0; |
| 4305 |
| 4306 if (l = checkSC(i)) i += l; |
| 4307 |
| 4308 if (tokens[i].type === TokenType.RightSquareBracket) i++;else return 0
; |
| 4309 |
| 4310 return i - start; |
| 4311 } |
| 4312 |
| 4313 function getAttributeSelector2() { |
| 4314 var type = NodeType.AttributeSelectorType; |
| 4315 var token = tokens[pos]; |
| 4316 var line = token.ln; |
| 4317 var column = token.col; |
| 4318 var content = []; |
| 4319 |
| 4320 // Skip `[`. |
| 4321 pos++; |
| 4322 |
| 4323 content = content.concat(getSC()); |
| 4324 content.push(getAttributeName()); |
| 4325 content = content.concat(getSC()); |
| 4326 |
| 4327 // Skip `]`. |
| 4328 pos++; |
| 4329 |
| 4330 var end = getLastPosition(content, line, column, 1); |
| 4331 return newNode(type, content, line, column, end); |
| 4332 } |
| 4333 |
| 4334 function checkAttributeName(i) { |
| 4335 var start = i; |
| 4336 var l = void 0; |
| 4337 |
| 4338 if (l = checkNamePrefix(i)) i += l; |
| 4339 |
| 4340 if (l = checkIdent(i)) i += l;else return 0; |
| 4341 |
| 4342 return i - start; |
| 4343 } |
| 4344 |
| 4345 function getAttributeName() { |
| 4346 var type = NodeType.AttributeNameType; |
| 4347 var token = tokens[pos]; |
| 4348 var line = token.ln; |
| 4349 var column = token.col; |
| 4350 var content = []; |
| 4351 |
| 4352 if (checkNamePrefix(pos)) content.push(getNamePrefix()); |
| 4353 content.push(getIdent()); |
| 4354 |
| 4355 return newNode(type, content, line, column); |
| 4356 } |
| 4357 |
| 4358 function checkAttributeMatch(i) { |
| 4359 var l = void 0; |
| 4360 if (l = checkAttributeMatch1(i)) tokens[i].attributeMatchType = 1;else
if (l = checkAttributeMatch2(i)) tokens[i].attributeMatchType = 2; |
| 4361 |
| 4362 return l; |
| 4363 } |
| 4364 |
| 4365 function getAttributeMatch() { |
| 4366 var type = tokens[pos].attributeMatchType; |
| 4367 if (type === 1) return getAttributeMatch1();else return getAttributeMa
tch2(); |
| 4368 } |
| 4369 |
| 4370 function checkAttributeMatch1(i) { |
| 4371 var start = i; |
| 4372 |
| 4373 var type = tokens[i].type; |
| 4374 if (type === TokenType.Tilde || type === TokenType.VerticalLine || typ
e === TokenType.CircumflexAccent || type === TokenType.DollarSign || type === To
kenType.Asterisk) i++;else return 0; |
| 4375 |
| 4376 if (tokens[i].type === TokenType.EqualsSign) i++;else return 0; |
| 4377 |
| 4378 return i - start; |
| 4379 } |
| 4380 |
| 4381 function getAttributeMatch1() { |
| 4382 var type = NodeType.AttributeMatchType; |
| 4383 var token = tokens[pos]; |
| 4384 var line = token.ln; |
| 4385 var column = token.col; |
| 4386 var content = tokens[pos].value + tokens[pos + 1].value; |
| 4387 pos += 2; |
| 4388 |
| 4389 return newNode(type, content, line, column); |
| 4390 } |
| 4391 |
| 4392 function checkAttributeMatch2(i) { |
| 4393 if (tokens[i].type === TokenType.EqualsSign) return 1;else return 0; |
| 4394 } |
| 4395 |
| 4396 function getAttributeMatch2() { |
| 4397 var type = NodeType.AttributeMatchType; |
| 4398 var token = tokens[pos]; |
| 4399 var line = token.ln; |
| 4400 var column = token.col; |
| 4401 var content = '='; |
| 4402 |
| 4403 pos++; |
| 4404 return newNode(type, content, line, column); |
| 4405 } |
| 4406 |
| 4407 function checkAttributeValue(i) { |
| 4408 return checkString(i) || checkIdent(i); |
| 4409 } |
| 4410 |
| 4411 function getAttributeValue() { |
| 4412 var type = NodeType.AttributeValueType; |
| 4413 var token = tokens[pos]; |
| 4414 var line = token.ln; |
| 4415 var column = token.col; |
| 4416 var content = []; |
| 4417 |
| 4418 if (checkString(pos)) content.push(getString());else content.push(getI
dent()); |
| 4419 |
| 4420 return newNode(type, content, line, column); |
| 4421 } |
| 4422 |
| 4423 function checkAttributeFlags(i) { |
| 4424 return checkIdent(i); |
| 4425 } |
| 4426 |
| 4427 function getAttributeFlags() { |
| 4428 var type = NodeType.AttributeFlagsType; |
| 4429 var token = tokens[pos]; |
| 4430 var line = token.ln; |
| 4431 var column = token.col; |
| 4432 var content = [getIdent()]; |
| 4433 |
| 4434 return newNode(type, content, line, column); |
| 4435 } |
| 4436 |
| 4437 function checkNamePrefix(i) { |
| 4438 if (i >= tokensLength) return 0; |
| 4439 |
| 4440 var l = void 0; |
| 4441 if (l = checkNamePrefix1(i)) tokens[i].namePrefixType = 1;else if (l =
checkNamePrefix2(i)) tokens[i].namePrefixType = 2; |
| 4442 |
| 4443 return l; |
| 4444 } |
| 4445 |
| 4446 function getNamePrefix() { |
| 4447 var type = tokens[pos].namePrefixType; |
| 4448 if (type === 1) return getNamePrefix1();else return getNamePrefix2(); |
| 4449 } |
| 4450 |
| 4451 /** |
| 4452 * (1) `panda|` |
| 4453 * (2) `panda<comment>|` |
| 4454 */ |
| 4455 function checkNamePrefix1(i) { |
| 4456 var start = i; |
| 4457 var l = void 0; |
| 4458 |
| 4459 if (l = checkNamespacePrefix(i)) i += l;else return 0; |
| 4460 |
| 4461 if (l = checkCommentML(i)) i += l; |
| 4462 |
| 4463 if (l = checkNamespaceSeparator(i)) i += l;else return 0; |
| 4464 |
| 4465 return i - start; |
| 4466 } |
| 4467 |
| 4468 function getNamePrefix1() { |
| 4469 var type = NodeType.NamePrefixType; |
| 4470 var token = tokens[pos]; |
| 4471 var line = token.ln; |
| 4472 var column = token.col; |
| 4473 var content = []; |
| 4474 |
| 4475 content.push(getNamespacePrefix()); |
| 4476 |
| 4477 if (checkCommentML(pos)) content.push(getCommentML()); |
| 4478 |
| 4479 content.push(getNamespaceSeparator()); |
| 4480 |
| 4481 return newNode(type, content, line, column); |
| 4482 } |
| 4483 |
| 4484 /** |
| 4485 * (1) `|` |
| 4486 */ |
| 4487 function checkNamePrefix2(i) { |
| 4488 return checkNamespaceSeparator(i); |
| 4489 } |
| 4490 |
| 4491 function getNamePrefix2() { |
| 4492 var type = NodeType.NamePrefixType; |
| 4493 var token = tokens[pos]; |
| 4494 var line = token.ln; |
| 4495 var column = token.col; |
| 4496 var content = [getNamespaceSeparator()]; |
| 4497 |
| 4498 return newNode(type, content, line, column); |
| 4499 } |
| 4500 |
| 4501 /** |
| 4502 * (1) `*` |
| 4503 * (2) `panda` |
| 4504 */ |
| 4505 function checkNamespacePrefix(i) { |
| 4506 if (i >= tokensLength) return 0; |
| 4507 |
| 4508 var l = void 0; |
| 4509 |
| 4510 if (tokens[i].type === TokenType.Asterisk) return 1;else if (l = check
Ident(i)) return l;else return 0; |
| 4511 } |
| 4512 |
| 4513 function getNamespacePrefix() { |
| 4514 var type = NodeType.NamespacePrefixType; |
| 4515 var token = tokens[pos]; |
| 4516 var line = token.ln; |
| 4517 var column = token.col; |
| 4518 var content = []; |
| 4519 |
| 4520 if (tokens[pos].type === TokenType.Asterisk) { |
| 4521 var asteriskNode = newNode(NodeType.IdentType, '*', line, column); |
| 4522 content.push(asteriskNode); |
| 4523 pos++; |
| 4524 } else if (checkIdent(pos)) content.push(getIdent()); |
| 4525 |
| 4526 return newNode(type, content, line, column); |
| 4527 } |
| 4528 |
| 4529 /** |
| 4530 * (1) `|` |
| 4531 */ |
| 4532 function checkNamespaceSeparator(i) { |
| 4533 if (i >= tokensLength) return 0; |
| 4534 |
| 4535 if (tokens[i].type !== TokenType.VerticalLine) return 0; |
| 4536 |
| 4537 // Return false if `|=` - [attr|=value] |
| 4538 if (tokens[i + 1] && tokens[i + 1].type === TokenType.EqualsSign) retu
rn 0; |
| 4539 |
| 4540 return 1; |
| 4541 } |
| 4542 |
| 4543 function getNamespaceSeparator() { |
| 4544 var type = NodeType.NamespaceSeparatorType; |
| 4545 var token = tokens[pos]; |
| 4546 var line = token.ln; |
| 4547 var column = token.col; |
| 4548 var content = '|'; |
| 4549 |
| 4550 pos++; |
| 4551 return newNode(type, content, line, column); |
| 4552 } |
| 4553 |
| 4554 module.exports = function (_tokens, context) { |
| 4555 tokens = _tokens; |
| 4556 tokensLength = tokens.length; |
| 4557 pos = 0; |
| 4558 |
| 4559 return contexts[context](); |
| 4560 }; |
| 4561 |
| 4562 /***/ }, |
| 4563 /* 15 */ |
| 4564 /***/ function(module, exports) { |
| 4565 |
| 4566 'use strict'; |
| 4567 |
| 4568 module.exports = { |
| 4569 ArgumentsType: 'arguments', |
| 4570 AtkeywordType: 'atkeyword', |
| 4571 AtruleType: 'atrule', |
| 4572 AttributeSelectorType: 'attributeSelector', |
| 4573 AttributeNameType: 'attributeName', |
| 4574 AttributeFlagsType: 'attributeFlags', |
| 4575 AttributeMatchType: 'attributeMatch', |
| 4576 AttributeValueType: 'attributeValue', |
| 4577 BlockType: 'block', |
| 4578 BracketsType: 'brackets', |
| 4579 ClassType: 'class', |
| 4580 CombinatorType: 'combinator', |
| 4581 CommentMLType: 'multilineComment', |
| 4582 CommentSLType: 'singlelineComment', |
| 4583 ConditionType: 'condition', |
| 4584 ConditionalStatementType: 'conditionalStatement', |
| 4585 DeclarationType: 'declaration', |
| 4586 DeclDelimType: 'declarationDelimiter', |
| 4587 DefaultType: 'default', |
| 4588 DelimType: 'delimiter', |
| 4589 DimensionType: 'dimension', |
| 4590 EscapedStringType: 'escapedString', |
| 4591 ExtendType: 'extend', |
| 4592 ExpressionType: 'expression', |
| 4593 FunctionType: 'function', |
| 4594 GlobalType: 'global', |
| 4595 IdentType: 'ident', |
| 4596 ImportantType: 'important', |
| 4597 IncludeType: 'include', |
| 4598 InterpolationType: 'interpolation', |
| 4599 InterpolatedVariableType: 'interpolatedVariable', |
| 4600 KeyframesSelectorType: 'keyframesSelector', |
| 4601 LoopType: 'loop', |
| 4602 MixinType: 'mixin', |
| 4603 NamePrefixType: 'namePrefix', |
| 4604 NamespacePrefixType: 'namespacePrefix', |
| 4605 NamespaceSeparatorType: 'namespaceSeparator', |
| 4606 NumberType: 'number', |
| 4607 OperatorType: 'operator', |
| 4608 OptionalType: 'optional', |
| 4609 ParenthesesType: 'parentheses', |
| 4610 ParentSelectorType: 'parentSelector', |
| 4611 ParentSelectorExtensionType: 'parentSelectorExtension', |
| 4612 PercentageType: 'percentage', |
| 4613 PlaceholderType: 'placeholder', |
| 4614 ProgidType: 'progid', |
| 4615 PropertyType: 'property', |
| 4616 PropertyDelimType: 'propertyDelimiter', |
| 4617 PseudocType: 'pseudoClass', |
| 4618 PseudoeType: 'pseudoElement', |
| 4619 RawType: 'raw', |
| 4620 RulesetType: 'ruleset', |
| 4621 SType: 'space', |
| 4622 SelectorType: 'selector', |
| 4623 ShashType: 'id', |
| 4624 StringType: 'string', |
| 4625 StylesheetType: 'stylesheet', |
| 4626 TypeSelectorType: 'typeSelector', |
| 4627 UnicodeRangeType: 'unicodeRange', |
| 4628 UniversalSelectorType: 'universalSelector', |
| 4629 UriType: 'uri', |
| 4630 UrangeType: 'urange', |
| 4631 ValueType: 'value', |
| 4632 VariableType: 'variable', |
| 4633 VariablesListType: 'variablesList', |
| 4634 VhashType: 'color' |
| 4635 }; |
| 4636 |
| 4637 /***/ }, |
| 4638 /* 16 */ |
| 4639 /***/ function(module, exports, __webpack_require__) { |
| 4640 |
| 4641 'use strict'; |
| 4642 |
| 4643 module.exports = function (css, tabSize) { |
| 4644 var TokenType = __webpack_require__(13); |
| 4645 |
| 4646 var tokens = []; |
| 4647 var urlMode = false; |
| 4648 var blockMode = 0; |
| 4649 var pos = 0; |
| 4650 var tn = 0; |
| 4651 var ln = 1; |
| 4652 var col = 1; |
| 4653 var cssLength = 0; |
| 4654 |
| 4655 var Punctuation = { |
| 4656 ' ': TokenType.Space, |
| 4657 '\n': TokenType.Newline, |
| 4658 '\r': TokenType.Newline, |
| 4659 '\t': TokenType.Tab, |
| 4660 '!': TokenType.ExclamationMark, |
| 4661 '"': TokenType.QuotationMark, |
| 4662 '#': TokenType.NumberSign, |
| 4663 '$': TokenType.DollarSign, |
| 4664 '%': TokenType.PercentSign, |
| 4665 '&': TokenType.Ampersand, |
| 4666 '\'': TokenType.Apostrophe, |
| 4667 '(': TokenType.LeftParenthesis, |
| 4668 ')': TokenType.RightParenthesis, |
| 4669 '*': TokenType.Asterisk, |
| 4670 '+': TokenType.PlusSign, |
| 4671 ',': TokenType.Comma, |
| 4672 '-': TokenType.HyphenMinus, |
| 4673 '.': TokenType.FullStop, |
| 4674 '/': TokenType.Solidus, |
| 4675 ':': TokenType.Colon, |
| 4676 ';': TokenType.Semicolon, |
| 4677 '<': TokenType.LessThanSign, |
| 4678 '=': TokenType.EqualsSign, |
| 4679 '>': TokenType.GreaterThanSign, |
| 4680 '?': TokenType.QuestionMark, |
| 4681 '@': TokenType.CommercialAt, |
| 4682 '[': TokenType.LeftSquareBracket, |
| 4683 ']': TokenType.RightSquareBracket, |
| 4684 '^': TokenType.CircumflexAccent, |
| 4685 '_': TokenType.LowLine, |
| 4686 '{': TokenType.LeftCurlyBracket, |
| 4687 '|': TokenType.VerticalLine, |
| 4688 '}': TokenType.RightCurlyBracket, |
| 4689 '~': TokenType.Tilde |
| 4690 }; |
| 4691 |
| 4692 /** |
| 4693 * Add a token to the token list |
| 4694 * @param {string} type |
| 4695 * @param {string} value |
| 4696 */ |
| 4697 function pushToken(type, value, column) { |
| 4698 tokens.push({ |
| 4699 tn: tn++, |
| 4700 ln: ln, |
| 4701 col: column, |
| 4702 type: type, |
| 4703 value: value |
| 4704 }); |
| 4705 } |
| 4706 |
| 4707 /** |
| 4708 * Check if a character is a decimal digit |
| 4709 * @param {string} c Character |
| 4710 * @returns {boolean} |
| 4711 */ |
| 4712 function isDecimalDigit(c) { |
| 4713 return '0123456789'.indexOf(c) >= 0; |
| 4714 } |
| 4715 |
| 4716 /** |
| 4717 * Parse spaces |
| 4718 * @param {string} css Unparsed part of CSS string |
| 4719 */ |
| 4720 function parseSpaces(css) { |
| 4721 var start = pos; |
| 4722 |
| 4723 // Read the string until we meet a non-space character: |
| 4724 for (; pos < cssLength; pos++) { |
| 4725 if (css.charAt(pos) !== ' ') break; |
| 4726 } |
| 4727 |
| 4728 // Add a substring containing only spaces to tokens: |
| 4729 pushToken(TokenType.Space, css.substring(start, pos--), col); |
| 4730 col += pos - start; |
| 4731 } |
| 4732 |
| 4733 /** |
| 4734 * Parse a string within quotes |
| 4735 * @param {string} css Unparsed part of CSS string |
| 4736 * @param {string} q Quote (either `'` or `"`) |
| 4737 */ |
| 4738 function parseString(css, q) { |
| 4739 var start = pos; |
| 4740 |
| 4741 // Read the string until we meet a matching quote: |
| 4742 for (pos++; pos < cssLength; pos++) { |
| 4743 // Skip escaped quotes: |
| 4744 if (css.charAt(pos) === '\\') pos++;else if (css.charAt(pos) === q
) break; |
| 4745 } |
| 4746 |
| 4747 // Add the string (including quotes) to tokens: |
| 4748 pushToken(q === '"' ? TokenType.StringDQ : TokenType.StringSQ, css.s
ubstring(start, pos + 1), col); |
| 4749 col += pos - start; |
| 4750 } |
| 4751 |
| 4752 /** |
| 4753 * Parse numbers |
| 4754 * @param {string} css Unparsed part of CSS string |
| 4755 */ |
| 4756 function parseDecimalNumber(css) { |
| 4757 var start = pos; |
| 4758 |
| 4759 // Read the string until we meet a character that's not a digit: |
| 4760 for (; pos < cssLength; pos++) { |
| 4761 if (!isDecimalDigit(css.charAt(pos))) break; |
| 4762 } |
| 4763 |
| 4764 // Add the number to tokens: |
| 4765 pushToken(TokenType.DecimalNumber, css.substring(start, pos--), col)
; |
| 4766 col += pos - start; |
| 4767 } |
| 4768 |
| 4769 /** |
| 4770 * Parse identifier |
| 4771 * @param {string} css Unparsed part of CSS string |
| 4772 */ |
| 4773 function parseIdentifier(css) { |
| 4774 var start = pos; |
| 4775 |
| 4776 // Skip all opening slashes: |
| 4777 while (css.charAt(pos) === '/') { |
| 4778 pos++; |
| 4779 } // Read the string until we meet a punctuation mark: |
| 4780 for (; pos < cssLength; pos++) { |
| 4781 // Skip all '\': |
| 4782 if (css.charAt(pos) === '\\') pos++;else if (Punctuation[css.charA
t(pos)]) break; |
| 4783 } |
| 4784 |
| 4785 var ident = css.substring(start, pos--); |
| 4786 |
| 4787 // Enter url mode if parsed substring is `url`: |
| 4788 urlMode = urlMode || ident === 'url'; |
| 4789 |
| 4790 // Add identifier to tokens: |
| 4791 pushToken(TokenType.Identifier, ident, col); |
| 4792 col += pos - start; |
| 4793 } |
| 4794 |
| 4795 /** |
| 4796 * Parse a multiline comment |
| 4797 * @param {string} css Unparsed part of CSS string |
| 4798 */ |
| 4799 function parseMLComment(css) { |
| 4800 var start = pos; |
| 4801 |
| 4802 // Read the string until we meet `*/`. |
| 4803 // Since we already know first 2 characters (`/*`), start reading |
| 4804 // from `pos + 2`: |
| 4805 for (pos = pos + 2; pos < cssLength; pos++) { |
| 4806 if (css.charAt(pos) === '*' && css.charAt(pos + 1) === '/') { |
| 4807 pos++; |
| 4808 break; |
| 4809 } |
| 4810 } |
| 4811 |
| 4812 // Add full comment (including `/*` and `*/`) to the list of tokens: |
| 4813 var comment = css.substring(start, pos + 1); |
| 4814 pushToken(TokenType.CommentML, comment, col); |
| 4815 |
| 4816 var newlines = comment.split('\n'); |
| 4817 if (newlines.length > 1) { |
| 4818 ln += newlines.length - 1; |
| 4819 col = newlines[newlines.length - 1].length; |
| 4820 } else { |
| 4821 col += pos - start; |
| 4822 } |
| 4823 } |
| 4824 |
| 4825 function parseSLComment(css) { |
| 4826 var start = pos; |
| 4827 |
| 4828 // Read the string until we meet line break. |
| 4829 // Since we already know first 2 characters (`//`), start reading |
| 4830 // from `pos + 2`: |
| 4831 for (pos += 2; pos < cssLength; pos++) { |
| 4832 if (css.charAt(pos) === '\n' || css.charAt(pos) === '\r') { |
| 4833 break; |
| 4834 } |
| 4835 } |
| 4836 |
| 4837 // Add comment (including `//` and line break) to the list of tokens
: |
| 4838 pushToken(TokenType.CommentSL, css.substring(start, pos--), col); |
| 4839 col += pos - start; |
| 4840 } |
| 4841 |
| 4842 /** |
| 4843 * Convert a CSS string to a list of tokens |
| 4844 * @param {string} css CSS string |
| 4845 * @returns {Array} List of tokens |
| 4846 * @private |
| 4847 */ |
| 4848 function getTokens(css) { |
| 4849 var c; // Current character |
| 4850 var cn; // Next character |
| 4851 |
| 4852 cssLength = css.length; |
| 4853 |
| 4854 // Parse string, character by character: |
| 4855 for (pos = 0; pos < cssLength; col++, pos++) { |
| 4856 c = css.charAt(pos); |
| 4857 cn = css.charAt(pos + 1); |
| 4858 |
| 4859 // If we meet `/*`, it's a start of a multiline comment. |
| 4860 // Parse following characters as a multiline comment: |
| 4861 if (c === '/' && cn === '*') { |
| 4862 parseMLComment(css); |
| 4863 } |
| 4864 |
| 4865 // If we meet `//` and it is not a part of url: |
| 4866 else if (!urlMode && c === '/' && cn === '/') { |
| 4867 // If we're currently inside a block, treat `//` as a start |
| 4868 // of identifier. Else treat `//` as a start of a single-line |
| 4869 // comment: |
| 4870 if (blockMode > 0) parseIdentifier(css);else parseSLComment(cs
s); |
| 4871 } |
| 4872 |
| 4873 // If current character is a double or single quote, it's a star
t |
| 4874 // of a string: |
| 4875 else if (c === '"' || c === "'") { |
| 4876 parseString(css, c); |
| 4877 } |
| 4878 |
| 4879 // If current character is a space: |
| 4880 else if (c === ' ') { |
| 4881 parseSpaces(css); |
| 4882 } |
| 4883 |
| 4884 // If current character is a punctuation mark: |
| 4885 else if (Punctuation[c]) { |
| 4886 // Add it to the list of tokens: |
| 4887 pushToken(Punctuation[c], c, col); |
| 4888 if (c === '\n' || c === '\r') { |
| 4889 ln++; |
| 4890 col = 0; |
| 4891 } // Go to next line |
| 4892 else if (c === ')') urlMode = false; // Exit url mode |
| 4893 else if (c === '{') blockMode++; // Enter a block |
| 4894 else if (c === '}') blockMode--; // Exit a block |
| 4895 else if (c === '\t' && tabSize > 1) col += tabSize
- 1; |
| 4896 } |
| 4897 |
| 4898 // If current character is a decimal digit: |
| 4899 else if (isDecimalDigit(c)) { |
| 4900 parseDecimalNumber(css); |
| 4901 } |
| 4902 |
| 4903 // If current character is anything else: |
| 4904 else { |
| 4905 parseIdentifier(css); |
| 4906 } |
| 4907 } |
| 4908 |
| 4909 return tokens; |
| 4910 } |
| 4911 |
| 4912 return getTokens(css); |
| 4913 }; |
| 4914 |
| 4915 /***/ }, |
| 4916 /* 17 */ |
| 4917 /***/ function(module, exports, __webpack_require__) { |
| 4918 |
| 4919 'use strict'; |
| 4920 |
| 4921 exports.__esModule = true; |
| 4922 exports.default = { |
| 4923 mark: __webpack_require__(18), |
| 4924 parse: __webpack_require__(19), |
| 4925 stringify: __webpack_require__(6), |
| 4926 tokenizer: __webpack_require__(20) |
| 4927 }; |
| 4928 module.exports = exports['default']; |
| 4929 |
| 4930 /***/ }, |
| 4931 /* 18 */ |
| 4932 /***/ function(module, exports, __webpack_require__) { |
| 4933 |
| 4934 'use strict'; |
| 4935 |
| 4936 var TokenType = __webpack_require__(13); |
| 4937 |
| 4938 module.exports = function () { |
| 4939 /** |
| 4940 * Mark whitespaces and comments |
| 4941 */ |
| 4942 function markSC(tokens) { |
| 4943 var tokensLength = tokens.length; |
| 4944 var ws = -1; // Flag for whitespaces |
| 4945 var sc = -1; // Flag for whitespaces and comments |
| 4946 var t = void 0; // Current token |
| 4947 |
| 4948 // For every token in the token list, mark spaces and line breaks |
| 4949 // as spaces (set both `ws` and `sc` flags). Mark multiline comments |
| 4950 // with `sc` flag. |
| 4951 // If there are several spaces or tabs or line breaks or multiline |
| 4952 // comments in a row, group them: take the last one's index number |
| 4953 // and save it to the first token in the group as a reference: |
| 4954 // e.g., `ws_last = 7` for a group of whitespaces or `sc_last = 9` |
| 4955 // for a group of whitespaces and comments. |
| 4956 for (var i = 0; i < tokensLength; i++) { |
| 4957 t = tokens[i]; |
| 4958 switch (t.type) { |
| 4959 case TokenType.Space: |
| 4960 case TokenType.Tab: |
| 4961 case TokenType.Newline: |
| 4962 t.ws = true; |
| 4963 t.sc = true; |
| 4964 |
| 4965 if (ws === -1) ws = i; |
| 4966 if (sc === -1) sc = i; |
| 4967 |
| 4968 break; |
| 4969 case TokenType.CommentML: |
| 4970 case TokenType.CommentSL: |
| 4971 if (ws !== -1) { |
| 4972 tokens[ws].ws_last = i - 1; |
| 4973 ws = -1; |
| 4974 } |
| 4975 |
| 4976 t.sc = true; |
| 4977 |
| 4978 break; |
| 4979 default: |
| 4980 if (ws !== -1) { |
| 4981 tokens[ws].ws_last = i - 1; |
| 4982 ws = -1; |
| 4983 } |
| 4984 |
| 4985 if (sc !== -1) { |
| 4986 tokens[sc].sc_last = i - 1; |
| 4987 sc = -1; |
| 4988 } |
| 4989 } |
| 4990 } |
| 4991 |
| 4992 if (ws !== -1) tokens[ws].ws_last = i - 1; |
| 4993 if (sc !== -1) tokens[sc].sc_last = i - 1; |
| 4994 } |
| 4995 |
| 4996 /** |
| 4997 * Pair brackets |
| 4998 */ |
| 4999 function markBrackets(tokens) { |
| 5000 var tokensLength = tokens.length; |
| 5001 var ps = []; // Parentheses |
| 5002 var sbs = []; // Square brackets |
| 5003 var cbs = []; // Curly brackets |
| 5004 var t = void 0; // Current token |
| 5005 |
| 5006 // For every token in the token list, if we meet an opening (left) |
| 5007 // bracket, push its index number to a corresponding array. |
| 5008 // If we then meet a closing (right) bracket, look at the correspond
ing |
| 5009 // array. If there are any elements (records about previously met |
| 5010 // left brackets), take a token of the last left bracket (take |
| 5011 // the last index number from the array and find a token with |
| 5012 // this index number) and save right bracket's index as a reference: |
| 5013 for (var i = 0; i < tokensLength; i++) { |
| 5014 t = tokens[i]; |
| 5015 switch (t.type) { |
| 5016 case TokenType.LeftParenthesis: |
| 5017 ps.push(i); |
| 5018 break; |
| 5019 case TokenType.RightParenthesis: |
| 5020 if (ps.length) { |
| 5021 t.left = ps.pop(); |
| 5022 tokens[t.left].right = i; |
| 5023 } |
| 5024 break; |
| 5025 case TokenType.LeftSquareBracket: |
| 5026 sbs.push(i); |
| 5027 break; |
| 5028 case TokenType.RightSquareBracket: |
| 5029 if (sbs.length) { |
| 5030 t.left = sbs.pop(); |
| 5031 tokens[t.left].right = i; |
| 5032 } |
| 5033 break; |
| 5034 case TokenType.LeftCurlyBracket: |
| 5035 cbs.push(i); |
| 5036 break; |
| 5037 case TokenType.RightCurlyBracket: |
| 5038 if (cbs.length) { |
| 5039 t.left = cbs.pop(); |
| 5040 tokens[t.left].right = i; |
| 5041 } |
| 5042 break; |
| 5043 } |
| 5044 } |
| 5045 } |
| 5046 |
| 5047 return function (tokens) { |
| 5048 markBrackets(tokens); |
| 5049 markSC(tokens); |
| 5050 }; |
| 5051 }(); |
| 5052 |
| 5053 /***/ }, |
| 5054 /* 19 */ |
| 5055 /***/ function(module, exports, __webpack_require__) { |
| 5056 |
| 5057 'use strict'; |
| 5058 |
| 5059 var Node = __webpack_require__(1); |
| 5060 var NodeType = __webpack_require__(15); |
| 5061 var TokenType = __webpack_require__(13); |
| 5062 |
| 5063 var tokens = void 0; |
| 5064 var tokensLength = void 0; |
| 5065 var pos = void 0; |
| 5066 |
| 5067 var contexts = { |
| 5068 'arguments': function _arguments() { |
| 5069 return checkArguments(pos) && getArguments(); |
| 5070 }, |
| 5071 'atkeyword': function atkeyword() { |
| 5072 return checkAtkeyword(pos) && getAtkeyword(); |
| 5073 }, |
| 5074 'atrule': function atrule() { |
| 5075 return checkAtrule(pos) && getAtrule(); |
| 5076 }, |
| 5077 'block': function block() { |
| 5078 return checkBlock(pos) && getBlock(); |
| 5079 }, |
| 5080 'brackets': function brackets() { |
| 5081 return checkBrackets(pos) && getBrackets(); |
| 5082 }, |
| 5083 'class': function _class() { |
| 5084 return checkClass(pos) && getClass(); |
| 5085 }, |
| 5086 'combinator': function combinator() { |
| 5087 return checkCombinator(pos) && getCombinator(); |
| 5088 }, |
| 5089 'commentML': function commentML() { |
| 5090 return checkCommentML(pos) && getCommentML(); |
| 5091 }, |
| 5092 'commentSL': function commentSL() { |
| 5093 return checkCommentSL(pos) && getCommentSL(); |
| 5094 }, |
| 5095 'condition': function condition() { |
| 5096 return checkCondition(pos) && getCondition(); |
| 5097 }, |
| 5098 'conditionalStatement': function conditionalStatement() { |
| 5099 return checkConditionalStatement(pos) && getConditionalStatement(); |
| 5100 }, |
| 5101 'declaration': function declaration() { |
| 5102 return checkDeclaration(pos) && getDeclaration(); |
| 5103 }, |
| 5104 'declDelim': function declDelim() { |
| 5105 return checkDeclDelim(pos) && getDeclDelim(); |
| 5106 }, |
| 5107 'default': function _default() { |
| 5108 return checkDefault(pos) && getDefault(); |
| 5109 }, |
| 5110 'delim': function delim() { |
| 5111 return checkDelim(pos) && getDelim(); |
| 5112 }, |
| 5113 'dimension': function dimension() { |
| 5114 return checkDimension(pos) && getDimension(); |
| 5115 }, |
| 5116 'expression': function expression() { |
| 5117 return checkExpression(pos) && getExpression(); |
| 5118 }, |
| 5119 'extend': function extend() { |
| 5120 return checkExtend(pos) && getExtend(); |
| 5121 }, |
| 5122 'function': function _function() { |
| 5123 return checkFunction(pos) && getFunction(); |
| 5124 }, |
| 5125 'global': function global() { |
| 5126 return checkGlobal(pos) && getGlobal(); |
| 5127 }, |
| 5128 'ident': function ident() { |
| 5129 return checkIdent(pos) && getIdent(); |
| 5130 }, |
| 5131 'important': function important() { |
| 5132 return checkImportant(pos) && getImportant(); |
| 5133 }, |
| 5134 'include': function include() { |
| 5135 return checkInclude(pos) && getInclude(); |
| 5136 }, |
| 5137 'interpolation': function interpolation() { |
| 5138 return checkInterpolation(pos) && getInterpolation(); |
| 5139 }, |
| 5140 'loop': function loop() { |
| 5141 return checkLoop(pos) && getLoop(); |
| 5142 }, |
| 5143 'mixin': function mixin() { |
| 5144 return checkMixin(pos) && getMixin(); |
| 5145 }, |
| 5146 'namespace': function namespace() { |
| 5147 return checkNamespace(pos) && getNamespace(); |
| 5148 }, |
| 5149 'number': function number() { |
| 5150 return checkNumber(pos) && getNumber(); |
| 5151 }, |
| 5152 'operator': function operator() { |
| 5153 return checkOperator(pos) && getOperator(); |
| 5154 }, |
| 5155 'optional': function optional() { |
| 5156 return checkOptional(pos) && getOptional(); |
| 5157 }, |
| 5158 'parentheses': function parentheses() { |
| 5159 return checkParentheses(pos) && getParentheses(); |
| 5160 }, |
| 5161 'parentselector': function parentselector() { |
| 5162 return checkParentSelector(pos) && getParentSelector(); |
| 5163 }, |
| 5164 'percentage': function percentage() { |
| 5165 return checkPercentage(pos) && getPercentage(); |
| 5166 }, |
| 5167 'placeholder': function placeholder() { |
| 5168 return checkPlaceholder(pos) && getPlaceholder(); |
| 5169 }, |
| 5170 'progid': function progid() { |
| 5171 return checkProgid(pos) && getProgid(); |
| 5172 }, |
| 5173 'property': function property() { |
| 5174 return checkProperty(pos) && getProperty(); |
| 5175 }, |
| 5176 'propertyDelim': function propertyDelim() { |
| 5177 return checkPropertyDelim(pos) && getPropertyDelim(); |
| 5178 }, |
| 5179 'pseudoc': function pseudoc() { |
| 5180 return checkPseudoc(pos) && getPseudoc(); |
| 5181 }, |
| 5182 'pseudoe': function pseudoe() { |
| 5183 return checkPseudoe(pos) && getPseudoe(); |
| 5184 }, |
| 5185 'ruleset': function ruleset() { |
| 5186 return checkRuleset(pos) && getRuleset(); |
| 5187 }, |
| 5188 's': function s() { |
| 5189 return checkS(pos) && getS(); |
| 5190 }, |
| 5191 'selector': function selector() { |
| 5192 return checkSelector(pos) && getSelector(); |
| 5193 }, |
| 5194 'shash': function shash() { |
| 5195 return checkShash(pos) && getShash(); |
| 5196 }, |
| 5197 'string': function string() { |
| 5198 return checkString(pos) && getString(); |
| 5199 }, |
| 5200 'stylesheet': function stylesheet() { |
| 5201 return checkStylesheet(pos) && getStylesheet(); |
| 5202 }, |
| 5203 'typeSelector': function typeSelector() { |
| 5204 return checkTypeSelector(pos) && getTypeSelector(); |
| 5205 }, |
| 5206 'unary': function unary() { |
| 5207 return checkUnary(pos) && getUnary(); |
| 5208 }, |
| 5209 'unicodeRange': function unicodeRange() { |
| 5210 return checkUnicodeRange(pos) && getUnicodeRange(); |
| 5211 }, |
| 5212 'universalSelector': function universalSelector() { |
| 5213 return checkUniversalSelector(pos) && getUniversalSelector(); |
| 5214 }, |
| 5215 'urange': function urange() { |
| 5216 return checkUrange(pos) && getUrange(); |
| 5217 }, |
| 5218 'uri': function uri() { |
| 5219 return checkUri(pos) && getUri(); |
| 5220 }, |
| 5221 'value': function value() { |
| 5222 return checkValue(pos) && getValue(); |
| 5223 }, |
| 5224 'variable': function variable() { |
| 5225 return checkVariable(pos) && getVariable(); |
| 5226 }, |
| 5227 'variableslist': function variableslist() { |
| 5228 return checkVariablesList(pos) && getVariablesList(); |
| 5229 }, |
| 5230 'vhash': function vhash() { |
| 5231 return checkVhash(pos) && getVhash(); |
| 5232 } |
| 5233 }; |
| 5234 |
| 5235 /** |
| 1135 * Stop parsing and display error | 5236 * Stop parsing and display error |
| 1136 * @param {Number=} i Token's index number | 5237 * @param {Number=} i Token's index number |
| 1137 » */function throwError(i){var ln=i?tokens[i].ln:tokens[pos].ln;throw {li
ne:ln,syntax:'scss'};} /** | 5238 » */ |
| 1138 » * @param {Object} exclude | 5239 » function throwError(i) { |
| 1139 » * @param {Number} i Token's index number | 5240 » var ln = i ? tokens[i].ln : tokens[pos].ln; |
| 1140 » * @returns {Number} | 5241 |
| 1141 » */function checkExcluding(exclude,i){var start=i;while(i < tokensLength
) {if(exclude[tokens[i++].type])break;}return i - start - 2;} /** | 5242 » throw { line: ln, syntax: 'scss' }; |
| 5243 » } |
| 5244 |
| 5245 » /** |
| 1142 * @param {Number} start | 5246 * @param {Number} start |
| 1143 * @param {Number} finish | 5247 * @param {Number} finish |
| 1144 * @returns {String} | 5248 * @returns {String} |
| 1145 » */function joinValues(start,finish){var s='';for(var i=start;i < finish
+ 1;i++) {s += tokens[i].value;}return s;} /** | 5249 » */ |
| 5250 » function joinValues(start, finish) { |
| 5251 » var s = ''; |
| 5252 |
| 5253 » for (var i = start; i < finish + 1; i++) { |
| 5254 » s += tokens[i].value; |
| 5255 » } |
| 5256 |
| 5257 » return s; |
| 5258 » } |
| 5259 |
| 5260 » /** |
| 1146 * @param {Number} start | 5261 * @param {Number} start |
| 1147 * @param {Number} num | 5262 * @param {Number} num |
| 1148 * @returns {String} | 5263 * @returns {String} |
| 1149 » */function joinValues2(start,num){if(start + num - 1 >= tokensLength)re
turn;var s='';for(var i=0;i < num;i++) {s += tokens[start + i].value;}return s;}
function getLastPosition(content,line,column,colOffset){return typeof content ==
= 'string'?getLastPositionForString(content,line,column,colOffset):getLastPositi
onForArray(content,line,column,colOffset);}function getLastPositionForString(con
tent,line,column,colOffset){var position=[];if(!content){position = [line,column
];if(colOffset)position[1] += colOffset - 1;return position;}var lastLinebreak=c
ontent.lastIndexOf('\n');var endsWithLinebreak=lastLinebreak === content.length
- 1;var splitContent=content.split('\n');var linebreaksCount=splitContent.length
- 1;var prevLinebreak=linebreaksCount === 0 || linebreaksCount === 1?-1:content
.length - splitContent[linebreaksCount - 1].length - 2; // Line: | 5264 » */ |
| 1150 » var offset=endsWithLinebreak?linebreaksCount - 1:linebreaksCount;positio
n[0] = line + offset; // Column: | 5265 » function joinValues2(start, num) { |
| 1151 » if(endsWithLinebreak){offset = prevLinebreak !== -1?content.length - pre
vLinebreak:content.length - 1;}else {offset = linebreaksCount !== 0?content.leng
th - lastLinebreak - column - 1:content.length - 1;}position[1] = column + offse
t;if(!colOffset)return position;if(endsWithLinebreak){position[0]++;position[1]
= colOffset;}else {position[1] += colOffset;}return position;}function getLastPo
sitionForArray(content,line,column,colOffset){var position;if(content.length ===
0){position = [line,column];}else {var c=content[content.length - 1];if(c.hasOw
nProperty('end')){position = [c.end.line,c.end.column];}else {position = getLast
Position(c.content,line,column);}}if(!colOffset)return position;if(tokens[pos -
1].type !== 'Newline'){position[1] += colOffset;}else {position[0]++;position[1]
= 1;}return position;}function newNode(type,content,line,column,end){if(!end)en
d = getLastPosition(content,line,column);return new Node({type:type,content:cont
ent,start:{line:line,column:column},end:{line:end[0],column:end[1]},syntax:'scss
'});} /** | 5266 » if (start + num - 1 >= tokensLength) return; |
| 5267 |
| 5268 » var s = ''; |
| 5269 |
| 5270 » for (var i = 0; i < num; i++) { |
| 5271 » s += tokens[start + i].value; |
| 5272 » } |
| 5273 |
| 5274 » return s; |
| 5275 » } |
| 5276 |
| 5277 » function getLastPosition(content, line, column, colOffset) { |
| 5278 » return typeof content === 'string' ? getLastPositionForString(content,
line, column, colOffset) : getLastPositionForArray(content, line, column, colOf
fset); |
| 5279 » } |
| 5280 |
| 5281 » function getLastPositionForString(content, line, column, colOffset) { |
| 5282 » var position = []; |
| 5283 |
| 5284 » if (!content) { |
| 5285 » position = [line, column]; |
| 5286 » if (colOffset) position[1] += colOffset - 1; |
| 5287 » return position; |
| 5288 » } |
| 5289 |
| 5290 » var lastLinebreak = content.lastIndexOf('\n'); |
| 5291 » var endsWithLinebreak = lastLinebreak === content.length - 1; |
| 5292 » var splitContent = content.split('\n'); |
| 5293 » var linebreaksCount = splitContent.length - 1; |
| 5294 » var prevLinebreak = linebreaksCount === 0 || linebreaksCount === 1 ? -
1 : content.length - splitContent[linebreaksCount - 1].length - 2; |
| 5295 |
| 5296 » // Line: |
| 5297 » var offset = endsWithLinebreak ? linebreaksCount - 1 : linebreaksCount
; |
| 5298 » position[0] = line + offset; |
| 5299 |
| 5300 » // Column: |
| 5301 » if (endsWithLinebreak) { |
| 5302 » offset = prevLinebreak !== -1 ? content.length - prevLinebreak : con
tent.length - 1; |
| 5303 » } else { |
| 5304 » offset = linebreaksCount !== 0 ? content.length - lastLinebreak - co
lumn - 1 : content.length - 1; |
| 5305 » } |
| 5306 » position[1] = column + offset; |
| 5307 |
| 5308 » if (!colOffset) return position; |
| 5309 |
| 5310 » if (endsWithLinebreak) { |
| 5311 » position[0]++; |
| 5312 » position[1] = colOffset; |
| 5313 » } else { |
| 5314 » position[1] += colOffset; |
| 5315 » } |
| 5316 |
| 5317 » return position; |
| 5318 » } |
| 5319 |
| 5320 » function getLastPositionForArray(content, line, column, colOffset) { |
| 5321 » var position; |
| 5322 |
| 5323 » if (content.length === 0) { |
| 5324 » position = [line, column]; |
| 5325 » } else { |
| 5326 » var c = content[content.length - 1]; |
| 5327 » if (c.hasOwnProperty('end')) { |
| 5328 » position = [c.end.line, c.end.column]; |
| 5329 » } else { |
| 5330 » position = getLastPosition(c.content, line, column); |
| 5331 » } |
| 5332 » } |
| 5333 |
| 5334 » if (!colOffset) return position; |
| 5335 |
| 5336 » if (tokens[pos - 1] && tokens[pos - 1].type !== 'Newline') { |
| 5337 » position[1] += colOffset; |
| 5338 » } else { |
| 5339 » position[0]++; |
| 5340 » position[1] = 1; |
| 5341 » } |
| 5342 |
| 5343 » return position; |
| 5344 » } |
| 5345 |
| 5346 » function newNode(type, content, line, column, end) { |
| 5347 » if (!end) end = getLastPosition(content, line, column); |
| 5348 » return new Node({ |
| 5349 » type: type, |
| 5350 » content: content, |
| 5351 » start: { |
| 5352 » line: line, |
| 5353 » column: column |
| 5354 » }, |
| 5355 » end: { |
| 5356 » line: end[0], |
| 5357 » column: end[1] |
| 5358 » }, |
| 5359 » syntax: 'scss' |
| 5360 » }); |
| 5361 » } |
| 5362 |
| 5363 » /** |
| 1152 * @param {Number} i Token's index number | 5364 * @param {Number} i Token's index number |
| 1153 * @returns {Number} | 5365 * @returns {Number} |
| 1154 » */function checkAny(i){return checkBrackets(i) || checkParentheses(i) |
| checkString(i) || checkVariablesList(i) || checkVariable(i) || checkPlaceholde
r(i) || checkPercentage(i) || checkDimension(i) || checkNumber(i) || checkUri(i)
|| checkExpression(i) || checkFunction(i) || checkInterpolation(i) || checkIden
t(i) || checkClass(i) || checkUnary(i);} /** | 5366 » */ |
| 5367 » function checkAny(i) { |
| 5368 » var l = void 0; |
| 5369 |
| 5370 » if (l = checkBrackets(i)) tokens[i].any_type = 1;else if (l = checkPar
entheses(i)) tokens[i].any_type = 2;else if (l = checkString(i)) tokens[i].any_t
ype = 3;else if (l = checkVariablesList(i)) tokens[i].any_type = 4;else if (l =
checkVariable(i)) tokens[i].any_type = 5;else if (l = checkPlaceholder(i)) token
s[i].any_type = 6;else if (l = checkPercentage(i)) tokens[i].any_type = 7;else i
f (l = checkDimension(i)) tokens[i].any_type = 8;else if (l = checkUnicodeRange(
i)) tokens[i].any_type = 9;else if (l = checkNumber(i)) tokens[i].any_type = 10;
else if (l = checkUri(i)) tokens[i].any_type = 11;else if (l = checkExpression(i
)) tokens[i].any_type = 12;else if (l = checkFunction(i)) tokens[i].any_type = 1
3;else if (l = checkInterpolation(i)) tokens[i].any_type = 14;else if (l = check
Ident(i)) tokens[i].any_type = 15;else if (l = checkClass(i)) tokens[i].any_type
= 16;else if (l = checkUnary(i)) tokens[i].any_type = 17; |
| 5371 |
| 5372 » return l; |
| 5373 » } |
| 5374 |
| 5375 » /** |
| 1155 * @returns {Array} | 5376 * @returns {Array} |
| 1156 » */function getAny(){if(checkBrackets(pos))return getBrackets();else if(
checkParentheses(pos))return getParentheses();else if(checkString(pos))return ge
tString();else if(checkVariablesList(pos))return getVariablesList();else if(chec
kVariable(pos))return getVariable();else if(checkPlaceholder(pos))return getPlac
eholder();else if(checkPercentage(pos))return getPercentage();else if(checkDimen
sion(pos))return getDimension();else if(checkNumber(pos))return getNumber();else
if(checkUri(pos))return getUri();else if(checkExpression(pos))return getExpress
ion();else if(checkFunction(pos))return getFunction();else if(checkInterpolation
(pos))return getInterpolation();else if(checkIdent(pos))return getIdent();else i
f(checkClass(pos))return getClass();else if(checkUnary(pos))return getUnary();}
/** | 5377 » */ |
| 5378 » function getAny() { |
| 5379 » var type = tokens[pos].any_type; |
| 5380 |
| 5381 » if (type === 1) return getBrackets(); |
| 5382 » if (type === 2) return getParentheses(); |
| 5383 » if (type === 3) return getString(); |
| 5384 » if (type === 4) return getVariablesList(); |
| 5385 » if (type === 5) return getVariable(); |
| 5386 » if (type === 6) return getPlaceholder(); |
| 5387 » if (type === 7) return getPercentage(); |
| 5388 » if (type === 8) return getDimension(); |
| 5389 » if (type === 9) return getUnicodeRange(); |
| 5390 » if (type === 10) return getNumber(); |
| 5391 » if (type === 11) return getUri(); |
| 5392 » if (type === 12) return getExpression(); |
| 5393 » if (type === 13) return getFunction(); |
| 5394 » if (type === 14) return getInterpolation(); |
| 5395 » if (type === 15) return getIdent(); |
| 5396 » if (type === 16) return getClass(); |
| 5397 » if (type === 17) return getUnary(); |
| 5398 » } |
| 5399 |
| 5400 » /** |
| 1157 * Check if token is part of mixin's arguments. | 5401 * Check if token is part of mixin's arguments. |
| 1158 * @param {Number} i Token's index number | 5402 * @param {Number} i Token's index number |
| 1159 * @returns {Number} Length of arguments | 5403 * @returns {Number} Length of arguments |
| 1160 » */function checkArguments(i){var start=i;var l=undefined;if(i >= tokens
Length || tokens[i].type !== TokenType.LeftParenthesis)return 0;i++;while(i < to
kens[start].right) {if(l = checkArgument(i))i += l;else return 0;}return tokens[
start].right - start + 1;} /** | 5404 » */ |
| 5405 » function checkArguments(i) { |
| 5406 » var start = i; |
| 5407 » var l = void 0; |
| 5408 |
| 5409 » if (i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis)
return 0; |
| 5410 |
| 5411 » i++; |
| 5412 |
| 5413 » while (i < tokens[start].right) { |
| 5414 » if (l = checkArgument(i)) i += l;else return 0; |
| 5415 » } |
| 5416 |
| 5417 » return tokens[start].right - start + 1; |
| 5418 » } |
| 5419 |
| 5420 » /** |
| 1161 * Check if token is valid to be part of arguments list | 5421 * Check if token is valid to be part of arguments list |
| 1162 * @param {Number} i Token's index number | 5422 * @param {Number} i Token's index number |
| 1163 * @returns {Number} Length of argument | 5423 * @returns {Number} Length of argument |
| 1164 » */function checkArgument(i){return checkBrackets(i) || checkParentheses
(i) || checkDeclaration(i) || checkFunction(i) || checkVariablesList(i) || check
Variable(i) || checkSC(i) || checkDelim(i) || checkDeclDelim(i) || checkString(i
) || checkPercentage(i) || checkDimension(i) || checkNumber(i) || checkUri(i) ||
checkInterpolation(i) || checkIdent(i) || checkVhash(i) || checkOperator(i) ||
checkUnary(i);} /** | 5424 » */ |
| 5425 » function checkArgument(i) { |
| 5426 » return checkBrackets(i) || checkParentheses(i) || checkSingleValueDecl
aration(i) || checkFunction(i) || checkVariablesList(i) || checkVariable(i) || c
heckSC(i) || checkDelim(i) || checkDeclDelim(i) || checkString(i) || checkPercen
tage(i) || checkDimension(i) || checkNumber(i) || checkUri(i) || checkInterpolat
ion(i) || checkIdent(i) || checkVhash(i) || checkOperator(i) || checkUnary(i) ||
checkImportant(i) || checkGlobal(i) || checkDefault(i) || checkOptional(i) || c
heckParentSelector(i); |
| 5427 » } |
| 5428 |
| 5429 » /** |
| 1165 * @returns {Array} Node that is part of arguments list | 5430 * @returns {Array} Node that is part of arguments list |
| 1166 » */function getArgument(){if(checkBrackets(pos))return getBrackets();els
e if(checkParentheses(pos))return getParentheses();else if(checkDeclaration(pos)
)return getDeclaration();else if(checkFunction(pos))return getFunction();else if
(checkVariablesList(pos))return getVariablesList();else if(checkVariable(pos))re
turn getVariable();else if(checkSC(pos))return getSC();else if(checkDelim(pos))r
eturn getDelim();else if(checkDeclDelim(pos))return getDeclDelim();else if(check
String(pos))return getString();else if(checkPercentage(pos))return getPercentage
();else if(checkDimension(pos))return getDimension();else if(checkNumber(pos))re
turn getNumber();else if(checkUri(pos))return getUri();else if(checkInterpolatio
n(pos))return getInterpolation();else if(checkIdent(pos))return getIdent();else
if(checkVhash(pos))return getVhash();else if(checkOperator(pos))return getOperat
or();else if(checkUnary(pos))return getUnary();} /** | 5431 » */ |
| 5432 » function getArgument() { |
| 5433 » if (checkBrackets(pos)) return getBrackets();else if (checkParentheses
(pos)) return getParentheses();else if (checkSingleValueDeclaration(pos)) return
getSingleValueDeclaration();else if (checkFunction(pos)) return getFunction();e
lse if (checkVariablesList(pos)) return getVariablesList();else if (checkVariabl
e(pos)) return getVariable();else if (checkSC(pos)) return getSC();else if (chec
kDelim(pos)) return getDelim();else if (checkDeclDelim(pos)) return getDeclDelim
();else if (checkString(pos)) return getString();else if (checkPercentage(pos))
return getPercentage();else if (checkDimension(pos)) return getDimension();else
if (checkNumber(pos)) return getNumber();else if (checkUri(pos)) return getUri()
;else if (checkInterpolation(pos)) return getInterpolation();else if (checkIdent
(pos)) return getIdent();else if (checkVhash(pos)) return getVhash();else if (ch
eckOperator(pos)) return getOperator();else if (checkUnary(pos)) return getUnary
();else if (checkImportant(pos)) return getImportant();else if (checkGlobal(pos)
) return getGlobal();else if (checkDefault(pos)) return getDefault();else if (ch
eckOptional(pos)) return getOptional();else if (checkParentSelector(pos)) return
getParentSelector(); |
| 5434 » } |
| 5435 |
| 5436 » /** |
| 1167 * Check if token is part of an @-word (e.g. `@import`, `@include`) | 5437 * Check if token is part of an @-word (e.g. `@import`, `@include`) |
| 1168 * @param {Number} i Token's index number | 5438 * @param {Number} i Token's index number |
| 1169 * @returns {Number} | 5439 * @returns {Number} |
| 1170 » */function checkAtkeyword(i){var l; // Check that token is `@`: | 5440 » */ |
| 1171 » if(i >= tokensLength || tokens[i++].type !== TokenType.CommercialAt)retu
rn 0;return (l = checkIdentOrInterpolation(i))?l + 1:0;} /** | 5441 » function checkAtkeyword(i) { |
| 5442 » var l; |
| 5443 |
| 5444 » // Check that token is `@`: |
| 5445 » if (i >= tokensLength || tokens[i++].type !== TokenType.CommercialAt)
return 0; |
| 5446 |
| 5447 » return (l = checkIdentOrInterpolation(i)) ? l + 1 : 0; |
| 5448 » } |
| 5449 |
| 5450 » /** |
| 1172 * Get node with @-word | 5451 * Get node with @-word |
| 1173 * @returns {Array} `['atkeyword', ['ident', x]]` where `x` is | 5452 * @returns {Array} `['atkeyword', ['ident', x]]` where `x` is |
| 1174 * an identifier without | 5453 * an identifier without |
| 1175 * `@` (e.g. `import`, `include`) | 5454 * `@` (e.g. `import`, `include`) |
| 1176 » */function getAtkeyword(){var startPos=pos;var x=undefined;pos++;x = ge
tIdentOrInterpolation();var token=tokens[startPos];return newNode(NodeType.Atkey
wordType,x,token.ln,token.col);} /** | 5455 » */ |
| 5456 » function getAtkeyword() { |
| 5457 » var startPos = pos; |
| 5458 » var x = void 0; |
| 5459 |
| 5460 » pos++; |
| 5461 |
| 5462 » x = getIdentOrInterpolation(); |
| 5463 |
| 5464 » var token = tokens[startPos]; |
| 5465 » return newNode(NodeType.AtkeywordType, x, token.ln, token.col); |
| 5466 » } |
| 5467 |
| 5468 » /** |
| 1177 * Check if token is a part of an @-rule | 5469 * Check if token is a part of an @-rule |
| 1178 * @param {Number} i Token's index number | 5470 * @param {Number} i Token's index number |
| 1179 * @returns {Number} Length of @-rule | 5471 * @returns {Number} Length of @-rule |
| 1180 » */function checkAtrule(i){var l;if(i >= tokensLength)return 0; // If to
ken already has a record of being part of an @-rule, | 5472 » */ |
| 1181 » // return the @-rule's length: | 5473 » function checkAtrule(i) { |
| 1182 » if(tokens[i].atrule_l !== undefined)return tokens[i].atrule_l; // If tok
en is part of an @-rule, save the rule's type to token: | 5474 » var l; |
| 1183 » if(l = checkKeyframesRule(i))tokens[i].atrule_type = 4;else if(l = check
Atruler(i))tokens[i].atrule_type = 1; // @-rule with ruleset | 5475 |
| 1184 » else if(l = checkAtruleb(i))tokens[i].atrule_type = 2; // Block @-rule | 5476 » if (i >= tokensLength) return 0; |
| 1185 » else if(l = checkAtrules(i))tokens[i].atrule_type = 3; // Single-line @-
rule | 5477 |
| 1186 » else return 0; // If token is part of an @-rule, save the rule's length
to token: | 5478 » // If token already has a record of being part of an @-rule, |
| 1187 » tokens[i].atrule_l = l;return l;} /** | 5479 » // return the @-rule's length: |
| 5480 » if (tokens[i].atrule_l !== undefined) return tokens[i].atrule_l; |
| 5481 |
| 5482 » // If token is part of an @-rule, save the rule's type to token. |
| 5483 » // @keyframes: |
| 5484 » if (l = checkKeyframesRule(i)) tokens[i].atrule_type = 4; |
| 5485 » // @-rule with ruleset: |
| 5486 » else if (l = checkAtruler(i)) tokens[i].atrule_type = 1; |
| 5487 » // Block @-rule: |
| 5488 » else if (l = checkAtruleb(i)) tokens[i].atrule_type = 2; |
| 5489 » // Single-line @-rule: |
| 5490 » else if (l = checkAtrules(i)) tokens[i].atrule_type = 3;else retur
n 0; |
| 5491 |
| 5492 » // If token is part of an @-rule, save the rule's length to token: |
| 5493 » tokens[i].atrule_l = l; |
| 5494 |
| 5495 » return l; |
| 5496 » } |
| 5497 |
| 5498 » /** |
| 1188 * Get node with @-rule | 5499 * Get node with @-rule |
| 1189 * @returns {Array} | 5500 * @returns {Array} |
| 1190 » */function getAtrule(){switch(tokens[pos].atrule_type){case 1:return ge
tAtruler(); // @-rule with ruleset | 5501 » */ |
| 1191 » case 2:return getAtruleb(); // Block @-rule | 5502 » function getAtrule() { |
| 1192 » case 3:return getAtrules(); // Single-line @-rule | 5503 » switch (tokens[pos].atrule_type) { |
| 1193 » case 4:return getKeyframesRule();}} /** | 5504 » case 1: |
| 5505 » return getAtruler(); // @-rule with ruleset |
| 5506 » case 2: |
| 5507 » return getAtruleb(); // Block @-rule |
| 5508 » case 3: |
| 5509 » return getAtrules(); // Single-line @-rule |
| 5510 » case 4: |
| 5511 » return getKeyframesRule(); |
| 5512 » } |
| 5513 » } |
| 5514 |
| 5515 » /** |
| 1194 * Check if token is part of a block @-rule | 5516 * Check if token is part of a block @-rule |
| 1195 * @param {Number} i Token's index number | 5517 * @param {Number} i Token's index number |
| 1196 * @returns {Number} Length of the @-rule | 5518 * @returns {Number} Length of the @-rule |
| 1197 » */function checkAtruleb(i){var start=i;var l=undefined;if(i >= tokensLe
ngth)return 0;if(l = checkAtkeyword(i))i += l;else return 0;if(l = checkTsets(i)
)i += l;if(l = checkBlock(i))i += l;else return 0;return i - start;} /** | 5519 » */ |
| 5520 » function checkAtruleb(i) { |
| 5521 » var start = i; |
| 5522 » var l = void 0; |
| 5523 |
| 5524 » if (i >= tokensLength) return 0; |
| 5525 |
| 5526 » if (l = checkAtkeyword(i)) i += l;else return 0; |
| 5527 |
| 5528 » if (l = checkTsets(i)) i += l; |
| 5529 |
| 5530 » if (l = checkBlock(i)) i += l;else return 0; |
| 5531 |
| 5532 » return i - start; |
| 5533 » } |
| 5534 |
| 5535 » /** |
| 1198 * Get node with a block @-rule | 5536 * Get node with a block @-rule |
| 1199 * @returns {Array} `['atruleb', ['atkeyword', x], y, ['block', z]]` | 5537 * @returns {Array} `['atruleb', ['atkeyword', x], y, ['block', z]]` |
| 1200 » */function getAtruleb(){var startPos=pos;var x=undefined;x = [getAtkeyw
ord()].concat(getTsets()).concat([getBlock()]);var token=tokens[startPos];return
newNode(NodeType.AtruleType,x,token.ln,token.col);} /** | 5538 » */ |
| 5539 » function getAtruleb() { |
| 5540 » var startPos = pos; |
| 5541 » var x = void 0; |
| 5542 |
| 5543 » x = [getAtkeyword()].concat(getTsets()).concat([getBlock()]); |
| 5544 |
| 5545 » var token = tokens[startPos]; |
| 5546 » return newNode(NodeType.AtruleType, x, token.ln, token.col); |
| 5547 » } |
| 5548 |
| 5549 » /** |
| 1201 * Check if token is part of an @-rule with ruleset | 5550 * Check if token is part of an @-rule with ruleset |
| 1202 * @param {Number} i Token's index number | 5551 * @param {Number} i Token's index number |
| 1203 * @returns {Number} Length of the @-rule | 5552 * @returns {Number} Length of the @-rule |
| 1204 » */function checkAtruler(i){var start=i;var l=undefined;if(i >= tokensLe
ngth)return 0;if(l = checkAtkeyword(i))i += l;else return 0;if(l = checkTsets(i)
)i += l;if(i < tokensLength && tokens[i].type === TokenType.LeftCurlyBracket)i++
;else return 0;if(l = checkAtrulers(i))i += l;if(i < tokensLength && tokens[i].t
ype === TokenType.RightCurlyBracket)i++;else return 0;return i - start;} /** | 5553 » */ |
| 5554 » function checkAtruler(i) { |
| 5555 » var start = i; |
| 5556 » var l = void 0; |
| 5557 |
| 5558 » if (i >= tokensLength) return 0; |
| 5559 |
| 5560 » if (l = checkAtkeyword(i)) i += l;else return 0; |
| 5561 |
| 5562 » if (l = checkTsets(i)) i += l; |
| 5563 |
| 5564 » if (i < tokensLength && tokens[i].type === TokenType.LeftCurlyBracket)
i++;else return 0; |
| 5565 |
| 5566 » if (l = checkAtrulers(i)) i += l; |
| 5567 |
| 5568 » if (i < tokensLength && tokens[i].type === TokenType.RightCurlyBracket
) i++;else return 0; |
| 5569 |
| 5570 » return i - start; |
| 5571 » } |
| 5572 |
| 5573 » /** |
| 1205 * Get node with an @-rule with ruleset | 5574 * Get node with an @-rule with ruleset |
| 1206 * @returns {Array} ['atruler', ['atkeyword', x], y, z] | 5575 * @returns {Array} ['atruler', ['atkeyword', x], y, z] |
| 1207 » */function getAtruler(){var startPos=pos;var x=undefined;x = [getAtkeyw
ord()].concat(getTsets());x.push(getAtrulers());var token=tokens[startPos];retur
n newNode(NodeType.AtruleType,x,token.ln,token.col);} /** | 5576 » */ |
| 5577 » function getAtruler() { |
| 5578 » var startPos = pos; |
| 5579 » var x = void 0; |
| 5580 |
| 5581 » x = [getAtkeyword()].concat(getTsets()); |
| 5582 |
| 5583 » x.push(getAtrulers()); |
| 5584 |
| 5585 » var token = tokens[startPos]; |
| 5586 » return newNode(NodeType.AtruleType, x, token.ln, token.col); |
| 5587 » } |
| 5588 |
| 5589 » /** |
| 1208 * @param {Number} i Token's index number | 5590 * @param {Number} i Token's index number |
| 1209 * @returns {Number} | 5591 * @returns {Number} |
| 1210 » */function checkAtrulers(i){var start=i;var l=undefined;if(i >= tokensL
ength)return 0;while(l = checkRuleset(i) || checkAtrule(i) || checkSC(i)) {i +=
l;}if(i < tokensLength)tokens[i].atrulers_end = 1;return i - start;} /** | 5592 » */ |
| 5593 » function checkAtrulers(i) { |
| 5594 » var start = i; |
| 5595 » var l = void 0; |
| 5596 |
| 5597 » if (i >= tokensLength) return 0; |
| 5598 |
| 5599 » while (l = checkRuleset(i) || checkAtrule(i) || checkSC(i)) { |
| 5600 » i += l; |
| 5601 » } |
| 5602 |
| 5603 » if (i < tokensLength) tokens[i].atrulers_end = 1; |
| 5604 |
| 5605 » return i - start; |
| 5606 » } |
| 5607 |
| 5608 » /** |
| 1211 * @returns {Array} `['atrulers', x]` | 5609 * @returns {Array} `['atrulers', x]` |
| 1212 » */function getAtrulers(){var startPos=pos;var x=undefined;var token=tok
ens[startPos];var line=token.ln;var column=token.col;pos++;x = getSC();while(!to
kens[pos].atrulers_end) {if(checkSC(pos))x = x.concat(getSC());else if(checkAtru
le(pos))x.push(getAtrule());else if(checkRuleset(pos))x.push(getRuleset());}x =
x.concat(getSC());var end=getLastPosition(x,line,column,1);pos++;return newNode(
NodeType.BlockType,x,token.ln,token.col,end);} /** | 5610 » */ |
| 5611 » function getAtrulers() { |
| 5612 » var startPos = pos; |
| 5613 » var x = void 0; |
| 5614 » var token = tokens[startPos]; |
| 5615 » var line = token.ln; |
| 5616 » var column = token.col; |
| 5617 » pos++; |
| 5618 |
| 5619 » x = getSC(); |
| 5620 |
| 5621 » while (!tokens[pos].atrulers_end) { |
| 5622 » if (checkSC(pos)) x = x.concat(getSC());else if (checkAtrule(pos)) x
.push(getAtrule());else if (checkRuleset(pos)) x.push(getRuleset()); |
| 5623 » } |
| 5624 |
| 5625 » x = x.concat(getSC()); |
| 5626 |
| 5627 » var end = getLastPosition(x, line, column, 1); |
| 5628 » pos++; |
| 5629 |
| 5630 » return newNode(NodeType.BlockType, x, token.ln, token.col, end); |
| 5631 » } |
| 5632 |
| 5633 » /** |
| 1213 * @param {Number} i Token's index number | 5634 * @param {Number} i Token's index number |
| 1214 * @returns {Number} | 5635 * @returns {Number} |
| 1215 » */function checkAtrules(i){var start=i;var l=undefined;if(i >= tokensLe
ngth)return 0;if(l = checkAtkeyword(i))i += l;else return 0;if(l = checkTsets(i)
)i += l;return i - start;} /** | 5636 » */ |
| 5637 » function checkAtrules(i) { |
| 5638 » var start = i; |
| 5639 » var l = void 0; |
| 5640 |
| 5641 » if (i >= tokensLength) return 0; |
| 5642 |
| 5643 » if (l = checkAtkeyword(i)) i += l;else return 0; |
| 5644 |
| 5645 » if (l = checkTsets(i)) i += l; |
| 5646 |
| 5647 » return i - start; |
| 5648 » } |
| 5649 |
| 5650 » /** |
| 1216 * @returns {Array} `['atrules', ['atkeyword', x], y]` | 5651 * @returns {Array} `['atrules', ['atkeyword', x], y]` |
| 1217 » */function getAtrules(){var startPos=pos;var x=undefined;x = [getAtkeyw
ord()].concat(getTsets());var token=tokens[startPos];return newNode(NodeType.Atr
uleType,x,token.ln,token.col);} /** | 5652 » */ |
| 5653 » function getAtrules() { |
| 5654 » var startPos = pos; |
| 5655 » var x = void 0; |
| 5656 |
| 5657 » x = [getAtkeyword()].concat(getTsets()); |
| 5658 |
| 5659 » var token = tokens[startPos]; |
| 5660 » return newNode(NodeType.AtruleType, x, token.ln, token.col); |
| 5661 » } |
| 5662 |
| 5663 » /** |
| 1218 * Check if token is part of a block (e.g. `{...}`). | 5664 * Check if token is part of a block (e.g. `{...}`). |
| 1219 * @param {Number} i Token's index number | 5665 * @param {Number} i Token's index number |
| 1220 * @returns {Number} Length of the block | 5666 * @returns {Number} Length of the block |
| 1221 » */function checkBlock(i){return i < tokensLength && tokens[i].type ===
TokenType.LeftCurlyBracket?tokens[i].right - i + 1:0;} /** | 5667 » */ |
| 5668 » function checkBlock(i) { |
| 5669 » return i < tokensLength && tokens[i].type === TokenType.LeftCurlyBrack
et ? tokens[i].right - i + 1 : 0; |
| 5670 » } |
| 5671 |
| 5672 » /** |
| 1222 * Get node with a block | 5673 * Get node with a block |
| 1223 * @returns {Array} `['block', x]` | 5674 * @returns {Array} `['block', x]` |
| 1224 » */function getBlock(){var startPos=pos;var end=tokens[pos].right;var x=
[];var token=tokens[startPos];var line=token.ln;var column=token.col;pos++;while
(pos < end) {if(checkBlockdecl(pos))x = x.concat(getBlockdecl());else throwError
();}var end_=getLastPosition(x,line,column,1);pos = end + 1;return newNode(NodeT
ype.BlockType,x,token.ln,token.col,end_);} /** | 5675 » */ |
| 5676 » function getBlock() { |
| 5677 » var startPos = pos; |
| 5678 » var end = tokens[pos].right; |
| 5679 » var x = []; |
| 5680 » var token = tokens[startPos]; |
| 5681 » var line = token.ln; |
| 5682 » var column = token.col; |
| 5683 |
| 5684 » pos++; |
| 5685 |
| 5686 » while (pos < end) { |
| 5687 » if (checkBlockdecl(pos)) x = x.concat(getBlockdecl());else throwErro
r(); |
| 5688 » } |
| 5689 |
| 5690 » var end_ = getLastPosition(x, line, column, 1); |
| 5691 » pos = end + 1; |
| 5692 |
| 5693 » return newNode(NodeType.BlockType, x, token.ln, token.col, end_); |
| 5694 » } |
| 5695 |
| 5696 » /** |
| 1225 * Check if token is part of a declaration (property-value pair) | 5697 * Check if token is part of a declaration (property-value pair) |
| 1226 * @param {Number} i Token's index number | 5698 * @param {Number} i Token's index number |
| 1227 * @returns {Number} Length of the declaration | 5699 * @returns {Number} Length of the declaration |
| 1228 » */function checkBlockdecl(i){var l;if(i >= tokensLength)return 0;if(l =
checkBlockdecl1(i))tokens[i].bd_type = 1;else if(l = checkBlockdecl2(i))tokens[
i].bd_type = 2;else if(l = checkBlockdecl3(i))tokens[i].bd_type = 3;else if(l =
checkBlockdecl4(i))tokens[i].bd_type = 4;else return 0;return l;} /** | 5700 » */ |
| 5701 » function checkBlockdecl(i) { |
| 5702 » var l; |
| 5703 |
| 5704 » if (i >= tokensLength) return 0; |
| 5705 |
| 5706 » if (l = checkBlockdecl1(i)) tokens[i].bd_type = 1;else if (l = checkBl
ockdecl2(i)) tokens[i].bd_type = 2;else if (l = checkBlockdecl3(i)) tokens[i].bd
_type = 3;else if (l = checkBlockdecl4(i)) tokens[i].bd_type = 4;else return 0; |
| 5707 |
| 5708 » return l; |
| 5709 » } |
| 5710 |
| 5711 » /** |
| 1229 * @returns {Array} | 5712 * @returns {Array} |
| 1230 » */function getBlockdecl(){switch(tokens[pos].bd_type){case 1:return get
Blockdecl1();case 2:return getBlockdecl2();case 3:return getBlockdecl3();case 4:
return getBlockdecl4();}} /** | 5713 » */ |
| 5714 » function getBlockdecl() { |
| 5715 » switch (tokens[pos].bd_type) { |
| 5716 » case 1: |
| 5717 » return getBlockdecl1(); |
| 5718 » case 2: |
| 5719 » return getBlockdecl2(); |
| 5720 » case 3: |
| 5721 » return getBlockdecl3(); |
| 5722 » case 4: |
| 5723 » return getBlockdecl4(); |
| 5724 » } |
| 5725 » } |
| 5726 |
| 5727 » /** |
| 1231 * @param {Number} i Token's index number | 5728 * @param {Number} i Token's index number |
| 1232 * @returns {Number} | 5729 * @returns {Number} |
| 1233 » */function checkBlockdecl1(i){var start=i;var l=undefined;if(l = checkS
C(i))i += l;if(l = checkConditionalStatement(i))tokens[i].bd_kind = 1;else if(l
= checkInclude(i))tokens[i].bd_kind = 2;else if(l = checkExtend(i))tokens[i].bd_
kind = 4;else if(l = checkLoop(i))tokens[i].bd_kind = 3;else if(l = checkAtrule(
i))tokens[i].bd_kind = 6;else if(l = checkRuleset(i))tokens[i].bd_kind = 7;else
if(l = checkDeclaration(i))tokens[i].bd_kind = 5;else return 0;i += l;if(i < tok
ensLength && (l = checkDeclDelim(i)))i += l;else return 0;if(l = checkSC(i))i +=
l;return i - start;} /** | 5730 » */ |
| 5731 » function checkBlockdecl1(i) { |
| 5732 » var start = i; |
| 5733 » var l = void 0; |
| 5734 |
| 5735 » if (l = checkSC(i)) i += l; |
| 5736 |
| 5737 » if (l = checkConditionalStatement(i)) tokens[i].bd_kind = 1;else if (l
= checkInclude(i)) tokens[i].bd_kind = 2;else if (l = checkExtend(i)) tokens[i]
.bd_kind = 4;else if (l = checkLoop(i)) tokens[i].bd_kind = 3;else if (l = check
Atrule(i)) tokens[i].bd_kind = 6;else if (l = checkRuleset(i)) tokens[i].bd_kind
= 7;else if (l = checkDeclaration(i)) tokens[i].bd_kind = 5;else return 0; |
| 5738 |
| 5739 » i += l; |
| 5740 |
| 5741 » if (i < tokensLength && (l = checkDeclDelim(i))) i += l;else return 0; |
| 5742 |
| 5743 » if (l = checkSC(i)) i += l; |
| 5744 |
| 5745 » return i - start; |
| 5746 » } |
| 5747 |
| 5748 » /** |
| 1234 * @returns {Array} | 5749 * @returns {Array} |
| 1235 » */function getBlockdecl1(){var sc=getSC();var x=undefined;switch(tokens
[pos].bd_kind){case 1:x = getConditionalStatement();break;case 2:x = getInclude(
);break;case 3:x = getLoop();break;case 4:x = getExtend();break;case 5:x = getDe
claration();break;case 6:x = getAtrule();break;case 7:x = getRuleset();break;}re
turn sc.concat([x]).concat([getDeclDelim()]).concat(getSC());} /** | 5750 » */ |
| 5751 » function getBlockdecl1() { |
| 5752 » var sc = getSC(); |
| 5753 » var x = void 0; |
| 5754 |
| 5755 » switch (tokens[pos].bd_kind) { |
| 5756 » case 1: |
| 5757 » x = getConditionalStatement(); |
| 5758 » break; |
| 5759 » case 2: |
| 5760 » x = getInclude(); |
| 5761 » break; |
| 5762 » case 3: |
| 5763 » x = getLoop(); |
| 5764 » break; |
| 5765 » case 4: |
| 5766 » x = getExtend(); |
| 5767 » break; |
| 5768 » case 5: |
| 5769 » x = getDeclaration(); |
| 5770 » break; |
| 5771 » case 6: |
| 5772 » x = getAtrule(); |
| 5773 » break; |
| 5774 » case 7: |
| 5775 » x = getRuleset(); |
| 5776 » break; |
| 5777 » } |
| 5778 |
| 5779 » return sc.concat([x]).concat([getDeclDelim()]).concat(getSC()); |
| 5780 » } |
| 5781 |
| 5782 » /** |
| 1236 * @param {Number} i Token's index number | 5783 * @param {Number} i Token's index number |
| 1237 * @returns {Number} | 5784 * @returns {Number} |
| 1238 » */function checkBlockdecl2(i){var start=i;var l=undefined;if(l = checkS
C(i))i += l;if(l = checkConditionalStatement(i))tokens[i].bd_kind = 1;else if(l
= checkInclude(i))tokens[i].bd_kind = 2;else if(l = checkExtend(i))tokens[i].bd_
kind = 4;else if(l = checkMixin(i))tokens[i].bd_kind = 8;else if(l = checkLoop(i
))tokens[i].bd_kind = 3;else if(l = checkAtrule(i))tokens[i].bd_kind = 6;else if
(l = checkRuleset(i))tokens[i].bd_kind = 7;else if(l = checkDeclaration(i))token
s[i].bd_kind = 5;else return 0;i += l;if(l = checkSC(i))i += l;return i - start;
} /** | 5785 » */ |
| 5786 » function checkBlockdecl2(i) { |
| 5787 » var start = i; |
| 5788 » var l = void 0; |
| 5789 |
| 5790 » if (l = checkSC(i)) i += l; |
| 5791 |
| 5792 » if (l = checkConditionalStatement(i)) tokens[i].bd_kind = 1;else if (l
= checkInclude(i)) tokens[i].bd_kind = 2;else if (l = checkExtend(i)) tokens[i]
.bd_kind = 4;else if (l = checkMixin(i)) tokens[i].bd_kind = 8;else if (l = chec
kLoop(i)) tokens[i].bd_kind = 3;else if (l = checkAtrule(i)) tokens[i].bd_kind =
6;else if (l = checkRuleset(i)) tokens[i].bd_kind = 7;else if (l = checkDeclara
tion(i)) tokens[i].bd_kind = 5;else return 0; |
| 5793 |
| 5794 » i += l; |
| 5795 |
| 5796 » if (l = checkSC(i)) i += l; |
| 5797 |
| 5798 » return i - start; |
| 5799 » } |
| 5800 |
| 5801 » /** |
| 1239 * @returns {Array} | 5802 * @returns {Array} |
| 1240 » */function getBlockdecl2(){var sc=getSC();var x=undefined;switch(tokens
[pos].bd_kind){case 1:x = getConditionalStatement();break;case 2:x = getInclude(
);break;case 3:x = getLoop();break;case 4:x = getExtend();break;case 5:x = getDe
claration();break;case 6:x = getAtrule();break;case 7:x = getRuleset();break;cas
e 8:x = getMixin();break;}return sc.concat([x]).concat(getSC());} /** | 5803 » */ |
| 5804 » function getBlockdecl2() { |
| 5805 » var sc = getSC(); |
| 5806 » var x = void 0; |
| 5807 |
| 5808 » switch (tokens[pos].bd_kind) { |
| 5809 » case 1: |
| 5810 » x = getConditionalStatement(); |
| 5811 » break; |
| 5812 » case 2: |
| 5813 » x = getInclude(); |
| 5814 » break; |
| 5815 » case 3: |
| 5816 » x = getLoop(); |
| 5817 » break; |
| 5818 » case 4: |
| 5819 » x = getExtend(); |
| 5820 » break; |
| 5821 » case 5: |
| 5822 » x = getDeclaration(); |
| 5823 » break; |
| 5824 » case 6: |
| 5825 » x = getAtrule(); |
| 5826 » break; |
| 5827 » case 7: |
| 5828 » x = getRuleset(); |
| 5829 » break; |
| 5830 » case 8: |
| 5831 » x = getMixin(); |
| 5832 » break; |
| 5833 » } |
| 5834 |
| 5835 » return sc.concat([x]).concat(getSC()); |
| 5836 » } |
| 5837 |
| 5838 » /** |
| 1241 * @param {Number} i Token's index number | 5839 * @param {Number} i Token's index number |
| 1242 * @returns {Number} | 5840 * @returns {Number} |
| 1243 » */function checkBlockdecl3(i){var start=i;var l=undefined;if(l = checkS
C(i))i += l;if(l = checkDeclDelim(i))i += l;else return 0;if(l = checkSC(i))i +=
l;return i - start;} /** | 5841 » */ |
| 5842 » function checkBlockdecl3(i) { |
| 5843 » var start = i; |
| 5844 » var l = void 0; |
| 5845 |
| 5846 » if (l = checkSC(i)) i += l; |
| 5847 |
| 5848 » if (l = checkDeclDelim(i)) i += l;else return 0; |
| 5849 |
| 5850 » if (l = checkSC(i)) i += l; |
| 5851 |
| 5852 » return i - start; |
| 5853 » } |
| 5854 |
| 5855 » /** |
| 1244 * @returns {Array} `[s0, ['declDelim'], s1]` where `s0` and `s1` are | 5856 * @returns {Array} `[s0, ['declDelim'], s1]` where `s0` and `s1` are |
| 1245 * are optional whitespaces. | 5857 * are optional whitespaces. |
| 1246 » */function getBlockdecl3(){return getSC().concat([getDeclDelim()]).conc
at(getSC());} /** | 5858 » */ |
| 5859 » function getBlockdecl3() { |
| 5860 » return getSC().concat([getDeclDelim()]).concat(getSC()); |
| 5861 » } |
| 5862 |
| 5863 » /** |
| 1247 * @param {Number} i Token's index number | 5864 * @param {Number} i Token's index number |
| 1248 * @returns {Number} | 5865 * @returns {Number} |
| 1249 » */function checkBlockdecl4(i){return checkSC(i);} /** | 5866 » */ |
| 5867 » function checkBlockdecl4(i) { |
| 5868 » return checkSC(i); |
| 5869 » } |
| 5870 |
| 5871 » /** |
| 1250 * @returns {Array} | 5872 * @returns {Array} |
| 1251 » */function getBlockdecl4(){return getSC();} /** | 5873 » */ |
| 5874 » function getBlockdecl4() { |
| 5875 » return getSC(); |
| 5876 » } |
| 5877 |
| 5878 » /** |
| 1252 * Check if token is part of text inside square brackets, e.g. `[1]` | 5879 * Check if token is part of text inside square brackets, e.g. `[1]` |
| 1253 * @param {Number} i Token's index number | 5880 * @param {Number} i Token's index number |
| 1254 * @returns {Number} | 5881 * @returns {Number} |
| 1255 » */function checkBrackets(i){if(i >= tokensLength || tokens[i].type !==
TokenType.LeftSquareBracket)return 0;return tokens[i].right - i + 1;} /** | 5882 » */ |
| 5883 » function checkBrackets(i) { |
| 5884 » if (i >= tokensLength) return 0; |
| 5885 |
| 5886 » var start = i; |
| 5887 |
| 5888 » if (tokens[i].type === TokenType.LeftSquareBracket) i++;else return 0; |
| 5889 |
| 5890 » if (i < tokens[start].right) { |
| 5891 » var l = checkTsets(i); |
| 5892 » if (l) i += l;else return 0; |
| 5893 » } |
| 5894 |
| 5895 » i++; |
| 5896 |
| 5897 » return i - start; |
| 5898 » } |
| 5899 |
| 5900 » /** |
| 1256 * Get node with text inside parentheses or square brackets (e.g. `(1)`) | 5901 * Get node with text inside parentheses or square brackets (e.g. `(1)`) |
| 1257 * @return {Node} | 5902 * @return {Node} |
| 1258 » */function getBrackets(){var startPos=pos;var token=tokens[startPos];va
r line=token.ln;var column=token.col;pos++;var tsets=getTsets();var end=getLastP
osition(tsets,line,column,1);pos++;return newNode(NodeType.BracketsType,tsets,to
ken.ln,token.col,end);} /** | 5903 » */ |
| 5904 » function getBrackets() { |
| 5905 » var startPos = pos; |
| 5906 » var token = tokens[startPos]; |
| 5907 » var line = token.ln; |
| 5908 » var column = token.col; |
| 5909 » var tsets = []; |
| 5910 » var right = token.right; |
| 5911 |
| 5912 » pos++; |
| 5913 |
| 5914 » if (pos < right) { |
| 5915 » tsets = getTsets(); |
| 5916 » } |
| 5917 |
| 5918 » var end = getLastPosition(tsets, line, column, 1); |
| 5919 » pos++; |
| 5920 |
| 5921 » return newNode(NodeType.BracketsType, tsets, token.ln, token.col, end)
; |
| 5922 » } |
| 5923 |
| 5924 » /** |
| 1259 * Check if token is part of a class selector (e.g. `.abc`) | 5925 * Check if token is part of a class selector (e.g. `.abc`) |
| 1260 * @param {Number} i Token's index number | 5926 * @param {Number} i Token's index number |
| 1261 * @returns {Number} Length of the class selector | 5927 * @returns {Number} Length of the class selector |
| 1262 » */function checkClass(i){var start=i;var l=undefined;if(i >= tokensLeng
th)return 0;if(tokens[i].class_l)return tokens[i].class_l;if(tokens[i++].type !=
= TokenType.FullStop)return 0;if(l = checkIdentOrInterpolation(i))i += l;else re
turn 0;return i - start;} /** | 5928 » */ |
| 5929 » function checkClass(i) { |
| 5930 » var start = i; |
| 5931 » var l = void 0; |
| 5932 |
| 5933 » if (i >= tokensLength) return 0; |
| 5934 |
| 5935 » if (tokens[i].class_l) return tokens[i].class_l; |
| 5936 |
| 5937 » if (tokens[i++].type !== TokenType.FullStop) return 0; |
| 5938 |
| 5939 » if (l = checkIdentOrInterpolation(i)) i += l;else return 0; |
| 5940 |
| 5941 » while (i < tokensLength) { |
| 5942 » if (l = checkIdentOrInterpolation(i)) i += l;else break; |
| 5943 » } |
| 5944 |
| 5945 » tokens[start].classEnd = i; |
| 5946 |
| 5947 » return i - start; |
| 5948 » } |
| 5949 |
| 5950 » /** |
| 1263 * Get node with a class selector | 5951 * Get node with a class selector |
| 1264 * @returns {Array} `['class', ['ident', x]]` where x is a class's | 5952 * @returns {Array} `['class', ['ident', x]]` where x is a class's |
| 1265 * identifier (without `.`, e.g. `abc`). | 5953 * identifier (without `.`, e.g. `abc`). |
| 1266 » */function getClass(){var startPos=pos;var x=[];pos++;x = x.concat(getI
dentOrInterpolation());var token=tokens[startPos];return newNode(NodeType.ClassT
ype,x,token.ln,token.col);}function checkCombinator(i){if(i >= tokensLength)retu
rn 0;var l=undefined;if(l = checkCombinator1(i))tokens[i].combinatorType = 1;els
e if(l = checkCombinator2(i))tokens[i].combinatorType = 2;else if(l = checkCombi
nator3(i))tokens[i].combinatorType = 3;return l;}function getCombinator(){var ty
pe=tokens[pos].combinatorType;if(type === 1)return getCombinator1();if(type ===
2)return getCombinator2();if(type === 3)return getCombinator3();} /** | 5954 » */ |
| 5955 » function getClass() { |
| 5956 » var startPos = pos; |
| 5957 » var type = NodeType.ClassType; |
| 5958 » var token = tokens[startPos]; |
| 5959 » var line = token.ln; |
| 5960 » var column = token.col; |
| 5961 » var content = []; |
| 5962 » var end = token.classEnd; |
| 5963 |
| 5964 » // Skip `.` |
| 5965 » pos++; |
| 5966 |
| 5967 » while (pos < end) { |
| 5968 » if (checkIdentOrInterpolation(pos)) { |
| 5969 » content = content.concat(getIdentOrInterpolation()); |
| 5970 » } else break; |
| 5971 » } |
| 5972 |
| 5973 » return newNode(type, content, line, column); |
| 5974 » } |
| 5975 |
| 5976 » function checkCombinator(i) { |
| 5977 » if (i >= tokensLength) return 0; |
| 5978 |
| 5979 » var l = void 0; |
| 5980 » if (l = checkCombinator1(i)) tokens[i].combinatorType = 1;else if (l =
checkCombinator2(i)) tokens[i].combinatorType = 2;else if (l = checkCombinator3
(i)) tokens[i].combinatorType = 3; |
| 5981 |
| 5982 » return l; |
| 5983 » } |
| 5984 |
| 5985 » function getCombinator() { |
| 5986 » var type = tokens[pos].combinatorType; |
| 5987 » if (type === 1) return getCombinator1(); |
| 5988 » if (type === 2) return getCombinator2(); |
| 5989 » if (type === 3) return getCombinator3(); |
| 5990 » } |
| 5991 » /** |
| 1267 * (1) `||` | 5992 * (1) `||` |
| 1268 » */function checkCombinator1(i){if(tokens[i].type === TokenType.Vertical
Line && tokens[i + 1].type === TokenType.VerticalLine)return 2;else return 0;}fu
nction getCombinator1(){var type=NodeType.CombinatorType;var token=tokens[pos];v
ar line=token.ln;var column=token.col;var content='||';pos += 2;return newNode(t
ype,content,line,column);} /** | 5993 » */ |
| 5994 » function checkCombinator1(i) { |
| 5995 » if (tokens[i].type === TokenType.VerticalLine && tokens[i + 1].type ==
= TokenType.VerticalLine) return 2;else return 0; |
| 5996 » } |
| 5997 |
| 5998 » function getCombinator1() { |
| 5999 » var type = NodeType.CombinatorType; |
| 6000 » var token = tokens[pos]; |
| 6001 » var line = token.ln; |
| 6002 » var column = token.col; |
| 6003 » var content = '||'; |
| 6004 |
| 6005 » pos += 2; |
| 6006 » return newNode(type, content, line, column); |
| 6007 » } |
| 6008 |
| 6009 » /** |
| 1269 * (1) `>` | 6010 * (1) `>` |
| 1270 * (2) `+` | 6011 * (2) `+` |
| 1271 * (3) `~` | 6012 * (3) `~` |
| 1272 » */function checkCombinator2(i){var type=tokens[i].type;if(type === Toke
nType.PlusSign || type === TokenType.GreaterThanSign || type === TokenType.Tilde
)return 1;else return 0;}function getCombinator2(){var type=NodeType.CombinatorT
ype;var token=tokens[pos];var line=token.ln;var column=token.col;var content=tok
ens[pos++].value;return newNode(type,content,line,column);} /** | 6013 » */ |
| 6014 » function checkCombinator2(i) { |
| 6015 » var type = tokens[i].type; |
| 6016 » if (type === TokenType.PlusSign || type === TokenType.GreaterThanSign
|| type === TokenType.Tilde) return 1;else return 0; |
| 6017 » } |
| 6018 |
| 6019 » function getCombinator2() { |
| 6020 » var type = NodeType.CombinatorType; |
| 6021 » var token = tokens[pos]; |
| 6022 » var line = token.ln; |
| 6023 » var column = token.col; |
| 6024 » var content = tokens[pos++].value; |
| 6025 |
| 6026 » return newNode(type, content, line, column); |
| 6027 » } |
| 6028 |
| 6029 » /** |
| 1273 * (1) `/panda/` | 6030 * (1) `/panda/` |
| 1274 » */function checkCombinator3(i){var start=i;if(tokens[i].type === TokenT
ype.Solidus)i++;else return 0;var l=undefined;if(l = checkIdent(i))i += l;else r
eturn 0;if(tokens[i].type === TokenType.Solidus)i++;else return 0;return i - sta
rt;}function getCombinator3(){var type=NodeType.CombinatorType;var token=tokens[
pos];var line=token.ln;var column=token.col; // Skip `/`. | 6031 » */ |
| 1275 » pos++;var ident=getIdent(); // Skip `/`. | 6032 » function checkCombinator3(i) { |
| 1276 » pos++;var content='/' + ident.content + '/';return newNode(type,content,
line,column);} /** | 6033 » var start = i; |
| 6034 |
| 6035 » if (tokens[i].type === TokenType.Solidus) i++;else return 0; |
| 6036 |
| 6037 » var l = void 0; |
| 6038 » if (l = checkIdent(i)) i += l;else return 0; |
| 6039 |
| 6040 » if (tokens[i].type === TokenType.Solidus) i++;else return 0; |
| 6041 |
| 6042 » return i - start; |
| 6043 » } |
| 6044 |
| 6045 » function getCombinator3() { |
| 6046 » var type = NodeType.CombinatorType; |
| 6047 » var token = tokens[pos]; |
| 6048 » var line = token.ln; |
| 6049 » var column = token.col; |
| 6050 |
| 6051 » // Skip `/`. |
| 6052 » pos++; |
| 6053 » var ident = getIdent(); |
| 6054 |
| 6055 » // Skip `/`. |
| 6056 » pos++; |
| 6057 |
| 6058 » var content = '/' + ident.content + '/'; |
| 6059 |
| 6060 » return newNode(type, content, line, column); |
| 6061 » } |
| 6062 |
| 6063 » /** |
| 1277 * Check if token is a multiline comment. | 6064 * Check if token is a multiline comment. |
| 1278 * @param {Number} i Token's index number | 6065 * @param {Number} i Token's index number |
| 1279 * @returns {Number} `1` if token is a multiline comment, otherwise `0` | 6066 * @returns {Number} `1` if token is a multiline comment, otherwise `0` |
| 1280 » */function checkCommentML(i){return i < tokensLength && tokens[i].type
=== TokenType.CommentML?1:0;} /** | 6067 » */ |
| 6068 » function checkCommentML(i) { |
| 6069 » return i < tokensLength && tokens[i].type === TokenType.CommentML ? 1
: 0; |
| 6070 » } |
| 6071 |
| 6072 » /** |
| 1281 * Get node with a multiline comment | 6073 * Get node with a multiline comment |
| 1282 * @returns {Array} `['commentML', x]` where `x` | 6074 * @returns {Array} `['commentML', x]` where `x` |
| 1283 * is the comment's text (without `/*` and `* /`). | 6075 * is the comment's text (without `/*` and `* /`). |
| 1284 » */function getCommentML(){var startPos=pos;var s=tokens[pos].value.subs
tring(2);var l=s.length;var token=tokens[startPos];var line=token.ln;var column=
token.col;if(s.charAt(l - 2) === '*' && s.charAt(l - 1) === '/')s = s.substring(
0,l - 2);var end=getLastPosition(s,line,column,2);if(end[0] === line)end[1] += 2
;pos++;return newNode(NodeType.CommentMLType,s,token.ln,token.col,end);} /** | 6076 » */ |
| 6077 » function getCommentML() { |
| 6078 » var startPos = pos; |
| 6079 » var s = tokens[pos].value.substring(2); |
| 6080 » var l = s.length; |
| 6081 » var token = tokens[startPos]; |
| 6082 » var line = token.ln; |
| 6083 » var column = token.col; |
| 6084 |
| 6085 » if (s.charAt(l - 2) === '*' && s.charAt(l - 1) === '/') s = s.substrin
g(0, l - 2); |
| 6086 |
| 6087 » var end = getLastPosition(s, line, column, 2); |
| 6088 » if (end[0] === line) end[1] += 2; |
| 6089 » pos++; |
| 6090 |
| 6091 » return newNode(NodeType.CommentMLType, s, token.ln, token.col, end); |
| 6092 » } |
| 6093 |
| 6094 » /** |
| 1285 * Check if token is part of a single-line comment. | 6095 * Check if token is part of a single-line comment. |
| 1286 * @param {Number} i Token's index number | 6096 * @param {Number} i Token's index number |
| 1287 * @returns {Number} `1` if token is a single-line comment, otherwise `0
` | 6097 * @returns {Number} `1` if token is a single-line comment, otherwise `0
` |
| 1288 » */function checkCommentSL(i){return i < tokensLength && tokens[i].type
=== TokenType.CommentSL?1:0;} /** | 6098 » */ |
| 6099 » function checkCommentSL(i) { |
| 6100 » return i < tokensLength && tokens[i].type === TokenType.CommentSL ? 1
: 0; |
| 6101 » } |
| 6102 |
| 6103 » /** |
| 1289 * Get node with a single-line comment. | 6104 * Get node with a single-line comment. |
| 1290 * @returns {Array} `['commentSL', x]` where `x` is comment's message | 6105 * @returns {Array} `['commentSL', x]` where `x` is comment's message |
| 1291 * (without `//`) | 6106 * (without `//`) |
| 1292 » */function getCommentSL(){var startPos=pos;var x=undefined;var token=to
kens[startPos];var line=token.ln;var column=token.col;x = tokens[pos++].value.su
bstring(2);var end=getLastPosition(x,line,column + 2);return newNode(NodeType.Co
mmentSLType,x,token.ln,token.col,end);} /** | 6107 » */ |
| 6108 » function getCommentSL() { |
| 6109 » var startPos = pos; |
| 6110 » var x = void 0; |
| 6111 » var token = tokens[startPos]; |
| 6112 » var line = token.ln; |
| 6113 » var column = token.col; |
| 6114 |
| 6115 » x = tokens[pos++].value.substring(2); |
| 6116 » var end = getLastPosition(x, line, column + 2); |
| 6117 |
| 6118 » return newNode(NodeType.CommentSLType, x, token.ln, token.col, end); |
| 6119 » } |
| 6120 |
| 6121 » /** |
| 1293 * Check if token is part of a condition | 6122 * Check if token is part of a condition |
| 1294 * (e.g. `@if ...`, `@else if ...` or `@else ...`). | 6123 * (e.g. `@if ...`, `@else if ...` or `@else ...`). |
| 1295 * @param {Number} i Token's index number | 6124 * @param {Number} i Token's index number |
| 1296 * @returns {Number} Length of the condition | 6125 * @returns {Number} Length of the condition |
| 1297 » */function checkCondition(i){var start=i;var l=undefined;var _i=undefin
ed;var s=undefined;if(i >= tokensLength)return 0;if(l = checkAtkeyword(i))i += l
;else return 0;if(['if','else'].indexOf(tokens[start + 1].value) < 0)return 0;wh
ile(i < tokensLength) {if(l = checkBlock(i))break;s = checkSC(i);_i = i + s;if(l
= _checkCondition(_i))i += l + s;else break;}return i - start;}function _checkC
ondition(i){return checkVariable(i) || checkNumber(i) || checkInterpolation(i) |
| checkIdent(i) || checkOperator(i) || checkCombinator(i) || checkString(i);} /*
* | 6126 » */ |
| 6127 » function checkCondition(i) { |
| 6128 » var start = i; |
| 6129 » var l = void 0; |
| 6130 » var _i = void 0; |
| 6131 » var s = void 0; |
| 6132 |
| 6133 » if (i >= tokensLength) return 0; |
| 6134 |
| 6135 » if (l = checkAtkeyword(i)) i += l;else return 0; |
| 6136 |
| 6137 » if (['if', 'else'].indexOf(tokens[start + 1].value) < 0) return 0; |
| 6138 |
| 6139 » while (i < tokensLength) { |
| 6140 » if (l = checkBlock(i)) break; |
| 6141 |
| 6142 » s = checkSC(i); |
| 6143 » _i = i + s; |
| 6144 |
| 6145 » if (l = _checkCondition(_i)) i += l + s;else break; |
| 6146 » } |
| 6147 |
| 6148 » return i - start; |
| 6149 » } |
| 6150 |
| 6151 » function _checkCondition(i) { |
| 6152 » return checkVariable(i) || checkNumber(i) || checkInterpolation(i) ||
checkIdent(i) || checkOperator(i) || checkCombinator(i) || checkString(i); |
| 6153 » } |
| 6154 |
| 6155 » /** |
| 1298 * Get node with a condition. | 6156 * Get node with a condition. |
| 1299 * @returns {Array} `['condition', x]` | 6157 * @returns {Array} `['condition', x]` |
| 1300 » */function getCondition(){var startPos=pos;var x=[];var s;var _pos;x.pu
sh(getAtkeyword());while(pos < tokensLength) {if(checkBlock(pos))break;s = check
SC(pos);_pos = pos + s;if(!_checkCondition(_pos))break;if(s)x = x.concat(getSC()
);x.push(_getCondition());}var token=tokens[startPos];return newNode(NodeType.Co
nditionType,x,token.ln,token.col);}function _getCondition(){if(checkVariable(pos
))return getVariable();if(checkNumber(pos))return getNumber();if(checkInterpolat
ion(pos))return getInterpolation();if(checkIdent(pos))return getIdent();if(check
Operator(pos))return getOperator();if(checkCombinator(pos))return getCombinator(
);if(checkString(pos))return getString();} /** | 6158 » */ |
| 6159 » function getCondition() { |
| 6160 » var startPos = pos; |
| 6161 » var x = []; |
| 6162 » var s; |
| 6163 » var _pos; |
| 6164 |
| 6165 » x.push(getAtkeyword()); |
| 6166 |
| 6167 » while (pos < tokensLength) { |
| 6168 » if (checkBlock(pos)) break; |
| 6169 |
| 6170 » s = checkSC(pos); |
| 6171 » _pos = pos + s; |
| 6172 |
| 6173 » if (!_checkCondition(_pos)) break; |
| 6174 |
| 6175 » if (s) x = x.concat(getSC()); |
| 6176 » x.push(_getCondition()); |
| 6177 » } |
| 6178 |
| 6179 » var token = tokens[startPos]; |
| 6180 » return newNode(NodeType.ConditionType, x, token.ln, token.col); |
| 6181 » } |
| 6182 |
| 6183 » function _getCondition() { |
| 6184 » if (checkVariable(pos)) return getVariable(); |
| 6185 » if (checkNumber(pos)) return getNumber(); |
| 6186 » if (checkInterpolation(pos)) return getInterpolation(); |
| 6187 » if (checkIdent(pos)) return getIdent(); |
| 6188 » if (checkOperator(pos)) return getOperator(); |
| 6189 » if (checkCombinator(pos)) return getCombinator(); |
| 6190 » if (checkString(pos)) return getString(); |
| 6191 » } |
| 6192 |
| 6193 » /** |
| 1301 * Check if token is part of a conditional statement | 6194 * Check if token is part of a conditional statement |
| 1302 * (e.g. `@if ... {} @else if ... {} @else ... {}`). | 6195 * (e.g. `@if ... {} @else if ... {} @else ... {}`). |
| 1303 * @param {Number} i Token's index number | 6196 * @param {Number} i Token's index number |
| 1304 * @returns {Number} Length of the condition | 6197 * @returns {Number} Length of the condition |
| 1305 » */function checkConditionalStatement(i){var start=i;var l=undefined;if(
i >= tokensLength)return 0;if(l = checkCondition(i))i += l;else return 0;if(l =
checkSC(i))i += l;if(l = checkBlock(i))i += l;else return 0;return i - start;} /
** | 6198 » */ |
| 6199 » function checkConditionalStatement(i) { |
| 6200 » var start = i; |
| 6201 » var l = void 0; |
| 6202 |
| 6203 » if (i >= tokensLength) return 0; |
| 6204 |
| 6205 » if (l = checkCondition(i)) i += l;else return 0; |
| 6206 |
| 6207 » if (l = checkSC(i)) i += l; |
| 6208 |
| 6209 » if (l = checkBlock(i)) i += l;else return 0; |
| 6210 |
| 6211 » return i - start; |
| 6212 » } |
| 6213 |
| 6214 » /** |
| 1306 * Get node with a condition. | 6215 * Get node with a condition. |
| 1307 * @returns {Array} `['condition', x]` | 6216 * @returns {Array} `['condition', x]` |
| 1308 » */function getConditionalStatement(){var startPos=pos;var x=[];x.push(g
etCondition());x = x.concat(getSC());x.push(getBlock());var token=tokens[startPo
s];return newNode(NodeType.ConditionalStatementType,x,token.ln,token.col);} /** | 6217 » */ |
| 6218 » function getConditionalStatement() { |
| 6219 » var startPos = pos; |
| 6220 » var x = []; |
| 6221 |
| 6222 » x.push(getCondition()); |
| 6223 » x = x.concat(getSC()); |
| 6224 » x.push(getBlock()); |
| 6225 |
| 6226 » var token = tokens[startPos]; |
| 6227 » return newNode(NodeType.ConditionalStatementType, x, token.ln, token.c
ol); |
| 6228 » } |
| 6229 |
| 6230 » /** |
| 1309 * Check if token is part of a declaration (property-value pair) | 6231 * Check if token is part of a declaration (property-value pair) |
| 1310 * @param {Number} i Token's index number | 6232 * @param {Number} i Token's index number |
| 1311 * @returns {Number} Length of the declaration | 6233 * @returns {Number} Length of the declaration |
| 1312 » */function checkDeclaration(i){var start=i;var l=undefined;if(i >= toke
nsLength)return 0;if(l = checkProperty(i))i += l;else return 0;if(l = checkSC(i)
)i += l;if(l = checkPropertyDelim(i))i++;else return 0;if(l = checkSC(i))i += l;
if(l = checkValue(i))i += l;else return 0;return i - start;} /** | 6234 » */ |
| 6235 » function checkDeclaration(i) { |
| 6236 » var start = i; |
| 6237 » var l = void 0; |
| 6238 |
| 6239 » if (i >= tokensLength) return 0; |
| 6240 |
| 6241 » if (l = checkProperty(i)) i += l;else return 0; |
| 6242 |
| 6243 » if (l = checkSC(i)) i += l; |
| 6244 |
| 6245 » if (l = checkPropertyDelim(i)) i++;else return 0; |
| 6246 |
| 6247 » if (l = checkSC(i)) i += l; |
| 6248 |
| 6249 » if (l = checkValue(i)) i += l;else return 0; |
| 6250 |
| 6251 » return i - start; |
| 6252 » } |
| 6253 |
| 6254 » /** |
| 1313 * Get node with a declaration | 6255 * Get node with a declaration |
| 1314 * @returns {Array} `['declaration', ['property', x], ['propertyDelim'], | 6256 * @returns {Array} `['declaration', ['property', x], ['propertyDelim'], |
| 1315 * ['value', y]]` | 6257 * ['value', y]]` |
| 1316 » */function getDeclaration(){var startPos=pos;var x=[];x.push(getPropert
y());x = x.concat(getSC());x.push(getPropertyDelim());x = x.concat(getSC());x.pu
sh(getValue());var token=tokens[startPos];return newNode(NodeType.DeclarationTyp
e,x,token.ln,token.col);} /** | 6258 » */ |
| 6259 » function getDeclaration() { |
| 6260 » var startPos = pos; |
| 6261 » var x = []; |
| 6262 |
| 6263 » x.push(getProperty()); |
| 6264 » x = x.concat(getSC()); |
| 6265 » x.push(getPropertyDelim()); |
| 6266 » x = x.concat(getSC()); |
| 6267 » x.push(getValue()); |
| 6268 |
| 6269 » var token = tokens[startPos]; |
| 6270 » return newNode(NodeType.DeclarationType, x, token.ln, token.col); |
| 6271 » } |
| 6272 |
| 6273 » /** |
| 6274 » * @param {number} i Token's index number |
| 6275 » * @returns {number} Length of the declaration |
| 6276 » */ |
| 6277 » function checkSingleValueDeclaration(i) { |
| 6278 » var start = i; |
| 6279 » var l = void 0; |
| 6280 |
| 6281 » if (i >= tokensLength) return 0; |
| 6282 |
| 6283 » if (l = checkProperty(i)) i += l;else return 0; |
| 6284 |
| 6285 » if (l = checkSC(i)) i += l; |
| 6286 |
| 6287 » if (l = checkPropertyDelim(i)) i++;else return 0; |
| 6288 |
| 6289 » if (l = checkSC(i)) i += l; |
| 6290 |
| 6291 » if (l = checkSingleValue(i)) i += l;else return 0; |
| 6292 |
| 6293 » return i - start; |
| 6294 » } |
| 6295 |
| 6296 » /** |
| 6297 » * Get node with a declaration |
| 6298 » * @returns {Array} `['declaration', ['property', x], ['propertyDelim'], |
| 6299 » * ['value', y]]` |
| 6300 » */ |
| 6301 » function getSingleValueDeclaration() { |
| 6302 » var startPos = pos; |
| 6303 » var x = []; |
| 6304 |
| 6305 » x.push(getProperty()); |
| 6306 » x = x.concat(getSC()); |
| 6307 » x.push(getPropertyDelim()); |
| 6308 » x = x.concat(getSC()); |
| 6309 » x.push(getSingleValue()); |
| 6310 |
| 6311 » var token = tokens[startPos]; |
| 6312 » return newNode(NodeType.DeclarationType, x, token.ln, token.col); |
| 6313 » } |
| 6314 |
| 6315 » /** |
| 1317 * Check if token is a semicolon | 6316 * Check if token is a semicolon |
| 1318 * @param {Number} i Token's index number | 6317 * @param {Number} i Token's index number |
| 1319 * @returns {Number} `1` if token is a semicolon, otherwise `0` | 6318 * @returns {Number} `1` if token is a semicolon, otherwise `0` |
| 1320 » */function checkDeclDelim(i){return i < tokensLength && tokens[i].type
=== TokenType.Semicolon?1:0;} /** | 6319 » */ |
| 6320 » function checkDeclDelim(i) { |
| 6321 » return i < tokensLength && tokens[i].type === TokenType.Semicolon ? 1
: 0; |
| 6322 » } |
| 6323 |
| 6324 » /** |
| 1321 * Get node with a semicolon | 6325 * Get node with a semicolon |
| 1322 * @returns {Array} `['declDelim']` | 6326 * @returns {Array} `['declDelim']` |
| 1323 » */function getDeclDelim(){var startPos=pos++;var token=tokens[startPos]
;return newNode(NodeType.DeclDelimType,';',token.ln,token.col);} /** | 6327 » */ |
| 6328 » function getDeclDelim() { |
| 6329 » var startPos = pos++; |
| 6330 |
| 6331 » var token = tokens[startPos]; |
| 6332 » return newNode(NodeType.DeclDelimType, ';', token.ln, token.col); |
| 6333 » } |
| 6334 |
| 6335 » /** |
| 1324 * Check if token if part of `!default` word. | 6336 * Check if token if part of `!default` word. |
| 1325 * @param {Number} i Token's index number | 6337 * @param {Number} i Token's index number |
| 1326 * @returns {Number} Length of the `!default` word | 6338 * @returns {Number} Length of the `!default` word |
| 1327 » */function checkDefault(i){var start=i;var l=undefined;if(i >= tokensLe
ngth || tokens[i++].type !== TokenType.ExclamationMark)return 0;if(l = checkSC(i
))i += l;if(tokens[i].value === 'default'){tokens[start].defaultEnd = i;return i
- start + 1;}else {return 0;}} /** | 6339 » */ |
| 6340 » function checkDefault(i) { |
| 6341 » var start = i; |
| 6342 » var l = void 0; |
| 6343 |
| 6344 » if (i >= tokensLength || tokens[i++].type !== TokenType.ExclamationMar
k) return 0; |
| 6345 |
| 6346 » if (l = checkSC(i)) i += l; |
| 6347 |
| 6348 » if (tokens[i].value === 'default') { |
| 6349 » tokens[start].defaultEnd = i; |
| 6350 » return i - start + 1; |
| 6351 » } else { |
| 6352 » return 0; |
| 6353 » } |
| 6354 » } |
| 6355 |
| 6356 » /** |
| 1328 * Get node with a `!default` word | 6357 * Get node with a `!default` word |
| 1329 * @returns {Array} `['default', sc]` where `sc` is optional whitespace | 6358 * @returns {Array} `['default', sc]` where `sc` is optional whitespace |
| 1330 » */function getDefault(){var token=tokens[pos];var line=token.ln;var col
umn=token.col;var content=joinValues(pos,token.defaultEnd);pos = token.defaultEn
d + 1;return newNode(NodeType.DefaultType,content,line,column);} /** | 6359 » */ |
| 6360 » function getDefault() { |
| 6361 » var token = tokens[pos]; |
| 6362 » var line = token.ln; |
| 6363 » var column = token.col; |
| 6364 » var content = joinValues(pos, token.defaultEnd); |
| 6365 |
| 6366 » pos = token.defaultEnd + 1; |
| 6367 |
| 6368 » return newNode(NodeType.DefaultType, content, line, column); |
| 6369 » } |
| 6370 |
| 6371 » /** |
| 1331 * Check if token is a comma | 6372 * Check if token is a comma |
| 1332 * @param {Number} i Token's index number | 6373 * @param {Number} i Token's index number |
| 1333 * @returns {Number} `1` if token is a comma, otherwise `0` | 6374 * @returns {Number} `1` if token is a comma, otherwise `0` |
| 1334 » */function checkDelim(i){return i < tokensLength && tokens[i].type ===
TokenType.Comma?1:0;} /** | 6375 » */ |
| 6376 » function checkDelim(i) { |
| 6377 » return i < tokensLength && tokens[i].type === TokenType.Comma ? 1 : 0; |
| 6378 » } |
| 6379 |
| 6380 » /** |
| 1335 * Get node with a comma | 6381 * Get node with a comma |
| 1336 * @returns {Array} `['delim']` | 6382 * @returns {Array} `['delim']` |
| 1337 » */function getDelim(){var startPos=pos;pos++;var token=tokens[startPos]
;return newNode(NodeType.DelimType,',',token.ln,token.col);} /** | 6383 » */ |
| 6384 » function getDelim() { |
| 6385 » var startPos = pos; |
| 6386 |
| 6387 » pos++; |
| 6388 |
| 6389 » var token = tokens[startPos]; |
| 6390 » return newNode(NodeType.DelimType, ',', token.ln, token.col); |
| 6391 » } |
| 6392 |
| 6393 » /** |
| 1338 * Check if token is part of a number with dimension unit (e.g. `10px`) | 6394 * Check if token is part of a number with dimension unit (e.g. `10px`) |
| 1339 * @param {Number} i Token's index number | 6395 * @param {Number} i Token's index number |
| 6396 * @return {Number} |
| 6397 */ |
| 6398 function checkDimension(i) { |
| 6399 var ln = checkNumber(i); |
| 6400 var li = void 0; |
| 6401 |
| 6402 if (i >= tokensLength || !ln || i + ln >= tokensLength) return 0; |
| 6403 |
| 6404 return (li = checkUnit(i + ln)) ? ln + li : 0; |
| 6405 } |
| 6406 |
| 6407 /** |
| 6408 * Get node of a number with dimension unit |
| 6409 * @return {Node} |
| 6410 */ |
| 6411 function getDimension() { |
| 6412 var type = NodeType.DimensionType; |
| 6413 var token = tokens[pos]; |
| 6414 var line = token.ln; |
| 6415 var column = token.col; |
| 6416 var content = [getNumber(), getUnit()]; |
| 6417 |
| 6418 return newNode(type, content, line, column); |
| 6419 } |
| 6420 |
| 6421 /** |
| 6422 * Check if token is unit |
| 6423 * @param {Number} i Token's index number |
| 6424 * @return {Number} |
| 6425 */ |
| 6426 function checkUnit(i) { |
| 6427 var units = ['em', 'ex', 'ch', 'rem', 'vh', 'vw', 'vmin', 'vmax', 'px'
, 'mm', 'q', 'cm', 'in', 'pt', 'pc', 'deg', 'grad', 'rad', 'turn', 's', 'ms', 'H
z', 'kHz', 'dpi', 'dpcm', 'dppx']; |
| 6428 |
| 6429 return units.indexOf(tokens[i].value) !== -1 ? 1 : 0; |
| 6430 } |
| 6431 |
| 6432 /** |
| 6433 * Get unit node of type ident |
| 6434 * @return {Node} An ident node containing the unit value |
| 6435 */ |
| 6436 function getUnit() { |
| 6437 var type = NodeType.IdentType; |
| 6438 var token = tokens[pos]; |
| 6439 var line = token.ln; |
| 6440 var column = token.col; |
| 6441 var content = token.value; |
| 6442 |
| 6443 pos++; |
| 6444 |
| 6445 return newNode(type, content, line, column); |
| 6446 } |
| 6447 |
| 6448 /** |
| 6449 * @param {Number} i Token's index number |
| 1340 * @returns {Number} | 6450 * @returns {Number} |
| 1341 » */function checkDimension(i){var ln=checkNumber(i);var li=undefined;if(
i >= tokensLength || !ln || i + ln >= tokensLength)return 0;return (li = checkNm
Name2(i + ln))?ln + li:0;} /** | 6451 » */ |
| 1342 » * Get node of a number with dimension unit | 6452 » function checkExpression(i) { |
| 1343 » * @returns {Array} `['dimension', ['number', x], ['ident', y]]` where | 6453 » var start = i; |
| 1344 » * `x` is a number converted to string (e.g. `'10'`) and `y` is | 6454 |
| 1345 » * a dimension unit (e.g. `'px'`). | 6455 » if (i >= tokensLength || tokens[i++].value !== 'expression' || i >= to
kensLength || tokens[i].type !== TokenType.LeftParenthesis) return 0; |
| 1346 » */function getDimension(){var startPos=pos;var x=[getNumber()];var toke
n=tokens[pos];var ident=newNode(NodeType.IdentType,getNmName2(),token.ln,token.c
ol);x.push(ident);token = tokens[startPos];return newNode(NodeType.DimensionType
,x,token.ln,token.col);} /** | 6456 |
| 1347 » * @param {Number} i Token's index number | 6457 » return tokens[i].right - start + 1; |
| 1348 » * @returns {Number} | 6458 » } |
| 1349 » */function checkExpression(i){var start=i;if(i >= tokensLength || token
s[i++].value !== 'expression' || i >= tokensLength || tokens[i].type !== TokenTy
pe.LeftParenthesis)return 0;return tokens[i].right - start + 1;} /** | 6459 |
| 6460 » /** |
| 1350 * @returns {Array} | 6461 * @returns {Array} |
| 1351 » */function getExpression(){var startPos=pos;var e;var token=tokens[star
tPos];var line=token.ln;var column=token.col;pos++;e = joinValues(pos + 1,tokens
[pos].right - 1);var end=getLastPosition(e,line,column,1);if(end[0] === line)end
[1] += 11;pos = tokens[pos].right + 1;return newNode(NodeType.ExpressionType,e,t
oken.ln,token.col,end);}function checkExtend(i){var l=0;if(l = checkExtend1(i))t
okens[i].extend_child = 1;else if(l = checkExtend2(i))tokens[i].extend_child = 2
;return l;}function getExtend(){var type=tokens[pos].extend_child;if(type === 1)
return getExtend1();else if(type === 2)return getExtend2();} /** | 6462 » */ |
| 6463 » function getExpression() { |
| 6464 » var startPos = pos; |
| 6465 » var e; |
| 6466 » var token = tokens[startPos]; |
| 6467 » var line = token.ln; |
| 6468 » var column = token.col; |
| 6469 |
| 6470 » pos++; |
| 6471 |
| 6472 » e = joinValues(pos + 1, tokens[pos].right - 1); |
| 6473 » var end = getLastPosition(e, line, column, 1); |
| 6474 » if (end[0] === line) end[1] += 11; |
| 6475 » pos = tokens[pos].right + 1; |
| 6476 |
| 6477 » return newNode(NodeType.ExpressionType, e, token.ln, token.col, end); |
| 6478 » } |
| 6479 |
| 6480 » function checkExtend(i) { |
| 6481 » var l = 0; |
| 6482 |
| 6483 » if (l = checkExtend1(i)) tokens[i].extend_child = 1;else if (l = check
Extend2(i)) tokens[i].extend_child = 2; |
| 6484 |
| 6485 » return l; |
| 6486 » } |
| 6487 |
| 6488 » function getExtend() { |
| 6489 » var type = tokens[pos].extend_child; |
| 6490 |
| 6491 » if (type === 1) return getExtend1();else if (type === 2) return getExt
end2(); |
| 6492 » } |
| 6493 |
| 6494 » /** |
| 1352 * Checks if token is part of an extend with `!optional` flag. | 6495 * Checks if token is part of an extend with `!optional` flag. |
| 1353 * @param {Number} i | 6496 * @param {Number} i |
| 1354 » */function checkExtend1(i){var start=i;var l;if(i >= tokensLength)retur
n 0;if(l = checkAtkeyword(i))i += l;else return 0;if(tokens[start + 1].value !==
'extend')return 0;if(l = checkSC(i))i += l;else return 0;if(l = checkSelectorsG
roup(i))i += l;else return 0;if(l = checkSC(i))i += l;else return 0;if(l = check
Optional(i))i += l;else return 0;return i - start;}function getExtend1(){var sta
rtPos=pos;var x=[].concat([getAtkeyword()],getSC(),getSelectorsGroup(),getSC(),[
getOptional()]);var token=tokens[startPos];return newNode(NodeType.ExtendType,x,
token.ln,token.col);} /** | 6497 » */ |
| 6498 » function checkExtend1(i) { |
| 6499 » var start = i; |
| 6500 » var l; |
| 6501 |
| 6502 » if (i >= tokensLength) return 0; |
| 6503 |
| 6504 » if (l = checkAtkeyword(i)) i += l;else return 0; |
| 6505 |
| 6506 » if (tokens[start + 1].value !== 'extend') return 0; |
| 6507 |
| 6508 » if (l = checkSC(i)) i += l;else return 0; |
| 6509 |
| 6510 » if (l = checkSelectorsGroup(i)) i += l;else return 0; |
| 6511 |
| 6512 » if (l = checkSC(i)) i += l;else return 0; |
| 6513 |
| 6514 » if (l = checkOptional(i)) i += l;else return 0; |
| 6515 |
| 6516 » return i - start; |
| 6517 » } |
| 6518 |
| 6519 » function getExtend1() { |
| 6520 » var startPos = pos; |
| 6521 » var x = [].concat([getAtkeyword()], getSC(), getSelectorsGroup(), getS
C(), [getOptional()]); |
| 6522 |
| 6523 » var token = tokens[startPos]; |
| 6524 » return newNode(NodeType.ExtendType, x, token.ln, token.col); |
| 6525 » } |
| 6526 |
| 6527 » /** |
| 1355 * Checks if token is part of an extend without `!optional` flag. | 6528 * Checks if token is part of an extend without `!optional` flag. |
| 1356 * @param {Number} i | 6529 * @param {Number} i |
| 1357 » */function checkExtend2(i){var start=i;var l;if(i >= tokensLength)retur
n 0;if(l = checkAtkeyword(i))i += l;else return 0;if(tokens[start + 1].value !==
'extend')return 0;if(l = checkSC(i))i += l;else return 0;if(l = checkSelectorsG
roup(i))i += l;else return 0;return i - start;}function getExtend2(){var startPo
s=pos;var x=[].concat([getAtkeyword()],getSC(),getSelectorsGroup());var token=to
kens[startPos];return newNode(NodeType.ExtendType,x,token.ln,token.col);} /** | 6530 » */ |
| 6531 » function checkExtend2(i) { |
| 6532 » var start = i; |
| 6533 » var l; |
| 6534 |
| 6535 » if (i >= tokensLength) return 0; |
| 6536 |
| 6537 » if (l = checkAtkeyword(i)) i += l;else return 0; |
| 6538 |
| 6539 » if (tokens[start + 1].value !== 'extend') return 0; |
| 6540 |
| 6541 » if (l = checkSC(i)) i += l;else return 0; |
| 6542 |
| 6543 » if (l = checkSelectorsGroup(i)) i += l;else return 0; |
| 6544 |
| 6545 » return i - start; |
| 6546 » } |
| 6547 |
| 6548 » function getExtend2() { |
| 6549 » var startPos = pos; |
| 6550 » var x = [].concat([getAtkeyword()], getSC(), getSelectorsGroup()); |
| 6551 » var token = tokens[startPos]; |
| 6552 » return newNode(NodeType.ExtendType, x, token.ln, token.col); |
| 6553 » } |
| 6554 |
| 6555 » /** |
| 1358 * @param {Number} i Token's index number | 6556 * @param {Number} i Token's index number |
| 1359 * @returns {Number} | 6557 * @returns {Number} |
| 1360 » */function checkFunction(i){var start=i;var l=undefined;if(i >= tokensL
ength)return 0;if(l = checkIdentOrInterpolation(i))i += l;else return 0;return i
< tokensLength && tokens[i].type === TokenType.LeftParenthesis?tokens[i].right
- start + 1:0;} /** | 6558 » */ |
| 6559 » function checkFunction(i) { |
| 6560 » var start = i; |
| 6561 » var l = void 0; |
| 6562 |
| 6563 » if (i >= tokensLength) return 0; |
| 6564 |
| 6565 » if (l = checkIdentOrInterpolation(i)) i += l;else return 0; |
| 6566 |
| 6567 » return i < tokensLength && tokens[i].type === TokenType.LeftParenthesi
s ? tokens[i].right - start + 1 : 0; |
| 6568 » } |
| 6569 |
| 6570 » /** |
| 1361 * @returns {Array} | 6571 * @returns {Array} |
| 1362 » */function getFunction(){var startPos=pos;var x=getIdentOrInterpolation
();var body=undefined;body = getArguments();x.push(body);var token=tokens[startP
os];return newNode(NodeType.FunctionType,x,token.ln,token.col);} /** | 6572 » */ |
| 6573 » function getFunction() { |
| 6574 » var startPos = pos; |
| 6575 » var x = getIdentOrInterpolation(); |
| 6576 » var body = void 0; |
| 6577 |
| 6578 » body = getArguments(); |
| 6579 |
| 6580 » x.push(body); |
| 6581 |
| 6582 » var token = tokens[startPos]; |
| 6583 » return newNode(NodeType.FunctionType, x, token.ln, token.col); |
| 6584 » } |
| 6585 |
| 6586 » /** |
| 1363 * @returns {Array} | 6587 * @returns {Array} |
| 1364 » */function getArguments(){var startPos=pos;var x=[];var body=undefined;
var token=tokens[startPos];var line=token.ln;var column=token.col;pos++;while(po
s < tokensLength && tokens[pos].type !== TokenType.RightParenthesis) {if(checkDe
claration(pos))x.push(getDeclaration());else if(checkArgument(pos)){body = getAr
gument();if(typeof body.content === 'string')x.push(body);else x = x.concat(body
);}else if(checkClass(pos))x.push(getClass());else throwError();}var end=getLast
Position(x,line,column,1);pos++;return newNode(NodeType.ArgumentsType,x,token.ln
,token.col,end);} /** | 6588 » */ |
| 6589 » function getArguments() { |
| 6590 » var startPos = pos; |
| 6591 » var x = []; |
| 6592 » var body = void 0; |
| 6593 » var token = tokens[startPos]; |
| 6594 » var line = token.ln; |
| 6595 » var column = token.col; |
| 6596 |
| 6597 » pos++; |
| 6598 |
| 6599 » while (pos < tokensLength && tokens[pos].type !== TokenType.RightParen
thesis) { |
| 6600 » if (checkSingleValueDeclaration(pos)) x.push(getSingleValueDeclarati
on());else if (checkArgument(pos)) { |
| 6601 » body = getArgument(); |
| 6602 » if (typeof body.content === 'string') x.push(body);else x = x.conc
at(body); |
| 6603 » } else if (checkClass(pos)) x.push(getClass());else throwError(); |
| 6604 » } |
| 6605 |
| 6606 » var end = getLastPosition(x, line, column, 1); |
| 6607 » pos++; |
| 6608 |
| 6609 » return newNode(NodeType.ArgumentsType, x, token.ln, token.col, end); |
| 6610 » } |
| 6611 |
| 6612 » /** |
| 1365 * Check if token is part of an identifier | 6613 * Check if token is part of an identifier |
| 1366 * @param {Number} i Token's index number | 6614 * @param {Number} i Token's index number |
| 1367 * @returns {Number} Length of the identifier | 6615 * @returns {Number} Length of the identifier |
| 1368 » */function checkIdent(i){var start=i;var interpolations=[];var wasIdent
=undefined;var wasInt=false;var l=undefined;if(i >= tokensLength)return 0; // Ch
eck if token is part of an identifier starting with `_`: | 6616 » */ |
| 1369 » if(tokens[i].type === TokenType.LowLine)return checkIdentLowLine(i);if(t
okens[i].type === TokenType.HyphenMinus && tokens[i + 1].type === TokenType.Deci
malNumber)return 0; // If token is a character, `-`, `$` or `*`, skip it & conti
nue: | 6617 » function checkIdent(i) { |
| 1370 » if(l = _checkIdent(i))i += l;else return 0; // Remember if previous toke
n's type was identifier: | 6618 » var start = i; |
| 1371 » wasIdent = tokens[i - 1].type === TokenType.Identifier;while(i < tokensL
ength) {l = _checkIdent(i);if(!l)break;wasIdent = true;i += l;}if(!wasIdent && !
wasInt && tokens[start].type !== TokenType.Asterisk)return 0;tokens[start].ident
_last = i - 1;if(interpolations.length)tokens[start].interpolations = interpolat
ions;return i - start;}function _checkIdent(i){if(tokens[i].type === TokenType.H
yphenMinus || tokens[i].type === TokenType.Identifier || tokens[i].type === Toke
nType.DollarSign || tokens[i].type === TokenType.LowLine || tokens[i].type === T
okenType.DecimalNumber || tokens[i].type === TokenType.Asterisk)return 1;return
0;} /** | 6619 |
| 1372 » * Check if token is part of an identifier starting with `_` | 6620 » if (i >= tokensLength) return 0; |
| 1373 » * @param {Number} i Token's index number | 6621 |
| 1374 » * @returns {Number} Length of the identifier | 6622 » // Check if token is part of a negative number |
| 1375 » */function checkIdentLowLine(i){var start=i;if(i++ >= tokensLength)retu
rn 0;for(;i < tokensLength;i++) {if(tokens[i].type !== TokenType.HyphenMinus &&
tokens[i].type !== TokenType.DecimalNumber && tokens[i].type !== TokenType.LowLi
ne && tokens[i].type !== TokenType.Identifier)break;} // Save index number of th
e last token of the identifier: | 6623 » if (tokens[i].type === TokenType.HyphenMinus && tokens[i + 1].type ===
TokenType.DecimalNumber) return 0; |
| 1376 » tokens[start].ident_last = i - 1;return i - start;} /** | 6624 |
| 6625 » if (tokens[i].type === TokenType.HyphenMinus) i++; |
| 6626 |
| 6627 » if (checkInterpolation(i)) { |
| 6628 » tokens[start].ident_last = i - 1; |
| 6629 » return i - start; |
| 6630 » } |
| 6631 |
| 6632 » if (tokens[i].type === TokenType.LowLine || tokens[i].type === TokenTy
pe.Identifier) i++;else return 0; |
| 6633 |
| 6634 » for (; i < tokensLength; i++) { |
| 6635 » if (tokens[i].type !== TokenType.HyphenMinus && tokens[i].type !== T
okenType.LowLine && tokens[i].type !== TokenType.Identifier && tokens[i].type !=
= TokenType.DecimalNumber) break; |
| 6636 » } |
| 6637 |
| 6638 » tokens[start].ident_last = i - 1; |
| 6639 |
| 6640 » return i - start; |
| 6641 » } |
| 6642 |
| 6643 » /** |
| 1377 * Get node with an identifier | 6644 * Get node with an identifier |
| 1378 * @returns {Array} `['ident', x]` where `x` is identifier's name | 6645 * @returns {Array} `['ident', x]` where `x` is identifier's name |
| 1379 » */function getIdent(){var startPos=pos;var x=joinValues(pos,tokens[pos]
.ident_last);pos = tokens[pos].ident_last + 1;var token=tokens[startPos];return
newNode(NodeType.IdentType,x,token.ln,token.col);}function checkIdentOrInterpola
tion(i){var start=i;var l=undefined;while(i < tokensLength) {if(l = checkInterpo
lation(i) || checkIdent(i))i += l;else break;}return i - start;}function getIden
tOrInterpolation(){var x=[];while(pos < tokensLength) {if(checkInterpolation(pos
))x.push(getInterpolation());else if(checkIdent(pos))x.push(getIdent());else bre
ak;}return x;} /** | 6646 » */ |
| 6647 » function getIdent() { |
| 6648 » var startPos = pos; |
| 6649 » var x = joinValues(pos, tokens[pos].ident_last); |
| 6650 |
| 6651 » pos = tokens[pos].ident_last + 1; |
| 6652 |
| 6653 » var token = tokens[startPos]; |
| 6654 » return newNode(NodeType.IdentType, x, token.ln, token.col); |
| 6655 » } |
| 6656 |
| 6657 » /** |
| 6658 » * @param {number} i Token's index number |
| 6659 » * @returns {number} Length of the identifier |
| 6660 » */ |
| 6661 » function checkPartialIdent(i) { |
| 6662 » var start = i; |
| 6663 |
| 6664 » if (i >= tokensLength) return 0; |
| 6665 |
| 6666 » for (; i < tokensLength; i++) { |
| 6667 » if (tokens[i].type !== TokenType.HyphenMinus && tokens[i].type !== T
okenType.LowLine && tokens[i].type !== TokenType.Identifier && tokens[i].type !=
= TokenType.DecimalNumber) break; |
| 6668 » } |
| 6669 |
| 6670 » tokens[start].ident_last = i - 1; |
| 6671 |
| 6672 » return i - start; |
| 6673 » } |
| 6674 |
| 6675 » function checkIdentOrInterpolation(i) { |
| 6676 » var start = i; |
| 6677 » var l = void 0; |
| 6678 » var prevIsInterpolation = false; |
| 6679 |
| 6680 » while (i < tokensLength) { |
| 6681 » if (l = checkInterpolation(i)) { |
| 6682 » tokens[i].ii_type = 1; |
| 6683 » i += l; |
| 6684 » prevIsInterpolation = true; |
| 6685 » } else if (l = checkIdent(i)) { |
| 6686 » tokens[i].ii_type = 2; |
| 6687 » i += l; |
| 6688 » prevIsInterpolation = false; |
| 6689 » } else if (prevIsInterpolation && (l = checkPartialIdent(i))) { |
| 6690 » tokens[i].ii_type = 3; |
| 6691 » i += l; |
| 6692 » prevIsInterpolation = false; |
| 6693 » } else break; |
| 6694 » } |
| 6695 |
| 6696 » return i - start; |
| 6697 » } |
| 6698 |
| 6699 » function getIdentOrInterpolation() { |
| 6700 » var x = []; |
| 6701 |
| 6702 » while (pos < tokensLength) { |
| 6703 » var tokenType = tokens[pos].ii_type; |
| 6704 |
| 6705 » if (tokenType === 1) { |
| 6706 » x.push(getInterpolation()); |
| 6707 » } else if (tokenType === 2 || tokenType === 3) { |
| 6708 » x.push(getIdent()); |
| 6709 » } else break; |
| 6710 » } |
| 6711 |
| 6712 » return x; |
| 6713 » } |
| 6714 |
| 6715 » /** |
| 1380 * Check if token is part of `!important` word | 6716 * Check if token is part of `!important` word |
| 1381 * @param {Number} i Token's index number | 6717 * @param {Number} i Token's index number |
| 1382 * @returns {Number} | 6718 * @returns {Number} |
| 1383 » */function checkImportant(i){var start=i;var l=undefined;if(i >= tokens
Length || tokens[i++].type !== TokenType.ExclamationMark)return 0;if(l = checkSC
(i))i += l;if(tokens[i].value === 'important'){tokens[start].importantEnd = i;re
turn i - start + 1;}else {return 0;}} /** | 6719 » */ |
| 6720 » function checkImportant(i) { |
| 6721 » var start = i; |
| 6722 » var l = void 0; |
| 6723 |
| 6724 » if (i >= tokensLength || tokens[i++].type !== TokenType.ExclamationMar
k) return 0; |
| 6725 |
| 6726 » if (l = checkSC(i)) i += l; |
| 6727 |
| 6728 » if (tokens[i].value === 'important') { |
| 6729 » tokens[start].importantEnd = i; |
| 6730 » return i - start + 1; |
| 6731 » } else { |
| 6732 » return 0; |
| 6733 » } |
| 6734 » } |
| 6735 |
| 6736 » /** |
| 1384 * Get node with `!important` word | 6737 * Get node with `!important` word |
| 1385 * @returns {Array} `['important', sc]` where `sc` is optional whitespac
e | 6738 * @returns {Array} `['important', sc]` where `sc` is optional whitespac
e |
| 1386 » */function getImportant(){var token=tokens[pos];var line=token.ln;var c
olumn=token.col;var content=joinValues(pos,token.importantEnd);pos = token.impor
tantEnd + 1;return newNode(NodeType.ImportantType,content,line,column);} /** | 6739 » */ |
| 6740 » function getImportant() { |
| 6741 » var token = tokens[pos]; |
| 6742 » var line = token.ln; |
| 6743 » var column = token.col; |
| 6744 » var content = joinValues(pos, token.importantEnd); |
| 6745 |
| 6746 » pos = token.importantEnd + 1; |
| 6747 |
| 6748 » return newNode(NodeType.ImportantType, content, line, column); |
| 6749 » } |
| 6750 |
| 6751 » /** |
| 1387 * Check if token is part of an included mixin (`@include` or `@extend` | 6752 * Check if token is part of an included mixin (`@include` or `@extend` |
| 1388 * directive). | 6753 * directive). |
| 1389 * @param {Number} i Token's index number | 6754 * @param {Number} i Token's index number |
| 1390 * @returns {Number} Length of the included mixin | 6755 * @returns {Number} Length of the included mixin |
| 1391 » */function checkInclude(i){var l;if(i >= tokensLength)return 0;if(l = c
heckInclude1(i))tokens[i].include_type = 1;else if(l = checkInclude2(i))tokens[i
].include_type = 2;else if(l = checkInclude3(i))tokens[i].include_type = 3;else
if(l = checkInclude4(i))tokens[i].include_type = 4;else if(l = checkInclude5(i))
tokens[i].include_type = 5;return l;} /** | 6756 » */ |
| 6757 » function checkInclude(i) { |
| 6758 » var l; |
| 6759 |
| 6760 » if (i >= tokensLength) return 0; |
| 6761 |
| 6762 » if (l = checkInclude1(i)) tokens[i].include_type = 1;else if (l = chec
kInclude2(i)) tokens[i].include_type = 2;else if (l = checkInclude3(i)) tokens[i
].include_type = 3;else if (l = checkInclude4(i)) tokens[i].include_type = 4;els
e if (l = checkInclude5(i)) tokens[i].include_type = 5; |
| 6763 |
| 6764 » return l; |
| 6765 » } |
| 6766 |
| 6767 » /** |
| 1392 * Check if token is part of `!global` word | 6768 * Check if token is part of `!global` word |
| 1393 * @param {Number} i Token's index number | 6769 * @param {Number} i Token's index number |
| 1394 * @returns {Number} | 6770 * @returns {Number} |
| 1395 » */function checkGlobal(i){var start=i;var l=undefined;if(i >= tokensLen
gth || tokens[i++].type !== TokenType.ExclamationMark)return 0;if(l = checkSC(i)
)i += l;if(tokens[i].value === 'global'){tokens[start].globalEnd = i;return i -
start + 1;}else {return 0;}} /** | 6771 » */ |
| 6772 » function checkGlobal(i) { |
| 6773 » var start = i; |
| 6774 » var l = void 0; |
| 6775 |
| 6776 » if (i >= tokensLength || tokens[i++].type !== TokenType.ExclamationMar
k) return 0; |
| 6777 |
| 6778 » if (l = checkSC(i)) i += l; |
| 6779 |
| 6780 » if (tokens[i].value === 'global') { |
| 6781 » tokens[start].globalEnd = i; |
| 6782 » return i - start + 1; |
| 6783 » } else { |
| 6784 » return 0; |
| 6785 » } |
| 6786 » } |
| 6787 |
| 6788 » /** |
| 1396 * Get node with `!global` word | 6789 * Get node with `!global` word |
| 1397 » */function getGlobal(){var token=tokens[pos];var line=token.ln;var colu
mn=token.col;var content=joinValues(pos,token.globalEnd);pos = token.globalEnd +
1;return newNode(NodeType.GlobalType,content,line,column);} /** | 6790 » */ |
| 6791 » function getGlobal() { |
| 6792 » var token = tokens[pos]; |
| 6793 » var line = token.ln; |
| 6794 » var column = token.col; |
| 6795 » var content = joinValues(pos, token.globalEnd); |
| 6796 |
| 6797 » pos = token.globalEnd + 1; |
| 6798 |
| 6799 » return newNode(NodeType.GlobalType, content, line, column); |
| 6800 » } |
| 6801 |
| 6802 » /** |
| 1398 * Get node with included mixin | 6803 * Get node with included mixin |
| 1399 * @returns {Array} `['include', x]` | 6804 * @returns {Array} `['include', x]` |
| 1400 » */function getInclude(){switch(tokens[pos].include_type){case 1:return
getInclude1();case 2:return getInclude2();case 3:return getInclude3();case 4:ret
urn getInclude4();case 5:return getInclude5();}} /** | 6805 » */ |
| 6806 » function getInclude() { |
| 6807 » switch (tokens[pos].include_type) { |
| 6808 » case 1: |
| 6809 » return getInclude1(); |
| 6810 » case 2: |
| 6811 » return getInclude2(); |
| 6812 » case 3: |
| 6813 » return getInclude3(); |
| 6814 » case 4: |
| 6815 » return getInclude4(); |
| 6816 » case 5: |
| 6817 » return getInclude5(); |
| 6818 » } |
| 6819 » } |
| 6820 |
| 6821 » /** |
| 1401 * Get node with included mixin with keyfames selector like | 6822 * Get node with included mixin with keyfames selector like |
| 1402 * `@include nani(foo) { 0% {}}` | 6823 * `@include nani(foo) { 0% {}}` |
| 1403 * @param {Number} i Token's index number | 6824 * @param {Number} i Token's index number |
| 1404 * @returns {Number} Length of the include | 6825 * @returns {Number} Length of the include |
| 1405 » */function checkInclude1(i){var start=i;var l=undefined;if(l = checkAtk
eyword(i))i += l;else return 0;if(tokens[start + 1].value !== 'include')return 0
;if(l = checkSC(i))i += l;else return 0;if(l = checkIdentOrInterpolation(i))i +=
l;else return 0;if(l = checkSC(i))i += l;if(l = checkArguments(i))i += l;else r
eturn 0;if(l = checkSC(i))i += l;if(l = checkKeyframesBlocks(i))i += l;else retu
rn 0;return i - start;} /** | 6826 » */ |
| 6827 » function checkInclude1(i) { |
| 6828 » var start = i; |
| 6829 » var l = void 0; |
| 6830 |
| 6831 » if (l = checkAtkeyword(i)) i += l;else return 0; |
| 6832 |
| 6833 » if (tokens[start + 1].value !== 'include') return 0; |
| 6834 |
| 6835 » if (l = checkSC(i)) i += l;else return 0; |
| 6836 |
| 6837 » if (l = checkIdentOrInterpolation(i)) i += l;else return 0; |
| 6838 |
| 6839 » if (l = checkSC(i)) i += l; |
| 6840 |
| 6841 » if (l = checkArguments(i)) i += l;else return 0; |
| 6842 |
| 6843 » if (l = checkSC(i)) i += l; |
| 6844 |
| 6845 » if (l = checkKeyframesBlocks(i)) i += l;else return 0; |
| 6846 |
| 6847 » return i - start; |
| 6848 » } |
| 6849 |
| 6850 » /** |
| 1406 * Get node with included mixin with keyfames selector like | 6851 * Get node with included mixin with keyfames selector like |
| 1407 * `@include nani(foo) { 0% {}}` | 6852 * `@include nani(foo) { 0% {}}` |
| 1408 * @returns {Array} `['include', ['atkeyword', x], sc, ['selector', y],
sc, | 6853 * @returns {Array} `['include', ['atkeyword', x], sc, ['selector', y],
sc, |
| 1409 * ['arguments', z], sc, ['block', q], sc` where `x` is `include` o
r | 6854 * ['arguments', z], sc, ['block', q], sc` where `x` is `include` o
r |
| 1410 * `extend`, `y` is mixin's identifier (selector), `z` are argument
s | 6855 * `extend`, `y` is mixin's identifier (selector), `z` are argument
s |
| 1411 * passed to the mixin, `q` is block passed to the mixin containing
a | 6856 * passed to the mixin, `q` is block passed to the mixin containing
a |
| 1412 * ruleset > selector > keyframesSelector, and `sc` are optional | 6857 * ruleset > selector > keyframesSelector, and `sc` are optional |
| 1413 * whitespaces | 6858 * whitespaces |
| 1414 » */function getInclude1(){var startPos=pos;var x=[].concat(getAtkeyword(
),getSC(),getIdentOrInterpolation(),getSC(),getArguments(),getSC(),getKeyframesB
locks());var token=tokens[startPos];return newNode(NodeType.IncludeType,x,token.
ln,token.col);} /** | 6859 » */ |
| 6860 » function getInclude1() { |
| 6861 » var startPos = pos; |
| 6862 » var x = [].concat(getAtkeyword(), getSC(), getIdentOrInterpolation(),
getSC(), getArguments(), getSC(), getKeyframesBlocks()); |
| 6863 |
| 6864 » var token = tokens[startPos]; |
| 6865 » return newNode(NodeType.IncludeType, x, token.ln, token.col); |
| 6866 » } |
| 6867 |
| 6868 » /** |
| 1415 * Check if token is part of an included mixin like `@include nani(foo)
{...}` | 6869 * Check if token is part of an included mixin like `@include nani(foo)
{...}` |
| 1416 * @param {Number} i Token's index number | 6870 * @param {Number} i Token's index number |
| 1417 * @returns {Number} Length of the include | 6871 * @returns {Number} Length of the include |
| 1418 » */function checkInclude2(i){var start=i;var l=undefined;if(l = checkAtk
eyword(i))i += l;else return 0;if(tokens[start + 1].value !== 'include')return 0
;if(l = checkSC(i))i += l;else return 0;if(l = checkIdentOrInterpolation(i))i +=
l;else return 0;if(l = checkSC(i))i += l;if(l = checkArguments(i))i += l;else r
eturn 0;if(l = checkSC(i))i += l;if(l = checkBlock(i))i += l;else return 0;retur
n i - start;} /** | 6872 » */ |
| 6873 » function checkInclude2(i) { |
| 6874 » var start = i; |
| 6875 » var l = void 0; |
| 6876 |
| 6877 » if (l = checkAtkeyword(i)) i += l;else return 0; |
| 6878 |
| 6879 » if (tokens[start + 1].value !== 'include') return 0; |
| 6880 |
| 6881 » if (l = checkSC(i)) i += l;else return 0; |
| 6882 |
| 6883 » if (l = checkIdentOrInterpolation(i)) i += l;else return 0; |
| 6884 |
| 6885 » if (l = checkSC(i)) i += l; |
| 6886 |
| 6887 » if (l = checkArguments(i)) i += l;else return 0; |
| 6888 |
| 6889 » if (l = checkSC(i)) i += l; |
| 6890 |
| 6891 » if (l = checkBlock(i)) i += l;else return 0; |
| 6892 |
| 6893 » return i - start; |
| 6894 » } |
| 6895 |
| 6896 » /** |
| 1419 * Get node with included mixin like `@include nani(foo) {...}` | 6897 * Get node with included mixin like `@include nani(foo) {...}` |
| 1420 * @returns {Array} `['include', ['atkeyword', x], sc, ['selector', y],
sc, | 6898 * @returns {Array} `['include', ['atkeyword', x], sc, ['selector', y],
sc, |
| 1421 * ['arguments', z], sc, ['block', q], sc` where `x` is `include` o
r | 6899 * ['arguments', z], sc, ['block', q], sc` where `x` is `include` o
r |
| 1422 * `extend`, `y` is mixin's identifier (selector), `z` are argument
s | 6900 * `extend`, `y` is mixin's identifier (selector), `z` are argument
s |
| 1423 * passed to the mixin, `q` is block passed to the mixin and `sc` | 6901 * passed to the mixin, `q` is block passed to the mixin and `sc` |
| 1424 * are optional whitespaces | 6902 * are optional whitespaces |
| 1425 » */function getInclude2(){var startPos=pos;var x=[].concat(getAtkeyword(
),getSC(),getIdentOrInterpolation(),getSC(),getArguments(),getSC(),getBlock());v
ar token=tokens[startPos];return newNode(NodeType.IncludeType,x,token.ln,token.c
ol);} /** | 6903 » */ |
| 6904 » function getInclude2() { |
| 6905 » var startPos = pos; |
| 6906 » var x = [].concat(getAtkeyword(), getSC(), getIdentOrInterpolation(),
getSC(), getArguments(), getSC(), getBlock()); |
| 6907 |
| 6908 » var token = tokens[startPos]; |
| 6909 » return newNode(NodeType.IncludeType, x, token.ln, token.col); |
| 6910 » } |
| 6911 |
| 6912 » /** |
| 1426 * Check if token is part of an included mixin like `@include nani(foo)` | 6913 * Check if token is part of an included mixin like `@include nani(foo)` |
| 1427 * @param {Number} i Token's index number | 6914 * @param {Number} i Token's index number |
| 1428 * @returns {Number} Length of the include | 6915 * @returns {Number} Length of the include |
| 1429 » */function checkInclude3(i){var start=i;var l=undefined;if(l = checkAtk
eyword(i))i += l;else return 0;if(tokens[start + 1].value !== 'include')return 0
;if(l = checkSC(i))i += l;else return 0;if(l = checkIdentOrInterpolation(i))i +=
l;else return 0;if(l = checkSC(i))i += l;if(l = checkArguments(i))i += l;else r
eturn 0;return i - start;} /** | 6916 » */ |
| 6917 » function checkInclude3(i) { |
| 6918 » var start = i; |
| 6919 » var l = void 0; |
| 6920 |
| 6921 » if (l = checkAtkeyword(i)) i += l;else return 0; |
| 6922 |
| 6923 » if (tokens[start + 1].value !== 'include') return 0; |
| 6924 |
| 6925 » if (l = checkSC(i)) i += l;else return 0; |
| 6926 |
| 6927 » if (l = checkIdentOrInterpolation(i)) i += l;else return 0; |
| 6928 |
| 6929 » if (l = checkSC(i)) i += l; |
| 6930 |
| 6931 » if (l = checkArguments(i)) i += l;else return 0; |
| 6932 |
| 6933 » return i - start; |
| 6934 » } |
| 6935 |
| 6936 » /** |
| 1430 * Get node with included mixin like `@include nani(foo)` | 6937 * Get node with included mixin like `@include nani(foo)` |
| 1431 * @returns {Array} `['include', ['atkeyword', x], sc, ['selector', y],
sc, | 6938 * @returns {Array} `['include', ['atkeyword', x], sc, ['selector', y],
sc, |
| 1432 * ['arguments', z], sc]` where `x` is `include` or `extend`, `y` i
s | 6939 * ['arguments', z], sc]` where `x` is `include` or `extend`, `y` i
s |
| 1433 * mixin's identifier (selector), `z` are arguments passed to the | 6940 * mixin's identifier (selector), `z` are arguments passed to the |
| 1434 * mixin and `sc` are optional whitespaces | 6941 * mixin and `sc` are optional whitespaces |
| 1435 » */function getInclude3(){var startPos=pos;var x=[].concat(getAtkeyword(
),getSC(),getIdentOrInterpolation(),getSC(),getArguments());var token=tokens[sta
rtPos];return newNode(NodeType.IncludeType,x,token.ln,token.col);} /** | 6942 » */ |
| 6943 » function getInclude3() { |
| 6944 » var startPos = pos; |
| 6945 » var x = [].concat(getAtkeyword(), getSC(), getIdentOrInterpolation(),
getSC(), getArguments()); |
| 6946 |
| 6947 » var token = tokens[startPos]; |
| 6948 » return newNode(NodeType.IncludeType, x, token.ln, token.col); |
| 6949 » } |
| 6950 |
| 6951 » /** |
| 1436 * Check if token is part of an included mixin with a content block pass
ed | 6952 * Check if token is part of an included mixin with a content block pass
ed |
| 1437 * as an argument (e.g. `@include nani {...}`) | 6953 * as an argument (e.g. `@include nani {...}`) |
| 1438 * @param {Number} i Token's index number | 6954 * @param {Number} i Token's index number |
| 1439 * @returns {Number} Length of the mixin | 6955 * @returns {Number} Length of the mixin |
| 1440 » */function checkInclude4(i){var start=i;var l=undefined;if(l = checkAtk
eyword(i))i += l;else return 0;if(tokens[start + 1].value !== 'include')return 0
;if(l = checkSC(i))i += l;else return 0;if(l = checkIdentOrInterpolation(i))i +=
l;else return 0;if(l = checkSC(i))i += l;if(l = checkBlock(i))i += l;else retur
n 0;return i - start;} /** | 6956 » */ |
| 6957 » function checkInclude4(i) { |
| 6958 » var start = i; |
| 6959 » var l = void 0; |
| 6960 |
| 6961 » if (l = checkAtkeyword(i)) i += l;else return 0; |
| 6962 |
| 6963 » if (tokens[start + 1].value !== 'include') return 0; |
| 6964 |
| 6965 » if (l = checkSC(i)) i += l;else return 0; |
| 6966 |
| 6967 » if (l = checkIdentOrInterpolation(i)) i += l;else return 0; |
| 6968 |
| 6969 » if (l = checkSC(i)) i += l; |
| 6970 |
| 6971 » if (l = checkBlock(i)) i += l;else return 0; |
| 6972 |
| 6973 » return i - start; |
| 6974 » } |
| 6975 |
| 6976 » /** |
| 1441 * Get node with an included mixin with a content block passed | 6977 * Get node with an included mixin with a content block passed |
| 1442 * as an argument (e.g. `@include nani {...}`) | 6978 * as an argument (e.g. `@include nani {...}`) |
| 1443 * @returns {Array} `['include', x]` | 6979 * @returns {Array} `['include', x]` |
| 1444 » */function getInclude4(){var startPos=pos;var x=[].concat(getAtkeyword(
),getSC(),getIdentOrInterpolation(),getSC(),getBlock());var token=tokens[startPo
s];return newNode(NodeType.IncludeType,x,token.ln,token.col);} /** | 6980 » */ |
| 6981 » function getInclude4() { |
| 6982 » var startPos = pos; |
| 6983 » var x = [].concat(getAtkeyword(), getSC(), getIdentOrInterpolation(),
getSC(), getBlock()); |
| 6984 |
| 6985 » var token = tokens[startPos]; |
| 6986 » return newNode(NodeType.IncludeType, x, token.ln, token.col); |
| 6987 » } |
| 6988 |
| 6989 » /** |
| 1445 * @param {Number} i Token's index number | 6990 * @param {Number} i Token's index number |
| 1446 * @returns {Number} | 6991 * @returns {Number} |
| 1447 » */function checkInclude5(i){var start=i;var l=undefined;if(l = checkAtk
eyword(i))i += l;else return 0;if(tokens[start + 1].value !== 'include')return 0
;if(l = checkSC(i))i += l;else return 0;if(l = checkIdentOrInterpolation(i))i +=
l;else return 0;return i - start;} /** | 6992 » */ |
| 6993 » function checkInclude5(i) { |
| 6994 » var start = i; |
| 6995 » var l = void 0; |
| 6996 |
| 6997 » if (l = checkAtkeyword(i)) i += l;else return 0; |
| 6998 |
| 6999 » if (tokens[start + 1].value !== 'include') return 0; |
| 7000 |
| 7001 » if (l = checkSC(i)) i += l;else return 0; |
| 7002 |
| 7003 » if (l = checkIdentOrInterpolation(i)) i += l;else return 0; |
| 7004 |
| 7005 » return i - start; |
| 7006 » } |
| 7007 |
| 7008 » /** |
| 1448 * @returns {Array} `['include', x]` | 7009 * @returns {Array} `['include', x]` |
| 1449 » */function getInclude5(){var startPos=pos;var x=[].concat(getAtkeyword(
),getSC(),getIdentOrInterpolation());var token=tokens[startPos];return newNode(N
odeType.IncludeType,x,token.ln,token.col);} /** | 7010 » */ |
| 7011 » function getInclude5() { |
| 7012 » var startPos = pos; |
| 7013 » var x = [].concat(getAtkeyword(), getSC(), getIdentOrInterpolation()); |
| 7014 |
| 7015 » var token = tokens[startPos]; |
| 7016 » return newNode(NodeType.IncludeType, x, token.ln, token.col); |
| 7017 » } |
| 7018 |
| 7019 » /** |
| 1450 * Check if token is part of an interpolated variable (e.g. `#{$nani}`). | 7020 * Check if token is part of an interpolated variable (e.g. `#{$nani}`). |
| 1451 * @param {Number} i Token's index number | 7021 * @param {Number} i Token's index number |
| 1452 * @returns {Number} | 7022 * @returns {Number} |
| 1453 » */function checkInterpolation(i){var start=i;var l=undefined;if(i >= to
kensLength)return 0;if(tokens[i].type !== TokenType.NumberSign || !tokens[i + 1]
|| tokens[i + 1].type !== TokenType.LeftCurlyBracket)return 0;i += 2;while(toke
ns[i].type !== TokenType.RightCurlyBracket) {if(l = checkArgument(i))i += l;else
return 0;}return tokens[i].type === TokenType.RightCurlyBracket?i - start + 1:0
;} /** | 7023 » */ |
| 7024 » function checkInterpolation(i) { |
| 7025 » var start = i; |
| 7026 » var l = void 0; |
| 7027 |
| 7028 » if (i >= tokensLength) return 0; |
| 7029 |
| 7030 » if (tokens[i].type !== TokenType.NumberSign || !tokens[i + 1] || token
s[i + 1].type !== TokenType.LeftCurlyBracket) return 0; |
| 7031 |
| 7032 » i += 2; |
| 7033 |
| 7034 » while (tokens[i].type !== TokenType.RightCurlyBracket) { |
| 7035 » if (l = checkArgument(i)) i += l;else return 0; |
| 7036 » } |
| 7037 |
| 7038 » return tokens[i].type === TokenType.RightCurlyBracket ? i - start + 1
: 0; |
| 7039 » } |
| 7040 |
| 7041 » /** |
| 1454 * Get node with an interpolated variable | 7042 * Get node with an interpolated variable |
| 1455 * @returns {Array} `['interpolation', x]` | 7043 * @returns {Array} `['interpolation', x]` |
| 1456 » */function getInterpolation(){var startPos=pos;var x=[];var token=token
s[startPos];var line=token.ln;var column=token.col; // Skip `#{`: | 7044 » */ |
| 1457 » pos += 2;while(pos < tokensLength && tokens[pos].type !== TokenType.Righ
tCurlyBracket) {var body=getArgument();if(typeof body.content === 'string')x.pus
h(body);else x = x.concat(body);}var end=getLastPosition(x,line,column,1); // Sk
ip `}`: | 7045 » function getInterpolation() { |
| 1458 » pos++;return newNode(NodeType.InterpolationType,x,token.ln,token.col,end
);}function checkKeyframesBlock(i){var start=i;var l=undefined;if(i >= tokensLen
gth)return 0;if(l = checkKeyframesSelector(i))i += l;else return 0;if(l = checkS
C(i))i += l;if(l = checkBlock(i))i += l;else return 0;return i - start;}function
getKeyframesBlock(){var type=NodeType.RulesetType;var token=tokens[pos];var lin
e=token.ln;var column=token.col;var content=[].concat([getKeyframesSelector()],g
etSC(),[getBlock()]);return newNode(type,content,line,column);}function checkKey
framesBlocks(i){var start=i;var l=undefined;if(i < tokensLength && tokens[i].typ
e === TokenType.LeftCurlyBracket)i++;else return 0;if(l = checkSC(i))i += l;if(l
= checkKeyframesBlock(i))i += l;else return 0;while(tokens[i].type !== TokenTyp
e.RightCurlyBracket) {if(l = checkSC(i))i += l;else if(l = checkKeyframesBlock(i
))i += l;else break;}if(i < tokensLength && tokens[i].type === TokenType.RightCu
rlyBracket)i++;else return 0;return i - start;}function getKeyframesBlocks(){var
type=NodeType.BlockType;var token=tokens[pos];var line=token.ln;var column=toke
n.col;var content=[];var keyframesBlocksEnd=token.right; // Skip `{`. | 7046 » var startPos = pos; |
| 1459 » pos++;while(pos < keyframesBlocksEnd) {if(checkSC(pos))content = content
.concat(getSC());else if(checkKeyframesBlock(pos))content.push(getKeyframesBlock
());}var end=getLastPosition(content,line,column,1); // Skip `}`. | 7047 » var x = []; |
| 1460 » pos++;return newNode(type,content,line,column,end);} /** | 7048 » var token = tokens[startPos]; |
| 7049 » var line = token.ln; |
| 7050 » var column = token.col; |
| 7051 |
| 7052 » // Skip `#{`: |
| 7053 » pos += 2; |
| 7054 |
| 7055 » while (pos < tokensLength && tokens[pos].type !== TokenType.RightCurly
Bracket) { |
| 7056 » var body = getArgument(); |
| 7057 » if (typeof body.content === 'string') x.push(body);else x = x.concat
(body); |
| 7058 » } |
| 7059 |
| 7060 » var end = getLastPosition(x, line, column, 1); |
| 7061 |
| 7062 » // Skip `}`: |
| 7063 » pos++; |
| 7064 |
| 7065 » return newNode(NodeType.InterpolationType, x, token.ln, token.col, end
); |
| 7066 » } |
| 7067 |
| 7068 » /** |
| 7069 » * Check a single keyframe block - `5% {}` |
| 7070 » * @param {Number} i |
| 7071 » * @returns {Number} |
| 7072 » */ |
| 7073 » function checkKeyframesBlock(i) { |
| 7074 » var start = i; |
| 7075 » var l = void 0; |
| 7076 |
| 7077 » if (i >= tokensLength) return 0; |
| 7078 |
| 7079 » if (l = checkKeyframesSelectorsGroup(i)) i += l;else return 0; |
| 7080 |
| 7081 » if (l = checkSC(i)) i += l; |
| 7082 |
| 7083 » if (l = checkBlock(i)) i += l;else return 0; |
| 7084 |
| 7085 » return i - start; |
| 7086 » } |
| 7087 |
| 7088 » /** |
| 7089 » * Get a single keyframe block - `5% {}` |
| 7090 » * @returns {Node} |
| 7091 » */ |
| 7092 » function getKeyframesBlock() { |
| 7093 » var type = NodeType.RulesetType; |
| 7094 » var token = tokens[pos]; |
| 7095 » var line = token.ln; |
| 7096 » var column = token.col; |
| 7097 » var content = [].concat(getKeyframesSelectorsGroup(), getSC(), [getBlo
ck()]); |
| 7098 |
| 7099 » return newNode(type, content, line, column); |
| 7100 » } |
| 7101 |
| 7102 » /** |
| 7103 » * Check all keyframe blocks - `5% {} 100% {}` |
| 7104 » * @param {Number} i |
| 7105 » * @returns {Number} |
| 7106 » */ |
| 7107 » function checkKeyframesBlocks(i) { |
| 7108 » var start = i; |
| 7109 » var l = void 0; |
| 7110 |
| 7111 » if (i < tokensLength && tokens[i].type === TokenType.LeftCurlyBracket)
i++;else return 0; |
| 7112 |
| 7113 » if (l = checkSC(i)) i += l; |
| 7114 |
| 7115 » if (l = checkKeyframesBlock(i)) i += l;else return 0; |
| 7116 |
| 7117 » while (tokens[i].type !== TokenType.RightCurlyBracket) { |
| 7118 » if (l = checkSC(i)) i += l;else if (l = checkKeyframesBlock(i)) i +=
l;else break; |
| 7119 » } |
| 7120 |
| 7121 » if (i < tokensLength && tokens[i].type === TokenType.RightCurlyBracket
) i++;else return 0; |
| 7122 |
| 7123 » return i - start; |
| 7124 » } |
| 7125 |
| 7126 » /** |
| 7127 » * Get all keyframe blocks - `5% {} 100% {}` |
| 7128 » * @returns {Node} |
| 7129 » */ |
| 7130 » function getKeyframesBlocks() { |
| 7131 » var type = NodeType.BlockType; |
| 7132 » var token = tokens[pos]; |
| 7133 » var line = token.ln; |
| 7134 » var column = token.col; |
| 7135 » var content = []; |
| 7136 » var keyframesBlocksEnd = token.right; |
| 7137 |
| 7138 » // Skip `{`. |
| 7139 » pos++; |
| 7140 |
| 7141 » while (pos < keyframesBlocksEnd) { |
| 7142 » if (checkSC(pos)) content = content.concat(getSC());else if (checkKe
yframesBlock(pos)) content.push(getKeyframesBlock());else if (checkAtrule(pos))
content.push(getAtrule()); // @content |
| 7143 » else break; |
| 7144 » } |
| 7145 |
| 7146 » var end = getLastPosition(content, line, column, 1); |
| 7147 |
| 7148 » // Skip `}`. |
| 7149 » pos++; |
| 7150 |
| 7151 » return newNode(type, content, line, column, end); |
| 7152 » } |
| 7153 |
| 7154 » /** |
| 1461 * Check if token is part of a @keyframes rule. | 7155 * Check if token is part of a @keyframes rule. |
| 1462 * @param {Number} i Token's index number | 7156 * @param {Number} i Token's index number |
| 1463 * @return {Number} Length of the @keyframes rule | 7157 * @return {Number} Length of the @keyframes rule |
| 1464 » */function checkKeyframesRule(i){var start=i;var l=undefined;if(i >= to
kensLength)return 0;if(l = checkAtkeyword(i))i += l;else return 0;var atruleName
=joinValues2(i - l,l);if(atruleName.indexOf('keyframes') === -1)return 0;if(l =
checkSC(i))i += l;else return 0;if(l = checkIdentOrInterpolation(i))i += l;else
return 0;if(l = checkSC(i))i += l;if(l = checkKeyframesBlocks(i))i += l;else ret
urn 0;return i - start;} /** | 7158 » */ |
| 7159 » function checkKeyframesRule(i) { |
| 7160 » var start = i; |
| 7161 » var l = void 0; |
| 7162 |
| 7163 » if (i >= tokensLength) return 0; |
| 7164 |
| 7165 » if (l = checkAtkeyword(i)) i += l;else return 0; |
| 7166 |
| 7167 » var atruleName = joinValues2(i - l, l); |
| 7168 » if (atruleName.indexOf('keyframes') === -1) return 0; |
| 7169 |
| 7170 » if (l = checkSC(i)) i += l;else return 0; |
| 7171 |
| 7172 » if (l = checkIdentOrInterpolation(i)) i += l;else return 0; |
| 7173 |
| 7174 » if (l = checkSC(i)) i += l; |
| 7175 |
| 7176 » if (l = checkKeyframesBlocks(i)) i += l;else return 0; |
| 7177 |
| 7178 » return i - start; |
| 7179 » } |
| 7180 |
| 7181 » /** |
| 1465 * @return {Node} | 7182 * @return {Node} |
| 1466 » */function getKeyframesRule(){var type=NodeType.AtruleType;var token=to
kens[pos];var line=token.ln;var column=token.col;var content=[].concat([getAtkey
word()],getSC(),getIdentOrInterpolation(),getSC(),[getKeyframesBlocks()]);return
newNode(type,content,line,column);}function checkKeyframesSelector(i){var start
=i;var l=undefined;if(i >= tokensLength)return 0;if(l = checkIdent(i)){ // Valid
selectors are only `from` and `to`. | 7183 » */ |
| 1467 » var selector=joinValues2(i,l);if(selector !== 'from' && selector !== 'to
')return 0;i += l;tokens[start].keyframesSelectorType = 1;}else if(l = checkPerc
entage(i)){i += l;tokens[start].keyframesSelectorType = 2;}else if(l = checkInte
rpolation(i)){i += l;tokens[start].keyframesSelectorType = 3;}else {return 0;}re
turn i - start;}function getKeyframesSelector(){var keyframesSelectorType=NodeTy
pe.KeyframesSelectorType;var selectorType=NodeType.SelectorType;var token=tokens
[pos];var line=token.ln;var column=token.col;var content=[];if(token.keyframesSe
lectorType === 1){content.push(getIdent());}else if(token.keyframesSelectorType
=== 2){content.push(getPercentage());}else {content.push(getInterpolation());}va
r keyframesSelector=newNode(keyframesSelectorType,content,line,column);return ne
wNode(selectorType,[keyframesSelector],line,column);} /** | 7184 » function getKeyframesRule() { |
| 7185 » var type = NodeType.AtruleType; |
| 7186 » var token = tokens[pos]; |
| 7187 » var line = token.ln; |
| 7188 » var column = token.col; |
| 7189 » var content = [].concat([getAtkeyword()], getSC(), getIdentOrInterpola
tion(), getSC(), [getKeyframesBlocks()]); |
| 7190 |
| 7191 » return newNode(type, content, line, column); |
| 7192 » } |
| 7193 |
| 7194 » /** |
| 7195 » * Check a single keyframe selector - `5%`, `from` etc |
| 7196 » * @param {Number} i |
| 7197 » * @returns {Number} |
| 7198 » */ |
| 7199 » function checkKeyframesSelector(i) { |
| 7200 » var start = i; |
| 7201 » var l = void 0; |
| 7202 |
| 7203 » if (i >= tokensLength) return 0; |
| 7204 |
| 7205 » if (l = checkIdent(i)) { |
| 7206 » // Valid selectors are only `from` and `to`. |
| 7207 » var selector = joinValues2(i, l); |
| 7208 » if (selector !== 'from' && selector !== 'to') return 0; |
| 7209 |
| 7210 » i += l; |
| 7211 » tokens[start].keyframesSelectorType = 1; |
| 7212 » } else if (l = checkPercentage(i)) { |
| 7213 » i += l; |
| 7214 » tokens[start].keyframesSelectorType = 2; |
| 7215 » } else if (l = checkInterpolation(i)) { |
| 7216 » i += l; |
| 7217 » tokens[start].keyframesSelectorType = 3; |
| 7218 » } else { |
| 7219 » return 0; |
| 7220 » } |
| 7221 |
| 7222 » return i - start; |
| 7223 » } |
| 7224 |
| 7225 » /** |
| 7226 » * Get a single keyframe selector |
| 7227 » * @returns {Node} |
| 7228 » */ |
| 7229 » function getKeyframesSelector() { |
| 7230 » var keyframesSelectorType = NodeType.KeyframesSelectorType; |
| 7231 » var selectorType = NodeType.SelectorType; |
| 7232 |
| 7233 » var token = tokens[pos]; |
| 7234 » var line = token.ln; |
| 7235 » var column = token.col; |
| 7236 » var content = []; |
| 7237 |
| 7238 » if (token.keyframesSelectorType === 1) { |
| 7239 » content.push(getIdent()); |
| 7240 » } else if (token.keyframesSelectorType === 2) { |
| 7241 » content.push(getPercentage()); |
| 7242 » } else if (token.keyframesSelectorType === 3) { |
| 7243 » content.push(getInterpolation()); |
| 7244 » } |
| 7245 |
| 7246 » var keyframesSelector = newNode(keyframesSelectorType, content, line,
column); |
| 7247 » return newNode(selectorType, [keyframesSelector], line, column); |
| 7248 » } |
| 7249 |
| 7250 » /** |
| 7251 » * Check the keyframe's selector groups |
| 7252 » * @param {Number} i |
| 7253 » * @returns {Number} |
| 7254 » */ |
| 7255 » function checkKeyframesSelectorsGroup(i) { |
| 7256 » var start = i; |
| 7257 » var l = void 0; |
| 7258 |
| 7259 » if (l = checkKeyframesSelector(i)) i += l;else return 0; |
| 7260 |
| 7261 » while (i < tokensLength) { |
| 7262 » var sb = checkSC(i); |
| 7263 » var c = checkDelim(i + sb); |
| 7264 » if (!c) break; |
| 7265 » var sa = checkSC(i + sb + c); |
| 7266 » if (l = checkKeyframesSelector(i + sb + c + sa)) i += sb + c + sa +
l;else break; |
| 7267 » } |
| 7268 |
| 7269 » tokens[start].selectorsGroupEnd = i; |
| 7270 |
| 7271 » return i - start; |
| 7272 » } |
| 7273 |
| 7274 » /** |
| 7275 » * Get the keyframe's selector groups |
| 7276 » * @returns {Array} An array of keyframe selectors |
| 7277 » */ |
| 7278 » function getKeyframesSelectorsGroup() { |
| 7279 » var selectorsGroup = []; |
| 7280 » var selectorsGroupEnd = tokens[pos].selectorsGroupEnd; |
| 7281 |
| 7282 » selectorsGroup.push(getKeyframesSelector()); |
| 7283 |
| 7284 » while (pos < selectorsGroupEnd) { |
| 7285 » selectorsGroup = selectorsGroup.concat(getSC()); |
| 7286 » selectorsGroup.push(getDelim()); |
| 7287 » selectorsGroup = selectorsGroup.concat(getSC()); |
| 7288 » selectorsGroup.push(getKeyframesSelector()); |
| 7289 » } |
| 7290 |
| 7291 » return selectorsGroup; |
| 7292 » } |
| 7293 |
| 7294 » /** |
| 1468 * Check if token is part of a loop. | 7295 * Check if token is part of a loop. |
| 1469 * @param {Number} i Token's index number | 7296 * @param {Number} i Token's index number |
| 1470 * @returns {Number} Length of the loop | 7297 * @returns {Number} Length of the loop |
| 1471 » */function checkLoop(i){var start=i;var l=undefined;if(i >= tokensLengt
h)return 0;if(l = checkAtkeyword(i))i += l;else return 0;if(['for','each','while
'].indexOf(tokens[start + 1].value) < 0)return 0;while(i < tokensLength) {if(l =
checkBlock(i)){i += l;break;}else if(l = checkVariable(i) || checkNumber(i) ||
checkInterpolation(i) || checkIdent(i) || checkSC(i) || checkOperator(i) || chec
kCombinator(i) || checkString(i))i += l;else return 0;}return i - start;} /** | 7298 » */ |
| 7299 » function checkLoop(i) { |
| 7300 » var start = i; |
| 7301 » var l = void 0; |
| 7302 |
| 7303 » if (i >= tokensLength) return 0; |
| 7304 |
| 7305 » if (l = checkAtkeyword(i)) i += l;else return 0; |
| 7306 |
| 7307 » if (['for', 'each', 'while'].indexOf(tokens[start + 1].value) < 0) ret
urn 0; |
| 7308 |
| 7309 » while (i < tokensLength) { |
| 7310 » if (l = checkBlock(i)) { |
| 7311 » i += l; |
| 7312 » break; |
| 7313 » } else if (l = checkVariable(i) || checkNumber(i) || checkInterpolat
ion(i) || checkIdent(i) || checkSC(i) || checkOperator(i) || checkCombinator(i)
|| checkString(i)) i += l;else return 0; |
| 7314 » } |
| 7315 |
| 7316 » return i - start; |
| 7317 » } |
| 7318 |
| 7319 » /** |
| 1472 * Get node with a loop. | 7320 * Get node with a loop. |
| 1473 * @returns {Array} `['loop', x]` | 7321 * @returns {Array} `['loop', x]` |
| 1474 » */function getLoop(){var startPos=pos;var x=[];x.push(getAtkeyword());w
hile(pos < tokensLength) {if(checkBlock(pos)){x.push(getBlock());break;}else if(
checkVariable(pos))x.push(getVariable());else if(checkNumber(pos))x.push(getNumb
er());else if(checkInterpolation(pos))x.push(getInterpolation());else if(checkId
ent(pos))x.push(getIdent());else if(checkOperator(pos))x.push(getOperator());els
e if(checkCombinator(pos))x.push(getCombinator());else if(checkSC(pos))x = x.con
cat(getSC());else if(checkString(pos))x.push(getString());}var token=tokens[star
tPos];return newNode(NodeType.LoopType,x,token.ln,token.col);} /** | 7322 » */ |
| 7323 » function getLoop() { |
| 7324 » var startPos = pos; |
| 7325 » var x = []; |
| 7326 |
| 7327 » x.push(getAtkeyword()); |
| 7328 |
| 7329 » while (pos < tokensLength) { |
| 7330 » if (checkBlock(pos)) { |
| 7331 » x.push(getBlock()); |
| 7332 » break; |
| 7333 » } else if (checkVariable(pos)) x.push(getVariable());else if (checkN
umber(pos)) x.push(getNumber());else if (checkInterpolation(pos)) x.push(getInte
rpolation());else if (checkIdent(pos)) x.push(getIdent());else if (checkOperator
(pos)) x.push(getOperator());else if (checkCombinator(pos)) x.push(getCombinator
());else if (checkSC(pos)) x = x.concat(getSC());else if (checkString(pos)) x.pu
sh(getString()); |
| 7334 » } |
| 7335 |
| 7336 » var token = tokens[startPos]; |
| 7337 » return newNode(NodeType.LoopType, x, token.ln, token.col); |
| 7338 » } |
| 7339 |
| 7340 » /** |
| 1475 * Check if token is part of a mixin | 7341 * Check if token is part of a mixin |
| 1476 * @param {Number} i Token's index number | 7342 * @param {Number} i Token's index number |
| 1477 * @returns {Number} Length of the mixin | 7343 * @returns {Number} Length of the mixin |
| 1478 » */function checkMixin(i){var start=i;var l=undefined;if(i >= tokensLeng
th)return 0;if((l = checkAtkeyword(i)) && tokens[i + 1].value === 'mixin')i += l
;else return 0;if(l = checkSC(i))i += l;if(l = checkIdentOrInterpolation(i))i +=
l;else return 0;if(l = checkSC(i))i += l;if(l = checkArguments(i))i += l;if(l =
checkSC(i))i += l;if(l = checkBlock(i))i += l;else return 0;return i - start;}
/** | 7344 » */ |
| 7345 » function checkMixin(i) { |
| 7346 » var start = i; |
| 7347 » var l = void 0; |
| 7348 |
| 7349 » if (i >= tokensLength) return 0; |
| 7350 |
| 7351 » if ((l = checkAtkeyword(i)) && tokens[i + 1].value === 'mixin') i += l
;else return 0; |
| 7352 |
| 7353 » if (l = checkSC(i)) i += l; |
| 7354 |
| 7355 » if (l = checkIdentOrInterpolation(i)) i += l;else return 0; |
| 7356 |
| 7357 » if (l = checkSC(i)) i += l; |
| 7358 |
| 7359 » if (l = checkArguments(i)) i += l; |
| 7360 |
| 7361 » if (l = checkSC(i)) i += l; |
| 7362 |
| 7363 » if (l = checkBlock(i)) i += l;else return 0; |
| 7364 |
| 7365 » return i - start; |
| 7366 » } |
| 7367 |
| 7368 » /** |
| 1479 * Get node with a mixin | 7369 * Get node with a mixin |
| 1480 * @returns {Array} `['mixin', x]` | 7370 * @returns {Array} `['mixin', x]` |
| 1481 » */function getMixin(){var startPos=pos;var x=[getAtkeyword()];x = x.con
cat(getSC());if(checkIdentOrInterpolation(pos))x = x.concat(getIdentOrInterpolat
ion());x = x.concat(getSC());if(checkArguments(pos))x.push(getArguments());x = x
.concat(getSC());if(checkBlock(pos))x.push(getBlock());var token=tokens[startPos
];return newNode(NodeType.MixinType,x,token.ln,token.col);} /** | 7371 » */ |
| 7372 » function getMixin() { |
| 7373 » var startPos = pos; |
| 7374 » var x = [getAtkeyword()]; |
| 7375 |
| 7376 » x = x.concat(getSC()); |
| 7377 |
| 7378 » if (checkIdentOrInterpolation(pos)) x = x.concat(getIdentOrInterpolati
on()); |
| 7379 |
| 7380 » x = x.concat(getSC()); |
| 7381 |
| 7382 » if (checkArguments(pos)) x.push(getArguments()); |
| 7383 |
| 7384 » x = x.concat(getSC()); |
| 7385 |
| 7386 » if (checkBlock(pos)) x.push(getBlock()); |
| 7387 |
| 7388 » var token = tokens[startPos]; |
| 7389 » return newNode(NodeType.MixinType, x, token.ln, token.col); |
| 7390 » } |
| 7391 |
| 7392 » /** |
| 1482 * Check if token is a namespace sign (`|`) | 7393 * Check if token is a namespace sign (`|`) |
| 1483 * @param {Number} i Token's index number | 7394 * @param {Number} i Token's index number |
| 1484 * @returns {Number} `1` if token is `|`, `0` if not | 7395 * @returns {Number} `1` if token is `|`, `0` if not |
| 1485 » */function checkNamespace(i){return i < tokensLength && tokens[i].type
=== TokenType.VerticalLine?1:0;} /** | 7396 » */ |
| 7397 » function checkNamespace(i) { |
| 7398 » return i < tokensLength && tokens[i].type === TokenType.VerticalLine ?
1 : 0; |
| 7399 » } |
| 7400 |
| 7401 » /** |
| 1486 * Get node with a namespace sign | 7402 * Get node with a namespace sign |
| 1487 * @returns {Array} `['namespace']` | 7403 * @returns {Array} `['namespace']` |
| 1488 » */function getNamespace(){var startPos=pos;pos++;var token=tokens[start
Pos];return newNode(NodeType.NamespaceType,'|',token.ln,token.col);} /** | 7404 » */ |
| 7405 » function getNamespace() { |
| 7406 » var startPos = pos; |
| 7407 |
| 7408 » pos++; |
| 7409 |
| 7410 » var token = tokens[startPos]; |
| 7411 » return newNode(NodeType.NamespaceType, '|', token.ln, token.col); |
| 7412 » } |
| 7413 |
| 7414 » /** |
| 1489 * @param {Number} i Token's index number | 7415 * @param {Number} i Token's index number |
| 1490 * @returns {Number} | 7416 * @returns {Number} |
| 1491 » */function checkNmName2(i){if(tokens[i].type === TokenType.Identifier)r
eturn 1;else if(tokens[i].type !== TokenType.DecimalNumber)return 0;i++;return i
< tokensLength && tokens[i].type === TokenType.Identifier?2:1;} /** | 7417 » */ |
| 7418 » function checkNmName2(i) { |
| 7419 » if (tokens[i].type === TokenType.Identifier) return 1;else if (tokens[
i].type !== TokenType.DecimalNumber) return 0; |
| 7420 |
| 7421 » i++; |
| 7422 |
| 7423 » return i < tokensLength && tokens[i].type === TokenType.Identifier ? 2
: 1; |
| 7424 » } |
| 7425 |
| 7426 » /** |
| 1492 * @returns {String} | 7427 * @returns {String} |
| 1493 » */function getNmName2(){var s=tokens[pos].value;if(tokens[pos++].type =
== TokenType.DecimalNumber && pos < tokensLength && tokens[pos].type === TokenTy
pe.Identifier)s += tokens[pos++].value;return s;} /** | 7428 » */ |
| 7429 » function getNmName2() { |
| 7430 » var s = tokens[pos].value; |
| 7431 |
| 7432 » if (tokens[pos++].type === TokenType.DecimalNumber && pos < tokensLeng
th && tokens[pos].type === TokenType.Identifier) s += tokens[pos++].value; |
| 7433 |
| 7434 » return s; |
| 7435 » } |
| 7436 |
| 7437 » /** |
| 1494 * Check if token is part of a number | 7438 * Check if token is part of a number |
| 1495 * @param {Number} i Token's index number | 7439 * @param {Number} i Token's index number |
| 1496 * @returns {Number} Length of number | 7440 * @returns {Number} Length of number |
| 1497 » */function checkNumber(i){if(i >= tokensLength)return 0;if(tokens[i].nu
mber_l)return tokens[i].number_l; // `10`: | 7441 » */ |
| 1498 » if(i < tokensLength && tokens[i].type === TokenType.DecimalNumber && (!t
okens[i + 1] || tokens[i + 1] && tokens[i + 1].type !== TokenType.FullStop))retu
rn tokens[i].number_l = 1,tokens[i].number_l; // `10.`: | 7442 » function checkNumber(i) { |
| 1499 » if(i < tokensLength && tokens[i].type === TokenType.DecimalNumber && tok
ens[i + 1] && tokens[i + 1].type === TokenType.FullStop && (!tokens[i + 2] || to
kens[i + 2].type !== TokenType.DecimalNumber))return tokens[i].number_l = 2,toke
ns[i].number_l; // `.10`: | 7443 » if (i >= tokensLength) return 0; |
| 1500 » if(i < tokensLength && tokens[i].type === TokenType.FullStop && tokens[i
+ 1].type === TokenType.DecimalNumber)return tokens[i].number_l = 2,tokens[i].n
umber_l; // `10.10`: | 7444 |
| 1501 » if(i < tokensLength && tokens[i].type === TokenType.DecimalNumber && tok
ens[i + 1] && tokens[i + 1].type === TokenType.FullStop && tokens[i + 2] && toke
ns[i + 2].type === TokenType.DecimalNumber)return tokens[i].number_l = 3,tokens[
i].number_l;return 0;} /** | 7445 » if (tokens[i].number_l) return tokens[i].number_l; |
| 7446 |
| 7447 » // `10`: |
| 7448 » if (i < tokensLength && tokens[i].type === TokenType.DecimalNumber &&
(!tokens[i + 1] || tokens[i + 1] && tokens[i + 1].type !== TokenType.FullStop))
{ |
| 7449 » tokens[i].number_l = 1; |
| 7450 » return 1; |
| 7451 » } |
| 7452 |
| 7453 » // `10.`: |
| 7454 » if (i < tokensLength && tokens[i].type === TokenType.DecimalNumber &&
tokens[i + 1] && tokens[i + 1].type === TokenType.FullStop && (!tokens[i + 2] ||
tokens[i + 2].type !== TokenType.DecimalNumber)) { |
| 7455 » tokens[i].number_l = 2; |
| 7456 » return 2; |
| 7457 » } |
| 7458 |
| 7459 » // `.10`: |
| 7460 » if (i < tokensLength && tokens[i].type === TokenType.FullStop && token
s[i + 1].type === TokenType.DecimalNumber) { |
| 7461 » tokens[i].number_l = 2; |
| 7462 » return 2; |
| 7463 » } |
| 7464 |
| 7465 » // `10.10`: |
| 7466 » if (i < tokensLength && tokens[i].type === TokenType.DecimalNumber &&
tokens[i + 1] && tokens[i + 1].type === TokenType.FullStop && tokens[i + 2] && t
okens[i + 2].type === TokenType.DecimalNumber) { |
| 7467 » tokens[i].number_l = 3; |
| 7468 » return 3; |
| 7469 » } |
| 7470 |
| 7471 » return 0; |
| 7472 » } |
| 7473 |
| 7474 » /** |
| 1502 * Get node with number | 7475 * Get node with number |
| 1503 * @returns {Array} `['number', x]` where `x` is a number converted | 7476 * @returns {Array} `['number', x]` where `x` is a number converted |
| 1504 * to string. | 7477 * to string. |
| 1505 » */function getNumber(){var s='';var startPos=pos;var l=tokens[pos].numb
er_l;for(var j=0;j < l;j++) {s += tokens[pos + j].value;}pos += l;var token=toke
ns[startPos];return newNode(NodeType.NumberType,s,token.ln,token.col);} /** | 7478 » */ |
| 7479 » function getNumber() { |
| 7480 » var s = ''; |
| 7481 » var startPos = pos; |
| 7482 » var l = tokens[pos].number_l; |
| 7483 |
| 7484 » for (var j = 0; j < l; j++) { |
| 7485 » s += tokens[pos + j].value; |
| 7486 » } |
| 7487 |
| 7488 » pos += l; |
| 7489 |
| 7490 » var token = tokens[startPos]; |
| 7491 » return newNode(NodeType.NumberType, s, token.ln, token.col); |
| 7492 » } |
| 7493 |
| 7494 » /** |
| 1506 * Check if token is an operator (`/`, `%`, `,`, `:` or `=`). | 7495 * Check if token is an operator (`/`, `%`, `,`, `:` or `=`). |
| 1507 * @param {Number} i Token's index number | 7496 * @param {Number} i Token's index number |
| 1508 * @returns {Number} `1` if token is an operator, otherwise `0` | 7497 * @returns {Number} `1` if token is an operator, otherwise `0` |
| 1509 » */function checkOperator(i){if(i >= tokensLength)return 0;switch(tokens
[i].type){case TokenType.Solidus:case TokenType.PercentSign:case TokenType.Comma
:case TokenType.Colon:case TokenType.EqualsSign:case TokenType.EqualitySign:case
TokenType.InequalitySign:case TokenType.LessThanSign:case TokenType.GreaterThan
Sign:case TokenType.Asterisk:return 1;}return 0;} /** | 7498 » */ |
| 7499 » function checkOperator(i) { |
| 7500 » if (i >= tokensLength) return 0; |
| 7501 |
| 7502 » switch (tokens[i].type) { |
| 7503 » case TokenType.Solidus: |
| 7504 » case TokenType.PercentSign: |
| 7505 » case TokenType.Comma: |
| 7506 » case TokenType.Colon: |
| 7507 » case TokenType.EqualsSign: |
| 7508 » case TokenType.EqualitySign: |
| 7509 » case TokenType.InequalitySign: |
| 7510 » case TokenType.LessThanSign: |
| 7511 » case TokenType.GreaterThanSign: |
| 7512 » case TokenType.Asterisk: |
| 7513 » return 1; |
| 7514 » } |
| 7515 |
| 7516 » return 0; |
| 7517 » } |
| 7518 |
| 7519 » /** |
| 1510 * Get node with an operator | 7520 * Get node with an operator |
| 1511 * @returns {Array} `['operator', x]` where `x` is an operator converted | 7521 * @returns {Array} `['operator', x]` where `x` is an operator converted |
| 1512 * to string. | 7522 * to string. |
| 1513 » */function getOperator(){var startPos=pos;var x=tokens[pos++].value;var
token=tokens[startPos];return newNode(NodeType.OperatorType,x,token.ln,token.co
l);} /** | 7523 » */ |
| 7524 » function getOperator() { |
| 7525 » var startPos = pos; |
| 7526 » var x = tokens[pos++].value; |
| 7527 |
| 7528 » var token = tokens[startPos]; |
| 7529 » return newNode(NodeType.OperatorType, x, token.ln, token.col); |
| 7530 » } |
| 7531 |
| 7532 » /** |
| 1514 * Check if token is part of `!optional` word | 7533 * Check if token is part of `!optional` word |
| 1515 * @param {Number} i Token's index number | 7534 * @param {Number} i Token's index number |
| 1516 * @returns {Number} | 7535 * @returns {Number} |
| 1517 » */function checkOptional(i){var start=i;var l=undefined;if(i >= tokensL
ength || tokens[i++].type !== TokenType.ExclamationMark)return 0;if(l = checkSC(
i))i += l;if(tokens[i].value === 'optional'){tokens[start].optionalEnd = i;retur
n i - start + 1;}else {return 0;}} /** | 7536 » */ |
| 7537 » function checkOptional(i) { |
| 7538 » var start = i; |
| 7539 » var l = void 0; |
| 7540 |
| 7541 » if (i >= tokensLength || tokens[i++].type !== TokenType.ExclamationMar
k) return 0; |
| 7542 |
| 7543 » if (l = checkSC(i)) i += l; |
| 7544 |
| 7545 » if (tokens[i].value === 'optional') { |
| 7546 » tokens[start].optionalEnd = i; |
| 7547 » return i - start + 1; |
| 7548 » } else { |
| 7549 » return 0; |
| 7550 » } |
| 7551 » } |
| 7552 |
| 7553 » /** |
| 1518 * Get node with `!optional` word | 7554 * Get node with `!optional` word |
| 1519 » */function getOptional(){var token=tokens[pos];var line=token.ln;var co
lumn=token.col;var content=joinValues(pos,token.optionalEnd);pos = token.optiona
lEnd + 1;return newNode(NodeType.OptionalType,content,line,column);} /** | 7555 » */ |
| 7556 » function getOptional() { |
| 7557 » var token = tokens[pos]; |
| 7558 » var line = token.ln; |
| 7559 » var column = token.col; |
| 7560 » var content = joinValues(pos, token.optionalEnd); |
| 7561 |
| 7562 » pos = token.optionalEnd + 1; |
| 7563 |
| 7564 » return newNode(NodeType.OptionalType, content, line, column); |
| 7565 » } |
| 7566 |
| 7567 » /** |
| 1520 * Check if token is part of text inside parentheses, e.g. `(1)` | 7568 * Check if token is part of text inside parentheses, e.g. `(1)` |
| 1521 * @param {Number} i Token's index number | 7569 * @param {Number} i Token's index number |
| 1522 * @return {Number} | 7570 * @return {Number} |
| 1523 » */function checkParentheses(i){if(i >= tokensLength || tokens[i].type !
== TokenType.LeftParenthesis)return 0;return tokens[i].right - i + 1;} /** | 7571 » */ |
| 7572 » function checkParentheses(i) { |
| 7573 » if (i >= tokensLength) return 0; |
| 7574 |
| 7575 » var start = i; |
| 7576 » var right = tokens[i].right; |
| 7577 |
| 7578 » if (tokens[i].type === TokenType.LeftParenthesis) i++;else return 0; |
| 7579 |
| 7580 » if (i < right) { |
| 7581 » var l = checkTsets(i); |
| 7582 » if (l) i += l;else return 0; |
| 7583 » } |
| 7584 |
| 7585 » i++; |
| 7586 |
| 7587 » return i - start; |
| 7588 » } |
| 7589 |
| 7590 » /** |
| 1524 * Get node with text inside parentheses, e.g. `(1)` | 7591 * Get node with text inside parentheses, e.g. `(1)` |
| 1525 * @return {Node} | 7592 * @return {Node} |
| 1526 » */function getParentheses(){var type=NodeType.ParenthesesType;var token
=tokens[pos];var line=token.ln;var column=token.col;pos++;var tsets=getTsets();v
ar end=getLastPosition(tsets,line,column,1);pos++;return newNode(type,tsets,line
,column,end);} /** | 7593 » */ |
| 1527 » * Check if token is a parent selector (`&`). | 7594 » function getParentheses() { |
| 7595 » var type = NodeType.ParenthesesType; |
| 7596 » var token = tokens[pos]; |
| 7597 » var line = token.ln; |
| 7598 » var column = token.col; |
| 7599 » var tsets = []; |
| 7600 » var right = token.right; |
| 7601 |
| 7602 » pos++; |
| 7603 |
| 7604 » if (pos < right) { |
| 7605 » tsets = getTsets(); |
| 7606 » } |
| 7607 |
| 7608 » var end = getLastPosition(tsets, line, column, 1); |
| 7609 » pos++; |
| 7610 |
| 7611 » return newNode(type, tsets, line, column, end); |
| 7612 » } |
| 7613 |
| 7614 » /** |
| 7615 » * Check if token is a parent selector, e.g. `&` |
| 7616 » * @param {number} i Token's index number |
| 7617 » * @return {number} |
| 7618 » */ |
| 7619 » function checkParentSelector(i) { |
| 7620 » return i < tokensLength && tokens[i].type === TokenType.Ampersand ? 1
: 0; |
| 7621 » } |
| 7622 |
| 7623 » /** |
| 7624 » * Get node with a parent selector |
| 7625 » * @return {Node} |
| 7626 » */ |
| 7627 » function getParentSelector() { |
| 7628 » var startPos = pos; |
| 7629 » var token = tokens[startPos]; |
| 7630 |
| 7631 » pos++; |
| 7632 |
| 7633 » return newNode(NodeType.ParentSelectorType, '&', token.ln, token.col); |
| 7634 » } |
| 7635 |
| 7636 » /** |
| 7637 » * Check if token is a parent selector extension, e.g. `&--foo-bar` |
| 7638 » * @param {number} i Token's index number |
| 7639 » * @returns {number} Length of the parent selector extension |
| 7640 » */ |
| 7641 » function checkParentSelectorExtension(i) { |
| 7642 » var start = i; |
| 7643 » var l = void 0; |
| 7644 |
| 7645 » if (i >= tokensLength) return 0; |
| 7646 |
| 7647 » while (i < tokensLength) { |
| 7648 » if (l = checkIdentOrInterpolation(i) || checkPartialIdent(i)) i += l
;else break; |
| 7649 » } |
| 7650 |
| 7651 » return i - start; |
| 7652 » } |
| 7653 |
| 7654 » /** |
| 7655 » * Get parent selector extension node |
| 7656 » * @return {Node} |
| 7657 » */ |
| 7658 » function getParentSelectorExtension() { |
| 7659 » var type = NodeType.ParentSelectorExtensionType; |
| 7660 » var token = tokens[pos]; |
| 7661 » var line = token.ln; |
| 7662 » var column = token.col; |
| 7663 » var content = []; |
| 7664 |
| 7665 » while (pos < tokensLength) { |
| 7666 » if (checkIdentOrInterpolation(pos)) { |
| 7667 » content = content.concat(getIdentOrInterpolation()); |
| 7668 » } else if (checkPartialIdent(pos)) { |
| 7669 » content.push(getIdent()); |
| 7670 » } else break; |
| 7671 » } |
| 7672 |
| 7673 » return newNode(type, content, line, column); |
| 7674 » } |
| 7675 |
| 7676 » /** |
| 7677 » * Check if token is a parent selector with an extension or not |
| 7678 » * @param {number} i Token's index number |
| 7679 » * @return {number} Length of the parent selector and extension if appli
cable |
| 7680 » */ |
| 7681 » function checkParentSelectorWithExtension(i) { |
| 7682 » var start = i; |
| 7683 » var l = void 0; |
| 7684 |
| 7685 » if (i >= tokensLength) return 0; |
| 7686 |
| 7687 » if (l = checkParentSelector(i)) i += l;else return 0; |
| 7688 |
| 7689 » if (l = checkParentSelectorExtension(i)) i += l; |
| 7690 |
| 7691 » return i - start; |
| 7692 » } |
| 7693 |
| 7694 » /** |
| 7695 » * Get parent selector node and extension node if applicable |
| 7696 » * @return {Array} |
| 7697 » */ |
| 7698 » function getParentSelectorWithExtension() { |
| 7699 » var content = [getParentSelector()]; |
| 7700 |
| 7701 » if (checkParentSelectorExtension(pos)) content.push(getParentSelectorE
xtension()); |
| 7702 |
| 7703 » return content; |
| 7704 » } |
| 7705 |
| 7706 » /** |
| 7707 » * Check if token is part of a number or an interpolation with a percent
sign |
| 7708 » * (e.g. `10%`). |
| 1528 * @param {Number} i Token's index number | 7709 * @param {Number} i Token's index number |
| 1529 * @returns {Number} | 7710 * @returns {Number} |
| 1530 » */function checkParentSelector(i){return i < tokensLength && tokens[i].
type === TokenType.Ampersand?1:0;} /** | 7711 » */ |
| 1531 » * Get node with a parent selector | 7712 » function checkPercentage(i) { |
| 1532 » */function getParentSelector(){var startPos=pos;pos++;var token=tokens[
startPos];return newNode(NodeType.ParentSelectorType,'&',token.ln,token.col);}fu
nction checkParentSelectorExtension(i){if(i >= tokensLength)return 0;var start=i
;var l=undefined;while(i < tokensLength) {if(l = checkNumber(i) || checkIdentOrI
nterpolation(i))i += l;else break;}return i - start;}function getParentSelectorE
xtension(){var type=NodeType.ParentSelectorExtensionType;var token=tokens[pos];v
ar line=token.ln;var column=token.col;var content=[];while(pos < tokensLength) {
if(checkNumber(pos))content.push(getNumber());else if(checkIdentOrInterpolation(
pos))content = content.concat(getIdentOrInterpolation());else break;}return newN
ode(type,content,line,column);}function checkParentSelectorWithExtension(i){if(i
>= tokensLength)return 0;var start=i;var l=undefined;if(l = checkParentSelector
(i))i += l;else return 0;if(l = checkParentSelectorExtension(i))i += l;return i
- start;}function getParentSelectorWithExtension(){var content=[getParentSelecto
r()];if(checkParentSelectorExtension(pos))content.push(getParentSelectorExtensio
n());return content;} /** | 7713 » var start = i; |
| 1533 » * Check if token is part of a number with percent sign (e.g. `10%`) | 7714 » var l = void 0; |
| 7715 |
| 7716 » if (i >= tokensLength) return 0; |
| 7717 |
| 7718 » if (l = checkNumberOrInterpolation(i)) i += l;else return 0; |
| 7719 |
| 7720 » if (i >= tokensLength) return 0; |
| 7721 |
| 7722 » if (tokens[i].type !== TokenType.PercentSign) return 0; |
| 7723 |
| 7724 » return i - start + 1; |
| 7725 » } |
| 7726 |
| 7727 » /** |
| 7728 » * Get a percentage node that contains either a number or an interpolati
on |
| 7729 » * @returns {Object} The percentage node |
| 7730 » */ |
| 7731 » function getPercentage() { |
| 7732 » var startPos = pos; |
| 7733 » var token = tokens[startPos]; |
| 7734 » var line = token.ln; |
| 7735 » var column = token.col; |
| 7736 » var content = getNumberOrInterpolation(); |
| 7737 » var end = getLastPosition(content, line, column, 1); |
| 7738 |
| 7739 » // Skip % |
| 7740 » pos++; |
| 7741 |
| 7742 » return newNode(NodeType.PercentageType, content, token.ln, token.col,
end); |
| 7743 » } |
| 7744 |
| 7745 » /** |
| 7746 » * Check if token is a number or an interpolation |
| 1534 * @param {Number} i Token's index number | 7747 * @param {Number} i Token's index number |
| 1535 * @returns {Number} | 7748 * @returns {Number} |
| 1536 » */function checkPercentage(i){var x;if(i >= tokensLength)return 0;x = c
heckNumber(i);if(!x || i + x >= tokensLength)return 0;return tokens[i + x].type
=== TokenType.PercentSign?x + 1:0;} /** | 7749 » */ |
| 1537 » * Get node of number with percent sign | 7750 » function checkNumberOrInterpolation(i) { |
| 1538 » * @returns {Array} `['percentage', ['number', x]]` where `x` is a numbe
r | 7751 » var start = i; |
| 1539 » * (without percent sign) converted to string. | 7752 » var l = void 0; |
| 1540 » */function getPercentage(){var startPos=pos;var x=[getNumber()];var tok
en=tokens[startPos];var line=token.ln;var column=token.col;var end=getLastPositi
on(x,line,column,1);pos++;return newNode(NodeType.PercentageType,x,token.ln,toke
n.col,end);} /** | 7753 |
| 7754 » while (i < tokensLength) { |
| 7755 » if (l = checkInterpolation(i) || checkNumber(i)) i += l;else break; |
| 7756 » } |
| 7757 |
| 7758 » return i - start; |
| 7759 » } |
| 7760 |
| 7761 » /** |
| 7762 » * Get a number and/or interpolation node |
| 7763 » * @returns {Array} An array containing a single or multiple nodes |
| 7764 » */ |
| 7765 » function getNumberOrInterpolation() { |
| 7766 » var content = []; |
| 7767 |
| 7768 » while (pos < tokensLength) { |
| 7769 » if (checkInterpolation(pos)) content.push(getInterpolation());else i
f (checkNumber(pos)) content.push(getNumber());else break; |
| 7770 » } |
| 7771 |
| 7772 » return content; |
| 7773 » } |
| 7774 |
| 7775 » /** |
| 1541 * Check if token is part of a placeholder selector (e.g. `%abc`). | 7776 * Check if token is part of a placeholder selector (e.g. `%abc`). |
| 1542 * @param {Number} i Token's index number | 7777 * @param {Number} i Token's index number |
| 1543 * @returns {Number} Length of the selector | 7778 * @returns {Number} Length of the selector |
| 1544 » */function checkPlaceholder(i){var l;if(i >= tokensLength)return 0;if(t
okens[i].placeholder_l)return tokens[i].placeholder_l;if(tokens[i].type === Toke
nType.PercentSign && (l = checkIdentOrInterpolation(i + 1))){tokens[i].placehold
er_l = l + 1;return l + 1;}else return 0;} /** | 7779 » */ |
| 7780 » function checkPlaceholder(i) { |
| 7781 » var l; |
| 7782 |
| 7783 » if (i >= tokensLength) return 0; |
| 7784 |
| 7785 » if (tokens[i].placeholder_l) return tokens[i].placeholder_l; |
| 7786 |
| 7787 » if (tokens[i].type !== TokenType.PercentSign) return 0; |
| 7788 |
| 7789 » if (l = checkIdentOrInterpolation(i + 1)) { |
| 7790 » tokens[i].placeholder_l = l + 1; |
| 7791 » return l + 1; |
| 7792 » } else return 0; |
| 7793 » } |
| 7794 |
| 7795 » /** |
| 1545 * Get node with a placeholder selector | 7796 * Get node with a placeholder selector |
| 1546 * @returns {Array} `['placeholder', ['ident', x]]` where x is a placeho
lder's | 7797 * @returns {Array} `['placeholder', ['ident', x]]` where x is a placeho
lder's |
| 1547 * identifier (without `%`, e.g. `abc`). | 7798 * identifier (without `%`, e.g. `abc`). |
| 1548 » */function getPlaceholder(){var startPos=pos;pos++;var x=getIdentOrInte
rpolation();var token=tokens[startPos];return newNode(NodeType.PlaceholderType,x
,token.ln,token.col);} /** | 7799 » */ |
| 7800 » function getPlaceholder() { |
| 7801 » var startPos = pos; |
| 7802 |
| 7803 » pos++; |
| 7804 |
| 7805 » var x = getIdentOrInterpolation(); |
| 7806 |
| 7807 » var token = tokens[startPos]; |
| 7808 » return newNode(NodeType.PlaceholderType, x, token.ln, token.col); |
| 7809 » } |
| 7810 |
| 7811 » /** |
| 1549 * @param {Number} i Token's index number | 7812 * @param {Number} i Token's index number |
| 1550 * @returns {Number} | 7813 * @returns {Number} |
| 1551 » */function checkProgid(i){var start=i;var l=undefined;if(i >= tokensLen
gth)return 0;if(joinValues2(i,6) === 'progid:DXImageTransform.Microsoft.')i += 6
;else return 0;if(l = checkIdentOrInterpolation(i))i += l;else return 0;if(l = c
heckSC(i))i += l;if(tokens[i].type === TokenType.LeftParenthesis){tokens[start].
progid_end = tokens[i].right;i = tokens[i].right + 1;}else return 0;return i - s
tart;} /** | 7814 » */ |
| 7815 » function checkProgid(i) { |
| 7816 » var start = i; |
| 7817 » var l = void 0; |
| 7818 |
| 7819 » if (i >= tokensLength) return 0; |
| 7820 |
| 7821 » if (joinValues2(i, 6) === 'progid:DXImageTransform.Microsoft.') i += 6
;else return 0; |
| 7822 |
| 7823 » if (l = checkIdentOrInterpolation(i)) i += l;else return 0; |
| 7824 |
| 7825 » if (l = checkSC(i)) i += l; |
| 7826 |
| 7827 » if (tokens[i].type === TokenType.LeftParenthesis) { |
| 7828 » tokens[start].progid_end = tokens[i].right; |
| 7829 » i = tokens[i].right + 1; |
| 7830 » } else return 0; |
| 7831 |
| 7832 » return i - start; |
| 7833 » } |
| 7834 |
| 7835 » /** |
| 1552 * @returns {Array} | 7836 * @returns {Array} |
| 1553 » */function getProgid(){var startPos=pos;var progid_end=tokens[pos].prog
id_end;var x=joinValues(pos,progid_end);pos = progid_end + 1;var token=tokens[st
artPos];return newNode(NodeType.ProgidType,x,token.ln,token.col);} /** | 7837 » */ |
| 7838 » function getProgid() { |
| 7839 » var startPos = pos; |
| 7840 » var progid_end = tokens[pos].progid_end; |
| 7841 » var x = joinValues(pos, progid_end); |
| 7842 |
| 7843 » pos = progid_end + 1; |
| 7844 |
| 7845 » var token = tokens[startPos]; |
| 7846 » return newNode(NodeType.ProgidType, x, token.ln, token.col); |
| 7847 » } |
| 7848 |
| 7849 » /** |
| 1554 * Check if token is part of a property | 7850 * Check if token is part of a property |
| 1555 * @param {Number} i Token's index number | 7851 * @param {Number} i Token's index number |
| 1556 * @returns {Number} Length of the property | 7852 * @returns {Number} Length of the property |
| 1557 » */function checkProperty(i){var start=i;var l=undefined;if(i >= tokensL
ength)return 0;if(l = checkVariable(i) || checkIdentOrInterpolation(i))i += l;el
se return 0;return i - start;} /** | 7853 » */ |
| 7854 » function checkProperty(i) { |
| 7855 » var start = i; |
| 7856 » var l = void 0; |
| 7857 |
| 7858 » if (i >= tokensLength) return 0; |
| 7859 |
| 7860 » if (l = checkVariable(i) || checkIdentOrInterpolation(i)) i += l;else
return 0; |
| 7861 |
| 7862 » return i - start; |
| 7863 » } |
| 7864 |
| 7865 » /** |
| 1558 * Get node with a property | 7866 * Get node with a property |
| 1559 * @returns {Array} `['property', x]` | 7867 * @returns {Array} `['property', x]` |
| 1560 » */function getProperty(){var startPos=pos;var x=[];if(checkVariable(pos
)){x.push(getVariable());}else {x = x.concat(getIdentOrInterpolation());}var tok
en=tokens[startPos];return newNode(NodeType.PropertyType,x,token.ln,token.col);}
/** | 7868 » */ |
| 7869 » function getProperty() { |
| 7870 » var startPos = pos; |
| 7871 » var x = []; |
| 7872 |
| 7873 » if (checkVariable(pos)) { |
| 7874 » x.push(getVariable()); |
| 7875 » } else { |
| 7876 » x = x.concat(getIdentOrInterpolation()); |
| 7877 » } |
| 7878 |
| 7879 » var token = tokens[startPos]; |
| 7880 » return newNode(NodeType.PropertyType, x, token.ln, token.col); |
| 7881 » } |
| 7882 |
| 7883 » /** |
| 1561 * Check if token is a colon | 7884 * Check if token is a colon |
| 1562 * @param {Number} i Token's index number | 7885 * @param {Number} i Token's index number |
| 1563 * @returns {Number} `1` if token is a colon, otherwise `0` | 7886 * @returns {Number} `1` if token is a colon, otherwise `0` |
| 1564 » */function checkPropertyDelim(i){return i < tokensLength && tokens[i].t
ype === TokenType.Colon?1:0;} /** | 7887 » */ |
| 7888 » function checkPropertyDelim(i) { |
| 7889 » return i < tokensLength && tokens[i].type === TokenType.Colon ? 1 : 0; |
| 7890 » } |
| 7891 |
| 7892 » /** |
| 1565 * Get node with a colon | 7893 * Get node with a colon |
| 1566 * @returns {Array} `['propertyDelim']` | 7894 * @returns {Array} `['propertyDelim']` |
| 1567 » */function getPropertyDelim(){var startPos=pos;pos++;var token=tokens[s
tartPos];return newNode(NodeType.PropertyDelimType,':',token.ln,token.col);} /** | 7895 » */ |
| 7896 » function getPropertyDelim() { |
| 7897 » var startPos = pos; |
| 7898 |
| 7899 » pos++; |
| 7900 |
| 7901 » var token = tokens[startPos]; |
| 7902 » return newNode(NodeType.PropertyDelimType, ':', token.ln, token.col); |
| 7903 » } |
| 7904 |
| 7905 » /** |
| 1568 * @param {Number} i Token's index number | 7906 * @param {Number} i Token's index number |
| 1569 * @returns {Number} | 7907 * @returns {Number} |
| 1570 » */function checkPseudo(i){return checkPseudoe(i) || checkPseudoc(i);} /
** | 7908 » */ |
| 7909 » function checkPseudo(i) { |
| 7910 » return checkPseudoe(i) || checkPseudoc(i); |
| 7911 » } |
| 7912 |
| 7913 » /** |
| 1571 * @returns {Array} | 7914 * @returns {Array} |
| 1572 » */function getPseudo(){if(checkPseudoe(pos))return getPseudoe();if(chec
kPseudoc(pos))return getPseudoc();} /** | 7915 » */ |
| 7916 » function getPseudo() { |
| 7917 » if (checkPseudoe(pos)) return getPseudoe(); |
| 7918 » if (checkPseudoc(pos)) return getPseudoc(); |
| 7919 » } |
| 7920 |
| 7921 » /** |
| 1573 * @param {Number} i Token's index number | 7922 * @param {Number} i Token's index number |
| 1574 * @returns {Number} | 7923 * @returns {Number} |
| 1575 » */function checkPseudoe(i){var l;if(i >= tokensLength || tokens[i++].ty
pe !== TokenType.Colon || i >= tokensLength || tokens[i++].type !== TokenType.Co
lon)return 0;return (l = checkIdentOrInterpolation(i))?l + 2:0;} /** | 7924 » */ |
| 7925 » function checkPseudoe(i) { |
| 7926 » var l; |
| 7927 |
| 7928 » if (i >= tokensLength || tokens[i++].type !== TokenType.Colon || i >=
tokensLength || tokens[i++].type !== TokenType.Colon) return 0; |
| 7929 |
| 7930 » return (l = checkIdentOrInterpolation(i)) ? l + 2 : 0; |
| 7931 » } |
| 7932 |
| 7933 » /** |
| 1576 * @returns {Array} | 7934 * @returns {Array} |
| 1577 » */function getPseudoe(){var startPos=pos;pos += 2;var x=getIdentOrInter
polation();var token=tokens[startPos];return newNode(NodeType.PseudoeType,x,toke
n.ln,token.col);} /** | 7935 » */ |
| 7936 » function getPseudoe() { |
| 7937 » var startPos = pos; |
| 7938 |
| 7939 » pos += 2; |
| 7940 |
| 7941 » var x = getIdentOrInterpolation(); |
| 7942 |
| 7943 » var token = tokens[startPos]; |
| 7944 » return newNode(NodeType.PseudoeType, x, token.ln, token.col); |
| 7945 » } |
| 7946 |
| 7947 » /** |
| 1578 * @param {Number} i Token's index number | 7948 * @param {Number} i Token's index number |
| 1579 * @returns {Number} | 7949 * @returns {Number} |
| 1580 » */function checkPseudoc(i){var l;if(i >= tokensLength || tokens[i].type
!== TokenType.Colon)return 0;if(l = checkPseudoClass3(i))tokens[i].pseudoClassT
ype = 3;else if(l = checkPseudoClass4(i))tokens[i].pseudoClassType = 4;else if(l
= checkPseudoClass5(i))tokens[i].pseudoClassType = 5;else if(l = checkPseudoCla
ss1(i))tokens[i].pseudoClassType = 1;else if(l = checkPseudoClass2(i))tokens[i].
pseudoClassType = 2;else if(l = checkPseudoClass6(i))tokens[i].pseudoClassType =
6;else return 0;return l;} /** | 7950 » */ |
| 7951 » function checkPseudoc(i) { |
| 7952 » var l; |
| 7953 |
| 7954 » if (i >= tokensLength || tokens[i].type !== TokenType.Colon) return 0; |
| 7955 |
| 7956 » if (l = checkPseudoClass3(i)) tokens[i].pseudoClassType = 3;else if (l
= checkPseudoClass4(i)) tokens[i].pseudoClassType = 4;else if (l = checkPseudoC
lass5(i)) tokens[i].pseudoClassType = 5;else if (l = checkPseudoClass1(i)) token
s[i].pseudoClassType = 1;else if (l = checkPseudoClass2(i)) tokens[i].pseudoClas
sType = 2;else if (l = checkPseudoClass6(i)) tokens[i].pseudoClassType = 6;else
return 0; |
| 7957 |
| 7958 » return l; |
| 7959 » } |
| 7960 |
| 7961 » /** |
| 1581 * @returns {Array} | 7962 * @returns {Array} |
| 1582 » */function getPseudoc(){var childType=tokens[pos].pseudoClassType;if(ch
ildType === 1)return getPseudoClass1();if(childType === 2)return getPseudoClass2
();if(childType === 3)return getPseudoClass3();if(childType === 4)return getPseu
doClass4();if(childType === 5)return getPseudoClass5();if(childType === 6)return
getPseudoClass6();} /** | 7963 » */ |
| 7964 » function getPseudoc() { |
| 7965 » var childType = tokens[pos].pseudoClassType; |
| 7966 » if (childType === 1) return getPseudoClass1(); |
| 7967 » if (childType === 2) return getPseudoClass2(); |
| 7968 » if (childType === 3) return getPseudoClass3(); |
| 7969 » if (childType === 4) return getPseudoClass4(); |
| 7970 » if (childType === 5) return getPseudoClass5(); |
| 7971 » if (childType === 6) return getPseudoClass6(); |
| 7972 » } |
| 7973 |
| 7974 » /** |
| 1583 * (-) `:not(panda)` | 7975 * (-) `:not(panda)` |
| 1584 » */function checkPseudoClass1(i){var start=i; // Skip `:`. | 7976 » */ |
| 1585 » i++;if(i >= tokensLength)return 0;var l=undefined;if(l = checkIdentOrInt
erpolation(i))i += l;else return 0;if(i >= tokensLength || tokens[i].type !== To
kenType.LeftParenthesis)return 0;var right=tokens[i].right; // Skip `(`. | 7977 » function checkPseudoClass1(i) { |
| 1586 » i++;if(l = checkSelectorsGroup(i))i += l;else return 0;if(i !== right)re
turn 0;return right - start + 1;} /** | 7978 » var start = i; |
| 7979 |
| 7980 » // Skip `:`. |
| 7981 » i++; |
| 7982 |
| 7983 » if (i >= tokensLength) return 0; |
| 7984 |
| 7985 » var l = void 0; |
| 7986 » if (l = checkIdentOrInterpolation(i)) i += l;else return 0; |
| 7987 |
| 7988 » if (i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis)
return 0; |
| 7989 |
| 7990 » var right = tokens[i].right; |
| 7991 |
| 7992 » // Skip `(`. |
| 7993 » i++; |
| 7994 |
| 7995 » if (l = checkSelectorsGroup(i)) i += l;else return 0; |
| 7996 |
| 7997 » if (i !== right) return 0; |
| 7998 |
| 7999 » return right - start + 1; |
| 8000 » } |
| 8001 |
| 8002 » /** |
| 1587 * (-) `:not(panda)` | 8003 * (-) `:not(panda)` |
| 1588 » */function getPseudoClass1(){var type=NodeType.PseudocType;var token=to
kens[pos];var line=token.ln;var column=token.col;var content=[]; // Skip `:`. | 8004 » */ |
| 1589 » pos++;content = content.concat(getIdentOrInterpolation());{var _type=Nod
eType.ArgumentsType;var _token=tokens[pos];var _line=_token.ln;var _column=_toke
n.col; // Skip `(`. | 8005 » function getPseudoClass1() { |
| 1590 » pos++;var selectors=getSelectorsGroup();var end=getLastPosition(selector
s,_line,_column,1);var args=newNode(_type,selectors,_line,_column,end);content.p
ush(args); // Skip `)`. | 8006 » var type = NodeType.PseudocType; |
| 1591 » pos++;}return newNode(type,content,line,column);} /** | 8007 » var token = tokens[pos]; |
| 8008 » var line = token.ln; |
| 8009 » var column = token.col; |
| 8010 » var content = []; |
| 8011 |
| 8012 » // Skip `:`. |
| 8013 » pos++; |
| 8014 |
| 8015 » content = content.concat(getIdentOrInterpolation()); |
| 8016 |
| 8017 » { |
| 8018 » var _type = NodeType.ArgumentsType; |
| 8019 » var _token = tokens[pos]; |
| 8020 » var _line = _token.ln; |
| 8021 » var _column = _token.col; |
| 8022 |
| 8023 » // Skip `(`. |
| 8024 » pos++; |
| 8025 |
| 8026 » var selectors = getSelectorsGroup(); |
| 8027 » var end = getLastPosition(selectors, _line, _column, 1); |
| 8028 » var args = newNode(_type, selectors, _line, _column, end); |
| 8029 » content.push(args); |
| 8030 |
| 8031 » // Skip `)`. |
| 8032 » pos++; |
| 8033 » } |
| 8034 |
| 8035 » return newNode(type, content, line, column); |
| 8036 » } |
| 8037 |
| 8038 » /** |
| 1592 * (1) `:nth-child(odd)` | 8039 * (1) `:nth-child(odd)` |
| 1593 * (2) `:nth-child(even)` | 8040 * (2) `:nth-child(even)` |
| 1594 * (3) `:lang(de-DE)` | 8041 * (3) `:lang(de-DE)` |
| 1595 » */function checkPseudoClass2(i){var start=i;var l=0; // Skip `:`. | 8042 » */ |
| 1596 » i++;if(i >= tokensLength)return 0;if(l = checkIdentOrInterpolation(i))i
+= l;else return 0;if(i >= tokensLength || tokens[i].type !== TokenType.LeftPare
nthesis)return 0;var right=tokens[i].right; // Skip `(`. | 8043 » function checkPseudoClass2(i) { |
| 1597 » i++;if(l = checkSC(i))i += l;if(l = checkIdentOrInterpolation(i))i += l;
else return 0;if(l = checkSC(i))i += l;if(i !== right)return 0;return i - start
+ 1;}function getPseudoClass2(){var type=NodeType.PseudocType;var token=tokens[p
os];var line=token.ln;var column=token.col;var content=[]; // Skip `:`. | 8044 » var start = i; |
| 1598 » pos++;content = content.concat(getIdentOrInterpolation());var l=tokens[p
os].ln;var c=tokens[pos].col;var value=[]; // Skip `(`. | 8045 » var l = 0; |
| 1599 » pos++;value = value.concat(getSC()).concat(getIdentOrInterpolation()).co
ncat(getSC());var end=getLastPosition(value,l,c,1);var args=newNode(NodeType.Arg
umentsType,value,l,c,end);content.push(args); // Skip `)`. | 8046 |
| 1600 » pos++;return newNode(type,content,line,column);} /** | 8047 » // Skip `:`. |
| 8048 » i++; |
| 8049 |
| 8050 » if (i >= tokensLength) return 0; |
| 8051 |
| 8052 » if (l = checkIdentOrInterpolation(i)) i += l;else return 0; |
| 8053 |
| 8054 » if (i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis)
return 0; |
| 8055 |
| 8056 » var right = tokens[i].right; |
| 8057 |
| 8058 » // Skip `(`. |
| 8059 » i++; |
| 8060 |
| 8061 » if (l = checkSC(i)) i += l; |
| 8062 |
| 8063 » if (l = checkIdentOrInterpolation(i)) i += l;else return 0; |
| 8064 |
| 8065 » if (l = checkSC(i)) i += l; |
| 8066 |
| 8067 » if (i !== right) return 0; |
| 8068 |
| 8069 » return i - start + 1; |
| 8070 » } |
| 8071 |
| 8072 » function getPseudoClass2() { |
| 8073 » var type = NodeType.PseudocType; |
| 8074 » var token = tokens[pos]; |
| 8075 » var line = token.ln; |
| 8076 » var column = token.col; |
| 8077 » var content = []; |
| 8078 |
| 8079 » // Skip `:`. |
| 8080 » pos++; |
| 8081 |
| 8082 » content = content.concat(getIdentOrInterpolation()); |
| 8083 |
| 8084 » var l = tokens[pos].ln; |
| 8085 » var c = tokens[pos].col; |
| 8086 » var value = []; |
| 8087 |
| 8088 » // Skip `(`. |
| 8089 » pos++; |
| 8090 |
| 8091 » value = value.concat(getSC()).concat(getIdentOrInterpolation()).concat
(getSC()); |
| 8092 |
| 8093 » var end = getLastPosition(value, l, c, 1); |
| 8094 » var args = newNode(NodeType.ArgumentsType, value, l, c, end); |
| 8095 » content.push(args); |
| 8096 |
| 8097 » // Skip `)`. |
| 8098 » pos++; |
| 8099 |
| 8100 » return newNode(type, content, line, column); |
| 8101 » } |
| 8102 |
| 8103 » /** |
| 1601 * (-) `:nth-child(-3n + 2)` | 8104 * (-) `:nth-child(-3n + 2)` |
| 1602 » */function checkPseudoClass3(i){var start=i;var l=0; // Skip `:`. | 8105 » */ |
| 1603 » i++;if(i >= tokensLength)return 0;if(l = checkIdentOrInterpolation(i))i
+= l;else return 0;if(i >= tokensLength || tokens[i].type !== TokenType.LeftPare
nthesis)return 0;var right=tokens[i].right; // Skip `(`. | 8106 » function checkPseudoClass3(i) { |
| 1604 » i++;if(l = checkSC(i))i += l;if(l = checkUnary(i))i += l;if(i >= tokensL
ength)return 0;if(tokens[i].type === TokenType.DecimalNumber)i++;if(i >= tokensL
ength)return 0;if(tokens[i].value === 'n')i++;else return 0;if(l = checkSC(i))i
+= l;if(i >= tokensLength)return 0;if(tokens[i].value === '+' || tokens[i].value
=== '-')i++;else return 0;if(l = checkSC(i))i += l;if(tokens[i].type === TokenT
ype.DecimalNumber)i++;else return 0;if(l = checkSC(i))i += l;if(i !== right)retu
rn 0;return i - start + 1;}function getPseudoClass3(){var type=NodeType.PseudocT
ype;var token=tokens[pos];var line=token.ln;var column=token.col; // Skip `:`. | 8107 » var start = i; |
| 1605 » pos++;var content=getIdentOrInterpolation();var l=tokens[pos].ln;var c=t
okens[pos].col;var value=[]; // Skip `(`. | 8108 » var l = 0; |
| 1606 » pos++;if(checkUnary(pos))value.push(getUnary());if(checkNumber(pos))valu
e.push(getNumber());{var _l=tokens[pos].ln;var _c=tokens[pos].col;var _content=t
okens[pos].value;var ident=newNode(NodeType.IdentType,_content,_l,_c);value.push
(ident);pos++;}value = value.concat(getSC());if(checkUnary(pos))value.push(getUn
ary());value = value.concat(getSC());if(checkNumber(pos))value.push(getNumber())
;value = value.concat(getSC());var end=getLastPosition(value,l,c,1);var args=new
Node(NodeType.ArgumentsType,value,l,c,end);content.push(args); // Skip `)`. | 8109 |
| 1607 » pos++;return newNode(type,content,line,column);} /** | 8110 » // Skip `:`. |
| 8111 » i++; |
| 8112 |
| 8113 » if (i >= tokensLength) return 0; |
| 8114 |
| 8115 » if (l = checkIdentOrInterpolation(i)) i += l;else return 0; |
| 8116 |
| 8117 » if (i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis)
return 0; |
| 8118 |
| 8119 » var right = tokens[i].right; |
| 8120 |
| 8121 » // Skip `(`. |
| 8122 » i++; |
| 8123 |
| 8124 » if (l = checkSC(i)) i += l; |
| 8125 |
| 8126 » if (l = checkUnary(i)) i += l; |
| 8127 |
| 8128 » if (l = checkNumberOrInterpolation(i)) i += l; |
| 8129 |
| 8130 » if (i >= tokensLength) return 0; |
| 8131 » if (tokens[i].value === 'n') i++;else return 0; |
| 8132 |
| 8133 » if (l = checkSC(i)) i += l; |
| 8134 |
| 8135 » if (i >= tokensLength) return 0; |
| 8136 |
| 8137 » if (tokens[i].type === TokenType.PlusSign || tokens[i].type === TokenT
ype.HyphenMinus) i++;else return 0; |
| 8138 |
| 8139 » if (l = checkSC(i)) i += l; |
| 8140 |
| 8141 » if (l = checkNumberOrInterpolation(i)) i += l;else return 0; |
| 8142 |
| 8143 » if (l = checkSC(i)) i += l; |
| 8144 |
| 8145 » if (i !== right) return 0; |
| 8146 |
| 8147 » return i - start + 1; |
| 8148 » } |
| 8149 |
| 8150 » function getPseudoClass3() { |
| 8151 » var type = NodeType.PseudocType; |
| 8152 » var token = tokens[pos]; |
| 8153 » var line = token.ln; |
| 8154 » var column = token.col; |
| 8155 |
| 8156 » // Skip `:`. |
| 8157 » pos++; |
| 8158 |
| 8159 » var content = getIdentOrInterpolation(); |
| 8160 |
| 8161 » var l = tokens[pos].ln; |
| 8162 » var c = tokens[pos].col; |
| 8163 » var value = []; |
| 8164 |
| 8165 » // Skip `(`. |
| 8166 » pos++; |
| 8167 |
| 8168 » if (checkUnary(pos)) value.push(getUnary()); |
| 8169 |
| 8170 » if (checkNumberOrInterpolation(pos)) value = value.concat(getNumberOrI
nterpolation()); |
| 8171 |
| 8172 » { |
| 8173 » var _l = tokens[pos].ln; |
| 8174 » var _c = tokens[pos].col; |
| 8175 » var _content = tokens[pos].value; |
| 8176 » var ident = newNode(NodeType.IdentType, _content, _l, _c); |
| 8177 » value.push(ident); |
| 8178 » pos++; |
| 8179 » } |
| 8180 |
| 8181 » value = value.concat(getSC()); |
| 8182 » if (checkUnary(pos)) value.push(getUnary()); |
| 8183 » value = value.concat(getSC()); |
| 8184 » if (checkNumberOrInterpolation(pos)) value = value.concat(getNumberOrI
nterpolation()); |
| 8185 » value = value.concat(getSC()); |
| 8186 |
| 8187 » var end = getLastPosition(value, l, c, 1); |
| 8188 » var args = newNode(NodeType.ArgumentsType, value, l, c, end); |
| 8189 » content.push(args); |
| 8190 |
| 8191 » // Skip `)`. |
| 8192 » pos++; |
| 8193 |
| 8194 » return newNode(type, content, line, column); |
| 8195 » } |
| 8196 |
| 8197 » /** |
| 1608 * (-) `:nth-child(-3n)` | 8198 * (-) `:nth-child(-3n)` |
| 1609 » */function checkPseudoClass4(i){var start=i;var l=0; // Skip `:`. | 8199 » */ |
| 1610 » i++;if(i >= tokensLength)return 0;if(l = checkIdentOrInterpolation(i))i
+= l;else return 0;if(i >= tokensLength)return 0;if(tokens[i].type !== TokenType
.LeftParenthesis)return 0;var right=tokens[i].right; // Skip `(`. | 8200 » function checkPseudoClass4(i) { |
| 1611 » i++;if(l = checkSC(i))i += l;if(l = checkUnary(i))i += l;if(tokens[i].ty
pe === TokenType.DecimalNumber)i++;if(tokens[i].value === 'n')i++;else return 0;
if(l = checkSC(i))i += l;if(i !== right)return 0;return i - start + 1;}function
getPseudoClass4(){var type=NodeType.PseudocType;var token=tokens[pos];var line=t
oken.ln;var column=token.col; // Skip `:`. | 8201 » var start = i; |
| 1612 » pos++;var content=getIdentOrInterpolation();var l=tokens[pos].ln;var c=t
okens[pos].col;var value=[]; // Skip `(`. | 8202 » var l = 0; |
| 1613 » pos++;value = value.concat(getSC());if(checkUnary(pos))value.push(getUna
ry());if(checkNumber(pos))value.push(getNumber());if(checkIdent(pos))value.push(
getIdent());value = value.concat(getSC());var end=getLastPosition(value,l,c,1);v
ar args=newNode(NodeType.ArgumentsType,value,l,c,end);content.push(args); // Ski
p `)`. | 8203 |
| 1614 » pos++;return newNode(type,content,line,column);} /** | 8204 » // Skip `:`. |
| 8205 » i++; |
| 8206 |
| 8207 » if (i >= tokensLength) return 0; |
| 8208 |
| 8209 » if (l = checkIdentOrInterpolation(i)) i += l;else return 0; |
| 8210 |
| 8211 » if (i >= tokensLength) return 0; |
| 8212 » if (tokens[i].type !== TokenType.LeftParenthesis) return 0; |
| 8213 |
| 8214 » var right = tokens[i].right; |
| 8215 |
| 8216 » // Skip `(`. |
| 8217 » i++; |
| 8218 |
| 8219 » if (l = checkSC(i)) i += l; |
| 8220 |
| 8221 » // Check for leading unary `-` |
| 8222 » if (l = checkUnary(i)) i += l; |
| 8223 |
| 8224 » // Check for interpolation `#{i}` |
| 8225 » if (l = checkInterpolation(i)) i += l; |
| 8226 |
| 8227 » if (tokens[i].type === TokenType.DecimalNumber) i++; |
| 8228 |
| 8229 » if (tokens[i].value === 'n') i++;else return 0; |
| 8230 |
| 8231 » if (l = checkSC(i)) i += l; |
| 8232 |
| 8233 » if (i !== right) return 0; |
| 8234 |
| 8235 » return i - start + 1; |
| 8236 » } |
| 8237 |
| 8238 » function getPseudoClass4() { |
| 8239 » var type = NodeType.PseudocType; |
| 8240 » var token = tokens[pos]; |
| 8241 » var line = token.ln; |
| 8242 » var column = token.col; |
| 8243 |
| 8244 » // Skip `:`. |
| 8245 » pos++; |
| 8246 |
| 8247 » var content = getIdentOrInterpolation(); |
| 8248 |
| 8249 » var l = tokens[pos].ln; |
| 8250 » var c = tokens[pos].col; |
| 8251 » var value = []; |
| 8252 |
| 8253 » // Skip `(`. |
| 8254 » pos++; |
| 8255 |
| 8256 » value = value.concat(getSC()); |
| 8257 |
| 8258 » if (checkUnary(pos)) value.push(getUnary()); |
| 8259 » if (checkInterpolation(pos)) value.push(getInterpolation()); |
| 8260 » if (checkNumber(pos)) value.push(getNumber()); |
| 8261 » if (checkIdent(pos)) value.push(getIdent()); |
| 8262 » value = value.concat(getSC()); |
| 8263 |
| 8264 » var end = getLastPosition(value, l, c, 1); |
| 8265 » var args = newNode(NodeType.ArgumentsType, value, l, c, end); |
| 8266 » content.push(args); |
| 8267 |
| 8268 » // Skip `)`. |
| 8269 » pos++; |
| 8270 |
| 8271 » return newNode(type, content, line, column); |
| 8272 » } |
| 8273 |
| 8274 » /** |
| 1615 * (-) `:nth-child(+8)` | 8275 * (-) `:nth-child(+8)` |
| 1616 » */function checkPseudoClass5(i){var start=i;var l=0; // Skip `:`. | 8276 » */ |
| 1617 » i++;if(i >= tokensLength)return 0;if(l = checkIdentOrInterpolation(i))i
+= l;else return 0;if(i >= tokensLength)return 0;if(tokens[i].type !== TokenType
.LeftParenthesis)return 0;var right=tokens[i].right; // Skip `(`. | 8277 » function checkPseudoClass5(i) { |
| 1618 » i++;if(l = checkSC(i))i += l;if(l = checkUnary(i))i += l;if(tokens[i].ty
pe === TokenType.DecimalNumber)i++;else return 0;if(l = checkSC(i))i += l;if(i !
== right)return 0;return i - start + 1;}function getPseudoClass5(){var type=Node
Type.PseudocType;var token=tokens[pos];var line=token.ln;var column=token.col; /
/ Skip `:`. | 8278 » var start = i; |
| 1619 » pos++;var content=getIdentOrInterpolation();var l=tokens[pos].ln;var c=t
okens[pos].col;var value=[]; // Skip `(`. | 8279 » var l = 0; |
| 1620 » pos++;if(checkUnary(pos))value.push(getUnary());if(checkNumber(pos))valu
e.push(getNumber());value = value.concat(getSC());var end=getLastPosition(value,
l,c,1);var args=newNode(NodeType.ArgumentsType,value,l,c,end);content.push(args)
; // Skip `)`. | 8280 |
| 1621 » pos++;return newNode(type,content,line,column);} /** | 8281 » // Skip `:`. |
| 8282 » i++; |
| 8283 |
| 8284 » if (i >= tokensLength) return 0; |
| 8285 |
| 8286 » if (l = checkIdentOrInterpolation(i)) i += l;else return 0; |
| 8287 |
| 8288 » if (i >= tokensLength) return 0; |
| 8289 » if (tokens[i].type !== TokenType.LeftParenthesis) return 0; |
| 8290 |
| 8291 » var right = tokens[i].right; |
| 8292 |
| 8293 » // Skip `(`. |
| 8294 » i++; |
| 8295 |
| 8296 » if (l = checkSC(i)) i += l; |
| 8297 |
| 8298 » if (l = checkUnary(i)) i += l; |
| 8299 » if (tokens[i].type === TokenType.DecimalNumber) i++;else return 0; |
| 8300 |
| 8301 » if (l = checkSC(i)) i += l; |
| 8302 |
| 8303 » if (i !== right) return 0; |
| 8304 |
| 8305 » return i - start + 1; |
| 8306 » } |
| 8307 |
| 8308 » function getPseudoClass5() { |
| 8309 » var type = NodeType.PseudocType; |
| 8310 » var token = tokens[pos]; |
| 8311 » var line = token.ln; |
| 8312 » var column = token.col; |
| 8313 |
| 8314 » // Skip `:`. |
| 8315 » pos++; |
| 8316 |
| 8317 » var content = getIdentOrInterpolation(); |
| 8318 |
| 8319 » var l = tokens[pos].ln; |
| 8320 » var c = tokens[pos].col; |
| 8321 » var value = []; |
| 8322 |
| 8323 » // Skip `(`. |
| 8324 » pos++; |
| 8325 |
| 8326 » if (checkUnary(pos)) value.push(getUnary()); |
| 8327 » if (checkNumber(pos)) value.push(getNumber()); |
| 8328 » value = value.concat(getSC()); |
| 8329 |
| 8330 » var end = getLastPosition(value, l, c, 1); |
| 8331 » var args = newNode(NodeType.ArgumentsType, value, l, c, end); |
| 8332 » content.push(args); |
| 8333 |
| 8334 » // Skip `)`. |
| 8335 » pos++; |
| 8336 |
| 8337 » return newNode(type, content, line, column); |
| 8338 » } |
| 8339 |
| 8340 » /** |
| 1622 * (-) `:checked` | 8341 * (-) `:checked` |
| 1623 » */function checkPseudoClass6(i){var start=i;var l=0; // Skip `:`. | 8342 » */ |
| 1624 » i++;if(i >= tokensLength)return 0;if(l = checkIdentOrInterpolation(i))i
+= l;else return 0;return i - start;}function getPseudoClass6(){var type=NodeTyp
e.PseudocType;var token=tokens[pos];var line=token.ln;var column=token.col; // S
kip `:`. | 8343 » function checkPseudoClass6(i) { |
| 1625 » pos++;var content=getIdentOrInterpolation();return newNode(type,content,
line,column);} /** | 8344 » var start = i; |
| 8345 » var l = 0; |
| 8346 |
| 8347 » // Skip `:`. |
| 8348 » i++; |
| 8349 |
| 8350 » if (i >= tokensLength) return 0; |
| 8351 |
| 8352 » if (l = checkIdentOrInterpolation(i)) i += l;else return 0; |
| 8353 |
| 8354 » return i - start; |
| 8355 » } |
| 8356 |
| 8357 » function getPseudoClass6() { |
| 8358 » var type = NodeType.PseudocType; |
| 8359 » var token = tokens[pos]; |
| 8360 » var line = token.ln; |
| 8361 » var column = token.col; |
| 8362 |
| 8363 » // Skip `:`. |
| 8364 » pos++; |
| 8365 |
| 8366 » var content = getIdentOrInterpolation(); |
| 8367 |
| 8368 » return newNode(type, content, line, column); |
| 8369 » } |
| 8370 |
| 8371 » /** |
| 1626 * @param {Number} i Token's index number | 8372 * @param {Number} i Token's index number |
| 1627 * @returns {Number} | 8373 * @returns {Number} |
| 1628 » */function checkRuleset(i){var start=i;var l=undefined;if(i >= tokensLe
ngth)return 0;if(l = checkSelectorsGroup(i))i += l;else return 0;if(l = checkSC(
i))i += l;if(l = checkBlock(i))i += l;else return 0;return i - start;}function g
etRuleset(){var type=NodeType.RulesetType;var token=tokens[pos];var line=token.l
n;var column=token.col;var content=[];content = content.concat(getSelectorsGroup
());content = content.concat(getSC());content.push(getBlock());return newNode(ty
pe,content,line,column);} /** | 8374 » */ |
| 8375 » function checkRuleset(i) { |
| 8376 » var start = i; |
| 8377 » var l = void 0; |
| 8378 |
| 8379 » if (i >= tokensLength) return 0; |
| 8380 |
| 8381 » if (l = checkSelectorsGroup(i)) i += l;else return 0; |
| 8382 |
| 8383 » if (l = checkSC(i)) i += l; |
| 8384 |
| 8385 » if (l = checkBlock(i)) i += l;else return 0; |
| 8386 |
| 8387 » return i - start; |
| 8388 » } |
| 8389 |
| 8390 » function getRuleset() { |
| 8391 » var type = NodeType.RulesetType; |
| 8392 » var token = tokens[pos]; |
| 8393 » var line = token.ln; |
| 8394 » var column = token.col; |
| 8395 » var content = []; |
| 8396 |
| 8397 » content = content.concat(getSelectorsGroup()); |
| 8398 » content = content.concat(getSC()); |
| 8399 » content.push(getBlock()); |
| 8400 |
| 8401 » return newNode(type, content, line, column); |
| 8402 » } |
| 8403 |
| 8404 » /** |
| 1629 * Check if token is marked as a space (if it's a space or a tab | 8405 * Check if token is marked as a space (if it's a space or a tab |
| 1630 * or a line break). | 8406 * or a line break). |
| 1631 * @param {Number} i | 8407 * @param {Number} i |
| 1632 * @returns {Number} Number of spaces in a row starting with the given t
oken. | 8408 * @returns {Number} Number of spaces in a row starting with the given t
oken. |
| 1633 » */function checkS(i){return i < tokensLength && tokens[i].ws?tokens[i].
ws_last - i + 1:0;} /** | 8409 » */ |
| 8410 » function checkS(i) { |
| 8411 » return i < tokensLength && tokens[i].ws ? tokens[i].ws_last - i + 1 :
0; |
| 8412 » } |
| 8413 |
| 8414 » /** |
| 1634 * Get node with spaces | 8415 * Get node with spaces |
| 1635 * @returns {Array} `['s', x]` where `x` is a string containing spaces | 8416 * @returns {Array} `['s', x]` where `x` is a string containing spaces |
| 1636 » */function getS(){var startPos=pos;var x=joinValues(pos,tokens[pos].ws_
last);pos = tokens[pos].ws_last + 1;var token=tokens[startPos];return newNode(No
deType.SType,x,token.ln,token.col);} /** | 8417 » */ |
| 8418 » function getS() { |
| 8419 » var startPos = pos; |
| 8420 » var x = joinValues(pos, tokens[pos].ws_last); |
| 8421 |
| 8422 » pos = tokens[pos].ws_last + 1; |
| 8423 |
| 8424 » var token = tokens[startPos]; |
| 8425 » return newNode(NodeType.SType, x, token.ln, token.col); |
| 8426 » } |
| 8427 |
| 8428 » /** |
| 1637 * Check if token is a space or a comment. | 8429 * Check if token is a space or a comment. |
| 1638 * @param {Number} i Token's index number | 8430 * @param {Number} i Token's index number |
| 1639 * @returns {Number} Number of similar (space or comment) tokens | 8431 * @returns {Number} Number of similar (space or comment) tokens |
| 1640 * in a row starting with the given token. | 8432 * in a row starting with the given token. |
| 1641 » */function checkSC(i){if(i >= tokensLength)return 0;var l=undefined;var
lsc=0;while(i < tokensLength) {if(!(l = checkS(i)) && !(l = checkCommentML(i))
&& !(l = checkCommentSL(i)))break;i += l;lsc += l;}return lsc || 0;} /** | 8433 » */ |
| 8434 » function checkSC(i) { |
| 8435 » if (i >= tokensLength) return 0; |
| 8436 |
| 8437 » var l = void 0; |
| 8438 » var lsc = 0; |
| 8439 |
| 8440 » while (i < tokensLength) { |
| 8441 » if (!(l = checkS(i)) && !(l = checkCommentML(i)) && !(l = checkComme
ntSL(i))) break; |
| 8442 » i += l; |
| 8443 » lsc += l; |
| 8444 » } |
| 8445 |
| 8446 » return lsc || 0; |
| 8447 » } |
| 8448 |
| 8449 » /** |
| 1642 * Get node with spaces and comments | 8450 * Get node with spaces and comments |
| 1643 * @returns {Array} Array containing nodes with spaces (if there are any
) | 8451 * @returns {Array} Array containing nodes with spaces (if there are any
) |
| 1644 * and nodes with comments (if there are any): | 8452 * and nodes with comments (if there are any): |
| 1645 * `[['s', x]*, ['comment', y]*]` where `x` is a string of spaces | 8453 * `[['s', x]*, ['comment', y]*]` where `x` is a string of spaces |
| 1646 * and `y` is a comment's text (without `/*` and `* /`). | 8454 * and `y` is a comment's text (without `/*` and `* /`). |
| 1647 » */function getSC(){var sc=[];if(pos >= tokensLength)return sc;while(pos
< tokensLength) {if(checkS(pos))sc.push(getS());else if(checkCommentML(pos))sc.
push(getCommentML());else if(checkCommentSL(pos))sc.push(getCommentSL());else br
eak;}return sc;} /** | 8455 » */ |
| 1648 » * Check if token is part of a hexadecimal number (e.g. `#fff`) inside | 8456 » function getSC() { |
| 1649 » * a simple selector | 8457 » var sc = []; |
| 1650 » * @param {Number} i Token's index number | 8458 |
| 1651 » * @returns {Number} | 8459 » if (pos >= tokensLength) return sc; |
| 1652 » */function checkShash(i){var l;if(i >= tokensLength || tokens[i].type !
== TokenType.NumberSign)return 0;return (l = checkIdentOrInterpolation(i + 1))?l
+ 1:0;} /** | 8460 |
| 1653 » * Get node with a hexadecimal number (e.g. `#fff`) inside a simple | 8461 » while (pos < tokensLength) { |
| 1654 » * selector | 8462 » if (checkS(pos)) sc.push(getS());else if (checkCommentML(pos)) sc.pu
sh(getCommentML());else if (checkCommentSL(pos)) sc.push(getCommentSL());else br
eak; |
| 1655 » * @returns {Array} `['shash', x]` where `x` is a hexadecimal number | 8463 » } |
| 1656 » * converted to string (without `#`, e.g. `fff`) | 8464 |
| 1657 » */function getShash(){var startPos=pos;var token=tokens[startPos];pos++
;var x=getIdentOrInterpolation();return newNode(NodeType.ShashType,x,token.ln,to
ken.col);} /** | 8465 » return sc; |
| 8466 » } |
| 8467 |
| 8468 » /** |
| 8469 » * Check if token is part of a hexadecimal number (e.g. `#fff`) inside a
simple |
| 8470 » * selector |
| 8471 » * @param {number} i Token's index number |
| 8472 » * @return {number} |
| 8473 » */ |
| 8474 » function checkShash(i) { |
| 8475 » var start = i; |
| 8476 » var l = void 0; |
| 8477 |
| 8478 » if (i >= tokensLength) return 0; |
| 8479 |
| 8480 » if (tokens[i].type === TokenType.NumberSign) i++;else return 0; |
| 8481 |
| 8482 » if (l = checkIdentOrInterpolation(i) || checkPartialIdent(i)) i += l;e
lse return 0; |
| 8483 |
| 8484 » while (i < tokensLength) { |
| 8485 » if (l = checkIdentOrInterpolation(i) || checkPartialIdent(i)) i += l
;else break; |
| 8486 » } |
| 8487 |
| 8488 » tokens[start].shashEnd = i; |
| 8489 |
| 8490 » return i - start; |
| 8491 » } |
| 8492 |
| 8493 » /** |
| 8494 » * Get node with a hexadecimal number (e.g. `#fff`) inside a simple sele
ctor |
| 8495 » * @returns {Node} |
| 8496 » */ |
| 8497 » function getShash() { |
| 8498 » var startPos = pos; |
| 8499 » var type = NodeType.ShashType; |
| 8500 » var token = tokens[startPos]; |
| 8501 » var line = token.ln; |
| 8502 » var column = token.col; |
| 8503 » var end = token.shashEnd; |
| 8504 » var content = []; |
| 8505 |
| 8506 » // Skip `#` |
| 8507 » pos++; |
| 8508 |
| 8509 » while (pos < end) { |
| 8510 » if (checkIdentOrInterpolation(pos)) { |
| 8511 » content = content.concat(getIdentOrInterpolation()); |
| 8512 » } else if (checkPartialIdent(pos)) { |
| 8513 » content.push(getIdent()); |
| 8514 » } else break; |
| 8515 » } |
| 8516 |
| 8517 » return newNode(type, content, line, column); |
| 8518 » } |
| 8519 |
| 8520 » /** |
| 1658 * Check if token is part of a string (text wrapped in quotes) | 8521 * Check if token is part of a string (text wrapped in quotes) |
| 1659 * @param {Number} i Token's index number | 8522 * @param {Number} i Token's index number |
| 1660 * @returns {Number} `1` if token is part of a string, `0` if not | 8523 * @returns {Number} `1` if token is part of a string, `0` if not |
| 1661 » */function checkString(i){return i < tokensLength && (tokens[i].type ==
= TokenType.StringSQ || tokens[i].type === TokenType.StringDQ)?1:0;} /** | 8524 » */ |
| 8525 » function checkString(i) { |
| 8526 » if (i >= tokensLength) return 0; |
| 8527 |
| 8528 » if (tokens[i].type === TokenType.StringSQ || tokens[i].type === TokenT
ype.StringDQ) { |
| 8529 » return 1; |
| 8530 » } |
| 8531 |
| 8532 » return 0; |
| 8533 » } |
| 8534 |
| 8535 » /** |
| 1662 * Get string's node | 8536 * Get string's node |
| 1663 * @returns {Array} `['string', x]` where `x` is a string (including | 8537 * @returns {Array} `['string', x]` where `x` is a string (including |
| 1664 * quotes). | 8538 * quotes). |
| 1665 » */function getString(){var startPos=pos;var x=tokens[pos++].value;var t
oken=tokens[startPos];return newNode(NodeType.StringType,x,token.ln,token.col);}
/** | 8539 » */ |
| 8540 » function getString() { |
| 8541 » var startPos = pos; |
| 8542 » var x = tokens[pos++].value; |
| 8543 |
| 8544 » var token = tokens[startPos]; |
| 8545 » return newNode(NodeType.StringType, x, token.ln, token.col); |
| 8546 » } |
| 8547 |
| 8548 » /** |
| 1666 * Validate stylesheet: it should consist of any number (0 or more) of | 8549 * Validate stylesheet: it should consist of any number (0 or more) of |
| 1667 * rulesets (sets of rules with selectors), @-rules, whitespaces or | 8550 * rulesets (sets of rules with selectors), @-rules, whitespaces or |
| 1668 * comments. | 8551 * comments. |
| 1669 * @param {Number} i Token's index number | 8552 * @param {Number} i Token's index number |
| 1670 * @returns {Number} | 8553 * @returns {Number} |
| 1671 » */function checkStylesheet(i){var start=i;var l=undefined;while(i < tok
ensLength) {if(l = checkSC(i) || checkDeclaration(i) || checkDeclDelim(i) || che
ckInclude(i) || checkExtend(i) || checkMixin(i) || checkLoop(i) || checkConditio
nalStatement(i) || checkAtrule(i) || checkRuleset(i))i += l;else throwError(i);}
return i - start;} /** | 8554 » */ |
| 8555 » function checkStylesheet(i) { |
| 8556 » var start = i; |
| 8557 » var l = void 0; |
| 8558 |
| 8559 » while (i < tokensLength) { |
| 8560 » if (l = checkSC(i)) tokens[i].ss_child = 1;else if (l = checkRuleset
(i)) tokens[i].ss_child = 2;else if (l = checkInclude(i)) tokens[i].ss_child = 3
;else if (l = checkExtend(i)) tokens[i].ss_child = 4;else if (l = checkMixin(i))
tokens[i].ss_child = 5;else if (l = checkLoop(i)) tokens[i].ss_child = 6;else i
f (l = checkConditionalStatement(i)) tokens[i].ss_child = 7;else if (l = checkAt
rule(i)) tokens[i].ss_child = 8;else if (l = checkDeclaration(i)) tokens[i].ss_c
hild = 9;else if (l = checkDeclDelim(i)) tokens[i].ss_child = 10;else throwError
(i); |
| 8561 |
| 8562 » i += l; |
| 8563 » } |
| 8564 |
| 8565 » return i - start; |
| 8566 » } |
| 8567 |
| 8568 » /** |
| 1672 * @returns {Array} `['stylesheet', x]` where `x` is all stylesheet's | 8569 * @returns {Array} `['stylesheet', x]` where `x` is all stylesheet's |
| 1673 * nodes. | 8570 * nodes. |
| 1674 » */function getStylesheet(){var startPos=pos;var x=[];while(pos < tokens
Length) {if(checkSC(pos))x = x.concat(getSC());else if(checkRuleset(pos))x.push(
getRuleset());else if(checkInclude(pos))x.push(getInclude());else if(checkExtend
(pos))x.push(getExtend());else if(checkMixin(pos))x.push(getMixin());else if(che
ckLoop(pos))x.push(getLoop());else if(checkConditionalStatement(pos))x.push(getC
onditionalStatement());else if(checkAtrule(pos))x.push(getAtrule());else if(chec
kDeclaration(pos))x.push(getDeclaration());else if(checkDeclDelim(pos))x.push(ge
tDeclDelim());else throwError();}var token=tokens[startPos];return newNode(NodeT
ype.StylesheetType,x,token.ln,token.col);} /** | 8571 » */ |
| 8572 » function getStylesheet() { |
| 8573 » var startPos = pos; |
| 8574 » var x = []; |
| 8575 |
| 8576 » while (pos < tokensLength) { |
| 8577 » var childType = tokens[pos].ss_child; |
| 8578 |
| 8579 » if (childType === 1) x = x.concat(getSC());else if (childType === 2)
x.push(getRuleset());else if (childType === 3) x.push(getInclude());else if (ch
ildType === 4) x.push(getExtend());else if (childType === 5) x.push(getMixin());
else if (childType === 6) x.push(getLoop());else if (childType === 7) x.push(get
ConditionalStatement());else if (childType === 8) x.push(getAtrule());else if (c
hildType === 9) x.push(getDeclaration());else if (childType === 10) x.push(getDe
clDelim()); |
| 8580 » } |
| 8581 |
| 8582 » var token = tokens[startPos]; |
| 8583 » return newNode(NodeType.StylesheetType, x, token.ln, token.col); |
| 8584 » } |
| 8585 |
| 8586 » /** |
| 1675 * @param {Number} i Token's index number | 8587 * @param {Number} i Token's index number |
| 1676 * @returns {Number} | 8588 * @returns {Number} |
| 1677 » */function checkTset(i){return checkVhash(i) || checkOperator(i) || che
ckAny(i) || checkSC(i) || checkInterpolation(i);} /** | 8589 » */ |
| 8590 » function checkTset(i) { |
| 8591 » var l; |
| 8592 » if (l = checkVhash(i)) tokens[i].tset_type = 1;else if (l = checkOpera
tor(i)) tokens[i].tset_type = 2;else if (l = checkAny(i)) tokens[i].tset_type =
3;else if (l = checkSC(i)) tokens[i].tset_type = 4;else if (l = checkInterpolati
on(i)) tokens[i].tset_type = 5; |
| 8593 |
| 8594 » return l; |
| 8595 » } |
| 8596 |
| 8597 » /** |
| 1678 * @returns {Array} | 8598 * @returns {Array} |
| 1679 » */function getTset(){if(checkVhash(pos))return getVhash();else if(check
Operator(pos))return getOperator();else if(checkAny(pos))return getAny();else if
(checkSC(pos))return getSC();else if(checkInterpolation(pos))return getInterpola
tion();} /** | 8599 » */ |
| 8600 » function getTset() { |
| 8601 » var tsetType = tokens[pos].tset_type; |
| 8602 |
| 8603 » if (tsetType === 1) return getVhash();else if (tsetType === 2) return
getOperator();else if (tsetType === 3) return getAny();else if (tsetType === 4)
return getSC();else if (tsetType === 5) return getInterpolation(); |
| 8604 » } |
| 8605 |
| 8606 » /** |
| 1680 * @param {Number} i Token's index number | 8607 * @param {Number} i Token's index number |
| 1681 * @returns {Number} | 8608 * @returns {Number} |
| 1682 » */function checkTsets(i){var start=i;var l=undefined;if(i >= tokensLeng
th)return 0;while(l = checkTset(i)) {i += l;}return i - start;} /** | 8609 » */ |
| 8610 » function checkTsets(i) { |
| 8611 » var start = i; |
| 8612 » var l = void 0; |
| 8613 |
| 8614 » if (i >= tokensLength) return 0; |
| 8615 |
| 8616 » while (l = checkTset(i)) { |
| 8617 » i += l; |
| 8618 » } |
| 8619 |
| 8620 » tokens[start].tsets_end = i; |
| 8621 » return i - start; |
| 8622 » } |
| 8623 |
| 8624 » /** |
| 1683 * @returns {Array} | 8625 * @returns {Array} |
| 1684 » */function getTsets(){var x=[];var t=undefined;while(t = getTset()) {if
(typeof t.content === 'string')x.push(t);else x = x.concat(t);}return x;} /** | 8626 » */ |
| 8627 » function getTsets() { |
| 8628 » var x = []; |
| 8629 » var t = void 0; |
| 8630 |
| 8631 » if (pos >= tokensLength) return x; |
| 8632 |
| 8633 » var end = tokens[pos].tsets_end; |
| 8634 » while (pos < end) { |
| 8635 » t = getTset(); |
| 8636 » if (typeof t.content === 'string') x.push(t);else x = x.concat(t); |
| 8637 » } |
| 8638 |
| 8639 » return x; |
| 8640 » } |
| 8641 |
| 8642 » /** |
| 1685 * Check if token is an unary (arithmetical) sign (`+` or `-`) | 8643 * Check if token is an unary (arithmetical) sign (`+` or `-`) |
| 1686 * @param {Number} i Token's index number | 8644 * @param {Number} i Token's index number |
| 1687 * @returns {Number} `1` if token is an unary sign, `0` if not | 8645 * @returns {Number} `1` if token is an unary sign, `0` if not |
| 1688 » */function checkUnary(i){return i < tokensLength && (tokens[i].type ===
TokenType.HyphenMinus || tokens[i].type === TokenType.PlusSign)?1:0;} /** | 8646 » */ |
| 8647 » function checkUnary(i) { |
| 8648 » if (i >= tokensLength) { |
| 8649 » return 0; |
| 8650 » } |
| 8651 |
| 8652 » if (tokens[i].type === TokenType.HyphenMinus || tokens[i].type === Tok
enType.PlusSign) { |
| 8653 » return 1; |
| 8654 » } |
| 8655 |
| 8656 » return 0; |
| 8657 » } |
| 8658 |
| 8659 » /** |
| 1689 * Get node with an unary (arithmetical) sign (`+` or `-`) | 8660 * Get node with an unary (arithmetical) sign (`+` or `-`) |
| 1690 * @returns {Array} `['unary', x]` where `x` is an unary sign | 8661 * @returns {Array} `['unary', x]` where `x` is an unary sign |
| 1691 * converted to string. | 8662 * converted to string. |
| 1692 */function getUnary(){var startPos=pos;var x=tokens[pos++].value;var to
ken=tokens[startPos];return newNode(NodeType.OperatorType,x,token.ln,token.col);
} /** | 8663 */ |
| 1693 * Check if token is part of URI (e.g. `url('/css/styles.css')`) | 8664 function getUnary() { |
| 1694 * @param {Number} i Token's index number | 8665 var startPos = pos; |
| 1695 * @returns {Number} Length of URI | 8666 var x = tokens[pos++].value; |
| 1696 */function checkUri(i){var start=i;if(i >= tokensLength || tokens[i++].
value !== 'url' || i >= tokensLength || tokens[i].type !== TokenType.LeftParenth
esis)return 0;return tokens[i].right - start + 1;} /** | 8667 |
| 1697 * Get node with URI | 8668 var token = tokens[startPos]; |
| 1698 * @returns {Array} `['uri', x]` where `x` is URI's nodes (without `url` | 8669 return newNode(NodeType.OperatorType, x, token.ln, token.col); |
| 1699 * and braces, e.g. `['string', ''/css/styles.css'']`). | 8670 } |
| 1700 */function getUri(){var startPos=pos;var uriExcluding={};var uri=undefi
ned;var token=undefined;var l=undefined;var raw=undefined;pos += 2;uriExcluding[
TokenType.Space] = 1;uriExcluding[TokenType.Tab] = 1;uriExcluding[TokenType.Newl
ine] = 1;uriExcluding[TokenType.LeftParenthesis] = 1;uriExcluding[TokenType.Righ
tParenthesis] = 1;if(checkUriContent(pos)){uri = [].concat(getSC()).concat(getUr
iContent()).concat(getSC());}else {uri = [].concat(getSC());l = checkExcluding(u
riExcluding,pos);token = tokens[pos];raw = newNode(NodeType.RawType,joinValues(p
os,pos + l),token.ln,token.col);uri.push(raw);pos += l + 1;uri = uri.concat(getS
C());}token = tokens[startPos];var line=token.ln;var column=token.col;var end=ge
tLastPosition(uri,line,column,1);pos++;return newNode(NodeType.UriType,uri,token
.ln,token.col,end);} /** | 8671 |
| 8672 /** |
| 8673 * Check if token is a unicode range (single or multiple <urange> nodes) |
| 8674 * @param {number} i Token's index |
| 8675 * @return {number} Unicode range node's length |
| 8676 */ |
| 8677 function checkUnicodeRange(i) { |
| 8678 var start = i; |
| 8679 var l = void 0; |
| 8680 |
| 8681 if (i >= tokensLength) return 0; |
| 8682 |
| 8683 if (l = checkUrange(i)) i += l;else return 0; |
| 8684 |
| 8685 while (i < tokensLength) { |
| 8686 var spaceBefore = checkSC(i); |
| 8687 var comma = checkDelim(i + spaceBefore); |
| 8688 if (!comma) break; |
| 8689 |
| 8690 var spaceAfter = checkSC(i + spaceBefore + comma); |
| 8691 if (l = checkUrange(i + spaceBefore + comma + spaceAfter)) { |
| 8692 i += spaceBefore + comma + spaceAfter + l; |
| 8693 } else break; |
| 8694 } |
| 8695 |
| 8696 return i - start; |
| 8697 } |
| 8698 |
| 8699 /** |
| 8700 * Get a unicode range node |
| 8701 * @return {Node} |
| 8702 */ |
| 8703 function getUnicodeRange() { |
| 8704 var type = NodeType.UnicodeRangeType; |
| 8705 var token = tokens[pos]; |
| 8706 var line = token.ln; |
| 8707 var column = token.col; |
| 8708 var content = []; |
| 8709 |
| 8710 while (pos < tokensLength) { |
| 8711 if (checkSC(pos)) content = content.concat(getSC());else if (checkDe
lim(pos)) content.push(getDelim());else if (checkUrange(pos)) content.push(getUr
ange());else break; |
| 8712 } |
| 8713 |
| 8714 return newNode(type, content, line, column); |
| 8715 } |
| 8716 |
| 8717 /** |
| 8718 * Check if token is a u-range (part of a unicode-range) |
| 8719 * (1) `U+416` |
| 8720 * (2) `U+400-4ff` |
| 8721 * (3) `U+4??` |
| 8722 * @param {number} i Token's index |
| 8723 * @return {number} Urange node's length |
| 8724 */ |
| 8725 function checkUrange(i) { |
| 8726 var start = i; |
| 8727 var l = void 0; |
| 8728 |
| 8729 if (i >= tokensLength) return 0; |
| 8730 |
| 8731 // Check for unicode prefix (u+ or U+) |
| 8732 if (tokens[i].value === 'U' || tokens[i].value === 'u') i += 1;else re
turn 0; |
| 8733 |
| 8734 if (i >= tokensLength) return 0; |
| 8735 |
| 8736 if (tokens[i].value === '+') i += 1;else return 0; |
| 8737 |
| 8738 while (i < tokensLength) { |
| 8739 if (l = checkIdent(i)) i += l;else if (l = checkNumber(i)) i += l;el
se if (l = checkUnary(i)) i += l;else if (l = _checkUnicodeWildcard(i)) i += l;e
lse break; |
| 8740 } |
| 8741 |
| 8742 tokens[start].urangeEnd = i - 1; |
| 8743 |
| 8744 return i - start; |
| 8745 } |
| 8746 |
| 8747 /** |
| 8748 * Get a u-range node (part of a unicode-range) |
| 8749 * @return {Node} |
| 8750 */ |
| 8751 function getUrange() { |
| 8752 var startPos = pos; |
| 8753 var type = NodeType.UrangeType; |
| 8754 var token = tokens[pos]; |
| 8755 var line = token.ln; |
| 8756 var column = token.col; |
| 8757 var content = []; |
| 8758 |
| 8759 content = joinValues(startPos, tokens[startPos].urangeEnd); |
| 8760 pos = tokens[startPos].urangeEnd + 1; |
| 8761 |
| 8762 return newNode(type, content, line, column); |
| 8763 } |
| 8764 |
| 8765 /** |
| 8766 * Check for unicode wildcard characters `?` |
| 8767 * @param {number} i Token's index |
| 8768 * @return {number} Wildcard length |
| 8769 */ |
| 8770 function _checkUnicodeWildcard(i) { |
| 8771 var start = i; |
| 8772 |
| 8773 if (i >= tokensLength) return 0; |
| 8774 |
| 8775 while (i < tokensLength) { |
| 8776 if (tokens[i].type === TokenType.QuestionMark) i += 1;else break; |
| 8777 } |
| 8778 |
| 8779 tokens[start].uri_raw_end = i; |
| 8780 |
| 8781 return i - start; |
| 8782 } |
| 8783 |
| 8784 /** |
| 8785 * Check if token is part of URI, e.g. `url('/css/styles.css')` |
| 8786 * @param {number} i Token's index number |
| 8787 * @returns {number} Length of URI |
| 8788 */ |
| 8789 function checkUri(i) { |
| 8790 var start = i; |
| 8791 var l = void 0; |
| 8792 |
| 8793 if (i >= tokensLength || tokens[i].value !== 'url') return 0; |
| 8794 |
| 8795 // Skip `url` |
| 8796 i++; |
| 8797 |
| 8798 if (i >= tokensLength || tokens[i].type !== TokenType.LeftParenthesis)
return 0; |
| 8799 |
| 8800 // Store the opening parenthesis token as we will reference it's `righ
t` |
| 8801 // property to determine when the parentheses close |
| 8802 var leftParenthesis = tokens[i]; |
| 8803 |
| 8804 // Skip `(` |
| 8805 i++; |
| 8806 |
| 8807 // Determine the type of URI |
| 8808 while (i < leftParenthesis.right) { |
| 8809 if (l = checkUri1(i)) { |
| 8810 i += l; |
| 8811 tokens[start].uriType = 1; // Raw based URI (without quotes) |
| 8812 } else if (l = checkUri2(i)) { |
| 8813 i += l; |
| 8814 tokens[start].uriType = 2; // Non-raw based URI (with quotes) |
| 8815 } else return 0; |
| 8816 } |
| 8817 |
| 8818 return i - start; |
| 8819 } |
| 8820 |
| 8821 /** |
| 8822 * Get specific type of URI node |
| 8823 * @return {Node} Specific type of URI node |
| 8824 */ |
| 8825 function getUri() { |
| 8826 var uriType = tokens[pos].uriType; |
| 8827 |
| 8828 if (uriType === 1) return getUri1(); |
| 8829 if (uriType === 2) return getUri2(); |
| 8830 } |
| 8831 |
| 8832 /** |
| 8833 * Check if token type is valid URI character |
| 8834 * @param {number} i Token's index number |
| 8835 * @return {number} Length of raw node |
| 8836 */ |
| 8837 function checkUriRawCharacters(i) { |
| 8838 var start = i; |
| 8839 var l = void 0; |
| 8840 |
| 8841 if (l = checkIdent(i)) i += l;else if (l = checkNumber(i)) i += l;else
{ |
| 8842 switch (tokens[i].type) { |
| 8843 case TokenType.ExclamationMark: |
| 8844 case TokenType.NumberSign: |
| 8845 case TokenType.DollarSign: |
| 8846 case TokenType.PercentSign: |
| 8847 case TokenType.Ampersand: |
| 8848 case TokenType.Asterisk: |
| 8849 case TokenType.PlusSign: |
| 8850 case TokenType.Comma: |
| 8851 case TokenType.HyphenMinus: |
| 8852 case TokenType.FullStop: |
| 8853 case TokenType.Solidus: |
| 8854 case TokenType.Colon: |
| 8855 case TokenType.Semicolon: |
| 8856 case TokenType.LessThanSign: |
| 8857 case TokenType.EqualsSign: |
| 8858 case TokenType.GreaterThanSign: |
| 8859 case TokenType.QuotationMark: |
| 8860 case TokenType.CommercialAt: |
| 8861 case TokenType.LeftSquareBracket: |
| 8862 case TokenType.RightSquareBracket: |
| 8863 case TokenType.CircumflexAccent: |
| 8864 case TokenType.LowLine: |
| 8865 case TokenType.LeftCurlyBracket: |
| 8866 case TokenType.VerticalLine: |
| 8867 case TokenType.RightCurlyBracket: |
| 8868 case TokenType.Tilde: |
| 8869 i += 1; |
| 8870 break; |
| 8871 |
| 8872 default: |
| 8873 return 0; |
| 8874 } |
| 8875 } |
| 8876 |
| 8877 return i - start; |
| 8878 } |
| 8879 |
| 8880 /** |
| 8881 * Check if content of URI can be contained within a raw node |
| 8882 * @param {number} i Token's index number |
| 8883 * @return {number} Length of raw node |
| 8884 */ |
| 8885 function checkUriRaw(i) { |
| 8886 var start = i; |
| 8887 var l = void 0; |
| 8888 |
| 8889 while (i < tokensLength) { |
| 8890 if (checkInterpolation(i) || checkVariable(i)) break;else if (l = ch
eckUriRawCharacters(i)) i += l;else break; |
| 8891 } |
| 8892 |
| 8893 tokens[start].uri_raw_end = i; |
| 8894 |
| 8895 return i - start; |
| 8896 } |
| 8897 |
| 8898 /** |
| 8899 * Get a raw node |
| 8900 * @return {Node} |
| 8901 */ |
| 8902 function getUriRaw() { |
| 8903 var startPos = pos; |
| 8904 var type = NodeType.RawType; |
| 8905 var token = tokens[startPos]; |
| 8906 var line = token.ln; |
| 8907 var column = token.col; |
| 8908 var content = []; |
| 8909 var l = void 0; |
| 8910 |
| 8911 while (pos < tokens[startPos].uri_raw_end) { |
| 8912 if (checkInterpolation(pos) || checkVariable(pos)) break;else if (l
= checkUriRawCharacters(pos)) pos += l;else break; |
| 8913 } |
| 8914 |
| 8915 content = joinValues(startPos, pos - 1); |
| 8916 |
| 8917 return newNode(type, content, line, column); |
| 8918 } |
| 8919 |
| 8920 /** |
| 8921 * Check for a raw (without quotes) URI |
| 8922 * (1) http://foo.com/bar.png |
| 8923 * (2) http://foo.com/#{$bar}.png |
| 8924 * (3) #{$foo}/bar.png |
| 8925 * (4) #{$foo} |
| 8926 * @param {number} i Token's index number |
| 8927 * @return {number} Length of URI node |
| 8928 */ |
| 8929 function checkUri1(i) { |
| 8930 var start = i; |
| 8931 var l = void 0; |
| 8932 |
| 8933 if (l = checkSC(i)) i += l; |
| 8934 |
| 8935 while (i < tokensLength) { |
| 8936 if (l = checkInterpolation(i) || checkUriRaw(i)) i += l;else break; |
| 8937 } |
| 8938 |
| 8939 if (l = checkSC(i)) i += l; |
| 8940 |
| 8941 // Check that we are at the end of the uri |
| 8942 if (i < tokens[start - 1].right) return 0; |
| 8943 |
| 8944 tokens[start].uri_end = i; |
| 8945 |
| 8946 return i - start; |
| 8947 } |
| 8948 |
| 8949 /** |
| 8950 * Get a raw (without quotes) URI |
| 8951 node |
| 8952 * @return {Node} |
| 8953 */ |
| 8954 function getUri1() { |
| 8955 var startPos = pos; |
| 8956 var type = NodeType.UriType; |
| 8957 var token = tokens[startPos]; |
| 8958 var line = token.ln; |
| 8959 var column = token.col; |
| 8960 var content = []; |
| 8961 var end = void 0; |
| 8962 |
| 8963 // Skip `url` and `(` |
| 8964 pos += 2; |
| 8965 |
| 8966 if (checkSC(pos)) content = content.concat(getSC()); |
| 8967 |
| 8968 while (pos < tokens[startPos + 2].uri_end) { |
| 8969 if (checkInterpolation(pos)) content.push(getInterpolation());else i
f (checkUriRaw(pos)) content.push(getUriRaw());else break; |
| 8970 } |
| 8971 |
| 8972 if (checkSC(pos)) content = content.concat(getSC()); |
| 8973 |
| 8974 // Check that we are at the end of the uri |
| 8975 if (pos < tokens[startPos + 1].right) return 0; |
| 8976 |
| 8977 end = getLastPosition(content, line, column, 1); |
| 8978 |
| 8979 // Skip `)` |
| 8980 pos++; |
| 8981 |
| 8982 return newNode(type, content, line, column, end); |
| 8983 } |
| 8984 |
| 8985 /** |
| 8986 * Check for a non-raw (with quotes) URI |
| 8987 * (1) 'http://foo.com/bar.png' |
| 8988 * (2) 'http://foo.com/'#{$bar}.png |
| 8989 * (3) #{$foo}'/bar.png' |
| 8990 * @param {number} i Token's index number |
| 8991 * @return {number} Length of URI node |
| 8992 */ |
| 8993 function checkUri2(i) { |
| 8994 var start = i; |
| 8995 var l = void 0; |
| 8996 |
| 8997 while (i < tokensLength) { |
| 8998 if (l = checkSC(i)) i += l;else if (l = checkString(i)) i += l;else
if (l = checkFunction(i)) i += l;else if (l = checkUnary(i)) i += l;else if (l =
checkIdentOrInterpolation(i)) i += l;else if (l = checkVariable(i)) i += l;else
break; |
| 8999 } |
| 9000 |
| 9001 tokens[start].uri_end = i; |
| 9002 |
| 9003 return i - start; |
| 9004 } |
| 9005 |
| 9006 /** |
| 9007 * Get a non-raw (with quotes) URI node |
| 9008 * @return {Node} |
| 9009 */ |
| 9010 function getUri2() { |
| 9011 var startPos = pos; |
| 9012 var token = tokens[startPos]; |
| 9013 var line = token.ln; |
| 9014 var column = token.col; |
| 9015 var content = []; |
| 9016 var end = void 0; |
| 9017 |
| 9018 // Skip `url` and `(` |
| 9019 pos += 2; |
| 9020 |
| 9021 while (pos < tokens[startPos + 2].uri_end) { |
| 9022 if (checkSC(pos)) content = content.concat(getSC());else if (checkUn
ary(pos)) content.push(getUnary());else if (_checkValue(pos)) content.push(_getV
alue());else break; |
| 9023 } |
| 9024 |
| 9025 end = getLastPosition(content, line, column, 1); |
| 9026 |
| 9027 // Skip `)` |
| 9028 pos++; |
| 9029 |
| 9030 return newNode(NodeType.UriType, content, line, column, end); |
| 9031 } |
| 9032 |
| 9033 /** |
| 9034 * Check if token is part of a value |
| 9035 * @param {Number} i Token's index number |
| 9036 * @returns {Number} Length of the value |
| 9037 */ |
| 9038 function checkValue(i) { |
| 9039 var start = i; |
| 9040 var l = void 0; |
| 9041 var s = void 0; |
| 9042 var _i = void 0; |
| 9043 |
| 9044 while (i < tokensLength) { |
| 9045 if (checkDeclDelim(i)) break; |
| 9046 |
| 9047 s = checkSC(i); |
| 9048 _i = i + s; |
| 9049 |
| 9050 if (l = _checkValue(_i)) i += l + s; |
| 9051 if (!l || checkBlock(i - l)) break; |
| 9052 } |
| 9053 |
| 9054 return i - start; |
| 9055 } |
| 9056 |
| 9057 /** |
| 9058 * @returns {Array} |
| 9059 */ |
| 9060 function getValue() { |
| 9061 var startPos = pos; |
| 9062 var x = []; |
| 9063 var _pos = void 0; |
| 9064 var s = void 0; |
| 9065 |
| 9066 while (pos < tokensLength) { |
| 9067 s = checkSC(pos); |
| 9068 _pos = pos + s; |
| 9069 |
| 9070 if (checkDeclDelim(_pos)) break; |
| 9071 |
| 9072 if (!_checkValue(_pos)) break; |
| 9073 |
| 9074 if (s) x = x.concat(getSC()); |
| 9075 x.push(_getValue()); |
| 9076 |
| 9077 if (checkBlock(_pos)) break; |
| 9078 } |
| 9079 |
| 9080 var token = tokens[startPos]; |
| 9081 return newNode(NodeType.ValueType, x, token.ln, token.col); |
| 9082 } |
| 9083 |
| 9084 /** |
| 9085 * @param {number} i Token's index number |
| 9086 * @returns {number} Length of the value |
| 9087 */ |
| 9088 function checkSingleValue(i) { |
| 9089 var start = i; |
| 9090 var l = void 0; |
| 9091 var s = void 0; |
| 9092 var _i = void 0; |
| 9093 |
| 9094 while (i < tokensLength) { |
| 9095 if (checkDeclDelim(i) || checkDelim(i)) break; |
| 9096 |
| 9097 s = checkSC(i); |
| 9098 _i = i + s; |
| 9099 |
| 9100 if (l = _checkValue(_i)) i += l + s; |
| 9101 if (!l || checkBlock(i - l)) break; |
| 9102 } |
| 9103 |
| 9104 return i - start; |
| 9105 } |
| 9106 |
| 9107 /** |
| 9108 * @returns {Array} |
| 9109 */ |
| 9110 function getSingleValue() { |
| 9111 var startPos = pos; |
| 9112 var x = []; |
| 9113 var _pos = void 0; |
| 9114 var s = void 0; |
| 9115 |
| 9116 while (pos < tokensLength) { |
| 9117 s = checkSC(pos); |
| 9118 _pos = pos + s; |
| 9119 |
| 9120 if (checkDeclDelim(_pos) || checkDelim(_pos)) break; |
| 9121 |
| 9122 if (!_checkValue(_pos)) break; |
| 9123 |
| 9124 if (s) x = x.concat(getSC()); |
| 9125 x.push(_getValue()); |
| 9126 |
| 9127 if (checkBlock(_pos)) break; |
| 9128 } |
| 9129 |
| 9130 var token = tokens[startPos]; |
| 9131 return newNode(NodeType.ValueType, x, token.ln, token.col); |
| 9132 } |
| 9133 |
| 9134 /** |
| 1701 * @param {Number} i Token's index number | 9135 * @param {Number} i Token's index number |
| 1702 * @returns {Number} | 9136 * @returns {Number} |
| 1703 » */function checkUriContent(i){return checkUri1(i) || checkFunction(i);}
/** | 9137 » */ |
| 9138 » function _checkValue(i) { |
| 9139 » return checkInterpolation(i) || checkVariable(i) || checkVhash(i) || c
heckBlock(i) || checkAtkeyword(i) || checkOperator(i) || checkImportant(i) || ch
eckGlobal(i) || checkDefault(i) || checkProgid(i) || checkAny(i) || checkParentS
elector(i); |
| 9140 » } |
| 9141 |
| 9142 » /** |
| 1704 * @returns {Array} | 9143 * @returns {Array} |
| 1705 » */function getUriContent(){if(checkUri1(pos))return getString();else if
(checkFunction(pos))return getFunction();} /** | 9144 » */ |
| 1706 » * @param {Number} i Token's index number | 9145 » function _getValue() { |
| 1707 » * @returns {Number} | 9146 » if (checkInterpolation(pos)) return getInterpolation();else if (checkV
ariable(pos)) return getVariable();else if (checkVhash(pos)) return getVhash();e
lse if (checkBlock(pos)) return getBlock();else if (checkAtkeyword(pos)) return
getAtkeyword();else if (checkOperator(pos)) return getOperator();else if (checkI
mportant(pos)) return getImportant();else if (checkGlobal(pos)) return getGlobal
();else if (checkDefault(pos)) return getDefault();else if (checkProgid(pos)) re
turn getProgid();else if (checkAny(pos)) return getAny();else if (checkParentSel
ector(pos)) return getParentSelector(); |
| 1708 » */function checkUri1(i){var start=i;var l=undefined;if(i >= tokensLengt
h)return 0;if(l = checkSC(i))i += l;if(tokens[i].type !== TokenType.StringDQ &&
tokens[i].type !== TokenType.StringSQ)return 0;i++;if(l = checkSC(i))i += l;retu
rn i - start;} /** | 9147 » } |
| 1709 » * Check if token is part of a value | 9148 |
| 1710 » * @param {Number} i Token's index number | 9149 » /** |
| 1711 » * @returns {Number} Length of the value | |
| 1712 » */function checkValue(i){var start=i;var l=undefined;var s=undefined;va
r _i=undefined;while(i < tokensLength) {if(checkDeclDelim(i))break;s = checkSC(i
);_i = i + s;if(l = _checkValue(_i))i += l + s;if(!l || checkBlock(i - l))break;
}return i - start;} /** | |
| 1713 » * @param {Number} i Token's index number | |
| 1714 » * @returns {Number} | |
| 1715 » */function _checkValue(i){return checkInterpolation(i) || checkVariable
(i) || checkVhash(i) || checkBlock(i) || checkAtkeyword(i) || checkOperator(i) |
| checkImportant(i) || checkGlobal(i) || checkDefault(i) || checkProgid(i) || ch
eckAny(i);} /** | |
| 1716 » * @returns {Array} | |
| 1717 » */function getValue(){var startPos=pos;var x=[];var _pos=undefined;var
s=undefined;while(pos < tokensLength) {s = checkSC(pos);_pos = pos + s;if(checkD
eclDelim(_pos))break;if(!_checkValue(_pos))break;if(s)x = x.concat(getSC());x.pu
sh(_getValue());if(checkBlock(_pos))break;}var token=tokens[startPos];return new
Node(NodeType.ValueType,x,token.ln,token.col);} /** | |
| 1718 » * @returns {Array} | |
| 1719 » */function _getValue(){if(checkInterpolation(pos))return getInterpolati
on();else if(checkVariable(pos))return getVariable();else if(checkVhash(pos))ret
urn getVhash();else if(checkBlock(pos))return getBlock();else if(checkAtkeyword(
pos))return getAtkeyword();else if(checkOperator(pos))return getOperator();else
if(checkImportant(pos))return getImportant();else if(checkGlobal(pos))return get
Global();else if(checkDefault(pos))return getDefault();else if(checkProgid(pos))
return getProgid();else if(checkAny(pos))return getAny();} /** | |
| 1720 * Check if token is part of a variable | 9150 * Check if token is part of a variable |
| 1721 * @param {Number} i Token's index number | 9151 * @param {Number} i Token's index number |
| 1722 * @returns {Number} Length of the variable | 9152 * @returns {Number} Length of the variable |
| 1723 » */function checkVariable(i){var l;if(i >= tokensLength || tokens[i].typ
e !== TokenType.DollarSign)return 0;return (l = checkIdent(i + 1))?l + 1:0;} /** | 9153 » */ |
| 9154 » function checkVariable(i) { |
| 9155 » var l; |
| 9156 |
| 9157 » if (i >= tokensLength || tokens[i].type !== TokenType.DollarSign) retu
rn 0; |
| 9158 |
| 9159 » return (l = checkIdent(i + 1)) ? l + 1 : 0; |
| 9160 » } |
| 9161 |
| 9162 » /** |
| 1724 * Get node with a variable | 9163 * Get node with a variable |
| 1725 * @returns {Array} `['variable', ['ident', x]]` where `x` is | 9164 * @returns {Array} `['variable', ['ident', x]]` where `x` is |
| 1726 * a variable name. | 9165 * a variable name. |
| 1727 » */function getVariable(){var startPos=pos;var x=[];pos++;x.push(getIden
t());var token=tokens[startPos];return newNode(NodeType.VariableType,x,token.ln,
token.col);} /** | 9166 » */ |
| 9167 » function getVariable() { |
| 9168 » var startPos = pos; |
| 9169 » var x = []; |
| 9170 |
| 9171 » pos++; |
| 9172 |
| 9173 » x.push(getIdent()); |
| 9174 |
| 9175 » var token = tokens[startPos]; |
| 9176 » return newNode(NodeType.VariableType, x, token.ln, token.col); |
| 9177 » } |
| 9178 |
| 9179 » /** |
| 1728 * Check if token is part of a variables list (e.g. `$values...`). | 9180 * Check if token is part of a variables list (e.g. `$values...`). |
| 1729 * @param {Number} i Token's index number | 9181 * @param {Number} i Token's index number |
| 1730 * @returns {Number} | 9182 * @returns {Number} |
| 1731 » */function checkVariablesList(i){var d=0; // Number of dots | 9183 » */ |
| 1732 » var l=undefined;if(i >= tokensLength)return 0;if(l = checkVariable(i))i
+= l;else return 0;while(i < tokensLength && tokens[i].type === TokenType.FullSt
op) {d++;i++;}return d === 3?l + d:0;} /** | 9184 » function checkVariablesList(i) { |
| 9185 » var d = 0; // Number of dots |
| 9186 » var l = void 0; |
| 9187 |
| 9188 » if (i >= tokensLength) return 0; |
| 9189 |
| 9190 » if (l = checkVariable(i)) i += l;else return 0; |
| 9191 |
| 9192 » while (i < tokensLength && tokens[i].type === TokenType.FullStop) { |
| 9193 » d++; |
| 9194 » i++; |
| 9195 » } |
| 9196 |
| 9197 » return d === 3 ? l + d : 0; |
| 9198 » } |
| 9199 |
| 9200 » /** |
| 1733 * Get node with a variables list | 9201 * Get node with a variables list |
| 1734 * @returns {Array} `['variableslist', ['variable', ['ident', x]]]` wher
e | 9202 * @returns {Array} `['variableslist', ['variable', ['ident', x]]]` wher
e |
| 1735 * `x` is a variable name. | 9203 * `x` is a variable name. |
| 1736 » */function getVariablesList(){var startPos=pos;var x=getVariable();var
token=tokens[startPos];var line=token.ln;var column=token.col;var end=getLastPos
ition([x],line,column,3);pos += 3;return newNode(NodeType.VariablesListType,[x],
token.ln,token.col,end);} /** | 9204 » */ |
| 9205 » function getVariablesList() { |
| 9206 » var startPos = pos; |
| 9207 » var x = getVariable(); |
| 9208 » var token = tokens[startPos]; |
| 9209 » var line = token.ln; |
| 9210 » var column = token.col; |
| 9211 |
| 9212 » var end = getLastPosition([x], line, column, 3); |
| 9213 » pos += 3; |
| 9214 |
| 9215 » return newNode(NodeType.VariablesListType, [x], token.ln, token.col, e
nd); |
| 9216 » } |
| 9217 |
| 9218 » /** |
| 1737 * Check if token is part of a hexadecimal number (e.g. `#fff`) inside | 9219 * Check if token is part of a hexadecimal number (e.g. `#fff`) inside |
| 1738 * some value | 9220 * some value |
| 1739 * @param {Number} i Token's index number | 9221 * @param {Number} i Token's index number |
| 1740 * @returns {Number} | 9222 * @returns {Number} |
| 1741 » */function checkVhash(i){var l;if(i >= tokensLength || tokens[i].type !
== TokenType.NumberSign)return 0;return (l = checkNmName2(i + 1))?l + 1:0;} /** | 9223 » */ |
| 9224 » function checkVhash(i) { |
| 9225 » var l; |
| 9226 |
| 9227 » if (i >= tokensLength || tokens[i].type !== TokenType.NumberSign) retu
rn 0; |
| 9228 |
| 9229 » return (l = checkNmName2(i + 1)) ? l + 1 : 0; |
| 9230 » } |
| 9231 |
| 9232 » /** |
| 1742 * Get node with a hexadecimal number (e.g. `#fff`) inside some value | 9233 * Get node with a hexadecimal number (e.g. `#fff`) inside some value |
| 1743 * @returns {Array} `['vhash', x]` where `x` is a hexadecimal number | 9234 * @returns {Array} `['vhash', x]` where `x` is a hexadecimal number |
| 1744 * converted to string (without `#`, e.g. `'fff'`). | 9235 * converted to string (without `#`, e.g. `'fff'`). |
| 1745 » */function getVhash(){var startPos=pos;var x=undefined;var token=tokens
[startPos];var line=token.ln;var column=token.col;pos++;x = getNmName2();var end
=getLastPosition(x,line,column + 1);return newNode(NodeType.VhashType,x,token.ln
,token.col,end);}module.exports = function(_tokens,context){tokens = _tokens;tok
ensLength = tokens.length;pos = 0;return contexts[context]();};function checkSel
ectorsGroup(i){if(i >= tokensLength)return 0;var start=i;var l=undefined;if(l =
checkSelector(i))i += l;else return 0;while(i < tokensLength) {var sb=checkSC(i)
;var c=checkDelim(i + sb);if(!c)break;var sa=checkSC(i + sb + c);if(l = checkSel
ector(i + sb + c + sa))i += sb + c + sa + l;else break;}tokens[start].selectorsG
roupEnd = i;return i - start;}function getSelectorsGroup(){var selectorsGroup=[]
;var selectorsGroupEnd=tokens[pos].selectorsGroupEnd;selectorsGroup.push(getSele
ctor());while(pos < selectorsGroupEnd) {selectorsGroup = selectorsGroup.concat(g
etSC());selectorsGroup.push(getDelim());selectorsGroup = selectorsGroup.concat(g
etSC());selectorsGroup.push(getSelector());}return selectorsGroup;}function chec
kSelector(i){var l;if(l = checkSelector1(i))tokens[i].selectorType = 1;else if(l
= checkSelector2(i))tokens[i].selectorType = 2;return l;}function getSelector()
{var selectorType=tokens[pos].selectorType;if(selectorType === 1)return getSelec
tor1();else return getSelector2();} /** | 9236 » */ |
| 9237 » function getVhash() { |
| 9238 » var startPos = pos; |
| 9239 » var x = void 0; |
| 9240 » var token = tokens[startPos]; |
| 9241 » var line = token.ln; |
| 9242 » var column = token.col; |
| 9243 |
| 9244 » pos++; |
| 9245 |
| 9246 » x = getNmName2(); |
| 9247 » var end = getLastPosition(x, line, column + 1); |
| 9248 » return newNode(NodeType.VhashType, x, token.ln, token.col, end); |
| 9249 » } |
| 9250 |
| 9251 » function checkSelectorsGroup(i) { |
| 9252 » if (i >= tokensLength) return 0; |
| 9253 |
| 9254 » var start = i; |
| 9255 » var l = void 0; |
| 9256 |
| 9257 » if (l = checkSelector(i)) i += l;else return 0; |
| 9258 |
| 9259 » while (i < tokensLength) { |
| 9260 » var sb = checkSC(i); |
| 9261 » var c = checkDelim(i + sb); |
| 9262 » if (!c) break; |
| 9263 » var sa = checkSC(i + sb + c); |
| 9264 » if (l = checkSelector(i + sb + c + sa)) i += sb + c + sa + l;else br
eak; |
| 9265 » } |
| 9266 |
| 9267 » tokens[start].selectorsGroupEnd = i; |
| 9268 » return i - start; |
| 9269 » } |
| 9270 |
| 9271 » function getSelectorsGroup() { |
| 9272 » var selectorsGroup = []; |
| 9273 » var selectorsGroupEnd = tokens[pos].selectorsGroupEnd; |
| 9274 |
| 9275 » selectorsGroup.push(getSelector()); |
| 9276 |
| 9277 » while (pos < selectorsGroupEnd) { |
| 9278 » selectorsGroup = selectorsGroup.concat(getSC()); |
| 9279 » selectorsGroup.push(getDelim()); |
| 9280 » selectorsGroup = selectorsGroup.concat(getSC()); |
| 9281 » selectorsGroup.push(getSelector()); |
| 9282 » } |
| 9283 |
| 9284 » return selectorsGroup; |
| 9285 » } |
| 9286 |
| 9287 » function checkSelector(i) { |
| 9288 » var l; |
| 9289 |
| 9290 » if (l = checkSelector1(i)) tokens[i].selectorType = 1;else if (l = che
ckSelector2(i)) tokens[i].selectorType = 2; |
| 9291 |
| 9292 » return l; |
| 9293 » } |
| 9294 |
| 9295 » function getSelector() { |
| 9296 » var selectorType = tokens[pos].selectorType; |
| 9297 » if (selectorType === 1) return getSelector1();else return getSelector2
(); |
| 9298 » } |
| 9299 |
| 9300 » /** |
| 1746 * Checks for selector which starts with a compound selector. | 9301 * Checks for selector which starts with a compound selector. |
| 1747 » */function checkSelector1(i){if(i >= tokensLength)return 0;var start=i;
var l=undefined;if(l = checkCompoundSelector(i))i += l;else return 0;while(i < t
okensLength) {var s=checkSC(i);var c=checkCombinator(i + s);if(!s && !c)break;if
(c){i += s + c;s = checkSC(i);}if(l = checkCompoundSelector(i + s))i += s + l;el
se break;}tokens[start].selectorEnd = i;return i - start;}function getSelector1(
){var type=NodeType.SelectorType;var token=tokens[pos];var line=token.ln;var col
umn=token.col;var selectorEnd=token.selectorEnd;var content=getCompoundSelector(
);while(pos < selectorEnd) {if(checkSC(pos))content = content.concat(getSC());el
se if(checkCombinator(pos))content.push(getCombinator());else if(checkCompoundSe
lector(pos))content = content.concat(getCompoundSelector());}return newNode(type
,content,line,column);} /** | 9302 » */ |
| 9303 » function checkSelector1(i) { |
| 9304 » if (i >= tokensLength) return 0; |
| 9305 |
| 9306 » var start = i; |
| 9307 » var l = void 0; |
| 9308 |
| 9309 » if (l = checkCompoundSelector(i)) i += l;else return 0; |
| 9310 |
| 9311 » while (i < tokensLength) { |
| 9312 » var s = checkSC(i); |
| 9313 » var c = checkCombinator(i + s); |
| 9314 » if (!s && !c) break; |
| 9315 » if (c) { |
| 9316 » i += s + c; |
| 9317 » s = checkSC(i); |
| 9318 » } |
| 9319 |
| 9320 » if (l = checkCompoundSelector(i + s)) i += s + l;else break; |
| 9321 » } |
| 9322 |
| 9323 » tokens[start].selectorEnd = i; |
| 9324 » return i - start; |
| 9325 » } |
| 9326 |
| 9327 » function getSelector1() { |
| 9328 » var type = NodeType.SelectorType; |
| 9329 » var token = tokens[pos]; |
| 9330 » var line = token.ln; |
| 9331 » var column = token.col; |
| 9332 » var selectorEnd = token.selectorEnd; |
| 9333 » var content = getCompoundSelector(); |
| 9334 |
| 9335 » while (pos < selectorEnd) { |
| 9336 » if (checkSC(pos)) content = content.concat(getSC());else if (checkCo
mbinator(pos)) content.push(getCombinator());else if (checkCompoundSelector(pos)
) content = content.concat(getCompoundSelector()); |
| 9337 » } |
| 9338 |
| 9339 » return newNode(type, content, line, column); |
| 9340 » } |
| 9341 |
| 9342 » /** |
| 1748 * Checks for a selector that starts with a combinator. | 9343 * Checks for a selector that starts with a combinator. |
| 1749 */function checkSelector2(i){if(i >= tokensLength)return 0;var start=i;
var l=undefined;if(l = checkCombinator(i))i += l;else return 0;while(i < tokensL
ength) {var sb=checkSC(i);if(l = checkCompoundSelector(i + sb))i += sb + l;else
break;var sa=checkSC(i);var c=checkCombinator(i + sa);if(!sa && !c)break;if(c){i
+= sa + c;}}tokens[start].selectorEnd = i;return i - start;}function getSelecto
r2(){var type=NodeType.SelectorType;var token=tokens[pos];var line=token.ln;var
column=token.col;var selectorEnd=token.selectorEnd;var content=[getCombinator()]
;while(pos < selectorEnd) {if(checkSC(pos))content = content.concat(getSC());els
e if(checkCombinator(pos))content.push(getCombinator());else if(checkCompoundSel
ector(pos))content = content.concat(getCompoundSelector());}return newNode(type,
content,line,column);}function checkCompoundSelector(i){var l=undefined;if(l = c
heckCompoundSelector1(i)){tokens[i].compoundSelectorType = 1;}else if(l = checkC
ompoundSelector2(i)){tokens[i].compoundSelectorType = 2;}return l;}function getC
ompoundSelector(){var type=tokens[pos].compoundSelectorType;if(type === 1)return
getCompoundSelector1();if(type === 2)return getCompoundSelector2();}function ch
eckCompoundSelector1(i){if(i >= tokensLength)return 0;var start=i;var l=undefine
d;if(l = checkTypeSelector(i) || checkPlaceholder(i) || checkParentSelectorWithE
xtension(i))i += l;else return 0;while(i < tokensLength) {var _l2=checkShash(i)
|| checkClass(i) || checkAttributeSelector(i) || checkPseudo(i) || checkPlacehol
der(i);if(_l2)i += _l2;else break;}tokens[start].compoundSelectorEnd = i;return
i - start;}function getCompoundSelector1(){var sequence=[];var compoundSelectorE
nd=tokens[pos].compoundSelectorEnd;if(checkTypeSelector(pos))sequence.push(getTy
peSelector());else if(checkPlaceholder(pos))sequence.push(getPlaceholder());else
if(checkParentSelectorWithExtension(pos))sequence = sequence.concat(getParentSe
lectorWithExtension());while(pos < compoundSelectorEnd) {if(checkShash(pos))sequ
ence.push(getShash());else if(checkClass(pos))sequence.push(getClass());else if(
checkAttributeSelector(pos))sequence.push(getAttributeSelector());else if(checkP
seudo(pos))sequence.push(getPseudo());else if(checkPlaceholder(pos))sequence.pus
h(getPlaceholder());}return sequence;}function checkCompoundSelector2(i){if(i >=
tokensLength)return 0;var start=i;while(i < tokensLength) {var l=checkShash(i)
|| checkClass(i) || checkAttributeSelector(i) || checkPseudo(i) || checkPlacehol
der(i);if(l)i += l;else break;}tokens[start].compoundSelectorEnd = i;return i -
start;}function getCompoundSelector2(){var sequence=[];var compoundSelectorEnd=t
okens[pos].compoundSelectorEnd;while(pos < compoundSelectorEnd) {if(checkShash(p
os))sequence.push(getShash());else if(checkClass(pos))sequence.push(getClass());
else if(checkAttributeSelector(pos))sequence.push(getAttributeSelector());else i
f(checkPseudo(pos))sequence.push(getPseudo());else if(checkPlaceholder(pos))sequ
ence.push(getPlaceholder());}return sequence;}function checkTypeSelector(i){if(i
>= tokensLength)return 0;var start=i;var l=undefined;if(l = checkNamePrefix(i))
i += l;if(tokens[i].type === TokenType.Asterisk)i++;else if(l = checkIdentOrInte
rpolation(i))i += l;else return 0;return i - start;}function getTypeSelector(){v
ar type=NodeType.TypeSelectorType;var token=tokens[pos];var line=token.ln;var co
lumn=token.col;var content=[];if(checkNamePrefix(pos))content.push(getNamePrefix
());if(checkIdentOrInterpolation(pos))content = content.concat(getIdentOrInterpo
lation());return newNode(type,content,line,column);}function checkAttributeSelec
tor(i){var l=undefined;if(l = checkAttributeSelector1(i))tokens[i].attributeSele
ctorType = 1;else if(l = checkAttributeSelector2(i))tokens[i].attributeSelectorT
ype = 2;return l;}function getAttributeSelector(){var type=tokens[pos].attribute
SelectorType;if(type === 1)return getAttributeSelector1();else return getAttribu
teSelector2();} /** | 9344 */ |
| 9345 function checkSelector2(i) { |
| 9346 if (i >= tokensLength) return 0; |
| 9347 |
| 9348 var start = i; |
| 9349 var l = void 0; |
| 9350 |
| 9351 if (l = checkCombinator(i)) i += l;else return 0; |
| 9352 |
| 9353 while (i < tokensLength) { |
| 9354 var sb = checkSC(i); |
| 9355 if (l = checkCompoundSelector(i + sb)) i += sb + l;else break; |
| 9356 |
| 9357 var sa = checkSC(i); |
| 9358 var c = checkCombinator(i + sa); |
| 9359 if (!sa && !c) break; |
| 9360 if (c) { |
| 9361 i += sa + c; |
| 9362 } |
| 9363 } |
| 9364 |
| 9365 tokens[start].selectorEnd = i; |
| 9366 return i - start; |
| 9367 } |
| 9368 |
| 9369 function getSelector2() { |
| 9370 var type = NodeType.SelectorType; |
| 9371 var token = tokens[pos]; |
| 9372 var line = token.ln; |
| 9373 var column = token.col; |
| 9374 var selectorEnd = token.selectorEnd; |
| 9375 var content = [getCombinator()]; |
| 9376 |
| 9377 while (pos < selectorEnd) { |
| 9378 if (checkSC(pos)) content = content.concat(getSC());else if (checkCo
mbinator(pos)) content.push(getCombinator());else if (checkCompoundSelector(pos)
) content = content.concat(getCompoundSelector()); |
| 9379 } |
| 9380 |
| 9381 return newNode(type, content, line, column); |
| 9382 } |
| 9383 |
| 9384 function checkCompoundSelector(i) { |
| 9385 var l = void 0; |
| 9386 |
| 9387 if (l = checkCompoundSelector1(i)) { |
| 9388 tokens[i].compoundSelectorType = 1; |
| 9389 } else if (l = checkCompoundSelector2(i)) { |
| 9390 tokens[i].compoundSelectorType = 2; |
| 9391 } |
| 9392 |
| 9393 return l; |
| 9394 } |
| 9395 |
| 9396 function getCompoundSelector() { |
| 9397 var type = tokens[pos].compoundSelectorType; |
| 9398 if (type === 1) return getCompoundSelector1(); |
| 9399 if (type === 2) return getCompoundSelector2(); |
| 9400 } |
| 9401 |
| 9402 /** |
| 9403 * Check for compound selectors that start with either a type selector, |
| 9404 * placeholder or parent selector with extension |
| 9405 * (1) `foo.bar` |
| 9406 * (2) `foo[attr=val]` |
| 9407 * (3) `foo:first-of-type` |
| 9408 * (4) `foo%bar` |
| 9409 * @param {number} i Token's index |
| 9410 * @return {number} Compound selector's length |
| 9411 */ |
| 9412 function checkCompoundSelector1(i) { |
| 9413 if (i >= tokensLength) return 0; |
| 9414 |
| 9415 var start = i; |
| 9416 var l = void 0; |
| 9417 |
| 9418 if (l = checkUniversalSelector(i) || checkTypeSelector(i) || checkPlac
eholder(i) || checkParentSelectorWithExtension(i)) i += l;else return 0; |
| 9419 |
| 9420 while (i < tokensLength) { |
| 9421 var _l2 = checkShash(i) || checkClass(i) || checkAttributeSelector(i
) || checkPseudo(i) || checkPlaceholder(i); |
| 9422 |
| 9423 if (_l2) i += _l2;else break; |
| 9424 } |
| 9425 |
| 9426 tokens[start].compoundSelectorEnd = i; |
| 9427 |
| 9428 return i - start; |
| 9429 } |
| 9430 |
| 9431 /** |
| 9432 * @return {Array} An array of nodes that make up the compound selector |
| 9433 */ |
| 9434 function getCompoundSelector1() { |
| 9435 var sequence = []; |
| 9436 var compoundSelectorEnd = tokens[pos].compoundSelectorEnd; |
| 9437 |
| 9438 if (checkUniversalSelector(pos)) sequence.push(getUniversalSelector())
;else if (checkTypeSelector(pos)) sequence.push(getTypeSelector());else if (chec
kPlaceholder(pos)) sequence.push(getPlaceholder());else if (checkParentSelectorW
ithExtension(pos)) sequence = sequence.concat(getParentSelectorWithExtension()); |
| 9439 |
| 9440 while (pos < compoundSelectorEnd) { |
| 9441 if (checkShash(pos)) sequence.push(getShash());else if (checkClass(p
os)) sequence.push(getClass());else if (checkAttributeSelector(pos)) sequence.pu
sh(getAttributeSelector());else if (checkPseudo(pos)) sequence.push(getPseudo())
;else if (checkPlaceholder(pos)) sequence.push(getPlaceholder());else break; |
| 9442 } |
| 9443 |
| 9444 return sequence; |
| 9445 } |
| 9446 |
| 9447 /** |
| 9448 * Check for all other compound selectors |
| 9449 * (1) `.foo.bar` |
| 9450 * (2) `.foo[attr=val]` |
| 9451 * (3) `.foo:first-of-type` |
| 9452 * (4) `.foo%bar` |
| 9453 * (5) `.foo#{$bar}` |
| 9454 * @param {number} i Token's index |
| 9455 * @return {number} Compound selector's length |
| 9456 */ |
| 9457 function checkCompoundSelector2(i) { |
| 9458 if (i >= tokensLength) return 0; |
| 9459 |
| 9460 var start = i; |
| 9461 |
| 9462 while (i < tokensLength) { |
| 9463 var l = checkShash(i) || checkClass(i) || checkAttributeSelector(i)
|| checkPseudo(i) || checkPlaceholder(i) || checkInterpolation(i); |
| 9464 |
| 9465 if (l) i += l;else break; |
| 9466 } |
| 9467 |
| 9468 tokens[start].compoundSelectorEnd = i; |
| 9469 |
| 9470 return i - start; |
| 9471 } |
| 9472 |
| 9473 /** |
| 9474 * @return {Array} An array of nodes that make up the compound selector |
| 9475 */ |
| 9476 function getCompoundSelector2() { |
| 9477 var sequence = []; |
| 9478 var compoundSelectorEnd = tokens[pos].compoundSelectorEnd; |
| 9479 |
| 9480 while (pos < compoundSelectorEnd) { |
| 9481 if (checkShash(pos)) sequence.push(getShash());else if (checkClass(p
os)) sequence.push(getClass());else if (checkAttributeSelector(pos)) sequence.pu
sh(getAttributeSelector());else if (checkPseudo(pos)) sequence.push(getPseudo())
;else if (checkPlaceholder(pos)) sequence.push(getPlaceholder());else if (checkI
nterpolation(pos)) sequence.push(getInterpolation());else break; |
| 9482 } |
| 9483 |
| 9484 return sequence; |
| 9485 } |
| 9486 |
| 9487 function checkUniversalSelector(i) { |
| 9488 if (i >= tokensLength) return 0; |
| 9489 |
| 9490 var start = i; |
| 9491 var l = void 0; |
| 9492 |
| 9493 if (l = checkNamePrefix(i)) i += l; |
| 9494 |
| 9495 if (tokens[i].type === TokenType.Asterisk) i++;else return 0; |
| 9496 |
| 9497 return i - start; |
| 9498 } |
| 9499 |
| 9500 function getUniversalSelector() { |
| 9501 var type = NodeType.UniversalSelectorType; |
| 9502 var token = tokens[pos]; |
| 9503 var line = token.ln; |
| 9504 var column = token.col; |
| 9505 var content = []; |
| 9506 var end = void 0; |
| 9507 |
| 9508 if (checkNamePrefix(pos)) { |
| 9509 content.push(getNamePrefix()); |
| 9510 end = getLastPosition(content, line, column, 1); |
| 9511 } |
| 9512 |
| 9513 pos++; |
| 9514 |
| 9515 return newNode(type, content, line, column, end); |
| 9516 } |
| 9517 |
| 9518 /** |
| 9519 * Check if token is part of a type selector |
| 9520 * @param {number} i Token's index |
| 9521 * @return {number} Type selector's length |
| 9522 */ |
| 9523 function checkTypeSelector(i) { |
| 9524 var start = i; |
| 9525 var l = void 0; |
| 9526 |
| 9527 if (i >= tokensLength) return 0; |
| 9528 |
| 9529 if (l = checkNamePrefix(i)) i += l; |
| 9530 |
| 9531 if (l = checkIdentOrInterpolation(i)) i += l;else return 0; |
| 9532 |
| 9533 return i - start; |
| 9534 } |
| 9535 |
| 9536 /** |
| 9537 * Get type selector node |
| 9538 * @return {Node} |
| 9539 */ |
| 9540 function getTypeSelector() { |
| 9541 var type = NodeType.TypeSelectorType; |
| 9542 var token = tokens[pos]; |
| 9543 var line = token.ln; |
| 9544 var column = token.col; |
| 9545 var content = []; |
| 9546 |
| 9547 if (checkNamePrefix(pos)) content.push(getNamePrefix()); |
| 9548 |
| 9549 content = content.concat(getIdentOrInterpolation()); |
| 9550 |
| 9551 return newNode(type, content, line, column); |
| 9552 } |
| 9553 |
| 9554 function checkAttributeSelector(i) { |
| 9555 var l = void 0; |
| 9556 if (l = checkAttributeSelector1(i)) tokens[i].attributeSelectorType =
1;else if (l = checkAttributeSelector2(i)) tokens[i].attributeSelectorType = 2; |
| 9557 |
| 9558 return l; |
| 9559 } |
| 9560 |
| 9561 function getAttributeSelector() { |
| 9562 var type = tokens[pos].attributeSelectorType; |
| 9563 if (type === 1) return getAttributeSelector1();else return getAttribut
eSelector2(); |
| 9564 } |
| 9565 |
| 9566 /** |
| 1750 * (1) `[panda=nani]` | 9567 * (1) `[panda=nani]` |
| 1751 * (2) `[panda='nani']` | 9568 * (2) `[panda='nani']` |
| 1752 * (3) `[panda='nani' i]` | 9569 * (3) `[panda='nani' i]` |
| 1753 * | 9570 * |
| 1754 » */function checkAttributeSelector1(i){var start=i;if(tokens[i].type ===
TokenType.LeftSquareBracket)i++;else return 0;var l=undefined;if(l = checkSC(i)
)i += l;if(l = checkAttributeName(i))i += l;else return 0;if(l = checkSC(i))i +=
l;if(l = checkAttributeMatch(i))i += l;else return 0;if(l = checkSC(i))i += l;i
f(l = checkAttributeValue(i))i += l;else return 0;if(l = checkSC(i))i += l;if(l
= checkAttributeFlags(i)){i += l;if(l = checkSC(i))i += l;}if(tokens[i].type ===
TokenType.RightSquareBracket)i++;else return 0;return i - start;}function getAt
tributeSelector1(){var type=NodeType.AttributeSelectorType;var token=tokens[pos]
;var line=token.ln;var column=token.col;var content=[]; // Skip `[`. | 9571 » */ |
| 1755 » pos++;content = content.concat(getSC());content.push(getAttributeName())
;content = content.concat(getSC());content.push(getAttributeMatch());content = c
ontent.concat(getSC());content.push(getAttributeValue());content = content.conca
t(getSC());if(checkAttributeFlags(pos)){content.push(getAttributeFlags());conten
t = content.concat(getSC());} // Skip `]`. | 9572 » function checkAttributeSelector1(i) { |
| 1756 » pos++;var end=getLastPosition(content,line,column,1);return newNode(type
,content,line,column,end);} /** | 9573 » var start = i; |
| 9574 |
| 9575 » if (tokens[i].type === TokenType.LeftSquareBracket) i++;else return 0; |
| 9576 |
| 9577 » var l = void 0; |
| 9578 » if (l = checkSC(i)) i += l; |
| 9579 |
| 9580 » if (l = checkAttributeName(i)) i += l;else return 0; |
| 9581 |
| 9582 » if (l = checkSC(i)) i += l; |
| 9583 |
| 9584 » if (l = checkAttributeMatch(i)) i += l;else return 0; |
| 9585 |
| 9586 » if (l = checkSC(i)) i += l; |
| 9587 |
| 9588 » if (l = checkAttributeValue(i)) i += l;else return 0; |
| 9589 |
| 9590 » if (l = checkSC(i)) i += l; |
| 9591 |
| 9592 » if (l = checkAttributeFlags(i)) { |
| 9593 » i += l; |
| 9594 » if (l = checkSC(i)) i += l; |
| 9595 » } |
| 9596 |
| 9597 » if (tokens[i].type === TokenType.RightSquareBracket) i++;else return 0
; |
| 9598 |
| 9599 » return i - start; |
| 9600 » } |
| 9601 |
| 9602 » function getAttributeSelector1() { |
| 9603 » var type = NodeType.AttributeSelectorType; |
| 9604 » var token = tokens[pos]; |
| 9605 » var line = token.ln; |
| 9606 » var column = token.col; |
| 9607 » var content = []; |
| 9608 |
| 9609 » // Skip `[`. |
| 9610 » pos++; |
| 9611 |
| 9612 » content = content.concat(getSC()); |
| 9613 » content.push(getAttributeName()); |
| 9614 » content = content.concat(getSC()); |
| 9615 » content.push(getAttributeMatch()); |
| 9616 » content = content.concat(getSC()); |
| 9617 » content.push(getAttributeValue()); |
| 9618 » content = content.concat(getSC()); |
| 9619 |
| 9620 » if (checkAttributeFlags(pos)) { |
| 9621 » content.push(getAttributeFlags()); |
| 9622 » content = content.concat(getSC()); |
| 9623 » } |
| 9624 |
| 9625 » // Skip `]`. |
| 9626 » pos++; |
| 9627 |
| 9628 » var end = getLastPosition(content, line, column, 1); |
| 9629 » return newNode(type, content, line, column, end); |
| 9630 » } |
| 9631 |
| 9632 » /** |
| 1757 * (1) `[panda]` | 9633 * (1) `[panda]` |
| 1758 » */function checkAttributeSelector2(i){var start=i;if(tokens[i].type ===
TokenType.LeftSquareBracket)i++;else return 0;var l=undefined;if(l = checkSC(i)
)i += l;if(l = checkAttributeName(i))i += l;else return 0;if(l = checkSC(i))i +=
l;if(tokens[i].type === TokenType.RightSquareBracket)i++;else return 0;return i
- start;}function getAttributeSelector2(){var type=NodeType.AttributeSelectorTy
pe;var token=tokens[pos];var line=token.ln;var column=token.col;var content=[];
// Skip `[`. | 9634 » */ |
| 1759 » pos++;content = content.concat(getSC());content.push(getAttributeName())
;content = content.concat(getSC()); // Skip `]`. | 9635 » function checkAttributeSelector2(i) { |
| 1760 » pos++;var end=getLastPosition(content,line,column,1);return newNode(type
,content,line,column,end);}function checkAttributeName(i){var start=i;var l=unde
fined;if(l = checkNamePrefix(i))i += l;if(l = checkIdentOrInterpolation(i))i +=
l;else return 0;return i - start;}function getAttributeName(){var type=NodeType.
AttributeNameType;var token=tokens[pos];var line=token.ln;var column=token.col;v
ar content=[];if(checkNamePrefix(pos))content.push(getNamePrefix());content = co
ntent.concat(getIdentOrInterpolation());return newNode(type,content,line,column)
;}function checkAttributeMatch(i){var l=undefined;if(l = checkAttributeMatch1(i)
)tokens[i].attributeMatchType = 1;else if(l = checkAttributeMatch2(i))tokens[i].
attributeMatchType = 2;return l;}function getAttributeMatch(){var type=tokens[po
s].attributeMatchType;if(type === 1)return getAttributeMatch1();else return getA
ttributeMatch2();}function checkAttributeMatch1(i){var start=i;var type=tokens[i
].type;if(type === TokenType.Tilde || type === TokenType.VerticalLine || type ==
= TokenType.CircumflexAccent || type === TokenType.DollarSign || type === TokenT
ype.Asterisk)i++;else return 0;if(tokens[i].type === TokenType.EqualsSign)i++;el
se return 0;return i - start;}function getAttributeMatch1(){var type=NodeType.At
tributeMatchType;var token=tokens[pos];var line=token.ln;var column=token.col;va
r content=tokens[pos].value + tokens[pos + 1].value;pos += 2;return newNode(type
,content,line,column);}function checkAttributeMatch2(i){if(tokens[i].type === To
kenType.EqualsSign)return 1;else return 0;}function getAttributeMatch2(){var typ
e=NodeType.AttributeMatchType;var token=tokens[pos];var line=token.ln;var column
=token.col;var content='=';pos++;return newNode(type,content,line,column);}funct
ion checkAttributeValue(i){return checkString(i) || checkIdentOrInterpolation(i)
;}function getAttributeValue(){var type=NodeType.AttributeValueType;var token=to
kens[pos];var line=token.ln;var column=token.col;var content=[];if(checkString(p
os))content.push(getString());else content = content.concat(getIdentOrInterpolat
ion());return newNode(type,content,line,column);}function checkAttributeFlags(i)
{return checkIdentOrInterpolation(i);}function getAttributeFlags(){var type=Node
Type.AttributeFlagsType;var token=tokens[pos];var line=token.ln;var column=token
.col;var content=getIdentOrInterpolation();return newNode(type,content,line,colu
mn);}function checkNamePrefix(i){if(i >= tokensLength)return 0;var l=undefined;i
f(l = checkNamePrefix1(i))tokens[i].namePrefixType = 1;else if(l = checkNamePref
ix2(i))tokens[i].namePrefixType = 2;return l;}function getNamePrefix(){var type=
tokens[pos].namePrefixType;if(type === 1)return getNamePrefix1();else return get
NamePrefix2();} /** | 9636 » var start = i; |
| 9637 |
| 9638 » if (tokens[i].type === TokenType.LeftSquareBracket) i++;else return 0; |
| 9639 |
| 9640 » var l = void 0; |
| 9641 » if (l = checkSC(i)) i += l; |
| 9642 |
| 9643 » if (l = checkAttributeName(i)) i += l;else return 0; |
| 9644 |
| 9645 » if (l = checkSC(i)) i += l; |
| 9646 |
| 9647 » if (tokens[i].type === TokenType.RightSquareBracket) i++;else return 0
; |
| 9648 |
| 9649 » return i - start; |
| 9650 » } |
| 9651 |
| 9652 » function getAttributeSelector2() { |
| 9653 » var type = NodeType.AttributeSelectorType; |
| 9654 » var token = tokens[pos]; |
| 9655 » var line = token.ln; |
| 9656 » var column = token.col; |
| 9657 » var content = []; |
| 9658 |
| 9659 » // Skip `[`. |
| 9660 » pos++; |
| 9661 |
| 9662 » content = content.concat(getSC()); |
| 9663 » content.push(getAttributeName()); |
| 9664 » content = content.concat(getSC()); |
| 9665 |
| 9666 » // Skip `]`. |
| 9667 » pos++; |
| 9668 |
| 9669 » var end = getLastPosition(content, line, column, 1); |
| 9670 » return newNode(type, content, line, column, end); |
| 9671 » } |
| 9672 |
| 9673 » function checkAttributeName(i) { |
| 9674 » var start = i; |
| 9675 » var l = void 0; |
| 9676 |
| 9677 » if (l = checkNamePrefix(i)) i += l; |
| 9678 |
| 9679 » if (l = checkIdentOrInterpolation(i)) i += l;else return 0; |
| 9680 |
| 9681 » return i - start; |
| 9682 » } |
| 9683 |
| 9684 » function getAttributeName() { |
| 9685 » var type = NodeType.AttributeNameType; |
| 9686 » var token = tokens[pos]; |
| 9687 » var line = token.ln; |
| 9688 » var column = token.col; |
| 9689 » var content = []; |
| 9690 |
| 9691 » if (checkNamePrefix(pos)) content.push(getNamePrefix()); |
| 9692 » content = content.concat(getIdentOrInterpolation()); |
| 9693 |
| 9694 » return newNode(type, content, line, column); |
| 9695 » } |
| 9696 |
| 9697 » function checkAttributeMatch(i) { |
| 9698 » var l = void 0; |
| 9699 » if (l = checkAttributeMatch1(i)) tokens[i].attributeMatchType = 1;else
if (l = checkAttributeMatch2(i)) tokens[i].attributeMatchType = 2; |
| 9700 |
| 9701 » return l; |
| 9702 » } |
| 9703 |
| 9704 » function getAttributeMatch() { |
| 9705 » var type = tokens[pos].attributeMatchType; |
| 9706 » if (type === 1) return getAttributeMatch1();else return getAttributeMa
tch2(); |
| 9707 » } |
| 9708 |
| 9709 » function checkAttributeMatch1(i) { |
| 9710 » var start = i; |
| 9711 |
| 9712 » var type = tokens[i].type; |
| 9713 » if (type === TokenType.Tilde || type === TokenType.VerticalLine || typ
e === TokenType.CircumflexAccent || type === TokenType.DollarSign || type === To
kenType.Asterisk) i++;else return 0; |
| 9714 |
| 9715 » if (tokens[i].type === TokenType.EqualsSign) i++;else return 0; |
| 9716 |
| 9717 » return i - start; |
| 9718 » } |
| 9719 |
| 9720 » function getAttributeMatch1() { |
| 9721 » var type = NodeType.AttributeMatchType; |
| 9722 » var token = tokens[pos]; |
| 9723 » var line = token.ln; |
| 9724 » var column = token.col; |
| 9725 » var content = tokens[pos].value + tokens[pos + 1].value; |
| 9726 » pos += 2; |
| 9727 |
| 9728 » return newNode(type, content, line, column); |
| 9729 » } |
| 9730 |
| 9731 » function checkAttributeMatch2(i) { |
| 9732 » if (tokens[i].type === TokenType.EqualsSign) return 1;else return 0; |
| 9733 » } |
| 9734 |
| 9735 » function getAttributeMatch2() { |
| 9736 » var type = NodeType.AttributeMatchType; |
| 9737 » var token = tokens[pos]; |
| 9738 » var line = token.ln; |
| 9739 » var column = token.col; |
| 9740 » var content = '='; |
| 9741 |
| 9742 » pos++; |
| 9743 » return newNode(type, content, line, column); |
| 9744 » } |
| 9745 |
| 9746 » function checkAttributeValue(i) { |
| 9747 » return checkString(i) || checkIdentOrInterpolation(i); |
| 9748 » } |
| 9749 |
| 9750 » function getAttributeValue() { |
| 9751 » var type = NodeType.AttributeValueType; |
| 9752 » var token = tokens[pos]; |
| 9753 » var line = token.ln; |
| 9754 » var column = token.col; |
| 9755 » var content = []; |
| 9756 |
| 9757 » if (checkString(pos)) content.push(getString());else content = content
.concat(getIdentOrInterpolation()); |
| 9758 |
| 9759 » return newNode(type, content, line, column); |
| 9760 » } |
| 9761 |
| 9762 » function checkAttributeFlags(i) { |
| 9763 » return checkIdentOrInterpolation(i); |
| 9764 » } |
| 9765 |
| 9766 » function getAttributeFlags() { |
| 9767 » var type = NodeType.AttributeFlagsType; |
| 9768 » var token = tokens[pos]; |
| 9769 » var line = token.ln; |
| 9770 » var column = token.col; |
| 9771 » var content = getIdentOrInterpolation(); |
| 9772 |
| 9773 » return newNode(type, content, line, column); |
| 9774 » } |
| 9775 |
| 9776 » function checkNamePrefix(i) { |
| 9777 » if (i >= tokensLength) return 0; |
| 9778 |
| 9779 » var l = void 0; |
| 9780 » if (l = checkNamePrefix1(i)) tokens[i].namePrefixType = 1;else if (l =
checkNamePrefix2(i)) tokens[i].namePrefixType = 2; |
| 9781 |
| 9782 » return l; |
| 9783 » } |
| 9784 |
| 9785 » function getNamePrefix() { |
| 9786 » var type = tokens[pos].namePrefixType; |
| 9787 » if (type === 1) return getNamePrefix1();else return getNamePrefix2(); |
| 9788 » } |
| 9789 |
| 9790 » /** |
| 1761 * (1) `panda|` | 9791 * (1) `panda|` |
| 1762 * (2) `panda<comment>|` | 9792 * (2) `panda<comment>|` |
| 1763 » */function checkNamePrefix1(i){var start=i;var l=undefined;if(l = check
NamespacePrefix(i))i += l;else return 0;if(l = checkCommentML(i))i += l;if(l = c
heckNamespaceSeparator(i))i += l;else return 0;return i - start;}function getNam
ePrefix1(){var type=NodeType.NamePrefixType;var token=tokens[pos];var line=token
.ln;var column=token.col;var content=[];content.push(getNamespacePrefix());if(ch
eckCommentML(pos))content.push(getCommentML());content.push(getNamespaceSeparato
r());return newNode(type,content,line,column);} /** | 9793 » */ |
| 9794 » function checkNamePrefix1(i) { |
| 9795 » var start = i; |
| 9796 » var l = void 0; |
| 9797 |
| 9798 » if (l = checkNamespacePrefix(i)) i += l;else return 0; |
| 9799 |
| 9800 » if (l = checkCommentML(i)) i += l; |
| 9801 |
| 9802 » if (l = checkNamespaceSeparator(i)) i += l;else return 0; |
| 9803 |
| 9804 » return i - start; |
| 9805 » } |
| 9806 |
| 9807 » function getNamePrefix1() { |
| 9808 » var type = NodeType.NamePrefixType; |
| 9809 » var token = tokens[pos]; |
| 9810 » var line = token.ln; |
| 9811 » var column = token.col; |
| 9812 » var content = []; |
| 9813 |
| 9814 » content.push(getNamespacePrefix()); |
| 9815 |
| 9816 » if (checkCommentML(pos)) content.push(getCommentML()); |
| 9817 |
| 9818 » content.push(getNamespaceSeparator()); |
| 9819 |
| 9820 » return newNode(type, content, line, column); |
| 9821 » } |
| 9822 |
| 9823 » /** |
| 1764 * (1) `|` | 9824 * (1) `|` |
| 1765 » */function checkNamePrefix2(i){return checkNamespaceSeparator(i);}funct
ion getNamePrefix2(){var type=NodeType.NamePrefixType;var token=tokens[pos];var
line=token.ln;var column=token.col;var content=[getNamespaceSeparator()];return
newNode(type,content,line,column);} /** | 9825 » */ |
| 9826 » function checkNamePrefix2(i) { |
| 9827 » return checkNamespaceSeparator(i); |
| 9828 » } |
| 9829 |
| 9830 » function getNamePrefix2() { |
| 9831 » var type = NodeType.NamePrefixType; |
| 9832 » var token = tokens[pos]; |
| 9833 » var line = token.ln; |
| 9834 » var column = token.col; |
| 9835 » var content = [getNamespaceSeparator()]; |
| 9836 |
| 9837 » return newNode(type, content, line, column); |
| 9838 » } |
| 9839 |
| 9840 » /** |
| 1766 * (1) `*` | 9841 * (1) `*` |
| 1767 * (2) `panda` | 9842 * (2) `panda` |
| 1768 » */function checkNamespacePrefix(i){if(i >= tokensLength)return 0;var l=
undefined;if(tokens[i].type === TokenType.Asterisk)return 1;else if(l = checkIde
ntOrInterpolation(i))return l;else return 0;}function getNamespacePrefix(){var t
ype=NodeType.NamespacePrefixType;var token=tokens[pos];var line=token.ln;var col
umn=token.col;var content=[];if(checkIdentOrInterpolation(pos))content = content
.concat(getIdentOrInterpolation());return newNode(type,content,line,column);} /*
* | 9843 » */ |
| 9844 » function checkNamespacePrefix(i) { |
| 9845 » if (i >= tokensLength) return 0; |
| 9846 |
| 9847 » var l = void 0; |
| 9848 |
| 9849 » if (tokens[i].type === TokenType.Asterisk) return 1;else if (l = check
IdentOrInterpolation(i)) return l;else return 0; |
| 9850 » } |
| 9851 |
| 9852 » function getNamespacePrefix() { |
| 9853 » var type = NodeType.NamespacePrefixType; |
| 9854 » var token = tokens[pos]; |
| 9855 » var line = token.ln; |
| 9856 » var column = token.col; |
| 9857 » var content = []; |
| 9858 |
| 9859 » if (token.type === TokenType.Asterisk) { |
| 9860 » var asteriskNode = newNode(NodeType.IdentType, '*', token.ln, token.
col); |
| 9861 » content.push(asteriskNode); |
| 9862 » pos++; |
| 9863 » } else if (checkIdentOrInterpolation(pos)) content = content.concat(ge
tIdentOrInterpolation()); |
| 9864 |
| 9865 » return newNode(type, content, line, column); |
| 9866 » } |
| 9867 |
| 9868 » /** |
| 1769 * (1) `|` | 9869 * (1) `|` |
| 1770 » */function checkNamespaceSeparator(i){if(i >= tokensLength)return 0;if(
tokens[i].type === TokenType.VerticalLine)return 1;else return 0;}function getNa
mespaceSeparator(){var type=NodeType.NamespaceSeparatorType;var token=tokens[pos
];var line=token.ln;var column=token.col;var content='|';pos++;return newNode(ty
pe,content,line,column);} | 9870 » */ |
| 9871 » function checkNamespaceSeparator(i) { |
| 9872 » if (i >= tokensLength) return 0; |
| 9873 |
| 9874 » if (tokens[i].type !== TokenType.VerticalLine) return 0; |
| 9875 |
| 9876 » // Return false if `|=` - [attr|=value] |
| 9877 » if (tokens[i + 1] && tokens[i + 1].type === TokenType.EqualsSign) retu
rn 0; |
| 9878 |
| 9879 » return 1; |
| 9880 » } |
| 9881 |
| 9882 » function getNamespaceSeparator() { |
| 9883 » var type = NodeType.NamespaceSeparatorType; |
| 9884 » var token = tokens[pos]; |
| 9885 » var line = token.ln; |
| 9886 » var column = token.col; |
| 9887 » var content = '|'; |
| 9888 |
| 9889 » pos++; |
| 9890 » return newNode(type, content, line, column); |
| 9891 » } |
| 9892 |
| 9893 » module.exports = function (_tokens, context) { |
| 9894 » tokens = _tokens; |
| 9895 » tokensLength = tokens.length; |
| 9896 » pos = 0; |
| 9897 |
| 9898 » return contexts[context](); |
| 9899 » }; |
| 1771 | 9900 |
| 1772 /***/ }, | 9901 /***/ }, |
| 1773 /* 14 */ | 9902 /* 20 */ |
| 1774 /***/ function(module, exports) { | 9903 /***/ function(module, exports, __webpack_require__) { |
| 1775 | 9904 |
| 1776 'use strict'; | 9905 'use strict'; |
| 1777 | 9906 |
| 1778 module.exports = { | |
| 1779 ArgumentsType: 'arguments', | |
| 1780 AtkeywordType: 'atkeyword', | |
| 1781 AtruleType: 'atrule', | |
| 1782 AttributeSelectorType: 'attributeSelector', | |
| 1783 AttributeNameType: 'attributeName', | |
| 1784 AttributeFlagsType: 'attributeFlags', | |
| 1785 AttributeMatchType: 'attributeMatch', | |
| 1786 AttributeValueType: 'attributeValue', | |
| 1787 BlockType: 'block', | |
| 1788 BracketsType: 'brackets', | |
| 1789 ClassType: 'class', | |
| 1790 CombinatorType: 'combinator', | |
| 1791 CommentMLType: 'multilineComment', | |
| 1792 CommentSLType: 'singlelineComment', | |
| 1793 ConditionType: 'condition', | |
| 1794 ConditionalStatementType: 'conditionalStatement', | |
| 1795 DeclarationType: 'declaration', | |
| 1796 DeclDelimType: 'declarationDelimiter', | |
| 1797 DefaultType: 'default', | |
| 1798 DelimType: 'delimiter', | |
| 1799 DimensionType: 'dimension', | |
| 1800 EscapedStringType: 'escapedString', | |
| 1801 ExtendType: 'extend', | |
| 1802 ExpressionType: 'expression', | |
| 1803 FunctionType: 'function', | |
| 1804 GlobalType: 'global', | |
| 1805 IdentType: 'ident', | |
| 1806 ImportantType: 'important', | |
| 1807 IncludeType: 'include', | |
| 1808 InterpolationType: 'interpolation', | |
| 1809 InterpolatedVariableType: 'interpolatedVariable', | |
| 1810 KeyframesSelectorType: 'keyframesSelector', | |
| 1811 LoopType: 'loop', | |
| 1812 MixinType: 'mixin', | |
| 1813 NamePrefixType: 'namePrefix', | |
| 1814 NamespacePrefixType: 'namespacePrefix', | |
| 1815 NamespaceSeparatorType: 'namespaceSeparator', | |
| 1816 NumberType: 'number', | |
| 1817 OperatorType: 'operator', | |
| 1818 OptionalType: 'optional', | |
| 1819 ParenthesesType: 'parentheses', | |
| 1820 ParentSelectorType: 'parentSelector', | |
| 1821 ParentSelectorExtensionType: 'parentSelectorExtension', | |
| 1822 PercentageType: 'percentage', | |
| 1823 PlaceholderType: 'placeholder', | |
| 1824 ProgidType: 'progid', | |
| 1825 PropertyType: 'property', | |
| 1826 PropertyDelimType: 'propertyDelimiter', | |
| 1827 PseudocType: 'pseudoClass', | |
| 1828 PseudoeType: 'pseudoElement', | |
| 1829 RawType: 'raw', | |
| 1830 RulesetType: 'ruleset', | |
| 1831 SType: 'space', | |
| 1832 SelectorType: 'selector', | |
| 1833 ShashType: 'id', | |
| 1834 StringType: 'string', | |
| 1835 StylesheetType: 'stylesheet', | |
| 1836 TypeSelectorType: 'typeSelector', | |
| 1837 UriType: 'uri', | |
| 1838 ValueType: 'value', | |
| 1839 VariableType: 'variable', | |
| 1840 VariablesListType: 'variablesList', | |
| 1841 VhashType: 'color' | |
| 1842 }; | |
| 1843 | |
| 1844 /***/ }, | |
| 1845 /* 15 */ | |
| 1846 /***/ function(module, exports, __webpack_require__) { | |
| 1847 | |
| 1848 'use strict'; | |
| 1849 | |
| 1850 module.exports = function (css, tabSize) { | 9907 module.exports = function (css, tabSize) { |
| 1851 » var TokenType = __webpack_require__(12); | 9908 » var TokenType = __webpack_require__(13); |
| 1852 | 9909 |
| 1853 var tokens = []; | 9910 var tokens = []; |
| 1854 var urlMode = false; | 9911 var urlMode = false; |
| 1855 » var blockMode = 0; | 9912 » var c = void 0; // Current character |
| 1856 » var c = undefined; // Current character | 9913 » var cn = void 0; // Next character |
| 1857 » var cn = undefined; // Next character | |
| 1858 var pos = 0; | 9914 var pos = 0; |
| 1859 var tn = 0; | 9915 var tn = 0; |
| 1860 var ln = 1; | 9916 var ln = 1; |
| 1861 var col = 1; | 9917 var col = 1; |
| 1862 | 9918 |
| 1863 var Punctuation = { | 9919 var Punctuation = { |
| 1864 ' ': TokenType.Space, | 9920 ' ': TokenType.Space, |
| 1865 '\n': TokenType.Newline, | 9921 '\n': TokenType.Newline, |
| 1866 '\r': TokenType.Newline, | 9922 '\r': TokenType.Newline, |
| 1867 '\t': TokenType.Tab, | 9923 '\t': TokenType.Tab, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1889 '>': TokenType.GreaterThanSign, | 9945 '>': TokenType.GreaterThanSign, |
| 1890 '?': TokenType.QuestionMark, | 9946 '?': TokenType.QuestionMark, |
| 1891 '@': TokenType.CommercialAt, | 9947 '@': TokenType.CommercialAt, |
| 1892 '[': TokenType.LeftSquareBracket, | 9948 '[': TokenType.LeftSquareBracket, |
| 1893 ']': TokenType.RightSquareBracket, | 9949 ']': TokenType.RightSquareBracket, |
| 1894 '^': TokenType.CircumflexAccent, | 9950 '^': TokenType.CircumflexAccent, |
| 1895 '_': TokenType.LowLine, | 9951 '_': TokenType.LowLine, |
| 1896 '{': TokenType.LeftCurlyBracket, | 9952 '{': TokenType.LeftCurlyBracket, |
| 1897 '|': TokenType.VerticalLine, | 9953 '|': TokenType.VerticalLine, |
| 1898 '}': TokenType.RightCurlyBracket, | 9954 '}': TokenType.RightCurlyBracket, |
| 1899 » '~': TokenType.Tilde | 9955 » '~': TokenType.Tilde, |
| 9956 » '`': TokenType.Backtick |
| 1900 }; | 9957 }; |
| 1901 | 9958 |
| 1902 /** | 9959 /** |
| 1903 * Add a token to the token list | 9960 * Add a token to the token list |
| 1904 * @param {string} type | 9961 * @param {string} type |
| 1905 * @param {string} value | 9962 * @param {string} value |
| 1906 */ | 9963 */ |
| 1907 function pushToken(type, value, column) { | 9964 function pushToken(type, value, column) { |
| 1908 tokens.push({ | 9965 tokens.push({ |
| 1909 tn: tn++, | 9966 tn: tn++, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1978 } | 10035 } |
| 1979 | 10036 |
| 1980 /** | 10037 /** |
| 1981 * Parse identifier | 10038 * Parse identifier |
| 1982 * @param {string} css Unparsed part of CSS string | 10039 * @param {string} css Unparsed part of CSS string |
| 1983 */ | 10040 */ |
| 1984 function parseIdentifier(css) { | 10041 function parseIdentifier(css) { |
| 1985 var start = pos; | 10042 var start = pos; |
| 1986 | 10043 |
| 1987 // Skip all opening slashes: | 10044 // Skip all opening slashes: |
| 1988 » while (css.charAt(pos) === '/') pos++; | 10045 » while (css.charAt(pos) === '/') { |
| 1989 | 10046 » pos++; |
| 1990 » // Read the string until we meet a punctuation mark: | 10047 » } // Read the string until we meet a punctuation mark: |
| 1991 for (; pos < css.length; pos++) { | 10048 for (; pos < css.length; pos++) { |
| 1992 // Skip all '\': | 10049 // Skip all '\': |
| 1993 if (css.charAt(pos) === '\\') pos++;else if (css.charAt(pos) in Pu
nctuation) break; | 10050 if (css.charAt(pos) === '\\') pos++;else if (css.charAt(pos) in Pu
nctuation) break; |
| 1994 } | 10051 } |
| 1995 | 10052 |
| 1996 var ident = css.substring(start, pos--); | 10053 var ident = css.substring(start, pos--); |
| 1997 | 10054 |
| 1998 // Enter url mode if parsed substring is `url`: | 10055 // Enter url mode if parsed substring is `url`: |
| 1999 if (!urlMode && ident === 'url' && css.charAt(pos + 1) === '(') { | 10056 if (!urlMode && ident === 'url' && css.charAt(pos + 1) === '(') { |
| 2000 urlMode = true; | 10057 urlMode = true; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2126 // Check for CRLF here or just LF | 10183 // Check for CRLF here or just LF |
| 2127 if (c === '\r' && cn === '\n' || c === '\n') { | 10184 if (c === '\r' && cn === '\n' || c === '\n') { |
| 2128 // If \r we know the next character is \n due to s
tatement above | 10185 // If \r we know the next character is \n due to s
tatement above |
| 2129 // so we push a CRLF token type to the token list
and importantly | 10186 // so we push a CRLF token type to the token list
and importantly |
| 2130 // skip the next character so as not to double cou
nt newlines or | 10187 // skip the next character so as not to double cou
nt newlines or |
| 2131 // columns etc | 10188 // columns etc |
| 2132 if (c === '\r') { | 10189 if (c === '\r') { |
| 2133 pushToken(TokenType.Newline, '\r\n', col); | 10190 pushToken(TokenType.Newline, '\r\n', col); |
| 2134 pos++; // If CRLF skip the next character and pu
sh crlf token | 10191 pos++; // If CRLF skip the next character and pu
sh crlf token |
| 2135 } else if (c === '\n') { | 10192 } else if (c === '\n') { |
| 2136 » // If just a LF newline and not part of CRLF n
ewline we can just | 10193 » // If just a LF newline and not part of CRLF new
line we can just |
| 2137 » // push punctuation as usual | 10194 » // push punctuation as usual |
| 2138 » pushToken(Punctuation[c], c, col); | 10195 » pushToken(Punctuation[c], c, col); |
| 2139 » } | 10196 » } |
| 2140 | 10197 |
| 2141 ln++; // Go to next line | 10198 ln++; // Go to next line |
| 2142 col = 0; // Reset the column count | 10199 col = 0; // Reset the column count |
| 2143 } else if (c !== '\r' && c !== '\n') { | 10200 } else if (c !== '\r' && c !== '\n') { |
| 2144 » // Handle all other punctuation and add to list
of tokens | 10201 » // Handle all other punctuation and add to list of
tokens |
| 2145 » pushToken(Punctuation[c], c, col); | 10202 » pushToken(Punctuation[c], c, col); |
| 2146 » } // Go to next line | 10203 » } // Go to next line |
| 2147 if (c === ')') urlMode = false; // Exit url mode | 10204 if (c === ')') urlMode = false; // Exit url mode |
| 2148 if (c === '{') blockMode++; // Enter a block | |
| 2149 if (c === '}') blockMode--; // Exit a block | |
| 2150 else if (c === '\t' && tabSize > 1) col += tabSize -
1; | 10205 else if (c === '\t' && tabSize > 1) col += tabSize -
1; |
| 2151 } | 10206 } |
| 2152 | 10207 |
| 2153 // If current character is a decimal digit: | 10208 // If current character is a decimal digit: |
| 2154 else if (isDecimalDigit(c)) { | 10209 else if (isDecimalDigit(c)) { |
| 2155 parseDecimalNumber(css); | 10210 parseDecimalNumber(css); |
| 2156 } | 10211 } |
| 2157 | 10212 |
| 2158 // If current character is anything else: | 10213 // If current character is anything else: |
| 2159 else { | 10214 else { |
| 2160 parseIdentifier(css); | 10215 parseIdentifier(css); |
| 2161 } | 10216 } |
| 2162 } | 10217 } |
| 2163 | 10218 |
| 2164 return tokens; | 10219 return tokens; |
| 2165 } | 10220 } |
| 2166 | 10221 |
| 2167 return getTokens(css); | 10222 return getTokens(css); |
| 2168 }; | 10223 }; |
| 2169 | 10224 |
| 2170 /***/ }, | 10225 /***/ }, |
| 2171 /* 16 */ | 10226 /* 21 */ |
| 2172 /***/ function(module, exports, __webpack_require__) { | 10227 /***/ function(module, exports, __webpack_require__) { |
| 2173 | 10228 |
| 2174 'use strict'; | 10229 'use strict'; |
| 2175 | 10230 |
| 2176 var Node = __webpack_require__(1); | 10231 var Node = __webpack_require__(1); |
| 2177 » var NodeTypes = __webpack_require__(14); | 10232 » var NodeTypes = __webpack_require__(15); |
| 2178 | 10233 |
| 2179 module.exports = function () { | 10234 module.exports = function () { |
| 2180 return new Node({ | 10235 return new Node({ |
| 2181 type: NodeTypes.StylesheetType, | 10236 type: NodeTypes.StylesheetType, |
| 2182 content: [], | 10237 content: [], |
| 2183 start: [0, 0], | 10238 start: [0, 0], |
| 2184 end: [0, 0] | 10239 end: [0, 0] |
| 2185 }); | 10240 }); |
| 2186 }; | 10241 }; |
| 2187 | 10242 |
| 2188 /***/ } | 10243 /***/ } |
| 2189 /******/ ]) | 10244 /******/ ]) |
| 2190 }); | 10245 }); |
| 2191 ; | 10246 ; |
| OLD | NEW |