Last change
on this file since 6c1585f was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.4 KB
|
Line | |
---|
1 |
|
---|
2 | /*!
|
---|
3 | * Stylus - If
|
---|
4 | * Copyright (c) Automattic <developer.wordpress.com>
|
---|
5 | * MIT Licensed
|
---|
6 | */
|
---|
7 |
|
---|
8 | /**
|
---|
9 | * Module dependencies.
|
---|
10 | */
|
---|
11 |
|
---|
12 | var Node = require('./node');
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * Initialize a new `If` with the given `cond`.
|
---|
16 | *
|
---|
17 | * @param {Expression} cond
|
---|
18 | * @param {Boolean|Block} negate, block
|
---|
19 | * @api public
|
---|
20 | */
|
---|
21 |
|
---|
22 | var If = module.exports = function If(cond, negate){
|
---|
23 | Node.call(this);
|
---|
24 | this.cond = cond;
|
---|
25 | this.elses = [];
|
---|
26 | if (negate && negate.nodeName) {
|
---|
27 | this.block = negate;
|
---|
28 | } else {
|
---|
29 | this.negate = negate;
|
---|
30 | }
|
---|
31 | };
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * Inherit from `Node.prototype`.
|
---|
35 | */
|
---|
36 |
|
---|
37 | If.prototype.__proto__ = Node.prototype;
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * Return a clone of this node.
|
---|
41 | *
|
---|
42 | * @return {Node}
|
---|
43 | * @api public
|
---|
44 | */
|
---|
45 |
|
---|
46 | If.prototype.clone = function(parent){
|
---|
47 | var clone = new If();
|
---|
48 | clone.cond = this.cond.clone(parent, clone);
|
---|
49 | clone.block = this.block.clone(parent, clone);
|
---|
50 | clone.elses = this.elses.map(function(node){ return node.clone(parent, clone); });
|
---|
51 | clone.negate = this.negate;
|
---|
52 | clone.postfix = this.postfix;
|
---|
53 | clone.lineno = this.lineno;
|
---|
54 | clone.column = this.column;
|
---|
55 | clone.filename = this.filename;
|
---|
56 | return clone;
|
---|
57 | };
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * Return a JSON representation of this node.
|
---|
61 | *
|
---|
62 | * @return {Object}
|
---|
63 | * @api public
|
---|
64 | */
|
---|
65 |
|
---|
66 | If.prototype.toJSON = function(){
|
---|
67 | return {
|
---|
68 | __type: 'If',
|
---|
69 | cond: this.cond,
|
---|
70 | block: this.block,
|
---|
71 | elses: this.elses,
|
---|
72 | negate: this.negate,
|
---|
73 | postfix: this.postfix,
|
---|
74 | lineno: this.lineno,
|
---|
75 | column: this.column,
|
---|
76 | filename: this.filename
|
---|
77 | };
|
---|
78 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.