[6a3a178] | 1 |
|
---|
| 2 | /*!
|
---|
| 3 | * Stylus - Call
|
---|
| 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 `Call` with `name` and `args`.
|
---|
| 16 | *
|
---|
| 17 | * @param {String} name
|
---|
| 18 | * @param {Expression} args
|
---|
| 19 | * @api public
|
---|
| 20 | */
|
---|
| 21 |
|
---|
| 22 | var Call = module.exports = function Call(name, args){
|
---|
| 23 | Node.call(this);
|
---|
| 24 | this.name = name;
|
---|
| 25 | this.args = args;
|
---|
| 26 | };
|
---|
| 27 |
|
---|
| 28 | /**
|
---|
| 29 | * Inherit from `Node.prototype`.
|
---|
| 30 | */
|
---|
| 31 |
|
---|
| 32 | Call.prototype.__proto__ = Node.prototype;
|
---|
| 33 |
|
---|
| 34 | /**
|
---|
| 35 | * Return a clone of this node.
|
---|
| 36 | *
|
---|
| 37 | * @return {Node}
|
---|
| 38 | * @api public
|
---|
| 39 | */
|
---|
| 40 |
|
---|
| 41 | Call.prototype.clone = function(parent){
|
---|
| 42 | var clone = new Call(this.name);
|
---|
| 43 | clone.args = this.args.clone(parent, clone);
|
---|
| 44 | if (this.block) clone.block = this.block.clone(parent, clone);
|
---|
| 45 | clone.lineno = this.lineno;
|
---|
| 46 | clone.column = this.column;
|
---|
| 47 | clone.filename = this.filename;
|
---|
| 48 | return clone;
|
---|
| 49 | };
|
---|
| 50 |
|
---|
| 51 | /**
|
---|
| 52 | * Return <name>(param1, param2, ...).
|
---|
| 53 | *
|
---|
| 54 | * @return {String}
|
---|
| 55 | * @api public
|
---|
| 56 | */
|
---|
| 57 |
|
---|
| 58 | Call.prototype.toString = function(){
|
---|
| 59 | var args = this.args.nodes.map(function(node) {
|
---|
| 60 | var str = node.toString();
|
---|
| 61 | return str.slice(1, str.length - 1);
|
---|
| 62 | }).join(', ');
|
---|
| 63 |
|
---|
| 64 | return this.name + '(' + args + ')';
|
---|
| 65 | };
|
---|
| 66 |
|
---|
| 67 | /**
|
---|
| 68 | * Return a JSON representation of this node.
|
---|
| 69 | *
|
---|
| 70 | * @return {Object}
|
---|
| 71 | * @api public
|
---|
| 72 | */
|
---|
| 73 |
|
---|
| 74 | Call.prototype.toJSON = function(){
|
---|
| 75 | var json = {
|
---|
| 76 | __type: 'Call',
|
---|
| 77 | name: this.name,
|
---|
| 78 | args: this.args,
|
---|
| 79 | lineno: this.lineno,
|
---|
| 80 | column: this.column,
|
---|
| 81 | filename: this.filename
|
---|
| 82 | };
|
---|
| 83 | if (this.block) json.block = this.block;
|
---|
| 84 | return json;
|
---|
| 85 | };
|
---|