source: trip-planner-front/node_modules/stylus/lib/nodes/feature.js@ 6a3a178

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

initial commit

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