[6a3a178] | 1 |
|
---|
| 2 | /*!
|
---|
| 3 | * Stylus - Arguments
|
---|
| 4 | * Copyright (c) Automattic <developer.wordpress.com>
|
---|
| 5 | * MIT Licensed
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | /**
|
---|
| 9 | * Module dependencies.
|
---|
| 10 | */
|
---|
| 11 |
|
---|
| 12 | var Node = require('./node')
|
---|
| 13 | , nodes = require('../nodes')
|
---|
| 14 | , utils = require('../utils');
|
---|
| 15 |
|
---|
| 16 | /**
|
---|
| 17 | * Initialize a new `Arguments`.
|
---|
| 18 | *
|
---|
| 19 | * @api public
|
---|
| 20 | */
|
---|
| 21 |
|
---|
| 22 | var Arguments = module.exports = function Arguments(){
|
---|
| 23 | nodes.Expression.call(this);
|
---|
| 24 | this.map = {};
|
---|
| 25 | };
|
---|
| 26 |
|
---|
| 27 | /**
|
---|
| 28 | * Inherit from `nodes.Expression.prototype`.
|
---|
| 29 | */
|
---|
| 30 |
|
---|
| 31 | Arguments.prototype.__proto__ = nodes.Expression.prototype;
|
---|
| 32 |
|
---|
| 33 | /**
|
---|
| 34 | * Initialize an `Arguments` object with the nodes
|
---|
| 35 | * from the given `expr`.
|
---|
| 36 | *
|
---|
| 37 | * @param {Expression} expr
|
---|
| 38 | * @return {Arguments}
|
---|
| 39 | * @api public
|
---|
| 40 | */
|
---|
| 41 |
|
---|
| 42 | Arguments.fromExpression = function(expr){
|
---|
| 43 | var args = new Arguments
|
---|
| 44 | , len = expr.nodes.length;
|
---|
| 45 | args.lineno = expr.lineno;
|
---|
| 46 | args.column = expr.column;
|
---|
| 47 | args.isList = expr.isList;
|
---|
| 48 | for (var i = 0; i < len; ++i) {
|
---|
| 49 | args.push(expr.nodes[i]);
|
---|
| 50 | }
|
---|
| 51 | return args;
|
---|
| 52 | };
|
---|
| 53 |
|
---|
| 54 | /**
|
---|
| 55 | * Return a clone of this node.
|
---|
| 56 | *
|
---|
| 57 | * @return {Node}
|
---|
| 58 | * @api public
|
---|
| 59 | */
|
---|
| 60 |
|
---|
| 61 | Arguments.prototype.clone = function(parent){
|
---|
| 62 | var clone = nodes.Expression.prototype.clone.call(this, parent);
|
---|
| 63 | clone.map = {};
|
---|
| 64 | for (var key in this.map) {
|
---|
| 65 | clone.map[key] = this.map[key].clone(parent, clone);
|
---|
| 66 | }
|
---|
| 67 | clone.isList = this.isList;
|
---|
| 68 | clone.lineno = this.lineno;
|
---|
| 69 | clone.column = this.column;
|
---|
| 70 | clone.filename = this.filename;
|
---|
| 71 | return clone;
|
---|
| 72 | };
|
---|
| 73 |
|
---|
| 74 | /**
|
---|
| 75 | * Return a JSON representation of this node.
|
---|
| 76 | *
|
---|
| 77 | * @return {Object}
|
---|
| 78 | * @api public
|
---|
| 79 | */
|
---|
| 80 |
|
---|
| 81 | Arguments.prototype.toJSON = function(){
|
---|
| 82 | return {
|
---|
| 83 | __type: 'Arguments',
|
---|
| 84 | map: this.map,
|
---|
| 85 | isList: this.isList,
|
---|
| 86 | preserve: this.preserve,
|
---|
| 87 | lineno: this.lineno,
|
---|
| 88 | column: this.column,
|
---|
| 89 | filename: this.filename,
|
---|
| 90 | nodes: this.nodes
|
---|
| 91 | };
|
---|
| 92 | };
|
---|