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/ident.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/ident.js')
| -rw-r--r-- | node_modules/stylus/lib/nodes/ident.js | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/node_modules/stylus/lib/nodes/ident.js b/node_modules/stylus/lib/nodes/ident.js new file mode 100644 index 00000000..181f738a --- /dev/null +++ b/node_modules/stylus/lib/nodes/ident.js @@ -0,0 +1,156 @@ + +/*! + * Stylus - Ident + * Copyright (c) Automattic <developer.wordpress.com> + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var Node = require('./node') + , nodes = require('./'); + +/** + * Initialize a new `Ident` by `name` with the given `val` node. + * + * @param {String} name + * @param {Node} val + * @api public + */ + +var Ident = module.exports = function Ident(name, val, mixin){ + Node.call(this); + this.name = name; + this.string = name; + this.val = val || nodes.null; + this.mixin = !!mixin; +}; + +/** + * Check if the variable has a value. + * + * @return {Boolean} + * @api public + */ + +Ident.prototype.__defineGetter__('isEmpty', function(){ + return undefined == this.val; +}); + +/** + * Return hash. + * + * @return {String} + * @api public + */ + +Ident.prototype.__defineGetter__('hash', function(){ + return this.name; +}); + +/** + * Inherit from `Node.prototype`. + */ + +Ident.prototype.__proto__ = Node.prototype; + +/** + * Return a clone of this node. + * + * @return {Node} + * @api public + */ + +Ident.prototype.clone = function(parent){ + var clone = new Ident(this.name); + clone.val = this.val.clone(parent, clone); + clone.mixin = this.mixin; + clone.lineno = this.lineno; + clone.column = this.column; + clone.filename = this.filename; + clone.property = this.property; + clone.rest = this.rest; + return clone; +}; + +/** + * Return a JSON representation of this node. + * + * @return {Object} + * @api public + */ + +Ident.prototype.toJSON = function(){ + return { + __type: 'Ident', + name: this.name, + val: this.val, + mixin: this.mixin, + property: this.property, + rest: this.rest, + lineno: this.lineno, + column: this.column, + filename: this.filename + }; +}; + +/** + * Return <name>. + * + * @return {String} + * @api public + */ + +Ident.prototype.toString = function(){ + return this.name; +}; + +/** + * Coerce `other` to an ident. + * + * @param {Node} other + * @return {String} + * @api public + */ + +Ident.prototype.coerce = function(other){ + switch (other.nodeName) { + case 'ident': + case 'string': + case 'literal': + return new Ident(other.string); + case 'unit': + return new Ident(other.toString()); + default: + return Node.prototype.coerce.call(this, other); + } +}; + +/** + * Operate on `right` with the given `op`. + * + * @param {String} op + * @param {Node} right + * @return {Node} + * @api public + */ + +Ident.prototype.operate = function(op, right){ + var val = right.first; + switch (op) { + case '-': + if ('unit' == val.nodeName) { + var expr = new nodes.Expression; + val = val.clone(); + val.val = -val.val; + expr.push(this); + expr.push(val); + return expr; + } + case '+': + return new nodes.Ident(this.string + this.coerce(val).string); + } + return Node.prototype.operate.call(this, op, right); +}; |
