source: trip-planner-front/node_modules/stylus/lib/functions/selector.js@ 84d0fbb

Last change on this file since 84d0fbb was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.8 KB
Line 
1var utils = require('../utils');
2
3/**
4 * Return the current selector or compile
5 * selector from a string or a list.
6 *
7 * @param {String|Expression}
8 * @return {String}
9 * @api public
10 */
11
12(module.exports = function selector(){
13 var stack = this.selectorStack
14 , args = [].slice.call(arguments);
15
16 if (1 == args.length) {
17 var expr = utils.unwrap(args[0])
18 , len = expr.nodes.length;
19
20 // selector('.a')
21 if (1 == len) {
22 utils.assertString(expr.first, 'selector');
23 var SelectorParser = require('../selector-parser')
24 , val = expr.first.string
25 , parsed = new SelectorParser(val).parse().val;
26
27 if (parsed == val) return val;
28
29 stack.push(parse(val));
30 } else if (len > 1) {
31 // selector-list = '.a', '.b', '.c'
32 // selector(selector-list)
33 if (expr.isList) {
34 pushToStack(expr.nodes, stack);
35 // selector('.a' '.b' '.c')
36 } else {
37 stack.push(parse(expr.nodes.map(function(node){
38 utils.assertString(node, 'selector');
39 return node.string;
40 }).join(' ')));
41 }
42 }
43 // selector('.a', '.b', '.c')
44 } else if (args.length > 1) {
45 pushToStack(args, stack);
46 }
47
48 return stack.length ? utils.compileSelectors(stack).join(',') : '&';
49}).raw = true;
50
51function pushToStack(selectors, stack) {
52 selectors.forEach(function(sel) {
53 sel = sel.first;
54 utils.assertString(sel, 'selector');
55 stack.push(parse(sel.string));
56 });
57}
58
59function parse(selector) {
60 var Parser = new require('../parser')
61 , parser = new Parser(selector)
62 , nodes;
63 parser.state.push('selector-parts');
64 nodes = parser.selector();
65 nodes.forEach(function(node) {
66 node.val = node.segments.map(function(seg){
67 return seg.toString();
68 }).join('');
69 });
70 return nodes;
71}
Note: See TracBrowser for help on using the repository browser.