source: trip-planner-front/node_modules/stylus/lib/nodes/selector.js@ 1ad8e64

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

initial commit

  • Property mode set to 100644
File size: 1.7 KB
Line 
1
2/*!
3 * Stylus - Selector
4 * Copyright (c) Automattic <developer.wordpress.com>
5 * MIT Licensed
6 */
7
8/**
9 * Module dependencies.
10 */
11
12var Block = require('./block')
13 , Node = require('./node');
14
15/**
16 * Initialize a new `Selector` with the given `segs`.
17 *
18 * @param {Array} segs
19 * @api public
20 */
21
22var Selector = module.exports = function Selector(segs){
23 Node.call(this);
24 this.inherits = true;
25 this.segments = segs;
26 this.optional = false;
27};
28
29/**
30 * Inherit from `Node.prototype`.
31 */
32
33Selector.prototype.__proto__ = Node.prototype;
34
35/**
36 * Return the selector string.
37 *
38 * @return {String}
39 * @api public
40 */
41
42Selector.prototype.toString = function(){
43 return this.segments.join('') + (this.optional ? ' !optional' : '');
44};
45
46/**
47 * Check if this is placeholder selector.
48 *
49 * @return {Boolean}
50 * @api public
51 */
52
53Selector.prototype.__defineGetter__('isPlaceholder', function(){
54 return this.val && ~this.val.substr(0, 2).indexOf('$');
55});
56
57/**
58 * Return a clone of this node.
59 *
60 * @return {Node}
61 * @api public
62 */
63
64Selector.prototype.clone = function(parent){
65 var clone = new Selector;
66 clone.lineno = this.lineno;
67 clone.column = this.column;
68 clone.filename = this.filename;
69 clone.inherits = this.inherits;
70 clone.val = this.val;
71 clone.segments = this.segments.map(function(node){ return node.clone(parent, clone); });
72 clone.optional = this.optional;
73 return clone;
74};
75
76/**
77 * Return a JSON representation of this node.
78 *
79 * @return {Object}
80 * @api public
81 */
82
83Selector.prototype.toJSON = function(){
84 return {
85 __type: 'Selector',
86 inherits: this.inherits,
87 segments: this.segments,
88 optional: this.optional,
89 val: this.val,
90 lineno: this.lineno,
91 column: this.column,
92 filename: this.filename
93 };
94};
Note: See TracBrowser for help on using the repository browser.