diff options
| author | ruki <waruqi@gmail.com> | 2018-11-08 00:38:48 +0800 |
|---|---|---|
| committer | ruki <waruqi@gmail.com> | 2018-11-07 21:53:09 +0800 |
| commit | 26105034da4fcce7ac883c899d781f016559310d (patch) | |
| tree | c459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/stylus/lib/nodes/function.js | |
| parent | 2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff) | |
| download | xmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip | |
switch to vuepress
Diffstat (limited to 'node_modules/stylus/lib/nodes/function.js')
| -rw-r--r-- | node_modules/stylus/lib/nodes/function.js | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/node_modules/stylus/lib/nodes/function.js b/node_modules/stylus/lib/nodes/function.js new file mode 100644 index 00000000..25a6586b --- /dev/null +++ b/node_modules/stylus/lib/nodes/function.js @@ -0,0 +1,128 @@ + +/*! + * Stylus - Function + * Copyright (c) Automattic <developer.wordpress.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(parent){ + if (this.fn) { + var clone = new Function( + this.name + , this.fn); + } else { + var clone = new Function(this.name); + clone.params = this.params.clone(parent, clone); + clone.block = this.block.clone(parent, clone); + } + clone.lineno = this.lineno; + clone.column = this.column; + 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(', ') + + ')'; + } +}; + +/** + * Return a JSON representation of this node. + * + * @return {Object} + * @api public + */ + +Function.prototype.toJSON = function(){ + var json = { + __type: 'Function', + name: this.name, + lineno: this.lineno, + column: this.column, + filename: this.filename + }; + if (this.fn) { + json.fn = this.fn; + } else { + json.params = this.params; + json.block = this.block; + } + return json; +}; |
