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.4 KB
|
Line | |
---|
1 |
|
---|
2 | /*!
|
---|
3 | * Stylus - Root
|
---|
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 `Root` node.
|
---|
16 | *
|
---|
17 | * @api public
|
---|
18 | */
|
---|
19 |
|
---|
20 | var Root = module.exports = function Root(){
|
---|
21 | this.nodes = [];
|
---|
22 | };
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Inherit from `Node.prototype`.
|
---|
26 | */
|
---|
27 |
|
---|
28 | Root.prototype.__proto__ = Node.prototype;
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * Push a `node` to this block.
|
---|
32 | *
|
---|
33 | * @param {Node} node
|
---|
34 | * @api public
|
---|
35 | */
|
---|
36 |
|
---|
37 | Root.prototype.push = function(node){
|
---|
38 | this.nodes.push(node);
|
---|
39 | };
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Unshift a `node` to this block.
|
---|
43 | *
|
---|
44 | * @param {Node} node
|
---|
45 | * @api public
|
---|
46 | */
|
---|
47 |
|
---|
48 | Root.prototype.unshift = function(node){
|
---|
49 | this.nodes.unshift(node);
|
---|
50 | };
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * Return a clone of this node.
|
---|
54 | *
|
---|
55 | * @return {Node}
|
---|
56 | * @api public
|
---|
57 | */
|
---|
58 |
|
---|
59 | Root.prototype.clone = function(){
|
---|
60 | var clone = new Root();
|
---|
61 | clone.lineno = this.lineno;
|
---|
62 | clone.column = this.column;
|
---|
63 | clone.filename = this.filename;
|
---|
64 | this.nodes.forEach(function(node){
|
---|
65 | clone.push(node.clone(clone, clone));
|
---|
66 | });
|
---|
67 | return clone;
|
---|
68 | };
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * Return "root".
|
---|
72 | *
|
---|
73 | * @return {String}
|
---|
74 | * @api public
|
---|
75 | */
|
---|
76 |
|
---|
77 | Root.prototype.toString = function(){
|
---|
78 | return '[Root]';
|
---|
79 | };
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * Return a JSON representation of this node.
|
---|
83 | *
|
---|
84 | * @return {Object}
|
---|
85 | * @api public
|
---|
86 | */
|
---|
87 |
|
---|
88 | Root.prototype.toJSON = function(){
|
---|
89 | return {
|
---|
90 | __type: 'Root',
|
---|
91 | nodes: this.nodes,
|
---|
92 | lineno: this.lineno,
|
---|
93 | column: this.column,
|
---|
94 | filename: this.filename
|
---|
95 | };
|
---|
96 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.