Sha256: c27669e2d467d617b3095e7e194c7e8f8e96649d714247d45568bb02279268be

Contents?: true

Size: 1.73 KB

Versions: 51

Compression:

Stored size: 1.73 KB

Contents

/*!
 * Stylus - Function
 * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
 * MIT Licensed
 */

/**
 * Module dependencies.
 */

var Node = require('./node');

/**
 * Initialize a new `Function` with `name`, `params`, and `body`.
 *
 * @param {String} name
 * @param {Params|Function} params
 * @param {Block} body
 * @api public
 */

var Function = module.exports = function Function(name, params, body){
  Node.call(this);
  this.name = name;
  this.params = params;
  this.block = body;
  if ('function' == typeof params) this.fn = params;
};

/**
 * Check function arity.
 *
 * @return {Boolean}
 * @api public
 */

Function.prototype.__defineGetter__('arity', function(){
  return this.params.length;
});

/**
 * Inherit from `Node.prototype`.
 */

Function.prototype.__proto__ = Node.prototype;

/**
 * Return hash.
 *
 * @return {String}
 * @api public
 */

Function.prototype.__defineGetter__('hash', function(){
  return 'function ' + this.name;
});

/**
 * Return a clone of this node.
 * 
 * @return {Node}
 * @api public
 */

Function.prototype.clone = function(){
  if (this.fn) {
    var clone = new Function(
        this.name
      , this.fn);
  } else {
    var clone = new Function(
        this.name
      , this.params.clone()
      , this.block.clone());
  }
  clone.lineno = this.lineno;
  clone.filename = this.filename;
  return clone;
};

/**
 * Return <name>(param1, param2, ...).
 *
 * @return {String}
 * @api public
 */

Function.prototype.toString = function(){
  if (this.fn) {
    return this.name
      + '('
      + this.fn.toString()
        .match(/^function *\w*\((.*?)\)/)
        .slice(1)
        .join(', ')
      + ')';
  } else {
    return this.name
      + '('
      + this.params.nodes.join(', ')
      + ')';
  }
};

Version data entries

51 entries across 37 versions & 2 rubygems

Version Path
ela-4.1.6 node_modules/codo/node_modules/stylus/lib/nodes/function.js
ela-4.1.6 node_modules/poised/node_modules/nib/node_modules/stylus/lib/nodes/function.js
ela-4.1.5 node_modules/codo/node_modules/stylus/lib/nodes/function.js
ela-4.1.5 node_modules/poised/node_modules/nib/node_modules/stylus/lib/nodes/function.js
ela-4.1.4 node_modules/codo/node_modules/stylus/lib/nodes/function.js
ela-4.1.4 node_modules/poised/node_modules/nib/node_modules/stylus/lib/nodes/function.js
ela-4.1.3 node_modules/codo/node_modules/stylus/lib/nodes/function.js
ela-4.1.3 node_modules/poised/node_modules/nib/node_modules/stylus/lib/nodes/function.js
ela-4.1.2 node_modules/codo/node_modules/stylus/lib/nodes/function.js
ela-4.1.2 node_modules/poised/node_modules/nib/node_modules/stylus/lib/nodes/function.js
ela-4.1.1 node_modules/poised/node_modules/nib/node_modules/stylus/lib/nodes/function.js
ela-4.1.1 node_modules/codo/node_modules/stylus/lib/nodes/function.js
ela-4.1.0 node_modules/codo/node_modules/stylus/lib/nodes/function.js
ela-4.1.0 node_modules/poised/node_modules/nib/node_modules/stylus/lib/nodes/function.js
ela-4.0.0 node_modules/codo/node_modules/stylus/lib/nodes/function.js
ela-3.4.3 node_modules/codo/node_modules/stylus/lib/nodes/function.js
ela-3.4.2 node_modules/codo/node_modules/stylus/lib/nodes/function.js
ela-3.4.0 node_modules/codo/node_modules/stylus/lib/nodes/function.js
ela-3.3.1 node_modules/codo/node_modules/stylus/lib/nodes/function.js
ela-3.3.0 node_modules/poised.old/node_modules/nib/node_modules/stylus/lib/nodes/function.js