You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
769 B
30 lines
769 B
9 years ago
|
var utils = require('../utils')
|
||
|
, nodes = require('../nodes');
|
||
|
|
||
|
/**
|
||
|
* Add property `name` with the given `expr`
|
||
|
* to the mixin-able block.
|
||
|
*
|
||
|
* @param {String|Ident|Literal} name
|
||
|
* @param {Expression} expr
|
||
|
* @return {Property}
|
||
|
* @api public
|
||
|
*/
|
||
|
|
||
|
(module.exports = function addProperty(name, expr){
|
||
|
utils.assertType(name, 'expression', 'name');
|
||
|
name = utils.unwrap(name).first;
|
||
|
utils.assertString(name, 'name');
|
||
|
utils.assertType(expr, 'expression', 'expr');
|
||
|
var prop = new nodes.Property([name], expr);
|
||
|
var block = this.closestBlock;
|
||
|
|
||
|
var len = block.nodes.length
|
||
|
, head = block.nodes.slice(0, block.index)
|
||
|
, tail = block.nodes.slice(block.index++, len);
|
||
|
head.push(prop);
|
||
|
block.nodes = head.concat(tail);
|
||
|
|
||
|
return prop;
|
||
|
}).raw = true;
|